Now testing events in constructors! (#1511)
* Added inTransaction tests.
* Added expectEvent.inConstructor.
* Changed inTransaction, removed decodeLogs.
* Flipped comparison to improve the error message.
* Improved expectEvent tests.
* Migrated tests to use expectEvent.
* Added roles constructor tests.
* Fixed linter errors.
* Made lodash a dev dependency.
* Added more inLogs tests.
* Update expectEvent.test.js
* Removed lodash.
* Moved role constructor tests to public role behavior.
* Revert "Flipped comparison to improve the error message."
This reverts commit 438c57833d.
* Replaced chai-as-promised with shouldFail.
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
const SolidityEvent = require('web3/lib/web3/event.js');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
const should = require('chai')
|
||||
.use(require('chai-bignumber')(BigNumber))
|
||||
@ -16,8 +18,14 @@ function inLogs (logs, eventName, eventArgs = {}) {
|
||||
return event;
|
||||
}
|
||||
|
||||
async function inTransaction (tx, eventName, eventArgs = {}) {
|
||||
const { logs } = await tx;
|
||||
async function inConstruction (contract, eventName, eventArgs = {}) {
|
||||
return inTransaction(contract.transactionHash, contract.constructor, eventName, eventArgs);
|
||||
}
|
||||
|
||||
async function inTransaction (txHash, emitter, eventName, eventArgs = {}) {
|
||||
const receipt = await web3.eth.getTransactionReceipt(txHash);
|
||||
const logs = decodeLogs(receipt.logs, emitter.events);
|
||||
|
||||
return inLogs(logs, eventName, eventArgs);
|
||||
}
|
||||
|
||||
@ -35,7 +43,17 @@ function isBigNumber (object) {
|
||||
(object.constructor && object.constructor.name === 'BigNumber');
|
||||
}
|
||||
|
||||
function decodeLogs (logs, events) {
|
||||
return Array.prototype.concat(...logs.map(log =>
|
||||
log.topics.filter(topic => topic in events).map(topic => {
|
||||
const event = new SolidityEvent(null, events[topic], 0);
|
||||
return event.decode(log);
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
inLogs,
|
||||
inConstruction,
|
||||
inTransaction,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user