Skip to content

Commit 9c5276f

Browse files
committed
tilt: parallelize tests
1 parent 69a2d17 commit 9c5276f

File tree

6 files changed

+187
-118
lines changed

6 files changed

+187
-118
lines changed

Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ load('ext://namespace', 'namespace_create', 'namespace_inject')
22
load('ext://git_resource', 'git_checkout')
33

44
git_checkout('https://github.com/wormhole-foundation/wormhole.git#main', '.wormhole/', unsafe_mode=True)
5-
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'])
5+
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'])
66

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

sdk/__tests__/accountant.ts

+50-12
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,37 @@ export const ZERO_FEE = {
1010
};
1111

1212
// cache the client and signer
13-
let client: Awaited<ReturnType<typeof getWormchainSigningClient>>;
14-
let signer: string;
13+
let clientAndSigner: {
14+
[privateKey: string]: {
15+
client: Awaited<ReturnType<typeof getWormchainSigningClient>>;
16+
signer: string;
17+
};
18+
} = {};
19+
20+
async function getClientAndSigner(privateKey: string) {
21+
return (
22+
clientAndSigner[privateKey] ||
23+
(await (async () => {
24+
const wallet = await getWallet(privateKey);
25+
const client = await getWormchainSigningClient(url, wallet);
26+
const signers = await wallet.getAccounts();
27+
const signer = signers[0]!.address;
28+
const ret = { client, signer };
29+
clientAndSigner[privateKey] = ret;
30+
return ret;
31+
})())
32+
);
33+
}
1534

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

