-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
187 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
), | ||
]); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.