From 9385365717ba0ddaa5d68c98b1c02f9f58fe609c Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Mon, 28 Jan 2019 18:40:04 +0530 Subject: [PATCH 01/19] add remix-tests tsconfig --- remix-tests/tsconfig.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 remix-tests/tsconfig.json diff --git a/remix-tests/tsconfig.json b/remix-tests/tsconfig.json new file mode 100644 index 0000000000..bf2cf3a40d --- /dev/null +++ b/remix-tests/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "lib": ["dom", "es2018"], /* Specify library files to be included in the compilation. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + "outDir": "./dist", /* Redirect output structure to the directory. */ + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ + + /* Module Resolution Options */ + "baseUrl": "./src", /* Base directory to resolve non-absolute module names. */ + "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'. */ + + /* Experimental Options */ + "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + } +} From 435120ab242600008e406dae6e1b2cffae36d129 Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Mon, 28 Jan 2019 19:07:21 +0530 Subject: [PATCH 02/19] Try to create a typescript version of remix-tests module --- remix-tests/package.json | 6 ++++-- remix-tests/src/index.ts | 10 ++++++++++ remix-tests/src/runTestFiles.ts | 0 remix-tests/src/runTestSources.ts | 0 remix-tests/src/testRunner.ts | 0 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 remix-tests/src/index.ts create mode 100644 remix-tests/src/runTestFiles.ts create mode 100644 remix-tests/src/runTestSources.ts create mode 100644 remix-tests/src/testRunner.ts diff --git a/remix-tests/package.json b/remix-tests/package.json index a78636e48f..7ec98e760e 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -2,7 +2,8 @@ "name": "remix-tests", "version": "0.1.1", "description": "Tests for the Ethereum tool suite Remix", - "main": "./src/index.js", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "contributors": [ { "name": "Iuri Matias", @@ -17,8 +18,9 @@ "remix-tests": "./bin/remix-tests" }, "scripts": { + "build": "tsc", "lint": "standard", - "test": "standard && mocha tests/ -t 300000" + "test": "standard && mocha --require ts-node/register tests/*.ts -t 300000" }, "repository": { "type": "git", diff --git a/remix-tests/src/index.ts b/remix-tests/src/index.ts new file mode 100644 index 0000000000..9b79dfdff6 --- /dev/null +++ b/remix-tests/src/index.ts @@ -0,0 +1,10 @@ +import runTestFiles from './runTestFiles.ts' +import runTestSources from './runTestSources.ts' +import TestRunner from './testRunner.ts' + +module.exports = { + runTestFiles: runTestFiles, + runTestSources: runTestSources, + runTest: TestRunner.runTest, + assertLibCode: require('../sol/tests.sol.js') +} diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts new file mode 100644 index 0000000000..e69de29bb2 From 3a46a2fd4b236c7caa2d20746b6661723f47b9cc Mon Sep 17 00:00:00 2001 From: Sabyasachi Patra Date: Sun, 3 Feb 2019 18:16:23 +0530 Subject: [PATCH 03/19] migrated to ts [WIP] --- remix-tests/src/{index.js => _index.js} | 0 .../src/{runTestFiles.js => _runTestFiles.js} | 0 .../{runTestSources.js => _runTestSources.js} | 0 remix-tests/src/_testRunner.js | 149 ++++++++++ remix-tests/src/index.ts | 8 +- remix-tests/src/runTestFiles.ts | 133 +++++++++ remix-tests/src/runTestSources.ts | 118 ++++++++ remix-tests/src/testRunner.js | 260 +++++++++--------- remix-tests/src/testRunner.ts | 147 ++++++++++ remix-tests/tsconfig.json | 2 +- 10 files changed, 675 insertions(+), 142 deletions(-) rename remix-tests/src/{index.js => _index.js} (100%) rename remix-tests/src/{runTestFiles.js => _runTestFiles.js} (100%) rename remix-tests/src/{runTestSources.js => _runTestSources.js} (100%) create mode 100644 remix-tests/src/_testRunner.js diff --git a/remix-tests/src/index.js b/remix-tests/src/_index.js similarity index 100% rename from remix-tests/src/index.js rename to remix-tests/src/_index.js diff --git a/remix-tests/src/runTestFiles.js b/remix-tests/src/_runTestFiles.js similarity index 100% rename from remix-tests/src/runTestFiles.js rename to remix-tests/src/_runTestFiles.js diff --git a/remix-tests/src/runTestSources.js b/remix-tests/src/_runTestSources.js similarity index 100% rename from remix-tests/src/runTestSources.js rename to remix-tests/src/_runTestSources.js diff --git a/remix-tests/src/_testRunner.js b/remix-tests/src/_testRunner.js new file mode 100644 index 0000000000..ee2a385ea5 --- /dev/null +++ b/remix-tests/src/_testRunner.js @@ -0,0 +1,149 @@ +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/src/index.ts b/remix-tests/src/index.ts index 9b79dfdff6..03aec74397 100644 --- a/remix-tests/src/index.ts +++ b/remix-tests/src/index.ts @@ -1,10 +1,10 @@ -import runTestFiles from './runTestFiles.ts' -import runTestSources from './runTestSources.ts' -import TestRunner from './testRunner.ts' +import runTestFiles from './runTestFiles' +import runTestSources from './runTestSources' +import runTest from './testRunner' module.exports = { runTestFiles: runTestFiles, runTestSources: runTestSources, - runTest: TestRunner.runTest, + runTest: runTest, assertLibCode: require('../sol/tests.sol.js') } diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index e69de29bb2..9000900abd 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -0,0 +1,133 @@ +import async = require('async') +import path = require('path') +import fs = require('./fs') +import runTest = require('./testRunner.js') +require('colors') + +import Compiler = require('./compiler.js') +import Deployer = require('./deployer.js') + +function runTestFiles(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: any[] = [] + let contractsToTestDetails: any[] = [] + 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: any[] = [] + + 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) => { + runTest(contractName, contracts(contractName), contractsToTestDetails[index], { accounts }, testCallback, (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((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 () { + }) +} + +export = runTestFiles; \ No newline at end of file diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index e69de29bb2..1b38e1da66 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -0,0 +1,118 @@ +import async = require('async') +require('colors') + +import Compiler = require('./compiler.js') +import Deployer = require('./deployer.js') +import runTest = require('./testRunner.js') + +import Web3 = require('web3') +import Provider from 'remix-simulator' + +interface FinalResult { + totalPassing: number, + totalFailing: number, + totalTime: number, + errors: any[], +} + +var createWeb3Provider = function () { + let web3 = new Web3() + web3.setProvider(new Provider()) + return web3 +} + +function runTestSources(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: any[] = [] + let contractsToTestDetails: any[] = [] + + 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: any[] = [] + + 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) => { + runTest(contractName, contracts(contractName), contractsToTestDetails[index], { accounts }, _testCallback, (err, result) => { + if (err) { + return cb(err) + } + _resultsCallback(null, result, cb) + }) + }, function (err) { + if (err) { + return next(err) + } + + let finalResults: FinalResult = { + totalPassing: 0, + totalFailing: 0, + totalTime: 0, + errors: [], + } + + 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) +} +export = runTestSources; \ No newline at end of file diff --git a/remix-tests/src/testRunner.js b/remix-tests/src/testRunner.js index ee2a385ea5..4f70ecba1c 100644 --- a/remix-tests/src/testRunner.js +++ b/remix-tests/src/testRunner.js @@ -1,149 +1,135 @@ -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 +"use strict"; +exports.__esModule = true; +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 + 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 getOverridedSender(userdoc, signature, methodIdentifiers) { + var fullName = getFunctionFullName(signature, methodIdentifiers); + var match = /sender: account-+(\d)/g; + var 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 getAvailableFunctions(jsonInterface) { + return jsonInterface.reverse().filter(function (x) { return x.type === 'function'; }).map(function (x) { return x.name; }); } - -function getTestFunctions (jsonInterface) { - let specialFunctions = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'] - return jsonInterface.filter((x) => specialFunctions.indexOf(x.name) < 0 && x.type === 'function') +function getTestFunctions(jsonInterface) { + var specialFunctions = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach']; + return jsonInterface.filter(function (x) { return 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}) +function createRunList(jsonInterface) { + var availableFunctions = getAvailableFunctions(jsonInterface); + var testFunctions = getTestFunctions(jsonInterface); + var runList = []; + if (availableFunctions.indexOf('beforeAll') >= 0) { + runList.push({ name: 'beforeAll', 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}) + for (var _i = 0, testFunctions_1 = testFunctions; _i < testFunctions_1.length; _i++) { + var func = testFunctions_1[_i]; + 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 + 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] - } +function runTest(testName, testObject, contractDetails, opts, testCallback, resultsCallback) { + var runList = createRunList(testObject._jsonInterface); + var passingNum = 0; + var failureNum = 0; + var timePassed = 0; + var web3 = new Web3(); + var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-'; + var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1); + if (!isBrowser) { + var 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 + ')'); } - 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 + testCallback({ type: 'contract', value: testName, filename: testObject.filename }); + async.eachOfLimit(runList, 1, function (func, index, next) { + var sender; + if (func.signature) { + sender = getOverridedSender(contractDetails.userdoc, func.signature, contractDetails.evm.methodIdentifiers); + if (opts.accounts) { + sender = opts.accounts[sender]; } - } - - 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 + var sendParams; + if (sender) + sendParams = { from: sender }; + var method = testObject.methods[func.name].apply(testObject.methods[func.name], []); + var startTime = Date.now(); + if (func.constant) { + method.call(sendParams).then(function (result) { + var 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 { + var time = Math.ceil((Date.now() - startTime) / 1000.0); + var topic = Web3.utils.sha3('AssertionEvent(bool,string)'); + var testPassed = false; + for (var i in receipt.events) { + var event_1 = receipt.events[i]; + if (event_1.raw.topics.indexOf(topic) >= 0) { + var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event_1.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 + }); + }); } +exports.runTest = runTest; diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index e69de29bb2..ef32e6c17f 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -0,0 +1,147 @@ +import async = require('async'); +import changeCase = require('change-case'); +import 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: any = 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: any[] = [] + + 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 + }) + }) +} + +export = runTest \ No newline at end of file diff --git a/remix-tests/tsconfig.json b/remix-tests/tsconfig.json index bf2cf3a40d..64f82972b0 100644 --- a/remix-tests/tsconfig.json +++ b/remix-tests/tsconfig.json @@ -15,7 +15,7 @@ "baseUrl": "./src", /* Base directory to resolve non-absolute module names. */ "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'. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ /* Experimental Options */ "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ From c0653fde5d8fca6576fa27a15ca89e721c74057b Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Mon, 4 Feb 2019 14:28:51 +0530 Subject: [PATCH 04/19] add typescript tests --- remix-tests/package.json | 9 +++++---- remix-tests/tests/testRunner.ts | 0 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 remix-tests/tests/testRunner.ts diff --git a/remix-tests/package.json b/remix-tests/package.json index 7ec98e760e..bb58c0a207 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -19,8 +19,7 @@ }, "scripts": { "build": "tsc", - "lint": "standard", - "test": "standard && mocha --require ts-node/register tests/*.ts -t 300000" + "test": "mocha --require ts-node/register tests/*.ts -t 300000" }, "repository": { "type": "git", @@ -53,8 +52,10 @@ "yo-yoify": "latest" }, "devDependencies": { - "mocha": "^5.1.0", "babel-preset-es2017": "^6.24.1", - "standard": "^10.0.3" + "mocha": "^5.1.0", + "standard": "^10.0.3", + "ts-node": "^8.0.2", + "typescript": "^3.3.1" } } diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts new file mode 100644 index 0000000000..e69de29bb2 From 03f1967f5096934f94866dfe0d25c9d25b908bfa Mon Sep 17 00:00:00 2001 From: Sab94 Date: Mon, 4 Feb 2019 15:44:59 +0530 Subject: [PATCH 05/19] test migrated to typescript --- remix-tests/dist/index.d.ts | 1 + remix-tests/dist/index.js | 15 ++ remix-tests/dist/index.js.map | 1 + remix-tests/dist/runTestFiles.d.ts | 2 + remix-tests/dist/runTestFiles.js | 131 +++++++++++++++ remix-tests/dist/runTestFiles.js.map | 1 + remix-tests/dist/runTestSources.d.ts | 2 + remix-tests/dist/runTestSources.js | 106 +++++++++++++ remix-tests/dist/runTestSources.js.map | 1 + remix-tests/dist/testRunner.d.ts | 2 + remix-tests/{src => dist}/testRunner.js | 4 +- remix-tests/dist/testRunner.js.map | 1 + remix-tests/package.json | 2 + remix-tests/src/_index.js | 10 -- remix-tests/src/_runTestFiles.js | 133 ---------------- remix-tests/src/_runTestSources.js | 107 ------------- remix-tests/src/_testRunner.js | 149 ----------------- remix-tests/tests/testRunner.js | 198 ----------------------- remix-tests/tests/testRunner.ts | 203 ++++++++++++++++++++++++ remix-tests/tsconfig.json | 6 +- 20 files changed, 475 insertions(+), 600 deletions(-) create mode 100644 remix-tests/dist/index.d.ts create mode 100644 remix-tests/dist/index.js create mode 100644 remix-tests/dist/index.js.map create mode 100644 remix-tests/dist/runTestFiles.d.ts create mode 100644 remix-tests/dist/runTestFiles.js create mode 100644 remix-tests/dist/runTestFiles.js.map create mode 100644 remix-tests/dist/runTestSources.d.ts create mode 100644 remix-tests/dist/runTestSources.js create mode 100644 remix-tests/dist/runTestSources.js.map create mode 100644 remix-tests/dist/testRunner.d.ts rename remix-tests/{src => dist}/testRunner.js (98%) create mode 100644 remix-tests/dist/testRunner.js.map delete mode 100644 remix-tests/src/_index.js delete mode 100644 remix-tests/src/_runTestFiles.js delete mode 100644 remix-tests/src/_runTestSources.js delete mode 100644 remix-tests/src/_testRunner.js delete mode 100644 remix-tests/tests/testRunner.js 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,IAA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AG,CAAC,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC,EAAC,cAAc,EAAC,aAAa,CAAC,CAAA;iBAC/G;gBACD,IAAI,YAAY,GAAG,CAAC,EAAE;oBAClB,OAAO,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,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CAAC;oBACf,YAAY,EAAE,CAAC;oBACf,SAAS,EAAE,CAAC;oBACZ,MAAM,EAAE,EAAE;iBACb,CAAA;gBAED,YAAY,CAAC,YAAY,GAAG,YAAY,IAAI,CAAC,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 --- /dev/null +++ b/remix-tests/dist/testRunner.js.map @@ -0,0 +1 @@ +{"version":3,"file":"testRunner.js","sourceRoot":"","sources":["../src/testRunner.ts"],"names":[],"mappings":";AAAA,6BAAgC;AAChC,wCAA2C;AAC3C,2BAA8B;AAE9B,SAAS,mBAAmB,CAAE,SAAS,EAAE,iBAAiB;IACtD,KAAK,IAAI,MAAM,IAAI,iBAAiB,EAAE;QAClC,IAAI,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE;YAC7E,OAAO,MAAM,CAAA;SAChB;KACJ;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AAED,SAAS,kBAAkB,CAAE,OAAO,EAAE,SAAS,EAAE,iBAAiB;IAC9D,IAAI,QAAQ,GAAQ,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAA;IACrE,IAAI,KAAK,GAAG,wBAAwB,CAAA;IACpC,IAAI,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAClG,OAAO,QAAQ,IAAI,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5D,CAAC;AAED,SAAS,qBAAqB,CAAE,aAAa;IACzC,OAAO,aAAa,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,KAAK,UAAU,EAArB,CAAqB,CAA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AE,UAAU;YACtB,UAAU,EAAE,UAAU;YACtB,UAAU,EAAE,UAAU;SACzB,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC;AAED,iBAAS,OAAO,CAAA"} \ 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. */ } From cd06975f8830207ddb1f4543e023db7e7be574a9 Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Mon, 4 Feb 2019 18:00:16 +0530 Subject: [PATCH 06/19] log transaction error --- remix-tests/package.json | 1 + remix-tests/src/deployer.js | 12 +++-- remix-tests/src/runTestSources.ts | 4 +- remix-tests/src/testRunner.ts | 8 ++-- remix-tests/tests/testRunner.ts | 77 ++++++++++++++++--------------- 5 files changed, 56 insertions(+), 46 deletions(-) diff --git a/remix-tests/package.json b/remix-tests/package.json index c6d2155b08..4f4c420be9 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -37,6 +37,7 @@ }, "homepage": "https://github.com/ethereum/remix-tests#readme", "dependencies": { + "@types/async": "^2.4.0", "async": "^2.6.0", "change-case": "^3.0.1", "colors": "^1.1.2", diff --git a/remix-tests/src/deployer.js b/remix-tests/src/deployer.js index d91438f697..a2bdc0a20e 100644 --- a/remix-tests/src/deployer.js +++ b/remix-tests/src/deployer.js @@ -69,7 +69,7 @@ function deployAll (compileResult, web3, callback) { callback(null, { result: { createdAddress: receipt.contractAddress } }) // TODO this will only work with JavaScriptV VM }).on('error', function (err) { - console.dir(err) + console.error(err) callback(err) }) }) @@ -79,9 +79,13 @@ function deployAll (compileResult, web3, callback) { let contract = compiledObject[contractName] let encodeDataFinalCallback = (error, contractDeployData) => { if (error) return nextEach(error) - let contractObject = new web3.eth.Contract(contract.abi) - let deployObject = contractObject.deploy({arguments: [], data: '0x' + contractDeployData.dataHex}) - deployRunner(deployObject, contractObject, contractName, contract.filename, (error) => { nextEach(error) }) + try { + let contractObject = new web3.eth.Contract(contract.abi) + let deployObject = contractObject.deploy({arguments: [], data: '0x' + contractDeployData.dataHex}) + deployRunner(deployObject, contractObject, contractName, contract.filename, (error) => { nextEach(error) }) + } catch (e) { + throw e + } } let encodeDataStepCallback = (msg) => { console.dir(msg) } diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index 1b38e1da66..89e8fc7580 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -1,4 +1,4 @@ -import async = require('async') +import async from 'async' require('colors') import Compiler = require('./compiler.js') @@ -115,4 +115,4 @@ function runTestSources(contractSources, testCallback, resultCallback, finalCall } ], finalCallback) } -export = runTestSources; \ No newline at end of file +export = runTestSources; diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index ef32e6c17f..93d07be88d 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -1,6 +1,6 @@ -import async = require('async'); -import changeCase = require('change-case'); -import Web3 = require('web3'); +import async from 'async' +import * as changeCase from 'change-case' +import Web3 from 'web3' function getFunctionFullName (signature, methodIdentifiers) { for (var method in methodIdentifiers) { @@ -144,4 +144,4 @@ function runTest (testName, testObject, contractDetails, opts, testCallback, res }) } -export = runTest \ No newline at end of file +export = runTest diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index 7008c10a2c..49356c4608 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -1,48 +1,53 @@ -import async = require('async') -import Web3 = require('web3') -import assert = require('assert') +import async from 'async' +import Web3 from 'web3' +import * as assert from 'assert' +import { Provider } from 'remix-simulator' 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) { +function compileAndDeploy (filename: string, callback: Function) { let web3 = new Web3() web3.setProvider(new Provider()) - let compilationData - let accounts + let compilationData: Object + let accounts: Object async.waterfall([ - function getAccountList (next) { - web3.eth.getAccounts((_err, _accounts) => { + function getAccountList (next: Function) { + web3.eth.getAccounts((_err: Error, _accounts: Object) => { accounts = _accounts next(_err) }) }, - function compile (next) { + function compile (next: Function) { Compiler.compileFileOrFiles(filename, false, {accounts}, next) }, function deployAllContracts (compilationResult, next) { - compilationData = compilationResult - Deployer.deployAll(compilationResult, web3, next) + try { + compilationData = compilationResult + Deployer.deployAll(compilationResult, web3, next) + next() + } catch(e) { + throw e + } } ], 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) { @@ -55,15 +60,15 @@ function compileAndDeploy (filename, callback) { 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' }, @@ -74,11 +79,11 @@ function compileAndDeploy (filename, callback) { ]) }) }) - + 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) { @@ -91,15 +96,15 @@ function compileAndDeploy (filename, callback) { 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' }, @@ -108,7 +113,7 @@ function compileAndDeploy (filename, callback) { ]) }) }) - + // Test string equality describe('test string equality', function () { let filename = 'tests/examples_3/simple_string_test.sol' @@ -127,15 +132,15 @@ function compileAndDeploy (filename, callback) { 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' }, @@ -145,12 +150,12 @@ function compileAndDeploy (filename, callback) { ]) }) }) - + // 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) { @@ -163,7 +168,7 @@ function compileAndDeploy (filename, callback) { TestRunner.runTest('IntegerTest', contracts.IntegerTest, compilationData[filename]['IntegerTest'], { accounts }, testCallback, resultsCallback) }) }) - + it('should have 6 passing tests', function () { assert.equal(results.passingNum, 6) }) @@ -171,12 +176,12 @@ function compileAndDeploy (filename, callback) { 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) { @@ -186,12 +191,12 @@ function compileAndDeploy (filename, callback) { 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) }) @@ -200,4 +205,4 @@ function compileAndDeploy (filename, callback) { }) }) }) - }) \ No newline at end of file + }) From cffd6cd36f7a25a12922e51c0824a7a49761cecd Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Tue, 5 Feb 2019 14:57:46 +0530 Subject: [PATCH 07/19] make tests pass in typescript --- remix-tests/dist/runTestFiles.js | 7 +- remix-tests/dist/runTestFiles.js.map | 2 +- remix-tests/dist/runTestSources.js | 10 +- remix-tests/dist/runTestSources.js.map | 2 +- remix-tests/dist/testRunner.d.ts | 3 +- remix-tests/dist/testRunner.js | 25 ++-- remix-tests/dist/testRunner.js.map | 2 +- remix-tests/src/runTestFiles.ts | 4 +- remix-tests/src/runTestSources.ts | 2 +- remix-tests/src/testRunner.ts | 4 +- remix-tests/tests/testRunner.ts | 162 +++---------------------- 11 files changed, 54 insertions(+), 169 deletions(-) diff --git a/remix-tests/dist/runTestFiles.js b/remix-tests/dist/runTestFiles.js index e078436c36..bfda4e5843 100644 --- a/remix-tests/dist/runTestFiles.js +++ b/remix-tests/dist/runTestFiles.js @@ -1,8 +1,11 @@ "use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; var async = require("async"); var path = require("path"); var fs = require("./fs"); -var runTest = require("./testRunner.js"); +var testRunner_1 = __importDefault(require("./testRunner")); require('colors'); var Compiler = require("./compiler.js"); var Deployer = require("./deployer.js"); @@ -97,7 +100,7 @@ function runTestFiles(filepath, isDirectory, web3, opts) { cb(); }; async.eachOfLimit(contractsToTest, 1, function (contractName, index, cb) { - runTest(contractName, contracts(contractName), contractsToTestDetails[index], { accounts: accounts }, testCallback, function (err, result) { + testRunner_1.default(contractName, contracts(contractName), contractsToTestDetails[index], { accounts: accounts }, testCallback, function (err, result) { if (err) { return cb(err); } diff --git a/remix-tests/dist/runTestFiles.js.map b/remix-tests/dist/runTestFiles.js.map index e24ff21c44..32df333311 100644 --- a/remix-tests/dist/runTestFiles.js.map +++ b/remix-tests/dist/runTestFiles.js.map @@ -1 +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,IA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AK,GAAG,SAAS,GAAG,IAAI,CAAC,EAAC,cAAc,EAAC,aAAa,CAAC,CAAA;iBAC/G;gBACD,IAAI,YAAY,GAAG,CAAC,EAAE;oBAClB,OAAO,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.js b/remix-tests/dist/runTestSources.js index 76841aa4f5..4464b34ba0 100644 --- a/remix-tests/dist/runTestSources.js +++ b/remix-tests/dist/runTestSources.js @@ -2,11 +2,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; -var async = require("async"); +var async_1 = __importDefault(require("async")); require('colors'); var Compiler = require("./compiler.js"); var Deployer = require("./deployer.js"); -var runTest = require("./testRunner.js"); +var testRunner_1 = __importDefault(require("./testRunner")); var Web3 = require("web3"); var remix_simulator_1 = __importDefault(require("remix-simulator")); var createWeb3Provider = function () { @@ -18,7 +18,7 @@ function runTestSources(contractSources, testCallback, resultCallback, finalCall opts = opts || {}; var web3 = opts.web3 || createWeb3Provider(); var accounts = opts.accounts || null; - async.waterfall([ + async_1.default.waterfall([ function getAccountList(next) { if (accounts) return next(); @@ -73,8 +73,8 @@ function runTestSources(contractSources, testCallback, resultCallback, finalCall totalTime += result.timePassed; cb(); }; - async.eachOfLimit(contractsToTest, 1, function (contractName, index, cb) { - runTest(contractName, contracts(contractName), contractsToTestDetails[index], { accounts: accounts }, _testCallback, function (err, result) { + async_1.default.eachOfLimit(contractsToTest, 1, function (contractName, index, cb) { + testRunner_1.default(contractName, contracts(contractName), contractsToTestDetails[index], { accounts: accounts }, _testCallback, function (err, result) { if (err) { return cb(err); } diff --git a/remix-tests/dist/runTestSources.js.map b/remix-tests/dist/runTestSources.js.map index 0d4fbb638a..40031168ac 100644 --- a/remix-tests/dist/runTestSources.js.map +++ b/remix-tests/dist/runTestSources.js.map @@ -1 +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,Q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AAA;YACN,CAAC,EAAE,UAAU,GAAG;gBACZ,IAAI,GAAG,EAAE;oBACL,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;iBACnB;gBAED,IAAI,YAAY,GAAgB;oBAC5B,YAAY,EAAE,CAAC;oBACf,YAAY,EAAE,CAAC;oBACf,SAAS,EAAE,CAAC;oBACZ,MAAM,EAAE,EAAE;iBACb,CAAA;gBAED,YAAY,CAAC,YAAY,GAAG,YAAY,IAAI,CAAC,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 +{"version":3,"file":"runTestSources.js","sourceRoot":"","sources":["../src/runTestSources.ts"],"names":[],"mappings":";;;;AAAA,gDAAyB;AACzB,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEjB,wCAA0C;AAC1C,wCAA0C;AAC1C,4DAAkC;AAElC,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;A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BAAsB,CAAC,KAAK,CAAC,EAAE,EAAE,QAAQ,UAAA,EAAE,EAAE,aAAa,EAAE,UAAC,GAAG,EAAE,MAAM;oBACnH,IAAI,GAAG,EAAE;wBACL,OAAO,EAAE,CAAC,GAAG,CAAC,CAAA;qBACjB;oBACD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;gBACtC,CAAC,CAAC,CAAA;YACN,CAAC,EAAE,UAAU,GAAG;gBACZ,IAAI,GAAG,EAAE;oBACL,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;iBACnB;gBAED,IAAI,YAAY,GAAgB;oBAC5B,YAAY,EAAE,CAAC;oBACf,YAAY,EAAE,CAAC;oBACf,SAAS,EAAE,CAAC;oBACZ,MAAM,EAAE,EAAE;iBACb,CAAA;gBAED,YAAY,CAAC,YAAY,GAAG,YAAY,IAAI,CAAC,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 index 39d1b16101..4180f9ddd3 100644 --- a/remix-tests/dist/testRunner.d.ts +++ b/remix-tests/dist/testRunner.d.ts @@ -1,2 +1 @@ -declare function runTest(testName: any, testObject: any, contractDetails: any, opts: any, testCallback: any, resultsCallback: any): void; -export = runTest; +export default function runTest(testName: any, testObject: any, contractDetails: any, opts: any, testCallback: Function, resultsCallback: Function): void; diff --git a/remix-tests/dist/testRunner.js b/remix-tests/dist/testRunner.js index 23b7355b78..5ff7461016 100644 --- a/remix-tests/dist/testRunner.js +++ b/remix-tests/dist/testRunner.js @@ -1,7 +1,18 @@ "use strict"; -var async = require("async"); -var changeCase = require("change-case"); -var Web3 = require("web3"); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var async_1 = __importDefault(require("async")); +var changeCase = __importStar(require("change-case")); +var web3_1 = __importDefault(require("web3")); function getFunctionFullName(signature, methodIdentifiers) { for (var method in methodIdentifiers) { if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { @@ -50,7 +61,7 @@ function runTest(testName, testObject, contractDetails, opts, testCallback, resu var passingNum = 0; var failureNum = 0; var timePassed = 0; - var web3 = new Web3(); + var web3 = new web3_1.default(); var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-'; var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1); if (!isBrowser) { @@ -61,7 +72,7 @@ function runTest(testName, testObject, contractDetails, opts, testCallback, resu signale.warn('TestsAccounts.getAccount(' + opts.accounts.length + ')'); } testCallback({ type: 'contract', value: testName, filename: testObject.filename }); - async.eachOfLimit(runList, 1, function (func, index, next) { + async_1.default.eachOfLimit(runList, 1, function (func, index, next) { var sender; if (func.signature) { sender = getOverridedSender(contractDetails.userdoc, func.signature, contractDetails.evm.methodIdentifiers); @@ -93,7 +104,7 @@ function runTest(testName, testObject, contractDetails, opts, testCallback, resu method.send(sendParams).on('receipt', function (receipt) { try { var time = Math.ceil((Date.now() - startTime) / 1000.0); - var topic = Web3.utils.sha3('AssertionEvent(bool,string)'); + var topic = web3_1.default.utils.sha3('AssertionEvent(bool,string)'); var testPassed = false; for (var i in receipt.events) { var event_1 = receipt.events[i]; @@ -131,5 +142,5 @@ function runTest(testName, testObject, contractDetails, opts, testCallback, resu }); }); } -module.exports = runTest; +exports.default = 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 index bbf4bbacd1..ce7a01b128 100644 --- a/remix-tests/dist/testRunner.js.map +++ b/remix-tests/dist/testRunner.js.map @@ -1 +1 @@ -{"version":3,"file":"testRunner.js","sourceRoot":"","sources":["../src/testRunner.ts"],"names":[],"mappings":";AAAA,6BAAgC;AAChC,wCAA2C;AAC3C,2BAA8B;AAE9B,SAAS,mBAAmB,CAAE,SAAS,EAAE,iBAAiB;IACtD,KAAK,IAAI,MAAM,IAAI,iBAAiB,EAAE;QAClC,IAAI,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE;YAC7E,OAAO,MAAM,CAAA;SAChB;KACJ;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AAED,SAAS,kBAAkB,CAAE,OAAO,EAAE,SAAS,EAAE,iBAAiB;IAC9D,IAAI,QAAQ,GAAQ,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAA;IACrE,IAAI,KAAK,GAAG,wBAAwB,CAAA;IACpC,IAAI,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO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CAAC,GAAG,CAAC,CAAA;oBAChB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;iBACnB;YACL,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG;gBACxB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBAClB,IAAI,CAAC,GAAG,CAAC,CAAA;YACb,CAAC,CAAC,CAAA;SACL;IACL,CAAC,EAAE,UAAU,KAAK;QACd,eAAe,CAAC,KAAK,EAAE;YACnB,UAAU,EAAE,UAAU;YACtB,UAAU,EAAE,UAAU;YACtB,UAAU,EAAE,UAAU;SACzB,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC;AAzFD,0BAyFC"} \ No newline at end of file diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index 9000900abd..50146766be 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -1,7 +1,7 @@ import async = require('async') import path = require('path') import fs = require('./fs') -import runTest = require('./testRunner.js') +import runTest from './testRunner' require('colors') import Compiler = require('./compiler.js') @@ -130,4 +130,4 @@ function runTestFiles(filepath, isDirectory, web3, opts) { }) } -export = runTestFiles; \ No newline at end of file +export = runTestFiles; diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index 89e8fc7580..389f8ce1cb 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -3,7 +3,7 @@ require('colors') import Compiler = require('./compiler.js') import Deployer = require('./deployer.js') -import runTest = require('./testRunner.js') +import runTest from './testRunner' import Web3 = require('web3') import Provider from 'remix-simulator' diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index 93d07be88d..bab86b5403 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -53,7 +53,7 @@ function createRunList (jsonInterface) { return runList } -function runTest (testName, testObject, contractDetails, opts, testCallback, resultsCallback) { +export default function runTest (testName, testObject: any, contractDetails: any, opts: any, testCallback: Function, resultsCallback: Function) { let runList = createRunList(testObject._jsonInterface) let passingNum = 0 @@ -143,5 +143,3 @@ function runTest (testName, testObject, contractDetails, opts, testCallback, res }) }) } - -export = runTest diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index 49356c4608..d50e0ec98e 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -1,11 +1,11 @@ -import async from 'async' +import * as async from 'async' import Web3 from 'web3' import * as assert from 'assert' import { Provider } from 'remix-simulator' let Compiler = require('../src/compiler.js') let Deployer = require('../src/deployer.js') -let TestRunner = require('../src/testRunner.ts') +import runTest from '../dist/testRunner.js' interface Results { passingNum: number, @@ -13,51 +13,50 @@ interface Results { } function compileAndDeploy (filename: string, callback: Function) { - let web3 = new Web3() + let web3: Web3 = new Web3() web3.setProvider(new Provider()) - let compilationData: Object - let accounts: Object + let compilationData: object + let accounts: object async.waterfall([ - function getAccountList (next: Function) { - web3.eth.getAccounts((_err: Error, _accounts: Object) => { + function getAccountList(next: Function): void { + web3.eth.getAccounts((_err: Error, _accounts: object) => { accounts = _accounts next(_err) }) }, - function compile (next: Function) { + function compile(next: Function) { Compiler.compileFileOrFiles(filename, false, {accounts}, next) }, - function deployAllContracts (compilationResult, next) { + function deployAllContracts(compilationResult: object, next: Function): void { try { compilationData = compilationResult Deployer.deployAll(compilationResult, web3, next) - next() } catch(e) { throw e } } - ], function (_err, contracts) { + ], function(_err: Error | null | undefined, contracts: any): void { callback(null, compilationData, contracts, accounts) }) } - describe('testRunner', function () { - describe('#runTest', function() { - describe('test with beforeAll', function () { + describe('testRunner', () => { + describe('#runTest', () => { + describe('test with beforeAll', () => { 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) { + before((done) => { + compileAndDeploy(filename, (_err: Error, compilationData: object, contracts: any, accounts: object) => { + var testCallback = (test: object) => { tests.push(test) } - var resultsCallback = function (_err, _results) { + var resultsCallback = (_err: Error, _results: Results) => { results = _results done() } - TestRunner.runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) + runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) }) }) @@ -79,130 +78,5 @@ function compileAndDeploy (filename: string, callback: Function) { ]) }) }) - - 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) - }) - }) }) }) From ee384be3959811e6e19ea23223ae7e3b6a50e165 Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Tue, 5 Feb 2019 20:15:39 +0530 Subject: [PATCH 08/19] remove dist directory from git --- .gitignore | 1 + remix-tests/dist/index.d.ts | 1 - remix-tests/dist/index.js | 15 --- remix-tests/dist/index.js.map | 1 - remix-tests/dist/runTestFiles.d.ts | 2 - remix-tests/dist/runTestFiles.js | 134 ----------------------- remix-tests/dist/runTestFiles.js.map | 1 - remix-tests/dist/runTestSources.d.ts | 2 - remix-tests/dist/runTestSources.js | 106 ------------------ remix-tests/dist/runTestSources.js.map | 1 - remix-tests/dist/testRunner.d.ts | 1 - remix-tests/dist/testRunner.js | 146 ------------------------- remix-tests/dist/testRunner.js.map | 1 - 13 files changed, 1 insertion(+), 411 deletions(-) delete mode 100644 remix-tests/dist/index.d.ts delete mode 100644 remix-tests/dist/index.js delete mode 100644 remix-tests/dist/index.js.map delete mode 100644 remix-tests/dist/runTestFiles.d.ts delete mode 100644 remix-tests/dist/runTestFiles.js delete mode 100644 remix-tests/dist/runTestFiles.js.map delete mode 100644 remix-tests/dist/runTestSources.d.ts delete mode 100644 remix-tests/dist/runTestSources.js delete mode 100644 remix-tests/dist/runTestSources.js.map delete mode 100644 remix-tests/dist/testRunner.d.ts delete mode 100644 remix-tests/dist/testRunner.js delete mode 100644 remix-tests/dist/testRunner.js.map diff --git a/.gitignore b/.gitignore index 2f9b6cc3d7..15108cdba2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build +dist node_modules npm-debug.log lint.xml diff --git a/remix-tests/dist/index.d.ts b/remix-tests/dist/index.d.ts deleted file mode 100644 index cb0ff5c3b5..0000000000 --- a/remix-tests/dist/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/remix-tests/dist/index.js b/remix-tests/dist/index.js deleted file mode 100644 index 379aae2270..0000000000 --- a/remix-tests/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"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 deleted file mode 100644 index 6e20c6b110..0000000000 --- a/remix-tests/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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 deleted file mode 100644 index 3d69ac0fe3..0000000000 --- a/remix-tests/dist/runTestFiles.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index bfda4e5843..0000000000 --- a/remix-tests/dist/runTestFiles.js +++ /dev/null @@ -1,134 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -var async = require("async"); -var path = require("path"); -var fs = require("./fs"); -var testRunner_1 = __importDefault(require("./testRunner")); -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) { - testRunner_1.default(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 deleted file mode 100644 index 32df333311..0000000000 --- a/remix-tests/dist/runTestFiles.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"runTestFiles.js","sourceRoot":"","sources":["../src/runTestFiles.ts"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,2BAA6B;AAC7B,yBAA2B;AAC3B,4DAAkC;AAClC,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,IAAI,EAAE;gBACF,KAAK,EAAE,OAAO;gBACd,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,OAAO;aACjB;YACD,KAAK,EAAE;gBACH,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,WAAW;aACrB;SACJ;KACJ,CAAA;IACD,IAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IACpC,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAA;IACpC,KAAK,CAAC,SAAS,CAAC;QACZ,SAAS,cAAc,CAAE,IAAI;YACzB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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 deleted file mode 100644 index cd355186f4..0000000000 --- a/remix-tests/dist/runTestSources.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 4464b34ba0..0000000000 --- a/remix-tests/dist/runTestSources.js +++ /dev/null @@ -1,106 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -var async_1 = __importDefault(require("async")); -require('colors'); -var Compiler = require("./compiler.js"); -var Deployer = require("./deployer.js"); -var testRunner_1 = __importDefault(require("./testRunner")); -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_1.default.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_1.default.eachOfLimit(contractsToTest, 1, function (contractName, index, cb) { - testRunner_1.default(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 deleted file mode 100644 index 40031168ac..0000000000 --- a/remix-tests/dist/runTestSources.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"runTestSources.js","source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AAE,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 deleted file mode 100644 index 4180f9ddd3..0000000000 --- a/remix-tests/dist/testRunner.d.ts +++ /dev/null @@ -1 +0,0 @@ -export default function runTest(testName: any, testObject: any, contractDetails: any, opts: any, testCallback: Function, resultsCallback: Function): void; diff --git a/remix-tests/dist/testRunner.js b/remix-tests/dist/testRunner.js deleted file mode 100644 index 5ff7461016..0000000000 --- a/remix-tests/dist/testRunner.js +++ /dev/null @@ -1,146 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var async_1 = __importDefault(require("async")); -var changeCase = __importStar(require("change-case")); -var web3_1 = __importDefault(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) { - var fullName = getFunctionFullName(signature, methodIdentifiers); - var match = /sender: account-+(\d)/g; - var accountIndex = userdoc.methods[fullName] ? match.exec(userdoc.methods[fullName].notice) : null; - return fullName && accountIndex ? accountIndex[1] : null; -} -function getAvailableFunctions(jsonInterface) { - return jsonInterface.reverse().filter(function (x) { return x.type === 'function'; }).map(function (x) { return x.name; }); -} -function getTestFunctions(jsonInterface) { - var specialFunctions = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach']; - return jsonInterface.filter(function (x) { return specialFunctions.indexOf(x.name) < 0 && x.type === 'function'; }); -} -function createRunList(jsonInterface) { - var availableFunctions = getAvailableFunctions(jsonInterface); - var testFunctions = getTestFunctions(jsonInterface); - var runList = []; - if (availableFunctions.indexOf('beforeAll') >= 0) { - runList.push({ name: 'beforeAll', type: 'internal', constant: false }); - } - for (var _i = 0, testFunctions_1 = testFunctions; _i < testFunctions_1.length; _i++) { - var func = testFunctions_1[_i]; - 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) { - var runList = createRunList(testObject._jsonInterface); - var passingNum = 0; - var failureNum = 0; - var timePassed = 0; - var web3 = new web3_1.default(); - var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-'; - var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1); - if (!isBrowser) { - var 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_1.default.eachOfLimit(runList, 1, function (func, index, next) { - var sender; - if (func.signature) { - sender = getOverridedSender(contractDetails.userdoc, func.signature, contractDetails.evm.methodIdentifiers); - if (opts.accounts) { - sender = opts.accounts[sender]; - } - } - var sendParams; - if (sender) - sendParams = { from: sender }; - var method = testObject.methods[func.name].apply(testObject.methods[func.name], []); - var startTime = Date.now(); - if (func.constant) { - method.call(sendParams).then(function (result) { - var 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 { - var time = Math.ceil((Date.now() - startTime) / 1000.0); - var topic = web3_1.default.utils.sha3('AssertionEvent(bool,string)'); - var testPassed = false; - for (var i in receipt.events) { - var event_1 = receipt.events[i]; - if (event_1.raw.topics.indexOf(topic) >= 0) { - var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event_1.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 - }); - }); -} -exports.default = 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 deleted file mode 100644 index ce7a01b128..0000000000 --- a/remix-tests/dist/testRunner.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"testRunner.js","sourceRoot":"","sources":["../src/testRunner.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAyB;AACzB,s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U,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAC,CAAC,CAAA;gCACnI,UAAU,IAAI,CAAC,CAAA;gCACf,OAAO,IAAI,EAAE,CAAA;6BAChB;4BACD,UAAU,GAAG,IAAI,CAAA;yBACpB;qBACJ;oBAED,IAAI,UAAU,EAAE;wBACZ,YAAY,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAC,CAAC,CAAA;wBAC1G,UAAU,IAAI,CAAC,CAAA;qBAClB;oBAED,OAAO,IAAI,EAAE,CAAA;iBAChB;gBAAC,OAAO,GAAG,EAAE;oBACV,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;oBACrB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;oBAChB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;iBACnB;YACL,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG;gBACxB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBAClB,IAAI,CAAC,GAAG,CAAC,CAAA;YACb,CAAC,CAAC,CAAA;SACL;IACL,CAAC,EAAE,UAAU,KAAK;QACd,eAAe,CAAC,KAAK,EAAE;YACnB,UAAU,EAAE,UAAU;YACtB,UAAU,EAAE,UAAU;YACtB,UAAU,EAAE,UAAU;SACzB,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC;AAzFD,0BAyFC"} \ No newline at end of file From dcf8b1241736fd6ab36a315717f3ac43d777340a Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Tue, 5 Feb 2019 21:27:11 +0530 Subject: [PATCH 09/19] add more typings to src/testRunner.ts --- remix-tests/package.json | 2 +- remix-tests/src/testRunner.ts | 81 ++++++++++++++++++++++++++------- remix-tests/tests/testRunner.ts | 55 +++++++++++++++++----- 3 files changed, 110 insertions(+), 28 deletions(-) diff --git a/remix-tests/package.json b/remix-tests/package.json index 4f4c420be9..92001ca281 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -19,7 +19,7 @@ }, "scripts": { "build": "tsc", - "test": "mocha --require ts-node/register tests/*.ts -t 300000" + "test": "tsc && mocha --require ts-node/register tests/*.ts -t 300000" }, "repository": { "type": "git", diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index bab86b5403..8f47424520 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -2,6 +2,26 @@ import async from 'async' import * as changeCase from 'change-case' import Web3 from 'web3' +interface CbReturnInterface { + type: string, + value: any, + time?: number, + context?: string, + errMsg?: string + filename?: string +} +export interface ResultsInterface { + passingNum: number, + failureNum: number, + timePassed: number +} +export interface TestCbInterface { + (error: Error | null | undefined, result?: CbReturnInterface) : void; +} +export interface ResultCbInterface { + (error: Error | null | undefined, result: ResultsInterface) : void; +} + function getFunctionFullName (signature, methodIdentifiers) { for (var method in methodIdentifiers) { if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { @@ -53,12 +73,12 @@ function createRunList (jsonInterface) { return runList } -export default function runTest (testName, testObject: any, contractDetails: any, opts: any, testCallback: Function, resultsCallback: Function) { +export default function runTest (testName, testObject: any, contractDetails: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) { let runList = createRunList(testObject._jsonInterface) - let passingNum = 0 - let failureNum = 0 - let timePassed = 0 + let passingNum: number = 0 + let failureNum: number = 0 + let timePassed: number = 0 let web3 = new Web3() var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' @@ -70,8 +90,12 @@ export default function runTest (testName, testObject: any, contractDetails: any 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}) + const resp: CbReturnInterface = { + type: 'contract', + value: testName, + filename: testObject.filename + } + testCallback(undefined, resp) async.eachOfLimit(runList, 1, function (func, index, next) { let sender if (func.signature) { @@ -89,29 +113,48 @@ export default function runTest (testName, testObject: any, contractDetails: any 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}) + const resp: CbReturnInterface = { + type: 'testPass', + value: changeCase.sentenceCase(func.name), + time: time, + context: testName + } + testCallback(undefined, resp) passingNum += 1 timePassed += time } else { - testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: 'function returned false', context: testName}) + const resp: CbReturnInterface = { + type: 'testFailure', + value: changeCase.sentenceCase(func.name), + time: time, + errMsg: 'function returned false', + context: testName + } + testCallback(undefined, resp) failureNum += 1 } next() }) } else { - method.send(sendParams).on('receipt', function (receipt) { + method.send(sendParams).on('receipt', (receipt) => { try { - let time = Math.ceil((Date.now() - startTime) / 1000.0) + let time: number = Math.ceil((Date.now() - startTime) / 1000.0) let topic = Web3.utils.sha3('AssertionEvent(bool,string)') - - let testPassed = false + let testPassed: boolean = 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}) + const resp: CbReturnInterface = { + type: 'testFailure', + value: changeCase.sentenceCase(func.name), + time: time, + errMsg: testEvent[1], + context: testName + }; + testCallback(undefined, resp) failureNum += 1 return next() } @@ -120,7 +163,13 @@ export default function runTest (testName, testObject: any, contractDetails: any } if (testPassed) { - testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName}) + const resp: CbReturnInterface = { + type: 'testPass', + value: changeCase.sentenceCase(func.name), + time: time, + context: testName + } + testCallback(undefined, resp) passingNum += 1 } @@ -130,12 +179,12 @@ export default function runTest (testName, testObject: any, contractDetails: any console.dir(err) return next(err) } - }).on('error', function (err) { + }).on('error', function (err: Error | null | undefined) { console.error(err) next(err) }) } - }, function (error) { + }, function(error) { resultsCallback(error, { passingNum: passingNum, failureNum: failureNum, diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index d50e0ec98e..9f7d08b9bd 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -5,12 +5,7 @@ import { Provider } from 'remix-simulator' let Compiler = require('../src/compiler.js') let Deployer = require('../src/deployer.js') -import runTest from '../dist/testRunner.js' - -interface Results { - passingNum: number, - failureNum: number, -} +import runTest, { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner.js' function compileAndDeploy (filename: string, callback: Function) { let web3: Web3 = new Web3() @@ -19,7 +14,7 @@ function compileAndDeploy (filename: string, callback: Function) { let accounts: object async.waterfall([ function getAccountList(next: Function): void { - web3.eth.getAccounts((_err: Error, _accounts: object) => { + web3.eth.getAccounts((_err: Error | null | undefined, _accounts: object) => { accounts = _accounts next(_err) }) @@ -45,14 +40,16 @@ function compileAndDeploy (filename: string, callback: Function) { describe('#runTest', () => { describe('test with beforeAll', () => { let filename = 'tests/examples_1/simple_storage_test.sol' - let tests:any[] = [], results:Results; + let tests:any[] = [], results:ResultsInterface; before((done) => { - compileAndDeploy(filename, (_err: Error, compilationData: object, contracts: any, accounts: object) => { - var testCallback = (test: object) => { + compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) => { + var testCallback: TestCbInterface = (err, test) => { + if (err) { throw err } tests.push(test) } - var resultsCallback = (_err: Error, _results: Results) => { + var resultsCallback: ResultCbInterface = (err, _results) => { + if (err) { throw err } results = _results done() } @@ -78,5 +75,41 @@ function compileAndDeploy (filename: string, callback: Function) { ]) }) }) + + describe('test with beforeEach', function () { + let filename = 'tests/examples_2/simple_storage_test.sol' + let tests:any[] = [], results:ResultsInterface; + + before(function (done) { + compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) { + var testCallback: TestCbInterface = (err, test) => { + if (err) { throw err } + tests.push(test) + } + var resultsCallback: ResultCbInterface = (err, _results) => { + if (err) { throw err } + results = _results + done() + } + 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' } + ]) + }) + }) }) }) From 7f80f9a6aa8b438f3e5966ec036ac5ef809c8317 Mon Sep 17 00:00:00 2001 From: Sab94 Date: Wed, 6 Feb 2019 10:37:19 +0530 Subject: [PATCH 10/19] passing all tests --- remix-tests/tests/testRunner.ts | 225 +++++++++++++++++++++++--------- 1 file changed, 161 insertions(+), 64 deletions(-) diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index 9f7d08b9bd..3cf18875eb 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -7,78 +7,78 @@ let Compiler = require('../src/compiler.js') let Deployer = require('../src/deployer.js') import runTest, { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner.js' -function compileAndDeploy (filename: string, callback: Function) { - let web3: Web3 = new Web3() - web3.setProvider(new Provider()) - let compilationData: object - let accounts: object - async.waterfall([ - function getAccountList(next: Function): void { - web3.eth.getAccounts((_err: Error | null | undefined, _accounts: object) => { - accounts = _accounts - next(_err) - }) - }, - function compile(next: Function) { - Compiler.compileFileOrFiles(filename, false, {accounts}, next) - }, - function deployAllContracts(compilationResult: object, next: Function): void { - try { - compilationData = compilationResult - Deployer.deployAll(compilationResult, web3, next) - } catch(e) { - throw e - } +function compileAndDeploy(filename: string, callback: Function) { + let web3: Web3 = new Web3() + web3.setProvider(new Provider()) + let compilationData: object + let accounts: object + async.waterfall([ + function getAccountList(next: Function): void { + web3.eth.getAccounts((_err: Error | null | undefined, _accounts: object) => { + accounts = _accounts + next(_err) + }) + }, + function compile(next: Function) { + Compiler.compileFileOrFiles(filename, false, { accounts }, next) + }, + function deployAllContracts(compilationResult: object, next: Function): void { + try { + compilationData = compilationResult + Deployer.deployAll(compilationResult, web3, next) + } catch (e) { + throw e } - ], function(_err: Error | null | undefined, contracts: any): void { - callback(null, compilationData, contracts, accounts) - }) - } - - - describe('testRunner', () => { - describe('#runTest', () => { - describe('test with beforeAll', () => { - let filename = 'tests/examples_1/simple_storage_test.sol' - let tests:any[] = [], results:ResultsInterface; - - before((done) => { - compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) => { - var testCallback: TestCbInterface = (err, test) => { - if (err) { throw err } - tests.push(test) - } - var resultsCallback: ResultCbInterface = (err, _results) => { - if (err) { throw err } - results = _results - done() - } - runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) - }) - }) + } + ], function (_err: Error | null | undefined, contracts: any): void { + callback(null, compilationData, contracts, accounts) + }) +} - it('should 1 passing test', function () { - assert.equal(results.passingNum, 2) - }) - it('should 1 failing test', function () { - assert.equal(results.failureNum, 2) - }) +describe('testRunner', () => { + describe('#runTest', () => { + describe('test with beforeAll', () => { + let filename = 'tests/examples_1/simple_storage_test.sol' + let tests: any[] = [], results: ResultsInterface; - 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' } - ]) + before((done) => { + compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) => { + var testCallback: TestCbInterface = (err, test) => { + if (err) { throw err } + tests.push(test) + } + var resultsCallback: ResultCbInterface = (err, _results) => { + if (err) { throw err } + results = _results + done() + } + runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) }) }) - describe('test with beforeEach', function () { + 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:ResultsInterface; + let tests: any[] = [], results: ResultsInterface; before(function (done) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) { @@ -111,5 +111,102 @@ function compileAndDeploy (filename: string, callback: Function) { ]) }) }) + + // Test string equality + describe('test string equality', function () { + let filename = 'tests/examples_3/simple_string_test.sol' + let tests: any[] = [], results: ResultsInterface; + + before(function (done) { + compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + var testCallback: TestCbInterface = (err, test) => { + if (err) { throw err } + tests.push(test) + } + var resultsCallback: ResultCbInterface = (err, _results) => { + if (err) { throw err } + results = _results + done() + } + runTest('StringTest', contracts.StringTest, compilationData[filename]['StringTest'], { accounts }, testCallback, resultsCallback) + 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: ResultsInterface; + + before(function (done) { + compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + var testCallback: TestCbInterface = (err, test) => { + if (err) { throw err } + tests.push(test) + } + var resultsCallback: ResultCbInterface = (err, _results) => { + if (err) { throw err } + results = _results + done() + } + 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: ResultsInterface; + + before(function (done) { + compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + var testCallback: TestCbInterface = (err, test) => { + if (err) { throw err } + tests.push(test) + } + var resultsCallback: ResultCbInterface = (err, _results) => { + if (err) { throw err } + results = _results + done() + } + + 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) + }) }) }) +}) From 21ea2ce12f976132786b36fdc7258368d5fa5931 Mon Sep 17 00:00:00 2001 From: Sab94 Date: Wed, 6 Feb 2019 12:24:25 +0530 Subject: [PATCH 11/19] compiler, deployer, logger migrated to ts --- remix-tests/src/compiler.js | 129 ------------------------------ remix-tests/src/compiler.ts | 127 +++++++++++++++++++++++++++++ remix-tests/src/deployer.js | 113 -------------------------- remix-tests/src/deployer.ts | 109 +++++++++++++++++++++++++ remix-tests/src/fs.js | 3 +- remix-tests/src/logger.js | 58 -------------- remix-tests/src/logger.ts | 57 +++++++++++++ remix-tests/src/run.js | 2 +- remix-tests/src/runTestFiles.ts | 4 +- remix-tests/src/runTestSources.ts | 2 +- remix-tests/tests/testRunner.ts | 4 +- 11 files changed, 301 insertions(+), 307 deletions(-) delete mode 100644 remix-tests/src/compiler.js create mode 100644 remix-tests/src/compiler.ts delete mode 100644 remix-tests/src/deployer.js create mode 100644 remix-tests/src/deployer.ts delete mode 100644 remix-tests/src/logger.js create mode 100644 remix-tests/src/logger.ts diff --git a/remix-tests/src/compiler.js b/remix-tests/src/compiler.js deleted file mode 100644 index 7b450e97c4..0000000000 --- a/remix-tests/src/compiler.js +++ /dev/null @@ -1,129 +0,0 @@ -/* eslint no-extend-native: "warn" */ -let fs = require('./fs') -var async = require('async') -var path = require('path') -let RemixCompiler = require('remix-solidity').Compiler - -String.prototype.regexIndexOf = function (regex, startpos) { - var indexOf = this.substring(startpos || 0).search(regex) - return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf -} - -function writeTestAccountsContract (accounts) { - var testAccountContract = require('../sol/tests_accounts.sol.js') - var body = 'address[' + accounts.length + '] memory accounts;' - if (!accounts.length) body += ';' - else { - accounts.map((address, index) => { - body += `\naccounts[${index}] = ${address};\n` - }) - } - return testAccountContract.replace('>accounts<', body) -} - -var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' -var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) - -// TODO: replace this with remix's own compiler code -function compileFileOrFiles (filename, isDirectory, opts, cb) { - let compiler - let accounts = opts.accounts || [] - const sources = { - 'tests.sol': { content: require('../sol/tests.sol.js') }, - 'remix_tests.sol': { content: require('../sol/tests.sol.js') }, - 'remix_accounts.sol': { content: writeTestAccountsContract(accounts) } - } - const filepath = (isDirectory ? filename : path.dirname(filename)) - // TODO: for now assumes filepath dir contains all tests, later all this - // should be replaced with remix's & browser solidity compiler code - - // This logic is wrong - // We should only look into current file if a full file name with path is given - // We should only walk through directory if a directory name is passed - try { - // walkSync only if it is a directory - fs.walkSync(filepath, foundpath => { - // only process .sol files - if (foundpath.split('.').pop() === 'sol') { - let c = fs.readFileSync(foundpath).toString() - const s = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm - let includeTestLibs = '\nimport \'remix_tests.sol\';\n' - if (foundpath.indexOf('_test.sol') > 0 && c.regexIndexOf(s) < 0) { - c = includeTestLibs.concat(c) - } - sources[foundpath] = { content: c } - } - }) - } catch (e) { - throw e - } finally { - async.waterfall([ - function loadCompiler (next) { - compiler = new RemixCompiler() - compiler.onInternalCompilerLoaded() - // compiler.event.register('compilerLoaded', this, function (version) { - next() - // }); - }, - function doCompilation (next) { - compiler.event.register('compilationFinished', this, function (success, data, source) { - next(null, data) - }) - compiler.compile(sources, filepath) - } - ], function (err, result) { - let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') - if (errors.length > 0) { - if (!isBrowser) require('signale').fatal(errors) - return cb(new Error('errors compiling')) - } - cb(err, result.contracts) - }) - } -} - -function compileContractSources (sources, importFileCb, opts, cb) { - let compiler, filepath - let accounts = opts.accounts || [] - // Iterate over sources keys. Inject test libraries. Inject test library import statements. - if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) { - sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } - sources['remix_accounts.sol'] = { content: writeTestAccountsContract(accounts) } - } - const s = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm - let includeTestLibs = '\nimport \'remix_tests.sol\';\n' - for (let file in sources) { - const c = sources[file].content - if (file.indexOf('_test.sol') > 0 && c && c.regexIndexOf(s) < 0) { - sources[file].content = includeTestLibs.concat(c) - } - } - - async.waterfall([ - function loadCompiler (next) { - compiler = new RemixCompiler(importFileCb) - compiler.onInternalCompilerLoaded() - // compiler.event.register('compilerLoaded', this, function (version) { - next() - // }); - }, - function doCompilation (next) { - compiler.event.register('compilationFinished', this, function (success, data, source) { - next(null, data) - }) - compiler.compile(sources, filepath) - } - ], function (err, result) { - let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') - if (errors.length > 0) { - if (!isBrowser) require('signale').fatal(errors) - return cb(new Error('errors compiling')) - } - cb(err, result.contracts) - }) -} - -module.exports = { - compileFileOrFiles: compileFileOrFiles, - compileContractSources: compileContractSources -} diff --git a/remix-tests/src/compiler.ts b/remix-tests/src/compiler.ts new file mode 100644 index 0000000000..15d2a62a05 --- /dev/null +++ b/remix-tests/src/compiler.ts @@ -0,0 +1,127 @@ +/* eslint no-extend-native: "warn" */ +let fs = require('../src/fs') +var async = require('async') +var path = require('path') +let RemixCompiler = require('remix-solidity').Compiler + + +function regexIndexOf (inputString, regex, startpos = 0) { + var indexOf = inputString.substring(startpos).search(regex) + return (indexOf >= 0) ? (indexOf + (startpos)) : indexOf +} + +function writeTestAccountsContract (accounts) { + var testAccountContract = require('../sol/tests_accounts.sol.js') + var body = 'address[' + accounts.length + '] memory accounts;' + if (!accounts.length) body += ';' + else { + accounts.map((address, index) => { + body += `\naccounts[${index}] = ${address};\n` + }) + } + return testAccountContract.replace('>accounts<', body) +} + +var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' +var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) + +// TODO: replace this with remix's own compiler code +export function compileFileOrFiles (filename, isDirectory, opts, cb) { + let compiler + let accounts = opts.accounts || [] + const sources = { + 'tests.sol': { content: require('../sol/tests.sol.js') }, + 'remix_tests.sol': { content: require('../sol/tests.sol.js') }, + 'remix_accounts.sol': { content: writeTestAccountsContract(accounts) } + } + const filepath = (isDirectory ? filename : path.dirname(filename)) + // TODO: for now assumes filepath dir contains all tests, later all this + // should be replaced with remix's & browser solidity compiler code + + // This logic is wrong + // We should only look into current file if a full file name with path is given + // We should only walk through directory if a directory name is passed + try { + // walkSync only if it is a directory + fs.walkSync(filepath, foundpath => { + // only process .sol files + if (foundpath.split('.').pop() === 'sol') { + let c = fs.readFileSync(foundpath).toString() + const s = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm + let includeTestLibs = '\nimport \'remix_tests.sol\';\n' + if (foundpath.indexOf('_test.sol') > 0 && regexIndexOf(c, s) < 0) { + c = includeTestLibs.concat(c) + } + sources[foundpath] = { content: c } + } + }) + } catch (e) { + throw e + } finally { + async.waterfall([ + function loadCompiler (next) { + compiler = new RemixCompiler() + compiler.onInternalCompilerLoaded() + // compiler.event.register('compilerLoaded', this, function (version) { + next() + // }); + }, + function doCompilation (next) { + // @ts-ignore + compiler.event.register('compilationFinished', this, function (success, data, source) { + next(null, data) + }) + compiler.compile(sources, filepath) + } + ], function (err, result) { + let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') + if (errors.length > 0) { + if (!isBrowser) require('signale').fatal(errors) + return cb(new Error('errors compiling')) + } + cb(err, result.contracts) + }) + } +} + +export function compileContractSources (sources, importFileCb, opts, cb) { + let compiler, filepath + let accounts = opts.accounts || [] + // Iterate over sources keys. Inject test libraries. Inject test library import statements. + if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) { + sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } + sources['remix_accounts.sol'] = { content: writeTestAccountsContract(accounts) } + } + const s = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm + let includeTestLibs = '\nimport \'remix_tests.sol\';\n' + for (let file in sources) { + const c = sources[file].content + if (file.indexOf('_test.sol') > 0 && c && regexIndexOf(c, s) < 0) { + sources[file].content = includeTestLibs.concat(c) + } + } + + async.waterfall([ + function loadCompiler (next) { + compiler = new RemixCompiler(importFileCb) + compiler.onInternalCompilerLoaded() + // compiler.event.register('compilerLoaded', this, function (version) { + next() + // }); + }, + function doCompilation (next) { + // @ts-ignore + compiler.event.register('compilationFinished', this, function (success, data, source) { + next(null, data) + }) + compiler.compile(sources, filepath) + } + ], function (err, result) { + let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') + if (errors.length > 0) { + if (!isBrowser) require('signale').fatal(errors) + return cb(new Error('errors compiling')) + } + cb(err, result.contracts) + }) +} diff --git a/remix-tests/src/deployer.js b/remix-tests/src/deployer.js deleted file mode 100644 index a2bdc0a20e..0000000000 --- a/remix-tests/src/deployer.js +++ /dev/null @@ -1,113 +0,0 @@ -var async = require('async') -var remixLib = require('remix-lib') - -function deployAll (compileResult, web3, callback) { - let compiledObject = {} - let contracts = {} - let accounts = [] - - async.waterfall([ - function getAccountList (next) { - web3.eth.getAccounts((_err, _accounts) => { - accounts = _accounts - next() - }) - }, - function getContractData (next) { - for (let contractFile in compileResult) { - for (let contractName in compileResult[contractFile]) { - let contract = compileResult[contractFile][contractName] - - const className = contractName - const filename = contractFile - - let abi = contract.abi - let code = contract.evm.bytecode.object - - compiledObject[className] = {} - compiledObject[className].abi = abi - compiledObject[className].code = code - compiledObject[className].filename = filename - compiledObject[className].className = className - compiledObject[className].raw = contract - - if (contractFile.indexOf('_test.sol') >= 0) { - compiledObject[className].isTest = true - } - } - } - next() - }, - function determineContractsToDeploy (next) { - let contractsToDeploy = ['Assert'] - let allContracts = Object.keys(compiledObject) - - for (let contractName of allContracts) { - if (contractName === 'Assert') { - continue - } - if (compiledObject[contractName].isTest) { - contractsToDeploy.push(contractName) - } - } - next(null, contractsToDeploy) - }, - function deployContracts (contractsToDeploy, next) { - var deployRunner = (deployObject, contractObject, contractName, filename, callback) => { - deployObject.estimateGas().then((gasValue) => { - deployObject.send({ - from: accounts[0], - gas: Math.ceil(gasValue * 1.2) - }).on('receipt', function (receipt) { - contractObject.options.address = receipt.contractAddress - contractObject.options.from = accounts[0] - contractObject.options.gas = 5000 * 1000 - compiledObject[contractName].deployedAddress = receipt.contractAddress - - contracts[contractName] = contractObject - contracts[contractName].filename = filename - - callback(null, { result: { createdAddress: receipt.contractAddress } }) // TODO this will only work with JavaScriptV VM - }).on('error', function (err) { - console.error(err) - callback(err) - }) - }) - } - - async.eachOfLimit(contractsToDeploy, 1, function (contractName, index, nextEach) { - let contract = compiledObject[contractName] - let encodeDataFinalCallback = (error, contractDeployData) => { - if (error) return nextEach(error) - try { - let contractObject = new web3.eth.Contract(contract.abi) - let deployObject = contractObject.deploy({arguments: [], data: '0x' + contractDeployData.dataHex}) - deployRunner(deployObject, contractObject, contractName, contract.filename, (error) => { nextEach(error) }) - } catch (e) { - throw e - } - } - - let encodeDataStepCallback = (msg) => { console.dir(msg) } - - let encodeDataDeployLibraryCallback = (libData, callback) => { - let abi = compiledObject[libData.data.contractName].abi - let code = compiledObject[libData.data.contractName].code - let libraryObject = new web3.eth.Contract(abi) - let deployObject = libraryObject.deploy({arguments: [], data: '0x' + code}) - deployRunner(deployObject, libraryObject, libData.data.contractName, contract.filename, callback) - } - - let funAbi = null // no need to set the abi for encoding the constructor - let params = '' // we suppose that the test contract does not have any param in the constructor - remixLib.execution.txFormat.encodeConstructorCallAndDeployLibraries(contractName, contract.raw, compileResult, params, funAbi, encodeDataFinalCallback, encodeDataStepCallback, encodeDataDeployLibraryCallback) - }, function () { - next(null, contracts) - }) - } - ], callback) -} - -module.exports = { - deployAll: deployAll -} diff --git a/remix-tests/src/deployer.ts b/remix-tests/src/deployer.ts new file mode 100644 index 0000000000..157926aef6 --- /dev/null +++ b/remix-tests/src/deployer.ts @@ -0,0 +1,109 @@ +var async = require('async') +var remixLib = require('remix-lib') + +export function deployAll (compileResult, web3, callback) { + let compiledObject = {} + let contracts = {} + let accounts = [] + + async.waterfall([ + function getAccountList (next) { + web3.eth.getAccounts((_err, _accounts) => { + accounts = _accounts + next() + }) + }, + function getContractData (next) { + for (let contractFile in compileResult) { + for (let contractName in compileResult[contractFile]) { + let contract = compileResult[contractFile][contractName] + + const className = contractName + const filename = contractFile + + let abi = contract.abi + let code = contract.evm.bytecode.object + + compiledObject[className] = {} + compiledObject[className].abi = abi + compiledObject[className].code = code + compiledObject[className].filename = filename + compiledObject[className].className = className + compiledObject[className].raw = contract + + if (contractFile.indexOf('_test.sol') >= 0) { + compiledObject[className].isTest = true + } + } + } + next() + }, + function determineContractsToDeploy (next) { + let contractsToDeploy = ['Assert'] + let allContracts = Object.keys(compiledObject) + + for (let contractName of allContracts) { + if (contractName === 'Assert') { + continue + } + if (compiledObject[contractName].isTest) { + contractsToDeploy.push(contractName) + } + } + next(null, contractsToDeploy) + }, + function deployContracts (contractsToDeploy, next) { + var deployRunner = (deployObject, contractObject, contractName, filename, callback) => { + deployObject.estimateGas().then((gasValue) => { + deployObject.send({ + from: accounts[0], + gas: Math.ceil(gasValue * 1.2) + }).on('receipt', function (receipt) { + contractObject.options.address = receipt.contractAddress + contractObject.options.from = accounts[0] + contractObject.options.gas = 5000 * 1000 + compiledObject[contractName].deployedAddress = receipt.contractAddress + + contracts[contractName] = contractObject + contracts[contractName].filename = filename + + callback(null, { result: { createdAddress: receipt.contractAddress } }) // TODO this will only work with JavaScriptV VM + }).on('error', function (err) { + console.error(err) + callback(err) + }) + }) + } + + async.eachOfLimit(contractsToDeploy, 1, function (contractName, index, nextEach) { + let contract = compiledObject[contractName] + let encodeDataFinalCallback = (error, contractDeployData) => { + if (error) return nextEach(error) + try { + let contractObject = new web3.eth.Contract(contract.abi) + let deployObject = contractObject.deploy({arguments: [], data: '0x' + contractDeployData.dataHex}) + deployRunner(deployObject, contractObject, contractName, contract.filename, (error) => { nextEach(error) }) + } catch (e) { + throw e + } + } + + let encodeDataStepCallback = (msg) => { console.dir(msg) } + + let encodeDataDeployLibraryCallback = (libData, callback) => { + let abi = compiledObject[libData.data.contractName].abi + let code = compiledObject[libData.data.contractName].code + let libraryObject = new web3.eth.Contract(abi) + let deployObject = libraryObject.deploy({arguments: [], data: '0x' + code}) + deployRunner(deployObject, libraryObject, libData.data.contractName, contract.filename, callback) + } + + let funAbi = null // no need to set the abi for encoding the constructor + let params = '' // we suppose that the test contract does not have any param in the constructor + remixLib.execution.txFormat.encodeConstructorCallAndDeployLibraries(contractName, contract.raw, compileResult, params, funAbi, encodeDataFinalCallback, encodeDataStepCallback, encodeDataDeployLibraryCallback) + }, function () { + next(null, contracts) + }) + } + ], callback) +} diff --git a/remix-tests/src/fs.js b/remix-tests/src/fs.js index fa2dd4dfd7..eafe5339eb 100644 --- a/remix-tests/src/fs.js +++ b/remix-tests/src/fs.js @@ -1,4 +1,5 @@ // Extend fs + var fs = require('fs') const path = require('path') @@ -17,4 +18,4 @@ fs.walkSync = function (start, callback) { }) } -module.exports = fs +module.exports = fs \ No newline at end of file diff --git a/remix-tests/src/logger.js b/remix-tests/src/logger.js deleted file mode 100644 index 6dc6253bf1..0000000000 --- a/remix-tests/src/logger.js +++ /dev/null @@ -1,58 +0,0 @@ -var gray = require('ansi-gray') -const winston = require('winston') -var timestamp = require('time-stamp') -var supportsColor = require('color-support') - -function hasFlag (flag) { - return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)) -} - -function addColor (str) { - if (hasFlag('no-color')) { - return str - } - - if (hasFlag('color')) { - return gray(str) - } - - if (supportsColor()) { - return gray(str) - } - - return str -} -function getTimestamp () { - return '[' + addColor(timestamp('HH:mm:ss')) + ']' -} -// create winston logger format -const logFmt = winston.format.printf((info) => { - return `${getTimestamp()} ${info.level}: ${info.message}` -}) - -class Log { - constructor () { - this.logger = winston.createLogger({ - level: 'error', - transports: [new winston.transports.Console()], - format: winston.format.combine( - winston.format.colorize({ all: true }), - logFmt - ) - }) - } - setVerbosity (v) { - this.logger.configure({ - level: v, - transports: [new winston.transports.Console()], - format: winston.format.combine( - winston.format.colorize({ all: true }), - logFmt - ) - }) - } -} - -module.exports = { - Log -} diff --git a/remix-tests/src/logger.ts b/remix-tests/src/logger.ts new file mode 100644 index 0000000000..c1e5d13c92 --- /dev/null +++ b/remix-tests/src/logger.ts @@ -0,0 +1,57 @@ +var gray = require('ansi-gray') +const winston = require('winston') +var timestamp = require('time-stamp') +var supportsColor = require('color-support') + +function hasFlag (flag) { + return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)) +} + +function addColor (str) { + if (hasFlag('no-color')) { + return str + } + + if (hasFlag('color')) { + return gray(str) + } + + if (supportsColor()) { + return gray(str) + } + + return str +} +function getTimestamp () { + return '[' + addColor(timestamp('HH:mm:ss')) + ']' +} +// create winston logger format +const logFmt = winston.format.printf((info) => { + return `${getTimestamp()} ${info.level}: ${info.message}` +}) + +class Log { + logger: any; + constructor () { + this.logger = winston.createLogger({ + level: 'error', + transports: [new winston.transports.Console()], + format: winston.format.combine( + winston.format.colorize({ all: true }), + logFmt + ) + }) + } + setVerbosity (v) { + this.logger.configure({ + level: v, + transports: [new winston.transports.Console()], + format: winston.format.combine( + winston.format.colorize({ all: true }), + logFmt + ) + }) + } +} + +export = Log diff --git a/remix-tests/src/run.js b/remix-tests/src/run.js index e0aefb97f6..31e478dd82 100644 --- a/remix-tests/src/run.js +++ b/remix-tests/src/run.js @@ -3,7 +3,7 @@ const Web3 = require('web3') const RemixTests = require('./index.js') const fs = require('fs') const Provider = require('remix-simulator').Provider -const { Log } = require('./logger.js') +const { Log } = require('./logger') const logger = new Log() const log = logger.logger require('colors') diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index 50146766be..0b0b7dd7ea 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -4,8 +4,8 @@ import fs = require('./fs') import runTest from './testRunner' require('colors') -import Compiler = require('./compiler.js') -import Deployer = require('./deployer.js') +import Compiler = require('./compiler') +import Deployer = require('./deployer') function runTestFiles(filepath, isDirectory, web3, opts) { opts = opts || {} diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index 389f8ce1cb..867b1687c2 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -34,7 +34,7 @@ function runTestSources(contractSources, testCallback, resultCallback, finalCall }) }, function compile (next) { - Compiler.compileContractSources(contractSources, importFileCb, next) + Compiler.compileContractSources(contractSources, importFileCb, opts, next) }, function deployAllContracts (compilationResult, next) { Deployer.deployAll(compilationResult, web3, function (err, contracts) { diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index 3cf18875eb..129d719b3e 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -3,8 +3,8 @@ import Web3 from 'web3' import * as assert from 'assert' import { Provider } from 'remix-simulator' -let Compiler = require('../src/compiler.js') -let Deployer = require('../src/deployer.js') +let Compiler = require('../dist/compiler.js') +let Deployer = require('../dist/deployer.js') import runTest, { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner.js' function compileAndDeploy(filename: string, callback: Function) { From c0159cedc762e4bdbd279f8cd7a57ad579cb151d Mon Sep 17 00:00:00 2001 From: Sab94 Date: Wed, 6 Feb 2019 15:37:15 +0530 Subject: [PATCH 12/19] rename fs.ts --- remix-tests/bin/remix-tests | 2 +- remix-tests/src/compiler.ts | 2 +- remix-tests/src/fileSystem.ts | 20 ++++++++++ remix-tests/src/fs.js | 21 ----------- remix-tests/src/run.js | 65 --------------------------------- remix-tests/src/run.ts | 65 +++++++++++++++++++++++++++++++++ remix-tests/src/runTestFiles.ts | 6 +-- 7 files changed, 90 insertions(+), 91 deletions(-) create mode 100644 remix-tests/src/fileSystem.ts delete mode 100644 remix-tests/src/fs.js delete mode 100644 remix-tests/src/run.js create mode 100644 remix-tests/src/run.ts diff --git a/remix-tests/bin/remix-tests b/remix-tests/bin/remix-tests index 3c14572035..ea2e0358b5 100755 --- a/remix-tests/bin/remix-tests +++ b/remix-tests/bin/remix-tests @@ -1,4 +1,4 @@ #!/usr/bin/env node -require('../src/run.js'); +require('../dist/run.js'); diff --git a/remix-tests/src/compiler.ts b/remix-tests/src/compiler.ts index 15d2a62a05..cf5f4f4540 100644 --- a/remix-tests/src/compiler.ts +++ b/remix-tests/src/compiler.ts @@ -1,5 +1,5 @@ /* eslint no-extend-native: "warn" */ -let fs = require('../src/fs') +let fs = require('./fileSystem') var async = require('async') var path = require('path') let RemixCompiler = require('remix-solidity').Compiler diff --git a/remix-tests/src/fileSystem.ts b/remix-tests/src/fileSystem.ts new file mode 100644 index 0000000000..14ba6d8495 --- /dev/null +++ b/remix-tests/src/fileSystem.ts @@ -0,0 +1,20 @@ +// Extend fs +let fs: any = require('fs') +const path = require('path') + +// https://github.com/mikeal/node-utils/blob/master/file/lib/main.js +fs.walkSync = function (start, callback) { + fs.readdirSync(start).forEach(name => { + if (name === 'node_modules') { + return // hack + } + var abspath = path.join(start, name) + if (fs.statSync(abspath).isDirectory()) { + fs.walkSync(abspath, callback) + } else { + callback(abspath) + } + }) +} + +export = fs diff --git a/remix-tests/src/fs.js b/remix-tests/src/fs.js deleted file mode 100644 index eafe5339eb..0000000000 --- a/remix-tests/src/fs.js +++ /dev/null @@ -1,21 +0,0 @@ -// Extend fs - -var fs = require('fs') -const path = require('path') - -// https://github.com/mikeal/node-utils/blob/master/file/lib/main.js -fs.walkSync = function (start, callback) { - fs.readdirSync(start).forEach(name => { - if (name === 'node_modules') { - return // hack - } - var abspath = path.join(start, name) - if (fs.statSync(abspath).isDirectory()) { - fs.walkSync(abspath, callback) - } else { - callback(abspath) - } - }) -} - -module.exports = fs \ No newline at end of file diff --git a/remix-tests/src/run.js b/remix-tests/src/run.js deleted file mode 100644 index 31e478dd82..0000000000 --- a/remix-tests/src/run.js +++ /dev/null @@ -1,65 +0,0 @@ -const commander = require('commander') -const Web3 = require('web3') -const RemixTests = require('./index.js') -const fs = require('fs') -const Provider = require('remix-simulator').Provider -const { Log } = require('./logger') -const logger = new Log() -const log = logger.logger -require('colors') - -// parse verbosity -function mapVerbosity (v) { - const levels = { - 0: 'error', - 1: 'warn', - 2: 'info', - 3: 'verbose', - 4: 'debug', - 5: 'silly' - } - return levels[v] -} -const version = require('../package.json').version - -commander.version(version) - -commander.command('version').description('output the version number').action(function () { - console.log(version) -}) - -commander.command('help').description('output usage information').action(function () { - commander.help() -}) - -// get current version -commander - .option('-v, --verbose ', 'run with verbosity', mapVerbosity) - .action(function (filename) { - // Console message - console.log(('\n\t👁 :: Running remix-tests - Unit testing for solidity :: 👁\t\n').white) - // set logger verbosity - if (commander.verbose) { - logger.setVerbosity(commander.verbose) - log.info('verbosity level set to ' + commander.verbose.blue) - } - let web3 = new Web3() - // web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) - web3.setProvider(new Provider()) - // web3.setProvider(new web3.providers.WebsocketProvider('ws://localhost:8546')) - - if (!fs.existsSync(filename)) { - console.error(filename + ' not found') - process.exit(1) - } - - let isDirectory = fs.lstatSync(filename).isDirectory() - RemixTests.runTestFiles(filename, isDirectory, web3) - }) - -if (!process.argv.slice(2).length) { - log.error('Please specify a filename') - process.exit() -} - -commander.parse(process.argv) diff --git a/remix-tests/src/run.ts b/remix-tests/src/run.ts new file mode 100644 index 0000000000..dfc9961d20 --- /dev/null +++ b/remix-tests/src/run.ts @@ -0,0 +1,65 @@ +const commander = require('commander') +const Web3 = require('web3') +import runTestFiles from './runTestFiles' +import fs = require('./fileSystem') +const Provider = require('remix-simulator').Provider +import Log = require('./logger') +const logger = new Log() +const log = logger.logger +require('colors') + +// parse verbosity +function mapVerbosity (v) { + const levels = { + 0: 'error', + 1: 'warn', + 2: 'info', + 3: 'verbose', + 4: 'debug', + 5: 'silly' + } + return levels[v] +} +const version = require('../package.json').version + +commander.version(version) + +commander.command('version').description('output the version number').action(function () { + console.log(version) +}) + +commander.command('help').description('output usage information').action(function () { + commander.help() +}) + +// get current version +commander + .option('-v, --verbose ', 'run with verbosity', mapVerbosity) + .action(function (filename) { + // Console message + console.log(('\n\t👁 :: Running remix-tests - Unit testing for solidity :: 👁\t\n'),'color: white') + // set logger verbosity + if (commander.verbose) { + logger.setVerbosity(commander.verbose) + log.info('verbosity level set to ' + commander.verbose.blue) + } + let web3 = new Web3() + // web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) + web3.setProvider(new Provider()) + // web3.setProvider(new web3.providers.WebsocketProvider('ws://localhost:8546')) + + if (!fs.existsSync(filename)) { + console.error(filename + ' not found') + process.exit(1) + } + + let isDirectory = fs.lstatSync(filename).isDirectory() + runTestFiles(filename, isDirectory, web3) + }) + +if (!process.argv.slice(2).length) { + log.error('Please specify a filename') + process.exit() +} + +commander.parse(process.argv) diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index 0b0b7dd7ea..1e0c200040 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -1,13 +1,13 @@ import async = require('async') import path = require('path') -import fs = require('./fs') +import fs from './fileSystem' import runTest from './testRunner' require('colors') import Compiler = require('./compiler') import Deployer = require('./deployer') -function runTestFiles(filepath, isDirectory, web3, opts) { +function runTestFiles(filepath, isDirectory, web3, opts = {}) { opts = opts || {} const { Signale } = require('signale') // signale configuration @@ -31,7 +31,7 @@ function runTestFiles(filepath, isDirectory, web3, opts) { } } const signale = new Signale(options) - let accounts = opts.accounts || null + let accounts = opts['accounts'] || null async.waterfall([ function getAccountList (next) { if (accounts) return next(null) From fa5af91759285cfa332a4e254bd0e2be349a766a Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Wed, 6 Feb 2019 19:22:39 +0530 Subject: [PATCH 13/19] use types/web3 --- remix-tests/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/remix-tests/package.json b/remix-tests/package.json index 92001ca281..24f876a21f 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -38,6 +38,7 @@ "homepage": "https://github.com/ethereum/remix-tests#readme", "dependencies": { "@types/async": "^2.4.0", + "@types/web3": "^1.0.18", "async": "^2.6.0", "change-case": "^3.0.1", "colors": "^1.1.2", From 3478079dcd31bb479672f39226c167728b0b20fb Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Thu, 7 Feb 2019 00:52:22 +0530 Subject: [PATCH 14/19] Add more typings --- remix-tests/src/compiler.ts | 23 +++++++++++------------ remix-tests/src/deployer.ts | 15 ++++++++------- remix-tests/src/index.ts | 6 +++--- remix-tests/src/run.ts | 8 +++++--- remix-tests/src/runTestFiles.ts | 6 ++---- remix-tests/src/runTestSources.ts | 13 ++++++------- remix-tests/src/testRunner.ts | 2 +- remix-tests/tests/testRunner.ts | 14 +++++++------- 8 files changed, 43 insertions(+), 44 deletions(-) diff --git a/remix-tests/src/compiler.ts b/remix-tests/src/compiler.ts index cf5f4f4540..90d111cb4d 100644 --- a/remix-tests/src/compiler.ts +++ b/remix-tests/src/compiler.ts @@ -1,10 +1,9 @@ /* eslint no-extend-native: "warn" */ -let fs = require('./fileSystem') +import fs from './fileSystem' var async = require('async') var path = require('path') let RemixCompiler = require('remix-solidity').Compiler - function regexIndexOf (inputString, regex, startpos = 0) { var indexOf = inputString.substring(startpos).search(regex) return (indexOf >= 0) ? (indexOf + (startpos)) : indexOf @@ -26,8 +25,8 @@ var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? na var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) // TODO: replace this with remix's own compiler code -export function compileFileOrFiles (filename, isDirectory, opts, cb) { - let compiler +export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: any, cb: Function) { + let compiler: any let accounts = opts.accounts || [] const sources = { 'tests.sol': { content: require('../sol/tests.sol.js') }, @@ -43,7 +42,7 @@ export function compileFileOrFiles (filename, isDirectory, opts, cb) { // We should only walk through directory if a directory name is passed try { // walkSync only if it is a directory - fs.walkSync(filepath, foundpath => { + fs.walkSync(filepath, (foundpath: string) => { // only process .sol files if (foundpath.split('.').pop() === 'sol') { let c = fs.readFileSync(foundpath).toString() @@ -59,21 +58,21 @@ export function compileFileOrFiles (filename, isDirectory, opts, cb) { throw e } finally { async.waterfall([ - function loadCompiler (next) { + function loadCompiler(next: Function) { compiler = new RemixCompiler() compiler.onInternalCompilerLoaded() // compiler.event.register('compilerLoaded', this, function (version) { next() // }); }, - function doCompilation (next) { + function doCompilation(next: Function) { // @ts-ignore compiler.event.register('compilationFinished', this, function (success, data, source) { next(null, data) }) compiler.compile(sources, filepath) } - ], function (err, result) { + ], function (err: Error | null | undefined, result) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { if (!isBrowser) require('signale').fatal(errors) @@ -84,7 +83,7 @@ export function compileFileOrFiles (filename, isDirectory, opts, cb) { } } -export function compileContractSources (sources, importFileCb, opts, cb) { +export function compileContractSources(sources, importFileCb, opts, cb) { let compiler, filepath let accounts = opts.accounts || [] // Iterate over sources keys. Inject test libraries. Inject test library import statements. @@ -102,21 +101,21 @@ export function compileContractSources (sources, importFileCb, opts, cb) { } async.waterfall([ - function loadCompiler (next) { + function loadCompiler (next: Function) { compiler = new RemixCompiler(importFileCb) compiler.onInternalCompilerLoaded() // compiler.event.register('compilerLoaded', this, function (version) { next() // }); }, - function doCompilation (next) { + function doCompilation (next: Function) { // @ts-ignore compiler.event.register('compilationFinished', this, function (success, data, source) { next(null, data) }) compiler.compile(sources, filepath) } - ], function (err, result) { + ], function (err: Error | null | undefined , result) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { if (!isBrowser) require('signale').fatal(errors) diff --git a/remix-tests/src/deployer.ts b/remix-tests/src/deployer.ts index 157926aef6..0c091921cd 100644 --- a/remix-tests/src/deployer.ts +++ b/remix-tests/src/deployer.ts @@ -1,19 +1,20 @@ var async = require('async') var remixLib = require('remix-lib') +import Web3 from 'web3' -export function deployAll (compileResult, web3, callback) { +export function deployAll(compileResult: object, web3: Web3, callback: Function) { let compiledObject = {} let contracts = {} - let accounts = [] + let accounts: string[] = [] async.waterfall([ - function getAccountList (next) { + function getAccountList(next: Function) { web3.eth.getAccounts((_err, _accounts) => { accounts = _accounts next() }) }, - function getContractData (next) { + function getContractData(next: Function) { for (let contractFile in compileResult) { for (let contractName in compileResult[contractFile]) { let contract = compileResult[contractFile][contractName] @@ -38,8 +39,8 @@ export function deployAll (compileResult, web3, callback) { } next() }, - function determineContractsToDeploy (next) { - let contractsToDeploy = ['Assert'] + function determineContractsToDeploy(next: Function) { + let contractsToDeploy: string[] = ['Assert'] let allContracts = Object.keys(compiledObject) for (let contractName of allContracts) { @@ -52,7 +53,7 @@ export function deployAll (compileResult, web3, callback) { } next(null, contractsToDeploy) }, - function deployContracts (contractsToDeploy, next) { + function deployContracts(contractsToDeploy: string[], next: Function) { var deployRunner = (deployObject, contractObject, contractName, filename, callback) => { deployObject.estimateGas().then((gasValue) => { deployObject.send({ diff --git a/remix-tests/src/index.ts b/remix-tests/src/index.ts index 03aec74397..2ac9a00233 100644 --- a/remix-tests/src/index.ts +++ b/remix-tests/src/index.ts @@ -1,6 +1,6 @@ -import runTestFiles from './runTestFiles' -import runTestSources from './runTestSources' -import runTest from './testRunner' +import { runTestFiles } from './runTestFiles' +import { runTestSources } from './runTestSources' +import { runTest } from './testRunner' module.exports = { runTestFiles: runTestFiles, diff --git a/remix-tests/src/run.ts b/remix-tests/src/run.ts index dfc9961d20..217a43e843 100644 --- a/remix-tests/src/run.ts +++ b/remix-tests/src/run.ts @@ -1,7 +1,9 @@ +#!/usr/bin/env ts-node + const commander = require('commander') -const Web3 = require('web3') -import runTestFiles from './runTestFiles' -import fs = require('./fileSystem') +import Web3 from 'web3' +import { runTestFiles } from './runTestFiles' +import fs from './fileSystem' const Provider = require('remix-simulator').Provider import Log = require('./logger') const logger = new Log() diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index 1e0c200040..b6ea60ee3f 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -1,13 +1,13 @@ import async = require('async') import path = require('path') import fs from './fileSystem' -import runTest from './testRunner' +import { runTest } from './testRunner' require('colors') import Compiler = require('./compiler') import Deployer = require('./deployer') -function runTestFiles(filepath, isDirectory, web3, opts = {}) { +export function runTestFiles(filepath, isDirectory, web3, opts = {}) { opts = opts || {} const { Signale } = require('signale') // signale configuration @@ -129,5 +129,3 @@ function runTestFiles(filepath, isDirectory, web3, opts = {}) { ], function () { }) } - -export = runTestFiles; diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index 867b1687c2..34da06f5f6 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -1,9 +1,9 @@ import async from 'async' require('colors') -import Compiler = require('./compiler.js') -import Deployer = require('./deployer.js') -import runTest from './testRunner' +import { compileContractSources } from './compiler' +import { deployAll } from './deployer' +import { runTest } from './testRunner' import Web3 = require('web3') import Provider from 'remix-simulator' @@ -21,7 +21,7 @@ var createWeb3Provider = function () { return web3 } -function runTestSources(contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) { +export function runTestSources(contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) { opts = opts || {} let web3 = opts.web3 || createWeb3Provider() let accounts = opts.accounts || null @@ -34,10 +34,10 @@ function runTestSources(contractSources, testCallback, resultCallback, finalCall }) }, function compile (next) { - Compiler.compileContractSources(contractSources, importFileCb, opts, next) + compileContractSources(contractSources, importFileCb, opts, next) }, function deployAllContracts (compilationResult, next) { - Deployer.deployAll(compilationResult, web3, function (err, contracts) { + deployAll(compilationResult, web3, function (err, contracts) { if (err) { next(err) } @@ -115,4 +115,3 @@ function runTestSources(contractSources, testCallback, resultCallback, finalCall } ], finalCallback) } -export = runTestSources; diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index 8f47424520..b6d38470d2 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -73,7 +73,7 @@ function createRunList (jsonInterface) { return runList } -export default function runTest (testName, testObject: any, contractDetails: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) { +export function runTest(testName, testObject: any, contractDetails: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) { let runList = createRunList(testObject._jsonInterface) let passingNum: number = 0 diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index 129d719b3e..1917d5e76c 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -3,9 +3,9 @@ import Web3 from 'web3' import * as assert from 'assert' import { Provider } from 'remix-simulator' -let Compiler = require('../dist/compiler.js') -let Deployer = require('../dist/deployer.js') -import runTest, { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner.js' +import { compileFileOrFiles } from '../dist/compiler' +import { deployAll } from '../dist/deployer' +import { runTest, ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner' function compileAndDeploy(filename: string, callback: Function) { let web3: Web3 = new Web3() @@ -19,13 +19,13 @@ function compileAndDeploy(filename: string, callback: Function) { next(_err) }) }, - function compile(next: Function) { - Compiler.compileFileOrFiles(filename, false, { accounts }, next) + function compile(next: Function): void { + compileFileOrFiles(filename, false, { accounts }, next) }, function deployAllContracts(compilationResult: object, next: Function): void { try { compilationData = compilationResult - Deployer.deployAll(compilationResult, web3, next) + deployAll(compilationResult, web3, next) } catch (e) { throw e } @@ -39,7 +39,7 @@ function compileAndDeploy(filename: string, callback: Function) { describe('testRunner', () => { describe('#runTest', () => { describe('test with beforeAll', () => { - let filename = 'tests/examples_1/simple_storage_test.sol' + let filename: string = 'tests/examples_1/simple_storage_test.sol' let tests: any[] = [], results: ResultsInterface; before((done) => { From ea744dc67903ec4c6b57de09c10526ce25ed496e Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Sat, 9 Feb 2019 00:58:48 +0530 Subject: [PATCH 15/19] Update contract to sol v0.5.0, add more typings, make runTestFiles work --- remix-tests/examples/simple_storage.sol | 1 - remix-tests/package.json | 2 + remix-tests/src/run.ts | 12 ++-- remix-tests/src/runTestFiles.ts | 76 ++++++++++++++----------- remix-tests/src/runTestSources.ts | 5 +- remix-tests/src/testRunner.ts | 37 ++++++------ 6 files changed, 73 insertions(+), 60 deletions(-) diff --git a/remix-tests/examples/simple_storage.sol b/remix-tests/examples/simple_storage.sol index bc74b55c00..278155d1f1 100644 --- a/remix-tests/examples/simple_storage.sol +++ b/remix-tests/examples/simple_storage.sol @@ -13,5 +13,4 @@ contract SimpleStorage { function get() public view returns (uint retVal) { return storedData; } - } diff --git a/remix-tests/package.json b/remix-tests/package.json index 24f876a21f..7285b8970f 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -38,6 +38,7 @@ "homepage": "https://github.com/ethereum/remix-tests#readme", "dependencies": { "@types/async": "^2.4.0", + "@types/colors": "^1.2.1", "@types/web3": "^1.0.18", "async": "^2.6.0", "change-case": "^3.0.1", @@ -54,6 +55,7 @@ "yo-yoify": "latest" }, "devDependencies": { + "@types/commander": "^2.12.2", "@types/mocha": "^5.2.5", "@types/node": "^10.12.21", "babel-preset-es2017": "^6.24.1", diff --git a/remix-tests/src/run.ts b/remix-tests/src/run.ts index 217a43e843..b4cd97fd15 100644 --- a/remix-tests/src/run.ts +++ b/remix-tests/src/run.ts @@ -1,17 +1,15 @@ -#!/usr/bin/env ts-node - -const commander = require('commander') +import commander from 'commander' import Web3 from 'web3' import { runTestFiles } from './runTestFiles' import fs from './fileSystem' const Provider = require('remix-simulator').Provider -import Log = require('./logger') +import Log from './logger' const logger = new Log() const log = logger.logger -require('colors') +import colors from 'colors' // parse verbosity -function mapVerbosity (v) { +function mapVerbosity (v: number) { const levels = { 0: 'error', 1: 'warn', @@ -39,7 +37,7 @@ commander .option('-v, --verbose ', 'run with verbosity', mapVerbosity) .action(function (filename) { // Console message - console.log(('\n\t👁 :: Running remix-tests - Unit testing for solidity :: 👁\t\n'),'color: white') + console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n')) // set logger verbosity if (commander.verbose) { logger.setVerbosity(commander.verbose) diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index b6ea60ee3f..4b08d94595 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -1,13 +1,13 @@ -import async = require('async') -import path = require('path') +import async from 'async' import fs from './fileSystem' -import { runTest } from './testRunner' -require('colors') +import { runTest, TestResultInterface, ResultsInterface } from './testRunner' +import colors from 'colors' +import Web3 from 'web3' -import Compiler = require('./compiler') -import Deployer = require('./deployer') +import { compileFileOrFiles } from './compiler' +import { deployAll } from './deployer' -export function runTestFiles(filepath, isDirectory, web3, opts = {}) { +export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, opts?: object) { opts = opts || {} const { Signale } = require('signale') // signale configuration @@ -33,38 +33,42 @@ export function runTestFiles(filepath, isDirectory, web3, opts = {}) { const signale = new Signale(options) let accounts = opts['accounts'] || null async.waterfall([ - function getAccountList (next) { + function getAccountList (next: Function) { if (accounts) return next(null) - web3.eth.getAccounts((_err, _accounts) => { + web3.eth.getAccounts((_err: Error | null | undefined, _accounts) => { accounts = _accounts next(null) }) }, - function compile (next) { - Compiler.compileFileOrFiles(filepath, isDirectory, { accounts }, next) + function compile(next: Function) { + compileFileOrFiles(filepath, isDirectory, { accounts }, next) }, - function deployAllContracts (compilationResult, next) { - Deployer.deployAll(compilationResult, web3, function (err, contracts) { + function deployAllContracts (compilationResult, next: Function) { + deployAll(compilationResult, web3, (err, contracts) => { if (err) { next(err) } next(null, compilationResult, contracts) }) }, - function determineTestContractsToRun (compilationResult, contracts, next) { + function determineTestContractsToRun (compilationResult, contracts, next: Function) { let contractsToTest: any[] = [] let contractsToTestDetails: any[] = [] - const gatherContractsFrom = (filename) => { + const gatherContractsFrom = function(filename: string) { 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]) - }) + try { + Object.keys(compilationResult[filename]).forEach(contractName => { + contractsToTest.push(contractName) + contractsToTestDetails.push(compilationResult[filename][contractName]) + }) + } catch (e) { + console.error(e) + } } if (isDirectory) { - fs.walkSync(filepath, foundpath => { + fs.walkSync(filepath, (foundpath: string) => { gatherContractsFrom(foundpath) }) } else { @@ -72,13 +76,14 @@ export function runTestFiles(filepath, isDirectory, web3, opts = {}) { } next(null, contractsToTest, contractsToTestDetails, contracts) }, - function runTests (contractsToTest, contractsToTestDetails, contracts, next) { - let totalPassing = 0 - let totalFailing = 0 - let totalTime = 0 + function runTests(contractsToTest, contractsToTestDetails, contracts, next: Function) { + let totalPassing: number = 0 + let totalFailing: number = 0 + let totalTime: number = 0 let errors: any[] = [] - var testCallback = function (result) { + var _testCallback = function (err: Error | null | undefined, result: TestResultInterface) { + if(err) throw err; if (result.type === 'contract') { signale.name(result.value.white) } else if (result.type === 'testPass') { @@ -88,20 +93,25 @@ export function runTestFiles(filepath, isDirectory, web3, opts = {}) { errors.push(result) } } - var resultsCallback = function (_err, result, cb) { + var _resultsCallback = (_err: Error | null | undefined, result: ResultsInterface, cb) => { totalPassing += result.passingNum totalFailing += result.failureNum totalTime += result.timePassed cb() } - async.eachOfLimit(contractsToTest, 1, (contractName, index, cb) => { - runTest(contractName, contracts(contractName), contractsToTestDetails[index], { accounts }, testCallback, (err, result) => { + async.eachOfLimit(contractsToTest, 1, (contractName: string, index, cb) => { + try { + runTest(contractName, contracts[contractName], contractsToTestDetails[index], { accounts }, _testCallback, (err, result) => { if (err) { + console.log(err) return cb(err) } - resultsCallback(null, result, cb) + _resultsCallback(null, result, cb) }) + } catch(e) { + console.error(e) + } }, function (err) { if (err) { return next(err) @@ -109,23 +119,23 @@ export function runTestFiles(filepath, isDirectory, web3, opts = {}) { console.log('\n') if (totalPassing > 0) { - console.log(('%c ' + totalPassing + ' passing ') + ('%c(' + totalTime + 's)'),'color: green','color: grey') + console.log(colors.green(totalPassing + ' passing ') + colors.grey('(' + totalTime + 's)')) } if (totalFailing > 0) { - console.log(('%c ' + totalFailing + ' failing'),'color: red') + console.log(colors.red(totalFailing + ' failing')) } console.log('') errors.forEach((error, index) => { console.log(' ' + (index + 1) + ') ' + error.context + ' ' + error.value) console.log('') - console.log(('%c\t error: ' + error.errMsg),'color: red') + console.log(colors.red('\t error: ' + error.errMsg)) }) console.log('') next() }) } - ], function () { + ], () => { }) } diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index 34da06f5f6..ee989b11a5 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -37,7 +37,7 @@ export function runTestSources(contractSources, testCallback, resultCallback, fi compileContractSources(contractSources, importFileCb, opts, next) }, function deployAllContracts (compilationResult, next) { - deployAll(compilationResult, web3, function (err, contracts) { + deployAll(compilationResult, web3, (err, contracts) => { if (err) { next(err) } @@ -58,10 +58,9 @@ export function runTestSources(contractSources, testCallback, resultCallback, fi contractsToTest.push(contractName) }) } - next(null, contractsToTest, contractsToTestDetails, contracts) }, - function runTests (contractsToTest, contractsToTestDetails, contracts, next) { + function runTests(contractsToTest, contractsToTestDetails, contracts, next) { let totalPassing = 0 let totalFailing = 0 let totalTime = 0 diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index b6d38470d2..72ed491331 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -2,7 +2,7 @@ import async from 'async' import * as changeCase from 'change-case' import Web3 from 'web3' -interface CbReturnInterface { +export interface TestResultInterface { type: string, value: any, time?: number, @@ -10,13 +10,19 @@ interface CbReturnInterface { errMsg?: string filename?: string } +interface RunListInterface { + name: string, + type: string, + constant: boolean, + signature?: any +} export interface ResultsInterface { passingNum: number, failureNum: number, timePassed: number } export interface TestCbInterface { - (error: Error | null | undefined, result?: CbReturnInterface) : void; + (error: Error | null | undefined, result: TestResultInterface) : void; } export interface ResultCbInterface { (error: Error | null | undefined, result: ResultsInterface) : void; @@ -47,27 +53,27 @@ function getTestFunctions (jsonInterface) { return jsonInterface.filter((x) => specialFunctions.indexOf(x.name) < 0 && x.type === 'function') } -function createRunList (jsonInterface) { +function createRunList(jsonInterface): RunListInterface[] { let availableFunctions = getAvailableFunctions(jsonInterface) let testFunctions = getTestFunctions(jsonInterface) - let runList: any[] = [] + let runList: RunListInterface[] = [] if (availableFunctions.indexOf('beforeAll') >= 0) { - runList.push({name: 'beforeAll', type: 'internal', constant: false}) + 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: 'beforeEach', type: 'internal', constant: false }) } - runList.push({name: func.name, signature: func.signature, type: 'test', constant: func.constant}) + 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}) + runList.push({ name: 'afterEach', type: 'internal', constant: false }) } } if (availableFunctions.indexOf('afterAll') >= 0) { - runList.push({name: 'afterAll', type: 'internal', constant: false}) + runList.push({ name: 'afterAll', type: 'internal', constant: false }) } return runList @@ -90,7 +96,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a signale.warn('e.g: the following code won\'t work in the current context:') signale.warn('TestsAccounts.getAccount(' + opts.accounts.length + ')') } - const resp: CbReturnInterface = { + const resp: TestResultInterface = { type: 'contract', value: testName, filename: testObject.filename @@ -113,7 +119,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a method.call(sendParams).then((result) => { let time = Math.ceil((Date.now() - startTime) / 1000.0) if (result) { - const resp: CbReturnInterface = { + const resp: TestResultInterface = { type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, @@ -123,7 +129,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a passingNum += 1 timePassed += time } else { - const resp: CbReturnInterface = { + const resp: TestResultInterface = { type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, @@ -147,7 +153,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a if (event.raw.topics.indexOf(topic) >= 0) { var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data) if (!testEvent[0]) { - const resp: CbReturnInterface = { + const resp: TestResultInterface = { type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, @@ -163,7 +169,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a } if (testPassed) { - const resp: CbReturnInterface = { + const resp: TestResultInterface = { type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, @@ -175,8 +181,7 @@ export function runTest(testName, testObject: any, contractDetails: any, opts: a return next() } catch (err) { - console.log('error!') - console.dir(err) + console.error(err) return next(err) } }).on('error', function (err: Error | null | undefined) { From 0400854e8c1197b941266509bb749144730dd692 Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Mon, 18 Feb 2019 19:31:14 +0530 Subject: [PATCH 16/19] pass safe_math_tests --- .../tests/examples_1/simple_storage_test.sol | 1 - .../tests/examples_2/simple_storage.sol | 1 - remix-tests/tests/examples_4/SafeMath.sol | 2 +- .../tests/examples_4/SafeMathProxy.sol | 12 +++--- .../tests/examples_4/SafeMath_test.sol | 37 +++++++++++-------- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/remix-tests/tests/examples_1/simple_storage_test.sol b/remix-tests/tests/examples_1/simple_storage_test.sol index 35063a4179..a22ef9e504 100644 --- a/remix-tests/tests/examples_1/simple_storage_test.sol +++ b/remix-tests/tests/examples_1/simple_storage_test.sol @@ -26,5 +26,4 @@ contract MyTest { function shouldTriggerOnePass() public { Assert.equal(uint(1), uint(1), "the test 3 fails"); } - } diff --git a/remix-tests/tests/examples_2/simple_storage.sol b/remix-tests/tests/examples_2/simple_storage.sol index bc74b55c00..278155d1f1 100644 --- a/remix-tests/tests/examples_2/simple_storage.sol +++ b/remix-tests/tests/examples_2/simple_storage.sol @@ -13,5 +13,4 @@ contract SimpleStorage { function get() public view returns (uint retVal) { return storedData; } - } diff --git a/remix-tests/tests/examples_4/SafeMath.sol b/remix-tests/tests/examples_4/SafeMath.sol index 72a618504e..3fa42ea119 100644 --- a/remix-tests/tests/examples_4/SafeMath.sol +++ b/remix-tests/tests/examples_4/SafeMath.sol @@ -1,6 +1,6 @@ // Copyright (c) 2016 Smart Contract Solutions, Inc. -pragma solidity ^0.4.24; +pragma solidity >=0.4.22 <0.6.0; /** diff --git a/remix-tests/tests/examples_4/SafeMathProxy.sol b/remix-tests/tests/examples_4/SafeMathProxy.sol index 5b8828c0b6..96b88b8e9b 100644 --- a/remix-tests/tests/examples_4/SafeMathProxy.sol +++ b/remix-tests/tests/examples_4/SafeMathProxy.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity >=0.4.22 <0.6.0; import "./SafeMath.sol"; /* @@ -9,23 +9,23 @@ https://truffleframework.com/tutorials/testing-for-throws-in-solidity-tests contract SafeMathProxy { using SafeMath for uint; - function divProxy(uint256 a, uint256 b) returns (uint256) { + function divProxy(uint256 a, uint256 b) public pure returns (uint256) { return a.div(b); } - function mulProxy(uint256 a, uint256 b) returns (uint256) { + function mulProxy(uint256 a, uint256 b) public pure returns (uint256) { return a.mul(b); } - function subProxy(uint256 a, uint256 b) returns (uint256) { + function subProxy(uint256 a, uint256 b) public pure returns (uint256) { return a.sub(b); } - function addProxy(uint256 a, uint256 b) returns (uint256) { + function addProxy(uint256 a, uint256 b) public pure returns (uint256) { return a.add(b); } - function modProxy(uint256 a, uint256 b) returns (uint256) { + function modProxy(uint256 a, uint256 b) public pure returns (uint256) { return a.mod(b); } } diff --git a/remix-tests/tests/examples_4/SafeMath_test.sol b/remix-tests/tests/examples_4/SafeMath_test.sol index bf4534c913..9953ee8f62 100644 --- a/remix-tests/tests/examples_4/SafeMath_test.sol +++ b/remix-tests/tests/examples_4/SafeMath_test.sol @@ -1,16 +1,16 @@ -pragma solidity ^0.4.24; -import "./remix_tests.sol"; +pragma solidity >=0.4.22 <0.6.0; +import "remix_tests.sol"; import "./SafeMath.sol"; import "./SafeMathProxy.sol"; contract SafeMathTest { SafeMathProxy safemathproxy; - function beforeAll() { + function beforeAll() public { safemathproxy = new SafeMathProxy(); } - function unsafeMultiplicationShouldOverflow() public view returns (bool) { + function unsafeMultiplicationShouldOverflow() public returns (bool) { uint256 a = 4; uint256 b = 2 ** 256 - 1; return Assert.equal( @@ -20,27 +20,29 @@ contract SafeMathTest { ); } - function safeMultiplicationShouldRevert() public view returns (bool) { + function safeMultiplicationShouldRevert() public returns (bool) { uint256 a = 4; uint256 b = 2 ** 256 - 1; + (bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("mulProxy, [a, b]")); return Assert.equal( - address(safemathproxy).call.gas(40000).value(0)("mulProxy",[a, b]), + success, false, "safe multiplication did not revert" ); } - function safeDivisionByZeroShouldRevert() public view returns (bool) { + function safeDivisionByZeroShouldRevert() public returns (bool) { uint256 a = 4; uint256 b = 0; + (bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("divProxy, [a, b]")); return Assert.equal( - address(safemathproxy).call.gas(40000).value(0)("divProxy", [a, b]), + success, false, "safe division did not revert" ); } - function unsafeSubtractShouldUnderflow() public view returns (bool) { + function unsafeSubtractShouldUnderflow() public returns (bool) { uint256 a = 0; uint256 b = a - 1; return Assert.equal( @@ -50,35 +52,38 @@ contract SafeMathTest { ); } - function safeSubtractShouldRevert() public constant returns (bool) { + function safeSubtractShouldRevert() public returns (bool) { + (bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("subProxy, [0, 1]")); return Assert.equal( - address(safemathproxy).call.gas(40000).value(0)("subProxy", [0, 1]), + success, false, "safe subtract should revert" ); } - function unsafeAdditionShouldOverflow() public constant returns (bool) { + function unsafeAdditionShouldOverflow() public returns (bool) { uint256 a = 1; uint256 b = 2 ** 256 - 1; return Assert.equal(a + b, 0, "unsafe addition did not overflow"); } - function safeAdditionShouldRevert() public constant returns (bool) { + function safeAdditionShouldRevert() public returns (bool) { uint256 a = 1; uint256 b = 2 ** 256 - 1; + (bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("addProxy, [a, b]")); return Assert.equal( - address(safemathproxy).call.gas(40000).value(0)("addProxy", [a, b]), + success, false, "safe addition should revert" ); } - function safeModulusShouldRevert() public constant returns (bool) { + function safeModulusShouldRevert() public returns (bool) { uint256 a = 1; uint256 b = 0; + (bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("modProxy, [a, b]")); return Assert.equal( - address(safemathproxy).call.gas(40000).value(0)("modProxy", [a, b]), + success, false, "safe modulus did not revert" ); From 206a65494ea4ca106502d7a75e4d684f2e704adb Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Mon, 18 Feb 2019 20:39:30 +0530 Subject: [PATCH 17/19] Add types file --- remix-tests/src/compiler.ts | 14 +++++------ remix-tests/src/deployer.ts | 4 ++-- remix-tests/src/runTestFiles.ts | 3 ++- remix-tests/src/runTestSources.ts | 8 +------ remix-tests/src/testRunner.ts | 27 +-------------------- remix-tests/src/types.ts | 39 +++++++++++++++++++++++++++++++ remix-tests/tests/testRunner.ts | 7 +++--- 7 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 remix-tests/src/types.ts diff --git a/remix-tests/src/compiler.ts b/remix-tests/src/compiler.ts index 90d111cb4d..60a500f8dd 100644 --- a/remix-tests/src/compiler.ts +++ b/remix-tests/src/compiler.ts @@ -1,15 +1,15 @@ -/* eslint no-extend-native: "warn" */ import fs from './fileSystem' -var async = require('async') +import async from 'async' var path = require('path') let RemixCompiler = require('remix-solidity').Compiler +import { SrcIfc } from './types' -function regexIndexOf (inputString, regex, startpos = 0) { +function regexIndexOf (inputString: string, regex: RegExp, startpos: number = 0) { var indexOf = inputString.substring(startpos).search(regex) return (indexOf >= 0) ? (indexOf + (startpos)) : indexOf } -function writeTestAccountsContract (accounts) { +function writeTestAccountsContract (accounts: string[]) { var testAccountContract = require('../sol/tests_accounts.sol.js') var body = 'address[' + accounts.length + '] memory accounts;' if (!accounts.length) body += ';' @@ -72,7 +72,7 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: }) compiler.compile(sources, filepath) } - ], function (err: Error | null | undefined, result) { + ], function (err: Error | null | undefined, result: any) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { if (!isBrowser) require('signale').fatal(errors) @@ -83,7 +83,7 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: } } -export function compileContractSources(sources, importFileCb, opts, cb) { +export function compileContractSources(sources: SrcIfc, importFileCb, opts, cb) { let compiler, filepath let accounts = opts.accounts || [] // Iterate over sources keys. Inject test libraries. Inject test library import statements. @@ -115,7 +115,7 @@ export function compileContractSources(sources, importFileCb, opts, cb) { }) compiler.compile(sources, filepath) } - ], function (err: Error | null | undefined , result) { + ], function (err: Error | null | undefined , result: any) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { if (!isBrowser) require('signale').fatal(errors) diff --git a/remix-tests/src/deployer.ts b/remix-tests/src/deployer.ts index 0c091921cd..3934cad3dd 100644 --- a/remix-tests/src/deployer.ts +++ b/remix-tests/src/deployer.ts @@ -1,8 +1,8 @@ -var async = require('async') +import async from 'async' var remixLib = require('remix-lib') import Web3 from 'web3' -export function deployAll(compileResult: object, web3: Web3, callback: Function) { +export function deployAll(compileResult: object, web3: Web3, callback) { let compiledObject = {} let contracts = {} let accounts: string[] = [] diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index 4b08d94595..b14d7b5608 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -1,6 +1,7 @@ import async from 'async' import fs from './fileSystem' -import { runTest, TestResultInterface, ResultsInterface } from './testRunner' +import { runTest } from './testRunner' +import { TestResultInterface, ResultsInterface } from './types' import colors from 'colors' import Web3 from 'web3' diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index ee989b11a5..43104d6d6f 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -7,13 +7,7 @@ import { runTest } from './testRunner' import Web3 = require('web3') import Provider from 'remix-simulator' - -interface FinalResult { - totalPassing: number, - totalFailing: number, - totalTime: number, - errors: any[], -} +import { FinalResult } from './types' var createWeb3Provider = function () { let web3 = new Web3() diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index 72ed491331..dbfe7646e4 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -1,32 +1,7 @@ import async from 'async' import * as changeCase from 'change-case' import Web3 from 'web3' - -export interface TestResultInterface { - type: string, - value: any, - time?: number, - context?: string, - errMsg?: string - filename?: string -} -interface RunListInterface { - name: string, - type: string, - constant: boolean, - signature?: any -} -export interface ResultsInterface { - passingNum: number, - failureNum: number, - timePassed: number -} -export interface TestCbInterface { - (error: Error | null | undefined, result: TestResultInterface) : void; -} -export interface ResultCbInterface { - (error: Error | null | undefined, result: ResultsInterface) : void; -} +import { RunListInterface, TestCbInterface, TestResultInterface, ResultCbInterface } from './types' function getFunctionFullName (signature, methodIdentifiers) { for (var method in methodIdentifiers) { diff --git a/remix-tests/src/types.ts b/remix-tests/src/types.ts new file mode 100644 index 0000000000..f33b3a32d2 --- /dev/null +++ b/remix-tests/src/types.ts @@ -0,0 +1,39 @@ +/** sources object with name of the file and content **/ +export interface SrcIfc { + [key: string]: { + content: string + } +} +/** An object with final results of test **/ +export interface FinalResult { + totalPassing: number, + totalFailing: number, + totalTime: number, + errors: any[], +} +/** List of tests to run **/ +export interface RunListInterface { + name: string, + type: string, + constant: boolean, + signature?: any +} +export interface ResultsInterface { + passingNum: number, + failureNum: number, + timePassed: number +} +export interface TestResultInterface { + type: string, + value: any, + time?: number, + context?: string, + errMsg?: string + filename?: string +} +export interface TestCbInterface { + (error: Error | null | undefined, result: TestResultInterface) : void; +} +export interface ResultCbInterface { + (error: Error | null | undefined, result: ResultsInterface) : void; +} diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index 1917d5e76c..b467e106c5 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -5,16 +5,17 @@ import { Provider } from 'remix-simulator' import { compileFileOrFiles } from '../dist/compiler' import { deployAll } from '../dist/deployer' -import { runTest, ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner' +import { runTest } from '../dist/testRunner' +import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/types' function compileAndDeploy(filename: string, callback: Function) { let web3: Web3 = new Web3() web3.setProvider(new Provider()) let compilationData: object - let accounts: object + let accounts: string[] async.waterfall([ function getAccountList(next: Function): void { - web3.eth.getAccounts((_err: Error | null | undefined, _accounts: object) => { + web3.eth.getAccounts((_err: Error | null | undefined, _accounts: string[]) => { accounts = _accounts next(_err) }) From 7fb7747b5a2bd73eb53530a534fe1b2c0725bef5 Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Mon, 18 Feb 2019 21:45:43 +0530 Subject: [PATCH 18/19] Add more fixes, arrow functions --- remix-tests/src/compiler.ts | 8 ++++---- remix-tests/src/index.ts | 15 +++++---------- remix-tests/src/testRunner.ts | 8 ++++---- remix-tests/tests/testRunner.ts | 10 +++++----- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/remix-tests/src/compiler.ts b/remix-tests/src/compiler.ts index 60a500f8dd..ff6d3a3854 100644 --- a/remix-tests/src/compiler.ts +++ b/remix-tests/src/compiler.ts @@ -67,7 +67,7 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: }, function doCompilation(next: Function) { // @ts-ignore - compiler.event.register('compilationFinished', this, function (success, data, source) { + compiler.event.register('compilationFinished', this, (success, data, source) => { next(null, data) }) compiler.compile(sources, filepath) @@ -83,8 +83,8 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: } } -export function compileContractSources(sources: SrcIfc, importFileCb, opts, cb) { - let compiler, filepath +export function compileContractSources(sources: SrcIfc, importFileCb: any, opts: any, cb: Function) { + let compiler, filepath: string let accounts = opts.accounts || [] // Iterate over sources keys. Inject test libraries. Inject test library import statements. if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) { @@ -110,7 +110,7 @@ export function compileContractSources(sources: SrcIfc, importFileCb, opts, cb) }, function doCompilation (next: Function) { // @ts-ignore - compiler.event.register('compilationFinished', this, function (success, data, source) { + compiler.event.register('compilationFinished', this, (success, data, source) => { next(null, data) }) compiler.compile(sources, filepath) diff --git a/remix-tests/src/index.ts b/remix-tests/src/index.ts index 2ac9a00233..aad3269514 100644 --- a/remix-tests/src/index.ts +++ b/remix-tests/src/index.ts @@ -1,10 +1,5 @@ -import { runTestFiles } from './runTestFiles' -import { runTestSources } from './runTestSources' -import { runTest } from './testRunner' - -module.exports = { - runTestFiles: runTestFiles, - runTestSources: runTestSources, - runTest: runTest, - assertLibCode: require('../sol/tests.sol.js') -} +export { runTestFiles } from './runTestFiles' +export { runTestSources } from './runTestSources' +export { runTest } from './testRunner' +export * from './types' +export { assertLibCode } from '../sol/tests.sol.js' diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index dbfe7646e4..de044de78e 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -3,7 +3,7 @@ import * as changeCase from 'change-case' import Web3 from 'web3' import { RunListInterface, TestCbInterface, TestResultInterface, ResultCbInterface } from './types' -function getFunctionFullName (signature, methodIdentifiers) { +function getFunctionFullName (signature: string, methodIdentifiers) { for (var method in methodIdentifiers) { if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { return method @@ -12,7 +12,7 @@ function getFunctionFullName (signature, methodIdentifiers) { return null } -function getOverridedSender (userdoc, signature, methodIdentifiers) { +function getOverridedSender (userdoc, signature: string, methodIdentifiers) { let fullName: any = getFunctionFullName(signature, methodIdentifiers) let match = /sender: account-+(\d)/g let accountIndex = userdoc.methods[fullName] ? match.exec(userdoc.methods[fullName].notice) : null @@ -28,7 +28,7 @@ function getTestFunctions (jsonInterface) { return jsonInterface.filter((x) => specialFunctions.indexOf(x.name) < 0 && x.type === 'function') } -function createRunList(jsonInterface): RunListInterface[] { +function createRunList (jsonInterface): RunListInterface[] { let availableFunctions = getAvailableFunctions(jsonInterface) let testFunctions = getTestFunctions(jsonInterface) let runList: RunListInterface[] = [] @@ -54,7 +54,7 @@ function createRunList(jsonInterface): RunListInterface[] { return runList } -export function runTest(testName, testObject: any, contractDetails: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) { +export function runTest (testName, testObject: any, contractDetails: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) { let runList = createRunList(testObject._jsonInterface) let passingNum: number = 0 diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index b467e106c5..65e8488cf8 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -5,8 +5,8 @@ import { Provider } from 'remix-simulator' import { compileFileOrFiles } from '../dist/compiler' import { deployAll } from '../dist/deployer' -import { runTest } from '../dist/testRunner' -import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/types' +import { runTest } from '../dist/index' +import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/index' function compileAndDeploy(filename: string, callback: Function) { let web3: Web3 = new Web3() @@ -119,7 +119,7 @@ describe('testRunner', () => { let tests: any[] = [], results: ResultsInterface; before(function (done) { - compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + compileAndDeploy(filename, (_err, compilationData, contracts, accounts) => { var testCallback: TestCbInterface = (err, test) => { if (err) { throw err } tests.push(test) @@ -158,7 +158,7 @@ describe('testRunner', () => { let tests: any[] = [], results: ResultsInterface; before(function (done) { - compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + compileAndDeploy(filename, (_err, compilationData, contracts, accounts) => { var testCallback: TestCbInterface = (err, test) => { if (err) { throw err } tests.push(test) @@ -186,7 +186,7 @@ describe('testRunner', () => { let tests: any[] = [], results: ResultsInterface; before(function (done) { - compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) { + compileAndDeploy(filename, (_err, compilationData, contracts, accounts) => { var testCallback: TestCbInterface = (err, test) => { if (err) { throw err } tests.push(test) From e2ec98f2eb9ac279d802709c23f6d4d249ae2b53 Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Mon, 25 Feb 2019 20:00:54 +0530 Subject: [PATCH 19/19] fix ES6 mistakes --- remix-tests/package.json | 7 ++++--- remix-tests/src/compiler.ts | 12 ++++++------ remix-tests/src/deployer.ts | 2 +- remix-tests/src/fileSystem.ts | 8 ++++---- remix-tests/src/logger.ts | 20 ++++++++++---------- remix-tests/src/run.ts | 4 ++-- remix-tests/src/runTestFiles.ts | 4 ++-- remix-tests/src/runTestSources.ts | 6 +++--- remix-tests/src/testRunner.ts | 8 ++++---- 9 files changed, 36 insertions(+), 35 deletions(-) diff --git a/remix-tests/package.json b/remix-tests/package.json index 7285b8970f..4a2c245927 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -37,9 +37,6 @@ }, "homepage": "https://github.com/ethereum/remix-tests#readme", "dependencies": { - "@types/async": "^2.4.0", - "@types/colors": "^1.2.1", - "@types/web3": "^1.0.18", "async": "^2.6.0", "change-case": "^3.0.1", "colors": "^1.1.2", @@ -55,6 +52,10 @@ "yo-yoify": "latest" }, "devDependencies": { + "@types/async": "^2.4.0", + "@types/colors": "^1.2.1", + "@types/web3": "^1.0.18", + "@types/color-support": "^1.1.0", "@types/commander": "^2.12.2", "@types/mocha": "^5.2.5", "@types/node": "^10.12.21", diff --git a/remix-tests/src/compiler.ts b/remix-tests/src/compiler.ts index ff6d3a3854..ceb1260515 100644 --- a/remix-tests/src/compiler.ts +++ b/remix-tests/src/compiler.ts @@ -1,17 +1,17 @@ import fs from './fileSystem' import async from 'async' -var path = require('path') +import path from 'path' let RemixCompiler = require('remix-solidity').Compiler import { SrcIfc } from './types' function regexIndexOf (inputString: string, regex: RegExp, startpos: number = 0) { - var indexOf = inputString.substring(startpos).search(regex) + const indexOf = inputString.substring(startpos).search(regex) return (indexOf >= 0) ? (indexOf + (startpos)) : indexOf } function writeTestAccountsContract (accounts: string[]) { - var testAccountContract = require('../sol/tests_accounts.sol.js') - var body = 'address[' + accounts.length + '] memory accounts;' + const testAccountContract = require('../sol/tests_accounts.sol.js') + let body = `address[${accounts.length}] memory accounts;` if (!accounts.length) body += ';' else { accounts.map((address, index) => { @@ -21,8 +21,8 @@ function writeTestAccountsContract (accounts: string[]) { return testAccountContract.replace('>accounts<', body) } -var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' -var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) +const userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' +const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) // TODO: replace this with remix's own compiler code export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: any, cb: Function) { diff --git a/remix-tests/src/deployer.ts b/remix-tests/src/deployer.ts index 3934cad3dd..3a1eb0318a 100644 --- a/remix-tests/src/deployer.ts +++ b/remix-tests/src/deployer.ts @@ -54,7 +54,7 @@ export function deployAll(compileResult: object, web3: Web3, callback) { next(null, contractsToDeploy) }, function deployContracts(contractsToDeploy: string[], next: Function) { - var deployRunner = (deployObject, contractObject, contractName, filename, callback) => { + const deployRunner = (deployObject, contractObject, contractName, filename, callback) => { deployObject.estimateGas().then((gasValue) => { deployObject.send({ from: accounts[0], diff --git a/remix-tests/src/fileSystem.ts b/remix-tests/src/fileSystem.ts index 14ba6d8495..43ada7cb1b 100644 --- a/remix-tests/src/fileSystem.ts +++ b/remix-tests/src/fileSystem.ts @@ -1,14 +1,14 @@ // Extend fs let fs: any = require('fs') -const path = require('path') +import path from 'path' // https://github.com/mikeal/node-utils/blob/master/file/lib/main.js -fs.walkSync = function (start, callback) { - fs.readdirSync(start).forEach(name => { +fs.walkSync = function (start: string, callback: Function) { + fs.readdirSync(start).forEach((name: string) => { if (name === 'node_modules') { return // hack } - var abspath = path.join(start, name) + const abspath = path.join(start, name) if (fs.statSync(abspath).isDirectory()) { fs.walkSync(abspath, callback) } else { diff --git a/remix-tests/src/logger.ts b/remix-tests/src/logger.ts index c1e5d13c92..a1ef9a784e 100644 --- a/remix-tests/src/logger.ts +++ b/remix-tests/src/logger.ts @@ -1,23 +1,23 @@ -var gray = require('ansi-gray') -const winston = require('winston') -var timestamp = require('time-stamp') -var supportsColor = require('color-support') +import colors from 'colors' +import winston, { Logger, LoggerOptions } from 'winston' +import timestamp from 'time-stamp'; +import supportsColor from 'color-support' -function hasFlag (flag) { +function hasFlag (flag: string) { return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)) } -function addColor (str) { +function addColor (str: string) { if (hasFlag('no-color')) { return str } if (hasFlag('color')) { - return gray(str) + return colors.gray(str) } if (supportsColor()) { - return gray(str) + return colors.gray(str) } return str @@ -31,7 +31,7 @@ const logFmt = winston.format.printf((info) => { }) class Log { - logger: any; + logger: Logger; constructor () { this.logger = winston.createLogger({ level: 'error', @@ -42,7 +42,7 @@ class Log { ) }) } - setVerbosity (v) { + setVerbosity (v: LoggerOptions["level"]) { this.logger.configure({ level: v, transports: [new winston.transports.Console()], diff --git a/remix-tests/src/run.ts b/remix-tests/src/run.ts index b4cd97fd15..1364ad6855 100644 --- a/remix-tests/src/run.ts +++ b/remix-tests/src/run.ts @@ -2,7 +2,7 @@ import commander from 'commander' import Web3 from 'web3' import { runTestFiles } from './runTestFiles' import fs from './fileSystem' -const Provider = require('remix-simulator').Provider +import { Provider } from 'remix-simulator' import Log from './logger' const logger = new Log() const log = logger.logger @@ -35,7 +35,7 @@ commander.command('help').description('output usage information').action(functio // get current version commander .option('-v, --verbose ', 'run with verbosity', mapVerbosity) - .action(function (filename) { + .action((filename) => { // Console message console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n')) // set logger verbosity diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index b14d7b5608..7fbace3b9b 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -83,7 +83,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, let totalTime: number = 0 let errors: any[] = [] - var _testCallback = function (err: Error | null | undefined, result: TestResultInterface) { + const _testCallback = function (err: Error | null | undefined, result: TestResultInterface) { if(err) throw err; if (result.type === 'contract') { signale.name(result.value.white) @@ -94,7 +94,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, errors.push(result) } } - var _resultsCallback = (_err: Error | null | undefined, result: ResultsInterface, cb) => { + const _resultsCallback = (_err: Error | null | undefined, result: ResultsInterface, cb) => { totalPassing += result.passingNum totalFailing += result.failureNum totalTime += result.timePassed diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index 43104d6d6f..c9e18fbff3 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -9,7 +9,7 @@ import Web3 = require('web3') import Provider from 'remix-simulator' import { FinalResult } from './types' -var createWeb3Provider = function () { +const createWeb3Provider = function () { let web3 = new Web3() web3.setProvider(new Provider()) return web3 @@ -60,14 +60,14 @@ export function runTestSources(contractSources, testCallback, resultCallback, fi let totalTime = 0 let errors: any[] = [] - var _testCallback = function (result) { + const _testCallback = function (result) { if (result.type === 'testFailure') { errors.push(result) } testCallback(result) } - var _resultsCallback = function (_err, result, cb) { + const _resultsCallback = function (_err, result, cb) { resultCallback(_err, result, () => {}) totalPassing += result.passingNum totalFailing += result.failureNum diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index de044de78e..2b1791d1ce 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -4,7 +4,7 @@ import Web3 from 'web3' import { RunListInterface, TestCbInterface, TestResultInterface, ResultCbInterface } from './types' function getFunctionFullName (signature: string, methodIdentifiers) { - for (var method in methodIdentifiers) { + for (const method in methodIdentifiers) { if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { return method } @@ -62,8 +62,8 @@ export function runTest (testName, testObject: any, contractDetails: any, opts: let timePassed: number = 0 let web3 = new Web3() - var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' - var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) + const userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' + const 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 + ') :') @@ -126,7 +126,7 @@ export function runTest (testName, testObject: any, contractDetails: any, opts: 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) + const testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data) if (!testEvent[0]) { const resp: TestResultInterface = { type: 'testFailure',