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