diff --git a/packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.test.ts b/packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.test.ts deleted file mode 100644 index 919b9887960..00000000000 --- a/packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { TEST_CLIENT } from "../../../../../test/src/test-clients.js"; -import { baseSepolia } from "../../../../chains/chain-definitions/base-sepolia.js"; -import { sendBatchTransaction } from "../../../../transaction/actions/send-batch-transaction.js"; -import { prepareTransaction } from "../../../../transaction/prepare-transaction.js"; -import { generateAccount } from "../../../utils/generateAccount.js"; -import { inAppWallet } from "../../web/in-app.js"; - -const client = TEST_CLIENT; -const chain = baseSepolia; - -describe.runIf(process.env.TW_SECRET_KEY)("7702 Minimal Account", () => { - it("should batch transactions", async () => { - const iaw = inAppWallet({ - executionMode: { - mode: "EIP7702", - sponsorGas: true, - }, - }); - const account = await iaw.connect({ - client, - strategy: "guest", - chain, - }); - const tx1 = prepareTransaction({ - client, - chain, - to: (await generateAccount({ client })).address, - value: 0n, - }); - const tx2 = prepareTransaction({ - client, - chain, - to: (await generateAccount({ client })).address, - value: 0n, - }); - const result = await sendBatchTransaction({ - account, - transactions: [tx1, tx2], - }); - expect(result.transactionHash).toBeDefined(); - }); -}); diff --git a/packages/thirdweb/src/wallets/in-app/web/lib/in-app-integration.test.ts b/packages/thirdweb/src/wallets/in-app/web/lib/in-app-integration.test.ts index 97fd4eea3f5..80da9fa4543 100644 --- a/packages/thirdweb/src/wallets/in-app/web/lib/in-app-integration.test.ts +++ b/packages/thirdweb/src/wallets/in-app/web/lib/in-app-integration.test.ts @@ -1,112 +1,151 @@ import { describe, expect, it } from "vitest"; import { TEST_CLIENT } from "~test/test-clients.js"; +import { baseSepolia } from "../../../../chains/chain-definitions/base-sepolia.js"; import { sepolia } from "../../../../chains/chain-definitions/sepolia.js"; import { parseEventLogs } from "../../../../event/actions/parse-logs.js"; import { userOperationEventEvent } from "../../../../extensions/erc4337/__generated__/IEntryPoint/events/UserOperationEvent.js"; import { executedEvent } from "../../../../extensions/erc7702/__generated__/MinimalAccount/events/Executed.js"; import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js"; +import { sendBatchTransaction } from "../../../../transaction/actions/send-batch-transaction.js"; import { prepareTransaction } from "../../../../transaction/prepare-transaction.js"; +import { generateAccount } from "../../../utils/generateAccount.js"; import { inAppWallet } from "../in-app.js"; -describe("InAppWallet Integration Tests", () => { - it("should sign a message with backend strategy", async () => { - const wallet = inAppWallet(); - const account = await wallet.connect({ - client: TEST_CLIENT, - strategy: "backend", - walletSecret: "test-secret", - }); - expect(account.address).toBeDefined(); - const message = await account.signMessage({ - message: "Hello, world!", - }); - expect(message).toBeDefined(); - }); - it("should sign a message with guest strategy", async () => { - const wallet = inAppWallet(); - const account = await wallet.connect({ - client: TEST_CLIENT, - strategy: "guest", - }); - expect(account.address).toBeDefined(); - const message = await account.signMessage({ - message: "Hello, world!", +describe.runIf(process.env.TW_SECRET_KEY)( + "InAppWallet Integration Tests", + () => { + it("should sign a message with backend strategy", async () => { + const wallet = inAppWallet(); + const account = await wallet.connect({ + client: TEST_CLIENT, + strategy: "backend", + walletSecret: "test-secret", + }); + expect(account.address).toBeDefined(); + const message = await account.signMessage({ + message: "Hello, world!", + }); + expect(message).toBeDefined(); }); - expect(message).toBeDefined(); - }); - it("should sponsor gas for a 7702 smart account", async () => { - const chain = sepolia; - const wallet = inAppWallet({ - executionMode: { - mode: "EIP7702", - sponsorGas: true, - }, - }); - const account = await wallet.connect({ - client: TEST_CLIENT, - strategy: "guest", - chain, - }); - expect(account.address).toBeDefined(); - const tx = await sendAndConfirmTransaction({ - transaction: prepareTransaction({ - chain, + it("should sign a message with guest strategy", async () => { + const wallet = inAppWallet(); + const account = await wallet.connect({ client: TEST_CLIENT, - to: account.address, - value: 0n, - }), - account, - }); - expect(tx.transactionHash).toBeDefined(); - const logs = parseEventLogs({ - logs: tx.logs, - events: [executedEvent()], + strategy: "guest", + }); + expect(account.address).toBeDefined(); + const message = await account.signMessage({ + message: "Hello, world!", + }); + expect(message).toBeDefined(); }); - const executedLog = logs[0]; - if (!executedLog) { - throw new Error("No executed log found"); - } - expect(executedLog.args.to).toBe(account.address); - expect(executedLog.args.value).toBe(0n); - }); - it("should sponsor gas for a 4337 smart account", async () => { - const chain = sepolia; - const wallet = inAppWallet({ - executionMode: { - mode: "EIP4337", - smartAccount: { - chain, + it("should sponsor gas for a 7702 smart account", async () => { + const chain = sepolia; + const wallet = inAppWallet({ + executionMode: { + mode: "EIP7702", sponsorGas: true, }, - }, + }); + const account = await wallet.connect({ + client: TEST_CLIENT, + strategy: "guest", + chain, + }); + expect(account.address).toBeDefined(); + const tx = await sendAndConfirmTransaction({ + transaction: prepareTransaction({ + chain, + client: TEST_CLIENT, + to: account.address, + value: 0n, + }), + account, + }); + expect(tx.transactionHash).toBeDefined(); + const logs = parseEventLogs({ + logs: tx.logs, + events: [executedEvent()], + }); + const executedLog = logs[0]; + if (!executedLog) { + throw new Error("No executed log found"); + } + expect(executedLog.args.to).toBe(account.address); + expect(executedLog.args.value).toBe(0n); }); - const account = await wallet.connect({ - client: TEST_CLIENT, - strategy: "guest", - chain, + + it("should sponsor gas for a 4337 smart account", async () => { + const chain = sepolia; + const wallet = inAppWallet({ + executionMode: { + mode: "EIP4337", + smartAccount: { + chain, + sponsorGas: true, + }, + }, + }); + const account = await wallet.connect({ + client: TEST_CLIENT, + strategy: "guest", + chain, + }); + expect(account.address).toBeDefined(); + const tx = await sendAndConfirmTransaction({ + transaction: prepareTransaction({ + chain, + client: TEST_CLIENT, + to: account.address, + value: 0n, + }), + account, + }); + expect(tx.transactionHash).toBeDefined(); + const logs = parseEventLogs({ + logs: tx.logs, + events: [userOperationEventEvent()], + }); + const executedLog = logs[0]; + if (!executedLog) { + throw new Error("No executed log found"); + } + expect(executedLog.args.sender).toBe(account.address); + expect(executedLog.args.success).toBe(true); }); - expect(account.address).toBeDefined(); - const tx = await sendAndConfirmTransaction({ - transaction: prepareTransaction({ + + it("should batch transaction for a 7702 account", async () => { + const chain = baseSepolia; + const iaw = inAppWallet({ + executionMode: { + mode: "EIP7702", + sponsorGas: true, + }, + }); + const account = await iaw.connect({ + client: TEST_CLIENT, + strategy: "guest", chain, + }); + const tx1 = prepareTransaction({ client: TEST_CLIENT, - to: account.address, + chain, + to: (await generateAccount({ client: TEST_CLIENT })).address, value: 0n, - }), - account, - }); - expect(tx.transactionHash).toBeDefined(); - const logs = parseEventLogs({ - logs: tx.logs, - events: [userOperationEventEvent()], + }); + const tx2 = prepareTransaction({ + client: TEST_CLIENT, + chain, + to: (await generateAccount({ client: TEST_CLIENT })).address, + value: 0n, + }); + const result = await sendBatchTransaction({ + account, + transactions: [tx1, tx2], + }); + expect(result.transactionHash).toBeDefined(); }); - const executedLog = logs[0]; - if (!executedLog) { - throw new Error("No executed log found"); - } - expect(executedLog.args.sender).toBe(account.address); - expect(executedLog.args.success).toBe(true); - }); -}); + }, +);