Skip to content

Commit

Permalink
tilt: parallelize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Dec 4, 2024
1 parent 25c87c7 commit c08e3f9
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load('ext://namespace', 'namespace_create', 'namespace_inject')
load('ext://git_resource', 'git_checkout')

git_checkout('https://github.com/wormhole-foundation/wormhole.git#main', '.wormhole/', unsafe_mode=True)
local(['sed','-i','/{chainId: vaa.ChainIDEthereum, addr: "000000000000000000000000855FA758c77D68a04990E992aA4dcdeF899F654A"},/i {chainId: vaa.ChainIDSolana, addr: "8bf0b547c96edc5c1d512ca25c5c1d1812a180438a0046e511d1fb61561d5cdf"},{chainId: vaa.ChainIDSolana, addr: "0a490691c21334ca173d9ce386e2a86774ce173f351db10d5d0cccc5c4875376"},{chainId: vaa.ChainIDEthereum, addr: "0000000000000000000000006f84742680311cef5ba42bc10a71a4708b4561d1"},{chainId: vaa.ChainIDEthereum, addr: "000000000000000000000000c3ef4965b788cc4b905084d01f2eb7d4b6e93abf"},{chainId: vaa.ChainIDBSC, addr: "0000000000000000000000006f84742680311cef5ba42bc10a71a4708b4561d1"},{chainId: vaa.ChainIDBSC, addr: "0000000000000000000000003f4e941ef5071a1d09c2eb4a24da1fc43f76fcff"},', '.wormhole/node/pkg/accountant/ntt_config.go'])
local(['sed','-i','/{chainId: vaa.ChainIDEthereum, addr: "000000000000000000000000855FA758c77D68a04990E992aA4dcdeF899F654A"},/i {chainId: vaa.ChainIDSolana, addr: "8bf0b547c96edc5c1d512ca25c5c1d1812a180438a0046e511d1fb61561d5cdf"},{chainId: vaa.ChainIDSolana, addr: "0a490691c21334ca173d9ce386e2a86774ce173f351db10d5d0cccc5c4875376"},{chainId: vaa.ChainIDEthereum, addr: "0000000000000000000000006f84742680311cef5ba42bc10a71a4708b4561d1"},{chainId: vaa.ChainIDEthereum, addr: "0000000000000000000000009ba423008e530c4d464da15f0c9652942216f019"},{chainId: vaa.ChainIDBSC, addr: "0000000000000000000000006f84742680311cef5ba42bc10a71a4708b4561d1"},{chainId: vaa.ChainIDBSC, addr: "000000000000000000000000baac7efcddde498b0b791eda92d43b20f5cd8ff6"},', '.wormhole/node/pkg/accountant/ntt_config.go'])

load(".wormhole/Tiltfile", "namespace", "k8s_yaml_with_ns")

Expand Down
62 changes: 50 additions & 12 deletions sdk/__tests__/accountant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,37 @@ export const ZERO_FEE = {
};

// cache the client and signer
let client: Awaited<ReturnType<typeof getWormchainSigningClient>>;
let signer: string;
let clientAndSigner: {
[privateKey: string]: {
client: Awaited<ReturnType<typeof getWormchainSigningClient>>;
signer: string;
};
} = {};

async function getClientAndSigner(privateKey: string) {
return (
clientAndSigner[privateKey] ||
(await (async () => {
const wallet = await getWallet(privateKey);
const client = await getWormchainSigningClient(url, wallet);
const signers = await wallet.getAccounts();
const signer = signers[0]!.address;
const ret = { client, signer };
clientAndSigner[privateKey] = ret;
return ret;
})())
);
}

const privateKey =
"quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty";
const url = process.env["CI"]
? "http://wormchain:26657"
: "http://localhost:26659";

