Skip to content

Commit 10e245b

Browse files
authored
Merge branch 'master' into vicons
2 parents 841a853 + 87b88a9 commit 10e245b

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

libs/remix-tests/src/compiler.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from './fileSystem'
22
import async from 'async'
33
import path from 'path'
4+
import deepequal from 'deep-equal'
45
import Log from './logger'
56
import { Compiler as RemixCompiler } from '@remix-project/remix-solidity'
67
import { SrcIfc, CompilerConfiguration, CompilationErrors } from './types'
@@ -170,7 +171,8 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts
170171
* @param opts Options
171172
* @param cb Callback
172173
*/
173-
export function compileContractSources (sources: SrcIfc, compiler: any, opts: any, cb): void {
174+
export function compileContractSources (sources: SrcIfc, newCompConfig: any, importFileCb, UTRunner, opts: any, cb): void {
175+
let compiler
174176
const filepath = opts.testFilePath || ''
175177
const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm
176178

@@ -183,8 +185,28 @@ export function compileContractSources (sources: SrcIfc, compiler: any, opts: an
183185
}
184186

185187
async.waterfall([
186-
function doCompilation (next) {
188+
(next) => {
189+
if (!deepequal(UTRunner.compilerConfig, newCompConfig)) {
190+
UTRunner.compilerConfig = newCompConfig
191+
const { currentCompilerUrl, evmVersion, optimize, runs, usingWorker } = newCompConfig
192+
compiler = new RemixCompiler(importFileCb)
193+
compiler.set('evmVersion', evmVersion)
194+
compiler.set('optimize', optimize)
195+
compiler.set('runs', runs)
196+
compiler.loadVersion(usingWorker, currentCompilerUrl)
197+
// @ts-ignore
198+
compiler.event.register('compilerLoaded', this, (version) => {
199+
next()
200+
})
201+
} else {
202+
compiler = UTRunner.compiler
203+
next()
204+
}
205+
},
206+
(next) => {
187207
const compilationFinishedCb = (success, data, source) => {
208+
// data.error usually exists for exceptions like worker error etc.
209+
if (!data.error) UTRunner.compiler = compiler
188210
if (opts && opts.event) opts.event.emit('compilationFinished', success, data, source)
189211
next(null, data)
190212
}

libs/remix-tests/src/runTestSources.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import async, { ErrorCallback } from 'async'
2-
import deepequal from 'deep-equal'
3-
import { Compiler as RemixCompiler } from '@remix-project/remix-solidity'
42
import { compileContractSources, writeTestAccountsContract } from './compiler'
53
import { deployAll } from './deployer'
64
import { runTest } from './testRunner'
@@ -50,29 +48,13 @@ export class UnitTestRunner {
5048
* @param importFileCb Import file callback
5149
* @param opts Options
5250
*/
53-
async runTestSources (contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback, resultCallback, deployCb:any, finalCallback: any, importFileCb, opts: Options) {
51+
async runTestSources (contractSources: SrcIfc, newCompilerConfig: CompilerConfiguration, testCallback, resultCallback, deployCb:any, finalCallback: any, importFileCb, opts: Options) {
5452
opts = opts || {}
5553
const sourceASTs: any = {}
5654
if (opts.web3 || opts.accounts) this.init(opts.web3, opts.accounts)
57-
5855
async.waterfall([
5956
(next) => {
60-
if (!deepequal(this.compilerConfig, compilerConfig)) {
61-
this.compilerConfig = compilerConfig
62-
const { currentCompilerUrl, evmVersion, optimize, runs, usingWorker } = compilerConfig
63-
this.compiler = new RemixCompiler(importFileCb)
64-
this.compiler.set('evmVersion', evmVersion)
65-
this.compiler.set('optimize', optimize)
66-
this.compiler.set('runs', runs)
67-
this.compiler.loadVersion(usingWorker, currentCompilerUrl)
68-
// @ts-ignore
69-
this.compiler.event.register('compilerLoaded', this, (version) => {
70-
next()
71-
})
72-
} else next()
73-
},
74-
(next) => {
75-
compileContractSources(contractSources, this.compiler, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next)
57+
compileContractSources(contractSources, newCompilerConfig, importFileCb, this, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next)
7658
},
7759
(compilationResult: compilationInterface, asts: ASTInterface, next) => {
7860
for (const filename in asts) {

libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,20 @@ export class TestTabLogic {
2121
this.currentPath = this.helper.removeMultipleSlashes(this.helper.removeTrailingSlashes(path))
2222
}
2323

24-
generateTestFolder (path:string) {
24+
async generateTestFolder (path:string) {
2525
// Todo move this check to File Manager after refactoring
2626
// Checking to ignore the value which contains only whitespaces
2727
if (!path || !(/\S/.test(path))) return
2828
path = this.helper.removeMultipleSlashes(path)
2929
const fileProvider = this.fileManager.fileProviderOf(path.split('/')[0])
30-
fileProvider.exists(path).then((res: boolean) => {
31-
if (!res) fileProvider.createDir(path)
32-
})
30+
if(!await fileProvider.exists(path)) fileProvider.createDir(path)
3331
}
3432

3533
async pathExists (path: string) {
3634
// Checking to ignore the value which contains only whitespaces
3735
if (!path || !(/\S/.test(path))) return
3836
const fileProvider = this.fileManager.fileProviderOf(path.split('/')[0])
39-
const res = await fileProvider.exists(path, (e: Error, res: boolean) => { return res })
40-
return res
37+
return await fileProvider.exists(path)
4138
}
4239

4340
// eslint-disable-next-line @typescript-eslint/no-explicit-any

libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
222222
if (path !== '/') path = helper.removeTrailingSlashes(path)
223223
if (inputPath === '') inputPath = defaultPath
224224
setInputPathValue(path)
225-
testTabLogic.generateTestFolder(inputPath)
225+
await testTabLogic.generateTestFolder(inputPath)
226+
setToasterMsg('Folder created successfully')
226227
setDisableCreateButton(true)
227228
setDisableGenerateButton(false)
228229
testTabLogic.setCurrentPath(inputPath)
@@ -672,6 +673,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
672673
value={inputPathValue}
673674
title="Press 'Enter' to change the path for test files."
674675
style={{ backgroundImage: "var(--primary)" }}
676+
onKeyDown={() => { if (inputPathValue === '/') setInputPathValue('')} }
675677
onKeyUp={handleTestDirInput}
676678
onChange={handleEnter}
677679
onClick = {() => { if (inputPathValue === '/') setInputPathValue('')} }

0 commit comments

Comments
 (0)