Skip to content

[Wallet] Move 7702 batch transaction test to integration tests #7166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
});
});
},
);
Loading