1
1
import { local060Instance , local070Instance } from "~test/instances.js" ;
2
- import { toLightAccount } from "@aa-sdk /smart-accounts" ;
2
+ import { toLightAccount } from "@alchemy /smart-accounts" ;
3
3
import { requestGasAndPaymasterAndData } from "./requestGasAndPaymasterAndData.js" ;
4
4
import type { AlchemyTransport } from "@alchemy/common" ;
5
- import { http , zeroAddress , type Client } from "viem" ;
5
+ import { createWalletClient , custom , zeroAddress , type Client } from "viem" ;
6
6
import {
7
7
entryPoint06Address ,
8
8
entryPoint07Address ,
9
9
} 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" ;
13
11
14
- // todo(v5): migrate to using `@alchemy/smart-account` definitions of light account, rather than `@account-kit/smart-contracts`
15
12
describe ( "requestGasAndPaymasterAndData tests" , async ( ) => {
16
13
it ( "should be able to call requestGasAndPaymasterAndData with v0.6 user operation" , async ( ) => {
17
14
const client = local060Instance . getClient ( ) ;
15
+ const signer = privateKeyToAccount ( generatePrivateKey ( ) ) ;
18
16
19
17
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
+ } ) ,
22
23
version : "v1.1.0" ,
23
- signer :
24
- LocalAccountSigner . privateKeyToAccountSigner ( generatePrivateKey ( ) ) ,
24
+ owner : signer ,
25
25
} ) ;
26
26
27
+ const factoryArgs = await smartAccount . getFactoryArgs ( ) ;
27
28
const v06UserOperation = {
28
29
sender : smartAccount . address ,
29
30
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 ( [
32
36
{
33
- target : zeroAddress ,
37
+ to : zeroAddress ,
34
38
data : "0x" as const ,
35
39
} ,
36
40
] ) ,
@@ -42,7 +46,7 @@ describe("requestGasAndPaymasterAndData tests", async () => {
42
46
{
43
47
policyId : "test-policy-id" ,
44
48
entryPoint : entryPoint06Address ,
45
- dummySignature : await smartAccount . getDummySignature ( ) ,
49
+ dummySignature : await smartAccount . getStubSignature ( ) ,
46
50
userOperation : v06UserOperation ,
47
51
} ,
48
52
] ,
@@ -59,27 +63,31 @@ describe("requestGasAndPaymasterAndData tests", async () => {
59
63
60
64
it ( "should be able to call requestGasAndPaymasterAndData with v0.7 user operation" , async ( ) => {
61
65
const client = local070Instance . getClient ( ) ;
66
+ const signer = privateKeyToAccount ( generatePrivateKey ( ) ) ;
62
67
63
68
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
+ } ) ,
66
74
version : "v2.0.0" ,
67
- signer :
68
- LocalAccountSigner . privateKeyToAccountSigner ( generatePrivateKey ( ) ) ,
75
+ owner : signer ,
69
76
} ) ;
70
77
78
+ const factoryArgs = await smartAccount . getFactoryArgs ( ) ;
71
79
const v07UserOperation = {
72
80
sender : smartAccount . address ,
73
81
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 ( [
77
85
{
78
- target : zeroAddress ,
86
+ to : zeroAddress ,
79
87
data : "0x" as const ,
80
88
} ,
81
89
] ) ,
82
- signature : await smartAccount . getDummySignature ( ) ,
90
+ signature : await smartAccount . getStubSignature ( ) ,
83
91
} ;
84
92
85
93
const result = await requestGasAndPaymasterAndData (
@@ -88,7 +96,7 @@ describe("requestGasAndPaymasterAndData tests", async () => {
88
96
{
89
97
policyId : "test-policy-id" ,
90
98
entryPoint : entryPoint07Address ,
91
- dummySignature : await smartAccount . getDummySignature ( ) ,
99
+ dummySignature : await smartAccount . getStubSignature ( ) ,
92
100
userOperation : v07UserOperation ,
93
101
} ,
94
102
] ,
0 commit comments