|
1 | 1 | import { describe, expect, it } from "vitest";
|
2 | 2 | import { TEST_CLIENT } from "~test/test-clients.js";
|
| 3 | +import { baseSepolia } from "../../../../chains/chain-definitions/base-sepolia.js"; |
3 | 4 | import { sepolia } from "../../../../chains/chain-definitions/sepolia.js";
|
4 | 5 | import { parseEventLogs } from "../../../../event/actions/parse-logs.js";
|
5 | 6 | import { userOperationEventEvent } from "../../../../extensions/erc4337/__generated__/IEntryPoint/events/UserOperationEvent.js";
|
6 | 7 | import { executedEvent } from "../../../../extensions/erc7702/__generated__/MinimalAccount/events/Executed.js";
|
7 | 8 | import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js";
|
| 9 | +import { sendBatchTransaction } from "../../../../transaction/actions/send-batch-transaction.js"; |
8 | 10 | import { prepareTransaction } from "../../../../transaction/prepare-transaction.js";
|
| 11 | +import { generateAccount } from "../../../utils/generateAccount.js"; |
9 | 12 | import { inAppWallet } from "../in-app.js";
|
10 |
| -describe("InAppWallet Integration Tests", () => { |
11 |
| - it("should sign a message with backend strategy", async () => { |
12 |
| - const wallet = inAppWallet(); |
13 |
| - const account = await wallet.connect({ |
14 |
| - client: TEST_CLIENT, |
15 |
| - strategy: "backend", |
16 |
| - walletSecret: "test-secret", |
17 |
| - }); |
18 |
| - expect(account.address).toBeDefined(); |
19 |
| - const message = await account.signMessage({ |
20 |
| - message: "Hello, world!", |
21 |
| - }); |
22 |
| - expect(message).toBeDefined(); |
23 |
| - }); |
24 | 13 |
|
25 |
| - it("should sign a message with guest strategy", async () => { |
26 |
| - const wallet = inAppWallet(); |
27 |
| - const account = await wallet.connect({ |
28 |
| - client: TEST_CLIENT, |
29 |
| - strategy: "guest", |
30 |
| - }); |
31 |
| - expect(account.address).toBeDefined(); |
32 |
| - const message = await account.signMessage({ |
33 |
| - message: "Hello, world!", |
| 14 | +describe.runIf(process.env.TW_SECRET_KEY)( |
| 15 | + "InAppWallet Integration Tests", |
| 16 | + () => { |
| 17 | + it("should sign a message with backend strategy", async () => { |
| 18 | + const wallet = inAppWallet(); |
| 19 | + const account = await wallet.connect({ |
| 20 | + client: TEST_CLIENT, |
| 21 | + strategy: "backend", |
| 22 | + walletSecret: "test-secret", |
| 23 | + }); |
| 24 | + expect(account.address).toBeDefined(); |
| 25 | + const message = await account.signMessage({ |
| 26 | + message: "Hello, world!", |
| 27 | + }); |
| 28 | + expect(message).toBeDefined(); |
34 | 29 | });
|
35 |
| - expect(message).toBeDefined(); |
36 |
| - }); |
37 | 30 |
|
38 |
| - it("should sponsor gas for a 7702 smart account", async () => { |
39 |
| - const chain = sepolia; |
40 |
| - const wallet = inAppWallet({ |
41 |
| - executionMode: { |
42 |
| - mode: "EIP7702", |
43 |
| - sponsorGas: true, |
44 |
| - }, |
45 |
| - }); |
46 |
| - const account = await wallet.connect({ |
47 |
| - client: TEST_CLIENT, |
48 |
| - strategy: "guest", |
49 |
| - chain, |
50 |
| - }); |
51 |
| - expect(account.address).toBeDefined(); |
52 |
| - const tx = await sendAndConfirmTransaction({ |
53 |
| - transaction: prepareTransaction({ |
54 |
| - chain, |
| 31 | + it("should sign a message with guest strategy", async () => { |
| 32 | + const wallet = inAppWallet(); |
| 33 | + const account = await wallet.connect({ |
55 | 34 | client: TEST_CLIENT,
|
56 |
| - to: account.address, |
57 |
| - value: 0n, |
58 |
| - }), |
59 |
| - account, |
60 |
| - }); |
61 |
| - expect(tx.transactionHash).toBeDefined(); |
62 |
| - const logs = parseEventLogs({ |
63 |
| - logs: tx.logs, |
64 |
| - events: [executedEvent()], |
| 35 | + strategy: "guest", |
| 36 | + }); |
| 37 | + expect(account.address).toBeDefined(); |
| 38 | + const message = await account.signMessage({ |
| 39 | + message: "Hello, world!", |
| 40 | + }); |
| 41 | + expect(message).toBeDefined(); |
65 | 42 | });
|
66 |
| - const executedLog = logs[0]; |
67 |
| - if (!executedLog) { |
68 |
| - throw new Error("No executed log found"); |
69 |
| - } |
70 |
| - expect(executedLog.args.to).toBe(account.address); |
71 |
| - expect(executedLog.args.value).toBe(0n); |
72 |
| - }); |
73 | 43 |
|
74 |
| - it("should sponsor gas for a 4337 smart account", async () => { |
75 |
| - const chain = sepolia; |
76 |
| - const wallet = inAppWallet({ |
77 |
| - executionMode: { |
78 |
| - mode: "EIP4337", |
79 |
| - smartAccount: { |
80 |
| - chain, |
| 44 | + it("should sponsor gas for a 7702 smart account", async () => { |
| 45 | + const chain = sepolia; |
| 46 | + const wallet = inAppWallet({ |
| 47 | + executionMode: { |
| 48 | + mode: "EIP7702", |
81 | 49 | sponsorGas: true,
|
82 | 50 | },
|
83 |
| - }, |
| 51 | + }); |
| 52 | + const account = await wallet.connect({ |
| 53 | + client: TEST_CLIENT, |
| 54 | + strategy: "guest", |
| 55 | + chain, |
| 56 | + }); |
| 57 | + expect(account.address).toBeDefined(); |
| 58 | + const tx = await sendAndConfirmTransaction({ |
| 59 | + transaction: prepareTransaction({ |
| 60 | + chain, |
| 61 | + client: TEST_CLIENT, |
| 62 | + to: account.address, |
| 63 | + value: 0n, |
| 64 | + }), |
| 65 | + account, |
| 66 | + }); |
| 67 | + expect(tx.transactionHash).toBeDefined(); |
| 68 | + const logs = parseEventLogs({ |
| 69 | + logs: tx.logs, |
| 70 | + events: [executedEvent()], |
| 71 | + }); |
| 72 | + const executedLog = logs[0]; |
| 73 | + if (!executedLog) { |
| 74 | + throw new Error("No executed log found"); |
| 75 | + } |
| 76 | + expect(executedLog.args.to).toBe(account.address); |
| 77 | + expect(executedLog.args.value).toBe(0n); |
84 | 78 | });
|
85 |
| - const account = await wallet.connect({ |
86 |
| - client: TEST_CLIENT, |
87 |
| - strategy: "guest", |
88 |
| - chain, |
| 79 | + |
| 80 | + it("should sponsor gas for a 4337 smart account", async () => { |
| 81 | + const chain = sepolia; |
| 82 | + const wallet = inAppWallet({ |
| 83 | + executionMode: { |
| 84 | + mode: "EIP4337", |
| 85 | + smartAccount: { |
| 86 | + chain, |
| 87 | + sponsorGas: true, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }); |
| 91 | + const account = await wallet.connect({ |
| 92 | + client: TEST_CLIENT, |
| 93 | + strategy: "guest", |
| 94 | + chain, |
| 95 | + }); |
| 96 | + expect(account.address).toBeDefined(); |
| 97 | + const tx = await sendAndConfirmTransaction({ |
| 98 | + transaction: prepareTransaction({ |
| 99 | + chain, |
| 100 | + client: TEST_CLIENT, |
| 101 | + to: account.address, |
| 102 | + value: 0n, |
| 103 | + }), |
| 104 | + account, |
| 105 | + }); |
| 106 | + expect(tx.transactionHash).toBeDefined(); |
| 107 | + const logs = parseEventLogs({ |
| 108 | + logs: tx.logs, |
| 109 | + events: [userOperationEventEvent()], |
| 110 | + }); |
| 111 | + const executedLog = logs[0]; |
| 112 | + if (!executedLog) { |
| 113 | + throw new Error("No executed log found"); |
| 114 | + } |
| 115 | + expect(executedLog.args.sender).toBe(account.address); |
| 116 | + expect(executedLog.args.success).toBe(true); |
89 | 117 | });
|
90 |
| - expect(account.address).toBeDefined(); |
91 |
| - const tx = await sendAndConfirmTransaction({ |
92 |
| - transaction: prepareTransaction({ |
| 118 | + |
| 119 | + it("should batch transaction for a 7702 account", async () => { |
| 120 | + const chain = baseSepolia; |
| 121 | + const iaw = inAppWallet({ |
| 122 | + executionMode: { |
| 123 | + mode: "EIP7702", |
| 124 | + sponsorGas: true, |
| 125 | + }, |
| 126 | + }); |
| 127 | + const account = await iaw.connect({ |
| 128 | + client: TEST_CLIENT, |
| 129 | + strategy: "guest", |
93 | 130 | chain,
|
| 131 | + }); |
| 132 | + const tx1 = prepareTransaction({ |
94 | 133 | client: TEST_CLIENT,
|
95 |
| - to: account.address, |
| 134 | + chain, |
| 135 | + to: (await generateAccount({ client: TEST_CLIENT })).address, |
96 | 136 | value: 0n,
|
97 |
| - }), |
98 |
| - account, |
99 |
| - }); |
100 |
| - expect(tx.transactionHash).toBeDefined(); |
101 |
| - const logs = parseEventLogs({ |
102 |
| - logs: tx.logs, |
103 |
| - events: [userOperationEventEvent()], |
| 137 | + }); |
| 138 | + const tx2 = prepareTransaction({ |
| 139 | + client: TEST_CLIENT, |
| 140 | + chain, |
| 141 | + to: (await generateAccount({ client: TEST_CLIENT })).address, |
| 142 | + value: 0n, |
| 143 | + }); |
| 144 | + const result = await sendBatchTransaction({ |
| 145 | + account, |
| 146 | + transactions: [tx1, tx2], |
| 147 | + }); |
| 148 | + expect(result.transactionHash).toBeDefined(); |
104 | 149 | });
|
105 |
| - const executedLog = logs[0]; |
106 |
| - if (!executedLog) { |
107 |
| - throw new Error("No executed log found"); |
108 |
| - } |
109 |
| - expect(executedLog.args.sender).toBe(account.address); |
110 |
| - expect(executedLog.args.success).toBe(true); |
111 |
| - }); |
112 |
| -}); |
| 150 | + }, |
| 151 | +); |
0 commit comments