Skip to content

Commit 210eac8

Browse files
committed
fix: fully switch over to v5 method
1 parent f40cbb1 commit 210eac8

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

packages/aa-infra/src/actions/requestGasAndPaymasterAndData.test.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
import { local060Instance, local070Instance } from "~test/instances.js";
2-
import { toLightAccount } from "@aa-sdk/smart-accounts";
2+
import { toLightAccount } from "@alchemy/smart-accounts";
33
import { requestGasAndPaymasterAndData } from "./requestGasAndPaymasterAndData.js";
44
import type { AlchemyTransport } from "@alchemy/common";
5-
import { http, zeroAddress, type Client } from "viem";
5+
import { createWalletClient, custom, zeroAddress, type Client } from "viem";
66
import {
77
entryPoint06Address,
88
entryPoint07Address,
99
} from "viem/account-abstraction";
10-
import { generatePrivateKey } from "viem/accounts";
11-
import { sepolia } from "viem/chains";
12-
import { LocalAccountSigner } from "@aa-sdk/core";
10+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
1311

14-
// todo(v5): migrate to using `@alchemy/smart-account` definitions of light account, rather than `@account-kit/smart-contracts`
1512
describe("requestGasAndPaymasterAndData tests", async () => {
1613
it("should be able to call requestGasAndPaymasterAndData with v0.6 user operation", async () => {
1714
const client = local060Instance.getClient();
15+
const signer = privateKeyToAccount(generatePrivateKey());
1816

1917
const smartAccount = await toLightAccount({
20-
chain: sepolia,
21-
transport: http(),
18+
client: createWalletClient({
19+
account: signer,
20+
transport: custom(client.transport),
21+
chain: client.chain,
22+
}),
2223
version: "v1.1.0",
23-
signer:
24-
LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()),
24+
owner: signer,
2525
});
2626

27+
const factoryArgs = await smartAccount.getFactoryArgs();
2728
const v06UserOperation = {
2829
sender: smartAccount.address,
2930
nonce: 0n,
30-
initCode: await smartAccount.getInitCode(),
31-
callData: await smartAccount.encodeBatchExecute([
31+
initCode:
32+
factoryArgs.factory && factoryArgs.factoryData
33+
? (`${factoryArgs.factory}${factoryArgs.factoryData.slice(2)}` as const)
34+
: ("0x" as const),
35+
callData: await smartAccount.encodeCalls([
3236
{
33-
target: zeroAddress,
37+
to: zeroAddress,
3438
data: "0x" as const,
3539
},
3640
]),
@@ -42,7 +46,7 @@ describe("requestGasAndPaymasterAndData tests", async () => {
4246
{
4347
policyId: "test-policy-id",
4448
entryPoint: entryPoint06Address,
45-
dummySignature: await smartAccount.getDummySignature(),
49+
dummySignature: await smartAccount.getStubSignature(),
4650
userOperation: v06UserOperation,
4751
},
4852
],
@@ -59,27 +63,31 @@ describe("requestGasAndPaymasterAndData tests", async () => {
5963

6064
it("should be able to call requestGasAndPaymasterAndData with v0.7 user operation", async () => {
6165
const client = local070Instance.getClient();
66+
const signer = privateKeyToAccount(generatePrivateKey());
6267

6368
const smartAccount = await toLightAccount({
64-
chain: sepolia,
65-
transport: http(),
69+
client: createWalletClient({
70+
account: signer,
71+
transport: custom(client.transport),
72+
chain: client.chain,
73+
}),
6674
version: "v2.0.0",
67-
signer:
68-
LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()),
75+
owner: signer,
6976
});
7077

78+
const factoryArgs = await smartAccount.getFactoryArgs();
7179
const v07UserOperation = {
7280
sender: smartAccount.address,
7381
nonce: 0n,
74-
factory: await smartAccount.getFactoryAddress(),
75-
factoryData: await smartAccount.getFactoryData(),
76-
callData: await smartAccount.encodeBatchExecute([
82+
factory: factoryArgs.factory,
83+
factoryData: factoryArgs.factoryData,
84+
callData: await smartAccount.encodeCalls([
7785
{
78-
target: zeroAddress,
86+
to: zeroAddress,
7987
data: "0x" as const,
8088
},
8189
]),
82-
signature: await smartAccount.getDummySignature(),
90+
signature: await smartAccount.getStubSignature(),
8391
};
8492

8593
const result = await requestGasAndPaymasterAndData(
@@ -88,7 +96,7 @@ describe("requestGasAndPaymasterAndData tests", async () => {
8896
{
8997
policyId: "test-policy-id",
9098
entryPoint: entryPoint07Address,
91-
dummySignature: await smartAccount.getDummySignature(),
99+
dummySignature: await smartAccount.getStubSignature(),
92100
userOperation: v07UserOperation,
93101
},
94102
],

0 commit comments

Comments
 (0)