Skip to content

Commit 7a4ca9d

Browse files
committed
ci: e2e solana hub
1 parent 16e0b5d commit 7a4ca9d

File tree

1 file changed

+73
-32
lines changed

1 file changed

+73
-32
lines changed

ci_tests/src/index.ts

+73-32
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { NttManager__factory } from "../evm_binding/factories/NttManager__factor
3535
import { TransceiverStructs__factory } from "../evm_binding/factories/TransceiverStructs__factory";
3636
import { TrimmedAmountLib__factory } from "../evm_binding/factories/TrimmedAmount.sol/TrimmedAmountLib__factory";
3737
import { WormholeTransceiver__factory } from "../evm_binding/factories/WormholeTransceiver__factory";
38-
import { NTT } from "../solana_binding/ts/sdk";
38+
import { NTT, NttProgramId } from "../solana_binding/ts/sdk";
3939
import solanaTiltKey from "./solana-tilt.json"; // from https://github.com/wormhole-foundation/wormhole/blob/main/solana/keys/solana-devnet.json
4040

4141
// NOTE: This test uses ethers-v5 as it has proven to be significantly faster than v6.
@@ -53,6 +53,7 @@ interface EVMChainDetails extends BaseDetails {
5353
interface SolanaChainDetails extends BaseDetails {
5454
type: "solana";
5555
signer: web3.Keypair;
56+
manager: NTT;
5657
}
5758
interface BaseDetails {
5859
chainId: ChainId;
@@ -84,10 +85,6 @@ const SOL_CONNECTION = new web3.Connection(
8485
"confirmed"
8586
);
8687
const SOL_CORE_ADDRESS = "Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o";
87-
const SOL_NTT_CONTRACT = new NTT(SOL_CONNECTION, {
88-
nttId: "NTTManager111111111111111111111111111111111",
89-
wormholeId: SOL_CORE_ADDRESS,
90-
});
9188
const RELAYER_CONTRACT = "0x53855d4b64E9A3CF59A84bc768adA716B5536BC5";
9289

9390
// Wormhole format means that addresses are bytes32 instead of addresses when using them to support other chains.
@@ -265,8 +262,20 @@ async function deployEvm(
265262
};
266263
}
267264

268-
async function initSolana(mode: Mode): Promise<SolanaChainDetails> {
269-
console.log("Using public key", SOL_PUBLIC_KEY.toString());
265+
async function initSolana(
266+
mode: Mode,
267+
nttId: NttProgramId
268+
): Promise<SolanaChainDetails> {
269+
console.log(
270+
"Using public key",
271+
SOL_PUBLIC_KEY.toString(),
272+
"and manager address",
273+
nttId
274+
);
275+
const manager = new NTT(SOL_CONNECTION, {
276+
nttId,
277+
wormholeId: SOL_CORE_ADDRESS,
278+
});
270279
const mint = await spl.createMint(
271280
SOL_CONNECTION,
272281
SOL_PRIVATE_KEY,
@@ -289,7 +298,7 @@ async function initSolana(mode: Mode): Promise<SolanaChainDetails> {
289298
mint,
290299
tokenAccount,
291300
SOL_PRIVATE_KEY,
292-
BigInt(10000000)
301+
utils.parseUnits("100", 9).toBigInt()
293302
);
294303
console.log("Minted 10000000 tokens");
295304
}
@@ -299,30 +308,27 @@ async function initSolana(mode: Mode): Promise<SolanaChainDetails> {
299308
mint,
300309
SOL_PRIVATE_KEY,
301310
0, // mint
302-
SOL_NTT_CONTRACT.tokenAuthorityAddress()
311+
manager.tokenAuthorityAddress()
303312
);
304313
console.log(
305314
"Set token authority to",
306-
SOL_NTT_CONTRACT.tokenAuthorityAddress().toString()
315+
manager.tokenAuthorityAddress().toString()
307316
);
308317

309-
await SOL_NTT_CONTRACT.initialize({
318+
await manager.initialize({
310319
payer: SOL_PRIVATE_KEY,
311320
owner: SOL_PRIVATE_KEY,
312321
chain: "solana",
313322
mint,
314323
outboundLimit: new BN(1000000000),
315324
mode,
316325
});
317-
console.log(
318-
"Initialized ntt at",
319-
SOL_NTT_CONTRACT.program.programId.toString()
320-
);
326+
console.log("Initialized ntt at", manager.program.programId.toString());
321327

322-
await SOL_NTT_CONTRACT.registerTransceiver({
328+
await manager.registerTransceiver({
323329
payer: SOL_PRIVATE_KEY,
324330
owner: SOL_PRIVATE_KEY,
325-
transceiver: SOL_NTT_CONTRACT.program.programId,
331+
transceiver: manager.program.programId,
326332
});
327333
console.log("Registered transceiver with self");
328334

@@ -331,23 +337,25 @@ async function initSolana(mode: Mode): Promise<SolanaChainDetails> {
331337
chainId: 1,
332338
chainName: "solana",
333339
mode,
334-
transceiverAddress: SOL_NTT_CONTRACT.emitterAccountAddress().toString(),
335-
managerAddress: SOL_NTT_CONTRACT.program.programId.toString(),
340+
transceiverAddress: manager.emitterAccountAddress().toString(),
341+
managerAddress: manager.program.programId.toString(),
336342
NTTTokenAddress: mint.toString(),
337343
wormholeCoreAddress: SOL_CORE_ADDRESS,
338344
signer: SOL_PRIVATE_KEY,
345+
manager,
339346
};
340347
}
341348

342349
async function setupPeer(targetInfo: ChainDetails, peerInfo: ChainDetails) {
343350
const managerAddress =
344351
peerInfo.type === "evm"
345352
? addressToBytes32(peerInfo.managerAddress)
346-
: `0x${SOL_NTT_CONTRACT.program.programId.toBuffer().toString("hex")}`;
353+
: `0x${peerInfo.manager.program.programId.toBuffer().toString("hex")}`;
347354
const transceiverEmitter =
348355
peerInfo.type === "evm"
349356
? addressToBytes32(peerInfo.transceiverAddress)
350-
: `0x${SOL_NTT_CONTRACT.emitterAccountAddress()
357+
: `0x${peerInfo.manager
358+
.emitterAccountAddress()
351359
.toBuffer()
352360
.toString("hex")}`;
353361
const tokenDecimals = peerInfo.type === "evm" ? 18 : 9;
@@ -384,13 +392,13 @@ async function setupPeer(targetInfo: ChainDetails, peerInfo: ChainDetails) {
384392
);
385393
}
386394
} else if (targetInfo.type === "solana") {
387-
await SOL_NTT_CONTRACT.setWormholeTransceiverPeer({
395+
await targetInfo.manager.setWormholeTransceiverPeer({
388396
payer: SOL_PRIVATE_KEY,
389397
owner: SOL_PRIVATE_KEY,
390398
chain: coalesceChainName(peerInfo.chainId),
391399
address: Buffer.from(transceiverEmitter.substring(2), "hex"),
392400
});
393-
await SOL_NTT_CONTRACT.setPeer({
401+
await targetInfo.manager.setPeer({
394402
payer: SOL_PRIVATE_KEY,
395403
owner: SOL_PRIVATE_KEY,
396404
chain: coalesceChainName(peerInfo.chainId),
@@ -449,7 +457,7 @@ async function receive(
449457
SOL_PUBLIC_KEY,
450458
vaa
451459
);
452-
const released = await SOL_NTT_CONTRACT.redeem({
460+
const released = await chainDest.manager.redeem({
453461
payer: SOL_PRIVATE_KEY,
454462
vaa,
455463
});
@@ -471,12 +479,12 @@ async function getManagerAndUserBalance(
471479
await token.balanceOf(ETH_PUBLIC_KEY),
472480
];
473481
} else if (chain.type === "solana") {
474-
const mintAddress = await SOL_NTT_CONTRACT.mintAccountAddress();
482+
const mintAddress = await chain.manager.mintAccountAddress();
475483
const associatedTokenAddress = spl.getAssociatedTokenAddressSync(
476484
mintAddress,
477485
SOL_PUBLIC_KEY
478486
);
479-
const custodyAddress = await SOL_NTT_CONTRACT.custodyAccountAddress(
487+
const custodyAddress = await chain.manager.custodyAccountAddress(
480488
mintAddress
481489
);
482490
return [
@@ -545,12 +553,12 @@ async function transferWithChecks(
545553
sourceChain.wormholeCoreAddress
546554
);
547555
} else if (sourceChain.type === "solana") {
548-
const mintAddress = await SOL_NTT_CONTRACT.mintAccountAddress();
556+
const mintAddress = await sourceChain.manager.mintAccountAddress();
549557
const associatedTokenAddress = spl.getAssociatedTokenAddressSync(
550558
mintAddress,
551559
SOL_PUBLIC_KEY
552560
);
553-
const outboxItem = await SOL_NTT_CONTRACT.transfer({
561+
const outboxItem = await sourceChain.manager.transfer({
554562
payer: SOL_PRIVATE_KEY,
555563
from: associatedTokenAddress,
556564
fromAuthority: SOL_PRIVATE_KEY,
@@ -563,7 +571,7 @@ async function transferWithChecks(
563571
shouldQueue: false,
564572
});
565573
const wormholeMessage =
566-
SOL_NTT_CONTRACT.wormholeMessageAccountAddress(outboxItem);
574+
sourceChain.manager.wormholeMessageAccountAddress(outboxItem);
567575
const wormholeMessageAccount = await SOL_CONNECTION.getAccountInfo(
568576
wormholeMessage
569577
);
@@ -573,7 +581,8 @@ async function transferWithChecks(
573581
const messageData = PostedMessageData.deserialize(
574582
wormholeMessageAccount.data
575583
);
576-
emitterAddress = SOL_NTT_CONTRACT.emitterAccountAddress()
584+
emitterAddress = sourceChain.manager
585+
.emitterAccountAddress()
577586
.toBuffer()
578587
.toString("hex");
579588
sequence = messageData.message.sequence.toString();
@@ -634,6 +643,7 @@ async function transferWithChecks(
634643
}
635644

636645
async function testEthHub() {
646+
console.log("\n\n\n***\nEth Hub Test\n***");
637647
console.log("\nDeploying on eth-devnet");
638648
console.log("===============================================");
639649
const ethInfo = await deployEvm(ETH_SIGNER, "ethereum", "locking");
@@ -642,7 +652,10 @@ async function testEthHub() {
642652
const bscInfo = await deployEvm(BSC_SIGNER, "bsc", "burning");
643653
console.log("\nInitializing on solana-devnet");
644654
console.log("===============================================");
645-
const solInfo = await initSolana("burning");
655+
const solInfo = await initSolana(
656+
"burning",
657+
"NTTManager111111111111111111111111111111111"
658+
);
646659
await link([ethInfo, bscInfo, solInfo]);
647660
console.log("\nStarting tests");
648661
console.log("========================");
@@ -662,4 +675,32 @@ async function testEthHub() {
662675
// TODO: corrupted or bad VAA usage
663676
}
664677

665-
testEthHub();
678+
async function testSolanaHub() {
679+
console.log("\n\n\n***\nSolana Hub Test\n***");
680+
console.log("\nDeploying on eth-devnet");
681+
console.log("===============================================");
682+
const ethInfo = await deployEvm(ETH_SIGNER, "ethereum", "burning");
683+
console.log("\nDeploying on eth-devnet2");
684+
console.log("===============================================");
685+
const bscInfo = await deployEvm(BSC_SIGNER, "bsc", "burning");
686+
console.log("\nInitializing on solana-devnet");
687+
console.log("===============================================");
688+
const solInfo = await initSolana(
689+
"locking",
690+
"NTTManager222222222222222222222222222222222"
691+
);
692+
await link([ethInfo, bscInfo, solInfo]);
693+
console.log("\nStarting tests");
694+
console.log("========================");
695+
console.log("Solana -> Eth -> BSC -> Solana");
696+
await transferWithChecks(solInfo, ethInfo);
697+
await transferWithChecks(ethInfo, bscInfo);
698+
await transferWithChecks(bscInfo, solInfo);
699+
}
700+
701+
async function test() {
702+
await testEthHub();
703+
await testSolanaHub();
704+
}
705+
706+
test();

0 commit comments

Comments
 (0)