diff --git a/remix-tests/dist/index.d.ts b/remix-tests/dist/index.d.ts new file mode 100644 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/remix-tests/dist/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/remix-tests/dist/index.js b/remix-tests/dist/index.js new file mode 100644 index 0000000000..379aae2270 --- /dev/null +++ b/remix-tests/dist/index.js @@ -0,0 +1,15 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var runTestFiles_1 = __importDefault(require("./runTestFiles")); +var runTestSources_1 = __importDefault(require("./runTestSources")); +var testRunner_1 = __importDefault(require("./testRunner")); +module.exports = { + runTestFiles: runTestFiles_1.default, + runTestSources: runTestSources_1.default, + runTest: testRunner_1.default, + assertLibCode: require('../sol/tests.sol.js') +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/remix-tests/dist/index.js.map b/remix-tests/dist/index.js.map new file mode 100644 index 0000000000..6e20c6b110 --- /dev/null +++ b/remix-tests/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,gEAAyC;AACzC,oEAA6C;AAC7C,4DAAkC;AAElC,MAAM,CAAC,OAAO,GAAG;IACf,YAAY,EAAE,sBAAY;IAC1B,cAAc,EAAE,wBAAc;IAC9B,OAAO,EAAE,oBAAO;IAChB,aAAa,EAAE,OAAO,CAAC,qBAAqB,CAAC;CAC9C,CAAA"} \ No newline at end of file diff --git a/remix-tests/dist/runTestFiles.d.ts b/remix-tests/dist/runTestFiles.d.ts new file mode 100644 index 0000000000..3d69ac0fe3 --- /dev/null +++ b/remix-tests/dist/runTestFiles.d.ts @@ -0,0 +1,2 @@ +declare function runTestFiles(filepath: any, isDirectory: any, web3: any, opts: any): void; +export = runTestFiles; diff --git a/remix-tests/dist/runTestFiles.js b/remix-tests/dist/runTestFiles.js new file mode 100644 index 0000000000..e078436c36 --- /dev/null +++ b/remix-tests/dist/runTestFiles.js @@ -0,0 +1,131 @@ +"use strict"; +var async = require("async"); +var path = require("path"); +var fs = require("./fs"); +var runTest = require("./testRunner.js"); +require('colors'); +var Compiler = require("./compiler.js"); +var Deployer = require("./deployer.js"); +function runTestFiles(filepath, isDirectory, web3, opts) { + opts = opts || {}; + var Signale = require('signale').Signale; + // signale configuration + var options = { + types: { + result: { + badge: '\t✓', + label: '', + color: 'greenBright' + }, + name: { + badge: '\n\t◼', + label: '', + color: 'white' + }, + error: { + badge: '\t✘', + label: '', + color: 'redBright' + } + } + }; + var signale = new Signale(options); + var accounts = opts.accounts || null; + async.waterfall([ + function getAccountList(next) { + if (accounts) + return next(null); + web3.eth.getAccounts(function (_err, _accounts) { + accounts = _accounts; + next(null); + }); + }, + function compile(next) { + Compiler.compileFileOrFiles(filepath, isDirectory, { accounts: accounts }, next); + }, + function deployAllContracts(compilationResult, next) { + Deployer.deployAll(compilationResult, web3, function (err, contracts) { + if (err) { + next(err); + } + next(null, compilationResult, contracts); + }); + }, + function determineTestContractsToRun(compilationResult, contracts, next) { + var contractsToTest = []; + var contractsToTestDetails = []; + var gatherContractsFrom = function (filename) { + if (filename.indexOf('_test.sol') < 0) { + return; + } + Object.keys(compilationResult[path.basename(filename)]).forEach(function (contractName) { + contractsToTest.push(contractName); + contractsToTestDetails.push(compilationResult[path.basename(filename)][contractName]); + }); + }; + if (isDirectory) { + fs.walkSync(filepath, function (foundpath) { + gatherContractsFrom(foundpath); + }); + } + else { + gatherContractsFrom(filepath); + } + next(null, contractsToTest, contractsToTestDetails, contracts); + }, + function runTests(contractsToTest, contractsToTestDetails, contracts, next) { + var totalPassing = 0; + var totalFailing = 0; + var totalTime = 0; + var errors = []; + var testCallback = function (result) { + if (result.type === 'contract') { + signale.name(result.value.white); + } + else if (result.type === 'testPass') { + signale.result(result.value); + } + else if (result.type === 'testFailure') { + signale.result(result.value.red); + errors.push(result); + } + }; + var resultsCallback = function (_err, result, cb) { + totalPassing += result.passingNum; + totalFailing += result.failureNum; + totalTime += result.timePassed; + cb(); + }; + async.eachOfLimit(contractsToTest, 1, function (contractName, index, cb) { + runTest(contractName, contracts(contractName), contractsToTestDetails[index], { accounts: accounts }, testCallback, function (err, result) { + if (err) { + return cb(err); + } + resultsCallback(null, result, cb); + }); + }, function (err) { + if (err) { + return next(err); + } + console.log('\n'); + if (totalPassing > 0) { + console.log(('%c ' + totalPassing + ' passing ') + ('%c(' + totalTime + 's)'), 'color: green', 'color: grey'); + } + if (totalFailing > 0) { + console.log(('%c ' + totalFailing + ' failing'), 'color: red'); + } + console.log(''); + errors.forEach(function (error, index) { + console.log(' ' + (index + 1) + ') ' + error.context + ' ' + error.value); + console.log(''); + console.log(('%c\t error: ' + error.errMsg), 'color: red'); + }); + console.log(''); + next(); + }); + } + ], function () { + }); +} +module.exports = runTestFiles; +//# sourceMappingURL=runTestFiles.js.map \ No newline at end of file diff --git a/remix-tests/dist/runTestFiles.js.map b/remix-tests/dist/runTestFiles.js.map new file mode 100644 index 0000000000..e24ff21c44 --- /dev/null +++ b/remix-tests/dist/runTestFiles.js.map @@ -0,0 +1 @@ +{"version":3,"file":"runTestFiles.js","sourceRoot":"","sources":["../src/runTestFiles.ts"],"names":[],"mappings":";AAAA,6BAA+B;AAC/B,2BAA6B;AAC7B,yBAA2B;AAC3B,yCAA2C;AAC3C,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEjB,wCAA0C;AAC1C,wCAA0C;AAE1C,SAAS,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI;IACnD,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACT,IAAA,oCAAO,CAAuB;IACtC,wBAAwB;IACxB,IAAM,OAAO,GAAG;QACZ,KAAK,EAAE;YACH,MAAM,EAAE;gBACJ,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,aAAa;aACvB;YACD,I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AO,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC,EAAC,YAAY,CAAC,CAAA;iBACjE;gBACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;gBAEf,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,KAAK;oBACxB,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,GAAG,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;oBAC1E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;oBACf,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,EAAC,YAAY,CAAC,CAAA;gBAC7D,CAAC,CAAC,CAAA;gBACF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;gBAEf,IAAI,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;QACN,CAAC;KACJ,EAAE;IACH,CAAC,CAAC,CAAA;AACN,CAAC;AAED,iBAAS,YAAY,CAAC"} \ No newline at end of file diff --git a/remix-tests/dist/runTestSources.d.ts b/remix-tests/dist/runTestSources.d.ts new file mode 100644 index 0000000000..cd355186f4 --- /dev/null +++ b/remix-tests/dist/runTestSources.d.ts @@ -0,0 +1,2 @@ +declare function runTestSources(contractSources: any, testCallback: any, resultCallback: any, finalCallback: any, importFileCb: any, opts: any): void; +export = runTestSources; diff --git a/remix-tests/dist/runTestSources.js b/remix-tests/dist/runTestSources.js new file mode 100644 index 0000000000..76841aa4f5 --- /dev/null +++ b/remix-tests/dist/runTestSources.js @@ -0,0 +1,106 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +var async = require("async"); +require('colors'); +var Compiler = require("./compiler.js"); +var Deployer = require("./deployer.js"); +var runTest = require("./testRunner.js"); +var Web3 = require("web3"); +var remix_simulator_1 = __importDefault(require("remix-simulator")); +var createWeb3Provider = function () { + var web3 = new Web3(); + web3.setProvider(new remix_simulator_1.default()); + return web3; +}; +function runTestSources(contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) { + opts = opts || {}; + var web3 = opts.web3 || createWeb3Provider(); + var accounts = opts.accounts || null; + async.waterfall([ + function getAccountList(next) { + if (accounts) + return next(); + web3.eth.getAccounts(function (_err, _accounts) { + accounts = _accounts; + next(); + }); + }, + function compile(next) { + Compiler.compileContractSources(contractSources, importFileCb, next); + }, + function deployAllContracts(compilationResult, next) { + Deployer.deployAll(compilationResult, web3, function (err, contracts) { + if (err) { + next(err); + } + next(null, compilationResult, contracts); + }); + }, + function determineTestContractsToRun(compilationResult, contracts, next) { + var contractsToTest = []; + var contractsToTestDetails = []; + var _loop_1 = function (filename) { + if (filename.indexOf('_test.sol') < 0) { + return "continue"; + } + Object.keys(compilationResult[filename]).forEach(function (contractName) { + contractsToTestDetails.push(compilationResult[filename][contractName]); + contractsToTest.push(contractName); + }); + }; + for (var filename in compilationResult) { + _loop_1(filename); + } + next(null, contractsToTest, contractsToTestDetails, contracts); + }, + function runTests(contractsToTest, contractsToTestDetails, contracts, next) { + var totalPassing = 0; + var totalFailing = 0; + var totalTime = 0; + var errors = []; + var _testCallback = function (result) { + if (result.type === 'testFailure') { + errors.push(result); + } + testCallback(result); + }; + var _resultsCallback = function (_err, result, cb) { + resultCallback(_err, result, function () { }); + totalPassing += result.passingNum; + totalFailing += result.failureNum; + totalTime += result.timePassed; + cb(); + }; + async.eachOfLimit(contractsToTest, 1, function (contractName, index, cb) { + runTest(contractName, contracts(contractName), contractsToTestDetails[index], { accounts: accounts }, _testCallback, function (err, result) { + if (err) { + return cb(err); + } + _resultsCallback(null, result, cb); + }); + }, function (err) { + if (err) { + return next(err); + } + var finalResults = { + totalPassing: 0, + totalFailing: 0, + totalTime: 0, + errors: [], + }; + finalResults.totalPassing = totalPassing || 0; + finalResults.totalFailing = totalFailing || 0; + finalResults.totalTime = totalTime || 0; + finalResults.errors = []; + errors.forEach(function (error, _index) { + finalResults.errors.push({ context: error.context, value: error.value, message: error.errMsg }); + }); + next(null, finalResults); + }); + } + ], finalCallback); +} +module.exports = runTestSources; +//# sourceMappingURL=runTestSources.js.map \ No newline at end of file diff --git a/remix-tests/dist/runTestSources.js.map b/remix-tests/dist/runTestSources.js.map new file mode 100644 index 0000000000..0d4fbb638a --- /dev/null +++ b/remix-tests/dist/runTestSources.js.map @@ -0,0 +1 @@ +{"version":3,"file":"runTestSources.js","sourceRoot":"","sources":["../src/runTestSources.ts"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEjB,wCAA0C;AAC1C,wCAA0C;AAC1C,yCAA2C;AAE3C,2BAA6B;AAC7B,oEAAsC;AAStC,IAAI,kBAAkB,GAAG;IACrB,IAAI,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACrB,IAAI,CAAC,WAAW,CAAC,IAAI,yBAAQ,EAAE,CAAC,CAAA;IAChC,OAAO,IAAI,CAAA;AACf,CAAC,CAAA;AAED,SAAS,cAAc,CAAC,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,IAAI;IACpG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACjB,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAAA;IAC5C,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAA;IACpC,KAAK,CAAC,SAAS,CAAC;QACZ,SAAS,cAAc,CAAE,IAAI;YACzB,IAAI,QAAQ;gBAAE,OAAO,IAAI,EAAE,CAAA;YAC3B,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,UAAC,IAAI,EAAE,SAAS;gBACjC,QAAQ,GAAG,SAAS,CAAA;gBACpB,IAAI,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;QACN,CA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AC,CAAA;gBAC7C,YAAY,CAAC,YAAY,GAAG,YAAY,IAAI,CAAC,CAAA;gBAC7C,YAAY,CAAC,SAAS,GAAG,SAAS,IAAI,CAAC,CAAA;gBACvC,YAAY,CAAC,MAAM,GAAG,EAAE,CAAA;gBAExB,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,MAAM;oBACzB,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAC,CAAC,CAAA;gBACjG,CAAC,CAAC,CAAA;gBAEF,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;YAC5B,CAAC,CAAC,CAAA;QACN,CAAC;KACJ,EAAE,aAAa,CAAC,CAAA;AACrB,CAAC;AACD,iBAAS,cAAc,CAAC"} \ No newline at end of file diff --git a/remix-tests/dist/testRunner.d.ts b/remix-tests/dist/testRunner.d.ts new file mode 100644 index 0000000000..39d1b16101 --- /dev/null +++ b/remix-tests/dist/testRunner.d.ts @@ -0,0 +1,2 @@ +declare function runTest(testName: any, testObject: any, contractDetails: any, opts: any, testCallback: any, resultsCallback: any): void; +export = runTest; diff --git a/remix-tests/src/testRunner.js b/remix-tests/dist/testRunner.js similarity index 98% rename from remix-tests/src/testRunner.js rename to remix-tests/dist/testRunner.js index 4f70ecba1c..23b7355b78 100644 --- a/remix-tests/src/testRunner.js +++ b/remix-tests/dist/testRunner.js @@ -1,5 +1,4 @@ "use strict"; -exports.__esModule = true; var async = require("async"); var changeCase = require("change-case"); var Web3 = require("web3"); @@ -132,4 +131,5 @@ function runTest(testName, testObject, contractDetails, opts, testCallback, resu }); }); } -exports.runTest = runTest; +module.exports = runTest; +//# sourceMappingURL=testRunner.js.map \ No newline at end of file diff --git a/remix-tests/dist/testRunner.js.map b/remix-tests/dist/testRunner.js.map new file mode 100644 index 0000000000..bbf4bbacd1 ---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 No newline at end of file diff --git a/remix-tests/package.json b/remix-tests/package.json index bb58c0a207..c6d2155b08 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -52,6 +52,8 @@ "yo-yoify": "latest" }, "devDependencies": { + "@types/mocha": "^5.2.5", + "@types/node": "^10.12.21", "babel-preset-es2017": "^6.24.1", "mocha": "^5.1.0", "standard": "^10.0.3", diff --git a/remix-tests/src/_index.js b/remix-tests/src/_index.js deleted file mode 100644 index b2b64a0430..0000000000 --- a/remix-tests/src/_index.js +++ /dev/null @@ -1,10 +0,0 @@ -const runTestFiles = require('./runTestFiles.js') -const runTestSources = require('./runTestSources.js') -const TestRunner = require('./testRunner.js') - -module.exports = { - runTestFiles: runTestFiles, - runTestSources: runTestSources, - runTest: TestRunner.runTest, - assertLibCode: require('../sol/tests.sol.js') -} diff --git a/remix-tests/src/_runTestFiles.js b/remix-tests/src/_runTestFiles.js deleted file mode 100644 index a733b76efd..0000000000 --- a/remix-tests/src/_runTestFiles.js +++ /dev/null @@ -1,133 +0,0 @@ -const async = require('async') -const path = require('path') -const fs = require('./fs') -const TestRunner = require('./testRunner.js') -require('colors') - -let Compiler = require('./compiler.js') -let Deployer = require('./deployer.js') - -const runTestFiles = function (filepath, isDirectory, web3, opts) { - opts = opts || {} - const { Signale } = require('signale') - // signale configuration - const options = { - types: { - result: { - badge: '\t✓', - label: '', - color: 'greenBright' - }, - name: { - badge: '\n\t◼', - label: '', - color: 'white' - }, - error: { - badge: '\t✘', - label: '', - color: 'redBright' - } - } - } - const signale = new Signale(options) - let accounts = opts.accounts || null - async.waterfall([ - function getAccountList (next) { - if (accounts) return next(null) - web3.eth.getAccounts((_err, _accounts) => { - accounts = _accounts - next(null) - }) - }, - function compile (next) { - Compiler.compileFileOrFiles(filepath, isDirectory, { accounts }, next) - }, - function deployAllContracts (compilationResult, next) { - Deployer.deployAll(compilationResult, web3, function (err, contracts) { - if (err) { - next(err) - } - next(null, compilationResult, contracts) - }) - }, - function determineTestContractsToRun (compilationResult, contracts, next) { - let contractsToTest = [] - let contractsToTestDetails = [] - const gatherContractsFrom = (filename) => { - if (filename.indexOf('_test.sol') < 0) { - return - } - Object.keys(compilationResult[path.basename(filename)]).forEach(contractName => { - contractsToTest.push(contractName) - contractsToTestDetails.push(compilationResult[path.basename(filename)][contractName]) - }) - } - if (isDirectory) { - fs.walkSync(filepath, foundpath => { - gatherContractsFrom(foundpath) - }) - } else { - gatherContractsFrom(filepath) - } - next(null, contractsToTest, contractsToTestDetails, contracts) - }, - function runTests (contractsToTest, contractsToTestDetails, contracts, next) { - let totalPassing = 0 - let totalFailing = 0 - let totalTime = 0 - let errors = [] - - var testCallback = function (result) { - if (result.type === 'contract') { - signale.name(result.value.white) - } else if (result.type === 'testPass') { - signale.result(result.value) - } else if (result.type === 'testFailure') { - signale.result(result.value.red) - errors.push(result) - } - } - var resultsCallback = function (_err, result, cb) { - totalPassing += result.passingNum - totalFailing += result.failureNum - totalTime += result.timePassed - cb() - } - - async.eachOfLimit(contractsToTest, 1, (contractName, index, cb) => { - TestRunner.runTest(contractName, contracts[contractName], contractsToTestDetails[index], { accounts }, testCallback, (err, result) => { - if (err) { - return cb(err) - } - resultsCallback(null, result, cb) - }) - }, function (err, _results) { - if (err) { - return next(err) - } - - console.log('\n') - if (totalPassing > 0) { - console.log((' ' + totalPassing + ' passing ').green + ('(' + totalTime + 's)').grey) - } - if (totalFailing > 0) { - console.log((' ' + totalFailing + ' failing').red) - } - console.log('') - - errors.forEach((error, index) => { - console.log(' ' + (index + 1) + ') ' + error.context + ' ' + error.value) - console.log('') - console.log(('\t error: ' + error.errMsg).red) - }) - console.log('') - - next() - }) - } - ], function () { - }) -} - -module.exports = runTestFiles diff --git a/remix-tests/src/_runTestSources.js b/remix-tests/src/_runTestSources.js deleted file mode 100644 index e91bd66a98..0000000000 --- a/remix-tests/src/_runTestSources.js +++ /dev/null @@ -1,107 +0,0 @@ -const async = require('async') -require('colors') - -let Compiler = require('./compiler.js') -let Deployer = require('./deployer.js') -let TestRunner = require('./testRunner.js') - -const Web3 = require('web3') -const Provider = require('remix-simulator').Provider - -var createWeb3Provider = function () { - let web3 = new Web3() - web3.setProvider(new Provider()) - return web3 -} - -const runTestSources = function (contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) { - opts = opts || {} - let web3 = opts.web3 || createWeb3Provider() - let accounts = opts.accounts || null - async.waterfall([ - function getAccountList (next) { - if (accounts) return next() - web3.eth.getAccounts((_err, _accounts) => { - accounts = _accounts - next() - }) - }, - function compile (next) { - Compiler.compileContractSources(contractSources, importFileCb, next) - }, - function deployAllContracts (compilationResult, next) { - Deployer.deployAll(compilationResult, web3, function (err, contracts) { - if (err) { - next(err) - } - - next(null, compilationResult, contracts) - }) - }, - function determineTestContractsToRun (compilationResult, contracts, next) { - let contractsToTest = [] - let contractsToTestDetails = [] - - for (let filename in compilationResult) { - if (filename.indexOf('_test.sol') < 0) { - continue - } - Object.keys(compilationResult[filename]).forEach(contractName => { - contractsToTestDetails.push(compilationResult[filename][contractName]) - contractsToTest.push(contractName) - }) - } - - next(null, contractsToTest, contractsToTestDetails, contracts) - }, - function runTests (contractsToTest, contractsToTestDetails, contracts, next) { - let totalPassing = 0 - let totalFailing = 0 - let totalTime = 0 - let errors = [] - - var _testCallback = function (result) { - if (result.type === 'testFailure') { - errors.push(result) - } - testCallback(result) - } - - var _resultsCallback = function (_err, result, cb) { - resultCallback(_err, result, () => {}) - totalPassing += result.passingNum - totalFailing += result.failureNum - totalTime += result.timePassed - cb() - } - - async.eachOfLimit(contractsToTest, 1, (contractName, index, cb) => { - TestRunner.runTest(contractName, contracts[contractName], contractsToTestDetails[index], { accounts }, _testCallback, (err, result) => { - if (err) { - return cb(err) - } - _resultsCallback(null, result, cb) - }) - }, function (err, _results) { - if (err) { - return next(err) - } - - let finalResults = {} - - finalResults.totalPassing = totalPassing || 0 - finalResults.totalFailing = totalFailing || 0 - finalResults.totalTime = totalTime || 0 - finalResults.errors = [] - - errors.forEach((error, _index) => { - finalResults.errors.push({context: error.context, value: error.value, message: error.errMsg}) - }) - - next(null, finalResults) - }) - } - ], finalCallback) -} - -module.exports = runTestSources diff --git a/remix-tests/src/_testRunner.js b/remix-tests/src/_testRunner.js deleted file mode 100644 index ee2a385ea5..0000000000 --- a/remix-tests/src/_testRunner.js +++ /dev/null @@ -1,149 +0,0 @@ -var async = require('async') -var changeCase = require('change-case') -var Web3 = require('web3') - -function getFunctionFullName (signature, methodIdentifiers) { - for (var method in methodIdentifiers) { - if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { - return method - } - } - return null -} - -function getOverridedSender (userdoc, signature, methodIdentifiers) { - let fullName = getFunctionFullName(signature, methodIdentifiers) - let match = /sender: account-+(\d)/g - let accountIndex = userdoc.methods[fullName] ? match.exec(userdoc.methods[fullName].notice) : null - return fullName && accountIndex ? accountIndex[1] : null -} - -function getAvailableFunctions (jsonInterface) { - return jsonInterface.reverse().filter((x) => x.type === 'function').map((x) => x.name) -} - -function getTestFunctions (jsonInterface) { - let specialFunctions = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'] - return jsonInterface.filter((x) => specialFunctions.indexOf(x.name) < 0 && x.type === 'function') -} - -function createRunList (jsonInterface) { - let availableFunctions = getAvailableFunctions(jsonInterface) - let testFunctions = getTestFunctions(jsonInterface) - let runList = [] - - if (availableFunctions.indexOf('beforeAll') >= 0) { - runList.push({name: 'beforeAll', type: 'internal', constant: false}) - } - - for (let func of testFunctions) { - if (availableFunctions.indexOf('beforeEach') >= 0) { - runList.push({name: 'beforeEach', type: 'internal', constant: false}) - } - runList.push({name: func.name, signature: func.signature, type: 'test', constant: func.constant}) - if (availableFunctions.indexOf('afterEach') >= 0) { - runList.push({name: 'afterEach', type: 'internal', constant: false}) - } - } - - if (availableFunctions.indexOf('afterAll') >= 0) { - runList.push({name: 'afterAll', type: 'internal', constant: false}) - } - - return runList -} - -function runTest (testName, testObject, contractDetails, opts, testCallback, resultsCallback) { - let runList = createRunList(testObject._jsonInterface) - - let passingNum = 0 - let failureNum = 0 - let timePassed = 0 - let web3 = new Web3() - - var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' - var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) - if (!isBrowser) { - let signale = require('signale') - signale.warn('DO NOT TRY TO ACCESS (IN YOUR SOLIDITY TEST) AN ACCOUNT GREATER THAN THE LENGTH OF THE FOLLOWING ARRAY (' + opts.accounts.length + ') :') - signale.warn(opts.accounts) - signale.warn('e.g: the following code won\'t work in the current context:') - signale.warn('TestsAccounts.getAccount(' + opts.accounts.length + ')') - } - - testCallback({type: 'contract', value: testName, filename: testObject.filename}) - async.eachOfLimit(runList, 1, function (func, index, next) { - let sender - if (func.signature) { - sender = getOverridedSender(contractDetails.userdoc, func.signature, contractDetails.evm.methodIdentifiers) - if (opts.accounts) { - sender = opts.accounts[sender] - } - } - let sendParams - if (sender) sendParams = { from: sender } - - let method = testObject.methods[func.name].apply(testObject.methods[func.name], []) - let startTime = Date.now() - if (func.constant) { - method.call(sendParams).then((result) => { - let time = Math.ceil((Date.now() - startTime) / 1000.0) - if (result) { - testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName}) - passingNum += 1 - timePassed += time - } else { - testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: 'function returned false', context: testName}) - failureNum += 1 - } - next() - }) - } else { - method.send(sendParams).on('receipt', function (receipt) { - try { - let time = Math.ceil((Date.now() - startTime) / 1000.0) - let topic = Web3.utils.sha3('AssertionEvent(bool,string)') - - let testPassed = false - - for (let i in receipt.events) { - let event = receipt.events[i] - if (event.raw.topics.indexOf(topic) >= 0) { - var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data) - if (!testEvent[0]) { - testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: testEvent[1], context: testName}) - failureNum += 1 - return next() - } - testPassed = true - } - } - - if (testPassed) { - testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName}) - passingNum += 1 - } - - return next() - } catch (err) { - console.log('error!') - console.dir(err) - return next(err) - } - }).on('error', function (err) { - console.error(err) - next(err) - }) - } - }, function (error) { - resultsCallback(error, { - passingNum: passingNum, - failureNum: failureNum, - timePassed: timePassed - }) - }) -} - -module.exports = { - runTest: runTest -} diff --git a/remix-tests/tests/testRunner.js b/remix-tests/tests/testRunner.js deleted file mode 100644 index 092052fb7f..0000000000 --- a/remix-tests/tests/testRunner.js +++ /dev/null @@ -1,198 +0,0 @@ -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') -const Provider = require('remix-simulator').Provider - -function compileAndDeploy (filename, callback) { - let web3 = new Web3() - web3.setProvider(new Provider()) - let compilationData - let accounts - async.waterfall([ - function getAccountList (next) { - web3.eth.getAccounts((_err, _accounts) => { - accounts = _accounts - next(_err) - }) - }, - function compile (next) { - Compiler.compileFileOrFiles(filename, false, {accounts}, next) - }, - function deployAllContracts (compilationResult, next) { - compilationData = compilationResult - Deployer.deployAll(compilationResult, web3, next) - } - ], function (_err, contracts) { - callback(null, compilationData, contracts, accounts) - }) -} - - -describe('testRunner', function () { - 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, compilationData, contracts, accounts) { - var testCallback = function (test) { - tests.push(test) - } - var resultsCallback = function (_err, _results) { - results = _results - done() - } - TestRunner.runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) - }) - }) - - it('should 1 passing test', function () { - assert.equal(results.passingNum, 2) - }) - - it('should 1 failing test', function () { - assert.equal(results.failureNum, 2) - }) - - it('should returns 5 messages', function () { - assert.deepEqual(tests, [ - { type: 'contract', value: 'MyTest', filename: 'tests/examples_1/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: 'testFailure', value: 'Initial value should be200', time: 1, context: 'MyTest', errMsg: 'function returned false' } - ]) - }) - }) - - describe('test with beforeEach', function () { - let filename = 'tests/examples_2/simple_storage_test.sol' - let tests = [], results = {} - - before(function (done) { - compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { - var testCallback = function (test) { - tests.push(test) - } - var resultsCallback = function (_err, _results) { - results = _results - done() - } - TestRunner.runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) - }) - }) - - it('should 2 passing tests', function () { - assert.equal(results.passingNum, 2) - }) - - it('should 0 failing tests', function () { - assert.equal(results.failureNum, 0) - }) - - it('should returns 3 messages', function () { - assert.deepEqual(tests, [ - { type: 'contract', value: 'MyTest', filename: 'tests/examples_2/simple_storage_test.sol' }, - { type: 'testPass', value: 'Initial value should be100', time: 1, context: 'MyTest' }, - { type: 'testPass', value: 'Initial value should be200', time: 1, context: 'MyTest' } - ]) - }) - }) - - // Test string equality - describe('test string equality', function () { - let filename = 'tests/examples_3/simple_string_test.sol' - let tests = [], results = {} - - before(function (done) { - compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { - var testCallback = function (test) { - tests.push(test) - } - var resultsCallback = function (_err, _results) { - results = _results - done() - } - TestRunner.runTest('StringTest', contracts.StringTest, compilationData[filename]['StringTest'], { accounts }, testCallback, resultsCallback) - TestRunner.runTest('StringTest2', contracts.StringTest2, compilationData[filename]['StringTest2'], { accounts }, testCallback, resultsCallback) - }) - }) - - it('should 2 passing tests', function () { - assert.equal(results.passingNum, 2) - }) - - it('should 1 failing tests', function () { - assert.equal(results.failureNum, 1) - }) - - it('should returns 3 messages', function () { - assert.deepEqual(tests, [ - { type: 'contract', value: 'StringTest', filename: 'tests/examples_3/simple_string_test.sol' }, - { type: 'testFailure', value: 'Value should be hello world', time: 1, context: 'StringTest', "errMsg": "initial value is not correct" }, - { type: 'testPass', value: 'Value should not be hello wordl', time: 1, context: 'StringTest' }, - { type: 'testPass', value: 'Initial value should be hello', time: 1, context: 'StringTest' }, - ]) - }) - }) - - // Test signed/unsigned integer weight - describe('test number weight', function () { - let filename = 'tests/number/number_test.sol' - let tests = [], results = {} - - before(function (done) { - compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { - var testCallback = function (test) { - tests.push(test) - } - var resultsCallback = function (_err, _results) { - results = _results - done() - } - TestRunner.runTest('IntegerTest', contracts.IntegerTest, compilationData[filename]['IntegerTest'], { accounts }, testCallback, resultsCallback) - }) - }) - - it('should have 6 passing tests', function () { - assert.equal(results.passingNum, 6) - }) - it('should have 2 failing tests', function () { - assert.equal(results.failureNum, 2) - }) - }) - - // Test Transaction with different sender - describe('various sender', function () { - let filename = 'tests/various_sender/sender_test.sol' - let tests = [], results = {} - - before(function (done) { - compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { - var testCallback = function (test) { - tests.push(test) - } - var resultsCallback = function (_err, _results) { - results = _results - done() - } - - TestRunner.runTest('SenderTest', contracts.SenderTest, compilationData[filename]['SenderTest'], { accounts }, testCallback, resultsCallback) - - }) - }) - - it('should have 4 passing tests', function () { - assert.equal(results.passingNum, 4) - }) - it('should have 1 failing tests', function () { - assert.equal(results.failureNum, 0) - }) - }) - }) -}) diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index e69de29bb2..7008c10a2c 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -0,0 +1,203 @@ +import async = require('async') +import Web3 = require('web3') +import assert = require('assert') + +let Compiler = require('../src/compiler.js') +let Deployer = require('../src/deployer.js') +let TestRunner = require('../src/testRunner.ts') +const Provider = require('remix-simulator').Provider + +interface Results { + passingNum: number, + failureNum: number, +} + +function compileAndDeploy (filename, callback) { + let web3 = new Web3() + web3.setProvider(new Provider()) + let compilationData + let accounts + async.waterfall([ + function getAccountList (next) { + web3.eth.getAccounts((_err, _accounts) => { + accounts = _accounts + next(_err) + }) + }, + function compile (next) { + Compiler.compileFileOrFiles(filename, false, {accounts}, next) + }, + function deployAllContracts (compilationResult, next) { + compilationData = compilationResult + Deployer.deployAll(compilationResult, web3, next) + } + ], function (_err, contracts) { + callback(null, compilationData, contracts, accounts) + }) + } + + + describe('testRunner', function () { + describe('#runTest', function() { + describe('test with beforeAll', function () { + let filename = 'tests/examples_1/simple_storage_test.sol' + let tests:any[] = [], results:Results; + + before(function (done) { + compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + var testCallback = function (test) { + tests.push(test) + } + var resultsCallback = function (_err, _results) { + results = _results + done() + } + TestRunner.runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) + }) + }) + + it('should 1 passing test', function () { + assert.equal(results.passingNum, 2) + }) + + it('should 1 failing test', function () { + assert.equal(results.failureNum, 2) + }) + + it('should returns 5 messages', function () { + assert.deepEqual(tests, [ + { type: 'contract', value: 'MyTest', filename: 'tests/examples_1/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: 'testFailure', value: 'Initial value should be200', time: 1, context: 'MyTest', errMsg: 'function returned false' } + ]) + }) + }) + + describe('test with beforeEach', function () { + let filename = 'tests/examples_2/simple_storage_test.sol' + let tests:any[] = [], results:Results; + + before(function (done) { + compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + var testCallback = function (test) { + tests.push(test) + } + var resultsCallback = function (_err, _results) { + results = _results + done() + } + TestRunner.runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) + }) + }) + + it('should 2 passing tests', function () { + assert.equal(results.passingNum, 2) + }) + + it('should 0 failing tests', function () { + assert.equal(results.failureNum, 0) + }) + + it('should returns 3 messages', function () { + assert.deepEqual(tests, [ + { type: 'contract', value: 'MyTest', filename: 'tests/examples_2/simple_storage_test.sol' }, + { type: 'testPass', value: 'Initial value should be100', time: 1, context: 'MyTest' }, + { type: 'testPass', value: 'Initial value should be200', time: 1, context: 'MyTest' } + ]) + }) + }) + + // Test string equality + describe('test string equality', function () { + let filename = 'tests/examples_3/simple_string_test.sol' + let tests:any[] = [], results:Results; + + before(function (done) { + compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + var testCallback = function (test) { + tests.push(test) + } + var resultsCallback = function (_err, _results) { + results = _results + done() + } + TestRunner.runTest('StringTest', contracts.StringTest, compilationData[filename]['StringTest'], { accounts }, testCallback, resultsCallback) + TestRunner.runTest('StringTest2', contracts.StringTest2, compilationData[filename]['StringTest2'], { accounts }, testCallback, resultsCallback) + }) + }) + + it('should 2 passing tests', function () { + assert.equal(results.passingNum, 2) + }) + + it('should 1 failing tests', function () { + assert.equal(results.failureNum, 1) + }) + + it('should returns 3 messages', function () { + assert.deepEqual(tests, [ + { type: 'contract', value: 'StringTest', filename: 'tests/examples_3/simple_string_test.sol' }, + { type: 'testFailure', value: 'Value should be hello world', time: 1, context: 'StringTest', "errMsg": "initial value is not correct" }, + { type: 'testPass', value: 'Value should not be hello wordl', time: 1, context: 'StringTest' }, + { type: 'testPass', value: 'Initial value should be hello', time: 1, context: 'StringTest' }, + ]) + }) + }) + + // Test signed/unsigned integer weight + describe('test number weight', function () { + let filename = 'tests/number/number_test.sol' + let tests:any[] = [], results:Results; + + before(function (done) { + compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + var testCallback = function (test) { + tests.push(test) + } + var resultsCallback = function (_err, _results) { + results = _results + done() + } + TestRunner.runTest('IntegerTest', contracts.IntegerTest, compilationData[filename]['IntegerTest'], { accounts }, testCallback, resultsCallback) + }) + }) + + it('should have 6 passing tests', function () { + assert.equal(results.passingNum, 6) + }) + it('should have 2 failing tests', function () { + assert.equal(results.failureNum, 2) + }) + }) + + // Test Transaction with different sender + describe('various sender', function () { + let filename = 'tests/various_sender/sender_test.sol' + let tests:any[] = [], results:Results; + + before(function (done) { + compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + var testCallback = function (test) { + tests.push(test) + } + var resultsCallback = function (_err, _results) { + results = _results + done() + } + + TestRunner.runTest('SenderTest', contracts.SenderTest, compilationData[filename]['SenderTest'], { accounts }, testCallback, resultsCallback) + + }) + }) + + it('should have 4 passing tests', function () { + assert.equal(results.passingNum, 4) + }) + it('should have 1 failing tests', function () { + assert.equal(results.failureNum, 0) + }) + }) + }) + }) \ No newline at end of file diff --git a/remix-tests/tsconfig.json b/remix-tests/tsconfig.json index 64f82972b0..df84217c0b 100644 --- a/remix-tests/tsconfig.json +++ b/remix-tests/tsconfig.json @@ -1,4 +1,5 @@ { + "include": ["src"], "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ @@ -16,7 +17,10 @@ "paths": { "remix-tests": ["./"] }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ "typeRoots": ["node_modules/@types"], /* List of folders to include type definitions from. */ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - + "types": [ + "mocha", + "node" + ], /* Experimental Options */ "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ }