@@ -2,13 +2,13 @@ const { ethers } = require('hardhat');
2
2
const { expect } = require ( 'chai' ) ;
3
3
const { loadFixture } = require ( '@nomicfoundation/hardhat-network-helpers' ) ;
4
4
5
- const { packValidationData, packPaymasterData , UserOperation } = require ( '../../helpers/erc4337' ) ;
5
+ const { packValidationData, UserOperation } = require ( '../../helpers/erc4337' ) ;
6
6
const { MAX_UINT48 } = require ( '../../helpers/constants' ) ;
7
7
8
8
const fixture = async ( ) => {
9
- const [ authorizer , sender , entrypoint , paymaster ] = await ethers . getSigners ( ) ;
9
+ const [ authorizer , sender , entrypoint , factory , paymaster ] = await ethers . getSigners ( ) ;
10
10
const utils = await ethers . deployContract ( '$ERC4337Utils' ) ;
11
- return { utils, authorizer, sender, entrypoint, paymaster } ;
11
+ return { utils, authorizer, sender, entrypoint, factory , paymaster } ;
12
12
} ;
13
13
14
14
describe ( 'ERC4337Utils' , function ( ) {
@@ -144,6 +144,33 @@ describe('ERC4337Utils', function () {
144
144
} ) ;
145
145
146
146
describe ( 'userOp values' , function ( ) {
147
+ describe ( 'intiCode' , function ( ) {
148
+ beforeEach ( async function ( ) {
149
+ this . userOp = new UserOperation ( {
150
+ sender : this . sender ,
151
+ nonce : 1 ,
152
+ verificationGas : 0x12345678n ,
153
+ factory : this . factory ,
154
+ factoryData : '0x123456' ,
155
+ } ) ;
156
+
157
+ this . emptyUserOp = new UserOperation ( {
158
+ sender : this . sender ,
159
+ nonce : 1 ,
160
+ } ) ;
161
+ } ) ;
162
+
163
+ it ( 'returns factory' , async function ( ) {
164
+ expect ( this . utils . $factory ( this . userOp . packed ) ) . to . eventually . equal ( this . factory ) ;
165
+ expect ( this . utils . $factory ( this . emptyUserOp . packed ) ) . to . eventually . equal ( ethers . ZeroAddress ) ;
166
+ } ) ;
167
+
168
+ it ( 'returns factoryData' , async function ( ) {
169
+ expect ( this . utils . $factoryData ( this . userOp . packed ) ) . to . eventually . equal ( '0x123456' ) ;
170
+ expect ( this . utils . $factoryData ( this . emptyUserOp . packed ) ) . to . eventually . equal ( '0x' ) ;
171
+ } ) ;
172
+ } ) ;
173
+
147
174
it ( 'returns verificationGasLimit' , async function ( ) {
148
175
const userOp = new UserOperation ( { sender : this . sender , nonce : 1 , verificationGas : 0x12345678n } ) ;
149
176
expect ( this . utils . $verificationGasLimit ( userOp . packed ) ) . to . eventually . equal ( userOp . verificationGas ) ;
@@ -176,28 +203,43 @@ describe('ERC4337Utils', function () {
176
203
177
204
describe ( 'paymasterAndData' , function ( ) {
178
205
beforeEach ( async function ( ) {
179
- this . verificationGasLimit = 0x12345678n ;
180
- this . postOpGasLimit = 0x87654321n ;
181
- this . paymasterAndData = packPaymasterData ( this . paymaster , this . verificationGasLimit , this . postOpGasLimit ) ;
182
206
this . userOp = new UserOperation ( {
183
207
sender : this . sender ,
184
208
nonce : 1 ,
185
- paymasterAndData : this . paymasterAndData ,
209
+ paymaster : this . paymaster ,
210
+ paymasterVerificationGasLimit : 0x12345678n ,
211
+ paymasterPostOpGasLimit : 0x87654321n ,
212
+ paymasterData : '0xbeefcafe' ,
213
+ } ) ;
214
+
215
+ this . emptyUserOp = new UserOperation ( {
216
+ sender : this . sender ,
217
+ nonce : 1 ,
186
218
} ) ;
187
219
} ) ;
188
220
189
221
it ( 'returns paymaster' , async function ( ) {
190
- expect ( this . utils . $paymaster ( this . userOp . packed ) ) . to . eventually . equal ( this . paymaster ) ;
222
+ expect ( this . utils . $paymaster ( this . userOp . packed ) ) . to . eventually . equal ( this . userOp . paymaster ) ;
223
+ expect ( this . utils . $paymaster ( this . emptyUserOp . packed ) ) . to . eventually . equal ( ethers . ZeroAddress ) ;
191
224
} ) ;
192
225
193
226
it ( 'returns verificationGasLimit' , async function ( ) {
194
227
expect ( this . utils . $paymasterVerificationGasLimit ( this . userOp . packed ) ) . to . eventually . equal (
195
- this . verificationGasLimit ,
228
+ this . userOp . paymasterVerificationGasLimit ,
196
229
) ;
230
+ expect ( this . utils . $paymasterVerificationGasLimit ( this . emptyUserOp . packed ) ) . to . eventually . equal ( 0n ) ;
197
231
} ) ;
198
232
199
233
it ( 'returns postOpGasLimit' , async function ( ) {
200
- expect ( this . utils . $paymasterPostOpGasLimit ( this . userOp . packed ) ) . to . eventually . equal ( this . postOpGasLimit ) ;
234
+ expect ( this . utils . $paymasterPostOpGasLimit ( this . userOp . packed ) ) . to . eventually . equal (
235
+ this . userOp . paymasterPostOpGasLimit ,
236
+ ) ;
237
+ expect ( this . utils . $paymasterPostOpGasLimit ( this . emptyUserOp . packed ) ) . to . eventually . equal ( 0n ) ;
238
+ } ) ;
239
+
240
+ it ( 'returns data' , async function ( ) {
241
+ expect ( this . utils . $paymasterData ( this . userOp . packed ) ) . to . eventually . equal ( this . userOp . paymasterData ) ;
242
+ expect ( this . utils . $paymasterData ( this . emptyUserOp . packed ) ) . to . eventually . equal ( '0x' ) ;
201
243
} ) ;
202
244
} ) ;
203
245
} ) ;
0 commit comments