From 4e2d12af11d66e77ff903c0e69f8663fd67c7855 Mon Sep 17 00:00:00 2001 From: chrismaree Date: Thu, 31 Oct 2024 12:16:27 +0100 Subject: [PATCH 1/2] WIP Signed-off-by: chrismaree --- test/svm/SvmSpoke.Fill.ts | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/svm/SvmSpoke.Fill.ts b/test/svm/SvmSpoke.Fill.ts index 1ac426ef0..dbcfff196 100644 --- a/test/svm/SvmSpoke.Fill.ts +++ b/test/svm/SvmSpoke.Fill.ts @@ -533,4 +533,54 @@ describe("svm_spoke.fill", () => { assertSE(recipientBal, BigInt(relayAmount), "Recipient's balance should be increased by the relay amount"); }); }); + it("Fills a deposit for a recipient without an existing ATA", async () => { + // Generate a new recipient account + const newRecipient = Keypair.generate().publicKey; + const newRecipientATA = getAssociatedTokenAddressSync(mint, newRecipient); + + // Attempt to fill a deposit, expecting failure due to missing ATA + const newRelayData = { + ...relayData, + recipient: newRecipient, + depositId: new BN(Math.floor(Math.random() * 1000000)), + }; + updateRelayData(newRelayData); + accounts.recipientTokenAccount = newRecipientATA; + const relayHash = Array.from(calculateRelayHashUint8Array(newRelayData, chainId)); + + try { + await program.methods + .fillV3Relay(relayHash, newRelayData, new BN(1), relayer.publicKey) + .accounts(accounts) + .signers([relayer]) + .rpc(); + assert.fail("Fill should have failed due to missing ATA"); + } catch (err: any) { + assert.include(err.toString(), "AccountNotInitialized", "Expected AccountNotInitialized error"); + } + + // Create the ATA using the create_token_accounts method + const createTokenAccountsInstruction = await program.methods + .createTokenAccounts() + .accounts({ signer: relayer.publicKey, mint, tokenProgram: TOKEN_PROGRAM_ID }) + .remainingAccounts([ + { pubkey: newRecipient, isWritable: false, isSigner: false }, + { pubkey: newRecipientATA, isWritable: true, isSigner: false }, + ]) + .instruction(); + + // Fill the deposit in the same transaction + const fillInstruction = await program.methods + .fillV3Relay(relayHash, newRelayData, new BN(1), relayer.publicKey) + .accounts(accounts) + .instruction(); + + // Create and send the transaction + const transaction = new web3.Transaction().add(createTokenAccountsInstruction, fillInstruction); + await web3.sendAndConfirmTransaction(connection, transaction, [relayer]); + + // Verify the recipient's balance after the fill + const recipientAccount = await getAccount(connection, newRecipientATA); + assertSE(recipientAccount.amount, relayAmount, "Recipient's balance should be increased by the relay amount"); + }); }); From 8076d3c10568046e23fe7c8df5c08e1fa11d2a21 Mon Sep 17 00:00:00 2001 From: chrismaree Date: Thu, 31 Oct 2024 12:18:20 +0100 Subject: [PATCH 2/2] WIP Signed-off-by: chrismaree --- test/svm/SvmSpoke.Fill.ts | 99 +++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/test/svm/SvmSpoke.Fill.ts b/test/svm/SvmSpoke.Fill.ts index dbcfff196..5c3e6a642 100644 --- a/test/svm/SvmSpoke.Fill.ts +++ b/test/svm/SvmSpoke.Fill.ts @@ -433,7 +433,56 @@ describe("svm_spoke.fill", () => { "Recipient's balance should be increased by the relay amount" ); }); + it("Fills a deposit for a recipient without an existing ATA", async () => { + // Generate a new recipient account + const newRecipient = Keypair.generate().publicKey; + const newRecipientATA = getAssociatedTokenAddressSync(mint, newRecipient); + + // Attempt to fill a deposit, expecting failure due to missing ATA + const newRelayData = { + ...relayData, + recipient: newRecipient, + depositId: new BN(Math.floor(Math.random() * 1000000)), + }; + updateRelayData(newRelayData); + accounts.recipientTokenAccount = newRecipientATA; + const relayHash = Array.from(calculateRelayHashUint8Array(newRelayData, chainId)); + + try { + await program.methods + .fillV3Relay(relayHash, newRelayData, new BN(1), relayer.publicKey) + .accounts(accounts) + .signers([relayer]) + .rpc(); + assert.fail("Fill should have failed due to missing ATA"); + } catch (err: any) { + assert.include(err.toString(), "AccountNotInitialized", "Expected AccountNotInitialized error"); + } + // Create the ATA using the create_token_accounts method + const createTokenAccountsInstruction = await program.methods + .createTokenAccounts() + .accounts({ signer: relayer.publicKey, mint, tokenProgram: TOKEN_PROGRAM_ID }) + .remainingAccounts([ + { pubkey: newRecipient, isWritable: false, isSigner: false }, + { pubkey: newRecipientATA, isWritable: true, isSigner: false }, + ]) + .instruction(); + + // Fill the deposit in the same transaction + const fillInstruction = await program.methods + .fillV3Relay(relayHash, newRelayData, new BN(1), relayer.publicKey) + .accounts(accounts) + .instruction(); + + // Create and send the transaction + const transaction = new web3.Transaction().add(createTokenAccountsInstruction, fillInstruction); + await web3.sendAndConfirmTransaction(connection, transaction, [relayer]); + + // Verify the recipient's balance after the fill + const recipientAccount = await getAccount(connection, newRecipientATA); + assertSE(recipientAccount.amount, relayAmount, "Recipient's balance should be increased by the relay amount"); + }); it("Max fills in one transaction with account creation", async () => { // Save relayer balance before the the fills const iRelayerBal = (await getAccount(connection, relayerTA)).amount; @@ -533,54 +582,4 @@ describe("svm_spoke.fill", () => { assertSE(recipientBal, BigInt(relayAmount), "Recipient's balance should be increased by the relay amount"); }); }); - it("Fills a deposit for a recipient without an existing ATA", async () => { - // Generate a new recipient account - const newRecipient = Keypair.generate().publicKey; - const newRecipientATA = getAssociatedTokenAddressSync(mint, newRecipient); - - // Attempt to fill a deposit, expecting failure due to missing ATA - const newRelayData = { - ...relayData, - recipient: newRecipient, - depositId: new BN(Math.floor(Math.random() * 1000000)), - }; - updateRelayData(newRelayData); - accounts.recipientTokenAccount = newRecipientATA; - const relayHash = Array.from(calculateRelayHashUint8Array(newRelayData, chainId)); - - try { - await program.methods - .fillV3Relay(relayHash, newRelayData, new BN(1), relayer.publicKey) - .accounts(accounts) - .signers([relayer]) - .rpc(); - assert.fail("Fill should have failed due to missing ATA"); - } catch (err: any) { - assert.include(err.toString(), "AccountNotInitialized", "Expected AccountNotInitialized error"); - } - - // Create the ATA using the create_token_accounts method - const createTokenAccountsInstruction = await program.methods - .createTokenAccounts() - .accounts({ signer: relayer.publicKey, mint, tokenProgram: TOKEN_PROGRAM_ID }) - .remainingAccounts([ - { pubkey: newRecipient, isWritable: false, isSigner: false }, - { pubkey: newRecipientATA, isWritable: true, isSigner: false }, - ]) - .instruction(); - - // Fill the deposit in the same transaction - const fillInstruction = await program.methods - .fillV3Relay(relayHash, newRelayData, new BN(1), relayer.publicKey) - .accounts(accounts) - .instruction(); - - // Create and send the transaction - const transaction = new web3.Transaction().add(createTokenAccountsInstruction, fillInstruction); - await web3.sendAndConfirmTransaction(connection, transaction, [relayer]); - - // Verify the recipient's balance after the fill - const recipientAccount = await getAccount(connection, newRecipientATA); - assertSE(recipientAccount.amount, relayAmount, "Recipient's balance should be increased by the relay amount"); - }); });