Skip to content

Commit

Permalink
🐞 Fix emit.withArgs not enough arguments (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
yivlad committed May 6, 2022
1 parent ba7033f commit 2ccc395
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-hairs-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ethereum-waffle/chai": patch
---

Fix emit.withArgs not enough elements in list
6 changes: 6 additions & 0 deletions waffle-chai/src/matchers/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export function supportEmit(Assertion: Chai.AssertionStatic) {
);
for (let index = 0; index < expectedArgs.length; index++) {
if (expectedArgs[index]?.length !== undefined && typeof expectedArgs[index] !== 'string') {
context.assert(
actualArgs[index].length === expectedArgs[index].length,
`Expected ${actualArgs[index]} to equal ${expectedArgs[index]}, ` +
'but they have different lengths',
'Do not combine .not. with .withArgs()'
);
for (let j = 0; j < expectedArgs[index].length; j++) {
new Assertion(actualArgs[index][j]).equal(expectedArgs[index][j]);
}
Expand Down
36 changes: 36 additions & 0 deletions waffle-chai/test/matchers/eventsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,42 @@ export const eventsTest = (provider: MockProvider) => {
);
});

it('Event with array of BigNumbers and bytes32 types too many arguments', async () => {
await expect(
expect(events.emitArrays())
.to.emit(events, 'Arrays')
.withArgs(
[1, 2, 3, 4],
[
'0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123',
'0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162124'
]
)
).to.be.eventually.rejectedWith(
AssertionError,
'Expected 1,2,3 to equal 1,2,3,4, but they have different lengths'
);
});

it('Event with array of BigNumbers and bytes32 types not enough arguments', async () => {
await expect(
expect(events.emitArrays())
.to.emit(events, 'Arrays')
.withArgs(
[1, 2, 3],
[
'0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123'
]
)
).to.be.eventually.rejectedWith(
AssertionError,
'Expected 0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123,' +
'0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162124' +
' to equal 0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123,' +
' but they have different lengths'
);
});

it('Event with array of BigNumbers providing bignumbers to the matcher', async () => {
await expect(events.emitArrays())
.to.emit(events, 'Arrays')
Expand Down

0 comments on commit 2ccc395

Please sign in to comment.