Skip to content

Commit

Permalink
test: fail solidity tests if they made no assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
sohkai committed Apr 18, 2019
1 parent db8f88f commit ba6fff8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions contracts/test/TestDelegateProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ contract TestDelegateProxy is DelegateProxy {

// keep as last test as it will kill this contract
function testDieIfMinReturn0() public {
Assert.isTrue(true, ''); // Make at least one assertion to satisfy the runner

delegatedFwd(target, target.die.selector.toBytes());
Assert.fail('should be dead');
}
}
19 changes: 12 additions & 7 deletions test/helpers/runSolidityTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const HOOKS_MAP = {
afterAll: 'afterAll',
}

const processResult = txReceipt => {
const processResult = (txReceipt, mustAssert) => {
if (!txReceipt || !txReceipt.receipt) {
return
}
Expand All @@ -37,6 +37,9 @@ const processResult = txReceipt => {
throw new Error(log.args.message)
}
})
if (mustAssert && !decodedLogs.length) {
throw new Error('No assertions made')
}
}

/*
Expand Down Expand Up @@ -81,13 +84,15 @@ function runSolidityTest(c, mochaContext) {
if (interface.type === 'function') {
if (['beforeAll', 'beforeEach', 'afterEach', 'afterAll'].includes(interface.name)) {
// Set up hooks
global[HOOKS_MAP[interface.name]](() => {
return deployed[interface.name]().then(processResult)
})
global[HOOKS_MAP[interface.name]](() =>
deployed[interface.name]()
.then(receipt => processResult(receipt, false))
)
} else if (interface.name.startsWith('test')) {
it(interface.name, () => {
return deployed[interface.name]().then(processResult)
})
it(interface.name, () =>
deployed[interface.name]()
.then(receipt => processResult(receipt, true))
)
}
}
})
Expand Down

0 comments on commit ba6fff8

Please sign in to comment.