diff --git a/lib/matchers/matchers.ts b/lib/matchers/matchers.ts index f882eeb24..ce5c0e458 100644 --- a/lib/matchers/matchers.ts +++ b/lib/matchers/matchers.ts @@ -122,7 +122,13 @@ const solidity = (chai: any, utils: any) => { expectedArgs.length, actualArgs.length); for (let index = 0; index < expectedArgs.length; index++) { - new chai.Assertion(expectedArgs[index]).equal(actualArgs[index]); + if (expectedArgs[index].length !== undefined && typeof expectedArgs[index] !== 'string') { + for (let j = 0; j < expectedArgs[index].length; j++) { + new chai.Assertion(expectedArgs[index][j]).equal(actualArgs[index][j]); + } + } else { + new chai.Assertion((expectedArgs[index])).equal((actualArgs[index])); + } } }; diff --git a/package.json b/package.json index 18b0ed0a2..539618174 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "test:nobuild": "export NODE_ENV=test && mocha", "test": "yarn test:buildonly && yarn test:nobuild", "lint": "eslint '{lib,test}/**/*.ts'", + "lint:fix": "eslint --fix '{lib,test}/**/*.ts'", "build": "tsc -p tsconfig.build.json", "clean": "rimraf ./dist ./test/compiler/build ./test/example/build ./test/matchers/build" }, diff --git a/test/matchers/contracts/events.sol b/test/matchers/contracts/events.sol index cf78f8d9f..a35e19c4a 100644 --- a/test/matchers/contracts/events.sol +++ b/test/matchers/contracts/events.sol @@ -5,8 +5,9 @@ contract Events { event One(uint value, string msg, bytes32 encoded); event Two(uint indexed value, string msg); + event Arrays(uint256[3] value, bytes32[2] encoded); - function emitOne() public { + function emitOne() public { emit One(1, "One", 0x00cFBbaF7DDB3a1476767101c12a0162e241fbAD2a0162e2410cFBbaF7162123); } @@ -19,6 +20,16 @@ contract Events { emit Two(2, "Two"); } + function emitArrays() public { + emit Arrays([ + uint256(1), + uint256(2), + uint256(3)], + [ + bytes32(0x00cFBbaF7DDB3a1476767101c12a0162e241fbAD2a0162e2410cFBbaF7162123), + bytes32(0x00cFBbaF7DDB3a1476767101c12a0162e241fbAD2a0162e2410cFBbaF7162124)]); + } + function doNotEmit() pure public { } diff --git a/test/matchers/events.ts b/test/matchers/events.ts index 7ac058bc9..7e0370509 100644 --- a/test/matchers/events.ts +++ b/test/matchers/events.ts @@ -1,7 +1,7 @@ import {expect, AssertionError} from 'chai'; import {createMockProvider, deployContract, getWallets} from '../../lib'; import Events from './build/Events.json'; -import {Contract} from 'ethers'; +import {Contract, utils} from 'ethers'; describe('INTEGRATION: Events', () => { const provider = createMockProvider(); @@ -104,4 +104,49 @@ describe('INTEGRATION: Events', () => { 'to equal \'0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123\'' ); }); + + it('Event with array of BigNumbers and bytes32 types', async () => { + await expect(events.emitArrays()).to.emit(events, 'Arrays') + .withArgs( + [1, 2, 3], + ['0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123', + '0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162124']); + }); + + it('Event with array of BigNumbers providing bignumbers to the matcher', async () => { + await expect(events.emitArrays()).to.emit(events, 'Arrays') + .withArgs( + [utils.bigNumberify(1), 2, utils.bigNumberify(3)], + ['0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123', + '0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162124']); + }); + + it('Event with one different arg within array (bytes32)', async () => { + await expect( + expect(events.emitArrays()).to.emit(events, 'Arrays') + .withArgs( + [utils.bigNumberify(1), 2, utils.bigNumberify(3)], + ['0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162121', + '0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162124']) + ).to.be.eventually.rejectedWith( + AssertionError, + 'expected \'0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162121\' ' + + 'to equal \'0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123\'' + ); + }); + + it('Event with one different arg within array (BigNumber)', async () => { + await expect( + expect(events.emitArrays()).to.emit(events, 'Arrays') + .withArgs( + [0, 2, 3], + ['0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123', + '0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162124']) + ).to.be.eventually.rejectedWith( + AssertionError, + // eslint-disable-next-line no-useless-escape + 'Expected \"0\" ' + + 'to be equal 1' + ); + }); });