Skip to content

Commit aec8d88

Browse files
[Wallet] Move 7702 batch transaction test to integration tests (#7166)
1 parent 80207ae commit aec8d88

File tree

2 files changed

+128
-132
lines changed

2 files changed

+128
-132
lines changed

packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.test.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 128 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,151 @@
11
import { describe, expect, it } from "vitest";
22
import { TEST_CLIENT } from "~test/test-clients.js";
3+
import { baseSepolia } from "../../../../chains/chain-definitions/base-sepolia.js";
34
import { sepolia } from "../../../../chains/chain-definitions/sepolia.js";
45
import { parseEventLogs } from "../../../../event/actions/parse-logs.js";
56
import { userOperationEventEvent } from "../../../../extensions/erc4337/__generated__/IEntryPoint/events/UserOperationEvent.js";
67
import { executedEvent } from "../../../../extensions/erc7702/__generated__/MinimalAccount/events/Executed.js";
78
import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js";
9+
import { sendBatchTransaction } from "../../../../transaction/actions/send-batch-transaction.js";
810
import { prepareTransaction } from "../../../../transaction/prepare-transaction.js";
11+
import { generateAccount } from "../../../utils/generateAccount.js";
912
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-
});
2413

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();
3429
});
35-
expect(message).toBeDefined();
36-
});
3730

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({
5534
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();
6542
});
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-
});
7343

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",
8149
sponsorGas: true,
8250
},
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);
8478
});
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);
89117
});
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",
93130
chain,
131+
});
132+
const tx1 = prepareTransaction({
94133
client: TEST_CLIENT,
95-
to: account.address,
134+
chain,
135+
to: (await generateAccount({ client: TEST_CLIENT })).address,
96136
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();
104149
});
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

Comments
 (0)