From e24467b2571738447ac50cf89d719df4e798df96 Mon Sep 17 00:00:00 2001 From: Omkara <0mkar@protonmail.com> Date: Mon, 18 Feb 2019 20:39:30 +0530 Subject: [PATCH] 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) })