Skip to content

Commit

Permalink
ERC777 Make expectEvent compatible with web3.js 1.0 (OpenZeppelin#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Masius committed Nov 3, 2018
1 parent 9a6ed29 commit 2fc7b4d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test/helpers/expectEvent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
const BigNumber = web3.BigNumber;
const BigNumber = web3.utils.BN;
const should = require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();

function inEvents (events, eventName, eventArgs = {}) {
event = Object.values(events).find(function (e) {
if (e.event === eventName) {
for (const [k, v] of Object.entries(eventArgs)) {
contains(e.returnValues, k, v);
}
return true;
}
});
should.exist(event);
return event;
}

function inLogs (logs, eventName, eventArgs = {}) {
const event = logs.find(function (e) {
if (e.event === eventName) {
Expand All @@ -22,8 +35,11 @@ async function inTransaction (tx, eventName, eventArgs = {}) {
}

function contains (args, key, value) {
if (isBigNumber(args[key])) {
args[key].should.be.bignumber.equal(value);
if (args[key] == null) {
value.should.be.equal("0x00");
}
else if (isBigNumber(args[key])) {
args[key].toString().should.be.equal(value);
} else {
args[key].should.be.equal(value);
}
Expand All @@ -36,6 +52,7 @@ function isBigNumber (object) {
}

module.exports = {
inEvents,
inLogs,
inTransaction,
};

0 comments on commit 2fc7b4d

Please sign in to comment.