From 1fbe96e82153a4a494928380675725529ea33509 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Mon, 3 Jan 2022 14:37:46 +0530 Subject: [PATCH] do not reload compiler for same config --- libs/remix-tests/package.json | 1 + libs/remix-tests/src/compiler.ts | 15 +-------------- libs/remix-tests/src/runTestSources.ts | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/libs/remix-tests/package.json b/libs/remix-tests/package.json index e193dfa42f..2055922334 100644 --- a/libs/remix-tests/package.json +++ b/libs/remix-tests/package.json @@ -49,6 +49,7 @@ "color-support": "^1.1.3", "colors": "^1.1.2", "commander": "^2.13.0", + "deep-equal": "^1.0.1", "ethereumjs-util": "^7.0.10", "ethers": "^5.4.2", "ethjs-util": "^0.1.6", diff --git a/libs/remix-tests/src/compiler.ts b/libs/remix-tests/src/compiler.ts index f4b9250ecf..bf18f7fd98 100644 --- a/libs/remix-tests/src/compiler.ts +++ b/libs/remix-tests/src/compiler.ts @@ -170,8 +170,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): void { - let compiler +export function compileContractSources (sources: SrcIfc, compiler: any, opts: any, cb): void { const filepath = opts.testFilePath || '' const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm @@ -184,18 +183,6 @@ export function compileContractSources (sources: SrcIfc, compilerConfig: Compile } async.waterfall([ - function loadCompiler (next) { - const { currentCompilerUrl, evmVersion, optimize, runs, usingWorker } = compilerConfig - compiler = new RemixCompiler(importFileCb) - compiler.set('evmVersion', evmVersion) - compiler.set('optimize', optimize) - compiler.set('runs', runs) - compiler.loadVersion(usingWorker, currentCompilerUrl) - // @ts-ignore - compiler.event.register('compilerLoaded', this, (version) => { - next() - }) - }, function doCompilation (next) { // @ts-ignore compiler.event.register('compilationFinished', this, (success, data, source) => { diff --git a/libs/remix-tests/src/runTestSources.ts b/libs/remix-tests/src/runTestSources.ts index 9d8b8ba400..0f2a72cea5 100644 --- a/libs/remix-tests/src/runTestSources.ts +++ b/libs/remix-tests/src/runTestSources.ts @@ -1,4 +1,6 @@ import async, { ErrorCallback } from 'async' +import deepequal from 'deep-equal' +import { Compiler as RemixCompiler } from '@remix-project/remix-solidity' import { compileContractSources, writeTestAccountsContract } from './compiler' import { deployAll } from './deployer' import { runTest } from './testRunner' @@ -16,6 +18,8 @@ export class UnitTestRunner { accountsLibCode testsAccounts: string[] | null web3 + compiler + compilerConfig constructor () { this.event = new EventEmitter() @@ -53,7 +57,22 @@ export class UnitTestRunner { async.waterfall([ (next) => { - compileContractSources(contractSources, compilerConfig, importFileCb, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next) + if (!deepequal(this.compilerConfig, compilerConfig)) { + this.compilerConfig = compilerConfig + const { currentCompilerUrl, evmVersion, optimize, runs, usingWorker } = compilerConfig + this.compiler = new RemixCompiler(importFileCb) + this.compiler.set('evmVersion', evmVersion) + this.compiler.set('optimize', optimize) + this.compiler.set('runs', runs) + this.compiler.loadVersion(usingWorker, currentCompilerUrl) + // @ts-ignore + this.compiler.event.register('compilerLoaded', this, (version) => { + next() + }) + } else next() + }, + (next) => { + compileContractSources(contractSources, this.compiler, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next) }, (compilationResult: compilationInterface, asts: ASTInterface, next) => { for (const filename in asts) {