From e23a8c0238fe7cd10de10e633f66b328913f3a77 Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Mon, 25 Feb 2019 20:00:54 +0530 Subject: [PATCH] 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',