Skip to content

Commit

Permalink
Refactor expectEvent.inLogs function to use simple value number check
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogacz committed Sep 21, 2018
1 parent e4e9b63 commit aff6533
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/helpers/expectEvent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const should = require('chai').should();
const _ = require('lodash');

function inLogs (logs, eventName, eventArgs = {}) {
const event = logs.find(function (e) {
if (e.event === eventName) {
let matches = true;

for (const [k, v] of Object.entries(eventArgs)) {
if (!_.isEqual(e.args[k], v)) {
if (toSimpleValue(e.args[k]) !== toSimpleValue(v)) {
matches = false;
}
}
Expand All @@ -28,6 +27,16 @@ async function inTransaction (tx, eventName, eventArgs = {}) {
return inLogs(logs, eventName, eventArgs);
}

function toSimpleValue (value) {
return isBigNumber(value)
? value.toNumber()
: value;
}

function isBigNumber (value) {
return value.constructor.name === 'BigNumber';
}

module.exports = {
inLogs,
inTransaction,
Expand Down

0 comments on commit aff6533

Please sign in to comment.