|
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"; |
4 | 6 |
|
5 | 7 | // Note: Currently, in order for this to run, the evm bindings with extra contracts must be build
|
6 | 8 | // To do that, at the root, run `npm run generate:test`
|
7 | 9 |
|
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 |
39 | 13 |
|
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 |
43 | 17 |
|
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 | +); |
47 | 27 |
|
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 | +); |
55 | 37 |
|
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"; |
61 | 41 |
|
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"; |
65 | 45 |
|
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 | + }; |
69 | 61 |
|
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 | + }); |
73 | 66 |
|
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 | + ]); |
77 | 84 | });
|
78 | 85 | });
|
0 commit comments