Skip to content

Commit

Permalink
test: fix solidity test runner so it actually errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sohkai committed Apr 3, 2019
1 parent d1cd633 commit 5c70c46
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/helpers/decodeEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
31 changes: 27 additions & 4 deletions test/helpers/runSolidityTest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
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',
afterEach: 'afterEach',
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)
}
Expand All @@ -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()
Expand Down

0 comments on commit 5c70c46

Please sign in to comment.