Merge remote-tracking branch 'upstream/master'

pull/3094/head
0mkar 6 years ago
commit ed2af0315a
  1. 2
      src/compiler.js
  2. 15
      src/testRunner.js
  3. 11
      tests/examples_1/simple_storage_test.sol
  4. 6
      tests/testRunner.js

@ -68,7 +68,7 @@ function compileContractSources (sources, importFileCb, cb) {
compiler.compile(sources, filepath) compiler.compile(sources, filepath)
} }
], function (err, result) { ], function (err, result) {
let errors = (result.errors || []).filter((e) => e.type === 'Error') let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error')
if (errors.length > 0) { if (errors.length > 0) {
console.dir(errors) console.dir(errors)
return cb(new Error('errors compiling')) return cb(new Error('errors compiling'))

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

@ -1,5 +1,5 @@
pragma solidity ^0.4.7; pragma solidity ^0.4.7;
import "./tests.sol"; import "remix_tests.sol";
import "./simple_storage.sol"; import "./simple_storage.sol";
contract MyTest { contract MyTest {
@ -19,5 +19,14 @@ contract MyTest {
return foo.get() == 200; 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 () { it('should 1 passing test', function () {
assert.equal(results.passingNum, 1) assert.equal(results.passingNum, 2)
}) })
it('should 1 failing test', function () { it('should 1 failing test', function () {
assert.equal(results.failureNum, 1) assert.equal(results.failureNum, 2)
}) })
it('should returns 3 messages', function () { it('should returns 3 messages', function () {
assert.deepEqual(tests, [ assert.deepEqual(tests, [
{ type: 'contract', value: 'MyTest', filename: 'simple_storage_test.sol' }, { 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: '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' } { type: 'testFailure', value: 'Initial value should be200', time: 1, context: 'MyTest', errMsg: 'function returned false' }
]) ])

Loading…
Cancel
Save