check transaction for assertion even and add to testCallback

pull/7/head
Iuri Matias 7 years ago
parent dc7741e9a8
commit a4e522aacf
  1. 8
      examples/simple_storage_test.sol
  2. 2
      index.js
  3. 1
      run.js
  4. 2
      sol/tests.sol
  5. 32
      src/testRunner.js

@ -9,12 +9,12 @@ contract MyTest {
foo = new SimpleStorage();
}
function initialValueShouldBe100() public constant returns (bool) {
return Assert.equal(foo.get(), 100, "initial value is not correct");
function initialValueShouldBe100() public {
Assert.equal(foo.get(), 100, "initial value is not correct");
}
function initialValueShouldBe200() public constant returns (bool) {
return Assert.equal(foo.get(), 200, "initial value is not correct");
function initialValueShouldBe200() public {
Assert.equal(foo.get(), 200, "initial value is not correct");
}
}

@ -60,7 +60,7 @@ var runTestFiles = function (filepath, isDirectory, web3) {
}
async.eachOfLimit(contractsToTest, 1, (contractName, index, cb) => {
TestRunner.runTest(contractName, contracts[contractName], testCallback, (err, result) => {
TestRunner.runTest(web3, contractName, contracts[contractName], testCallback, (err, result) => {
if (err) {
return cb(err)
}

@ -6,6 +6,7 @@ const fs = require('fs')
commander.action(function (filename) {
let web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
//web3.setProvider(new web3.providers.WebsocketProvider('http://localhost:8546'))
let isDirectory = fs.lstatSync(filename).isDirectory()
RemixTests.runTestFiles(filename, isDirectory, web3)

@ -3,7 +3,7 @@ pragma solidity ^0.4.7;
library Assert {
event AssertionEvent(
bool indexed passed,
bool passed,
string message
);

@ -29,7 +29,7 @@ function createRunList (jsonInterface) {
return runList
}
function runTest (testName, testObject, testCallback, resultsCallback) {
function runTest (web3, testName, testObject, testCallback, resultsCallback) {
let runList = createRunList(testObject._jsonInterface)
let passingNum = 0
@ -48,13 +48,39 @@ function runTest (testName, testObject, testCallback, resultsCallback) {
passingNum += 1
timePassed += time
} else {
testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time})
testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: 'function returned false'})
failureNum += 1
}
next()
})
} else {
method.send().then(() => {
method.send().on('receipt', function(receipt) {
let time = Math.ceil((Date.now() - startTime) / 1000.0)
if (func.type === 'test') {
let topic = web3.utils.sha3('AssertionEvent(bool,string)')
let matchingEvents = []
for (let i in receipt.events) {
let event = receipt.events[i]
if (event.raw.topics.indexOf(topic) >= 0) {
matchingEvents.push(web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data))
}
}
if (matchingEvents.length === 0) {
return next();
}
let result = matchingEvents[0];
if (result[0]) {
testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time})
passingNum += 1
} else {
testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: result[1]})
failureNum += 1
}
}
next()
})
}

Loading…
Cancel
Save