export async function submitAccountantVAAs(vaas: Uint8Array[]) {
if (!signer) {
// NttAccountantTest = wormhole18s5lynnmx37hq4wlrw9gdn68sg2uxp5rwf5k3u
const wallet = await getWallet(privateKey);
client = await getWormchainSigningClient(url, wallet);
const signers = await wallet.getAccounts();
signer = signers[0]!.address;
}
export async function submitAccountantVAAs(
vaas: Uint8Array[],
privateKey: string
) {
const { client, signer } = await getClientAndSigner(privateKey);
const msg = client.wasm.msgExecuteContract({
sender: signer,
contract:
Expand All @@ -49,3 +63,27 @@ export async function submitAccountantVAAs(vaas: Uint8Array[]) {
}
console.log(`Accountant tx submitted: ${result.transactionHash}`);
}

export async function registerRelayers(privateKey: string) {
try {
await submitAccountantVAAs(
[
new Uint8Array(
Buffer.from(
"01000000000100a4f34c530ff196c060ff349f2bf7bcb16865771a7165ca84fb5e263f148a01b03592b9af46a410a3760f39097d7380e4e72b6e1da4fa25c2d7b2d00f102d0cae0100000000000000000001000000000000000000000000000000000000000000000000000000000000000400000000001ce9cf010000000000000000000000000000000000576f726d686f6c6552656c617965720100000002000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
"hex"
)
),
new Uint8Array(
Buffer.from(
"010000000001000fd839cfdbea0f43a35dbb8cc0219b55cd5ec9f59b7e4a7183dbeebd522f7c673c866a218bfa108d8c7606acb5fc6b94a7a4c3be06f10836c242afecdb80da6e00000000000000000000010000000000000000000000000000000000000000000000000000000000000004000000000445fb0b010000000000000000000000000000000000576f726d686f6c6552656c617965720100000004000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
"hex"
)
),
],
privateKey
);
} catch (e) {
console.log(e);
}
}
135 changes: 71 additions & 64 deletions sdk/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,85 @@
import { Chain } from "@wormhole-foundation/sdk-base";
import { deploy, link, transferWithChecks, wh } from "./utils.js";
import { submitAccountantVAAs } from "./accountant.js";
import { web3 } from "@coral-xyz/anchor";
import { chainToPlatform } from "@wormhole-foundation/sdk-connect";

import { registerRelayers } from "./accountant.js";
import { Ctx, testHub } from "./utils.js";

// Note: Currently, in order for this to run, the evm bindings with extra contracts must be build
// To do that, at the root, run `npm run generate:test`

const cases = [
["Solana", ["Ethereum", "Bsc"]],
["Ethereum", ["Bsc", "Solana"]],
// ["Bsc", ["Ethereum", "Solana"]],
];

async function registerRelayers() {
try {
await submitAccountantVAAs([
new Uint8Array(
Buffer.from(
"01000000000100a4f34c530ff196c060ff349f2bf7bcb16865771a7165ca84fb5e263f148a01b03592b9af46a410a3760f39097d7380e4e72b6e1da4fa25c2d7b2d00f102d0cae0100000000000000000001000000000000000000000000000000000000000000000000000000000000000400000000001ce9cf010000000000000000000000000000000000576f726d686f6c6552656c617965720100000002000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
"hex"
)
),
new Uint8Array(
Buffer.from(
"010000000001000fd839cfdbea0f43a35dbb8cc0219b55cd5ec9f59b7e4a7183dbeebd522f7c673c866a218bfa108d8c7606acb5fc6b94a7a4c3be06f10836c242afecdb80da6e00000000000000000000010000000000000000000000000000000000000000000000000000000000000004000000000445fb0b010000000000000000000000000000000000576f726d686f6c6552656c617965720100000004000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
"hex"
)
),
]);
} catch (e) {
console.log(e);
}
}

describe("Hub and Spoke Tests", function () {
beforeAll(async () => {
await registerRelayers();
});
// https://github.com/wormhole-foundation/wormhole/blob/347357b251e850a51eca351943cf71423c4f0bc3/scripts/devnet-consts.json#L257
const ETH_PRIVATE_KEY =
"0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"; // Ganache default private key

test.each(cases)("Test %s Hub", async (source, destinations) => {
// Get chain context objects
const hubChain = wh.getChain(source as Chain);
// https://github.com/wormhole-foundation/wormhole/blob/347357b251e850a51eca351943cf71423c4f0bc3/scripts/devnet-consts.json#L272
const ETH_PRIVATE_KEY_2 =
"0x646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913"; // Ganache account 3

const [a, b] = destinations;
const spokeChainA = wh.getChain(a as Chain);
const spokeChainB = wh.getChain(b as Chain);
// https://github.com/wormhole-foundation/wormhole/blob/347357b251e850a51eca351943cf71423c4f0bc3/sdk/js/src/token_bridge/__tests__/utils/consts.ts#L33-L38
const SOL_PRIVATE_KEY = web3.Keypair.fromSecretKey(
new Uint8Array([
14, 173, 153, 4, 176, 224, 201, 111, 32, 237, 183, 185, 159, 247, 22, 161,
89, 84, 215, 209, 212, 137, 10, 92, 157, 49, 29, 192, 101, 164, 152, 70, 87,
65, 8, 174, 214, 157, 175, 126, 98, 90, 54, 24, 100, 177, 247, 77, 19, 112,
47, 44, 165, 109, 233, 102, 14, 86, 109, 29, 134, 145, 132, 141,
])
);

// Deploy contracts for hub chain
console.log("Deploying contracts");
const [hub, spokeA, spokeB] = await Promise.all([
deploy({ context: hubChain, mode: "locking" }),
deploy({ context: spokeChainA, mode: "burning" }),
deploy({ context: spokeChainB, mode: "burning" }),
]);
// https://github.com/wormhole-foundation/wormhole/blob/347357b251e850a51eca351943cf71423c4f0bc3/sdk/js/src/nft_bridge/__tests__/utils/consts.ts#L24C51-L29C2
const SOL_PRIVATE_KEY_2 = web3.Keypair.fromSecretKey(
new Uint8Array([
118, 84, 4, 83, 83, 183, 31, 184, 20, 172, 95, 146, 7, 107, 141, 183, 124,
196, 66, 246, 215, 243, 54, 61, 118, 188, 239, 237, 168, 108, 227, 169, 93,
119, 180, 216, 9, 169, 30, 4, 167, 235, 188, 51, 70, 24, 181, 227, 189, 59,
163, 161, 252, 219, 17, 105, 197, 241, 19, 66, 205, 188, 232, 131,
])
);

console.log("Deployed: ", {
[hub.context.chain]: hub.contracts,
[spokeA.context.chain]: spokeA.contracts,
[spokeB.context.chain]: spokeB.contracts,
});
// https://github.com/wormhole-foundation/wormhole/blob/347357b251e850a51eca351943cf71423c4f0bc3/wormchain/contracts/tools/__tests__/test_ntt_accountant.ts#L139
const ACCT_MNEMONIC =
"quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty";

// Link contracts
console.log("Linking Peers");
await link([hub, spokeA, spokeB]);
// https://github.com/wormhole-foundation/wormhole/blob/347357b251e850a51eca351943cf71423c4f0bc3/scripts/devnet-consts.json#L211
const ACCT_MNEMONIC_2 =
"notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius";

// Transfer tokens from hub to spoke and check balances
console.log("Transfer hub to spoke A");
await transferWithChecks(hub, spokeA);
const makeGetNativeSigner =
(ethKey: string, solKey: web3.Keypair) =>
(ctx: Partial<Ctx>): any => {
const platform = chainToPlatform(ctx.context!.chain);
switch (platform) {
case "Evm":
return ethKey;
case "Solana":
return solKey;
default:
throw (
"Unsupported platform " + platform + " (add it to getNativeSigner)"
);
}
};

// Transfer between spokes and check balances
console.log("Transfer spoke A to spoke B");
await transferWithChecks(spokeA, spokeB);
describe("Hub and Spoke Tests", function () {
beforeAll(async () => {
await registerRelayers(ACCT_MNEMONIC);
});

// Transfer back to hub and check balances
console.log("Transfer spoke B to hub");
await transferWithChecks(spokeB, hub);
test("Test Solana and Ethereum Hubs", async () => {
await Promise.all([
testHub(
"Solana",
"Ethereum",
"Bsc",
makeGetNativeSigner(ETH_PRIVATE_KEY, SOL_PRIVATE_KEY),
ACCT_MNEMONIC
),
testHub(
"Ethereum",
"Bsc",
"Solana",
makeGetNativeSigner(ETH_PRIVATE_KEY_2, SOL_PRIVATE_KEY_2),
ACCT_MNEMONIC_2
),
]);
});
});
6 changes: 0 additions & 6 deletions sdk/__tests__/solana-tilt.json

This file was deleted.

Loading

0 comments on commit c08e3f9

Please sign in to comment.