From d9a9948e50884c32f7a21b9521f48998e5712138 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Mon, 6 Jul 2020 16:56:33 +0530 Subject: [PATCH] lint working for remix-tests --- libs/remix-tests/.eslintrc | 17 ++++++++ libs/remix-tests/package.json | 8 ++-- libs/remix-tests/src/compiler.ts | 42 +++++++++---------- libs/remix-tests/src/deployer.ts | 58 ++++++++++++-------------- libs/remix-tests/src/fileSystem.ts | 4 +- libs/remix-tests/src/logger.ts | 2 +- libs/remix-tests/src/run.ts | 6 +-- libs/remix-tests/src/runTestFiles.ts | 24 +++++------ libs/remix-tests/src/runTestSources.ts | 22 +++++----- libs/remix-tests/src/testRunner.ts | 22 +++++----- libs/remix-tests/src/types.ts | 8 ++-- libs/remix-tests/tests/testRunner.ts | 10 ++--- libs/remix-tests/tsconfig.json | 27 +++--------- libs/remix-tests/tsconfig.lib.json | 15 +++++++ workspace.json | 31 ++++++-------- 15 files changed, 150 insertions(+), 146 deletions(-) create mode 100644 libs/remix-tests/.eslintrc create mode 100644 libs/remix-tests/tsconfig.lib.json diff --git a/libs/remix-tests/.eslintrc b/libs/remix-tests/.eslintrc new file mode 100644 index 0000000000..8a034e188f --- /dev/null +++ b/libs/remix-tests/.eslintrc @@ -0,0 +1,17 @@ +{ + "extends": "../../.eslintrc", + "rules": { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/ban-ts-comment": "off" + }, + "env": { + "browser": true, + "amd": true, + "node": true, + "es6": true + }, + "ignorePatterns": ["!**/*"] +} \ No newline at end of file diff --git a/libs/remix-tests/package.json b/libs/remix-tests/package.json index 8e7e6d0d65..639c87b200 100644 --- a/libs/remix-tests/package.json +++ b/libs/remix-tests/package.json @@ -1,5 +1,5 @@ { - "name": "remix-tests", + "name": "@remix-project/remix-tests", "version": "0.1.33", "description": "Tool to test Solidity smart contracts", "main": "./dist/index.js", @@ -44,9 +44,9 @@ "change-case": "^3.0.1", "colors": "^1.1.2", "commander": "^2.13.0", - "remix-lib": "0.4.29", - "remix-simulator": "0.1.9-beta.5", - "remix-solidity": "0.3.30", + "@remix-project/remix-lib": "0.4.29", + "@remix-project/remix-simulator": "0.1.9-beta.5", + "@remix-project/remix-solidity": "0.3.30", "signale": "^1.4.0", "web3": "^1.2.4", "winston": "^3.0.0" diff --git a/libs/remix-tests/src/compiler.ts b/libs/remix-tests/src/compiler.ts index c3245057a3..84d5a01795 100644 --- a/libs/remix-tests/src/compiler.ts +++ b/libs/remix-tests/src/compiler.ts @@ -1,10 +1,10 @@ import fs from './fileSystem' import async from 'async' import path from 'path' -let RemixCompiler = require('remix-solidity').Compiler +const RemixCompiler = require('@remix-project/remix-solidity').Compiler import { SrcIfc, CompilerConfiguration, CompilationErrors } from './types' -function regexIndexOf (inputString: string, regex: RegExp, startpos: number = 0) { +function regexIndexOf (inputString: string, regex: RegExp, startpos = 0) { const indexOf = inputString.substring(startpos).search(regex) return (indexOf >= 0) ? (indexOf + (startpos)) : indexOf } @@ -41,8 +41,8 @@ function isRemixTestFile(path: string) { * @param isRoot True, If file is a root test contract file which is getting processed, not an imported file */ -function processFile(filePath: string, sources: SrcIfc, isRoot: boolean = false) { - const importRegEx: RegExp = /import ['"](.+?)['"];/g; +function processFile(filePath: string, sources: SrcIfc, isRoot = false) { + const importRegEx = /import ['"](.+?)['"];/g; let group: RegExpExecArray| null = null; const isFileAlreadyInSources: boolean = Object.keys(sources).includes(filePath) @@ -51,18 +51,18 @@ function processFile(filePath: string, sources: SrcIfc, isRoot: boolean = false) return let content: string = fs.readFileSync(filePath, { encoding: 'utf-8' }); - const testFileImportRegEx: RegExp = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm + const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm // import 'remix_tests.sol', if file is a root test contract file and doesn't already have it if (isRoot && filePath.endsWith('_test.sol') && regexIndexOf(content, testFileImportRegEx) < 0) { - const includeTestLibs: string = '\nimport \'remix_tests.sol\';\n' + const includeTestLibs = '\nimport \'remix_tests.sol\';\n' content = includeTestLibs.concat(content) } sources[filePath] = {content}; importRegEx.exec(''); // Resetting state of RegEx // Process each 'import' in file content - while (group = importRegEx.exec(content)) { + while ((group = importRegEx.exec(content))) { const importedFile: string = group[1]; const importedFilePath: string = path.join(path.dirname(filePath), importedFile); processFile(importedFilePath, sources) @@ -82,7 +82,7 @@ const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' elect * 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): void { let compiler: any const accounts: string[] = opts.accounts || [] const sources: SrcIfc = { @@ -108,18 +108,18 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: }) } - } catch (e) { + } catch (e) { // eslint-disable-line no-useless-catch throw e } finally { async.waterfall([ - function loadCompiler(next: Function) { + function loadCompiler(next) { compiler = new RemixCompiler() compiler.onInternalCompilerLoaded() // compiler.event.register('compilerLoaded', this, function (version) { next() // }); }, - function doCompilation(next: Function) { + function doCompilation(next) { // @ts-ignore compiler.event.register('compilationFinished', this, (success, data, source) => { next(null, data) @@ -127,9 +127,9 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: compiler.compile(sources, filepath) } ], function (err: Error | null | undefined, result: any) { - let error: Error[] = [] + const error: Error[] = [] if (result.error) error.push(result.error) - let errors = (result.errors || error).filter((e) => e.type === 'Error' || e.severity === 'error') + const errors = (result.errors || error).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { if (!isBrowser) require('signale').fatal(errors) return cb(new CompilationErrors(errors)) @@ -147,7 +147,7 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: * @param opts Options * @param cb Callback */ -export function compileContractSources(sources: SrcIfc, compilerConfig: CompilerConfiguration, importFileCb: any, opts: any, cb: Function) { +export function compileContractSources(sources: SrcIfc, compilerConfig: CompilerConfiguration, importFileCb: any, opts: any, cb): void { let compiler, filepath: string const accounts: string[] = opts.accounts || [] // Iterate over sources keys. Inject test libraries. Inject test library import statements. @@ -156,10 +156,10 @@ export function compileContractSources(sources: SrcIfc, compilerConfig: Compiler sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } sources['remix_accounts.sol'] = { content: writeTestAccountsContract(accounts) } } - const testFileImportRegEx: RegExp = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm + const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm - let includeTestLibs: string = '\nimport \'remix_tests.sol\';\n' - for (let file in sources) { + const includeTestLibs = '\nimport \'remix_tests.sol\';\n' + for (const file in sources) { const c: string = sources[file].content if (file.endsWith('_test.sol') && c && regexIndexOf(c, testFileImportRegEx) < 0) { sources[file].content = includeTestLibs.concat(c) @@ -167,7 +167,7 @@ export function compileContractSources(sources: SrcIfc, compilerConfig: Compiler } async.waterfall([ - function loadCompiler (next: Function) { + function loadCompiler (next) { const {currentCompilerUrl, evmVersion, optimize, usingWorker} = compilerConfig compiler = new RemixCompiler(importFileCb) compiler.set('evmVersion', evmVersion) @@ -178,7 +178,7 @@ export function compileContractSources(sources: SrcIfc, compilerConfig: Compiler next() }) }, - function doCompilation (next: Function) { + function doCompilation (next) { // @ts-ignore compiler.event.register('compilationFinished', this, (success, data, source) => { next(null, data) @@ -186,9 +186,9 @@ export function compileContractSources(sources: SrcIfc, compilerConfig: Compiler compiler.compile(sources, filepath) } ], function (err: Error | null | undefined , result: any) { - let error: Error[] = [] + const error: Error[] = [] if (result.error) error.push(result.error) - let errors = (result.errors || error).filter((e) => e.type === 'Error' || e.severity === 'error') + const errors = (result.errors || error).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { if (!isBrowser) require('signale').fatal(errors) return cb(new CompilationErrors(errors)) diff --git a/libs/remix-tests/src/deployer.ts b/libs/remix-tests/src/deployer.ts index 676a3529f1..38f816ca80 100644 --- a/libs/remix-tests/src/deployer.ts +++ b/libs/remix-tests/src/deployer.ts @@ -1,5 +1,5 @@ import async from 'async' -import { execution } from 'remix-lib' +import { execution } from '@remix-project/remix-lib' import Web3 from 'web3' import { compilationInterface } from 'types' @@ -12,27 +12,27 @@ import { compilationInterface } from 'types' */ export function deployAll(compileResult: compilationInterface, web3: Web3, withDoubleGas: boolean, callback) { - let compiledObject = {} - let contracts = {} + const compiledObject = {} + const contracts = {} let accounts: string[] = [] async.waterfall([ - function getAccountList(next: Function) { + function getAccountList(next) { web3.eth.getAccounts((_err, _accounts) => { accounts = _accounts next() }) }, - function getContractData(next: Function) { - for (let contractFile in compileResult) { - for (let contractName in compileResult[contractFile]) { - let contract = compileResult[contractFile][contractName] + function getContractData(next) { + for (const contractFile in compileResult) { + for (const contractName in compileResult[contractFile]) { + const contract = compileResult[contractFile][contractName] const className = contractName const filename = contractFile - let abi = contract.abi - let code = contract.evm.bytecode.object + const abi = contract.abi + const code = contract.evm.bytecode.object compiledObject[className] = {} compiledObject[className].abi = abi @@ -48,11 +48,11 @@ export function deployAll(compileResult: compilationInterface, web3: Web3, withD } next() }, - function determineContractsToDeploy(next: Function) { - let contractsToDeploy: string[] = ['Assert'] - let allContracts = Object.keys(compiledObject) + function determineContractsToDeploy(next) { + const contractsToDeploy: string[] = ['Assert'] + const allContracts = Object.keys(compiledObject) - for (let contractName of allContracts) { + for (const contractName of allContracts) { if (contractName === 'Assert') { continue } @@ -62,7 +62,7 @@ export function deployAll(compileResult: compilationInterface, web3: Web3, withD } next(null, contractsToDeploy) }, - function deployContracts(contractsToDeploy: string[], next: Function) { + function deployContracts(contractsToDeploy: string[], next) { const deployRunner = (deployObject, contractObject, contractName, filename, callback) => { deployObject.estimateGas().then((gasValue) => { const gasBase = Math.ceil(gasValue * 1.2) @@ -88,30 +88,26 @@ export function deployAll(compileResult: compilationInterface, web3: Web3, withD } async.eachOfLimit(contractsToDeploy, 1, function (contractName, index, nextEach) { - let contract = compiledObject[contractName] - let encodeDataFinalCallback = (error, contractDeployData) => { + const contract = compiledObject[contractName] + const 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}) + const contractObject = new web3.eth.Contract(contract.abi) + const 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) } + const 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}) + const encodeDataDeployLibraryCallback = (libData, callback) => { + const abi = compiledObject[libData.data.contractName].abi + const code = compiledObject[libData.data.contractName].code + const libraryObject = new web3.eth.Contract(abi) + const 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 + const funAbi = null // no need to set the abi for encoding the constructor + const params = '' // we suppose that the test contract does not have any param in the constructor execution.txFormat.encodeConstructorCallAndDeployLibraries(contractName, contract.raw, compileResult, params, funAbi, encodeDataFinalCallback, encodeDataStepCallback, encodeDataDeployLibraryCallback) }, function (err) { if(err) next(err) diff --git a/libs/remix-tests/src/fileSystem.ts b/libs/remix-tests/src/fileSystem.ts index 43ada7cb1b..6930ca576f 100644 --- a/libs/remix-tests/src/fileSystem.ts +++ b/libs/remix-tests/src/fileSystem.ts @@ -1,9 +1,9 @@ // Extend fs -let fs: any = require('fs') +const fs: any = require('fs') import path from 'path' // https://github.com/mikeal/node-utils/blob/master/file/lib/main.js -fs.walkSync = function (start: string, callback: Function) { +fs.walkSync = function (start: string, callback) { fs.readdirSync(start).forEach((name: string) => { if (name === 'node_modules') { return // hack diff --git a/libs/remix-tests/src/logger.ts b/libs/remix-tests/src/logger.ts index a1ef9a784e..e14288f5dd 100644 --- a/libs/remix-tests/src/logger.ts +++ b/libs/remix-tests/src/logger.ts @@ -42,7 +42,7 @@ class Log { ) }) } - setVerbosity (v: LoggerOptions["level"]) { + setVerbosity (v: LoggerOptions["level"]): void { this.logger.configure({ level: v, transports: [new winston.transports.Console()], diff --git a/libs/remix-tests/src/run.ts b/libs/remix-tests/src/run.ts index d49a020ed2..25782eb3a9 100644 --- a/libs/remix-tests/src/run.ts +++ b/libs/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' -import { Provider } from 'remix-simulator' +import { Provider } from '@remix-project/remix-simulator' import Log from './logger' const logger = new Log() const log = logger.logger @@ -47,7 +47,7 @@ commander logger.setVerbosity(commander.verbose) log.info('verbosity level set to ' + commander.verbose.blue) } - let web3 = new Web3() + const web3 = new Web3() const provider = new Provider() await provider.init() web3.setProvider(provider) @@ -57,7 +57,7 @@ commander process.exit(1) } - let isDirectory = fs.lstatSync(filename).isDirectory() + const isDirectory = fs.lstatSync(filename).isDirectory() runTestFiles(filename, isDirectory, web3) }) diff --git a/libs/remix-tests/src/runTestFiles.ts b/libs/remix-tests/src/runTestFiles.ts index 3806ecd5fc..c4ae5bf08f 100644 --- a/libs/remix-tests/src/runTestFiles.ts +++ b/libs/remix-tests/src/runTestFiles.ts @@ -17,7 +17,7 @@ import { deployAll } from './deployer' * @param opts Options */ -export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, finalCallback: any = () => {}, opts?: Options) { +export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, finalCallback, opts?: Options) { opts = opts || {} const sourceASTs: any = {} const { Signale } = require('signale') @@ -44,17 +44,17 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, const signale = new Signale(options) let accounts = opts['accounts'] || null async.waterfall([ - function getAccountList (next: Function) { + function getAccountList (next) { if (accounts) return next(null) web3.eth.getAccounts((_err: Error | null | undefined, _accounts) => { accounts = _accounts next(null) }) }, - function compile(next: Function) { + function compile(next) { compileFileOrFiles(filepath, isDirectory, { accounts }, next) }, - function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next: Function) { + function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) { // Extract AST of test contract file source for(const filename in asts) { if(filename.endsWith('_test.sol')) @@ -67,9 +67,9 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, next(null, compilationResult, contracts) }) }, - function determineTestContractsToRun (compilationResult: compilationInterface, contracts: any, next: Function) { - let contractsToTest: string[] = [] - let contractsToTestDetails: any[] = [] + function determineTestContractsToRun (compilationResult: compilationInterface, contracts: any, next) { + const contractsToTest: string[] = [] + const contractsToTestDetails: any[] = [] const gatherContractsFrom = function(filename: string) { if (!filename.endsWith('_test.sol')) { return @@ -92,11 +92,11 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, } next(null, contractsToTest, contractsToTestDetails, contracts) }, - function runTests(contractsToTest: string[], contractsToTestDetails: any[], contracts: any, next: Function) { - let totalPassing: number = 0 - let totalFailing: number = 0 - let totalTime: number = 0 - let errors: any[] = [] + function runTests(contractsToTest: string[], contractsToTestDetails: any[], contracts: any, next) { + let totalPassing = 0 + let totalFailing = 0 + let totalTime = 0 + const errors: any[] = [] const _testCallback = function (err: Error | null | undefined, result: TestResultInterface) { if(err) throw err; diff --git a/libs/remix-tests/src/runTestSources.ts b/libs/remix-tests/src/runTestSources.ts index 48d21d5254..800571064a 100644 --- a/libs/remix-tests/src/runTestSources.ts +++ b/libs/remix-tests/src/runTestSources.ts @@ -6,13 +6,13 @@ import { deployAll } from './deployer' import { runTest } from './testRunner' import Web3 from 'web3'; -import { Provider } from 'remix-simulator' +import { Provider } from '@remix-project/remix-simulator' import { FinalResult, SrcIfc, compilationInterface, ASTInterface, Options, TestResultInterface, AstNode, CompilerConfiguration } from './types' const createWeb3Provider = async function () { - let web3 = new Web3() - let provider = new Provider() + const web3 = new Web3() + const provider = new Provider() await provider.init() web3.setProvider(provider) return web3 @@ -28,10 +28,10 @@ const createWeb3Provider = async function () { * @param importFileCb Import file callback * @param opts Options */ -export async function runTestSources(contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback: Function, resultCallback: Function, finalCallback: any, importFileCb: Function, opts: Options) { +export async function runTestSources(contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback, resultCallback, finalCallback: any, importFileCb, opts: Options) { opts = opts || {} const sourceASTs: any = {} - let web3 = opts.web3 || await createWeb3Provider() + const web3 = opts.web3 || await createWeb3Provider() let accounts: string[] | null = opts.accounts || null async.waterfall([ function getAccountList (next) { @@ -66,10 +66,10 @@ export async function runTestSources(contractSources: SrcIfc, compilerConfig: Co }) }, function determineTestContractsToRun (compilationResult: compilationInterface, contracts: any, next) { - let contractsToTest: string[] = [] - let contractsToTestDetails: any[] = [] + const contractsToTest: string[] = [] + const contractsToTestDetails: any[] = [] - for (let filename in compilationResult) { + for (const filename in compilationResult) { if (!filename.endsWith('_test.sol')) { continue } @@ -84,7 +84,7 @@ export async function runTestSources(contractSources: SrcIfc, compilerConfig: Co let totalPassing = 0 let totalFailing = 0 let totalTime = 0 - let errors: any[] = [] + const errors: any[] = [] const _testCallback = function (err: Error | null | undefined, result: TestResultInterface) { if (result.type === 'testFailure') { @@ -94,7 +94,7 @@ export async function runTestSources(contractSources: SrcIfc, compilerConfig: Co } const _resultsCallback = function (_err, result, cb) { - resultCallback(_err, result, () => {}) + resultCallback(_err, result, () => {}) //eslint-disable-line @typescript-eslint/no-empty-function totalPassing += result.passingNum totalFailing += result.failureNum totalTime += result.timePassed @@ -114,7 +114,7 @@ export async function runTestSources(contractSources: SrcIfc, compilerConfig: Co return next(err) } - let finalResults: FinalResult = { + const finalResults: FinalResult = { totalPassing: 0, totalFailing: 0, totalTime: 0, diff --git a/libs/remix-tests/src/testRunner.ts b/libs/remix-tests/src/testRunner.ts index 316284cd96..78048c4333 100644 --- a/libs/remix-tests/src/testRunner.ts +++ b/libs/remix-tests/src/testRunner.ts @@ -46,7 +46,7 @@ function isPayable(funcABI: FunctionDescription): boolean { function getOverridedSender (userdoc: UserDocumentation, signature: string, methodIdentifiers: Record ): string | null { const fullName: string | null = getFunctionFullName(signature, methodIdentifiers) - const senderRegex: RegExp = /#sender: account-+(\d)/g + const senderRegex = /#sender: account-+(\d)/g const accountIndex: RegExpExecArray | null = fullName && userdoc.methods[fullName] ? senderRegex.exec(userdoc.methods[fullName].notice) : null return fullName && accountIndex ? accountIndex[1] : null } @@ -60,7 +60,7 @@ function getOverridedSender (userdoc: UserDocumentation, signature: string, meth function getProvidedValue (userdoc: UserDocumentation, signature: string, methodIdentifiers: Record ): string | null { const fullName: string | null = getFunctionFullName(signature, methodIdentifiers) - const valueRegex: RegExp = /#value: (\d+)/g + const valueRegex = /#value: (\d+)/g const value: RegExpExecArray | null = fullName && userdoc.methods[fullName] ? valueRegex.exec(userdoc.methods[fullName].notice) : null return fullName && value ? value[1] : null } @@ -129,27 +129,27 @@ function createRunList (jsonInterface: FunctionDescription[], fileAST: AstNode, const availableFunctions: string[] = getAvailableFunctions(fileAST, testContractName) const testFunctionsInterface: FunctionDescription[] = getTestFunctionsInterface(jsonInterface, availableFunctions) const specialFunctionsInterface: Record = getSpecialFunctionsInterface(jsonInterface) - let runList: RunListInterface[] = [] + const runList: RunListInterface[] = [] if (availableFunctions.includes('beforeAll')) { - let func = specialFunctionsInterface['beforeAll'] + const func = specialFunctionsInterface['beforeAll'] runList.push({ name: 'beforeAll', inputs: func.inputs, signature: func.signature, type: 'internal', constant: isConstant(func), payable: isPayable(func) }) } for (const func of testFunctionsInterface) { if (availableFunctions.includes('beforeEach')) { - let func = specialFunctionsInterface['beforeEach'] + const func = specialFunctionsInterface['beforeEach'] runList.push({ name: 'beforeEach', inputs: func.inputs, signature: func.signature, type: 'internal', constant: isConstant(func), payable: isPayable(func) }) } if(func.name && func.inputs) runList.push({ name: func.name, inputs: func.inputs, signature: func.signature, type: 'test', constant: isConstant(func), payable: isPayable(func) }) if (availableFunctions.indexOf('afterEach') >= 0) { - let func = specialFunctionsInterface['afterEach'] + const func = specialFunctionsInterface['afterEach'] runList.push({ name: 'afterEach', inputs: func.inputs, signature: func.signature, type: 'internal', constant: isConstant(func), payable: isPayable(func) }) } } if (availableFunctions.indexOf('afterAll') >= 0) { - let func = specialFunctionsInterface['afterAll'] + const func = specialFunctionsInterface['afterAll'] runList.push({ name: 'afterAll', inputs: func.inputs, signature: func.signature, type: 'internal', constant: isConstant(func), payable: isPayable(func) }) } @@ -157,9 +157,9 @@ function createRunList (jsonInterface: FunctionDescription[], fileAST: AstNode, } export function runTest (testName: string, testObject: any, contractDetails: CompiledContract, fileAST: AstNode, opts: Options, testCallback: TestCbInterface, resultsCallback: ResultCbInterface): void { - let passingNum: number = 0 - let failureNum: number = 0 - let timePassed: number = 0 + let passingNum = 0 + let failureNum = 0 + let timePassed = 0 const isJSONInterfaceAvailable = testObject && testObject.options && testObject.options.jsonInterface if(!isJSONInterfaceAvailable) return resultsCallback(new Error('Contract interface not available'), { passingNum, failureNum, timePassed }) @@ -229,7 +229,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com try { const time: number = (Date.now() - startTime) / 1000.0 const topic = Web3.utils.sha3('AssertionEvent(bool,string)') - let testPassed: boolean = false + let testPassed = false for (const i in receipt.events) { const event = receipt.events[i] diff --git a/libs/remix-tests/src/types.ts b/libs/remix-tests/src/types.ts index 195f4ea802..3f587e3fe3 100644 --- a/libs/remix-tests/src/types.ts +++ b/libs/remix-tests/src/types.ts @@ -59,7 +59,7 @@ export interface CompilationErrors { } export class CompilationErrors extends Error { - constructor(errors) { + constructor(errors: Array) { const mapError = errors.map((e) => { return e.formattedMessage || e.message }) super(mapError.join('\n')) this.errors = errors @@ -97,7 +97,7 @@ export interface AstNodeAtt { constant?: boolean name?: string public?: boolean - exportedSymbols?: Object + exportedSymbols?: Record argumentTypes?: null absolutePath?: string [x: string]: any @@ -105,7 +105,7 @@ export interface AstNodeAtt { export interface AstNode { absolutePath?: string - exportedSymbols?: Object + exportedSymbols?: Record id: number nodeType: string nodes?: Array @@ -142,7 +142,7 @@ export interface CompiledContract { /** EVM-related outputs */ evm: { assembly: string - legacyAssembly: {} + legacyAssembly: Record /** Bytecode and related details. */ bytecode: BytecodeObject deployedBytecode: BytecodeObject diff --git a/libs/remix-tests/tests/testRunner.ts b/libs/remix-tests/tests/testRunner.ts index 7a8728c92a..abddc997bc 100644 --- a/libs/remix-tests/tests/testRunner.ts +++ b/libs/remix-tests/tests/testRunner.ts @@ -2,12 +2,12 @@ import 'mocha' import * as async from 'async' import Web3 from 'web3'; import * as assert from 'assert' -import { Provider } from 'remix-simulator' +import { Provider } from '@remix-project/remix-simulator' -import { compileFileOrFiles } from '../dist/compiler' -import { deployAll } from '../dist/deployer' -import { runTest, compilationInterface } from '../dist/index' -import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/index' +import { compileFileOrFiles } from '../src/compiler' +import { deployAll } from '../src/deployer' +import { runTest, compilationInterface } from '../src/index' +import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../src/index' // deepEqualExcluding allows us to exclude specific keys whose values vary. // In this specific test, we'll use this helper to exclude `time` keys. diff --git a/libs/remix-tests/tsconfig.json b/libs/remix-tests/tsconfig.json index 45cd9f683f..a73c9a881d 100644 --- a/libs/remix-tests/tsconfig.json +++ b/libs/remix-tests/tsconfig.json @@ -1,24 +1,7 @@ { - "include": ["src"], + "extends": "../../tsconfig.json", "compilerOptions": { - "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": [ - "./@types", - "./node_modules/@types" - ], - "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. */ - } -} \ No newline at end of file + "types": ["node"] + }, + "include": ["**/*.ts"] +} diff --git a/libs/remix-tests/tsconfig.lib.json b/libs/remix-tests/tsconfig.lib.json new file mode 100644 index 0000000000..e2f1f97b61 --- /dev/null +++ b/libs/remix-tests/tsconfig.lib.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../dist/out-tsc", + "declaration": true, + "rootDir": "./src", + "types": ["node"] + }, + "exclude": [ + "**/*.spec.ts" + ], + "include": ["**/*.ts"] +} + \ No newline at end of file diff --git a/workspace.json b/workspace.json index 28a8e34aeb..a165f9b6f0 100644 --- a/workspace.json +++ b/workspace.json @@ -314,23 +314,20 @@ "schematics": {}, "architect": { "lint": { - "builder": "@nrwl/workspace:run-commands", + "builder": "@nrwl/linter:lint", "options": { - "commands": [ - { - "command": "./../../node_modules/.bin/npm-run-all lint" - } + "linter": "eslint", + "config": "libs/remix-tests/.eslintrc", + "tsConfig": [ + "libs/remix-tests/tsconfig.lib.json" ], - "cwd": "libs/remix-tests" + "exclude": ["**/node_modules/**", "libs/remix-tests/tests/**/*"] } }, "test": { "builder": "@nrwl/workspace:run-commands", "options": { "commands": [ - { - "command": "rm -rf ../../dist" - }, { "command": "./../../node_modules/.bin/npm-run-all test" } @@ -339,17 +336,13 @@ } }, "build": { - "builder": "@nrwl/workspace:run-commands", + "builder": "@nrwl/node:package", "options": { - "commands": [ - { - "command": "rm -rf ../../dist" - }, - { - "command": "./../../node_modules/.bin/npm-run-all build" - } - ], - "cwd": "libs/remix-tests" + "outputPath": "dist/libs/remix-tests", + "tsConfig": "libs/remix-tests/tsconfig.lib.json", + "packageJson": "libs/remix-tests/package.json", + "main": "libs/remix-tests/src/index.ts", + "assets": ["libs/remix-tests/*.md"] } } }