Add more typings

pull/7/head
Omkara 6 years ago
parent fa5af91759
commit 3478079dcd
  1. 21
      remix-tests/src/compiler.ts
  2. 15
      remix-tests/src/deployer.ts
  3. 6
      remix-tests/src/index.ts
  4. 8
      remix-tests/src/run.ts
  5. 6
      remix-tests/src/runTestFiles.ts
  6. 13
      remix-tests/src/runTestSources.ts
  7. 2
      remix-tests/src/testRunner.ts
  8. 14
      remix-tests/tests/testRunner.ts

@ -1,10 +1,9 @@
/* eslint no-extend-native: "warn" */ /* eslint no-extend-native: "warn" */
let fs = require('./fileSystem') import fs from './fileSystem'
var async = require('async') var async = require('async')
var path = require('path') var path = require('path')
let RemixCompiler = require('remix-solidity').Compiler let RemixCompiler = require('remix-solidity').Compiler
function regexIndexOf (inputString, regex, startpos = 0) { function regexIndexOf (inputString, regex, startpos = 0) {
var indexOf = inputString.substring(startpos).search(regex) var indexOf = inputString.substring(startpos).search(regex)
return (indexOf >= 0) ? (indexOf + (startpos)) : indexOf 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) var 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, isDirectory, opts, cb) { export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: any, cb: Function) {
let compiler let compiler: any
let accounts = opts.accounts || [] let accounts = opts.accounts || []
const sources = { const sources = {
'tests.sol': { content: require('../sol/tests.sol.js') }, '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 // We should only walk through directory if a directory name is passed
try { try {
// walkSync only if it is a directory // walkSync only if it is a directory
fs.walkSync(filepath, foundpath => { fs.walkSync(filepath, (foundpath: string) => {
// only process .sol files // only process .sol files
if (foundpath.split('.').pop() === 'sol') { if (foundpath.split('.').pop() === 'sol') {
let c = fs.readFileSync(foundpath).toString() let c = fs.readFileSync(foundpath).toString()
@ -59,21 +58,21 @@ export function compileFileOrFiles (filename, isDirectory, opts, cb) {
throw e throw e
} finally { } finally {
async.waterfall([ async.waterfall([
function loadCompiler (next) { function loadCompiler(next: Function) {
compiler = new RemixCompiler() compiler = new RemixCompiler()
compiler.onInternalCompilerLoaded() compiler.onInternalCompilerLoaded()
// compiler.event.register('compilerLoaded', this, function (version) { // compiler.event.register('compilerLoaded', this, function (version) {
next() next()
// }); // });
}, },
function doCompilation (next) { function doCompilation(next: Function) {
// @ts-ignore // @ts-ignore
compiler.event.register('compilationFinished', this, function (success, data, source) { compiler.event.register('compilationFinished', this, function (success, data, source) {
next(null, data) next(null, data)
}) })
compiler.compile(sources, filepath) 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') let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error')
if (errors.length > 0) { if (errors.length > 0) {
if (!isBrowser) require('signale').fatal(errors) if (!isBrowser) require('signale').fatal(errors)
@ -102,21 +101,21 @@ export function compileContractSources (sources, importFileCb, opts, cb) {
} }
async.waterfall([ async.waterfall([
function loadCompiler (next) { function loadCompiler (next: Function) {
compiler = new RemixCompiler(importFileCb) compiler = new RemixCompiler(importFileCb)
compiler.onInternalCompilerLoaded() compiler.onInternalCompilerLoaded()
// compiler.event.register('compilerLoaded', this, function (version) { // compiler.event.register('compilerLoaded', this, function (version) {
next() next()
// }); // });
}, },
function doCompilation (next) { function doCompilation (next: Function) {
// @ts-ignore // @ts-ignore
compiler.event.register('compilationFinished', this, function (success, data, source) { compiler.event.register('compilationFinished', this, function (success, data, source) {
next(null, data) next(null, data)
}) })
compiler.compile(sources, filepath) 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') let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error')
if (errors.length > 0) { if (errors.length > 0) {
if (!isBrowser) require('signale').fatal(errors) if (!isBrowser) require('signale').fatal(errors)

@ -1,19 +1,20 @@
var async = require('async') var async = require('async')
var remixLib = require('remix-lib') 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 compiledObject = {}
let contracts = {} let contracts = {}
let accounts = [] let accounts: string[] = []
async.waterfall([ async.waterfall([
function getAccountList (next) { function getAccountList(next: Function) {
web3.eth.getAccounts((_err, _accounts) => { web3.eth.getAccounts((_err, _accounts) => {
accounts = _accounts accounts = _accounts
next() next()
}) })
}, },
function getContractData (next) { function getContractData(next: Function) {
for (let contractFile in compileResult) { for (let contractFile in compileResult) {
for (let contractName in compileResult[contractFile]) { for (let contractName in compileResult[contractFile]) {
let contract = compileResult[contractFile][contractName] let contract = compileResult[contractFile][contractName]
@ -38,8 +39,8 @@ export function deployAll (compileResult, web3, callback) {
} }
next() next()
}, },
function determineContractsToDeploy (next) { function determineContractsToDeploy(next: Function) {
let contractsToDeploy = ['Assert'] let contractsToDeploy: string[] = ['Assert']
let allContracts = Object.keys(compiledObject) let allContracts = Object.keys(compiledObject)
for (let contractName of allContracts) { for (let contractName of allContracts) {
@ -52,7 +53,7 @@ export function deployAll (compileResult, web3, callback) {
} }
next(null, contractsToDeploy) next(null, contractsToDeploy)
}, },
function deployContracts (contractsToDeploy, next) { function deployContracts(contractsToDeploy: string[], next: Function) {
var deployRunner = (deployObject, contractObject, contractName, filename, callback) => { var deployRunner = (deployObject, contractObject, contractName, filename, callback) => {
deployObject.estimateGas().then((gasValue) => { deployObject.estimateGas().then((gasValue) => {
deployObject.send({ deployObject.send({

@ -1,6 +1,6 @@
import runTestFiles from './runTestFiles' import { runTestFiles } from './runTestFiles'
import runTestSources from './runTestSources' import { runTestSources } from './runTestSources'
import runTest from './testRunner' import { runTest } from './testRunner'
module.exports = { module.exports = {
runTestFiles: runTestFiles, runTestFiles: runTestFiles,

@ -1,7 +1,9 @@
#!/usr/bin/env ts-node
const commander = require('commander') const commander = require('commander')
const Web3 = require('web3') import Web3 from 'web3'
import runTestFiles from './runTestFiles' import { runTestFiles } from './runTestFiles'
import fs = require('./fileSystem') import fs from './fileSystem'
const Provider = require('remix-simulator').Provider const Provider = require('remix-simulator').Provider
import Log = require('./logger') import Log = require('./logger')
const logger = new Log() const logger = new Log()

@ -1,13 +1,13 @@
import async = require('async') import async = require('async')
import path = require('path') import path = require('path')
import fs from './fileSystem' import fs from './fileSystem'
import runTest from './testRunner' import { runTest } from './testRunner'
require('colors') require('colors')
import Compiler = require('./compiler') import Compiler = require('./compiler')
import Deployer = require('./deployer') import Deployer = require('./deployer')
function runTestFiles(filepath, isDirectory, web3, opts = {}) { export function runTestFiles(filepath, isDirectory, web3, opts = {}) {
opts = opts || {} opts = opts || {}
const { Signale } = require('signale') const { Signale } = require('signale')
// signale configuration // signale configuration
@ -129,5 +129,3 @@ function runTestFiles(filepath, isDirectory, web3, opts = {}) {
], function () { ], function () {
}) })
} }
export = runTestFiles;

@ -1,9 +1,9 @@
import async from 'async' import async from 'async'
require('colors') require('colors')
import Compiler = require('./compiler.js') import { compileContractSources } from './compiler'
import Deployer = require('./deployer.js') import { deployAll } from './deployer'
import runTest from './testRunner' import { runTest } from './testRunner'
import Web3 = require('web3') import Web3 = require('web3')
import Provider from 'remix-simulator' import Provider from 'remix-simulator'
@ -21,7 +21,7 @@ var createWeb3Provider = function () {
return web3 return web3
} }
function runTestSources(contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) { export function runTestSources(contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) {
opts = opts || {} opts = opts || {}
let web3 = opts.web3 || createWeb3Provider() let web3 = opts.web3 || createWeb3Provider()
let accounts = opts.accounts || null let accounts = opts.accounts || null
@ -34,10 +34,10 @@ function runTestSources(contractSources, testCallback, resultCallback, finalCall
}) })
}, },
function compile (next) { function compile (next) {
Compiler.compileContractSources(contractSources, importFileCb, opts, next) compileContractSources(contractSources, importFileCb, opts, next)
}, },
function deployAllContracts (compilationResult, next) { function deployAllContracts (compilationResult, next) {
Deployer.deployAll(compilationResult, web3, function (err, contracts) { deployAll(compilationResult, web3, function (err, contracts) {
if (err) { if (err) {
next(err) next(err)
} }
@ -115,4 +115,3 @@ function runTestSources(contractSources, testCallback, resultCallback, finalCall
} }
], finalCallback) ], finalCallback)
} }
export = runTestSources;

@ -73,7 +73,7 @@ function createRunList (jsonInterface) {
return runList 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 runList = createRunList(testObject._jsonInterface)
let passingNum: number = 0 let passingNum: number = 0

@ -3,9 +3,9 @@ import Web3 from 'web3'
import * as assert from 'assert' import * as assert from 'assert'
import { Provider } from 'remix-simulator' import { Provider } from 'remix-simulator'
let Compiler = require('../dist/compiler.js') import { compileFileOrFiles } from '../dist/compiler'
let Deployer = require('../dist/deployer.js') import { deployAll } from '../dist/deployer'
import runTest, { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner.js' import { runTest, ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner'
function compileAndDeploy(filename: string, callback: Function) { function compileAndDeploy(filename: string, callback: Function) {
let web3: Web3 = new Web3() let web3: Web3 = new Web3()
@ -19,13 +19,13 @@ function compileAndDeploy(filename: string, callback: Function) {
next(_err) next(_err)
}) })
}, },
function compile(next: Function) { function compile(next: Function): void {
Compiler.compileFileOrFiles(filename, false, { accounts }, next) compileFileOrFiles(filename, false, { accounts }, next)
}, },
function deployAllContracts(compilationResult: object, next: Function): void { function deployAllContracts(compilationResult: object, next: Function): void {
try { try {
compilationData = compilationResult compilationData = compilationResult
Deployer.deployAll(compilationResult, web3, next) deployAll(compilationResult, web3, next)
} catch (e) { } catch (e) {
throw e throw e
} }
@ -39,7 +39,7 @@ function compileAndDeploy(filename: string, callback: Function) {
describe('testRunner', () => { describe('testRunner', () => {
describe('#runTest', () => { describe('#runTest', () => {
describe('test with beforeAll', () => { 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; let tests: any[] = [], results: ResultsInterface;
before((done) => { before((done) => {

Loading…
Cancel
Save