From 7cd5869334ccc968dad8c24b7e6c386cecafac59 Mon Sep 17 00:00:00 2001 From: lianahus Date: Thu, 4 Aug 2022 12:48:20 +0200 Subject: [PATCH] disable SUT when sol.v is less than 0.4.12 --- apps/solidity-compiler/src/app/compiler-api.ts | 3 ++- .../staticAnalysisIntegration-test-0.4.24.ts | 2 +- .../src/lib/solidity-unit-testing.tsx | 18 +++++++++++++++++- package.json | 1 + yarn.lock | 5 +++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 08bc50888e..74eec1d57f 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -222,9 +222,10 @@ export const CompilerApiMixin = (Base) => class extends Base { } this.compiler.event.register('loadingCompiler', this.data.eventHandlers.onLoadingCompiler) - this.data.eventHandlers.onCompilerLoaded = () => { + this.data.eventHandlers.onCompilerLoaded = (version) => { this.data.loading = false this.statusChanged({ key: 'none' }) + this.emit('compilerLoaded', version) } this.compiler.event.register('compilerLoaded', this.data.eventHandlers.onCompilerLoaded) diff --git a/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts b/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts index 8052a1870a..9bcaaf7a7b 100644 --- a/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts +++ b/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts @@ -38,7 +38,7 @@ const testFiles: string[] = [ 'forLoopIteratesOverDynamicArray.sol' ] -let compilationResults: Record = {} +const compilationResults: Record = {} test('setup', function (t: test.Test) { solcOrg.loadRemoteVersion('v0.4.24+commit.e67f0147', (error, compiler) => { diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx index 8f55fe2ea7..e580a9448b 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx +++ b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx @@ -1,4 +1,5 @@ import React, { useState, useRef, useEffect, ReactElement } from 'react' // eslint-disable-line +import * as semver from 'semver' import { eachOfSeries } from 'async' // eslint-disable-line import type Web3 from 'web3' import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' @@ -154,8 +155,23 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d await setCurrentPath(defaultPath) }) + const truncateVersion = (version: string) => { + const tmp: RegExpExecArray | null = /^(\d+.\d+.\d+)/.exec(version) + return tmp ? tmp[1] : version + } + testTab.fileManager.events.on('noFileSelected', async () => { await updateForNewCurrent() }) - testTab.fileManager.events.on('currentFileChanged', async (file: string) => await updateForNewCurrent(file)) + testTab.fileManager.events.on('currentFileChanged', async (file: string) => { + await updateForNewCurrent(file) + }) + testTab.on('solidity', 'compilerLoaded', async (version: string) => { + const { currentVersion } = testTab.compileTab.getCurrentCompilerConfig() + + if (!semver.gt(truncateVersion(currentVersion), '0.4.12')) { + setDisableRunButton(true) + setRunButtonTitle('Please select Solidity compiler version greater than 0.4.12.') + } + }) }, []) // eslint-disable-line diff --git a/package.json b/package.json index ca78b75c73..06b9c286cf 100644 --- a/package.json +++ b/package.json @@ -252,6 +252,7 @@ "@types/react-dom": "^17.0.9", "@types/react-router-dom": "^5.3.0", "@types/request": "^2.48.7", + "@types/semver": "^7.3.10", "@types/tape": "^4.13.0", "@types/ws": "^7.2.4", "@typescript-eslint/eslint-plugin": "^4.32.0", diff --git a/yarn.lock b/yarn.lock index d544d2119c..bba528ba28 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4637,6 +4637,11 @@ integrity sha512-NxxZZek50ylIACiXebKQYHD3D4One3WXOasEXWazL6aTfYbZob7ClNKxUpg8I4/oWArX87oPWvj1cHKqfel3Hg== dependencies: "@types/ws" "*" + +"@types/semver@^7.3.10": + version "7.3.10" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.10.tgz#5f19ee40cbeff87d916eedc8c2bfe2305d957f73" + integrity sha512-zsv3fsC7S84NN6nPK06u79oWgrPVd0NvOyqgghV1haPaFcVxIrP4DLomRwGAXk0ui4HZA7mOcSFL98sMVW9viw== "@types/source-list-map@*": version "0.1.2"