@@ -166,13 +166,15 @@ function assertArgsArraysEqual(
166
166
actualArgs . length === expectedArgs . length ,
167
167
`Expected "${ eventName } " event to have ${ expectedArgs . length } argument(s), but it has ${ actualArgs . length } `
168
168
) ;
169
- for ( let index = 0 ; index < expectedArgs . length ; index ++ ) {
170
- if ( typeof expectedArgs [ index ] === "function" ) {
169
+ for ( const index in expectedArgs ) {
170
+ const expectedArg = expectedArgs [ index ] ;
171
+ const actualArg = actualArgs [ index ] ;
172
+ if ( typeof expectedArg === "function" ) {
171
173
const errorPrefix = `The predicate for the ${ ordinal (
172
- index + 1
174
+ parseInt ( index ) + 1
173
175
) } event argument`;
174
176
try {
175
- if ( expectedArgs [ index ] ( actualArgs [ index ] ) === true ) continue ;
177
+ if ( expectedArg ( actualArg ) === true ) continue ;
176
178
} catch ( e : any ) {
177
179
assert (
178
180
false ,
@@ -187,55 +189,55 @@ function assertArgsArraysEqual(
187
189
// no need for a negated message, since we disallow mixing .not. with
188
190
// .withArgs
189
191
) ;
190
- } else if ( expectedArgs [ index ] instanceof Uint8Array ) {
191
- new Assertion ( actualArgs [ index ] , undefined , ssfi , true ) . equal (
192
- ethers . hexlify ( expectedArgs [ index ] )
192
+ } else if ( expectedArg instanceof Uint8Array ) {
193
+ new Assertion ( actualArg , undefined , ssfi , true ) . equal (
194
+ ethers . hexlify ( expectedArg )
193
195
) ;
194
196
} else if (
195
- expectedArgs [ index ] ?. length !== undefined &&
196
- typeof expectedArgs [ index ] !== "string"
197
+ expectedArg ?. length !== undefined &&
198
+ typeof expectedArg !== "string"
197
199
) {
198
- const expectedLength = expectedArgs [ index ] . length ;
199
- const actualLength = actualArgs [ index ] . length ;
200
+ const expectedLength = expectedArg . length ;
201
+ const actualLength = actualArg . length ;
200
202
assert (
201
203
expectedLength === actualLength ,
202
204
`Expected the ${ ordinal (
203
- index + 1
205
+ parseInt ( index ) + 1
204
206
) } argument of the "${ eventName } " event to have ${ expectedLength } ${
205
207
expectedLength === 1 ? "element" : "elements"
206
208
} , but it has ${ actualLength } `
207
209
) ;
208
210
209
- for ( let j = 0 ; j < expectedArgs [ index ] . length ; j ++ ) {
210
- new Assertion ( actualArgs [ index ] [ j ] , undefined , ssfi , true ) . equal (
211
- expectedArgs [ index ] [ j ]
211
+ for ( let j = 0 ; j < expectedArg . length ; j ++ ) {
212
+ new Assertion ( actualArg [ j ] , undefined , ssfi , true ) . equal (
213
+ expectedArg [ j ]
212
214
) ;
213
215
}
214
216
} else {
215
217
if (
216
- actualArgs [ index ] . hash !== undefined &&
217
- actualArgs [ index ] . _isIndexed === true
218
+ actualArg . hash !== undefined &&
219
+ actualArg . _isIndexed === true
218
220
) {
219
221
new Assertion (
220
- actualArgs [ index ] . hash ,
222
+ actualArg . hash ,
221
223
undefined ,
222
224
ssfi ,
223
225
true
224
226
) . to . not . equal (
225
- expectedArgs [ index ] ,
227
+ expectedArg ,
226
228
"The actual value was an indexed and hashed value of the event argument. The expected value provided to the assertion should be the actual event argument (the pre-image of the hash). You provided the hash itself. Please supply the actual event argument (the pre-image of the hash) instead."
227
229
) ;
228
- const expectedArgBytes = ethers . isHexString ( expectedArgs [ index ] )
229
- ? ethers . getBytes ( expectedArgs [ index ] )
230
- : ethers . toUtf8Bytes ( expectedArgs [ index ] ) ;
230
+ const expectedArgBytes = ethers . isHexString ( expectedArg )
231
+ ? ethers . getBytes ( expectedArg )
232
+ : ethers . toUtf8Bytes ( expectedArg ) ;
231
233
const expectedHash = ethers . keccak256 ( expectedArgBytes ) ;
232
- new Assertion ( actualArgs [ index ] . hash , undefined , ssfi , true ) . to . equal (
234
+ new Assertion ( actualArg . hash , undefined , ssfi , true ) . to . equal (
233
235
expectedHash ,
234
236
`The actual value was an indexed and hashed value of the event argument. The expected value provided to the assertion was hashed to produce ${ expectedHash } . The actual hash and the expected hash did not match`
235
237
) ;
236
238
} else {
237
- new Assertion ( actualArgs [ index ] , undefined , ssfi , true ) . equal (
238
- expectedArgs [ index ]
239
+ new Assertion ( actualArg , undefined , ssfi , true ) . equal (
240
+ expectedArg
239
241
) ;
240
242
}
241
243
}
0 commit comments