From 4e97e98c43c454d08ae5eaae2877aa5927aa1dcf Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 12 Feb 2018 09:28:16 -0500 Subject: [PATCH] remove web3 param from runTest params, simply use Web3 directly --- index.js | 2 +- src/testRunner.js | 7 ++++--- tests/testRunner.js | 10 ++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 51bcb0808e..9b1d66dc92 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,7 @@ var runTestFiles = function (filepath, isDirectory, web3) { } async.eachOfLimit(contractsToTest, 1, (contractName, index, cb) => { - TestRunner.runTest(web3, contractName, contracts[contractName], testCallback, (err, result) => { + TestRunner.runTest(contractName, contracts[contractName], testCallback, (err, result) => { if (err) { return cb(err) } diff --git a/src/testRunner.js b/src/testRunner.js index 9265fe325b..fe868c1c2d 100644 --- a/src/testRunner.js +++ b/src/testRunner.js @@ -1,5 +1,6 @@ var async = require('async') var changeCase = require('change-case') +var Web3 = require('web3') function getAvailableFunctions (jsonInterface) { return jsonInterface.reverse().filter((x) => x.type === 'function').map((x) => x.name) @@ -29,7 +30,7 @@ function createRunList (jsonInterface) { return runList } -function runTest (web3, testName, testObject, testCallback, resultsCallback) { +function runTest (testName, testObject, testCallback, resultsCallback) { let runList = createRunList(testObject._jsonInterface) let passingNum = 0 @@ -57,13 +58,13 @@ function runTest (web3, testName, testObject, testCallback, resultsCallback) { 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 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)) + matchingEvents.push(Web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data)) } } diff --git a/tests/testRunner.js b/tests/testRunner.js index 72e216fa45..750984b710 100644 --- a/tests/testRunner.js +++ b/tests/testRunner.js @@ -18,20 +18,18 @@ function compileAndDeploy (filename, callback) { Deployer.deployAll(compilationResult, web3, next) } ], function (_err, contracts) { - callback(null, contracts, web3) + callback(null, contracts) }) } describe('testRunner', function () { - let web3; describe('#runTest', function() { describe('test with beforeAll', function () { let filename = 'tests/examples_1/simple_storage_test.sol' let tests = [], results = {} before(function (done) { - compileAndDeploy(filename, function (_err, contracts, _web3) { - web3 = _web3; + compileAndDeploy(filename, function (_err, contracts) { var testCallback = function (test) { tests.push(test) } @@ -39,7 +37,7 @@ describe('testRunner', function () { results = _results done() } - TestRunner.runTest(web3, 'MyTest', contracts.MyTest, testCallback, resultsCallback) + TestRunner.runTest('MyTest', contracts.MyTest, testCallback, resultsCallback) }) }) @@ -73,7 +71,7 @@ describe('testRunner', function () { results = _results done() } - TestRunner.runTest(web3, 'MyTest', contracts.MyTest, testCallback, resultsCallback) + TestRunner.runTest('MyTest', contracts.MyTest, testCallback, resultsCallback) }) })