Skip to content

Commit efe3daa

Browse files
committed
solana: Update TS test and IDL
1 parent b041c79 commit efe3daa

File tree

6 files changed

+827
-38
lines changed

6 files changed

+827
-38
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solana/tests/anchor.test.ts

+63-22
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ import {
2424
import { SolanaWormholeCore } from "@wormhole-foundation/sdk-solana-core";
2525
import * as fs from "fs";
2626

27-
import {
28-
PublicKey,
29-
SystemProgram,
30-
Transaction,
31-
sendAndConfirmTransaction,
32-
} from "@solana/web3.js";
3327
import { DummyTransferHook } from "../ts/idl/1_0_0/ts/dummy_transfer_hook.js";
3428
import { getTransceiverProgram, IdlVersion, NTT } from "../ts/index.js";
3529
import { derivePda } from "../ts/lib/utils.js";
@@ -41,9 +35,9 @@ const VERSION: IdlVersion = "3.0.0";
4135
const GUARDIAN_KEY =
4236
"cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0";
4337
const CORE_BRIDGE_ADDRESS = contracts.coreBridge("Mainnet", "Solana");
44-
const NTT_ADDRESS: PublicKey =
38+
const NTT_ADDRESS: anchor.web3.PublicKey =
4539
anchor.workspace.ExampleNativeTokenTransfers.programId;
46-
const WH_TRANSCEIVER_ADDRESS: PublicKey =
40+
const WH_TRANSCEIVER_ADDRESS: anchor.web3.PublicKey =
4741
anchor.workspace.NttTransceiver.programId;
4842

4943
async function signSendWait(
@@ -102,12 +96,12 @@ const mint = anchor.web3.Keypair.generate();
10296
const dummyTransferHook = anchor.workspace
10397
.DummyTransferHook as anchor.Program<DummyTransferHook>;
10498

105-
const [extraAccountMetaListPDA] = PublicKey.findProgramAddressSync(
99+
const [extraAccountMetaListPDA] = anchor.web3.PublicKey.findProgramAddressSync(
106100
[Buffer.from("extra-account-metas"), mint.publicKey.toBuffer()],
107101
dummyTransferHook.programId
108102
);
109103

110-
const [counterPDA] = PublicKey.findProgramAddressSync(
104+
const [counterPDA] = anchor.web3.PublicKey.findProgramAddressSync(
111105
[Buffer.from("counter")],
112106
dummyTransferHook.programId
113107
);
@@ -135,6 +129,7 @@ describe("example-native-token-transfers", () => {
135129
let ntt: SolanaNtt<"Devnet", "Solana">;
136130
let signer: Signer;
137131
let sender: AccountAddress<"Solana">;
132+
let multisig: anchor.web3.PublicKey;
138133
let tokenAddress: string;
139134

140135
beforeAll(async () => {
@@ -150,8 +145,8 @@ describe("example-native-token-transfers", () => {
150145
mintLen
151146
);
152147

153-
const transaction = new Transaction().add(
154-
SystemProgram.createAccount({
148+
const transaction = new anchor.web3.Transaction().add(
149+
anchor.web3.SystemProgram.createAccount({
155150
fromPubkey: payer.publicKey,
156151
newAccountPubkey: mint.publicKey,
157152
space: mintLen,
@@ -178,9 +173,14 @@ describe("example-native-token-transfers", () => {
178173
transaction.feePayer = payer.publicKey;
179174
transaction.recentBlockhash = blockhash;
180175

181-
await sendAndConfirmTransaction(connection, transaction, [payer, mint], {
182-
commitment: "confirmed",
183-
});
176+
await anchor.web3.sendAndConfirmTransaction(
177+
connection,
178+
transaction,
179+
[payer, mint],
180+
{
181+
commitment: "confirmed",
182+
}
183+
);
184184

185185
tokenAccount = await spl.createAssociatedTokenAccount(
186186
connection,
@@ -231,13 +231,22 @@ describe("example-native-token-transfers", () => {
231231
describe("Burning", () => {
232232
beforeAll(async () => {
233233
try {
234+
multisig = await spl.createMultisig(
235+
connection,
236+
payer,
237+
[owner.publicKey, ntt.pdas.tokenAuthority()],
238+
1,
239+
anchor.web3.Keypair.generate(),
240+
undefined,
241+
TOKEN_PROGRAM
242+
);
234243
await spl.setAuthority(
235244
connection,
236245
payer,
237246
mint.publicKey,
238247
owner,
239248
spl.AuthorityType.MintTokens,
240-
ntt.pdas.tokenAuthority(),
249+
multisig,
241250
[],
242251
undefined,
243252
TOKEN_PROGRAM
@@ -248,6 +257,7 @@ describe("example-native-token-transfers", () => {
248257
mint: mint.publicKey,
249258
outboundLimit: 1000000n,
250259
mode: "burning",
260+
multisig,
251261
});
252262
await signSendWait(ctx, initTxs, signer);
253263

@@ -285,21 +295,26 @@ describe("example-native-token-transfers", () => {
285295
extraAccountMetaList: extraAccountMetaListPDA,
286296
tokenProgram: TOKEN_PROGRAM,
287297
associatedTokenProgram: spl.ASSOCIATED_TOKEN_PROGRAM_ID,
288-
systemProgram: SystemProgram.programId,
298+
systemProgram: anchor.web3.SystemProgram.programId,
289299
})
290300
.instruction();
291301

292-
const transaction = new Transaction().add(
302+
const transaction = new anchor.web3.Transaction().add(
293303
initializeExtraAccountMetaListInstruction
294304
);
295305
transaction.feePayer = payer.publicKey;
296306
const { blockhash } = await connection.getLatestBlockhash();
297307
transaction.recentBlockhash = blockhash;
298308

299309
transaction.sign(payer);
300-
await sendAndConfirmTransaction(connection, transaction, [payer], {
301-
commitment: "confirmed",
302-
});
310+
await anchor.web3.sendAndConfirmTransaction(
311+
connection,
312+
transaction,
313+
[payer],
314+
{
315+
commitment: "confirmed",
316+
}
317+
);
303318
});
304319

305320
test("Can send tokens", async () => {
@@ -391,7 +406,7 @@ describe("example-native-token-transfers", () => {
391406
const published = emitter.publishMessage(0, serialized, 200);
392407
const rawVaa = guardians.addSignatures(published, [0]);
393408
const vaa = deserialize("Ntt:WormholeTransfer", serialize(rawVaa));
394-
const redeemTxs = ntt.redeem([vaa], sender);
409+
const redeemTxs = ntt.redeem([vaa], sender, multisig);
395410
try {
396411
await signSendWait(ctx, redeemTxs, signer);
397412
} catch (e) {
@@ -401,6 +416,32 @@ describe("example-native-token-transfers", () => {
401416

402417
expect((await counterValue()).toString()).toEqual("2");
403418
});
419+
420+
it("Can mint independently", async () => {
421+
const dest = await spl.getOrCreateAssociatedTokenAccount(
422+
connection,
423+
payer,
424+
mint.publicKey,
425+
anchor.web3.Keypair.generate().publicKey,
426+
false,
427+
undefined,
428+
undefined,
429+
TOKEN_PROGRAM
430+
);
431+
await spl.mintTo(
432+
connection,
433+
payer,
434+
mint.publicKey,
435+
dest.address,
436+
multisig,
437+
1,
438+
[owner],
439+
undefined,
440+
TOKEN_PROGRAM
441+
);
442+
const balance = await connection.getTokenAccountBalance(dest.address);
443+
expect(balance.value.amount.toString()).toBe("1");
444+
});
404445
});
405446

406447
describe("Static Checks", () => {

0 commit comments

Comments
 (0)