parent
5ceb83a597
commit
8a7e58c366
@ -1,120 +1,120 @@ |
||||
const async = require('async'); |
||||
const path = require('path'); |
||||
const fs = require('fs'); |
||||
require('colors'); |
||||
const async = require('async') |
||||
const path = require('path') |
||||
const fs = require('fs') |
||||
require('colors') |
||||
|
||||
let Compiler = require('./src/compiler.js'); |
||||
let Deployer = require('./src/deployer.js'); |
||||
let TestRunner = require('./src/testRunner.js'); |
||||
let Compiler = require('./src/compiler.js') |
||||
let Deployer = require('./src/deployer.js') |
||||
let TestRunner = require('./src/testRunner.js') |
||||
|
||||
var runTest = function(contractName, contractObj, testCallback, resultsCallback) { |
||||
TestRunner.runTest(contractName, contractObj, testCallback, resultsCallback); |
||||
var runTest = function (contractName, contractObj, testCallback, resultsCallback) { |
||||
TestRunner.runTest(contractName, contractObj, testCallback, resultsCallback) |
||||
} |
||||
|
||||
var runTestFile = function(filename, web3) { |
||||
var runTestFile = function (filename, web3) { |
||||
async.waterfall([ |
||||
function compile(next) { |
||||
Compiler.compileFile(filename, next); |
||||
function compile (next) { |
||||
Compiler.compileFile(filename, next) |
||||
}, |
||||
function deployAllContracts(compilationResult, next) { |
||||
Deployer.deployAll(compilationResult, web3, function(err, contracts) { |
||||
function deployAllContracts (compilationResult, next) { |
||||
Deployer.deployAll(compilationResult, web3, function (err, contracts) { |
||||
if (err) { |
||||
next(err); |
||||
next(err) |
||||
} |
||||
|
||||
let contractsToTest = Object.keys(compilationResult[path.basename(filename)]); |
||||
next(null, contractsToTest, contracts); |
||||
}); |
||||
let contractsToTest = Object.keys(compilationResult[path.basename(filename)]) |
||||
next(null, contractsToTest, contracts) |
||||
}) |
||||
}, |
||||
function runTests(contractsToTest, contracts, next) { |
||||
var testCallback = function(result) { |
||||
function runTests (contractsToTest, contracts, next) { |
||||
var testCallback = function (result) { |
||||
if (result.type === 'contract') { |
||||
console.log(("\t " + result.value).green); |
||||
console.log(('\t ' + result.value).green) |
||||
} else if (result.type === 'testPass') { |
||||
console.log("\t✓ ".green.bold + result.value.grey); |
||||
console.log('\t✓ '.green.bold + result.value.grey) |
||||
} else if (result.type === 'testFailure') { |
||||
console.log("\t✘ ".bold.red + result.value.red); |
||||
console.log('\t✘ '.bold.red + result.value.red) |
||||
} |
||||
} |
||||
var resultsCallback = function(err, result) { |
||||
var resultsCallback = function (err, result) { |
||||
if (err) { |
||||
return cb(err); |
||||
return cb(err) |
||||
} |
||||
if (result.passingNum > 0) { |
||||
console.log((result.passingNum + " passing").green); |
||||
console.log((result.passingNum + ' passing').green) |
||||
} |
||||
if (result.failureNum > 0) { |
||||
console.log((result.failureNum + " failing").red); |
||||
console.log((result.failureNum + ' failing').red) |
||||
} |
||||
} |
||||
|
||||
async.eachLimit(contractsToTest, 1, (contractName, cb) => { |
||||
runTest(contractName, contracts[contractName], testCallback, resultsCallback); |
||||
}, next); |
||||
runTest(contractName, contracts[contractName], testCallback, resultsCallback) |
||||
}, next) |
||||
} |
||||
], function() { |
||||
}); |
||||
], function () { |
||||
}) |
||||
} |
||||
|
||||
var runTestFiles = function(directory, web3) { |
||||
var runTestFiles = function (directory, web3) { |
||||
async.waterfall([ |
||||
function compile(next) { |
||||
Compiler.compileFiles(directory, next); |
||||
function compile (next) { |
||||
Compiler.compileFiles(directory, next) |
||||
}, |
||||
function deployAllContracts(compilationResult, next) { |
||||
Deployer.deployAll(compilationResult, web3, function(err, contracts) { |
||||
function deployAllContracts (compilationResult, next) { |
||||
Deployer.deployAll(compilationResult, web3, function (err, contracts) { |
||||
if (err) { |
||||
next(err); |
||||
next(err) |
||||
} |
||||
|
||||
let contractsToTest = []; |
||||
let contractsToTest = [] |
||||
fs.readdirSync(directory).forEach(filename => { |
||||
if (filename.indexOf('_test.sol') < 0) { |
||||
return; |
||||
return |
||||
} |
||||
Object.keys(compilationResult[path.basename(filename)]).forEach(contractName => { |
||||
contractsToTest.push(contractName) |
||||
}) |
||||
}) |
||||
|
||||
next(null, contractsToTest, contracts); |
||||
}); |
||||
next(null, contractsToTest, contracts) |
||||
}) |
||||
}, |
||||
function runTests(contractsToTest, contracts, next) { |
||||
var testCallback = function(result) { |
||||
function runTests (contractsToTest, contracts, next) { |
||||
var testCallback = function (result) { |
||||
if (result.type === 'contract') { |
||||
console.log("\n " + result.value); |
||||
console.log('\n ' + result.value) |
||||
} else if (result.type === 'testPass') { |
||||
console.log("\t✓ ".green.bold + result.value.grey); |
||||
console.log('\t✓ '.green.bold + result.value.grey) |
||||
} else if (result.type === 'testFailure') { |
||||
console.log("\t✘ ".bold.red + result.value.red); |
||||
console.log('\t✘ '.bold.red + result.value.red) |
||||
} |
||||
} |
||||
var resultsCallback = function(_err, result, cb) { |
||||
var resultsCallback = function (_err, result, cb) { |
||||
if (result.passingNum > 0) { |
||||
console.log((result.passingNum + " passing").green); |
||||
console.log((result.passingNum + ' passing').green) |
||||
} |
||||
if (result.failureNum > 0) { |
||||
console.log((result.failureNum + " failing").red); |
||||
console.log((result.failureNum + ' failing').red) |
||||
} |
||||
cb(); |
||||
cb() |
||||
} |
||||
|
||||
async.eachOfLimit(contractsToTest, 1, (contractName, index, cb) => { |
||||
runTest(contractName, contracts[contractName], testCallback, (err, result) => { |
||||
if (err) { |
||||
return cb(err); |
||||
return cb(err) |
||||
} |
||||
resultsCallback(null, result, cb); |
||||
}); |
||||
}, next); |
||||
resultsCallback(null, result, cb) |
||||
}) |
||||
}, next) |
||||
} |
||||
], function() { |
||||
}); |
||||
], function () { |
||||
}) |
||||
} |
||||
|
||||
module.exports = { |
||||
runTestFile: runTestFile, |
||||
runTestFiles: runTestFiles, |
||||
runTest: runTest |
||||
}; |
||||
} |
||||
|
@ -1,22 +1,21 @@ |
||||
const commander = require('commander'); |
||||
const Web3 = require('web3'); |
||||
const RemixTests = require('./index.js'); |
||||
const fs = require('fs'); |
||||
const commander = require('commander') |
||||
const Web3 = require('web3') |
||||
const RemixTests = require('./index.js') |
||||
const fs = require('fs') |
||||
|
||||
commander.action(function (filename) { |
||||
let web3 = new Web3(); |
||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); |
||||
let web3 = new Web3() |
||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) |
||||
|
||||
if (fs.lstatSync(filename).isDirectory()) { |
||||
RemixTests.runTestFiles(filename, web3); |
||||
RemixTests.runTestFiles(filename, web3) |
||||
} else { |
||||
RemixTests.runTestFile(filename, web3); |
||||
RemixTests.runTestFile(filename, web3) |
||||
} |
||||
}); |
||||
}) |
||||
|
||||
if (!process.argv.slice(2).length) { |
||||
console.log("please specify filename"); |
||||
console.log('please specify filename') |
||||
} |
||||
|
||||
commander.parse(process.argv); |
||||
|
||||
commander.parse(process.argv) |
||||
|
@ -1,96 +1,93 @@ |
||||
const async = require('async'); |
||||
const Web3 = require('web3'); |
||||
const assert = require('assert'); |
||||
const async = require('async') |
||||
const Web3 = require('web3') |
||||
const assert = require('assert') |
||||
|
||||
let Compiler = require('../src/compiler.js'); |
||||
let Deployer = require('../src/deployer.js'); |
||||
let TestRunner = require('../src/testRunner.js'); |
||||
let Compiler = require('../src/compiler.js') |
||||
let Deployer = require('../src/deployer.js') |
||||
let TestRunner = require('../src/testRunner.js') |
||||
|
||||
function compileAndDeploy(filename, callback) { |
||||
let web3 = new Web3(); |
||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); |
||||
function compileAndDeploy (filename, callback) { |
||||
let web3 = new Web3() |
||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) |
||||
|
||||
async.waterfall([ |
||||
function compile(next) { |
||||
Compiler.compileFile(filename, next); |
||||
function compile (next) { |
||||
Compiler.compileFile(filename, next) |
||||
}, |
||||
function deployAllContracts(compilationResult, next) { |
||||
Deployer.deployAll(compilationResult, web3, next); |
||||
function deployAllContracts (compilationResult, next) { |
||||
Deployer.deployAll(compilationResult, web3, next) |
||||
} |
||||
], function(_err, contracts) { |
||||
callback(null, contracts); |
||||
}); |
||||
], function (_err, contracts) { |
||||
callback(null, contracts) |
||||
}) |
||||
} |
||||
|
||||
describe('testRunner', function() { |
||||
describe("test with beforeAll", function() { |
||||
describe('testRunner', function () { |
||||
describe('test with beforeAll', function () { |
||||
let filename = 'tests/examples_1/simple_storage_test.sol' |
||||
let tests = [], results = {}; |
||||
let tests = [], results = {} |
||||
|
||||
before(function(done) { |
||||
compileAndDeploy(filename, function(_err, contracts) { |
||||
var testCallback = function(test) { |
||||
tests.push(test); |
||||
before(function (done) { |
||||
compileAndDeploy(filename, function (_err, contracts) { |
||||
var testCallback = function (test) { |
||||
tests.push(test) |
||||
} |
||||
var resultsCallback = function(_err, _results) { |
||||
results = _results; |
||||
done(); |
||||
var resultsCallback = function (_err, _results) { |
||||
results = _results |
||||
done() |
||||
} |
||||
TestRunner.runTest('MyTest', contracts.MyTest, testCallback, resultsCallback); |
||||
}); |
||||
}); |
||||
TestRunner.runTest('MyTest', contracts.MyTest, testCallback, resultsCallback) |
||||
}) |
||||
}) |
||||
|
||||
it('should 1 passing test', function() { |
||||
it('should 1 passing test', function () { |
||||
assert.equal(results.passingNum, 1) |
||||
}); |
||||
}) |
||||
|
||||
it('should 1 failing test', function() { |
||||
it('should 1 failing test', function () { |
||||
assert.equal(results.failureNum, 1) |
||||
}); |
||||
}) |
||||
|
||||
it('should returns 3 messages', function() { |
||||
it('should returns 3 messages', function () { |
||||
assert.deepEqual(tests, [ |
||||
{ type: 'contract', value: 'MyTest' }, |
||||
{ type: 'testPass', value: 'Initial value should be100' }, |
||||
{ type: 'testFailure', value: 'Initial value should be200' } |
||||
]); |
||||
}); |
||||
]) |
||||
}) |
||||
}) |
||||
|
||||
}); |
||||
|
||||
describe("test with beforeEach", function() { |
||||
describe('test with beforeEach', function () { |
||||
let filename = 'tests/examples_2/simple_storage_test.sol' |
||||
let tests = [], results = {}; |
||||
let tests = [], results = {} |
||||
|
||||
before(function(done) { |
||||
compileAndDeploy(filename, function(_err, contracts) { |
||||
var testCallback = function(test) { |
||||
tests.push(test); |
||||
before(function (done) { |
||||
compileAndDeploy(filename, function (_err, contracts) { |
||||
var testCallback = function (test) { |
||||
tests.push(test) |
||||
} |
||||
var resultsCallback = function(_err, _results) { |
||||
results = _results; |
||||
done(); |
||||
var resultsCallback = function (_err, _results) { |
||||
results = _results |
||||
done() |
||||
} |
||||
TestRunner.runTest("MyTest", contracts.MyTest, testCallback, resultsCallback); |
||||
}); |
||||
}); |
||||
TestRunner.runTest('MyTest', contracts.MyTest, testCallback, resultsCallback) |
||||
}) |
||||
}) |
||||
|
||||
it('should 2 passing tests', function() { |
||||
it('should 2 passing tests', function () { |
||||
assert.equal(results.passingNum, 2) |
||||
}); |
||||
}) |
||||
|
||||
it('should 0 failing tests', function() { |
||||
it('should 0 failing tests', function () { |
||||
assert.equal(results.failureNum, 0) |
||||
}); |
||||
}) |
||||
|
||||
it('should returns 3 messages', function() { |
||||
it('should returns 3 messages', function () { |
||||
assert.deepEqual(tests, [ |
||||
{ type: 'contract', value: 'MyTest' }, |
||||
{ type: 'testPass', value: 'Initial value should be100' }, |
||||
{ type: 'testPass', value: 'Initial value should be200' } |
||||
]); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
}); |
||||
]) |
||||
}) |
||||
}) |
||||
}) |
||||
|
Loading…
Reference in new issue