fix ES6 mistakes

pull/7/head
Omkara 6 years ago committed by 0mkar
parent 7b872b09f6
commit e23a8c0238
  1. 7
      remix-tests/package.json
  2. 12
      remix-tests/src/compiler.ts
  3. 2
      remix-tests/src/deployer.ts
  4. 8
      remix-tests/src/fileSystem.ts
  5. 20
      remix-tests/src/logger.ts
  6. 4
      remix-tests/src/run.ts
  7. 4
      remix-tests/src/runTestFiles.ts
  8. 6
      remix-tests/src/runTestSources.ts
  9. 8
      remix-tests/src/testRunner.ts

@ -37,9 +37,6 @@
}, },
"homepage": "https://github.com/ethereum/remix-tests#readme", "homepage": "https://github.com/ethereum/remix-tests#readme",
"dependencies": { "dependencies": {
"@types/async": "^2.4.0",
"@types/colors": "^1.2.1",
"@types/web3": "^1.0.18",
"async": "^2.6.0", "async": "^2.6.0",
"change-case": "^3.0.1", "change-case": "^3.0.1",
"colors": "^1.1.2", "colors": "^1.1.2",
@ -55,6 +52,10 @@
"yo-yoify": "latest" "yo-yoify": "latest"
}, },
"devDependencies": { "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/commander": "^2.12.2",
"@types/mocha": "^5.2.5", "@types/mocha": "^5.2.5",
"@types/node": "^10.12.21", "@types/node": "^10.12.21",

@ -1,17 +1,17 @@
import fs from './fileSystem' import fs from './fileSystem'
import async from 'async' import async from 'async'
var path = require('path') import path from 'path'
let RemixCompiler = require('remix-solidity').Compiler let RemixCompiler = require('remix-solidity').Compiler
import { SrcIfc } from './types' import { SrcIfc } from './types'
function regexIndexOf (inputString: string, regex: RegExp, startpos: number = 0) { 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 return (indexOf >= 0) ? (indexOf + (startpos)) : indexOf
} }
function writeTestAccountsContract (accounts: string[]) { function writeTestAccountsContract (accounts: string[]) {
var testAccountContract = require('../sol/tests_accounts.sol.js') const testAccountContract = require('../sol/tests_accounts.sol.js')
var body = 'address[' + accounts.length + '] memory accounts;' let body = `address[${accounts.length}] memory accounts;`
if (!accounts.length) body += ';' if (!accounts.length) body += ';'
else { else {
accounts.map((address, index) => { accounts.map((address, index) => {
@ -21,8 +21,8 @@ function writeTestAccountsContract (accounts: string[]) {
return testAccountContract.replace('>accounts<', body) return testAccountContract.replace('>accounts<', body)
} }
var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' const userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-'
var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1)
// TODO: replace this with remix's own compiler code // TODO: replace this with remix's own compiler code
export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: any, cb: Function) { export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: any, cb: Function) {

@ -54,7 +54,7 @@ export function deployAll(compileResult: object, web3: Web3, callback) {
next(null, contractsToDeploy) next(null, contractsToDeploy)
}, },
function deployContracts(contractsToDeploy: string[], next: Function) { 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.estimateGas().then((gasValue) => {
deployObject.send({ deployObject.send({
from: accounts[0], from: accounts[0],

@ -1,14 +1,14 @@
// Extend fs // Extend fs
let fs: any = require('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 // https://github.com/mikeal/node-utils/blob/master/file/lib/main.js
fs.walkSync = function (start, callback) { fs.walkSync = function (start: string, callback: Function) {
fs.readdirSync(start).forEach(name => { fs.readdirSync(start).forEach((name: string) => {
if (name === 'node_modules') { if (name === 'node_modules') {
return // hack return // hack
} }
var abspath = path.join(start, name) const abspath = path.join(start, name)
if (fs.statSync(abspath).isDirectory()) { if (fs.statSync(abspath).isDirectory()) {
fs.walkSync(abspath, callback) fs.walkSync(abspath, callback)
} else { } else {

@ -1,23 +1,23 @@
var gray = require('ansi-gray') import colors from 'colors'
const winston = require('winston') import winston, { Logger, LoggerOptions } from 'winston'
var timestamp = require('time-stamp') import timestamp from 'time-stamp';
var supportsColor = require('color-support') import supportsColor from 'color-support'
function hasFlag (flag) { function hasFlag (flag: string) {
return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)) return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
} }
function addColor (str) { function addColor (str: string) {
if (hasFlag('no-color')) { if (hasFlag('no-color')) {
return str return str
} }
if (hasFlag('color')) { if (hasFlag('color')) {
return gray(str) return colors.gray(str)
} }
if (supportsColor()) { if (supportsColor()) {
return gray(str) return colors.gray(str)
} }
return str return str
@ -31,7 +31,7 @@ const logFmt = winston.format.printf((info) => {
}) })
class Log { class Log {
logger: any; logger: Logger;
constructor () { constructor () {
this.logger = winston.createLogger({ this.logger = winston.createLogger({
level: 'error', level: 'error',
@ -42,7 +42,7 @@ class Log {
) )
}) })
} }
setVerbosity (v) { setVerbosity (v: LoggerOptions["level"]) {
this.logger.configure({ this.logger.configure({
level: v, level: v,
transports: [new winston.transports.Console()], transports: [new winston.transports.Console()],

@ -2,7 +2,7 @@ import commander from 'commander'
import Web3 from 'web3' import Web3 from 'web3'
import { runTestFiles } from './runTestFiles' import { runTestFiles } from './runTestFiles'
import fs from './fileSystem' import fs from './fileSystem'
const Provider = require('remix-simulator').Provider import { Provider } from 'remix-simulator'
import Log from './logger' import Log from './logger'
const logger = new Log() const logger = new Log()
const log = logger.logger const log = logger.logger
@ -35,7 +35,7 @@ commander.command('help').description('output usage information').action(functio
// get current version // get current version
commander commander
.option('-v, --verbose <level>', 'run with verbosity', mapVerbosity) .option('-v, --verbose <level>', 'run with verbosity', mapVerbosity)
.action(function (filename) { .action((filename) => {
// Console message // Console message
console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n')) console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n'))
// set logger verbosity // set logger verbosity

@ -83,7 +83,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
let totalTime: number = 0 let totalTime: number = 0
let errors: any[] = [] 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(err) throw err;
if (result.type === 'contract') { if (result.type === 'contract') {
signale.name(result.value.white) signale.name(result.value.white)
@ -94,7 +94,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
errors.push(result) errors.push(result)
} }
} }
var _resultsCallback = (_err: Error | null | undefined, result: ResultsInterface, cb) => { const _resultsCallback = (_err: Error | null | undefined, result: ResultsInterface, cb) => {
totalPassing += result.passingNum totalPassing += result.passingNum
totalFailing += result.failureNum totalFailing += result.failureNum
totalTime += result.timePassed totalTime += result.timePassed

@ -9,7 +9,7 @@ import Web3 = require('web3')
import Provider from 'remix-simulator' import Provider from 'remix-simulator'
import { FinalResult } from './types' import { FinalResult } from './types'
var createWeb3Provider = function () { const createWeb3Provider = function () {
let web3 = new Web3() let web3 = new Web3()
web3.setProvider(new Provider()) web3.setProvider(new Provider())
return web3 return web3
@ -60,14 +60,14 @@ export function runTestSources(contractSources, testCallback, resultCallback, fi
let totalTime = 0 let totalTime = 0
let errors: any[] = [] let errors: any[] = []
var _testCallback = function (result) { const _testCallback = function (result) {
if (result.type === 'testFailure') { if (result.type === 'testFailure') {
errors.push(result) errors.push(result)
} }
testCallback(result) testCallback(result)
} }
var _resultsCallback = function (_err, result, cb) { const _resultsCallback = function (_err, result, cb) {
resultCallback(_err, result, () => {}) resultCallback(_err, result, () => {})
totalPassing += result.passingNum totalPassing += result.passingNum
totalFailing += result.failureNum totalFailing += result.failureNum

@ -4,7 +4,7 @@ import Web3 from 'web3'
import { RunListInterface, TestCbInterface, TestResultInterface, ResultCbInterface } from './types' import { RunListInterface, TestCbInterface, TestResultInterface, ResultCbInterface } from './types'
function getFunctionFullName (signature: string, methodIdentifiers) { function getFunctionFullName (signature: string, methodIdentifiers) {
for (var method in methodIdentifiers) { for (const method in methodIdentifiers) {
if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) {
return method return method
} }
@ -62,8 +62,8 @@ export function runTest (testName, testObject: any, contractDetails: any, opts:
let timePassed: number = 0 let timePassed: number = 0
let web3 = new Web3() let web3 = new Web3()
var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' const userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-'
var isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1) const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1)
if (!isBrowser) { if (!isBrowser) {
let signale = require('signale') 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('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) { for (let i in receipt.events) {
let event = receipt.events[i] let event = receipt.events[i]
if (event.raw.topics.indexOf(topic) >= 0) { 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]) { if (!testEvent[0]) {
const resp: TestResultInterface = { const resp: TestResultInterface = {
type: 'testFailure', type: 'testFailure',

Loading…
Cancel
Save