From 9c81faa4ccda0de7ba623f86b0ddc0d76ffa326f Mon Sep 17 00:00:00 2001 From: 0xAnto Date: Sat, 21 Dec 2024 19:31:43 +0530 Subject: [PATCH] Fix: Add default FeePayer address for sponsored transactions in Script Composer --- src/api/transactionSubmission/build.ts | 4 +- .../transaction/transactionSubmission.test.ts | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/api/transactionSubmission/build.ts b/src/api/transactionSubmission/build.ts index 37ae6926c..ee35a0a6c 100644 --- a/src/api/transactionSubmission/build.ts +++ b/src/api/transactionSubmission/build.ts @@ -1,7 +1,7 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -import { AccountAddressInput } from "../../core"; +import { AccountAddress, AccountAddressInput } from "../../core"; import { generateTransaction } from "../../internal/transactionSubmission"; import { InputGenerateTransactionPayloadData, @@ -171,7 +171,7 @@ export class Build { payload: TransactionPayloadScript.load(new Deserializer(bytes)), ...args, }); - return new SimpleTransaction(rawTxn); + return new SimpleTransaction(rawTxn, args.withFeePayer === true ? AccountAddress.ZERO : undefined); } /** diff --git a/tests/e2e/transaction/transactionSubmission.test.ts b/tests/e2e/transaction/transactionSubmission.test.ts index 82cf4e2f6..fddf3e950 100644 --- a/tests/e2e/transaction/transactionSubmission.test.ts +++ b/tests/e2e/transaction/transactionSubmission.test.ts @@ -231,6 +231,48 @@ describe("transaction submission", () => { }); expect(response.signature?.type).toBe("fee_payer_signature"); }); + test("with batch payload", async () => { + const transaction = await aptos.transaction.build.scriptComposer({ + sender: singleSignerED25519SenderAccount.accountAddress, + builder: async (builder) => { + const coin = await builder.addBatchedCalls({ + function: "0x1::coin::withdraw", + functionArguments: [CallArgument.new_signer(0), 1], + typeArguments: ["0x1::aptos_coin::AptosCoin"], + }); + + const fungibleAsset = await builder.addBatchedCalls({ + function: "0x1::coin::coin_to_fungible_asset", + functionArguments: [coin[0]], + typeArguments: ["0x1::aptos_coin::AptosCoin"], + }); + + await builder.addBatchedCalls({ + function: "0x1::primary_fungible_store::deposit", + functionArguments: [singleSignerED25519SenderAccount.accountAddress, fungibleAsset[0]], + }); + return builder; + }, + withFeePayer: true, + }); + + const senderAuthenticator = aptos.transaction.sign({ signer: singleSignerED25519SenderAccount, transaction }); + const feePayerSignerAuthenticator = aptos.transaction.signAsFeePayer({ + signer: feePayerAccount, + transaction, + }); + + const response = await aptos.transaction.submit.simple({ + transaction, + senderAuthenticator, + feePayerAuthenticator: feePayerSignerAuthenticator, + }); + + await aptos.waitForTransaction({ + transactionHash: response.hash, + }); + expect(response.signature?.type).toBe("fee_payer_signature"); + }); test("with entry function payload", async () => { const transaction = await aptos.transaction.build.simple({ sender: singleSignerED25519SenderAccount.accountAddress,