Merge pull request #15 from ethereum/repeated_asserts_fix

fix to avoiding duplicate passing or failing tests due to multiple asserts
pull/3094/head
yann300 6 years ago committed by GitHub
commit b6a6cba087
  1. 15
      src/testRunner.js
  2. 11
      tests/examples_1/simple_storage_test.sol
  3. 6
      tests/testRunner.js

@ -61,19 +61,26 @@ function runTest (testName, testObject, testCallback, resultsCallback) {
let time = Math.ceil((Date.now() - startTime) / 1000.0)
let topic = Web3.utils.sha3('AssertionEvent(bool,string)')
let testPassed = false
for (let i in receipt.events) {
let event = receipt.events[i]
if (event.raw.topics.indexOf(topic) >= 0) {
var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data)
if (testEvent[0]) {
testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName})
passingNum += 1
} else {
if (!testEvent[0]) {
testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: testEvent[1], context: testName})
failureNum += 1
return next()
}
testPassed = true
}
}
if (testPassed) {
testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName})
passingNum += 1
}
return next()
} catch (err) {
console.log('error!')

@ -1,5 +1,5 @@
pragma solidity ^0.4.7;
import "./tests.sol";
import "remix_tests.sol";
import "./simple_storage.sol";
contract MyTest {
@ -19,5 +19,14 @@ contract MyTest {
return foo.get() == 200;
}
function shouldTriggerOneFail() public {
Assert.equal(uint(1), uint(2), "the test 1 fails");
Assert.equal(uint(1), uint(2), "the test 2 fails");
}
function shouldTriggerOnePass() public {
Assert.equal(uint(1), uint(1), "the test 3 fails");
}
}

@ -43,16 +43,18 @@ describe('testRunner', function () {
})
it('should 1 passing test', function () {
assert.equal(results.passingNum, 1)
assert.equal(results.passingNum, 2)
})
it('should 1 failing test', function () {
assert.equal(results.failureNum, 1)
assert.equal(results.failureNum, 2)
})
it('should returns 3 messages', function () {
assert.deepEqual(tests, [
{ type: 'contract', value: 'MyTest', filename: 'simple_storage_test.sol' },
{ type: 'testFailure', value: 'Should trigger one fail', time: 1, context: 'MyTest', errMsg: 'the test 1 fails' },
{ type: 'testPass', value: 'Should trigger one pass', time: 1, context: 'MyTest'},
{ type: 'testPass', value: 'Initial value should be100', time: 1, context: 'MyTest' },
{ type: 'testFailure', value: 'Initial value should be200', time: 1, context: 'MyTest', errMsg: 'function returned false' }
])

Loading…
Cancel
Save