22-
export async function submitAccountantVAAs(vaas: Uint8Array[]) {
23-
if (!signer) {
24-
// NttAccountantTest = wormhole18s5lynnmx37hq4wlrw9gdn68sg2uxp5rwf5k3u
25-
const wallet = await getWallet(privateKey);
26-
client = await getWormchainSigningClient(url, wallet);
27-
const signers = await wallet.getAccounts();
28-
signer = signers[0]!.address;
29-
}
39+
export async function submitAccountantVAAs(
40+
vaas: Uint8Array[],
41+
privateKey: string
42+
) {
43+
const { client, signer } = await getClientAndSigner(privateKey);
3044
const msg = client.wasm.msgExecuteContract({
3145
sender: signer,
3246
contract:
@@ -49,3 +63,27 @@ export async function submitAccountantVAAs(vaas: Uint8Array[]) {
4963
}
5064
console.log(`Accountant tx submitted: ${result.transactionHash}`);
5165
}
66+
67+
export async function registerRelayers(privateKey: string) {
68+
try {
69+
await submitAccountantVAAs(
70+
[
71+
new Uint8Array(
72+
Buffer.from(
73+
"01000000000100a4f34c530ff196c060ff349f2bf7bcb16865771a7165ca84fb5e263f148a01b03592b9af46a410a3760f39097d7380e4e72b6e1da4fa25c2d7b2d00f102d0cae0100000000000000000001000000000000000000000000000000000000000000000000000000000000000400000000001ce9cf010000000000000000000000000000000000576f726d686f6c6552656c617965720100000002000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
74+
"hex"
75+
)
76+
),
77+
new Uint8Array(
78+
Buffer.from(
79+
"010000000001000fd839cfdbea0f43a35dbb8cc0219b55cd5ec9f59b7e4a7183dbeebd522f7c673c866a218bfa108d8c7606acb5fc6b94a7a4c3be06f10836c242afecdb80da6e00000000000000000000010000000000000000000000000000000000000000000000000000000000000004000000000445fb0b010000000000000000000000000000000000576f726d686f6c6552656c617965720100000004000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
80+
"hex"
81+
)
82+
),
83+
],
84+
privateKey
85+
);
86+
} catch (e) {
87+
console.log(e);
88+
}
89+
}

sdk/__tests__/index.test.ts

+71-64
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,85 @@
1-
import { Chain } from "@wormhole-foundation/sdk-base";
2-
import { deploy, link, transferWithChecks, wh } from "./utils.js";
3-
import { submitAccountantVAAs } from "./accountant.js";
1+
import { web3 } from "@coral-xyz/anchor";
2+
import { chainToPlatform } from "@wormhole-foundation/sdk-connect";
3+
4+
import { registerRelayers } from "./accountant.js";
5+
import { Ctx, testHub } from "./utils.js";
46

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

8-
const cases = [
9-
["Solana", ["Ethereum", "Bsc"]],
10-
["Ethereum", ["Bsc", "Solana"]],
11-
// ["Bsc", ["Ethereum", "Solana"]],
12-
];
13-
14-
async function registerRelayers() {
15-
try {
16-
await submitAccountantVAAs([
17-
new Uint8Array(
18-
Buffer.from(
19-
"01000000000100a4f34c530ff196c060ff349f2bf7bcb16865771a7165ca84fb5e263f148a01b03592b9af46a410a3760f39097d7380e4e72b6e1da4fa25c2d7b2d00f102d0cae0100000000000000000001000000000000000000000000000000000000000000000000000000000000000400000000001ce9cf010000000000000000000000000000000000576f726d686f6c6552656c617965720100000002000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
20-
"hex"
21-
)
22-
),
23-
new Uint8Array(
24-
Buffer.from(
25-
"010000000001000fd839cfdbea0f43a35dbb8cc0219b55cd5ec9f59b7e4a7183dbeebd522f7c673c866a218bfa108d8c7606acb5fc6b94a7a4c3be06f10836c242afecdb80da6e00000000000000000000010000000000000000000000000000000000000000000000000000000000000004000000000445fb0b010000000000000000000000000000000000576f726d686f6c6552656c617965720100000004000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
26-
"hex"
27-
)
28-
),
29-
]);
30-
} catch (e) {
31-
console.log(e);
32-
}
33-
}
34-
35-
describe("Hub and Spoke Tests", function () {
36-
beforeAll(async () => {
37-
await registerRelayers();
38-
});
10+
// https://github.com/wormhole-foundation/wormhole/blob/347357b251e850a51eca351943cf71423c4f0bc3/scripts/devnet-consts.json#L257
11+
const ETH_PRIVATE_KEY =
12+
"0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"; // Ganache default private key
3913

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

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

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

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

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

66-
// Transfer tokens from hub to spoke and check balances
67-
console.log("Transfer hub to spoke A");
68-
await transferWithChecks(hub, spokeA);
46+
const makeGetNativeSigner =
47+
(ethKey: string, solKey: web3.Keypair) =>
48+
(ctx: Partial<Ctx>): any => {
49+
const platform = chainToPlatform(ctx.context!.chain);
50+
switch (platform) {
51+
case "Evm":
52+
return ethKey;
53+
case "Solana":
54+
return solKey;
55+
default:
56+
throw (
57+
"Unsupported platform " + platform + " (add it to getNativeSigner)"
58+
);
59+
}
60+
};
6961

70-
// Transfer between spokes and check balances
71-
console.log("Transfer spoke A to spoke B");
72-
await transferWithChecks(spokeA, spokeB);
62+
describe("Hub and Spoke Tests", function () {
63+
beforeAll(async () => {
64+
await registerRelayers(ACCT_MNEMONIC);
65+
});
7366

74-
// Transfer back to hub and check balances
75-
console.log("Transfer spoke B to hub");
76-
await transferWithChecks(spokeB, hub);
67+
test("Test Solana and Ethereum Hubs", async () => {
68+
await Promise.all([
69+
testHub(
70+
"Solana",
71+
"Ethereum",
72+
"Bsc",
73+
makeGetNativeSigner(ETH_PRIVATE_KEY, SOL_PRIVATE_KEY),
74+
ACCT_MNEMONIC
75+
),
76+
testHub(
77+
"Ethereum",
78+
"Bsc",
79+
"Solana",
80+
makeGetNativeSigner(ETH_PRIVATE_KEY_2, SOL_PRIVATE_KEY_2),
81+
ACCT_MNEMONIC_2
82+
),
83+
]);
7784
});
7885
});

sdk/__tests__/solana-tilt.json

-6
This file was deleted.

0 commit comments

Comments
 (0)