From 5c70c461cac54395c498c483f42082c009d8fc04 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Wed, 3 Apr 2019 17:28:57 +0200 Subject: [PATCH] test: fix solidity test runner so it actually errors --- test/helpers/decodeEvent.js | 2 +- test/helpers/runSolidityTest.js | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/test/helpers/decodeEvent.js b/test/helpers/decodeEvent.js index 0a8a2d7e8..8e974a15b 100644 --- a/test/helpers/decodeEvent.js +++ b/test/helpers/decodeEvent.js @@ -6,7 +6,7 @@ module.exports = { const eventSignature = abi.encodeEventSignature(eventAbi) const eventLogs = receipt.logs.filter(l => l.topics[0] === eventSignature) return eventLogs.map(log => { - log.event = abi.name + log.event = eventAbi.name log.args = abi.decodeLog(eventAbi.inputs, log.data, log.topics.slice(1)) return log }) diff --git a/test/helpers/runSolidityTest.js b/test/helpers/runSolidityTest.js index 9e12c31f2..1978769e1 100644 --- a/test/helpers/runSolidityTest.js +++ b/test/helpers/runSolidityTest.js @@ -1,3 +1,25 @@ +const { decodeEventsOfType } = require('./decodeEvent') + +const ASSERT_LIB_EVENTS_ABI = [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "result", + "type": "bool" + }, + { + "indexed": false, + "name": "message", + "type": "string" + } + ], + "name": "TestEvent", + "type": "event" + }, +] + const HOOKS_MAP = { beforeAll: 'before', beforeEach: 'beforeEach', @@ -5,11 +27,12 @@ const HOOKS_MAP = { afterAll: 'afterAll', } -const processResult = receipt => { - if (!receipt) { +const processResult = txReceipt => { + if (!txReceipt || !txReceipt.receipt) { return } - receipt.logs.forEach(log => { + const decodedLogs = decodeEventsOfType(txReceipt.receipt, ASSERT_LIB_EVENTS_ABI, 'TestEvent') + decodedLogs.forEach(log => { if (log.event === 'TestEvent' && log.args.result !== true) { throw new Error(log.args.message) } @@ -27,7 +50,7 @@ const linkLib = async (contract, libName) => { const prefix = underscores(PREFIX_UNDERSCORES) const suffix = underscores(ADDR_LENGTH - PREFIX_UNDERSCORES - libName.length) - + const libPlaceholder = `${prefix}${libName}${suffix}` const lib = await artifacts.require(libName).new()