Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show that we can create ATA in same transaction as fill #711

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions test/svm/SvmSpoke.Fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading