diff --git a/tests/account/read.test.ts b/tests/account/read.test.ts index be9ba68a1..e2ca26ecf 100644 --- a/tests/account/read.test.ts +++ b/tests/account/read.test.ts @@ -816,8 +816,6 @@ describe("Account:Read", () => { bundlerUrl }) - console.log(smartAccountAddress, "smartAccountAdderss") - const balances = await smartAccount.getBalances() expect(balances[0].amount).toBeGreaterThan(0n) diff --git a/tests/account/write.test.ts b/tests/account/write.test.ts index c7c2a0dfb..8d18f2f35 100644 --- a/tests/account/write.test.ts +++ b/tests/account/write.test.ts @@ -8,36 +8,26 @@ import { parseAbi } from "viem" import { generatePrivateKey, privateKeyToAccount } from "viem/accounts" -import { readContract } from "viem/actions" import { polygonAmoy } from "viem/chains" import { beforeAll, describe, expect, test } from "vitest" import { type BiconomySmartAccountV2, DEFAULT_ENTRYPOINT_ADDRESS, ERC20_ABI, + type TransferOwnershipCompatibleModule, createSmartAccountClient, getCustomChain, percentage } from "../../src/account" import { ECDSAModuleAbi } from "../../src/account/abi/ECDSAModule" import { EntryPointAbi } from "../../src/account/abi/EntryPointAbi" -import { getAAError } from "../../src/bundler/utils/getAAError" -import { - DEFAULT_ECDSA_OWNERSHIP_MODULE, - DEFAULT_MULTICHAIN_MODULE, - createMultiChainValidationModule -} from "../../src/modules" +import { DEFAULT_ECDSA_OWNERSHIP_MODULE } from "../../src/modules" import { PaymasterMode } from "../../src/paymaster" import { testOnlyOnOptimism } from "../setupFiles" -import { - checkBalance, - getBundlerUrl, - getConfig, - nonZeroBalance, - topUp -} from "../utils" - -describe("Account:Write", () => { +import { checkBalance, getConfig, nonZeroBalance, topUp } from "../utils" + +describe("Account:Write", async () => { + const nonceOptions = { nonceKey: Date.now() + 10 } const nftAddress = "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e" const token = "0x747A4168DB14F57871fa8cda8B5455D8C2a8e90a" const { @@ -72,6 +62,16 @@ describe("Account:Write", () => { }) ] + const firstOwner = account.address + const newOwner = accountTwo.address + + let _smartAccount = await createSmartAccountClient({ + signer: walletClient, + paymasterUrl, + bundlerUrl + // accountAddress: "0xe6dBb5C8696d2E0f90B875cbb6ef26E3bBa575AC" + }) + beforeAll(async () => { ;[smartAccount, smartAccountTwo] = await Promise.all( [walletClient, walletClientTwo].map((client) => @@ -203,10 +203,13 @@ describe("Account:Write", () => { ) expect(walletClientWithCustomChain.chain).toEqual(customChain) - const { wait } = await smartAccountCustomChain.sendTransaction({ - to: recipient, - value: BigInt(1) - }) + const { wait } = await smartAccountCustomChain.sendTransaction( + { + to: recipient, + value: BigInt(1) + }, + { nonceOptions } + ) const { success, receipt } = await wait() @@ -226,9 +229,7 @@ describe("Account:Write", () => { to: recipient, value: BigInt(1) }, - { - simulationType: "validation_and_execution" - } + { nonceOptions, simulationType: "validation_and_execution" } ) const result = await wait() @@ -262,6 +263,7 @@ describe("Account:Write", () => { [{ address: token, amount: BigInt(1), recipient: sender }], undefined, { + nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED } @@ -301,6 +303,7 @@ describe("Account:Write", () => { const nativeBalanceBefore = await checkBalance(smartAccountAddress) const tokenBalanceBefore = await checkBalance(smartAccountAddress, token) const { wait } = await smartAccount.sendTransaction([transaction], { + nonceOptions, paymasterServiceData: { mode: PaymasterMode.ERC20, preferredToken: token @@ -351,6 +354,7 @@ describe("Account:Write", () => { const nativeBalanceBefore = await checkBalance(smartAccountAddress) const tokenBalanceBefore = await checkBalance(smartAccountAddress, token) const { wait } = await smartAccount.sendTransaction(transaction, { + nonceOptions, paymasterServiceData: { mode: PaymasterMode.ERC20, feeQuote: selectedFeeQuote, @@ -373,321 +377,248 @@ describe("Account:Write", () => { expect(newBalance - balance).toBe(1n) }, 60000) - describe("Account:User Op Gas Offset", () => { - test("should increment user op verificationGasLimit by 50%. Paymaster OFF", async () => { - const transaction = { - to: recipient, - data: "0x" + test("should increment user op verificationGasLimit by 50%. Paymaster OFF", async () => { + const transaction = { + to: recipient, + data: "0x" + } + + const userOpWithNoOffset = await smartAccount.buildUserOp([transaction]) + const userOpWithOffset = await smartAccount.buildUserOp([transaction], { + gasOffset: { + verificationGasLimitOffsetPct: 50 // 50% increase } + }) - const userOpWithNoOffset = await smartAccount.buildUserOp([transaction]) - const userOpWithOffset = await smartAccount.buildUserOp([transaction], { - gasOffset: { - verificationGasLimitOffsetPct: 50 // 50% increase - } - }) + const difference = Math.round( + Number(userOpWithOffset.verificationGasLimit) - + Number(userOpWithNoOffset.verificationGasLimit) + ) + const percentageValue = Math.round( + percentage(difference, Number(userOpWithNoOffset.verificationGasLimit)) + ) - const difference = Math.round( - Number(userOpWithOffset.verificationGasLimit) - - Number(userOpWithNoOffset.verificationGasLimit) - ) - const percentageValue = Math.round( - percentage(difference, Number(userOpWithNoOffset.verificationGasLimit)) - ) + expect(percentageValue).toBe(50) + }, 60000) - expect(percentageValue).toBe(50) - }, 60000) + test("should increment user op gas values. Paymaster OFF", async () => { + const transaction = { + to: recipient, + data: "0x" + } - test("should increment user op gas values. Paymaster OFF", async () => { - const transaction = { - to: recipient, - data: "0x" + const userOpWithNoOffset = await smartAccount.buildUserOp([transaction]) + const userOpWithOffset = await smartAccount.buildUserOp([transaction], { + gasOffset: { + verificationGasLimitOffsetPct: 50, // 50% increase + preVerificationGasOffsetPct: 100 // 100% increase } + }) - const userOpWithNoOffset = await smartAccount.buildUserOp([transaction]) - const userOpWithOffset = await smartAccount.buildUserOp([transaction], { - gasOffset: { - verificationGasLimitOffsetPct: 50, // 50% increase - preVerificationGasOffsetPct: 100 // 100% increase - } - }) + const vglDifference = Math.round( + Number(userOpWithOffset.verificationGasLimit) - + Number(userOpWithNoOffset.verificationGasLimit) + ) + const cgllDifference = Math.round( + Number(userOpWithOffset.callGasLimit) - + Number(userOpWithNoOffset.callGasLimit) + ) + const pvgDifference = Math.round( + Number(userOpWithOffset.preVerificationGas) - + Number(userOpWithNoOffset.preVerificationGas) + ) - const vglDifference = Math.round( - Number(userOpWithOffset.verificationGasLimit) - - Number(userOpWithNoOffset.verificationGasLimit) - ) - const cgllDifference = Math.round( - Number(userOpWithOffset.callGasLimit) - - Number(userOpWithNoOffset.callGasLimit) - ) - const pvgDifference = Math.round( - Number(userOpWithOffset.preVerificationGas) - - Number(userOpWithNoOffset.preVerificationGas) - ) + const vglPercentageValue = Math.round( + percentage(vglDifference, Number(userOpWithNoOffset.verificationGasLimit)) + ) + const cglPercentageValue = Math.round( + percentage(cgllDifference, Number(userOpWithNoOffset.callGasLimit)) + ) + const pvgPercentageValue = Math.round( + percentage(pvgDifference, Number(userOpWithNoOffset.preVerificationGas)) + ) - const vglPercentageValue = Math.round( - percentage( - vglDifference, - Number(userOpWithNoOffset.verificationGasLimit) - ) - ) - const cglPercentageValue = Math.round( - percentage(cgllDifference, Number(userOpWithNoOffset.callGasLimit)) - ) - const pvgPercentageValue = Math.round( - percentage(pvgDifference, Number(userOpWithNoOffset.preVerificationGas)) - ) + expect(vglPercentageValue).toBe(50) + expect(cglPercentageValue).toBe(0) + expect(pvgPercentageValue).toBe(100) + }, 60000) - expect(vglPercentageValue).toBe(50) - expect(cglPercentageValue).toBe(0) - expect(pvgPercentageValue).toBe(100) - }, 60000) + test("should increment user op gas values. Paymaster ON", async () => { + const transaction = { + to: recipient, + data: "0x" + } - test("should increment user op gas values. Paymaster ON", async () => { - const transaction = { - to: recipient, - data: "0x" + const userOpWithNoOffset = await smartAccount.buildUserOp([transaction], { + paymasterServiceData: { mode: PaymasterMode.SPONSORED }, + gasOffset: { + verificationGasLimitOffsetPct: 0 // no increment but provided to avoid paymaster gas calculation (just for testing purposes) + } + }) // Passing gasOffset to avoid paymaster gas calculation + const userOpWithOffset = await smartAccount.buildUserOp([transaction], { + paymasterServiceData: { mode: PaymasterMode.SPONSORED }, + gasOffset: { + verificationGasLimitOffsetPct: 13.2, // 13.2% increase + preVerificationGasOffsetPct: 81 // 81% increase } + }) - const userOpWithNoOffset = await smartAccount.buildUserOp([transaction], { - paymasterServiceData: { mode: PaymasterMode.SPONSORED }, - gasOffset: { - verificationGasLimitOffsetPct: 0 // no increment but provided to avoid paymaster gas calculation (just for testing purposes) - } - }) // Passing gasOffset to avoid paymaster gas calculation - const userOpWithOffset = await smartAccount.buildUserOp([transaction], { - paymasterServiceData: { mode: PaymasterMode.SPONSORED }, - gasOffset: { - verificationGasLimitOffsetPct: 13.2, // 13.2% increase - preVerificationGasOffsetPct: 81 // 81% increase - } - }) + const vglDifference = Math.round( + Number(userOpWithOffset.verificationGasLimit) - + Number(userOpWithNoOffset.verificationGasLimit) + ) + const cgllDifference = Math.round( + Number(userOpWithOffset.callGasLimit) - + Number(userOpWithNoOffset.callGasLimit) + ) + const pvgDifference = Math.round( + Number(userOpWithOffset.preVerificationGas) - + Number(userOpWithNoOffset.preVerificationGas) + ) - const vglDifference = Math.round( - Number(userOpWithOffset.verificationGasLimit) - - Number(userOpWithNoOffset.verificationGasLimit) - ) - const cgllDifference = Math.round( - Number(userOpWithOffset.callGasLimit) - - Number(userOpWithNoOffset.callGasLimit) - ) - const pvgDifference = Math.round( - Number(userOpWithOffset.preVerificationGas) - - Number(userOpWithNoOffset.preVerificationGas) - ) + const vglPercentageValue = Math.round( + percentage(vglDifference, Number(userOpWithNoOffset.verificationGasLimit)) + ) + const cglPercentageValue = Math.round( + percentage(cgllDifference, Number(userOpWithNoOffset.callGasLimit)) + ) + const pvgPercentageValue = Math.round( + percentage(pvgDifference, Number(userOpWithNoOffset.preVerificationGas)) + ) - const vglPercentageValue = Math.round( - percentage( - vglDifference, - Number(userOpWithNoOffset.verificationGasLimit) - ) - ) - const cglPercentageValue = Math.round( - percentage(cgllDifference, Number(userOpWithNoOffset.callGasLimit)) - ) - const pvgPercentageValue = Math.round( - percentage(pvgDifference, Number(userOpWithNoOffset.preVerificationGas)) - ) + expect(vglPercentageValue).toBe(13) + expect(cglPercentageValue).toBe(0) + expect(pvgPercentageValue).toBe(81) + }, 60000) - expect(vglPercentageValue).toBe(13) - expect(cglPercentageValue).toBe(0) - expect(pvgPercentageValue).toBe(81) - }, 60000) + test("should throw if percentage given is bigger than 100. Paymaster ON", async () => { + const transaction = { + to: recipient, + data: "0x" + } - test("should throw if percentage given is bigger than 100. Paymaster ON", async () => { - const transaction = { - to: recipient, - data: "0x" + const userOpWithNoOffset = await smartAccount.buildUserOp([transaction], { + paymasterServiceData: { mode: PaymasterMode.SPONSORED }, + gasOffset: { + verificationGasLimitOffsetPct: 0 // no increment, just for testing purposes } + }) // Passing gasOffset to avoid paymaster gas calculation + const userOpWithOffset = smartAccount.buildUserOp([transaction], { + paymasterServiceData: { mode: PaymasterMode.SPONSORED }, + gasOffset: { + verificationGasLimitOffsetPct: 110 // 110% increase (not allowed) + } + }) - const userOpWithNoOffset = await smartAccount.buildUserOp([transaction], { - paymasterServiceData: { mode: PaymasterMode.SPONSORED }, - gasOffset: { - verificationGasLimitOffsetPct: 0 // no increment, just for testing purposes - } - }) // Passing gasOffset to avoid paymaster gas calculation - const userOpWithOffset = smartAccount.buildUserOp([transaction], { - paymasterServiceData: { mode: PaymasterMode.SPONSORED }, - gasOffset: { - verificationGasLimitOffsetPct: 110 // 110% increase (not allowed) - } - }) + expect(userOpWithOffset).rejects.toThrowError( + "The percentage value should be between 1 and 100." + ) + }, 60000) - expect(userOpWithOffset).rejects.toThrowError( - "The percentage value should be between 1 and 100." - ) - }, 60000) + test("should increment user op gas with no paymaster using sendTransaction", async () => { + const encodedCall = encodeFunctionData({ + abi: parseAbi(["function safeMint(address _to)"]), + functionName: "safeMint", + args: [recipient] + }) + const transaction = { + to: nftAddress, // NFT address + data: encodedCall + } - test("should increment user op gas with no paymaster using sendTransaction", async () => { - const encodedCall = encodeFunctionData({ - abi: parseAbi(["function safeMint(address _to)"]), - functionName: "safeMint", - args: [recipient] - }) - const transaction = { - to: nftAddress, // NFT address - data: encodedCall + const { wait } = await smartAccount.sendTransaction(transaction, { + nonceOptions, + gasOffset: { + verificationGasLimitOffsetPct: 10, // 10% increase + preVerificationGasOffsetPct: 20, // 20% increase + maxFeePerGasOffsetPct: 30, // 30% increase + callGasLimitOffsetPct: 40, // 40% increase + maxPriorityFeePerGasOffsetPct: 50 // 50% increase } + }) + const { + receipt: { transactionHash }, + userOpHash, + success + } = await wait() - const { wait } = await smartAccount.sendTransaction(transaction, { - gasOffset: { - verificationGasLimitOffsetPct: 10, // 10% increase - preVerificationGasOffsetPct: 20, // 20% increase - maxFeePerGasOffsetPct: 30, // 30% increase - callGasLimitOffsetPct: 40, // 40% increase - maxPriorityFeePerGasOffsetPct: 50 // 50% increase - } - }) - const { - receipt: { transactionHash }, - userOpHash, - success - } = await wait() + expect(userOpHash).toBeTruthy() + expect(success).toBe("true") + }, 60000) - expect(userOpHash).toBeTruthy() - expect(success).toBe("true") - expect(transactionHash).toBeTruthy() - }, 60000) - }) + test.skip("should transfer ownership of smart account to accountTwo", async () => { + const signerOfAccount = walletClient.account.address + const ownerOfAccount = await publicClient.readContract({ + address: DEFAULT_ECDSA_OWNERSHIP_MODULE, + abi: ECDSAModuleAbi, + functionName: "getOwner", + args: [await _smartAccount.getAccountAddress()] + }) - describe("Transfer ownership", async () => { - const firstOwner = account.address - const newOwner = accountTwo.address - let _smartAccount = await createSmartAccountClient({ + expect(ownerOfAccount).toBe(signerOfAccount) + const response = await _smartAccount.transferOwnership( + newOwner, + DEFAULT_ECDSA_OWNERSHIP_MODULE as TransferOwnershipCompatibleModule, + { + paymasterServiceData: { mode: PaymasterMode.SPONSORED } + } + ) + const receipt = await response.wait() + expect(receipt.success).toBe("true") + }, 50000) + + test.skip("should revert transfer ownership with signer that is not the owner", async () => { + _smartAccount = await createSmartAccountClient({ signer: walletClient, paymasterUrl, - bundlerUrl - // accountAddress: "0xe6dBb5C8696d2E0f90B875cbb6ef26E3bBa575AC" + bundlerUrl, + accountAddress: smartAccountAddress }) - const smartAccountAddress = await _smartAccount.getAccountAddress() - - test("should transfer ownership of smart account to accountTwo", async () => { - const signerOfAccount = walletClient.account.address - const ownerOfAccount = await publicClient.readContract({ - address: DEFAULT_ECDSA_OWNERSHIP_MODULE, - abi: ECDSAModuleAbi, - functionName: "getOwner", - args: [await _smartAccount.getAccountAddress()] - }) + const signerOfAccount = walletClient.account.address + const ownerOfAccount = await publicClient.readContract({ + address: DEFAULT_ECDSA_OWNERSHIP_MODULE, + abi: ECDSAModuleAbi, + functionName: "getOwner", + args: [await _smartAccount.getAccountAddress()] + }) - expect(ownerOfAccount).toBe(signerOfAccount) - const response = await _smartAccount.transferOwnership( + expect(ownerOfAccount).not.toBe(signerOfAccount) + expect( + _smartAccount.transferOwnership( newOwner, - DEFAULT_ECDSA_OWNERSHIP_MODULE, + DEFAULT_ECDSA_OWNERSHIP_MODULE as TransferOwnershipCompatibleModule, { paymasterServiceData: { mode: PaymasterMode.SPONSORED } } ) - const receipt = await response.wait() - expect(receipt.success).toBe("true") - }, 50000) - - test("should revert transfer ownership with signer that is not the owner", async () => { - _smartAccount = await createSmartAccountClient({ - signer: walletClient, - paymasterUrl, - bundlerUrl, - accountAddress: smartAccountAddress - }) - - const signerOfAccount = walletClient.account.address - const ownerOfAccount = await publicClient.readContract({ - address: DEFAULT_ECDSA_OWNERSHIP_MODULE, - abi: ECDSAModuleAbi, - functionName: "getOwner", - args: [await _smartAccount.getAccountAddress()] - }) - - expect(ownerOfAccount).not.toBe(signerOfAccount) - expect( - _smartAccount.transferOwnership( - newOwner, - DEFAULT_ECDSA_OWNERSHIP_MODULE, - { - paymasterServiceData: { mode: PaymasterMode.SPONSORED } - } - ) - ).rejects.toThrowError() - }, 50000) - - test("send an user op with the new owner", async () => { - _smartAccount = await createSmartAccountClient({ - signer: walletClientTwo, - paymasterUrl, - bundlerUrl, - accountAddress: smartAccountAddress - }) - const currentSmartAccountInstanceSigner = await _smartAccount - .getSigner() - .getAddress() - expect(currentSmartAccountInstanceSigner).toBe(newOwner) - const tx = { - to: nftAddress, - data: encodeFunctionData({ - abi: parseAbi(["function safeMint(address _to)"]), - functionName: "safeMint", - args: [smartAccountAddressTwo] - }) - } - const { wait } = await _smartAccount.sendTransaction(tx, { - paymasterServiceData: { mode: PaymasterMode.SPONSORED } - }) - const response = await wait() - expect(response.success).toBe("true") - }, 50000) - - test("should revert if sending an user op with the old owner", async () => { - _smartAccount = await createSmartAccountClient({ - signer: walletClient, - paymasterUrl, - bundlerUrl, - accountAddress: smartAccountAddress - }) - const tx = { - to: nftAddress, - data: encodeFunctionData({ - abi: parseAbi(["function safeMint(address _to)"]), - functionName: "safeMint", - args: [smartAccountAddressTwo] - }) - } - await expect( - _smartAccount.sendTransaction(tx, { - paymasterServiceData: { mode: PaymasterMode.SPONSORED } - }) - ).rejects.toThrowError( - await getAAError("Error coming from Bundler: AA24 signature error") - ) - }, 50000) - - test("should transfer ownership of smart account back to EOA 1", async () => { - _smartAccount = await createSmartAccountClient({ - signer: walletClientTwo, - paymasterUrl, - bundlerUrl, - accountAddress: smartAccountAddress - }) + ).rejects.toThrowError() + }, 50000) - const signerOfAccount = walletClientTwo.account.address - const ownerOfAccount = await publicClient.readContract({ - address: DEFAULT_ECDSA_OWNERSHIP_MODULE, - abi: ECDSAModuleAbi, - functionName: "getOwner", - args: [await _smartAccount.getAccountAddress()] + test.skip("send an user op with the new owner", async () => { + _smartAccount = await createSmartAccountClient({ + signer: walletClientTwo, + paymasterUrl, + bundlerUrl, + accountAddress: smartAccountAddress + }) + const currentSmartAccountInstanceSigner = await _smartAccount + .getSigner() + .getAddress() + expect(currentSmartAccountInstanceSigner).toBe(newOwner) + const tx = { + to: nftAddress, + data: encodeFunctionData({ + abi: parseAbi(["function safeMint(address _to)"]), + functionName: "safeMint", + args: [smartAccountAddressTwo] }) - - expect(ownerOfAccount).toBe(signerOfAccount) - - const response = await _smartAccount.transferOwnership( - firstOwner, - DEFAULT_ECDSA_OWNERSHIP_MODULE, - { - paymasterServiceData: { mode: PaymasterMode.SPONSORED } - } - ) - const receipt = await response.wait() - expect(receipt.success).toBe("true") - }, 50000) - }) + } + const { wait } = await _smartAccount.sendTransaction(tx, { + nonceOptions, + paymasterServiceData: { mode: PaymasterMode.SPONSORED } + }) + const response = await wait() + expect(response.success).toBe("true") + }, 50000) }) diff --git a/tests/bundler/write.test.ts b/tests/bundler/write.test.ts index 5fd3b3d9d..2527e33fb 100644 --- a/tests/bundler/write.test.ts +++ b/tests/bundler/write.test.ts @@ -16,6 +16,7 @@ import { } from "../utils" describe("Bundler:Write", () => { + const nonceOptions = { nonceKey: Date.now() + 20 } const nftAddress = "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e" const { chain, @@ -70,15 +71,18 @@ describe("Bundler:Write", () => { await topUp(smartAccountAddress, BigInt(1000000000000000000)) const balanceOfRecipient = await checkBalance(recipient) - const { wait } = await smartAccount.sendTransaction({ - to: recipient, - value: 1n - }) + const { wait } = await smartAccount.sendTransaction( + { + to: recipient, + value: 1n + }, + { nonceOptions } + ) const { receipt: { transactionHash }, success - } = await wait(3) + } = await wait() expect(success).toBe("true") @@ -106,15 +110,18 @@ describe("Bundler:Write", () => { }) const { wait } = - await smartAccountClientWithBundlerInstance.sendTransaction({ - to: recipient, - value: 1 - }) + await smartAccountClientWithBundlerInstance.sendTransaction( + { + to: recipient, + value: 1 + }, + { nonceOptions } + ) const { receipt: { transactionHash }, success - } = await wait(3) + } = await wait() expect(success).toBe("true") @@ -147,10 +154,13 @@ describe("Bundler:Write", () => { expect(chain.id).toBe(NETWORK_ID) - const { wait } = await newSmartAccount.sendTransaction({ - to: recipient, - value: 1n - }) + const { wait } = await newSmartAccount.sendTransaction( + { + to: recipient, + value: 1n + }, + { nonceOptions } + ) const { success } = await wait() diff --git a/tests/modules/write.test.ts b/tests/modules/write.test.ts index 22ad24ccb..2daad3f4f 100644 --- a/tests/modules/write.test.ts +++ b/tests/modules/write.test.ts @@ -56,6 +56,7 @@ import { PaymasterMode } from "../../src/paymaster" import { checkBalance, getBundlerUrl, getConfig, topUp } from "../utils" describe("Modules:Write", () => { + const nonceOptions = { nonceKey: Date.now() + 30 } const nftAddress = "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e" const token = "0x747A4168DB14F57871fa8cda8B5455D8C2a8e90a" const amount = parseUnits(".0001", 6) @@ -228,7 +229,7 @@ describe("Modules:Write", () => { const { wait } = await smartAccountThreeWithSession.sendTransaction( nftMintTx, - withSponsorship + { ...withSponsorship, nonceOptions } ) const { success } = await wait() @@ -362,7 +363,8 @@ describe("Modules:Write", () => { const { wait } = await smartAccountFourWithSession.sendTransaction(txs, { ...batchSessionParams, - ...withSponsorship + ...withSponsorship, + nonceOptions }) const { success } = await wait() expect(success).toBe("true") @@ -595,6 +597,7 @@ describe("Modules:Write", () => { txArray.push(setSessionAllowedTrx) } const userOp = await smartAccount.buildUserOp(txArray, { + nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED } @@ -615,6 +618,7 @@ describe("Modules:Write", () => { smartAccount = smartAccount.setActiveValidationModule(sessionModule) const maticBalanceBefore = await checkBalance(smartAccountAddress) const userOpResponse2 = await smartAccount.sendTransaction(nftMintTx, { + nonceOptions, params: { sessionSigner: sessionSigner, sessionValidationModule: abiSvmAddress @@ -645,6 +649,7 @@ describe("Modules:Write", () => { DEFAULT_BATCHED_SESSION_ROUTER_MODULE ) const { wait } = await smartAccount.sendTransaction(tx, { + nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED } }) const { success } = await wait() @@ -652,7 +657,7 @@ describe("Modules:Write", () => { } }, 50000) - test("should use ABI SVM to allow transfer ownership of smart account", async () => { + test.skip("should use ABI SVM to allow transfer ownership of smart account", async () => { const smartAccount = await createSmartAccountClient({ chainId, signer: walletClient, @@ -786,6 +791,7 @@ describe("Modules:Write", () => { txArray.push(setSessionAllowedTransferOwnerhsipTrx) } const userOpResponse1 = await smartAccount.sendTransaction(txArray, { + nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED } }) const transactionDetails = await userOpResponse1.wait() @@ -920,7 +926,8 @@ describe("Modules:Write", () => { txs, { ...batchSessionParams, - ...withSponsorship + ...withSponsorship, + nonceOptions } ) @@ -1037,11 +1044,13 @@ describe("Modules:Write", () => { const { wait: waitForCancelTx } = await smartAccountWithSession.sendTransaction(submitCancelTx, { + nonceOptions, ...singleSessionParamsForCancel, ...withSponsorship }) const { wait: waitForOrderTx } = await smartAccountWithSession.sendTransaction(submitOrderTx, { + nonceOptions, ...singleSessionParamsForOrder, ...withSponsorship }) diff --git a/tests/paymaster/write.test.ts b/tests/paymaster/write.test.ts index cb1170318..fa63a82e9 100644 --- a/tests/paymaster/write.test.ts +++ b/tests/paymaster/write.test.ts @@ -18,6 +18,7 @@ import { testOnlyOnOptimism } from "../setupFiles" import { checkBalance, getConfig, nonZeroBalance, topUp } from "../utils" describe("Paymaster:Write", () => { + const nonceOptions = { nonceKey: Date.now() + 40 } const nftAddress = "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e" const { chain, @@ -87,8 +88,8 @@ describe("Paymaster:Write", () => { const maticBalanceBefore = await checkBalance(smartAccountAddress) const response = await smartAccount.sendTransaction(transaction, { - paymasterServiceData: { mode: PaymasterMode.SPONSORED }, - simulationType: "validation" + nonceOptions, + paymasterServiceData: { mode: PaymasterMode.SPONSORED } }) const userOpReceipt = await response.wait(3) @@ -127,6 +128,7 @@ describe("Paymaster:Write", () => { expect(balance).toBe(0n) const { wait } = await smartAccount.deploy({ + nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED } }) const { success } = await wait() @@ -153,9 +155,7 @@ describe("Paymaster:Write", () => { } ], null, - { - paymasterServiceData: { mode: PaymasterMode.SPONSORED } - } + { nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED } } ) const { @@ -194,6 +194,7 @@ describe("Paymaster:Write", () => { const maticBalanceBefore = await checkBalance(smartAccountAddress) const response = await smartAccount.sendTransaction(transaction, { + nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED }, simulationType: "validation_and_execution" }) @@ -231,9 +232,7 @@ describe("Paymaster:Write", () => { { address: NATIVE_TOKEN_ALIAS, amount: BigInt(1) } ], sender, - { - paymasterServiceData: { mode: PaymasterMode.SPONSORED } - } + { nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED } } ) const { @@ -269,6 +268,7 @@ describe("Paymaster:Write", () => { [] /* null or undefined or [] */, sender, { + nonceOptions, paymasterServiceData: { mode: PaymasterMode.SPONSORED } // Will leave no dust } )