From c072285f816e50e2f17ea6486d75ed1334d95711 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 10 Nov 2021 13:45:14 +0530 Subject: [PATCH 001/103] SUT in React --- .eslintrc.json | 35 ++++++++ libs/remix-ui/solidity-unit-testing/.babelrc | 12 +++ .../solidity-unit-testing/.eslintrc.json | 18 ++++ libs/remix-ui/solidity-unit-testing/README.md | 7 ++ .../solidity-unit-testing/src/index.ts | 1 + .../remix-ui-solidity-unit-testing.module.css | 0 .../lib/remix-ui-solidity-unit-testing.tsx | 16 ++++ .../solidity-unit-testing/tsconfig.json | 20 +++++ .../solidity-unit-testing/tsconfig.lib.json | 13 +++ nx.json | 11 +-- package.json | 7 ++ tsconfig.base.json | 6 +- workspace.json | 84 ++++++++++++++++++- 13 files changed, 218 insertions(+), 12 deletions(-) create mode 100644 .eslintrc.json create mode 100644 libs/remix-ui/solidity-unit-testing/.babelrc create mode 100644 libs/remix-ui/solidity-unit-testing/.eslintrc.json create mode 100644 libs/remix-ui/solidity-unit-testing/README.md create mode 100644 libs/remix-ui/solidity-unit-testing/src/index.ts create mode 100644 libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.module.css create mode 100644 libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.tsx create mode 100644 libs/remix-ui/solidity-unit-testing/tsconfig.json create mode 100644 libs/remix-ui/solidity-unit-testing/tsconfig.lib.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000000..06cc47d9a2 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,35 @@ +{ + "root": true, + "ignorePatterns": ["**/*"], + "plugins": ["@nrwl/nx"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": { + "@nrwl/nx/enforce-module-boundaries": [ + "error", + { + "enforceBuildableLibDependency": true, + "allow": [], + "depConstraints": [ + { + "sourceTag": "*", + "onlyDependOnLibsWithTags": ["*"] + } + ] + } + ] + } + }, + { + "files": ["*.ts", "*.tsx"], + "extends": ["plugin:@nrwl/nx/typescript"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "extends": ["plugin:@nrwl/nx/javascript"], + "rules": {} + } + ] +} diff --git a/libs/remix-ui/solidity-unit-testing/.babelrc b/libs/remix-ui/solidity-unit-testing/.babelrc new file mode 100644 index 0000000000..ccae900be4 --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@nrwl/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [] +} diff --git a/libs/remix-ui/solidity-unit-testing/.eslintrc.json b/libs/remix-ui/solidity-unit-testing/.eslintrc.json new file mode 100644 index 0000000000..50e59482cf --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["plugin:@nrwl/nx/react", "../../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/remix-ui/solidity-unit-testing/README.md b/libs/remix-ui/solidity-unit-testing/README.md new file mode 100644 index 0000000000..d10d541404 --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/README.md @@ -0,0 +1,7 @@ +# remix-ui-solidity-unit-testing + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test remix-ui-solidity-unit-testing` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/remix-ui/solidity-unit-testing/src/index.ts b/libs/remix-ui/solidity-unit-testing/src/index.ts new file mode 100644 index 0000000000..3a236a6cae --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/src/index.ts @@ -0,0 +1 @@ +export * from './lib/remix-ui-solidity-unit-testing'; diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.module.css b/libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.module.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.tsx b/libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.tsx new file mode 100644 index 0000000000..7a354c6a03 --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.tsx @@ -0,0 +1,16 @@ +import './remix-ui-solidity-unit-testing.module.css'; + +/* eslint-disable-next-line */ +export interface RemixUiSolidityUnitTestingProps {} + +export function RemixUiSolidityUnitTesting( + props: RemixUiSolidityUnitTestingProps +) { + return ( +
+

Welcome to remix-ui-solidity-unit-testing!

+
+ ); +} + +export default RemixUiSolidityUnitTesting; diff --git a/libs/remix-ui/solidity-unit-testing/tsconfig.json b/libs/remix-ui/solidity-unit-testing/tsconfig.json new file mode 100644 index 0000000000..8bd701c578 --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + } + ] +} diff --git a/libs/remix-ui/solidity-unit-testing/tsconfig.lib.json b/libs/remix-ui/solidity-unit-testing/tsconfig.lib.json new file mode 100644 index 0000000000..b560bc4dec --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/tsconfig.lib.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": ["node"] + }, + "files": [ + "../../../node_modules/@nrwl/react/typings/cssmodule.d.ts", + "../../../node_modules/@nrwl/react/typings/image.d.ts" + ], + "exclude": ["**/*.spec.ts", "**/*.spec.tsx"], + "include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"] +} diff --git a/nx.json b/nx.json index a1a7131ff6..1804d940a2 100644 --- a/nx.json +++ b/nx.json @@ -145,19 +145,12 @@ "remix-ui-tabs": { "tags": [] }, - "remix-ui-theme-module": { + "remix-ui-theme-module": {}, + "remix-ui-solidity-unit-testing": { "tags": [] }, "remix-ui-editor-context-view": { "tags": [] } - }, - "targetDependencies": { - "build": [ - { - "target": "build", - "projects": "dependencies" - } - ] } } diff --git a/package.json b/package.json index 693012f115..a4e2b1e26e 100644 --- a/package.json +++ b/package.json @@ -162,7 +162,11 @@ "chokidar": "^2.1.8", "color-support": "^1.1.3", "commander": "^2.20.3", +<<<<<<< HEAD "core-js": "^3.19.3", +======= + "core-js": "^3.6.5", +>>>>>>> 6d78ad88e... SUT in React "deep-equal": "^1.0.1", "document-register-element": "1.13.1", "ethereumjs-util": "^7.0.10", @@ -266,8 +270,11 @@ "eslint-config-prettier": "^6.11.0", "eslint-config-standard": "^14.1.1", "eslint-plugin-import": "2.20.2", + "eslint-plugin-jsx-a11y": "6.4.1", "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "4.2.1", + "eslint-plugin-react": "7.23.1", + "eslint-plugin-react-hooks": "4.2.0", "eslint-plugin-standard": "4.0.1", "events": "^3.0.0", "execr": "^1.0.1", diff --git a/tsconfig.base.json b/tsconfig.base.json index 68e1ae5175..80122de18e 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -69,9 +69,13 @@ "@remix-ui/tabs": ["libs/remix-ui/tabs/src/index.ts"], "@remix-ui/helper": ["libs/remix-ui/helper/src/index.ts"], "@remix-ui/app": ["libs/remix-ui/app/src/index.ts"], + "@remix-ui/vertical-icons-panel": ["libs/remix-ui/vertical-icons-panel/src/index.ts"], "@remix-ui/theme-module": ["libs/remix-ui/theme-module/src/index.ts"], - "@remix-ui/editor-context-view": ["libs/remix-ui/editor-context-view/src/index.ts"] + "@remix-ui/editor-context-view": ["libs/remix-ui/editor-context-view/src/index.ts"], + "@remix-ui/solidity-unit-testing": [ + "libs/remix-ui/solidity-unit-testing/src/index.ts" + ] } }, "exclude": ["node_modules", "tmp"] diff --git a/workspace.json b/workspace.json index 15a2150908..38646e1e67 100644 --- a/workspace.json +++ b/workspace.json @@ -1,5 +1,71 @@ { "version": 1, + "cli": { + "defaultCollection": "@nrwl/react" + }, + "defaultProject": "remix-ide", + "schematics": { + "@nrwl/workspace": { + "library": { + "linter": "eslint" + } + }, + "@nrwl/cypress": { + "cypress-project": { + "linter": "eslint" + } + }, + "@nrwl/react": { + "application": { + "style": "css", + "linter": "eslint", + "babel": true + }, + "component": { + "style": "css" + }, + "library": { + "style": "css", + "linter": "eslint" + } + }, + "@nrwl/next": { + "application": { + "linter": "eslint" + } + }, + "@nrwl/web": { + "application": { + "linter": "eslint" + } + }, + "@nrwl/node": { + "application": { + "linter": "eslint" + }, + "library": { + "linter": "eslint" + } + }, + "@nrwl/nx-plugin": { + "plugin": { + "linter": "eslint" + } + }, + "@nrwl/nest": { + "application": { + "linter": "eslint" + } + }, + "@nrwl/express": { + "application": { + "linter": "eslint" + }, + "library": { + "linter": "eslint" + } + } + }, "projects": { "remix-ide": { "root": "apps/remix-ide", @@ -1117,6 +1183,21 @@ } } }, + "solidity-unit-testing": { + "root": "libs/remix-ui/solidity-unit-testing", + "sourceRoot": "libs/remix-ui/solidity-unit-testing/src", + "projectType": "library", + "architect": { + "lint": { + "builder": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": [ + "libs/remix-ui/solidity-unit-testing/**/*.{ts,tsx,js,jsx}" + ] + } + } + } + }, "remix-ui-editor-context-view": { "root": "libs/remix-ui/editor-context-view", "sourceRoot": "libs/remix-ui/editor-context-view/src", @@ -1131,8 +1212,7 @@ } } } - } - }, + }, "cli": { "defaultCollection": "@nrwl/react" }, From 835926f894f96a99da75ca1db8789625c93b17f8 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 10 Nov 2021 13:47:45 +0530 Subject: [PATCH 002/103] file updates --- libs/remix-ui/solidity-unit-testing/src/index.ts | 2 +- .../src/lib/remix-ui-solidity-unit-testing.module.css | 0 ...x-ui-solidity-unit-testing.tsx => solidity-unit-testing.tsx} | 0 3 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.module.css rename libs/remix-ui/solidity-unit-testing/src/lib/{remix-ui-solidity-unit-testing.tsx => solidity-unit-testing.tsx} (100%) diff --git a/libs/remix-ui/solidity-unit-testing/src/index.ts b/libs/remix-ui/solidity-unit-testing/src/index.ts index 3a236a6cae..e007a75e38 100644 --- a/libs/remix-ui/solidity-unit-testing/src/index.ts +++ b/libs/remix-ui/solidity-unit-testing/src/index.ts @@ -1 +1 @@ -export * from './lib/remix-ui-solidity-unit-testing'; +export * from './lib/solidity-unit-testing'; diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.module.css b/libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.module.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.tsx b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx similarity index 100% rename from libs/remix-ui/solidity-unit-testing/src/lib/remix-ui-solidity-unit-testing.tsx rename to libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx From 6db8c6c9b9be81d41ae6f73a287cab54c29cf5ec Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 10 Nov 2021 17:50:24 +0530 Subject: [PATCH 003/103] structure --- .../src/lib/actions/solidityUnitTestingAction.ts | 2 ++ .../src/lib/reducers/solidityUnitTestingReducer.ts | 1 + .../src/lib/solidity-unit-testing.tsx | 8 +++----- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 libs/remix-ui/solidity-unit-testing/src/lib/actions/solidityUnitTestingAction.ts create mode 100644 libs/remix-ui/solidity-unit-testing/src/lib/reducers/solidityUnitTestingReducer.ts diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/actions/solidityUnitTestingAction.ts b/libs/remix-ui/solidity-unit-testing/src/lib/actions/solidityUnitTestingAction.ts new file mode 100644 index 0000000000..c5728e9dec --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/src/lib/actions/solidityUnitTestingAction.ts @@ -0,0 +1,2 @@ +import React from 'react' + diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/reducers/solidityUnitTestingReducer.ts b/libs/remix-ui/solidity-unit-testing/src/lib/reducers/solidityUnitTestingReducer.ts new file mode 100644 index 0000000000..bb73474209 --- /dev/null +++ b/libs/remix-ui/solidity-unit-testing/src/lib/reducers/solidityUnitTestingReducer.ts @@ -0,0 +1 @@ +export const solidityUnitTestingReducer = (state, action) => {} \ No newline at end of file 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 7a354c6a03..e49cb99d7f 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,11 +1,9 @@ import './remix-ui-solidity-unit-testing.module.css'; /* eslint-disable-next-line */ -export interface RemixUiSolidityUnitTestingProps {} +export interface SolidityUnitTestingProps {} -export function RemixUiSolidityUnitTesting( - props: RemixUiSolidityUnitTestingProps -) { +export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { return (

Welcome to remix-ui-solidity-unit-testing!

@@ -13,4 +11,4 @@ export function RemixUiSolidityUnitTesting( ); } -export default RemixUiSolidityUnitTesting; +export default SolidityUnitTesting From 325e418d58382a7a51234d69e8a6703092880d63 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 11 Nov 2021 11:04:49 +0530 Subject: [PATCH 004/103] setup update --- apps/remix-ide/src/app/tabs/test-tab.js | 16 ++++++++++++++++ .../src/lib/solidity-unit-testing.tsx | 5 +++-- nx.json | 2 +- tsconfig.base.json | 1 - workspace.json | 11 ++++++++--- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index c82a2bcc1d..20e2fdcb17 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -1,3 +1,8 @@ +/* global */ +import React from 'react' // eslint-disable-line +import ReactDOM from 'react-dom' +import { SolidityUnitTesting } from '@remix-ui/solidity-unit-testing' // eslint-disable-line + import { ViewPlugin } from '@remixproject/engine-web' import { removeMultipleSlashes, removeTrailingSlashes } from '../../lib/helper' import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' @@ -94,6 +99,7 @@ module.exports = class TestTab extends ViewPlugin { await this.testRunner.init() await this.createTestLibs() this.updateRunAction() + this.renderComponent() } onDeactivation () { @@ -790,6 +796,16 @@ module.exports = class TestTab extends ViewPlugin { } render () { + return this.element + } + + renderComponent () { + ReactDOM.render( + + , this.element) + } + + render2 () { this.onActivationInternal() this.testsOutput = yo` - {/*
+
- ${this.updateGenerateFileAction()} - ${this.infoButton()} + {updateGenerateFileAction()} + + +
- ${this.updateRunAction()} - ${this.updateStopAction()} + {/* updateRunAction() */} + {/* ${this.updateStopAction()} */}
- ${this.selectAll()} - ${this.updateTestFileList()} + {/* ${this.selectAll()} + ${this.updateTestFileList()} */}
- ${this.resultStatistics} + {/* ${this.resultStatistics} ${this.testsExecutionStopped} - ${this.testsExecutionStoppedError} + ${this.testsExecutionStoppedError} */}
- ${this.testsOutput} -
*/} + {/* ${this.testsOutput} */} +
) } From 30f9c1be81e676a05958ba93a0e923ee3baf16aa Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Nov 2021 11:31:23 +0530 Subject: [PATCH 012/103] Run button UI --- .../src/lib/solidity-unit-testing.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 f5827d8d52..5bef62112f 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 @@ -107,10 +107,16 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { // return this.generateFileActionElement } - const updateRunAction = (currentFile: any) => { + const updateRunAction = (currentFile = null) => { console.log('updateRunAction --currentFile-->', currentFile) + return ( + ) + // const el = yo` // {/* ${this.selectAll()} ${this.updateTestFileList()} */} From 384b9560e18f6f0cae9b1e26de0692910ac8e8e6 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Nov 2021 11:43:10 +0530 Subject: [PATCH 014/103] select all UI --- .../src/lib/solidity-unit-testing.tsx | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) 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 27fc72f2b7..4a04855c34 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 @@ -10,6 +10,7 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { const [defaultPath, setDefaultPath] = useState('tests') const [disableCreateButton, setDisableCreateButton] = useState(true) const [disableStopButton, setDisableStopButton] = useState(true) + const [checkSelectAll, setCheckSelectAll] = useState(true) const handleTestDirInput = async (e:any) => { console.log('handleTestDirInput--e-->', e) @@ -153,6 +154,18 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { // runBtn.setAttribute('disabled', 'disabled') } + const checkAll = (event: any) => { + console.log('checkAll --event-->', event) + + // const checkBoxes = this._view.el.querySelectorAll('.singleTest') + // const checkboxesLabels = this._view.el.querySelectorAll('.singleTestLabel') + // // checks/unchecks all + // for (let i = 0; i < checkBoxes.length; i++) { + // checkBoxes[i].checked = event.target.checked + // this.toggleCheckbox(event.target.checked, checkboxesLabels[i].innerText) + // } + } + console.log('props---->', props) return (
@@ -198,11 +211,20 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { {updateRunAction()}
- {/* ${this.selectAll()} - ${this.updateTestFileList()} */} +
+ {}} + /> + +
+ {/* ${this.updateTestFileList()} */}
{/* ${this.resultStatistics} ${this.testsExecutionStopped} From 8dc155c6d7a72d985839a50b03fc9866b94627c0 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Nov 2021 11:50:15 +0530 Subject: [PATCH 015/103] test file list --- .../src/lib/solidity-unit-testing.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 4a04855c34..5b1526c589 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 @@ -166,6 +166,19 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { // } } + const updateTestFileList = (tests = []) => { + return (
No test file available
) + // const testsMessage = (tests && tests.length ? this.listTests() : 'No test file available') + // const el = yo`
${testsMessage}
` + // if (!this.testFilesListElement) { + // this.testFilesListElement = el + // } else { + // yo.update(this.testFilesListElement, el) + // } + // this.updateRunAction() + // return this.testFilesListElement + } + console.log('props---->', props) return (
@@ -224,7 +237,7 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { />
- {/* ${this.updateTestFileList()} */} + {updateTestFileList()}
{/* ${this.resultStatistics} ${this.testsExecutionStopped} From 1672900df745157d8219fe334599a2b0f3f43ddc Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Nov 2021 11:59:10 +0530 Subject: [PATCH 016/103] resultStatistics --- .../src/lib/solidity-unit-testing.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 5b1526c589..93512882c4 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 @@ -179,6 +179,15 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { // return this.testFilesListElement } + const createResultLabel = () => { + return (Progress: none finished (of none)) + // if (!this.data.selectedTests) return yo`` + // const ready = this.readyTestsNumber ? `${this.readyTestsNumber}` : '0' + // return yo`Progress: ${ready} finished (of ${this.runningTestsNumber})` + } + + const [resultStatistics] = useState(createResultLabel()) + console.log('props---->', props) return (
@@ -239,8 +248,8 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => {
{updateTestFileList()}
- {/* ${this.resultStatistics} - ${this.testsExecutionStopped} + {resultStatistics} + {/* ${this.testsExecutionStopped} ${this.testsExecutionStoppedError} */}
{/* ${this.testsOutput} */} From 28c7962a02f5ef2889088d74cd1fbcc1f783cba4 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Nov 2021 12:04:53 +0530 Subject: [PATCH 017/103] testExecutionStopped --- .../solidity-unit-testing/src/lib/solidity-unit-testing.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 93512882c4..19fb134376 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 @@ -11,6 +11,7 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { const [disableCreateButton, setDisableCreateButton] = useState(true) const [disableStopButton, setDisableStopButton] = useState(true) const [checkSelectAll, setCheckSelectAll] = useState(true) + const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const handleTestDirInput = async (e:any) => { console.log('handleTestDirInput--e-->', e) @@ -249,8 +250,8 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { {updateTestFileList()}
{resultStatistics} - {/* ${this.testsExecutionStopped} - ${this.testsExecutionStoppedError} */} + + {/* ${this.testsExecutionStoppedError} */}
{/* ${this.testsOutput} */}
From 80a75b96a0110fea9572c5d5cce3d4730b22121f Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Nov 2021 12:07:10 +0530 Subject: [PATCH 018/103] testsExecutionStoppedErrorHidden --- .../solidity-unit-testing/src/lib/solidity-unit-testing.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 19fb134376..f2b944515d 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 @@ -12,6 +12,8 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { const [disableStopButton, setDisableStopButton] = useState(true) const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) + const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) + const handleTestDirInput = async (e:any) => { console.log('handleTestDirInput--e-->', e) @@ -251,7 +253,7 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => {
{resultStatistics} - {/* ${this.testsExecutionStoppedError} */} +
{/* ${this.testsOutput} */}
From 01b0c9df495b632aef3fe35dbb81ad14cb259ed0 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Nov 2021 20:46:40 +0530 Subject: [PATCH 019/103] handleTestDirInput --- apps/remix-ide/src/app/tabs/test-tab.js | 4 +- .../src/lib/solidity-unit-testing.tsx | 116 ++++++++++++------ 2 files changed, 83 insertions(+), 37 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 08272ceb41..45fd1996ec 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom' import { SolidityUnitTesting } from '@remix-ui/solidity-unit-testing' // eslint-disable-line import { ViewPlugin } from '@remixproject/engine-web' -import { removeMultipleSlashes, removeTrailingSlashes } from '../../lib/helper' +import helper, { removeMultipleSlashes, removeTrailingSlashes } from '../../lib/helper' import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { format } from 'util' var yo = require('yo-yo') @@ -811,7 +811,7 @@ module.exports = class TestTab extends ViewPlugin { renderComponent () { console.log('renderComponent-start-->') ReactDOM.render( - + , this.element) console.log('renderComponent-end-->') } 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 f2b944515d..d58b6b3803 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 @@ -5,7 +5,9 @@ import './css/style.css' /* eslint-disable-next-line */ export interface SolidityUnitTestingProps {} -export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { +export const SolidityUnitTesting = (props: any) => { + + const {helper, testTab, testTabLogic} = props const [defaultPath, setDefaultPath] = useState('tests') const [disableCreateButton, setDisableCreateButton] = useState(true) @@ -14,45 +16,88 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) + const [inputPathValue, setInputPathValue] = useState('') + + const trimTestDirInput = (input:string) => { + if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') + else return input.trim() + } + + const updateForNewCurrent = async (file = null) => { + // Ensure that when someone clicks on compilation error and that opens a new file + // Test result, which is compilation error in this case, is not cleared + // if (this.currentErrors) { + // if (Array.isArray(this.currentErrors) && this.currentErrors.length > 0) { + // const errFiles = this.currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) + // if (errFiles.includes(file)) return + // } else if (this.currentErrors.sourceLocation && this.currentErrors.sourceLocation.file && this.currentErrors.sourceLocation.file === file) return + // } + // // if current file is changed while debugging and one of the files imported in test file are opened + // // do not clear the test results in SUT plugin + // if (this.isDebugging && this.allFilesInvolved.includes(file)) return + // this.data.allTests = [] + // this.updateTestFileList() + // this.clearResults() + // this.updateGenerateFileAction() + // if (!this.areTestsRunning) this.updateRunAction(file) + // try { + // await this.testTabLogic.getTests((error, tests) => { + // if (error) return tooltip(error) + // this.data.allTests = tests + // this.data.selectedTests = [...this.data.allTests] + // this.updateTestFileList(tests) + // if (!this.testsOutput) return // eslint-disable-line + // }) + // } catch (e) { + // console.log(e) + // } + } + + const updateDirList = (path: string) => { + // for (const o of this.uiPathList.querySelectorAll('option')) o.remove() + // testTabLogic.dirList(path).then((options) => { + // options.forEach((path) => this.uiPathList.appendChild(yo``)) + // }) + } const handleTestDirInput = async (e:any) => { console.log('handleTestDirInput--e-->', e) - // let testDirInput = this.trimTestDirInput(this.inputPath.value) - // testDirInput = removeMultipleSlashes(testDirInput) - // if (testDirInput !== '/') testDirInput = removeTrailingSlashes(testDirInput) - // if (e.key === 'Enter') { - // this.inputPath.value = testDirInput - // if (await this.testTabLogic.pathExists(testDirInput)) { - // this.testTabLogic.setCurrentPath(testDirInput) - // this.updateForNewCurrent() - // return - // } - // } + let testDirInput = trimTestDirInput(inputPathValue) + testDirInput = helper.removeMultipleSlashes(testDirInput) + if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput) + if (e.key === 'Enter') { + setInputPathValue(testDirInput) + if (await testTabLogic.pathExists(testDirInput)) { + testTabLogic.setCurrentPath(testDirInput) + updateForNewCurrent() + return + } + } - // if (testDirInput) { - // if (testDirInput.endsWith('/') && testDirInput !== '/') { - // testDirInput = removeTrailingSlashes(testDirInput) - // if (this.testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) { - // this.createTestFolder.disabled = true - // this.updateGenerateFileAction().disabled = true - // } - // this.updateDirList(testDirInput) - // } else { - // // If there is no matching folder in the workspace with entered text, enable Create button - // if (await this.testTabLogic.pathExists(testDirInput)) { - // this.createTestFolder.disabled = true - // this.updateGenerateFileAction().disabled = false - // } else { - // // Enable Create button - // this.createTestFolder.disabled = false - // // Disable Generate button because dir does not exist - // this.updateGenerateFileAction().disabled = true - // } - // } - // } else { - // this.updateDirList('/') - // } + if (testDirInput) { + if (testDirInput.endsWith('/') && testDirInput !== '/') { + testDirInput = helper.removeTrailingSlashes(testDirInput) + if (testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) { + setDisableCreateButton(true) + // this.updateGenerateFileAction().disabled = true + } + updateDirList(testDirInput) + } else { + // If there is no matching folder in the workspace with entered text, enable Create button + if (await testTabLogic.pathExists(testDirInput)) { + setDisableCreateButton(true) + // this.updateGenerateFileAction().disabled = false + } else { + // Enable Create button + setDisableCreateButton(false) + // Disable Generate button because dir does not exist + // this.updateGenerateFileAction().disabled = true + } + } + } else { + updateDirList('/') + } } const handleEnter = async(e:any) => { @@ -207,6 +252,7 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { id="utPath" data-id="uiPathInput" name="utPath" + value={inputPathValue} title="Press 'Enter' to change the path for test files." style= {{ backgroundImage: "var(--primary)"}} onKeyUp= {handleTestDirInput} From a36dbacaa5038c70e53bc80e77348fa8bb999af5 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 15 Nov 2021 11:22:30 +0530 Subject: [PATCH 020/103] updateGenerateFileAction --- .../src/lib/solidity-unit-testing.tsx | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) 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 d58b6b3803..c1e4b73dc4 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 @@ -11,6 +11,7 @@ export const SolidityUnitTesting = (props: any) => { const [defaultPath, setDefaultPath] = useState('tests') const [disableCreateButton, setDisableCreateButton] = useState(true) + const [disableGenerateButton, setDisableGenerateButton] = useState(false) const [disableStopButton, setDisableStopButton] = useState(true) const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) @@ -80,6 +81,7 @@ export const SolidityUnitTesting = (props: any) => { testDirInput = helper.removeTrailingSlashes(testDirInput) if (testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) { setDisableCreateButton(true) + setDisableGenerateButton(true) // this.updateGenerateFileAction().disabled = true } updateDirList(testDirInput) @@ -87,11 +89,13 @@ export const SolidityUnitTesting = (props: any) => { // If there is no matching folder in the workspace with entered text, enable Create button if (await testTabLogic.pathExists(testDirInput)) { setDisableCreateButton(true) + setDisableGenerateButton(false) // this.updateGenerateFileAction().disabled = false } else { // Enable Create button setDisableCreateButton(false) // Disable Generate button because dir does not exist + setDisableGenerateButton(true) // this.updateGenerateFileAction().disabled = true } } @@ -129,16 +133,16 @@ export const SolidityUnitTesting = (props: any) => { // this.uiPathList.appendChild(yo``) } - const updateGenerateFileAction = () => { - console.log('updateGenerateFileAction') - return ( - ) + // const updateGenerateFileAction = () => { + // console.log('updateGenerateFileAction') + // return ( + // ) // const el = yo` // From cde071645d3617ca406889d257c2ef4498c6d971 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 16 Nov 2021 13:03:40 +0530 Subject: [PATCH 021/103] datalist options --- .../src/lib/solidity-unit-testing.tsx | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) 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 c1e4b73dc4..c55189174d 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,4 @@ -import React, { useState } from 'react' // eslint-disable-line +import React, { useState, useEffect } from 'react' // eslint-disable-line import './css/style.css' @@ -16,6 +16,7 @@ export const SolidityUnitTesting = (props: any) => { const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) + const [pathOptions, setPathOptions] = useState([]) const [inputPathValue, setInputPathValue] = useState('') @@ -55,13 +56,12 @@ export const SolidityUnitTesting = (props: any) => { } const updateDirList = (path: string) => { - // for (const o of this.uiPathList.querySelectorAll('option')) o.remove() - // testTabLogic.dirList(path).then((options) => { - // options.forEach((path) => this.uiPathList.appendChild(yo``)) - // }) + testTabLogic.dirList(path).then((options: any) => { + setPathOptions(options) + }) } - const handleTestDirInput = async (e:any) => { + const handleTestDirInput = async (e: any) => { console.log('handleTestDirInput--e-->', e) let testDirInput = trimTestDirInput(inputPathValue) @@ -82,7 +82,6 @@ export const SolidityUnitTesting = (props: any) => { if (testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) { setDisableCreateButton(true) setDisableGenerateButton(true) - // this.updateGenerateFileAction().disabled = true } updateDirList(testDirInput) } else { @@ -90,13 +89,11 @@ export const SolidityUnitTesting = (props: any) => { if (await testTabLogic.pathExists(testDirInput)) { setDisableCreateButton(true) setDisableGenerateButton(false) - // this.updateGenerateFileAction().disabled = false } else { // Enable Create button setDisableCreateButton(false) // Disable Generate button because dir does not exist setDisableGenerateButton(true) - // this.updateGenerateFileAction().disabled = true } } } else { @@ -105,7 +102,7 @@ export const SolidityUnitTesting = (props: any) => { } const handleEnter = async(e:any) => { - console.log('handleTestDirInput --e-->', e) + console.log('handleEnter --e-->', e) // this.inputPath.value = removeMultipleSlashes(this.trimTestDirInput(this.inputPath.value)) // if (this.createTestFolder.disabled) { @@ -118,7 +115,7 @@ export const SolidityUnitTesting = (props: any) => { const handleCreateFolder = () => { - console.log('handleTestDirInput') + console.log('handleCreateFolder') // this.inputPath.value = this.trimTestDirInput(this.inputPath.value) // let path = removeMultipleSlashes(this.inputPath.value) // if (path !== '/') path = removeTrailingSlashes(path) @@ -271,7 +268,12 @@ export const SolidityUnitTesting = (props: any) => { > Create - + { + pathOptions.map(function (path) { + return + }) + } + From d62a339b37d671d9f2bb5b6f89f1ef476b0cdb25 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 16 Nov 2021 16:48:23 +0530 Subject: [PATCH 022/103] datalist improved --- .../src/lib/solidity-unit-testing.tsx | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) 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 c55189174d..46d1666061 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,4 @@ -import React, { useState, useEffect } from 'react' // eslint-disable-line +import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line import './css/style.css' @@ -18,7 +18,7 @@ export const SolidityUnitTesting = (props: any) => { const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) const [pathOptions, setPathOptions] = useState([]) - const [inputPathValue, setInputPathValue] = useState('') + const [inputPathValue, setInputPathValue] = useState('tests') const trimTestDirInput = (input:string) => { if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') @@ -55,6 +55,10 @@ export const SolidityUnitTesting = (props: any) => { // } } + useEffect(() => { + updateDirList('/') + }, []) + const updateDirList = (path: string) => { testTabLogic.dirList(path).then((options: any) => { setPathOptions(options) @@ -103,14 +107,15 @@ export const SolidityUnitTesting = (props: any) => { const handleEnter = async(e:any) => { console.log('handleEnter --e-->', e) - - // this.inputPath.value = removeMultipleSlashes(this.trimTestDirInput(this.inputPath.value)) - // if (this.createTestFolder.disabled) { - // if (await this.testTabLogic.pathExists(this.inputPath.value)) { - // this.testTabLogic.setCurrentPath(this.inputPath.value) - // this.updateForNewCurrent() - // } - // } + let inputPath = e.target.value + inputPath = helper.removeMultipleSlashes(trimTestDirInput(inputPath)) + setInputPathValue(inputPath) + if (disableCreateButton) { + if (await testTabLogic.pathExists(inputPath)) { + testTabLogic.setCurrentPath(inputPath) + // this.updateForNewCurrent() + } + } } const handleCreateFolder = () => { @@ -246,6 +251,12 @@ export const SolidityUnitTesting = (props: any) => {
+ { + pathOptions.map(function (path) { + return + }) + } + { > Create - { - pathOptions.map(function (path) { - return - }) - } -
From aa7110470a5fc58abb72a15570bfc4e0700cd5a0 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 16 Nov 2021 17:01:26 +0530 Subject: [PATCH 023/103] create button --- .../src/lib/solidity-unit-testing.tsx | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) 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 46d1666061..08b26edf49 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 @@ -16,7 +16,7 @@ export const SolidityUnitTesting = (props: any) => { const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) - const [pathOptions, setPathOptions] = useState([]) + const [pathOptions, setPathOptions] = useState(['']) const [inputPathValue, setInputPathValue] = useState('tests') @@ -118,21 +118,25 @@ export const SolidityUnitTesting = (props: any) => { } } - const handleCreateFolder = () => { + const handleCreateFolder = (e:any) => { console.log('handleCreateFolder') - // this.inputPath.value = this.trimTestDirInput(this.inputPath.value) - // let path = removeMultipleSlashes(this.inputPath.value) - // if (path !== '/') path = removeTrailingSlashes(path) - // if (this.inputPath.value === '') this.inputPath.value = this.defaultPath - // this.inputPath.value = path - // this.testTabLogic.generateTestFolder(this.inputPath.value) - // this.createTestFolder.disabled = true - // this.updateGenerateFileAction().disabled = false - // this.testTabLogic.setCurrentPath(this.inputPath.value) + let inputPath = e.target.value + inputPath = trimTestDirInput(inputPath) + let path = helper.removeMultipleSlashes(inputPath) + if (path !== '/') path = helper.removeTrailingSlashes(path) + if (inputPath === '') inputPath = defaultPath + setInputPathValue(path) + testTabLogic.generateTestFolder(inputPath) + setDisableCreateButton(true) + setDisableGenerateButton(false) + testTabLogic.setCurrentPath(inputPath) + console.log('path-->', path) + console.log('inputPath-->', inputPath) // this.updateRunAction() // this.updateForNewCurrent() - // this.uiPathList.appendChild(yo``) + pathOptions.push(inputPath) + setPathOptions(pathOptions) } // const updateGenerateFileAction = () => { From 5aa35d32409bef435bd7aedb5f2dc59eb3a39f10 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 17 Nov 2021 14:19:15 +0530 Subject: [PATCH 024/103] folder creation using Create --- .../src/lib/solidity-unit-testing.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 08b26edf49..78525428e4 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 @@ -118,11 +118,8 @@ export const SolidityUnitTesting = (props: any) => { } } - const handleCreateFolder = (e:any) => { - - console.log('handleCreateFolder') - let inputPath = e.target.value - inputPath = trimTestDirInput(inputPath) + const handleCreateFolder = () => { + let inputPath = trimTestDirInput(inputPathValue) let path = helper.removeMultipleSlashes(inputPath) if (path !== '/') path = helper.removeTrailingSlashes(path) if (inputPath === '') inputPath = defaultPath From b188e3e1e11fdbc70d155f70388eba9b03842f11 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 17 Nov 2021 18:42:59 +0530 Subject: [PATCH 025/103] testTabLogic --- apps/remix-ide/src/app/tabs/test-tab.js | 95 +----------- .../remix-ide/src/app/tabs/testTab/testTab.js | 3 + .../src/lib/logic/testTabLogic.ts | 140 ++++++++++++++++++ .../src/lib/solidity-unit-testing.tsx | 7 +- 4 files changed, 149 insertions(+), 96 deletions(-) create mode 100644 libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 45fd1996ec..42529f94b9 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -587,21 +587,6 @@ module.exports = class TestTab extends ViewPlugin { }) } - handleCreateFolder () { - this.inputPath.value = this.trimTestDirInput(this.inputPath.value) - let path = removeMultipleSlashes(this.inputPath.value) - if (path !== '/') path = removeTrailingSlashes(path) - if (this.inputPath.value === '') this.inputPath.value = this.defaultPath - this.inputPath.value = path - this.testTabLogic.generateTestFolder(this.inputPath.value) - this.createTestFolder.disabled = true - this.updateGenerateFileAction().disabled = false - this.testTabLogic.setCurrentPath(this.inputPath.value) - this.updateRunAction() - this.updateForNewCurrent() - this.uiPathList.appendChild(yo``) - } - clearResults () { yo.update(this.resultStatistics, yo``) this.call('editor', 'clearAnnotations') @@ -642,25 +627,6 @@ module.exports = class TestTab extends ViewPlugin { runBtn.setAttribute('disabled', 'disabled') } - updateGenerateFileAction () { - const el = yo` - - ` - if (!this.generateFileActionElement) { - this.generateFileActionElement = el - } else { - yo.update(this.generateFileActionElement, el) - } - return this.generateFileActionElement - } - updateRunAction (currentFile) { const el = yo` From 5eb4521331c6e9eaadf9bc240827932e01daf1bf Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 17 Nov 2021 19:00:49 +0530 Subject: [PATCH 026/103] generate file working --- .../src/lib/logic/testTabLogic.ts | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts index 661f0531ce..49d5b62f2e 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts +++ b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts @@ -49,7 +49,9 @@ export class TestTabLogic { const fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1] this.helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error: any, newFile: any) => { // if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) - // if (!fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName))) return modalDialogCustom.alert('Failed to create test file ' + newFile) + const isFileCreated = fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName)) + console.log('isFileCreated---->', isFileCreated) + // if (!isFileCreated) return modalDialogCustom.alert('Failed to create test file ' + newFile) this.fileManager.open(newFile) this.fileManager.syncEditor(newFile) }) @@ -89,52 +91,52 @@ export class TestTabLogic { const comment = hasCurrent ? `import "${relative}/${remixPath.basename(fileToImport)}";` : '// ' return `// SPDX-License-Identifier: GPL-3.0 - pragma solidity >=0.4.22 <0.9.0; +pragma solidity >=0.4.22 <0.9.0; - // This import is automatically injected by Remix - import "remix_tests.sol"; +// This import is automatically injected by Remix +import "remix_tests.sol"; - // This import is required to use custom transaction context - // Although it may fail compilation in 'Solidity Compiler' plugin - // But it will work fine in 'Solidity Unit Testing' plugin - import "remix_accounts.sol"; - ${comment} +// This import is required to use custom transaction context +// Although it may fail compilation in 'Solidity Compiler' plugin +// But it will work fine in 'Solidity Unit Testing' plugin +import "remix_accounts.sol"; +${comment} - // File name has to end with '_test.sol', this file can contain more than one testSuite contracts - contract ${contractName} { +// File name has to end with '_test.sol', this file can contain more than one testSuite contracts +contract ${contractName} { - /// 'beforeAll' runs before all other tests - /// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll' - function beforeAll() public { - // - Assert.equal(uint(1), uint(1), "1 should be equal to 1"); - } + /// 'beforeAll' runs before all other tests + /// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll' + function beforeAll() public { + // + Assert.equal(uint(1), uint(1), "1 should be equal to 1"); + } - function checkSuccess() public { - // Use 'Assert' methods: https://remix-ide.readthedocs.io/en/latest/assert_library.html - Assert.ok(2 == 2, 'should be true'); - Assert.greaterThan(uint(2), uint(1), "2 should be greater than to 1"); - Assert.lesserThan(uint(2), uint(3), "2 should be lesser than to 3"); - } + function checkSuccess() public { + // Use 'Assert' methods: https://remix-ide.readthedocs.io/en/latest/assert_library.html + Assert.ok(2 == 2, 'should be true'); + Assert.greaterThan(uint(2), uint(1), "2 should be greater than to 1"); + Assert.lesserThan(uint(2), uint(3), "2 should be lesser than to 3"); + } - function checkSuccess2() public pure returns (bool) { - // Use the return value (true or false) to test the contract - return true; - } - - function checkFailure() public { - Assert.notEqual(uint(1), uint(1), "1 should not be equal to 1"); - } + function checkSuccess2() public pure returns (bool) { + // Use the return value (true or false) to test the contract + return true; + } + + function checkFailure() public { + Assert.notEqual(uint(1), uint(1), "1 should not be equal to 1"); + } - /// Custom Transaction Context: https://remix-ide.readthedocs.io/en/latest/unittesting.html#customization - /// #sender: account-1 - /// #value: 100 - function checkSenderAndValue() public payable { - // account index varies 0-9, value is in wei - Assert.equal(msg.sender, TestsAccounts.getAccount(1), "Invalid sender"); - Assert.equal(msg.value, 100, "Invalid value"); - } + /// Custom Transaction Context: https://remix-ide.readthedocs.io/en/latest/unittesting.html#customization + /// #sender: account-1 + /// #value: 100 + function checkSenderAndValue() public payable { + // account index varies 0-9, value is in wei + Assert.equal(msg.sender, TestsAccounts.getAccount(1), "Invalid sender"); + Assert.equal(msg.value, 100, "Invalid value"); } +} ` } } From 7b495e63447781f9dadf54f1c37839a6feb668be Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 18 Nov 2021 11:29:53 +0530 Subject: [PATCH 027/103] updateTestFileList --- .../src/lib/solidity-unit-testing.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 9fd1be19f4..3c10fc2927 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 @@ -19,6 +19,7 @@ export const SolidityUnitTesting = (props: any) => { const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) + const [testsMessage, setTestsMessage] = useState('No test file available') const [pathOptions, setPathOptions] = useState(['']) const [inputPathValue, setInputPathValue] = useState('tests') @@ -224,17 +225,17 @@ export const SolidityUnitTesting = (props: any) => { // } } + const listTests = () => { + console.log('listTests--->') + // if (!this.data.allTests || !this.data.allTests.length) return [] + // return this.data.allTests.map( + // testFile => this.createSingleTest(testFile) + // ) + } + const updateTestFileList = (tests = []) => { - return (
No test file available
) - // const testsMessage = (tests && tests.length ? this.listTests() : 'No test file available') - // const el = yo`
${testsMessage}
` - // if (!this.testFilesListElement) { - // this.testFilesListElement = el - // } else { - // yo.update(this.testFilesListElement, el) - // } - // this.updateRunAction() - // return this.testFilesListElement + const testsMsg: any = (tests && tests.length) ? listTests() : 'No test file available' + setTestsMessage(testsMsg) } const createResultLabel = () => { @@ -318,7 +319,7 @@ export const SolidityUnitTesting = (props: any) => { /> - {updateTestFileList()} +
{testsMessage}
{resultStatistics} From 9c292fbd5f6cf7f5e091bf9f6f210a488aa9b0f1 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 18 Nov 2021 11:45:58 +0530 Subject: [PATCH 028/103] listTests --- .../src/lib/solidity-unit-testing.tsx | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) 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 3c10fc2927..e638ebf804 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 @@ -21,6 +21,8 @@ export const SolidityUnitTesting = (props: any) => { const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) const [testsMessage, setTestsMessage] = useState('No test file available') const [pathOptions, setPathOptions] = useState(['']) + const [allTests, setAllTests] = useState([]) + const [selectedTests, setSelectedTests] = useState([]) const [inputPathValue, setInputPathValue] = useState('tests') @@ -41,22 +43,21 @@ export const SolidityUnitTesting = (props: any) => { // // if current file is changed while debugging and one of the files imported in test file are opened // // do not clear the test results in SUT plugin // if (this.isDebugging && this.allFilesInvolved.includes(file)) return - // this.data.allTests = [] - // this.updateTestFileList() + console.log('Inside updateForNewCurrent --allTests-->', allTests) + updateTestFileList() // this.clearResults() - // this.updateGenerateFileAction() // if (!this.areTestsRunning) this.updateRunAction(file) - // try { - // await this.testTabLogic.getTests((error, tests) => { - // if (error) return tooltip(error) - // this.data.allTests = tests - // this.data.selectedTests = [...this.data.allTests] - // this.updateTestFileList(tests) - // if (!this.testsOutput) return // eslint-disable-line - // }) - // } catch (e) { - // console.log(e) - // } + try { + await testTabLogic.getTests((error: any, tests: any) => { + // if (error) return tooltip(error) + setAllTests(tests) + setSelectedTests(tests) + updateTestFileList(tests) + // if (!this.testsOutput) return // eslint-disable-line + }) + } catch (e) { + console.log('error in updateForNewCurrent', e) + } } useEffect(() => { @@ -225,12 +226,21 @@ export const SolidityUnitTesting = (props: any) => { // } } + const createSingleTest = (testFile) => { + return yo` +
+ this.toggleCheckbox(e.target.checked, testFile)} type="checkbox" checked="true"> + +
+ ` + } + const listTests = () => { - console.log('listTests--->') - // if (!this.data.allTests || !this.data.allTests.length) return [] - // return this.data.allTests.map( - // testFile => this.createSingleTest(testFile) - // ) + console.log('listTests--->', allTests) + if (!allTests || !allTests.length) return [] + return allTests.map( + testFile => createSingleTest(testFile) + ) } const updateTestFileList = (tests = []) => { From 41d63bff5947f0ee56cfa0adfdb6b5b59bb536b1 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 18 Nov 2021 12:36:44 +0530 Subject: [PATCH 029/103] listing test files --- apps/remix-ide/src/app/tabs/test-tab.js | 9 --- .../src/lib/logic/testTabLogic.ts | 1 - .../src/lib/solidity-unit-testing.tsx | 81 +++++++++---------- 3 files changed, 40 insertions(+), 51 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 42529f94b9..8b4aa8672f 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -61,7 +61,6 @@ module.exports = class TestTab extends ViewPlugin { } onActivationInternal () { - console.log('onActivationInternal---start->') this.testTabLogic = new TestTabLogic(this.fileManager) this.listenToEvents() this.call('filePanel', 'registerContextMenuItem', { @@ -73,7 +72,6 @@ module.exports = class TestTab extends ViewPlugin { path: [], pattern: [] }) - console.log('onActivationInternal---end->') } async setTestFolderPath (event) { @@ -95,7 +93,6 @@ module.exports = class TestTab extends ViewPlugin { } async onActivation () { - console.log('onActivation--->') const isSolidityActive = await this.call('manager', 'isActive', 'solidity') if (!isSolidityActive) { await this.call('manager', 'activatePlugin', 'solidity') @@ -106,7 +103,6 @@ module.exports = class TestTab extends ViewPlugin { } onDeactivation () { - console.log('onDeactivation--->') this.off('filePanel', 'newTestFileCreated') this.off('filePanel', 'setWorkspace') // 'currentFileChanged' event is added more than once @@ -114,7 +110,6 @@ module.exports = class TestTab extends ViewPlugin { } listenToEvents () { - console.log('listenToEvents--start-->') this.on('filePanel', 'newTestFileCreated', async file => { try { await this.testTabLogic.getTests((error, tests) => { @@ -152,7 +147,6 @@ module.exports = class TestTab extends ViewPlugin { }) this.fileManager.events.on('currentFileChanged', (file, provider) => this.updateForNewCurrent(file)) - console.log('listenToEvents--end-->') } async updateForNewCurrent (file) { @@ -709,18 +703,15 @@ module.exports = class TestTab extends ViewPlugin { } render () { - console.log('render--->') this.onActivationInternal() this.renderComponent() return this.element } renderComponent () { - console.log('renderComponent-start-->') ReactDOM.render( , this.element) - console.log('renderComponent-end-->') } render2 () { diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts index 49d5b62f2e..91f24b2872 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts +++ b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts @@ -39,7 +39,6 @@ export class TestTabLogic { generateTestFile () { console.log('Inside generateTestFile-1SUT-') - console.log('Inside generateTestFile---fileManager-SUT-->', this.fileManager) let fileName = this.fileManager.currentFile() const hasCurrent = !!fileName && this.fileManager.currentFile().split('.').pop().toLowerCase() === 'sol' if (!hasCurrent) fileName = this.currentPath + '/newFile.sol' 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 e638ebf804..b6da011134 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 @@ -21,7 +21,7 @@ export const SolidityUnitTesting = (props: any) => { const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) const [testsMessage, setTestsMessage] = useState('No test file available') const [pathOptions, setPathOptions] = useState(['']) - const [allTests, setAllTests] = useState([]) + let [allTests, setAllTests] = useState([]) const [selectedTests, setSelectedTests] = useState([]) const [inputPathValue, setInputPathValue] = useState('tests') @@ -48,9 +48,10 @@ export const SolidityUnitTesting = (props: any) => { // this.clearResults() // if (!this.areTestsRunning) this.updateRunAction(file) try { - await testTabLogic.getTests((error: any, tests: any) => { + testTabLogic.getTests((error: any, tests: any) => { // if (error) return tooltip(error) - setAllTests(tests) + console.log('tests in updateForNewCurrent testTabLogic.getTests', tests) + allTests = tests setSelectedTests(tests) updateTestFileList(tests) // if (!this.testsOutput) return // eslint-disable-line @@ -84,7 +85,6 @@ export const SolidityUnitTesting = (props: any) => { return } } - if (testDirInput) { if (testDirInput.endsWith('/') && testDirInput !== '/') { testDirInput = helper.removeTrailingSlashes(testDirInput) @@ -98,6 +98,8 @@ export const SolidityUnitTesting = (props: any) => { if (await testTabLogic.pathExists(testDirInput)) { setDisableCreateButton(true) setDisableGenerateButton(false) + testTabLogic.setCurrentPath(testDirInput) + updateForNewCurrent() } else { // Enable Create button setDisableCreateButton(false) @@ -118,7 +120,7 @@ export const SolidityUnitTesting = (props: any) => { if (disableCreateButton) { if (await testTabLogic.pathExists(inputPath)) { testTabLogic.setCurrentPath(inputPath) - // this.updateForNewCurrent() + updateForNewCurrent() } } } @@ -136,39 +138,11 @@ export const SolidityUnitTesting = (props: any) => { console.log('path-->', path) console.log('inputPath-->', inputPath) // this.updateRunAction() - // this.updateForNewCurrent() + updateForNewCurrent() pathOptions.push(inputPath) setPathOptions(pathOptions) } - // const updateGenerateFileAction = () => { - // console.log('updateGenerateFileAction') - // return ( - // ) - // const el = yo` - // - // ` - // if (!this.generateFileActionElement) { - // this.generateFileActionElement = el - // } else { - // yo.update(this.generateFileActionElement, el) - // } - // return this.generateFileActionElement - // } - const updateRunAction = (currentFile = null) => { console.log('updateRunAction --currentFile-->', currentFile) @@ -214,6 +188,31 @@ export const SolidityUnitTesting = (props: any) => { // runBtn.setAttribute('disabled', 'disabled') } + const toggleCheckbox = (eChecked: any, test:any) => { + console.log('toggleCheckbox--->', test) + // if (!this.data.selectedTests) { + // this.data.selectedTests = this._view.el.querySelectorAll('.singleTest:checked') + // } + // let selectedTests = this.data.selectedTests + // selectedTests = eChecked ? [...selectedTests, test] : selectedTests.filter(el => el !== test) + // this.data.selectedTests = selectedTests + // const checkAll = this._view.el.querySelector('[id="checkAllTests"]') + // const runBtn = document.getElementById('runTestsTabRunAction') + + // if (eChecked) { + // checkAll.checked = true + // const stopBtnInnerText = document.getElementById('runTestsTabStopAction').innerText + // if ((this.readyTestsNumber === this.runningTestsNumber || this.hasBeenStopped) && stopBtnInnerText.trim() === 'Stop') { + // runBtn.removeAttribute('disabled') + // runBtn.setAttribute('title', 'Run tests') + // } + // } else if (!selectedTests.length) { + // checkAll.checked = false + // runBtn.setAttribute('disabled', 'disabled') + // runBtn.setAttribute('title', 'No test file selected') + // } + } + const checkAll = (event: any) => { console.log('checkAll --event-->', event) @@ -226,13 +225,13 @@ export const SolidityUnitTesting = (props: any) => { // } } - const createSingleTest = (testFile) => { - return yo` -
- this.toggleCheckbox(e.target.checked, testFile)} type="checkbox" checked="true"> - + const createSingleTest = (testFile: string) => { + return ( +
+ toggleCheckbox(e.target.checked, testFile)} type="checkbox"/> +
- ` + ) } const listTests = () => { @@ -244,6 +243,7 @@ export const SolidityUnitTesting = (props: any) => { } const updateTestFileList = (tests = []) => { + console.log('updateTestFileList--tests->', tests) const testsMsg: any = (tests && tests.length) ? listTests() : 'No test file available' setTestsMessage(testsMsg) } @@ -257,7 +257,6 @@ export const SolidityUnitTesting = (props: any) => { const [resultStatistics] = useState(createResultLabel()) - console.log('props---->', props) return (
From 752975e4a686a6894dc0a8c4790fabe97fe06e44 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 18 Nov 2021 13:12:34 +0530 Subject: [PATCH 030/103] linting fix --- apps/remix-ide/src/app/tabs/test-tab.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 8b4aa8672f..826988a401 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom' import { SolidityUnitTesting } from '@remix-ui/solidity-unit-testing' // eslint-disable-line import { ViewPlugin } from '@remixproject/engine-web' -import helper, { removeMultipleSlashes, removeTrailingSlashes } from '../../lib/helper' +import helper from '../../lib/helper' import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { format } from 'util' var yo = require('yo-yo') @@ -694,7 +694,6 @@ module.exports = class TestTab extends ViewPlugin { return yo`Progress: ${ready} finished (of ${this.runningTestsNumber})` } - pathAdded (text) { for (const option of this.uiPathList.querySelectorAll('option')) { if (option.innerHTML === text) return true @@ -707,13 +706,13 @@ module.exports = class TestTab extends ViewPlugin { this.renderComponent() return this.element } - + renderComponent () { ReactDOM.render( , this.element) } - + render2 () { this.onActivationInternal() this.testsOutput = yo`
- {updateRunAction()} +
From 651af04a0a27ae975aede4c7938ed23fdfd7abfc Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 18 Nov 2021 14:14:57 +0530 Subject: [PATCH 033/103] stopTests --- .../src/lib/solidity-unit-testing.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 8a2a4d7245..b5fb86ce00 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 @@ -192,15 +192,12 @@ export const SolidityUnitTesting = (props: any) => { } const stopTests = () => { - console.log('stopTests') - // this.hasBeenStopped = true - // const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel') - // stopBtnLabel.innerText = 'Stopping' - // const stopBtn = document.getElementById('runTestsTabStopAction') - // stopBtn.setAttribute('disabled', 'disabled') - // const runBtn = document.getElementById('runTestsTabRunAction') - // runBtn.setAttribute('disabled', 'disabled') + setHasBeenStopped(true) + setStopButtonLabel('Stopping') + const stopBtn = document.getElementById('runTestsTabStopAction') + setDisableStopButton(true) + setDisableRunButton(true) } const toggleCheckbox = (eChecked: any, test:any) => { From 7027e134ac4199ab6c4daf1bbfea2208ea071a7f Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 18 Nov 2021 18:40:30 +0530 Subject: [PATCH 034/103] runTests --- .../src/lib/solidity-unit-testing.tsx | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) 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 b5fb86ce00..d3dc85a51f 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,5 +1,6 @@ import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line import { TestTabLogic } from './logic/testTabLogic' +var async = require('async') import './css/style.css' @@ -30,9 +31,12 @@ export const SolidityUnitTesting = (props: any) => { let [selectedTests, setSelectedTests] = useState([]) const [inputPathValue, setInputPathValue] = useState('tests') - const [readyTestsNumber, setReadyTestsNumber] = useState(0) - const [runningTestsNumber, setRunningTestsNumber] = useState(0) - const [hasBeenStopped, setHasBeenStopped] = useState(false) + + let [readyTestsNumber, setReadyTestsNumber] = useState(0) + let [runningTestsNumber, setRunningTestsNumber] = useState(0) + let [hasBeenStopped, setHasBeenStopped] = useState(false) + let [areTestsRunning, setAreTestsRunning] = useState(false) + const trimTestDirInput = (input:string) => { @@ -40,6 +44,16 @@ export const SolidityUnitTesting = (props: any) => { else return input.trim() } + const clearResults = () => { + console.log('clearResults--->') + // yo.update(this.resultStatistics, yo``) + // this.call('editor', 'clearAnnotations') + // this.testsOutput.innerHTML = '' + // this.testsOutput.hidden = true + // this.testsExecutionStopped.hidden = true + // this.testsExecutionStoppedError.hidden = true + } + const updateForNewCurrent = async (file = null) => { // Ensure that when someone clicks on compilation error and that opens a new file // Test result, which is compilation error in this case, is not cleared @@ -55,8 +69,8 @@ export const SolidityUnitTesting = (props: any) => { console.log('Inside updateForNewCurrent --allTests-->', allTests) allTests = [] updateTestFileList() - // this.clearResults() - // if (!this.areTestsRunning) this.updateRunAction(file) + clearResults() + if (!areTestsRunning) updateRunAction(file) try { testTabLogic.getTests((error: any, tests: any) => { // if (error) return tooltip(error) @@ -156,24 +170,22 @@ export const SolidityUnitTesting = (props: any) => { const runTests = () => { console.log('runtests--->') - // this.areTestsRunning = true - // this.hasBeenStopped = false - // this.readyTestsNumber = 0 - // this.runningTestsNumber = this.data.selectedTests.length - // const stopBtn = document.getElementById('runTestsTabStopAction') - // stopBtn.removeAttribute('disabled') - // const runBtn = document.getElementById('runTestsTabRunAction') - // runBtn.setAttribute('disabled', 'disabled') - // this.clearResults() + areTestsRunning = true + hasBeenStopped = false + readyTestsNumber = 0 + runningTestsNumber = selectedTests.length + setDisableStopButton(false) + setDisableRunButton(true) + clearResults() // yo.update(this.resultStatistics, this.createResultLabel()) - // const tests = this.data.selectedTests - // if (!tests) return + const tests = selectedTests + if (!tests) return // this.resultStatistics.hidden = tests.length === 0 // _paq.push(['trackEvent', 'solidityUnitTesting', 'runTests']) - // async.eachOfSeries(tests, (value, key, callback) => { - // if (this.hasBeenStopped) return - // this.runTest(value, callback) - // }) + async.eachOfSeries(tests, (value: any, key: any, callback: any) => { + if (hasBeenStopped) return + // runTest(value, callback) + }) } const updateRunAction = (currentFile : any = null) => { From 35c58eba1c8483bb3c9a74669a02fbd4c3d74a73 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 19 Nov 2021 14:14:01 +0530 Subject: [PATCH 035/103] clearResults --- .../src/lib/solidity-unit-testing.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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 d3dc85a51f..fd39f69131 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 @@ -47,11 +47,11 @@ export const SolidityUnitTesting = (props: any) => { const clearResults = () => { console.log('clearResults--->') // yo.update(this.resultStatistics, yo``) - // this.call('editor', 'clearAnnotations') + testTab.call('editor', 'clearAnnotations') // this.testsOutput.innerHTML = '' // this.testsOutput.hidden = true - // this.testsExecutionStopped.hidden = true - // this.testsExecutionStoppedError.hidden = true + setTestsExecutionStoppedHidden(true) + setTestsExecutionStoppedErrorHidden(true) } const updateForNewCurrent = async (file = null) => { @@ -189,10 +189,8 @@ export const SolidityUnitTesting = (props: any) => { } const updateRunAction = (currentFile : any = null) => { - console.log('updateRunAction --currentFile-->', currentFile) - // const isSolidityActive = this.appManager.isActive('solidity') - const isSolidityActive = true + const isSolidityActive = testTab.appManager.isActive('solidity') if (!isSolidityActive || !listTests().length) { setDisableRunButton(true) if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { @@ -207,7 +205,6 @@ export const SolidityUnitTesting = (props: any) => { console.log('stopTests') setHasBeenStopped(true) setStopButtonLabel('Stopping') - const stopBtn = document.getElementById('runTestsTabStopAction') setDisableStopButton(true) setDisableRunButton(true) } From d1bd9d9e235ce1c72d2d1e4c5454116ccc283058 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 19 Nov 2021 15:53:26 +0530 Subject: [PATCH 036/103] checkAll --- .../src/lib/solidity-unit-testing.tsx | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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 fd39f69131..5facd4bee6 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,6 +1,7 @@ import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line import { TestTabLogic } from './logic/testTabLogic' var async = require('async') +var ReactDOM = require('react-dom'); import './css/style.css' @@ -231,23 +232,24 @@ export const SolidityUnitTesting = (props: any) => { } const checkAll = (event: any) => { - console.log('checkAll --event-->', event) - - // const checkBoxes = this._view.el.querySelectorAll('.singleTest') - // const checkboxesLabels = this._view.el.querySelectorAll('.singleTestLabel') - // // checks/unchecks all - // for (let i = 0; i < checkBoxes.length; i++) { - // checkBoxes[i].checked = event.target.checked - // this.toggleCheckbox(event.target.checked, checkboxesLabels[i].innerText) - // } + console.log('checkAll --event.target.checked-->', event.target.checked) + const checkBoxes = document.getElementsByClassName('singleTest') + const checkboxesLabels = document.getElementsByClassName('singleTestLabel') + // checks/unchecks all + for (let i = 0; i < checkBoxes.length; i++) { + if(event.target.checked) checkBoxes[i].setAttribute('checked', 'checked') + else checkBoxes[i].removeAttribute('checked') + toggleCheckbox(event.target.checked, checkboxesLabels[i].innerHTML) + } } const createSingleTest = (testFile: string) => { const checked = true + const elemId = `singleTest${testFile}` return (
- toggleCheckbox(e.target.checked, testFile)} type="checkbox" checked={checked}/> - + toggleCheckbox(e.target.checked, testFile)} type="checkbox" checked={checked}/> +
) } From 792a74320897b31635ed61cd1fd22e13188bca4b Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 22 Nov 2021 12:50:21 +0530 Subject: [PATCH 037/103] refactor loading test files --- .../src/lib/solidity-unit-testing.tsx | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) 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 5facd4bee6..8a8db9b8b9 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 @@ -22,11 +22,13 @@ export const SolidityUnitTesting = (props: any) => { const [runButtonTitle, setRunButtonTitle] = useState('Run tests') const [stopButtonLabel, setStopButtonLabel] = useState('Stop') const [checkSelectAll, setCheckSelectAll] = useState(true) + const [checkSingleTest, setCheckSingleTest] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) - const [testsMessage, setTestsMessage] = useState('No test file available') + // const [testsMessage, setTestsMessage] = useState('No test file available') + var [testFiles, setTestFiles] = useState([{}]) const [pathOptions, setPathOptions] = useState(['']) let [allTests, setAllTests] = useState([]) let [selectedTests, setSelectedTests] = useState([]) @@ -79,7 +81,7 @@ export const SolidityUnitTesting = (props: any) => { allTests = tests selectedTests = [...allTests] setSelectedTests(tests) - updateTestFileList(tests) + updateTestFileList() // if (!this.testsOutput) return // eslint-disable-line }) } catch (e) { @@ -192,7 +194,7 @@ export const SolidityUnitTesting = (props: any) => { const updateRunAction = (currentFile : any = null) => { console.log('updateRunAction --currentFile-->', currentFile) const isSolidityActive = testTab.appManager.isActive('solidity') - if (!isSolidityActive || !listTests().length) { + if (!isSolidityActive || !testFiles.length) { setDisableRunButton(true) if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { setRunButtonTitle('No solidity file selected') @@ -211,13 +213,21 @@ export const SolidityUnitTesting = (props: any) => { } const toggleCheckbox = (eChecked: any, test:any) => { - console.log('toggleCheckbox--->', test) + console.log('toggleCheckbox--->', test, eChecked) + console.log('toggleCheckbox--selectedTests1->', selectedTests) if (!selectedTests) { // this.data.selectedTests = this._view.el.querySelectorAll('.singleTest:checked') } let selectedTestsList: any = selectedTests selectedTests = eChecked ? [...selectedTestsList, test] : selectedTestsList.filter((el:any) => el !== test) + setSelectedTests(selectedTests) + // console.log('toggleCheckbox--selectedTests2->', selectedTests) + // const clickElem = document.getElementById(`singleTest${test}`) + // console.log('toggleCheckbox--clickElem->', clickElem, `singleTest${test}`) + // if(eChecked) clickElem?.setAttribute('checked', 'checked') + // else clickElem?.removeAttribute('checked') + if (eChecked) { setCheckSelectAll(true) if ((readyTestsNumber === runningTestsNumber || hasBeenStopped) && stopButtonLabel.trim() === 'Stop') { @@ -243,29 +253,12 @@ export const SolidityUnitTesting = (props: any) => { } } - const createSingleTest = (testFile: string) => { - const checked = true - const elemId = `singleTest${testFile}` - return ( -
- toggleCheckbox(e.target.checked, testFile)} type="checkbox" checked={checked}/> - -
- ) - } - - const listTests = () => { - console.log('listTests--->', allTests) - if (!allTests || !allTests.length) return [] - return allTests.map( - testFile => createSingleTest(testFile) - ) - } - - const updateTestFileList = (tests = []) => { - console.log('updateTestFileList--tests->', tests) - const testsMsg: any = (tests && tests.length) ? listTests() : 'No test file available' - setTestsMessage(testsMsg) + const updateTestFileList = () => { + console.log('updateTestFileList--tests->', allTests) + if(allTests?.length) { + testFiles = allTests.map((testFile) => { return {'fileName': testFile, 'checked': true }}) + setTestFiles(testFiles) + } } const createResultLabel = () => { @@ -351,7 +344,17 @@ export const SolidityUnitTesting = (props: any) => { />
-
{testsMessage}
+
{testFiles.length ? testFiles.map((testFileObj: any) => { + console.log('testFileObj----->', testFileObj) + const elemId = `singleTest${testFileObj.fileName}` + return ( +
+ toggleCheckbox(e.target.checked, testFileObj.fileName)} type="checkbox" checked={testFileObj.fileName}/> + +
+ ) + }) + : "No test file available" }
{resultStatistics} From 2b271fab2608a4d2030bf52ab4654a0b13cbb3a9 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 22 Nov 2021 13:01:49 +0530 Subject: [PATCH 038/103] fix initial files loading --- .../src/lib/solidity-unit-testing.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 8a8db9b8b9..3c3e6556c9 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 @@ -8,6 +8,11 @@ import './css/style.css' /* eslint-disable-next-line */ export interface SolidityUnitTestingProps {} +interface TestObject { + fileName: string + checked: boolean +} + export const SolidityUnitTesting = (props: any) => { const {helper, testTab} = props @@ -28,7 +33,7 @@ export const SolidityUnitTesting = (props: any) => { const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) // const [testsMessage, setTestsMessage] = useState('No test file available') - var [testFiles, setTestFiles] = useState([{}]) + var [testFiles, setTestFiles] = useState([]) const [pathOptions, setPathOptions] = useState(['']) let [allTests, setAllTests] = useState([]) let [selectedTests, setSelectedTests] = useState([]) @@ -91,6 +96,7 @@ export const SolidityUnitTesting = (props: any) => { useEffect(() => { updateDirList('/') + updateForNewCurrent() }, []) const updateDirList = (path: string) => { @@ -194,7 +200,7 @@ export const SolidityUnitTesting = (props: any) => { const updateRunAction = (currentFile : any = null) => { console.log('updateRunAction --currentFile-->', currentFile) const isSolidityActive = testTab.appManager.isActive('solidity') - if (!isSolidityActive || !testFiles.length) { + if (!isSolidityActive || !testFiles?.length) { setDisableRunButton(true) if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { setRunButtonTitle('No solidity file selected') @@ -344,7 +350,7 @@ export const SolidityUnitTesting = (props: any) => { />
-
{testFiles.length ? testFiles.map((testFileObj: any) => { +
{testFiles?.length ? testFiles.map((testFileObj: any) => { console.log('testFileObj----->', testFileObj) const elemId = `singleTest${testFileObj.fileName}` return ( From 14c2acb7233e8f64d82d3379f6781d27e9c08b3e Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 22 Nov 2021 13:07:56 +0530 Subject: [PATCH 039/103] fix initial load on folder chang --- .../src/lib/solidity-unit-testing.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 3c3e6556c9..d4eb6b018f 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 @@ -261,10 +261,11 @@ export const SolidityUnitTesting = (props: any) => { const updateTestFileList = () => { console.log('updateTestFileList--tests->', allTests) - if(allTests?.length) { + if(allTests?.length) testFiles = allTests.map((testFile) => { return {'fileName': testFile, 'checked': true }}) - setTestFiles(testFiles) - } + else + testFiles = [] + setTestFiles(testFiles) } const createResultLabel = () => { From 3c19efa05fc6044064270c163106a60d207ffc2f Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 22 Nov 2021 13:25:23 +0530 Subject: [PATCH 040/103] fix testTabLogic --- apps/remix-ide/src/app/tabs/test-tab.js | 5 +++-- libs/remix-ui/solidity-unit-testing/src/index.ts | 1 + .../src/lib/logic/testTabLogic.ts | 2 +- .../src/lib/solidity-unit-testing.tsx | 11 ++++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 826988a401..a87cd7c0f9 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -2,6 +2,7 @@ import React from 'react' // eslint-disable-line import ReactDOM from 'react-dom' import { SolidityUnitTesting } from '@remix-ui/solidity-unit-testing' // eslint-disable-line +import { TestTabLogic } from '@remix-ui/solidity-unit-testing' // eslint-disable-line import { ViewPlugin } from '@remixproject/engine-web' import helper from '../../lib/helper' @@ -16,7 +17,7 @@ var { UnitTestRunner, assertLibCode } = require('@remix-project/remix-tests') const _paq = window._paq = window._paq || [] -const TestTabLogic = require('./testTab/testTab') +// const TestTabLogic = require('./testTab/testTab') const profile = { name: 'solidityUnitTesting', @@ -41,6 +42,7 @@ module.exports = class TestTab extends ViewPlugin { this.appManager = appManager this.renderer = new Renderer(this) this.testRunner = new UnitTestRunner() + this.testTabLogic = new TestTabLogic(this.fileManager, helper) this.hasBeenStopped = false this.runningTestsNumber = 0 this.readyTestsNumber = 0 @@ -61,7 +63,6 @@ module.exports = class TestTab extends ViewPlugin { } onActivationInternal () { - this.testTabLogic = new TestTabLogic(this.fileManager) this.listenToEvents() this.call('filePanel', 'registerContextMenuItem', { id: 'solidityUnitTesting', diff --git a/libs/remix-ui/solidity-unit-testing/src/index.ts b/libs/remix-ui/solidity-unit-testing/src/index.ts index e007a75e38..55a090f9ef 100644 --- a/libs/remix-ui/solidity-unit-testing/src/index.ts +++ b/libs/remix-ui/solidity-unit-testing/src/index.ts @@ -1 +1,2 @@ export * from './lib/solidity-unit-testing'; +export * from './lib/logic/testTabLogic' diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts index 91f24b2872..b22db30ca6 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts +++ b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts @@ -38,7 +38,7 @@ export class TestTabLogic { } generateTestFile () { - console.log('Inside generateTestFile-1SUT-') + console.log('Inside generateTestFile-1SUT-currentFile-', this.fileManager.currentFile(), this.currentPath) let fileName = this.fileManager.currentFile() const hasCurrent = !!fileName && this.fileManager.currentFile().split('.').pop().toLowerCase() === 'sol' if (!hasCurrent) fileName = this.currentPath + '/newFile.sol' 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 d4eb6b018f..f6d30589d7 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,5 +1,5 @@ import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line -import { TestTabLogic } from './logic/testTabLogic' +// import { TestTabLogic } from './logic/testTabLogic' var async = require('async') var ReactDOM = require('react-dom'); @@ -17,7 +17,7 @@ export const SolidityUnitTesting = (props: any) => { const {helper, testTab} = props - const testTabLogic = new TestTabLogic(testTab.fileManager, helper) + const { testTabLogic } = testTab const [defaultPath, setDefaultPath] = useState('tests') const [disableCreateButton, setDisableCreateButton] = useState(true) @@ -106,13 +106,14 @@ export const SolidityUnitTesting = (props: any) => { } const handleTestDirInput = async (e: any) => { - console.log('handleTestDirInput--e-->', e) + console.log('handleTestDirInput--e-->', e.target) - let testDirInput = trimTestDirInput(inputPathValue) + let testDirInput = trimTestDirInput(e.target.value) + console.log('handleTestDirInput--e-->', testDirInput) testDirInput = helper.removeMultipleSlashes(testDirInput) if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput) + setInputPathValue(testDirInput) if (e.key === 'Enter') { - setInputPathValue(testDirInput) if (await testTabLogic.pathExists(testDirInput)) { testTabLogic.setCurrentPath(testDirInput) updateForNewCurrent() From ad9292272522dd211bd3395ade4c2300bf0b8450 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 22 Nov 2021 13:31:23 +0530 Subject: [PATCH 041/103] update test files on generate file --- .../src/lib/logic/testTabLogic.ts | 12 ++++++------ .../src/lib/solidity-unit-testing.tsx | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts index b22db30ca6..df19fb665d 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts +++ b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts @@ -47,12 +47,12 @@ export class TestTabLogic { const splittedFileName = fileName.split('/') const fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1] this.helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error: any, newFile: any) => { - // if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) - const isFileCreated = fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName)) - console.log('isFileCreated---->', isFileCreated) - // if (!isFileCreated) return modalDialogCustom.alert('Failed to create test file ' + newFile) - this.fileManager.open(newFile) - this.fileManager.syncEditor(newFile) + // if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) + const isFileCreated = fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName)) + console.log('isFileCreated---->', isFileCreated) + // if (!isFileCreated) return modalDialogCustom.alert('Failed to create test file ' + newFile) + this.fileManager.open(newFile) + this.fileManager.syncEditor(newFile) }) } 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 f6d30589d7..8515bf0ae6 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 @@ -324,7 +324,10 @@ export const SolidityUnitTesting = (props: any) => { data-id="testTabGenerateTestFile" title="Generate sample test file." disabled={disableGenerateButton} - onClick={testTabLogic.generateTestFile.bind(testTabLogic)} + onClick={() => { + testTabLogic.generateTestFile() + updateForNewCurrent() + }} > Generate From 7cc20295b5384b58aad954f9bbf48c41157f51da Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 22 Nov 2021 13:50:14 +0530 Subject: [PATCH 042/103] select all --- .../src/lib/solidity-unit-testing.tsx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) 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 8515bf0ae6..d7d928ac2b 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 @@ -249,21 +249,17 @@ export const SolidityUnitTesting = (props: any) => { } const checkAll = (event: any) => { - console.log('checkAll --event.target.checked-->', event.target.checked) - const checkBoxes = document.getElementsByClassName('singleTest') - const checkboxesLabels = document.getElementsByClassName('singleTestLabel') - // checks/unchecks all - for (let i = 0; i < checkBoxes.length; i++) { - if(event.target.checked) checkBoxes[i].setAttribute('checked', 'checked') - else checkBoxes[i].removeAttribute('checked') - toggleCheckbox(event.target.checked, checkboxesLabels[i].innerHTML) - } + testFiles.forEach((testFileObj) => testFileObj.checked = event.target.checked) + setTestFiles(testFiles) + setCheckSelectAll(event.target.checked) } const updateTestFileList = () => { console.log('updateTestFileList--tests->', allTests) - if(allTests?.length) + if(allTests?.length) { testFiles = allTests.map((testFile) => { return {'fileName': testFile, 'checked': true }}) + setCheckSelectAll(true) + } else testFiles = [] setTestFiles(testFiles) @@ -360,7 +356,7 @@ export const SolidityUnitTesting = (props: any) => { const elemId = `singleTest${testFileObj.fileName}` return (
- toggleCheckbox(e.target.checked, testFileObj.fileName)} type="checkbox" checked={testFileObj.fileName}/> + toggleCheckbox(e.target.checked, testFileObj.fileName)} type="checkbox" checked={testFileObj.checked}/>
) From 2fb1bfc60cad49aff85eabe8de816cfc0708bff1 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 22 Nov 2021 14:44:50 +0530 Subject: [PATCH 043/103] select a test file done --- .../src/lib/solidity-unit-testing.tsx | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) 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 d7d928ac2b..c3f9adc852 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 @@ -27,16 +27,14 @@ export const SolidityUnitTesting = (props: any) => { const [runButtonTitle, setRunButtonTitle] = useState('Run tests') const [stopButtonLabel, setStopButtonLabel] = useState('Stop') const [checkSelectAll, setCheckSelectAll] = useState(true) - const [checkSingleTest, setCheckSingleTest] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) - // const [testsMessage, setTestsMessage] = useState('No test file available') - var [testFiles, setTestFiles] = useState([]) + let [testFiles, setTestFiles] = useState([]) const [pathOptions, setPathOptions] = useState(['']) let [allTests, setAllTests] = useState([]) - let [selectedTests, setSelectedTests] = useState([]) + let [selectedTests, setSelectedTests] = useState([]) const [inputPathValue, setInputPathValue] = useState('tests') @@ -78,7 +76,7 @@ export const SolidityUnitTesting = (props: any) => { allTests = [] updateTestFileList() clearResults() - if (!areTestsRunning) updateRunAction(file) + // if (!areTestsRunning) updateRunAction(file) try { testTabLogic.getTests((error: any, tests: any) => { // if (error) return tooltip(error) @@ -201,7 +199,7 @@ export const SolidityUnitTesting = (props: any) => { const updateRunAction = (currentFile : any = null) => { console.log('updateRunAction --currentFile-->', currentFile) const isSolidityActive = testTab.appManager.isActive('solidity') - if (!isSolidityActive || !testFiles?.length) { + if (!isSolidityActive || !selectedTests?.length) { setDisableRunButton(true) if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { setRunButtonTitle('No solidity file selected') @@ -219,22 +217,17 @@ export const SolidityUnitTesting = (props: any) => { setDisableRunButton(true) } - const toggleCheckbox = (eChecked: any, test:any) => { - console.log('toggleCheckbox--->', test, eChecked) - console.log('toggleCheckbox--selectedTests1->', selectedTests) - if (!selectedTests) { - // this.data.selectedTests = this._view.el.querySelectorAll('.singleTest:checked') - } - let selectedTestsList: any = selectedTests - selectedTests = eChecked ? [...selectedTestsList, test] : selectedTestsList.filter((el:any) => el !== test) - setSelectedTests(selectedTests) - // console.log('toggleCheckbox--selectedTests2->', selectedTests) + const getCurrentSelectedTests = () => { + let selectedTestsList: TestObject[] = testFiles.filter(testFileObj => testFileObj.checked) + return selectedTestsList.map(testFileObj => testFileObj.fileName) + } - // const clickElem = document.getElementById(`singleTest${test}`) - // console.log('toggleCheckbox--clickElem->', clickElem, `singleTest${test}`) - // if(eChecked) clickElem?.setAttribute('checked', 'checked') - // else clickElem?.removeAttribute('checked') - + const toggleCheckbox = (eChecked: any, index:any) => { + testFiles[index].checked = eChecked + setTestFiles(testFiles) + selectedTests = getCurrentSelectedTests() + console.log('selectedTests----->', selectedTests) + setSelectedTests(selectedTests) if (eChecked) { setCheckSelectAll(true) if ((readyTestsNumber === runningTestsNumber || hasBeenStopped) && stopButtonLabel.trim() === 'Stop') { @@ -245,13 +238,21 @@ export const SolidityUnitTesting = (props: any) => { setCheckSelectAll(false) setDisableRunButton(true) setRunButtonTitle('No test file selected') - } + } else setCheckSelectAll(false) } const checkAll = (event: any) => { testFiles.forEach((testFileObj) => testFileObj.checked = event.target.checked) setTestFiles(testFiles) setCheckSelectAll(event.target.checked) + if(event.target.checked) { + selectedTests = getCurrentSelectedTests() + setSelectedTests(selectedTests) + setDisableRunButton(false) + } else { + setSelectedTests([]) + setDisableRunButton(true) + } } const updateTestFileList = () => { @@ -351,12 +352,12 @@ export const SolidityUnitTesting = (props: any) => { />
-
{testFiles?.length ? testFiles.map((testFileObj: any) => { +
{testFiles?.length ? testFiles.map((testFileObj: any, index) => { console.log('testFileObj----->', testFileObj) const elemId = `singleTest${testFileObj.fileName}` return (
- toggleCheckbox(e.target.checked, testFileObj.fileName)} type="checkbox" checked={testFileObj.checked}/> + toggleCheckbox(e.target.checked, index)} type="checkbox" checked={testFileObj.checked}/>
) From 3a54759d692072bd5b38abc1a50d67f1a600543e Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 22 Nov 2021 18:24:37 +0530 Subject: [PATCH 044/103] runTest --- .../src/lib/solidity-unit-testing.tsx | 235 +++++++++++++++++- 1 file changed, 232 insertions(+), 3 deletions(-) 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 c3f9adc852..5536f3d63e 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,7 +1,7 @@ import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line // import { TestTabLogic } from './logic/testTabLogic' var async = require('async') -var ReactDOM = require('react-dom'); +import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import './css/style.css' @@ -42,6 +42,7 @@ export const SolidityUnitTesting = (props: any) => { let [runningTestsNumber, setRunningTestsNumber] = useState(0) let [hasBeenStopped, setHasBeenStopped] = useState(false) let [areTestsRunning, setAreTestsRunning] = useState(false) + let [isDebugging, setIsDebugging] = useState(false) @@ -176,6 +177,234 @@ export const SolidityUnitTesting = (props: any) => { setPathOptions(pathOptions) } + const testCallback = (result, runningTests) => { + console.log('result---in testCallback->', result) + // this.testsOutput.hidden = false + // let debugBtn = yo`` + // if ((result.type === 'testPass' || result.type === 'testFailure') && result.debugTxHash) { + // const { web3, debugTxHash } = result + // debugBtn = yo`
this.startDebug(debugTxHash, web3)}> + // + //
` + // debugBtn.style.cursor = 'pointer' + // } + // if (result.type === 'contract') { + // this.testSuite = result.value + // if (this.testSuites) { + // this.testSuites.push(this.testSuite) + // } else { + // this.testSuites = [this.testSuite] + // } + // this.rawFileName = result.filename + // this.runningTestFileName = this.cleanFileName(this.rawFileName, this.testSuite) + // this.outputHeader = yo` + //
+ // ${this.testSuite} (${this.rawFileName}) + //
+ // ` + // this.testsOutput.appendChild(this.outputHeader) + // } else if (result.type === 'testPass') { + // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) + // this.testsOutput.appendChild(yo` + //
this.discardHighlight()} + // > + //
+ // ✓ ${result.value} + // ${debugBtn} + //
+ //
+ // `) + // } else if (result.type === 'testFailure') { + // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) + // if (!result.assertMethod) { + // this.testsOutput.appendChild(yo` + //
this.highlightLocation(result.location, runningTests, result.filename)} + // > + //
+ // ✘ ${result.value} + // ${debugBtn} + //
+ // Error Message: + // "${result.errMsg}" + //
+ // `) + // } else { + // const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' + // const method = result.assertMethod === 'ok' ? '' : result.assertMethod + // const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected + // this.testsOutput.appendChild(yo` + //
this.highlightLocation(result.location, runningTests, result.filename)} + // > + //
+ // ✘ ${result.value} + // ${debugBtn} + //
+ // Error Message: + // "${result.errMsg}" + // Assertion: + //
+ // Expected value should be + //
${method}
+ //
${preposition} ${expected}
+ //
+ // Received value: + // ${result.returned} + // Skipping the remaining tests of the function. + //
+ // `) + // } + // } else if (result.type === 'logOnly') { + // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) + // } + } + + const resultsCallback = (_err, result, cb) => { + // total stats for the test + // result.passingNum + // result.failureNum + // result.timePassed + cb() + } + + const updateFinalResult = (_errors, result, filename) => { + // ++this.readyTestsNumber + // this.testsOutput.hidden = false + // if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { + // this.testCallback({ type: 'contract', filename }) + // this.currentErrors = _errors.errors + // this.setHeader(false) + // } + // if (_errors && _errors.errors) { + // _errors.errors.forEach((err) => this.renderer.error(err.formattedMessage || err.message, this.testsOutput, { type: err.severity, errorType: err.type })) + // } else if (_errors && Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage)) { + // _errors.forEach((err) => this.renderer.error(err.formattedMessage || err.message, this.testsOutput, { type: err.severity, errorType: err.type })) + // } else if (_errors && !_errors.errors && !Array.isArray(_errors)) { + // // To track error like this: https://github.com/ethereum/remix/pull/1438 + // this.renderer.error(_errors.formattedMessage || _errors.message, this.testsOutput, { type: 'error' }) + // } + // yo.update(this.resultStatistics, this.createResultLabel()) + // if (result) { + // const totalTime = parseFloat(result.totalTime).toFixed(2) + + // if (result.totalPassing > 0 && result.totalFailing > 0) { + // this.testsOutput.appendChild(yo` + //
+ // Result for ${filename} + // Passing: ${result.totalPassing} + // Failing: ${result.totalFailing} + // Total time: ${totalTime}s + //
+ // `) + // } else if (result.totalPassing > 0 && result.totalFailing <= 0) { + // this.testsOutput.appendChild(yo` + //
+ // Result for ${filename} + // Passing: ${result.totalPassing} + // Total time: ${totalTime}s + //
+ // `) + // } else if (result.totalPassing <= 0 && result.totalFailing > 0) { + // this.testsOutput.appendChild(yo` + //
+ // Result for ${filename} + // Failing: ${result.totalFailing} + // Total time: ${totalTime}s + //
+ // `) + // } + // // fix for displaying right label for multiple tests (testsuites) in a single file + // this.testSuites.forEach(testSuite => { + // this.testSuite = testSuite + // this.runningTestFileName = this.cleanFileName(filename, this.testSuite) + // this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) + // this.setHeader(true) + // }) + + // result.errors.forEach((error, index) => { + // this.testSuite = error.context + // this.runningTestFileName = this.cleanFileName(filename, error.context) + // this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) + // const isFailingLabel = document.querySelector(`.failed_${this.runningTestFileName}`) + // if (!isFailingLabel) this.setHeader(false) + // }) + // this.testsOutput.appendChild(yo` + //
+ //

+ //
+ // `) + // } + // if (this.hasBeenStopped && (this.readyTestsNumber !== this.runningTestsNumber)) { + // // if all tests has been through before stopping no need to print this. + // this.testsExecutionStopped.hidden = false + // } + // if (_errors) this.testsExecutionStoppedError.hidden = false + // if (_errors || this.hasBeenStopped || this.readyTestsNumber === this.runningTestsNumber) { + // // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files. + // const stopBtn = document.getElementById('runTestsTabStopAction') + // stopBtn.setAttribute('disabled', 'disabled') + // const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel') + // stopBtnLabel.innerText = 'Stop' + // if (this.data.selectedTests.length !== 0) { + // const runBtn = document.getElementById('runTestsTabRunAction') + // runBtn.removeAttribute('disabled') + // } + // this.areTestsRunning = false + // } + } + + const runTest = (testFilePath, callback) => { + console.log('runTest----->', testFilePath, hasBeenStopped) + isDebugging = false + if (hasBeenStopped) { + // this.updateFinalResult() + return + } + // this.resultStatistics.hidden = false + testTab.fileManager.readFile(testFilePath).then((content) => { + const runningTests = {} + runningTests[testFilePath] = { content } + const { currentVersion, evmVersion, optimize, runs, isUrl } = testTab.compileTab.getCurrentCompilerConfig() + const currentCompilerUrl = isUrl ? currentVersion : urlFromVersion(currentVersion) + const compilerConfig = { + currentCompilerUrl, + evmVersion, + optimize, + usingWorker: canUseWorker(currentVersion), + runs + } + const deployCb = async (file, contractAddress) => { + const compilerData = await testTab.call('compilerArtefacts', 'getCompilerAbstract', file) + await testTab.call('compilerArtefacts', 'addResolvedContract', contractAddress, compilerData) + } + testTab.testRunner.runTestSources( + runningTests, + compilerConfig, + (result) => testCallback(result, runningTests), + (_err, result, cb) => resultsCallback(_err, result, cb), + deployCb, + (error, result) => { + updateFinalResult(error, result, testFilePath) + callback(error) + }, (url, cb) => { + return testTab.contentImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message)) + }, { testFilePath } + ) + }).catch((error) => { + console.log('Error in runTest---->', error) + if (error) return // eslint-disable-line + }) + } + const runTests = () => { console.log('runtests--->') areTestsRunning = true @@ -192,7 +421,7 @@ export const SolidityUnitTesting = (props: any) => { // _paq.push(['trackEvent', 'solidityUnitTesting', 'runTests']) async.eachOfSeries(tests, (value: any, key: any, callback: any) => { if (hasBeenStopped) return - // runTest(value, callback) + runTest(value, callback) }) } @@ -230,8 +459,8 @@ export const SolidityUnitTesting = (props: any) => { setSelectedTests(selectedTests) if (eChecked) { setCheckSelectAll(true) + setDisableRunButton(false) if ((readyTestsNumber === runningTestsNumber || hasBeenStopped) && stopButtonLabel.trim() === 'Stop') { - setDisableRunButton(false) setRunButtonTitle('Run tests') } } else if (!selectedTests.length) { From 9a2cf35b2bb9a8dedae1447ed7fe4675856cf4f8 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 23 Nov 2021 18:01:45 +0530 Subject: [PATCH 045/103] cards for passed tests --- .../src/lib/solidity-unit-testing.tsx | 108 ++++++++++-------- 1 file changed, 60 insertions(+), 48 deletions(-) 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 5536f3d63e..aa654bb0ba 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 @@ -27,13 +27,15 @@ export const SolidityUnitTesting = (props: any) => { const [runButtonTitle, setRunButtonTitle] = useState('Run tests') const [stopButtonLabel, setStopButtonLabel] = useState('Stop') const [checkSelectAll, setCheckSelectAll] = useState(true) + const [testsOutput, setTestsOutput] = useState([]) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) + let [testFiles, setTestFiles] = useState([]) const [pathOptions, setPathOptions] = useState(['']) - let [allTests, setAllTests] = useState([]) + // let [allTests, setAllTests] = useState([]) let [selectedTests, setSelectedTests] = useState([]) const [inputPathValue, setInputPathValue] = useState('tests') @@ -44,7 +46,11 @@ export const SolidityUnitTesting = (props: any) => { let [areTestsRunning, setAreTestsRunning] = useState(false) let [isDebugging, setIsDebugging] = useState(false) + let allTests: any = [] + let testSuite: any + let testSuites: any + let runningTestFileName: any const trimTestDirInput = (input:string) => { if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') @@ -177,7 +183,11 @@ export const SolidityUnitTesting = (props: any) => { setPathOptions(pathOptions) } - const testCallback = (result, runningTests) => { + const cleanFileName = (fileName: any, testSuite: any) => { + return fileName ? fileName.replace(/\//g, '_').replace(/\./g, '_') + testSuite : fileName + } + + const testCallback = (result: any, runningTests: any) => { console.log('result---in testCallback->', result) // this.testsOutput.hidden = false // let debugBtn = yo`` @@ -188,37 +198,38 @@ export const SolidityUnitTesting = (props: any) => { //
` // debugBtn.style.cursor = 'pointer' // } - // if (result.type === 'contract') { - // this.testSuite = result.value - // if (this.testSuites) { - // this.testSuites.push(this.testSuite) - // } else { - // this.testSuites = [this.testSuite] - // } - // this.rawFileName = result.filename - // this.runningTestFileName = this.cleanFileName(this.rawFileName, this.testSuite) - // this.outputHeader = yo` - //
- // ${this.testSuite} (${this.rawFileName}) - //
- // ` - // this.testsOutput.appendChild(this.outputHeader) - // } else if (result.type === 'testPass') { - // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) - // this.testsOutput.appendChild(yo` - //
this.discardHighlight()} - // > - //
- // ✓ ${result.value} - // ${debugBtn} - //
- //
- // `) - // } else if (result.type === 'testFailure') { + if (result.type === 'contract') { + var testSuite = result.value + if (testSuites) { + testSuites.push(testSuite) + } else { + testSuites = [testSuite] + } + runningTestFileName = cleanFileName(result.filename, testSuite) + const ContractCard: any = ( +
+ {testSuite} ({result.filename}) +
+ ) + setTestsOutput(prevCards => ([...prevCards, ContractCard])) + } else if (result.type === 'testPass') { + // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) + const testPassCard: any = ( +
this.discardHighlight()} + > +
+ ✓ {result.value} + {/* ${debugBtn} */} +
+
+ ) + setTestsOutput(prevCards => ([...prevCards, testPassCard])) + } + //else if (result.type === 'testFailure') { // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) // if (!result.assertMethod) { // this.testsOutput.appendChild(yo` @@ -268,7 +279,7 @@ export const SolidityUnitTesting = (props: any) => { // } } - const resultsCallback = (_err, result, cb) => { + const resultsCallback = (_err: any, result: any, cb: any) => { // total stats for the test // result.passingNum // result.failureNum @@ -276,7 +287,8 @@ export const SolidityUnitTesting = (props: any) => { cb() } - const updateFinalResult = (_errors, result, filename) => { + const updateFinalResult = (_errors: any, result: any, filename: any) => { + console.log('result---in updateFinalResult->', result, filename) // ++this.readyTestsNumber // this.testsOutput.hidden = false // if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { @@ -362,7 +374,7 @@ export const SolidityUnitTesting = (props: any) => { // } } - const runTest = (testFilePath, callback) => { + const runTest = (testFilePath: any, callback: any) => { console.log('runTest----->', testFilePath, hasBeenStopped) isDebugging = false if (hasBeenStopped) { @@ -370,8 +382,8 @@ export const SolidityUnitTesting = (props: any) => { return } // this.resultStatistics.hidden = false - testTab.fileManager.readFile(testFilePath).then((content) => { - const runningTests = {} + testTab.fileManager.readFile(testFilePath).then((content: any) => { + const runningTests: any = {} runningTests[testFilePath] = { content } const { currentVersion, evmVersion, optimize, runs, isUrl } = testTab.compileTab.getCurrentCompilerConfig() const currentCompilerUrl = isUrl ? currentVersion : urlFromVersion(currentVersion) @@ -382,24 +394,24 @@ export const SolidityUnitTesting = (props: any) => { usingWorker: canUseWorker(currentVersion), runs } - const deployCb = async (file, contractAddress) => { + const deployCb = async (file: any, contractAddress: any) => { const compilerData = await testTab.call('compilerArtefacts', 'getCompilerAbstract', file) await testTab.call('compilerArtefacts', 'addResolvedContract', contractAddress, compilerData) } testTab.testRunner.runTestSources( runningTests, compilerConfig, - (result) => testCallback(result, runningTests), - (_err, result, cb) => resultsCallback(_err, result, cb), + (result: any) => testCallback(result, runningTests), + (_err: any, result: any, cb: any) => resultsCallback(_err, result, cb), deployCb, - (error, result) => { + (error: any, result: any) => { updateFinalResult(error, result, testFilePath) callback(error) - }, (url, cb) => { - return testTab.contentImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message)) + }, (url: any, cb: any) => { + return testTab.contentImport.resolveAndSave(url).then((result: any) => cb(null, result)).catch((error: any) => cb(error.message)) }, { testFilePath } ) - }).catch((error) => { + }).catch((error: any) => { console.log('Error in runTest---->', error) if (error) return // eslint-disable-line }) @@ -412,7 +424,7 @@ export const SolidityUnitTesting = (props: any) => { readyTestsNumber = 0 runningTestsNumber = selectedTests.length setDisableStopButton(false) - setDisableRunButton(true) + // setDisableRunButton(true) clearResults() // yo.update(this.resultStatistics, this.createResultLabel()) const tests = selectedTests @@ -487,7 +499,7 @@ export const SolidityUnitTesting = (props: any) => { const updateTestFileList = () => { console.log('updateTestFileList--tests->', allTests) if(allTests?.length) { - testFiles = allTests.map((testFile) => { return {'fileName': testFile, 'checked': true }}) + testFiles = allTests.map((testFile: any) => { return {'fileName': testFile, 'checked': true }}) setCheckSelectAll(true) } else @@ -597,7 +609,7 @@ export const SolidityUnitTesting = (props: any) => {
- {/* ${this.testsOutput} */} +
{testsOutput}
) From bc566d4258172b9b52c231eb84a17e83acb74e56 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 23 Nov 2021 18:19:02 +0530 Subject: [PATCH 046/103] testFailure card for tx revert --- .../src/lib/solidity-unit-testing.tsx | 95 +++++++++---------- 1 file changed, 47 insertions(+), 48 deletions(-) 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 aa654bb0ba..3791a1e5e6 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 @@ -61,8 +61,7 @@ export const SolidityUnitTesting = (props: any) => { console.log('clearResults--->') // yo.update(this.resultStatistics, yo``) testTab.call('editor', 'clearAnnotations') - // this.testsOutput.innerHTML = '' - // this.testsOutput.hidden = true + setTestsOutput([]) setTestsExecutionStoppedHidden(true) setTestsExecutionStoppedErrorHidden(true) } @@ -228,53 +227,53 @@ export const SolidityUnitTesting = (props: any) => {
) setTestsOutput(prevCards => ([...prevCards, testPassCard])) + } else if (result.type === 'testFailure') { + // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) + if (!result.assertMethod) { + const testFailCard: any = (
this.highlightLocation(result.location, runningTests, result.filename)} + > +
+ ✘ {result.value} + {/* ${debugBtn} */} +
+ Error Message: + "{result.errMsg}" +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard])) + } + // else { + // const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' + // const method = result.assertMethod === 'ok' ? '' : result.assertMethod + // const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected + // this.testsOutput.appendChild(yo` + //
this.highlightLocation(result.location, runningTests, result.filename)} + // > + //
+ // ✘ ${result.value} + // ${debugBtn} + //
+ // Error Message: + // "${result.errMsg}" + // Assertion: + //
+ // Expected value should be + //
${method}
+ //
${preposition} ${expected}
+ //
+ // Received value: + // ${result.returned} + // Skipping the remaining tests of the function. + //
+ // `) + // } } - //else if (result.type === 'testFailure') { - // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) - // if (!result.assertMethod) { - // this.testsOutput.appendChild(yo` - //
this.highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ ${result.value} - // ${debugBtn} - //
- // Error Message: - // "${result.errMsg}" - //
- // `) - // } else { - // const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' - // const method = result.assertMethod === 'ok' ? '' : result.assertMethod - // const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected - // this.testsOutput.appendChild(yo` - //
this.highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ ${result.value} - // ${debugBtn} - //
- // Error Message: - // "${result.errMsg}" - // Assertion: - //
- // Expected value should be - //
${method}
- //
${preposition} ${expected}
- //
- // Received value: - // ${result.returned} - // Skipping the remaining tests of the function. - //
- // `) - // } - // } else if (result.type === 'logOnly') { + //else if (result.type === 'logOnly') { // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) // } } From 59a23567237e1d795b4cff541e0c10696e117918 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 23 Nov 2021 18:27:44 +0530 Subject: [PATCH 047/103] testFailCard2 --- .../src/lib/solidity-unit-testing.tsx | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) 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 3791a1e5e6..57fd5f6654 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 @@ -230,7 +230,7 @@ export const SolidityUnitTesting = (props: any) => { } else if (result.type === 'testFailure') { // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) if (!result.assertMethod) { - const testFailCard: any = (
this.highlightLocation(result.location, runningTests, result.filename)} @@ -242,36 +242,34 @@ export const SolidityUnitTesting = (props: any) => { Error Message: "{result.errMsg}"
) - setTestsOutput(prevCards => ([...prevCards, testFailCard])) - } - // else { - // const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' - // const method = result.assertMethod === 'ok' ? '' : result.assertMethod - // const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected - // this.testsOutput.appendChild(yo` - //
this.highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ ${result.value} - // ${debugBtn} - //
- // Error Message: - // "${result.errMsg}" - // Assertion: - //
- // Expected value should be - //
${method}
- //
${preposition} ${expected}
- //
- // Received value: - // ${result.returned} - // Skipping the remaining tests of the function. - //
- // `) - // } + setTestsOutput(prevCards => ([...prevCards, testFailCard1])) + } else { + const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' + const method = result.assertMethod === 'ok' ? '' : result.assertMethod + const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected + const testFailCard2: any = (
this.highlightLocation(result.location, runningTests, result.filename)} + > +
+ ✘ {result.value} + {/* ${debugBtn} */} +
+ Error Message: + "{result.errMsg}" + Assertion: +
+ Expected value should be +
{method}
+
{preposition} {expected}
+
+ Received value: + {result.returned} + Skipping the remaining tests of the function. +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard2])) + } } //else if (result.type === 'logOnly') { // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) From ecf8057b34e81f2b9c0aea357205a44e9ac3b3aa Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 23 Nov 2021 18:54:29 +0530 Subject: [PATCH 048/103] debug button --- .../src/lib/solidity-unit-testing.tsx | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) 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 57fd5f6654..b4fbe89974 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 @@ -186,17 +186,24 @@ export const SolidityUnitTesting = (props: any) => { return fileName ? fileName.replace(/\//g, '_').replace(/\./g, '_') + testSuite : fileName } + const startDebug = async (txHash: any, web3: any) => { + // this.isDebugging = true + if (!await testTab.appManager.isActive('debugger')) await testTab.appManager.activatePlugin('debugger') + testTab.call('menuicons', 'select', 'debugger') + testTab.call('debugger', 'debug', txHash, web3) + } + const testCallback = (result: any, runningTests: any) => { console.log('result---in testCallback->', result) - // this.testsOutput.hidden = false - // let debugBtn = yo`` - // if ((result.type === 'testPass' || result.type === 'testFailure') && result.debugTxHash) { - // const { web3, debugTxHash } = result - // debugBtn = yo`
this.startDebug(debugTxHash, web3)}> - // - //
` - // debugBtn.style.cursor = 'pointer' - // } + let debugBtn + if ((result.type === 'testPass' || result.type === 'testFailure') && result.debugTxHash) { + const { web3, debugTxHash } = result + debugBtn = ( +
startDebug(debugTxHash, web3)}> + +
+ ) + } if (result.type === 'contract') { var testSuite = result.value if (testSuites) { @@ -222,7 +229,7 @@ export const SolidityUnitTesting = (props: any) => { >
✓ {result.value} - {/* ${debugBtn} */} + {debugBtn}
) @@ -237,7 +244,7 @@ export const SolidityUnitTesting = (props: any) => { >
✘ {result.value} - {/* ${debugBtn} */} + {debugBtn}
Error Message: "{result.errMsg}" @@ -254,7 +261,7 @@ export const SolidityUnitTesting = (props: any) => { >
✘ {result.value} - {/* ${debugBtn} */} + {debugBtn}
Error Message: "{result.errMsg}" From cce9229aee739f94d4a7f3afa81a095b811d539d Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 2 Dec 2021 19:04:53 +0530 Subject: [PATCH 049/103] print hardhat Logs --- .../src/lib/solidity-unit-testing.tsx | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) 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 b4fbe89974..87f67fdcf7 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 @@ -2,6 +2,7 @@ import React, { useState, useRef, useEffect } from 'react' // eslint-disable-lin // import { TestTabLogic } from './logic/testTabLogic' var async = require('async') import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' +import { format } from 'util' import './css/style.css' @@ -26,6 +27,7 @@ export const SolidityUnitTesting = (props: any) => { const [disableRunButton, setDisableRunButton] = useState(false) const [runButtonTitle, setRunButtonTitle] = useState('Run tests') const [stopButtonLabel, setStopButtonLabel] = useState('Stop') + const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsOutput, setTestsOutput] = useState([]) @@ -193,6 +195,25 @@ export const SolidityUnitTesting = (props: any) => { testTab.call('debugger', 'debug', txHash, web3) } + const printHHLogs = (logsArr: any, testName: any) => { + let finalLogs = `${testName}:\n` + for (const log of logsArr) { + let formattedLog + // Hardhat implements the same formatting options that can be found in Node.js' console.log, + // which in turn uses util.format: https://nodejs.org/dist/latest-v12.x/docs/api/util.html#util_util_format_format_args + // For example: console.log("Name: %s, Age: %d", remix, 6) will log 'Name: remix, Age: 6' + // We check first arg to determine if 'util.format' is needed + if (typeof log[0] === 'string' && (log[0].includes('%s') || log[0].includes('%d'))) { + formattedLog = format(log[0], ...log.slice(1)) + } else { + formattedLog = log.join(' ') + } + finalLogs = finalLogs + ' ' + formattedLog + '\n' + } + // _paq.push(['trackEvent', 'solidityUnitTesting', 'hardhat', 'console.log']) + testTab.call('terminal', 'log', { type: 'info', value: finalLogs }) + } + const testCallback = (result: any, runningTests: any) => { console.log('result---in testCallback->', result) let debugBtn @@ -219,7 +240,7 @@ export const SolidityUnitTesting = (props: any) => { ) setTestsOutput(prevCards => ([...prevCards, ContractCard])) } else if (result.type === 'testPass') { - // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) + if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) const testPassCard: any = (
{ ) setTestsOutput(prevCards => ([...prevCards, testPassCard])) } else if (result.type === 'testFailure') { - // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) + if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) if (!result.assertMethod) { const testFailCard1: any = (
{
) setTestsOutput(prevCards => ([...prevCards, testFailCard2])) } - } - //else if (result.type === 'logOnly') { - // if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) - // } + } else if (result.type === 'logOnly') { + if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) + } } const resultsCallback = (_err: any, result: any, cb: any) => { From 360419c970194a04c3e1ac12f9b16da481df7ecc Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 2 Dec 2021 20:04:22 +0530 Subject: [PATCH 050/103] highlightLocation --- .../src/lib/solidity-unit-testing.tsx | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 87f67fdcf7..77a9cd1ee1 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 @@ -214,6 +214,24 @@ export const SolidityUnitTesting = (props: any) => { testTab.call('terminal', 'log', { type: 'info', value: finalLogs }) } + const highlightLocation = async (location: any, runningTests: any, fileName: any) => { + if (location) { + var split = location.split(':') + var file = split[2] + location = { + start: parseInt(split[0]), + length: parseInt(split[1]) + } + location = testTab.offsetToLineColumnConverter.offsetToLineColumnWithContent( + location, + parseInt(file), + runningTests[fileName].content + ) + await testTab.call('editor', 'discardHighlight') + await testTab.call('editor', 'highlight', location, fileName, '', { focus: true }) + } + } + const testCallback = (result: any, runningTests: any) => { console.log('result---in testCallback->', result) let debugBtn @@ -261,7 +279,7 @@ export const SolidityUnitTesting = (props: any) => { const testFailCard1: any = (
this.highlightLocation(result.location, runningTests, result.filename)} + onClick={() => highlightLocation(result.location, runningTests, result.filename)} >
✘ {result.value} @@ -278,7 +296,7 @@ export const SolidityUnitTesting = (props: any) => { const testFailCard2: any = (
this.highlightLocation(result.location, runningTests, result.filename)} + onClick={() => highlightLocation(result.location, runningTests, result.filename)} >
✘ {result.value} From 38d07255fd96cd9985ec977db4872647426ff624 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 2 Dec 2021 20:23:28 +0530 Subject: [PATCH 051/103] discardHighlight --- .../solidity-unit-testing/src/lib/solidity-unit-testing.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 77a9cd1ee1..2c57d3fcfe 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 @@ -214,6 +214,10 @@ export const SolidityUnitTesting = (props: any) => { testTab.call('terminal', 'log', { type: 'info', value: finalLogs }) } + const discardHighlight = async () => { + await testTab.call('editor', 'discardHighlight') + } + const highlightLocation = async (location: any, runningTests: any, fileName: any) => { if (location) { var split = location.split(':') @@ -264,7 +268,7 @@ export const SolidityUnitTesting = (props: any) => { id={runningTestFileName} data-id="testTabSolidityUnitTestsOutputheader" className="testPass testLog bg-light mb-2 px-2 text-success border-0" - // onClick=${() => this.discardHighlight()} + onClick={() => discardHighlight()} >
✓ {result.value} From 0e613355581a9b8e120ada5930ffd2910ef08d76 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 6 Dec 2021 14:01:10 +0530 Subject: [PATCH 052/103] tests Summary --- .../src/lib/solidity-unit-testing.tsx | 119 ++++++++++-------- 1 file changed, 68 insertions(+), 51 deletions(-) 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 2c57d3fcfe..977bd6d17e 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 @@ -14,6 +14,13 @@ interface TestObject { checked: boolean } +interface TestSummary { + filename: string + passed: number + failed: number + timeTaken: any +} + export const SolidityUnitTesting = (props: any) => { const {helper, testTab} = props @@ -30,6 +37,8 @@ export const SolidityUnitTesting = (props: any) => { const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsOutput, setTestsOutput] = useState([]) + let [testsSummary, setTestsSummary] = useState() + const [testsSummaryHidden, setTestsSummaryHidden] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) @@ -335,8 +344,8 @@ export const SolidityUnitTesting = (props: any) => { const updateFinalResult = (_errors: any, result: any, filename: any) => { console.log('result---in updateFinalResult->', result, filename) - // ++this.readyTestsNumber - // this.testsOutput.hidden = false + ++readyTestsNumber + setTestsSummaryHidden(false) // if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { // this.testCallback({ type: 'contract', filename }) // this.currentErrors = _errors.errors @@ -351,55 +360,57 @@ export const SolidityUnitTesting = (props: any) => { // this.renderer.error(_errors.formattedMessage || _errors.message, this.testsOutput, { type: 'error' }) // } // yo.update(this.resultStatistics, this.createResultLabel()) - // if (result) { - // const totalTime = parseFloat(result.totalTime).toFixed(2) - - // if (result.totalPassing > 0 && result.totalFailing > 0) { - // this.testsOutput.appendChild(yo` - //
- // Result for ${filename} - // Passing: ${result.totalPassing} - // Failing: ${result.totalFailing} - // Total time: ${totalTime}s - //
- // `) - // } else if (result.totalPassing > 0 && result.totalFailing <= 0) { - // this.testsOutput.appendChild(yo` - //
- // Result for ${filename} - // Passing: ${result.totalPassing} - // Total time: ${totalTime}s - //
- // `) - // } else if (result.totalPassing <= 0 && result.totalFailing > 0) { - // this.testsOutput.appendChild(yo` - //
- // Result for ${filename} - // Failing: ${result.totalFailing} - // Total time: ${totalTime}s - //
- // `) - // } - // // fix for displaying right label for multiple tests (testsuites) in a single file - // this.testSuites.forEach(testSuite => { - // this.testSuite = testSuite - // this.runningTestFileName = this.cleanFileName(filename, this.testSuite) - // this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) - // this.setHeader(true) - // }) - - // result.errors.forEach((error, index) => { - // this.testSuite = error.context - // this.runningTestFileName = this.cleanFileName(filename, error.context) - // this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) - // const isFailingLabel = document.querySelector(`.failed_${this.runningTestFileName}`) - // if (!isFailingLabel) this.setHeader(false) - // }) - // this.testsOutput.appendChild(yo` - //
- //

- //
- // `) + if (result) { + const totalTime = parseFloat(result.totalTime).toFixed(2) + testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime } + setTestsSummary(testsSummary) + + // if (result.totalPassing > 0 && result.totalFailing > 0) { + // this.testsOutput.appendChild(yo` + //
+ // Result for ${filename} + // Passing: ${result.totalPassing} + // Failing: ${result.totalFailing} + // Total time: ${totalTime}s + //
+ // `) + // } else if (result.totalPassing > 0 && result.totalFailing <= 0) { + // this.testsOutput.appendChild(yo` + //
+ // Result for ${filename} + // Passing: ${result.totalPassing} + // Total time: ${totalTime}s + //
+ // `) + // } else if (result.totalPassing <= 0 && result.totalFailing > 0) { + // this.testsOutput.appendChild(yo` + //
+ // Result for ${filename} + // Failing: ${result.totalFailing} + // Total time: ${totalTime}s + //
+ // `) + } + // fix for displaying right label for multiple tests (testsuites) in a single file + // this.testSuites.forEach(testSuite => { + // this.testSuite = testSuite + // this.runningTestFileName = this.cleanFileName(filename, this.testSuite) + // this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) + // this.setHeader(true) + // }) + + // result.errors.forEach((error, index) => { + // this.testSuite = error.context + // this.runningTestFileName = this.cleanFileName(filename, error.context) + // this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) + // const isFailingLabel = document.querySelector(`.failed_${this.runningTestFileName}`) + // if (!isFailingLabel) this.setHeader(false) + // }) + // this.testsOutput.appendChild(yo` + //
+ //

+ //
+ // `) // } // if (this.hasBeenStopped && (this.readyTestsNumber !== this.runningTestsNumber)) { // // if all tests has been through before stopping no need to print this. @@ -656,6 +667,12 @@ export const SolidityUnitTesting = (props: any) => {
{testsOutput}
+
) From f46d948a08ba5308849827dcf1c992d06f646725 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 6 Dec 2021 18:51:51 +0530 Subject: [PATCH 053/103] test summary visibility --- .../src/lib/solidity-unit-testing.tsx | 34 +++---------------- 1 file changed, 4 insertions(+), 30 deletions(-) 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 977bd6d17e..934cb8dba3 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,4 @@ -import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line +import React, { useState, useRef, useEffect, CSSProperties } from 'react' // eslint-disable-line // import { TestTabLogic } from './logic/testTabLogic' var async = require('async') import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' @@ -38,7 +38,7 @@ export const SolidityUnitTesting = (props: any) => { const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsOutput, setTestsOutput] = useState([]) let [testsSummary, setTestsSummary] = useState() - const [testsSummaryHidden, setTestsSummaryHidden] = useState(true) + const [testsSummaryHidden, setTestsSummaryHidden] = useState('hidden') const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) @@ -345,7 +345,7 @@ export const SolidityUnitTesting = (props: any) => { const updateFinalResult = (_errors: any, result: any, filename: any) => { console.log('result---in updateFinalResult->', result, filename) ++readyTestsNumber - setTestsSummaryHidden(false) + setTestsSummaryHidden('visible') // if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { // this.testCallback({ type: 'contract', filename }) // this.currentErrors = _errors.errors @@ -364,32 +364,6 @@ export const SolidityUnitTesting = (props: any) => { const totalTime = parseFloat(result.totalTime).toFixed(2) testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime } setTestsSummary(testsSummary) - - // if (result.totalPassing > 0 && result.totalFailing > 0) { - // this.testsOutput.appendChild(yo` - //
- // Result for ${filename} - // Passing: ${result.totalPassing} - // Failing: ${result.totalFailing} - // Total time: ${totalTime}s - //
- // `) - // } else if (result.totalPassing > 0 && result.totalFailing <= 0) { - // this.testsOutput.appendChild(yo` - //
- // Result for ${filename} - // Passing: ${result.totalPassing} - // Total time: ${totalTime}s - //
- // `) - // } else if (result.totalPassing <= 0 && result.totalFailing > 0) { - // this.testsOutput.appendChild(yo` - //
- // Result for ${filename} - // Failing: ${result.totalFailing} - // Total time: ${totalTime}s - //
- // `) } // fix for displaying right label for multiple tests (testsuites) in a single file // this.testSuites.forEach(testSuite => { @@ -667,7 +641,7 @@ export const SolidityUnitTesting = (props: any) => {
{testsOutput}
-
) From dbb7f6daad0b769111d122874a1f3096c698f63f Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 10 Dec 2021 18:52:06 +0530 Subject: [PATCH 055/103] tests display refactoring --- .../src/lib/solidity-unit-testing.tsx | 261 ++++++------------ 1 file changed, 77 insertions(+), 184 deletions(-) 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 9c5d64d658..8c1dc8e2c6 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 @@ -259,16 +259,30 @@ export const SolidityUnitTesting = (props: any) => { for(const contract of contracts) { if(contract && contract !== 'summary') { runningTestFileName = cleanFileName(filename, contract) - // show contract and file name - const ContractCard: any = ( -
- {contract} ({filename}) -
- ) - setTestsOutput(prevCards => ([...prevCards, ContractCard])) - // show tests const tests = fileTestsResult[contract] if (tests?.length) { + const index = tests.findIndex((test: any) => test.type === 'testFailure') + let label + if (index > -1) label = (
+ FAIL +
) + else label = (
+ PASS +
) + // show contract and file name with label + const ContractCard: any = ( +
+ {label}{contract} ({filename}) +
+ ) + setTestsOutput(prevCards => ([...prevCards, ContractCard])) + // show tests for(const test of tests) { if (test.type === 'testPass') { if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) @@ -286,8 +300,61 @@ export const SolidityUnitTesting = (props: any) => {
) setTestsOutput(prevCards => ([...prevCards, testPassCard])) - } + } else if (test.type === 'testFailure') { + // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) + if (!test.assertMethod) { + const testFailCard1: any = (
highlightLocation(test.location, runningTests, test.filename)} + > +
+ ✘ {test.value} + {/* {debugBtn} */} +
+ Error Message: + "{test.errMsg}" +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard1])) + } else { + const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' + const method = test.assertMethod === 'ok' ? '' : test.assertMethod + const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected + const testFailCard2: any = (
highlightLocation(result.location, runningTests, result.filename)} + > +
+ ✘ {test.value} + {/* {debugBtn} */} +
+ Error Message: + "{test.errMsg}" + Assertion: +
+ Expected value should be +
{method}
+
{preposition} {expected}
+
+ Received value: + {test.returned} + Skipping the remaining tests of the function. +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard2])) + } + } else if (test.type === 'logOnly') { + // if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + } } + } else { + // show only contract and file name + const ContractCard: any = ( +
+ {contract} ({filename}) +
+ ) + setTestsOutput(prevCards => ([...prevCards, ContractCard])) } } } @@ -301,98 +368,9 @@ export const SolidityUnitTesting = (props: any) => { // //
// ) - // } - // if (result.type === 'contract') { - // var testSuite = result.value - // if (testSuites) { - // testSuites.push(testSuite) - // } else { - // testSuites = [testSuite] - // } - // runningTestFileName = cleanFileName(result.filename, testSuite) - // const ContractCard: any = ( - //
- // {testSuite} ({result.filename}) - //
- // ) - // setTestsOutput(prevCards => ([...prevCards, ContractCard])) - // } else if (result.type === 'testPass') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // const testPassCard: any = ( - //
discardHighlight()} - // > - //
- // ✓ {result.value} - // {debugBtn} - //
- //
- // ) - // setTestsOutput(prevCards => ([...prevCards, testPassCard])) - // } else if (result.type === 'testFailure') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // if (!result.assertMethod) { - // const testFailCard1: any = (
highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ {result.value} - // {debugBtn} - //
- // Error Message: - // "{result.errMsg}" - //
) - // setTestsOutput(prevCards => ([...prevCards, testFailCard1])) - // } else { - // const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' - // const method = result.assertMethod === 'ok' ? '' : result.assertMethod - // const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected - // const testFailCard2: any = (
highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ {result.value} - // {debugBtn} - //
- // Error Message: - // "{result.errMsg}" - // Assertion: - //
- // Expected value should be - //
{method}
- //
{preposition} {expected}
- //
- // Received value: - // {result.returned} - // Skipping the remaining tests of the function. - //
) - // setTestsOutput(prevCards => ([...prevCards, testFailCard2])) - // } - // } else if (result.type === 'logOnly') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // } + // } } - // const testCallback = (result: any, runningTests: any) => { - // console.log('result--------------in testCallback->', result) - // console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) - // if(result.filename) { - // if(!testsResultByFilename[result.filename]) { - // testsResultByFilename[result.filename] = {} - // testsResultByFilename[result.filename][contract]['tests'] = [] - // testsResultByFilename[result.filename]['summary'] = {} - // } - // testsResultByFilename[result.filename]['tests'].push(result) - // } - // } - const testCallback = (result: any, runningTests: any) => { console.log('result--------------in testCallback->', result) console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) @@ -407,91 +385,6 @@ export const SolidityUnitTesting = (props: any) => { testsResultByFilename[result.filename][result.context].push(result) showTestsResult() } - // let debugBtn - // if ((result.type === 'testPass' || result.type === 'testFailure') && result.debugTxHash) { - // const { web3, debugTxHash } = result - // debugBtn = ( - //
startDebug(debugTxHash, web3)}> - // - //
- // ) - // } - // if (result.type === 'contract') { - // var testSuite = result.value - // if (testSuites) { - // testSuites.push(testSuite) - // } else { - // testSuites = [testSuite] - // } - // runningTestFileName = cleanFileName(result.filename, testSuite) - // const ContractCard: any = ( - //
- // {testSuite} ({result.filename}) - //
- // ) - // setTestsOutput(prevCards => ([...prevCards, ContractCard])) - // } else if (result.type === 'testPass') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // const testPassCard: any = ( - //
discardHighlight()} - // > - //
- // ✓ {result.value} - // {debugBtn} - //
- //
- // ) - // setTestsOutput(prevCards => ([...prevCards, testPassCard])) - // } else if (result.type === 'testFailure') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // if (!result.assertMethod) { - // const testFailCard1: any = (
highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ {result.value} - // {debugBtn} - //
- // Error Message: - // "{result.errMsg}" - //
) - // setTestsOutput(prevCards => ([...prevCards, testFailCard1])) - // } else { - // const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' - // const method = result.assertMethod === 'ok' ? '' : result.assertMethod - // const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected - // const testFailCard2: any = (
highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ {result.value} - // {debugBtn} - //
- // Error Message: - // "{result.errMsg}" - // Assertion: - //
- // Expected value should be - //
{method}
- //
{preposition} {expected}
- //
- // Received value: - // {result.returned} - // Skipping the remaining tests of the function. - //
) - // setTestsOutput(prevCards => ([...prevCards, testFailCard2])) - // } - // } else if (result.type === 'logOnly') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // } } const resultsCallback = (_err: any, result: any, cb: any) => { From 3b5773aa31efea9f44375082603c045db976568b Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 10 Dec 2021 19:30:37 +0530 Subject: [PATCH 056/103] highlight location --- .../src/lib/solidity-unit-testing.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 8c1dc8e2c6..f8c2f2a4d3 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 @@ -233,6 +233,8 @@ export const SolidityUnitTesting = (props: any) => { } const highlightLocation = async (location: any, runningTests: any, fileName: any) => { + console.log('Inside highlightLocation---runningTests-->', runningTests) + console.log('Inside highlightLocation---fileName-->', fileName) if (location) { var split = location.split(':') var file = split[2] @@ -250,7 +252,8 @@ export const SolidityUnitTesting = (props: any) => { } } - const showTestsResult = () => { + const showTestsResult = (runningTests: any) => { + console.log('runningTests---->', runningTests) setTestsOutput([]) let filenames = Object.keys(testsResultByFilename) for(const filename of filenames) { @@ -284,6 +287,7 @@ export const SolidityUnitTesting = (props: any) => { setTestsOutput(prevCards => ([...prevCards, ContractCard])) // show tests for(const test of tests) { + console.log('test---->', test) if (test.type === 'testPass') { if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) const testPassCard: any = ( @@ -306,7 +310,7 @@ export const SolidityUnitTesting = (props: any) => { const testFailCard1: any = (
highlightLocation(test.location, runningTests, test.filename)} + onClick={() => highlightLocation(test.location, runningTests, test.filename)} >
✘ {test.value} @@ -322,8 +326,8 @@ export const SolidityUnitTesting = (props: any) => { const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected const testFailCard2: any = (
highlightLocation(result.location, runningTests, result.filename)} + id={"UTContext" + test.context} + onClick={() => highlightLocation(test.location, runningTests, test.filename)} >
✘ {test.value} @@ -383,7 +387,7 @@ export const SolidityUnitTesting = (props: any) => { testsResultByFilename[result.filename][result.value] = [] } else testsResultByFilename[result.filename][result.context].push(result) - showTestsResult() + showTestsResult(runningTests) } } From eb0bea722d249a79e93d0600971e6ab480b4ed6e Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 13 Dec 2021 17:21:43 +0530 Subject: [PATCH 057/103] tests summary --- .../src/lib/solidity-unit-testing.tsx | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) 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 f8c2f2a4d3..1b3dc4d804 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 @@ -62,6 +62,7 @@ export const SolidityUnitTesting = (props: any) => { let testSuite: any let testSuites: any let runningTestFileName: any + let runningTests: any @@ -252,7 +253,7 @@ export const SolidityUnitTesting = (props: any) => { } } - const showTestsResult = (runningTests: any) => { + const showTestsResult = () => { console.log('runningTests---->', runningTests) setTestsOutput([]) let filenames = Object.keys(testsResultByFilename) @@ -289,7 +290,7 @@ export const SolidityUnitTesting = (props: any) => { for(const test of tests) { console.log('test---->', test) if (test.type === 'testPass') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + // if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) const testPassCard: any = (
{ } } else { // show only contract and file name - const ContractCard: any = ( + const contractCard: any = (
{contract} ({filename})
) - setTestsOutput(prevCards => ([...prevCards, ContractCard])) + setTestsOutput(prevCards => ([...prevCards, contractCard])) } } } - // show testsSummary + // show summary + const testSummary = fileTestsResult['summary'] + if (testSummary && testSummary.filename) { + const summaryCard: any = (
+ Result for {testSummary.filename} + Passed: {testSummary.passed} + Failed: {testSummary.failed} + Time Taken: {testSummary.timeTaken}s +
) + setTestsOutput(prevCards => ([...prevCards, summaryCard])) + } } // let debugBtn // if ((result.type === 'testPass' || result.type === 'testFailure') && result.debugTxHash) { @@ -378,6 +389,7 @@ export const SolidityUnitTesting = (props: any) => { const testCallback = (result: any, runningTests: any) => { console.log('result--------------in testCallback->', result) console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) + runningTests = runningTests if(result.filename) { if(!testsResultByFilename[result.filename]) { testsResultByFilename[result.filename] = {} @@ -387,7 +399,7 @@ export const SolidityUnitTesting = (props: any) => { testsResultByFilename[result.filename][result.value] = [] } else testsResultByFilename[result.filename][result.context].push(result) - showTestsResult(runningTests) + showTestsResult() } } @@ -422,6 +434,7 @@ export const SolidityUnitTesting = (props: any) => { const totalTime = parseFloat(result.totalTime).toFixed(2) testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime } testsResultByFilename[filename]['summary']= testsSummary + showTestsResult() // setTestsSummary(testsSummary) } // fix for displaying right label for multiple tests (testsuites) in a single file From 91d52c9dc95c866e1f657a66bf86affc33c86e07 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 14 Dec 2021 16:46:50 +0530 Subject: [PATCH 058/103] debug button --- .../src/lib/solidity-unit-testing.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 1b3dc4d804..d2bc2b1767 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 @@ -289,6 +289,15 @@ export const SolidityUnitTesting = (props: any) => { // show tests for(const test of tests) { console.log('test---->', test) + let debugBtn + if (test.debugTxHash) { + const { web3, debugTxHash } = test + debugBtn = ( +
startDebug(debugTxHash, web3)}> + +
+ ) + } if (test.type === 'testPass') { // if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) const testPassCard: any = ( @@ -300,7 +309,7 @@ export const SolidityUnitTesting = (props: any) => { >
✓ {test.value} - {/* {debugBtn} */} + {debugBtn}
) @@ -315,7 +324,7 @@ export const SolidityUnitTesting = (props: any) => { >
✘ {test.value} - {/* {debugBtn} */} + {debugBtn}
Error Message: "{test.errMsg}" @@ -332,7 +341,7 @@ export const SolidityUnitTesting = (props: any) => { >
✘ {test.value} - {/* {debugBtn} */} + {debugBtn}
Error Message: "{test.errMsg}" @@ -374,16 +383,7 @@ export const SolidityUnitTesting = (props: any) => {
) setTestsOutput(prevCards => ([...prevCards, summaryCard])) } - } - // let debugBtn - // if ((result.type === 'testPass' || result.type === 'testFailure') && result.debugTxHash) { - // const { web3, debugTxHash } = result - // debugBtn = ( - //
startDebug(debugTxHash, web3)}> - // - //
- // ) - // } + } } const testCallback = (result: any, runningTests: any) => { From 45f074855c9932214d05f3bd9f86a1a06f25a0cd Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 15 Dec 2021 13:13:45 +0530 Subject: [PATCH 059/103] print hardhat logs --- .../solidity-unit-testing/src/lib/solidity-unit-testing.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 d2bc2b1767..4e6ce3f920 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 @@ -299,7 +299,7 @@ export const SolidityUnitTesting = (props: any) => { ) } if (test.type === 'testPass') { - // if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) const testPassCard: any = (
{ ) setTestsOutput(prevCards => ([...prevCards, testPassCard])) } else if (test.type === 'testFailure') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) if (!test.assertMethod) { const testFailCard1: any = (
{ setTestsOutput(prevCards => ([...prevCards, testFailCard2])) } } else if (test.type === 'logOnly') { - // if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) } } } else { From 8ebb852df3a7771202f850bfae105765289fea52 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 15 Dec 2021 17:48:29 +0530 Subject: [PATCH 060/103] render a test only once --- .../src/lib/solidity-unit-testing.tsx | 159 ++++++++++-------- 1 file changed, 86 insertions(+), 73 deletions(-) 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 4e6ce3f920..9095fe1c36 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 @@ -37,7 +37,7 @@ export const SolidityUnitTesting = (props: any) => { const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsOutput, setTestsOutput] = useState([]) - let [testsSummary, setTestsSummary] = useState() + // let [testsSummary, setTestsSummary] = useState() const [testsSummaryHidden, setTestsSummaryHidden] = useState('hidden') const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) @@ -255,7 +255,7 @@ export const SolidityUnitTesting = (props: any) => { const showTestsResult = () => { console.log('runningTests---->', runningTests) - setTestsOutput([]) + // setTestsOutput([]) let filenames = Object.keys(testsResultByFilename) for(const filename of filenames) { const fileTestsResult = testsResultByFilename[filename] @@ -285,81 +285,90 @@ export const SolidityUnitTesting = (props: any) => { {label}{contract} ({filename})
) - setTestsOutput(prevCards => ([...prevCards, ContractCard])) + setTestsOutput(prevCards => { + const index = prevCards.findIndex((card: any) => card.props.id === runningTestFileName) + prevCards[index] = ContractCard + return prevCards + }) // show tests for(const test of tests) { console.log('test---->', test) - let debugBtn - if (test.debugTxHash) { - const { web3, debugTxHash } = test - debugBtn = ( -
startDebug(debugTxHash, web3)}> - -
- ) - } - if (test.type === 'testPass') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - const testPassCard: any = ( -
discardHighlight()} - > -
- ✓ {test.value} - {debugBtn} -
+ if(!test.rendered) { + let debugBtn + if (test.debugTxHash) { + const { web3, debugTxHash } = test + debugBtn = ( +
startDebug(debugTxHash, web3)}> +
- ) - setTestsOutput(prevCards => ([...prevCards, testPassCard])) - } else if (test.type === 'testFailure') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - if (!test.assertMethod) { - const testFailCard1: any = (
highlightLocation(test.location, runningTests, test.filename)} - > -
- ✘ {test.value} - {debugBtn} -
- Error Message: - "{test.errMsg}" -
) - setTestsOutput(prevCards => ([...prevCards, testFailCard1])) - } else { - const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' - const method = test.assertMethod === 'ok' ? '' : test.assertMethod - const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected - const testFailCard2: any = (
highlightLocation(test.location, runningTests, test.filename)} - > -
- ✘ {test.value} + ) + } + if (test.type === 'testPass') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + const testPassCard: any = ( +
discardHighlight()} + > +
+ ✓ {test.value} {debugBtn} -
- Error Message: - "{test.errMsg}" - Assertion: -
- Expected value should be -
{method}
-
{preposition} {expected}
- Received value: - {test.returned} - Skipping the remaining tests of the function. -
) - setTestsOutput(prevCards => ([...prevCards, testFailCard2])) +
+ ) + setTestsOutput(prevCards => ([...prevCards, testPassCard])) + test.rendered = true + } else if (test.type === 'testFailure') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + if (!test.assertMethod) { + const testFailCard1: any = (
highlightLocation(test.location, runningTests, test.filename)} + > +
+ ✘ {test.value} + {debugBtn} +
+ Error Message: + "{test.errMsg}" +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard1])) + } else { + const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' + const method = test.assertMethod === 'ok' ? '' : test.assertMethod + const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected + const testFailCard2: any = (
highlightLocation(test.location, runningTests, test.filename)} + > +
+ ✘ {test.value} + {debugBtn} +
+ Error Message: + "{test.errMsg}" + Assertion: +
+ Expected value should be +
{method}
+
{preposition} {expected}
+
+ Received value: + {test.returned} + Skipping the remaining tests of the function. +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard2])) + } + test.rendered = true + } else if (test.type === 'logOnly') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + test.rendered = true } - } else if (test.type === 'logOnly') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - } + } } } else { // show only contract and file name @@ -374,7 +383,7 @@ export const SolidityUnitTesting = (props: any) => { } // show summary const testSummary = fileTestsResult['summary'] - if (testSummary && testSummary.filename) { + if (testSummary && testSummary.filename && !testSummary.rendered) { const summaryCard: any = (
Result for {testSummary.filename} Passed: {testSummary.passed} @@ -382,6 +391,7 @@ export const SolidityUnitTesting = (props: any) => { Time Taken: {testSummary.timeTaken}s
) setTestsOutput(prevCards => ([...prevCards, summaryCard])) + fileTestsResult['summary']['rendered'] = true } } } @@ -397,8 +407,11 @@ export const SolidityUnitTesting = (props: any) => { } if(result.type === 'contract') { testsResultByFilename[result.filename][result.value] = [] - } else + } else { + // Set that this test is not rendered on UI + result.rendered = false testsResultByFilename[result.filename][result.context].push(result) + } showTestsResult() } } @@ -432,7 +445,7 @@ export const SolidityUnitTesting = (props: any) => { // yo.update(this.resultStatistics, this.createResultLabel()) if (result) { const totalTime = parseFloat(result.totalTime).toFixed(2) - testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime } + const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } testsResultByFilename[filename]['summary']= testsSummary showTestsResult() // setTestsSummary(testsSummary) From 25b49c58d48965ae8a888011b1107f939237796d Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 15 Dec 2021 18:45:09 +0530 Subject: [PATCH 061/103] fixing runningTests --- .../src/lib/solidity-unit-testing.tsx | 65 ++++--------------- 1 file changed, 11 insertions(+), 54 deletions(-) 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 9095fe1c36..8faa53f428 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 @@ -14,13 +14,6 @@ interface TestObject { checked: boolean } -interface TestSummary { - filename: string - passed: number - failed: number - timeTaken: any -} - export const SolidityUnitTesting = (props: any) => { const {helper, testTab} = props @@ -37,16 +30,12 @@ export const SolidityUnitTesting = (props: any) => { const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsOutput, setTestsOutput] = useState([]) - // let [testsSummary, setTestsSummary] = useState() - const [testsSummaryHidden, setTestsSummaryHidden] = useState('hidden') const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) - let [testFiles, setTestFiles] = useState([]) const [pathOptions, setPathOptions] = useState(['']) - // let [allTests, setAllTests] = useState([]) let [selectedTests, setSelectedTests] = useState([]) const [inputPathValue, setInputPathValue] = useState('tests') @@ -58,16 +47,11 @@ export const SolidityUnitTesting = (props: any) => { let [isDebugging, setIsDebugging] = useState(false) let allTests: any = [] - - let testSuite: any - let testSuites: any - let runningTestFileName: any - let runningTests: any - - + let runningTestFileName: any + let runningTests: any = {} - let [testsResultByFilename, setTestsResultByFilename] = useState>({}) + let testsResultByFilename:Record = {} const trimTestDirInput = (input:string) => { if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') @@ -127,10 +111,7 @@ export const SolidityUnitTesting = (props: any) => { } const handleTestDirInput = async (e: any) => { - console.log('handleTestDirInput--e-->', e.target) - let testDirInput = trimTestDirInput(e.target.value) - console.log('handleTestDirInput--e-->', testDirInput) testDirInput = helper.removeMultipleSlashes(testDirInput) if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput) setInputPathValue(testDirInput) @@ -169,7 +150,6 @@ export const SolidityUnitTesting = (props: any) => { } const handleEnter = async(e:any) => { - console.log('handleEnter --e-->', e) let inputPath = e.target.value inputPath = helper.removeMultipleSlashes(trimTestDirInput(inputPath)) setInputPathValue(inputPath) @@ -191,8 +171,6 @@ export const SolidityUnitTesting = (props: any) => { setDisableCreateButton(true) setDisableGenerateButton(false) testTabLogic.setCurrentPath(inputPath) - console.log('path-->', path) - console.log('inputPath-->', inputPath) updateRunAction() updateForNewCurrent() pathOptions.push(inputPath) @@ -233,9 +211,10 @@ export const SolidityUnitTesting = (props: any) => { await testTab.call('editor', 'discardHighlight') } - const highlightLocation = async (location: any, runningTests: any, fileName: any) => { + const highlightLocation = async (location: any, fileName: any) => { console.log('Inside highlightLocation---runningTests-->', runningTests) console.log('Inside highlightLocation---fileName-->', fileName) + console.log('Inside highlightLocation---location-->', location) if (location) { var split = location.split(':') var file = split[2] @@ -255,7 +234,6 @@ export const SolidityUnitTesting = (props: any) => { const showTestsResult = () => { console.log('runningTests---->', runningTests) - // setTestsOutput([]) let filenames = Object.keys(testsResultByFilename) for(const filename of filenames) { const fileTestsResult = testsResultByFilename[filename] @@ -292,7 +270,6 @@ export const SolidityUnitTesting = (props: any) => { }) // show tests for(const test of tests) { - console.log('test---->', test) if(!test.rendered) { let debugBtn if (test.debugTxHash) { @@ -326,7 +303,7 @@ export const SolidityUnitTesting = (props: any) => { const testFailCard1: any = (
highlightLocation(test.location, runningTests, test.filename)} + onClick={() => highlightLocation(test.location, test.filename)} >
✘ {test.value} @@ -343,7 +320,7 @@ export const SolidityUnitTesting = (props: any) => { const testFailCard2: any = (
highlightLocation(test.location, runningTests, test.filename)} + onClick={() => highlightLocation(test.location, test.filename)} >
✘ {test.value} @@ -396,10 +373,9 @@ export const SolidityUnitTesting = (props: any) => { } } - const testCallback = (result: any, runningTests: any) => { + const testCallback = (result: any) => { console.log('result--------------in testCallback->', result) console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) - runningTests = runningTests if(result.filename) { if(!testsResultByFilename[result.filename]) { testsResultByFilename[result.filename] = {} @@ -428,7 +404,6 @@ export const SolidityUnitTesting = (props: any) => { console.log('result---------------------------in updateFinalResult->', result, filename) console.log('testsResultByFilename---------------------------in updateFinalResult->', testsResultByFilename) ++readyTestsNumber - setTestsSummaryHidden('visible') // if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { // this.testCallback({ type: 'contract', filename }) // this.currentErrors = _errors.errors @@ -448,15 +423,7 @@ export const SolidityUnitTesting = (props: any) => { const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } testsResultByFilename[filename]['summary']= testsSummary showTestsResult() - // setTestsSummary(testsSummary) } - // fix for displaying right label for multiple tests (testsuites) in a single file - // this.testSuites.forEach(testSuite => { - // this.testSuite = testSuite - // this.runningTestFileName = this.cleanFileName(filename, this.testSuite) - // this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) - // this.setHeader(true) - // }) // result.errors.forEach((error, index) => { // this.testSuite = error.context @@ -499,7 +466,7 @@ export const SolidityUnitTesting = (props: any) => { } // this.resultStatistics.hidden = false testTab.fileManager.readFile(testFilePath).then((content: any) => { - const runningTests: any = {} + runningTests = {} runningTests[testFilePath] = { content } const { currentVersion, evmVersion, optimize, runs, isUrl } = testTab.compileTab.getCurrentCompilerConfig() const currentCompilerUrl = isUrl ? currentVersion : urlFromVersion(currentVersion) @@ -517,7 +484,7 @@ export const SolidityUnitTesting = (props: any) => { testTab.testRunner.runTestSources( runningTests, compilerConfig, - (result: any) => testCallback(result, runningTests), + (result: any) => testCallback(result), (_err: any, result: any, cb: any) => resultsCallback(_err, result, cb), deployCb, (error: any, result: any) => { @@ -528,7 +495,7 @@ export const SolidityUnitTesting = (props: any) => { }, { testFilePath } ) }).catch((error: any) => { - console.log('Error in runTest---->', error) + console.log(error) if (error) return // eslint-disable-line }) } @@ -555,7 +522,6 @@ export const SolidityUnitTesting = (props: any) => { } const updateRunAction = (currentFile : any = null) => { - console.log('updateRunAction --currentFile-->', currentFile) const isSolidityActive = testTab.appManager.isActive('solidity') if (!isSolidityActive || !selectedTests?.length) { setDisableRunButton(true) @@ -568,7 +534,6 @@ export const SolidityUnitTesting = (props: any) => { } const stopTests = () => { - console.log('stopTests') setHasBeenStopped(true) setStopButtonLabel('Stopping') setDisableStopButton(true) @@ -584,7 +549,6 @@ export const SolidityUnitTesting = (props: any) => { testFiles[index].checked = eChecked setTestFiles(testFiles) selectedTests = getCurrentSelectedTests() - console.log('selectedTests----->', selectedTests) setSelectedTests(selectedTests) if (eChecked) { setCheckSelectAll(true) @@ -614,7 +578,6 @@ export const SolidityUnitTesting = (props: any) => { } const updateTestFileList = () => { - console.log('updateTestFileList--tests->', allTests) if(allTests?.length) { testFiles = allTests.map((testFile: any) => { return {'fileName': testFile, 'checked': true }}) setCheckSelectAll(true) @@ -727,12 +690,6 @@ export const SolidityUnitTesting = (props: any) => {
{testsOutput}
- {/*
- {testsSummary && testsSummary.filename ? `Result for ${testsSummary.filename}` : ''} - {testsSummary && testsSummary.passed >= 0 ? `Passed: ${testsSummary.passed}` : ''} - {testsSummary && testsSummary.failed >= 0 ? `Failed: ${testsSummary.failed}` : ''} - {testsSummary && testsSummary.timeTaken ? `Time Taken: ${testsSummary.timeTaken}` : ''} -
*/}
) From eb6cb8e3b9df34e003d9b07c41a9b8a375d91049 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 15 Dec 2021 20:20:50 +0530 Subject: [PATCH 062/103] handle files content --- .../src/lib/solidity-unit-testing.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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 8faa53f428..d8e66594c3 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 @@ -49,7 +49,7 @@ export const SolidityUnitTesting = (props: any) => { let allTests: any = [] let runningTestFileName: any - let runningTests: any = {} + let filesContent: any = {} let testsResultByFilename:Record = {} @@ -212,9 +212,6 @@ export const SolidityUnitTesting = (props: any) => { } const highlightLocation = async (location: any, fileName: any) => { - console.log('Inside highlightLocation---runningTests-->', runningTests) - console.log('Inside highlightLocation---fileName-->', fileName) - console.log('Inside highlightLocation---location-->', location) if (location) { var split = location.split(':') var file = split[2] @@ -225,7 +222,7 @@ export const SolidityUnitTesting = (props: any) => { location = testTab.offsetToLineColumnConverter.offsetToLineColumnWithContent( location, parseInt(file), - runningTests[fileName].content + filesContent[fileName].content ) await testTab.call('editor', 'discardHighlight') await testTab.call('editor', 'highlight', location, fileName, '', { focus: true }) @@ -233,7 +230,7 @@ export const SolidityUnitTesting = (props: any) => { } const showTestsResult = () => { - console.log('runningTests---->', runningTests) + console.log('filesContent---->', filesContent) let filenames = Object.keys(testsResultByFilename) for(const filename of filenames) { const fileTestsResult = testsResultByFilename[filename] @@ -466,8 +463,9 @@ export const SolidityUnitTesting = (props: any) => { } // this.resultStatistics.hidden = false testTab.fileManager.readFile(testFilePath).then((content: any) => { - runningTests = {} + const runningTests: any = {} runningTests[testFilePath] = { content } + filesContent[testFilePath] = { content } const { currentVersion, evmVersion, optimize, runs, isUrl } = testTab.compileTab.getCurrentCompilerConfig() const currentCompilerUrl = isUrl ? currentVersion : urlFromVersion(currentVersion) const compilerConfig = { From 3976ee3dc4bdd386a8a8c2b586c06a3b56f0d85c Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 16 Dec 2021 13:49:29 +0530 Subject: [PATCH 063/103] progress bar --- .../src/lib/solidity-unit-testing.tsx | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) 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 d8e66594c3..5f1bf15bf1 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 @@ -32,6 +32,7 @@ export const SolidityUnitTesting = (props: any) => { const [testsOutput, setTestsOutput] = useState([]) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) + const [progressBarHidden, setProgressBarHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) let [testFiles, setTestFiles] = useState([]) @@ -60,7 +61,7 @@ export const SolidityUnitTesting = (props: any) => { const clearResults = () => { console.log('clearResults--->') - // yo.update(this.resultStatistics, yo``) + setProgressBarHidden(true) testTab.call('editor', 'clearAnnotations') setTestsOutput([]) setTestsExecutionStoppedHidden(true) @@ -401,6 +402,7 @@ export const SolidityUnitTesting = (props: any) => { console.log('result---------------------------in updateFinalResult->', result, filename) console.log('testsResultByFilename---------------------------in updateFinalResult->', testsResultByFilename) ++readyTestsNumber + setReadyTestsNumber(readyTestsNumber) // if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { // this.testCallback({ type: 'contract', filename }) // this.currentErrors = _errors.errors @@ -414,7 +416,6 @@ export const SolidityUnitTesting = (props: any) => { // // To track error like this: https://github.com/ethereum/remix/pull/1438 // this.renderer.error(_errors.formattedMessage || _errors.message, this.testsOutput, { type: 'error' }) // } - // yo.update(this.resultStatistics, this.createResultLabel()) if (result) { const totalTime = parseFloat(result.totalTime).toFixed(2) const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } @@ -461,7 +462,6 @@ export const SolidityUnitTesting = (props: any) => { // this.updateFinalResult() return } - // this.resultStatistics.hidden = false testTab.fileManager.readFile(testFilePath).then((content: any) => { const runningTests: any = {} runningTests[testFilePath] = { content } @@ -503,15 +503,16 @@ export const SolidityUnitTesting = (props: any) => { areTestsRunning = true hasBeenStopped = false readyTestsNumber = 0 + setReadyTestsNumber(readyTestsNumber) runningTestsNumber = selectedTests.length + setRunningTestsNumber(runningTestsNumber) setDisableStopButton(false) - // setDisableRunButton(true) clearResults() - // yo.update(this.resultStatistics, this.createResultLabel()) + setProgressBarHidden(false) const tests = selectedTests console.log('tests--in runTests----------------->', tests) - if (!tests) return - // this.resultStatistics.hidden = tests.length === 0 + if (!tests || !tests.length) return + else setProgressBarHidden(false) // _paq.push(['trackEvent', 'solidityUnitTesting', 'runTests']) async.eachOfSeries(tests, (value: any, key: any, callback: any) => { if (hasBeenStopped) return @@ -585,15 +586,6 @@ export const SolidityUnitTesting = (props: any) => { setTestFiles(testFiles) } - const createResultLabel = () => { - return (Progress: none finished (of none)) - // if (!this.data.selectedTests) return yo`` - // const ready = this.readyTestsNumber ? `${this.readyTestsNumber}` : '0' - // return yo`Progress: ${ready} finished (of ${this.runningTestsNumber})` - } - - const [resultStatistics] = useState(createResultLabel()) - return (
@@ -683,7 +675,7 @@ export const SolidityUnitTesting = (props: any) => { }) : "No test file available" }
- {resultStatistics} +
From 80a0f27d17fcd0fd88de5e34cc9e651050cf9e1c Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 16 Dec 2021 19:30:47 +0530 Subject: [PATCH 064/103] code clean --- apps/remix-ide/src/app/tabs/test-tab.js | 56 ------------------------- 1 file changed, 56 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index a87cd7c0f9..1267b585aa 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -196,62 +196,6 @@ module.exports = class TestTab extends ViewPlugin { ) } - toggleCheckbox (eChecked, test) { - if (!this.data.selectedTests) { - this.data.selectedTests = this._view.el.querySelectorAll('.singleTest:checked') - } - let selectedTests = this.data.selectedTests - selectedTests = eChecked ? [...selectedTests, test] : selectedTests.filter(el => el !== test) - this.data.selectedTests = selectedTests - const checkAll = this._view.el.querySelector('[id="checkAllTests"]') - const runBtn = document.getElementById('runTestsTabRunAction') - - if (eChecked) { - checkAll.checked = true - const stopBtnInnerText = document.getElementById('runTestsTabStopAction').innerText - if ((this.readyTestsNumber === this.runningTestsNumber || this.hasBeenStopped) && stopBtnInnerText.trim() === 'Stop') { - runBtn.removeAttribute('disabled') - runBtn.setAttribute('title', 'Run tests') - } - } else if (!selectedTests.length) { - checkAll.checked = false - runBtn.setAttribute('disabled', 'disabled') - runBtn.setAttribute('title', 'No test file selected') - } - } - - checkAll (event) { - const checkBoxes = this._view.el.querySelectorAll('.singleTest') - const checkboxesLabels = this._view.el.querySelectorAll('.singleTestLabel') - // checks/unchecks all - for (let i = 0; i < checkBoxes.length; i++) { - checkBoxes[i].checked = event.target.checked - this.toggleCheckbox(event.target.checked, checkboxesLabels[i].innerText) - } - } - - async discardHighlight () { - await this.call('editor', 'discardHighlight') - } - - async highlightLocation (location, runningTests, fileName) { - if (location) { - var split = location.split(':') - var file = split[2] - location = { - start: parseInt(split[0]), - length: parseInt(split[1]) - } - location = this.offsetToLineColumnConverter.offsetToLineColumnWithContent( - location, - parseInt(file), - runningTests[fileName].content - ) - await this.call('editor', 'discardHighlight') - await this.call('editor', 'highlight', location, fileName, '', { focus: true }) - } - } - async startDebug (txHash, web3) { this.isDebugging = true if (!await this.appManager.isActive('debugger')) await this.appManager.activatePlugin('debugger') From 9486a64ae512de62d12aac181e7572992b958a31 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 17 Dec 2021 10:55:05 +0530 Subject: [PATCH 065/103] generic getAppParameter in renderer --- libs/remix-ui/renderer/src/lib/renderer.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/remix-ui/renderer/src/lib/renderer.tsx b/libs/remix-ui/renderer/src/lib/renderer.tsx index eae9e0d4b0..28f03a57c6 100644 --- a/libs/remix-ui/renderer/src/lib/renderer.tsx +++ b/libs/remix-ui/renderer/src/lib/renderer.tsx @@ -1,4 +1,6 @@ import React, { useEffect, useState } from 'react' //eslint-disable-line +import QueryParams from '../../../../../apps/remix-ide/src/lib/query-params' +const registry = require('../../../../../apps/remix-ide/src/global/registry') import './renderer.css' interface RendererProps { message: any; From 9d6dee28fe4b7fc675a1d913ff65f0357e1a3fb3 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 17 Dec 2021 11:39:50 +0530 Subject: [PATCH 066/103] renderTests --- .../src/lib/solidity-unit-testing.tsx | 212 +++++++++--------- 1 file changed, 108 insertions(+), 104 deletions(-) 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 5f1bf15bf1..cb32b2fa4c 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 @@ -230,6 +230,113 @@ export const SolidityUnitTesting = (props: any) => { } } + const renderTests = (tests: any, contract: any, filename: any) => { + const index = tests.findIndex((test: any) => test.type === 'testFailure') + let label + if (index > -1) label = (
+ FAIL +
) + else label = (
+ PASS +
) + // show contract and file name with label + const ContractCard: any = ( +
+ {label}{contract} ({filename}) +
+ ) + setTestsOutput(prevCards => { + const index = prevCards.findIndex((card: any) => card.props.id === runningTestFileName) + prevCards[index] = ContractCard + return prevCards + }) + // show tests + for(const test of tests) { + if(!test.rendered) { + let debugBtn + if (test.debugTxHash) { + const { web3, debugTxHash } = test + debugBtn = ( +
startDebug(debugTxHash, web3)}> + +
+ ) + } + if (test.type === 'testPass') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + const testPassCard: any = ( +
discardHighlight()} + > +
+ ✓ {test.value} + {debugBtn} +
+
+ ) + setTestsOutput(prevCards => ([...prevCards, testPassCard])) + test.rendered = true + } else if (test.type === 'testFailure') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + if (!test.assertMethod) { + const testFailCard1: any = (
highlightLocation(test.location, test.filename)} + > +
+ ✘ {test.value} + {debugBtn} +
+ Error Message: + "{test.errMsg}" +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard1])) + } else { + const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' + const method = test.assertMethod === 'ok' ? '' : test.assertMethod + const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected + const testFailCard2: any = (
highlightLocation(test.location, test.filename)} + > +
+ ✘ {test.value} + {debugBtn} +
+ Error Message: + "{test.errMsg}" + Assertion: +
+ Expected value should be +
{method}
+
{preposition} {expected}
+
+ Received value: + {test.returned} + Skipping the remaining tests of the function. +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard2])) + } + test.rendered = true + } else if (test.type === 'logOnly') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + test.rendered = true + } + } + } + } + const showTestsResult = () => { console.log('filesContent---->', filesContent) let filenames = Object.keys(testsResultByFilename) @@ -241,110 +348,7 @@ export const SolidityUnitTesting = (props: any) => { runningTestFileName = cleanFileName(filename, contract) const tests = fileTestsResult[contract] if (tests?.length) { - const index = tests.findIndex((test: any) => test.type === 'testFailure') - let label - if (index > -1) label = (
- FAIL -
) - else label = (
- PASS -
) - // show contract and file name with label - const ContractCard: any = ( -
- {label}{contract} ({filename}) -
- ) - setTestsOutput(prevCards => { - const index = prevCards.findIndex((card: any) => card.props.id === runningTestFileName) - prevCards[index] = ContractCard - return prevCards - }) - // show tests - for(const test of tests) { - if(!test.rendered) { - let debugBtn - if (test.debugTxHash) { - const { web3, debugTxHash } = test - debugBtn = ( -
startDebug(debugTxHash, web3)}> - -
- ) - } - if (test.type === 'testPass') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - const testPassCard: any = ( -
discardHighlight()} - > -
- ✓ {test.value} - {debugBtn} -
-
- ) - setTestsOutput(prevCards => ([...prevCards, testPassCard])) - test.rendered = true - } else if (test.type === 'testFailure') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - if (!test.assertMethod) { - const testFailCard1: any = (
highlightLocation(test.location, test.filename)} - > -
- ✘ {test.value} - {debugBtn} -
- Error Message: - "{test.errMsg}" -
) - setTestsOutput(prevCards => ([...prevCards, testFailCard1])) - } else { - const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' - const method = test.assertMethod === 'ok' ? '' : test.assertMethod - const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected - const testFailCard2: any = (
highlightLocation(test.location, test.filename)} - > -
- ✘ {test.value} - {debugBtn} -
- Error Message: - "{test.errMsg}" - Assertion: -
- Expected value should be -
{method}
-
{preposition} {expected}
-
- Received value: - {test.returned} - Skipping the remaining tests of the function. -
) - setTestsOutput(prevCards => ([...prevCards, testFailCard2])) - } - test.rendered = true - } else if (test.type === 'logOnly') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - test.rendered = true - } - } - } + renderTests(tests, contract, filename) } else { // show only contract and file name const contractCard: any = ( From 0f5c8301b718e0c627d5e0afc370e983f467bbdf Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 17 Dec 2021 12:32:06 +0530 Subject: [PATCH 067/103] handle errors --- .../src/lib/solidity-unit-testing.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 cb32b2fa4c..7dc60eebaf 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 @@ -346,9 +346,11 @@ export const SolidityUnitTesting = (props: any) => { for(const contract of contracts) { if(contract && contract !== 'summary') { runningTestFileName = cleanFileName(filename, contract) - const tests = fileTestsResult[contract] + const { tests, errors} = fileTestsResult[contract] if (tests?.length) { renderTests(tests, contract, filename) + } else if (errors) { + console.log('errors---->', errors) } else { // show only contract and file name const contractCard: any = ( @@ -384,11 +386,12 @@ export const SolidityUnitTesting = (props: any) => { testsResultByFilename[result.filename]['summary'] = {} } if(result.type === 'contract') { - testsResultByFilename[result.filename][result.value] = [] + testsResultByFilename[result.filename][result.value]= {} + testsResultByFilename[result.filename][result.value].tests = [] } else { // Set that this test is not rendered on UI result.rendered = false - testsResultByFilename[result.filename][result.context].push(result) + testsResultByFilename[result.filename][result.context]['tests'].push(result) } showTestsResult() } @@ -425,7 +428,9 @@ export const SolidityUnitTesting = (props: any) => { const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } testsResultByFilename[filename]['summary']= testsSummary showTestsResult() - } + } else if (_errors) { + testsResultByFilename[filename]['errors'] = _errors + } // result.errors.forEach((error, index) => { // this.testSuite = error.context From d6abe34c88a588384b83c5e5b948f630ea636583 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 17 Dec 2021 20:38:16 +0530 Subject: [PATCH 068/103] show errors --- .../src/lib/solidity-unit-testing.tsx | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) 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 7dc60eebaf..2d0259d229 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 @@ -2,6 +2,7 @@ import React, { useState, useRef, useEffect, CSSProperties } from 'react' // esl // import { TestTabLogic } from './logic/testTabLogic' var async = require('async') import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' +import { Renderer } from '@remix-ui/renderer' // eslint-disable-line import { format } from 'util' import './css/style.css' @@ -344,13 +345,11 @@ export const SolidityUnitTesting = (props: any) => { const fileTestsResult = testsResultByFilename[filename] const contracts = Object.keys(fileTestsResult) for(const contract of contracts) { - if(contract && contract !== 'summary') { + if(contract && contract !== 'summary' && contract !== 'errors') { runningTestFileName = cleanFileName(filename, contract) - const { tests, errors} = fileTestsResult[contract] + const tests = fileTestsResult[contract] if (tests?.length) { renderTests(tests, contract, filename) - } else if (errors) { - console.log('errors---->', errors) } else { // show only contract and file name const contractCard: any = ( @@ -360,6 +359,24 @@ export const SolidityUnitTesting = (props: any) => { ) setTestsOutput(prevCards => ([...prevCards, contractCard])) } + } else if (contract === 'errors' && fileTestsResult['errors']) { + const errors = fileTestsResult['errors'] + console.log('errors---->', errors) + if (errors && errors.errors) { + errors.errors.forEach((err: any) => { + const errorCard: any = + setTestsOutput(prevCards => ([...prevCards, errorCard])) + }) + } else if (errors && Array.isArray(errors) && (errors[0].message || errors[0].formattedMessage)) { + errors.forEach((err) => { + const errorCard: any = + setTestsOutput(prevCards => ([...prevCards, errorCard])) + }) + } else if (errors && !errors.errors && !Array.isArray(errors)) { + // To track error like this: https://github.com/ethereum/remix/pull/1438 + const errorCard: any = + setTestsOutput(prevCards => ([...prevCards, errorCard])) + } } } // show summary @@ -387,11 +404,11 @@ export const SolidityUnitTesting = (props: any) => { } if(result.type === 'contract') { testsResultByFilename[result.filename][result.value]= {} - testsResultByFilename[result.filename][result.value].tests = [] + testsResultByFilename[result.filename][result.value] = [] } else { // Set that this test is not rendered on UI result.rendered = false - testsResultByFilename[result.filename][result.context]['tests'].push(result) + testsResultByFilename[result.filename][result.context].push(result) } showTestsResult() } @@ -429,7 +446,11 @@ export const SolidityUnitTesting = (props: any) => { testsResultByFilename[filename]['summary']= testsSummary showTestsResult() } else if (_errors) { + if(!testsResultByFilename[filename]) { + testsResultByFilename[filename] = {} + } testsResultByFilename[filename]['errors'] = _errors + showTestsResult() } // result.errors.forEach((error, index) => { From be834f77458e3e4bd09836178385f4a441bbf33b Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 22 Dec 2021 13:03:21 +0530 Subject: [PATCH 069/103] renderer linting fix --- libs/remix-ui/renderer/src/lib/renderer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/renderer/src/lib/renderer.tsx b/libs/remix-ui/renderer/src/lib/renderer.tsx index 28f03a57c6..c2540af801 100644 --- a/libs/remix-ui/renderer/src/lib/renderer.tsx +++ b/libs/remix-ui/renderer/src/lib/renderer.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react' //eslint-disable-line import QueryParams from '../../../../../apps/remix-ide/src/lib/query-params' -const registry = require('../../../../../apps/remix-ide/src/global/registry') import './renderer.css' +const registry = require('../../../../../apps/remix-ide/src/global/registry') interface RendererProps { message: any; opt?: any, From a1d096f0d5c0714392bdf2c3051014c98c19aaa4 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 22 Dec 2021 18:56:20 +0530 Subject: [PATCH 070/103] compilation error handling --- .../src/lib/solidity-unit-testing.tsx | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) 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 2d0259d229..ac81ab2fb5 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 @@ -49,6 +49,7 @@ export const SolidityUnitTesting = (props: any) => { let [isDebugging, setIsDebugging] = useState(false) let allTests: any = [] + let currentErrors: any let runningTestFileName: any let filesContent: any = {} @@ -233,7 +234,11 @@ export const SolidityUnitTesting = (props: any) => { const renderTests = (tests: any, contract: any, filename: any) => { const index = tests.findIndex((test: any) => test.type === 'testFailure') - let label + let label = (
+ Unknown +
) if (index > -1) label = (
{ // show only contract and file name const contractCard: any = (
- {contract} ({filename}) + {contract ? contract: ''} ({filename})
) setTestsOutput(prevCards => ([...prevCards, contractCard])) @@ -396,7 +401,6 @@ export const SolidityUnitTesting = (props: any) => { const testCallback = (result: any) => { console.log('result--------------in testCallback->', result) - console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) if(result.filename) { if(!testsResultByFilename[result.filename]) { testsResultByFilename[result.filename] = {} @@ -410,6 +414,7 @@ export const SolidityUnitTesting = (props: any) => { result.rendered = false testsResultByFilename[result.filename][result.context].push(result) } + console.log('testsResultByFilename--------============------in testCallback END---====->', testsResultByFilename) showTestsResult() } } @@ -427,19 +432,17 @@ export const SolidityUnitTesting = (props: any) => { console.log('testsResultByFilename---------------------------in updateFinalResult->', testsResultByFilename) ++readyTestsNumber setReadyTestsNumber(readyTestsNumber) - // if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { - // this.testCallback({ type: 'contract', filename }) - // this.currentErrors = _errors.errors - // this.setHeader(false) - // } - // if (_errors && _errors.errors) { - // _errors.errors.forEach((err) => this.renderer.error(err.formattedMessage || err.message, this.testsOutput, { type: err.severity, errorType: err.type })) - // } else if (_errors && Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage)) { - // _errors.forEach((err) => this.renderer.error(err.formattedMessage || err.message, this.testsOutput, { type: err.severity, errorType: err.type })) - // } else if (_errors && !_errors.errors && !Array.isArray(_errors)) { - // // To track error like this: https://github.com/ethereum/remix/pull/1438 - // this.renderer.error(_errors.formattedMessage || _errors.message, this.testsOutput, { type: 'error' }) - // } + if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { + // testCallback({ type: 'contract', filename }) + const contractCard: any = ( +
+ ({filename}) +
+ ) + setTestsOutput(prevCards => ([...prevCards, contractCard])) + currentErrors = _errors.errors + // this.setHeader(false) + } if (result) { const totalTime = parseFloat(result.totalTime).toFixed(2) const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } @@ -450,27 +453,14 @@ export const SolidityUnitTesting = (props: any) => { testsResultByFilename[filename] = {} } testsResultByFilename[filename]['errors'] = _errors + setTestsExecutionStoppedErrorHidden(false) showTestsResult() } - - // result.errors.forEach((error, index) => { - // this.testSuite = error.context - // this.runningTestFileName = this.cleanFileName(filename, error.context) - // this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) - // const isFailingLabel = document.querySelector(`.failed_${this.runningTestFileName}`) - // if (!isFailingLabel) this.setHeader(false) - // }) - // this.testsOutput.appendChild(yo` - //
- //

- //
- // `) - // } - // if (this.hasBeenStopped && (this.readyTestsNumber !== this.runningTestsNumber)) { - // // if all tests has been through before stopping no need to print this. - // this.testsExecutionStopped.hidden = false - // } - // if (_errors) this.testsExecutionStoppedError.hidden = false + + if (hasBeenStopped && (readyTestsNumber !== runningTestsNumber)) { + // if all tests has been through before stopping no need to print this. + setTestsExecutionStoppedHidden(false) + } // if (_errors || this.hasBeenStopped || this.readyTestsNumber === this.runningTestsNumber) { // // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files. // const stopBtn = document.getElementById('runTestsTabStopAction') From 5402ea94e7aafce3ab94941fd2483606366daa34 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 22 Dec 2021 19:19:14 +0530 Subject: [PATCH 071/103] renderContract --- .../src/lib/solidity-unit-testing.tsx | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) 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 ac81ab2fb5..d2d9ebded2 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 @@ -232,21 +232,25 @@ export const SolidityUnitTesting = (props: any) => { } } - const renderTests = (tests: any, contract: any, filename: any) => { - const index = tests.findIndex((test: any) => test.type === 'testFailure') - let label = (
- Unknown -
) + const renderContract = (filename: any, contract: any, index: number, withoutLabel = false) => { + if (withoutLabel) { + const contractCard: any = ( +
+ {contract ? contract: ''} ({filename}) +
+ ) + setTestsOutput(prevCards => ([...prevCards, contractCard])) + return + } + let label if (index > -1) label = (
FAIL
) else label = (
PASS @@ -262,6 +266,12 @@ export const SolidityUnitTesting = (props: any) => { prevCards[index] = ContractCard return prevCards }) + } + + const renderTests = (tests: any, contract: any, filename: any) => { + const index = tests.findIndex((test: any) => test.type === 'testFailure') + // show filename and contract + renderContract(filename, contract, index) // show tests for(const test of tests) { if(!test.rendered) { @@ -357,12 +367,7 @@ export const SolidityUnitTesting = (props: any) => { renderTests(tests, contract, filename) } else { // show only contract and file name - const contractCard: any = ( -
- {contract ? contract: ''} ({filename}) -
- ) - setTestsOutput(prevCards => ([...prevCards, contractCard])) + renderContract(filename, contract, -1, true) } } else if (contract === 'errors' && fileTestsResult['errors']) { const errors = fileTestsResult['errors'] @@ -433,13 +438,8 @@ export const SolidityUnitTesting = (props: any) => { ++readyTestsNumber setReadyTestsNumber(readyTestsNumber) if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { - // testCallback({ type: 'contract', filename }) - const contractCard: any = ( -
- ({filename}) -
- ) - setTestsOutput(prevCards => ([...prevCards, contractCard])) + // show only file name + renderContract(filename, null, -1, true) currentErrors = _errors.errors // this.setHeader(false) } From e97d01522bd2046173000d52ae03bc9d6a4f12a1 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 23 Dec 2021 13:29:48 +0530 Subject: [PATCH 072/103] stop button --- .../src/lib/solidity-unit-testing.tsx | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) 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 d2d9ebded2..0053d824d5 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,5 +1,4 @@ -import React, { useState, useRef, useEffect, CSSProperties } from 'react' // eslint-disable-line -// import { TestTabLogic } from './logic/testTabLogic' +import React, { useState, useEffect } from 'react' // eslint-disable-line var async = require('async') import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { Renderer } from '@remix-ui/renderer' // eslint-disable-line @@ -44,10 +43,10 @@ export const SolidityUnitTesting = (props: any) => { let [readyTestsNumber, setReadyTestsNumber] = useState(0) let [runningTestsNumber, setRunningTestsNumber] = useState(0) - let [hasBeenStopped, setHasBeenStopped] = useState(false) - let [areTestsRunning, setAreTestsRunning] = useState(false) - let [isDebugging, setIsDebugging] = useState(false) - + + let areTestsRunning = false + let isDebugging = false + let hasBeenStopped = false let allTests: any = [] let currentErrors: any @@ -81,21 +80,20 @@ export const SolidityUnitTesting = (props: any) => { // } // // if current file is changed while debugging and one of the files imported in test file are opened // // do not clear the test results in SUT plugin - // if (this.isDebugging && this.allFilesInvolved.includes(file)) return + // if (isDebugging && this.allFilesInvolved.includes(file)) return console.log('Inside updateForNewCurrent --allTests-->', allTests) allTests = [] updateTestFileList() clearResults() - // if (!areTestsRunning) updateRunAction(file) try { - testTabLogic.getTests((error: any, tests: any) => { + testTabLogic.getTests(async (error: any, tests: any) => { // if (error) return tooltip(error) console.log('tests in updateForNewCurrent testTabLogic.getTests', tests) allTests = tests selectedTests = [...allTests] setSelectedTests(tests) updateTestFileList() - // if (!this.testsOutput) return // eslint-disable-line + if (!areTestsRunning) await updateRunAction(file) }) } catch (e) { console.log('error in updateForNewCurrent', e) @@ -164,7 +162,7 @@ export const SolidityUnitTesting = (props: any) => { } } - const handleCreateFolder = () => { + const handleCreateFolder = async() => { let inputPath = trimTestDirInput(inputPathValue) let path = helper.removeMultipleSlashes(inputPath) if (path !== '/') path = helper.removeTrailingSlashes(path) @@ -174,7 +172,7 @@ export const SolidityUnitTesting = (props: any) => { setDisableCreateButton(true) setDisableGenerateButton(false) testTabLogic.setCurrentPath(inputPath) - updateRunAction() + await updateRunAction() updateForNewCurrent() pathOptions.push(inputPath) setPathOptions(pathOptions) @@ -185,7 +183,7 @@ export const SolidityUnitTesting = (props: any) => { } const startDebug = async (txHash: any, web3: any) => { - // this.isDebugging = true + isDebugging = true if (!await testTab.appManager.isActive('debugger')) await testTab.appManager.activatePlugin('debugger') testTab.call('menuicons', 'select', 'debugger') testTab.call('debugger', 'debug', txHash, web3) @@ -354,7 +352,7 @@ export const SolidityUnitTesting = (props: any) => { } const showTestsResult = () => { - console.log('filesContent---->', filesContent) + console.log('inside showTestsResult filesContent---->', filesContent) let filenames = Object.keys(testsResultByFilename) for(const filename of filenames) { const fileTestsResult = testsResultByFilename[filename] @@ -441,7 +439,6 @@ export const SolidityUnitTesting = (props: any) => { // show only file name renderContract(filename, null, -1, true) currentErrors = _errors.errors - // this.setHeader(false) } if (result) { const totalTime = parseFloat(result.totalTime).toFixed(2) @@ -461,18 +458,15 @@ export const SolidityUnitTesting = (props: any) => { // if all tests has been through before stopping no need to print this. setTestsExecutionStoppedHidden(false) } - // if (_errors || this.hasBeenStopped || this.readyTestsNumber === this.runningTestsNumber) { - // // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files. - // const stopBtn = document.getElementById('runTestsTabStopAction') - // stopBtn.setAttribute('disabled', 'disabled') - // const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel') - // stopBtnLabel.innerText = 'Stop' - // if (this.data.selectedTests.length !== 0) { - // const runBtn = document.getElementById('runTestsTabRunAction') - // runBtn.removeAttribute('disabled') - // } - // this.areTestsRunning = false - // } + if (_errors || hasBeenStopped || readyTestsNumber === runningTestsNumber) { + // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files. + setDisableStopButton(true) + setStopButtonLabel('Stop') + if (selectedTests.length !== 0) { + setDisableRunButton(false) + } + areTestsRunning = false + } } const runTest = (testFilePath: any, callback: any) => { @@ -540,8 +534,10 @@ export const SolidityUnitTesting = (props: any) => { }) } - const updateRunAction = (currentFile : any = null) => { - const isSolidityActive = testTab.appManager.isActive('solidity') + const updateRunAction = async (currentFile : any = null) => { + const isSolidityActive = await testTab.appManager.isActive('solidity') + console.log('isSolidityActive-in updateRunAction--->', isSolidityActive) + console.log('selectedTests-in updateRunAction--->', selectedTests) if (!isSolidityActive || !selectedTests?.length) { setDisableRunButton(true) if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { @@ -553,7 +549,7 @@ export const SolidityUnitTesting = (props: any) => { } const stopTests = () => { - setHasBeenStopped(true) + hasBeenStopped = true setStopButtonLabel('Stopping') setDisableStopButton(true) setDisableRunButton(true) From e51cf15e6b8ffdabe0c8ff85be66147d6a954dd0 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 23 Dec 2021 17:03:00 +0530 Subject: [PATCH 073/103] stop tests --- .../src/lib/solidity-unit-testing.tsx | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) 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 0053d824d5..3cf3fc49a5 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,4 @@ -import React, { useState, useEffect } from 'react' // eslint-disable-line +import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line var async = require('async') import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { Renderer } from '@remix-ui/renderer' // eslint-disable-line @@ -44,9 +44,10 @@ export const SolidityUnitTesting = (props: any) => { let [readyTestsNumber, setReadyTestsNumber] = useState(0) let [runningTestsNumber, setRunningTestsNumber] = useState(0) + let hasBeenStopped = useRef(false) + let areTestsRunning = false let isDebugging = false - let hasBeenStopped = false let allTests: any = [] let currentErrors: any @@ -61,7 +62,6 @@ export const SolidityUnitTesting = (props: any) => { } const clearResults = () => { - console.log('clearResults--->') setProgressBarHidden(true) testTab.call('editor', 'clearAnnotations') setTestsOutput([]) @@ -81,14 +81,12 @@ export const SolidityUnitTesting = (props: any) => { // // if current file is changed while debugging and one of the files imported in test file are opened // // do not clear the test results in SUT plugin // if (isDebugging && this.allFilesInvolved.includes(file)) return - console.log('Inside updateForNewCurrent --allTests-->', allTests) allTests = [] updateTestFileList() clearResults() try { testTabLogic.getTests(async (error: any, tests: any) => { // if (error) return tooltip(error) - console.log('tests in updateForNewCurrent testTabLogic.getTests', tests) allTests = tests selectedTests = [...allTests] setSelectedTests(tests) @@ -96,7 +94,7 @@ export const SolidityUnitTesting = (props: any) => { if (!areTestsRunning) await updateRunAction(file) }) } catch (e) { - console.log('error in updateForNewCurrent', e) + console.log(e) } } @@ -352,7 +350,6 @@ export const SolidityUnitTesting = (props: any) => { } const showTestsResult = () => { - console.log('inside showTestsResult filesContent---->', filesContent) let filenames = Object.keys(testsResultByFilename) for(const filename of filenames) { const fileTestsResult = testsResultByFilename[filename] @@ -369,7 +366,6 @@ export const SolidityUnitTesting = (props: any) => { } } else if (contract === 'errors' && fileTestsResult['errors']) { const errors = fileTestsResult['errors'] - console.log('errors---->', errors) if (errors && errors.errors) { errors.errors.forEach((err: any) => { const errorCard: any = @@ -403,7 +399,6 @@ export const SolidityUnitTesting = (props: any) => { } const testCallback = (result: any) => { - console.log('result--------------in testCallback->', result) if(result.filename) { if(!testsResultByFilename[result.filename]) { testsResultByFilename[result.filename] = {} @@ -417,7 +412,6 @@ export const SolidityUnitTesting = (props: any) => { result.rendered = false testsResultByFilename[result.filename][result.context].push(result) } - console.log('testsResultByFilename--------============------in testCallback END---====->', testsResultByFilename) showTestsResult() } } @@ -431,8 +425,6 @@ export const SolidityUnitTesting = (props: any) => { } const updateFinalResult = (_errors: any, result: any, filename: any) => { - console.log('result---------------------------in updateFinalResult->', result, filename) - console.log('testsResultByFilename---------------------------in updateFinalResult->', testsResultByFilename) ++readyTestsNumber setReadyTestsNumber(readyTestsNumber) if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { @@ -454,11 +446,11 @@ export const SolidityUnitTesting = (props: any) => { showTestsResult() } - if (hasBeenStopped && (readyTestsNumber !== runningTestsNumber)) { + if (hasBeenStopped.current && (readyTestsNumber !== runningTestsNumber)) { // if all tests has been through before stopping no need to print this. setTestsExecutionStoppedHidden(false) } - if (_errors || hasBeenStopped || readyTestsNumber === runningTestsNumber) { + if (_errors || hasBeenStopped.current || readyTestsNumber === runningTestsNumber) { // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files. setDisableStopButton(true) setStopButtonLabel('Stop') @@ -470,10 +462,9 @@ export const SolidityUnitTesting = (props: any) => { } const runTest = (testFilePath: any, callback: any) => { - console.log('runTest----->', testFilePath, hasBeenStopped) isDebugging = false - if (hasBeenStopped) { - // this.updateFinalResult() + if (hasBeenStopped.current) { + updateFinalResult(null, null, null) return } testTab.fileManager.readFile(testFilePath).then((content: any) => { @@ -513,9 +504,8 @@ export const SolidityUnitTesting = (props: any) => { } const runTests = () => { - console.log('runtests--->') areTestsRunning = true - hasBeenStopped = false + hasBeenStopped.current = false readyTestsNumber = 0 setReadyTestsNumber(readyTestsNumber) runningTestsNumber = selectedTests.length @@ -524,20 +514,17 @@ export const SolidityUnitTesting = (props: any) => { clearResults() setProgressBarHidden(false) const tests = selectedTests - console.log('tests--in runTests----------------->', tests) if (!tests || !tests.length) return else setProgressBarHidden(false) // _paq.push(['trackEvent', 'solidityUnitTesting', 'runTests']) async.eachOfSeries(tests, (value: any, key: any, callback: any) => { - if (hasBeenStopped) return + if (hasBeenStopped.current) return runTest(value, callback) }) } const updateRunAction = async (currentFile : any = null) => { const isSolidityActive = await testTab.appManager.isActive('solidity') - console.log('isSolidityActive-in updateRunAction--->', isSolidityActive) - console.log('selectedTests-in updateRunAction--->', selectedTests) if (!isSolidityActive || !selectedTests?.length) { setDisableRunButton(true) if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { @@ -549,7 +536,7 @@ export const SolidityUnitTesting = (props: any) => { } const stopTests = () => { - hasBeenStopped = true + hasBeenStopped.current = true setStopButtonLabel('Stopping') setDisableStopButton(true) setDisableRunButton(true) @@ -568,7 +555,7 @@ export const SolidityUnitTesting = (props: any) => { if (eChecked) { setCheckSelectAll(true) setDisableRunButton(false) - if ((readyTestsNumber === runningTestsNumber || hasBeenStopped) && stopButtonLabel.trim() === 'Stop') { + if ((readyTestsNumber === runningTestsNumber || hasBeenStopped.current) && stopButtonLabel.trim() === 'Stop') { setRunButtonTitle('Run tests') } } else if (!selectedTests.length) { @@ -680,7 +667,6 @@ export const SolidityUnitTesting = (props: any) => {
{testFiles?.length ? testFiles.map((testFileObj: any, index) => { - console.log('testFileObj----->', testFileObj) const elemId = `singleTest${testFileObj.fileName}` return (
From e680c18c1ad169953acafc65f93bc5bfdefb3ff4 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 23 Dec 2021 17:25:21 +0530 Subject: [PATCH 074/103] _paq --- .../src/lib/solidity-unit-testing.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 3cf3fc49a5..de48855297 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,11 +1,12 @@ import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line -var async = require('async') +import { eachOfSeries } from 'async' import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { Renderer } from '@remix-ui/renderer' // eslint-disable-line import { format } from 'util' - import './css/style.css' +const _paq = (window as any)._paq = (window as any)._paq || [] + /* eslint-disable-next-line */ export interface SolidityUnitTestingProps {} @@ -202,7 +203,7 @@ export const SolidityUnitTesting = (props: any) => { } finalLogs = finalLogs + ' ' + formattedLog + '\n' } - // _paq.push(['trackEvent', 'solidityUnitTesting', 'hardhat', 'console.log']) + _paq.push(['trackEvent', 'solidityUnitTesting', 'hardhat', 'console.log']) testTab.call('terminal', 'log', { type: 'info', value: finalLogs }) } @@ -516,8 +517,8 @@ export const SolidityUnitTesting = (props: any) => { const tests = selectedTests if (!tests || !tests.length) return else setProgressBarHidden(false) - // _paq.push(['trackEvent', 'solidityUnitTesting', 'runTests']) - async.eachOfSeries(tests, (value: any, key: any, callback: any) => { + _paq.push(['trackEvent', 'solidityUnitTesting', 'runTests']) + eachOfSeries(tests, (value: any, key: any, callback: any) => { if (hasBeenStopped.current) return runTest(value, callback) }) From 2115426518a4677369af510b3aa801397584ee29 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 23 Dec 2021 17:37:44 +0530 Subject: [PATCH 075/103] currentErrors --- .../src/lib/solidity-unit-testing.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 de48855297..1dbdf5a5d2 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 @@ -73,15 +73,15 @@ export const SolidityUnitTesting = (props: any) => { const updateForNewCurrent = async (file = null) => { // Ensure that when someone clicks on compilation error and that opens a new file // Test result, which is compilation error in this case, is not cleared - // if (this.currentErrors) { - // if (Array.isArray(this.currentErrors) && this.currentErrors.length > 0) { - // const errFiles = this.currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) - // if (errFiles.includes(file)) return - // } else if (this.currentErrors.sourceLocation && this.currentErrors.sourceLocation.file && this.currentErrors.sourceLocation.file === file) return - // } + if (currentErrors) { + if (Array.isArray(currentErrors) && currentErrors.length > 0) { + const errFiles = currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) + if (errFiles.includes(file)) return + } else if (currentErrors.sourceLocation && currentErrors.sourceLocation.file && currentErrors.sourceLocation.file === file) return + } // // if current file is changed while debugging and one of the files imported in test file are opened // // do not clear the test results in SUT plugin - // if (isDebugging && this.allFilesInvolved.includes(file)) return + if (isDebugging && testTab.allFilesInvolved.includes(file)) return allTests = [] updateTestFileList() clearResults() From 9c04fc77e8e8ab136f405feca14ea0b0830a061d Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 23 Dec 2021 18:19:40 +0530 Subject: [PATCH 076/103] fix conflicts --- libs/remix-ui/solidity-unit-testing/src/index.ts | 2 +- nx.json | 4 +++- package.json | 4 ---- workspace.json | 1 - 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libs/remix-ui/solidity-unit-testing/src/index.ts b/libs/remix-ui/solidity-unit-testing/src/index.ts index 55a090f9ef..ad00e8d3b4 100644 --- a/libs/remix-ui/solidity-unit-testing/src/index.ts +++ b/libs/remix-ui/solidity-unit-testing/src/index.ts @@ -1,2 +1,2 @@ -export * from './lib/solidity-unit-testing'; +export * from './lib/solidity-unit-testing' export * from './lib/logic/testTabLogic' diff --git a/nx.json b/nx.json index b3a632f1b7..2e96853523 100644 --- a/nx.json +++ b/nx.json @@ -145,7 +145,9 @@ "remix-ui-tabs": { "tags": [] }, - "remix-ui-theme-module": {}, + "remix-ui-theme-module": { + "tags": [] + }, "solidity-unit-testing": { "tags": [] }, diff --git a/package.json b/package.json index a4e2b1e26e..a32a38bdb3 100644 --- a/package.json +++ b/package.json @@ -162,11 +162,7 @@ "chokidar": "^2.1.8", "color-support": "^1.1.3", "commander": "^2.20.3", -<<<<<<< HEAD "core-js": "^3.19.3", -======= - "core-js": "^3.6.5", ->>>>>>> 6d78ad88e... SUT in React "deep-equal": "^1.0.1", "document-register-element": "1.13.1", "ethereumjs-util": "^7.0.10", diff --git a/workspace.json b/workspace.json index b86c679373..ce790524ea 100644 --- a/workspace.json +++ b/workspace.json @@ -1179,7 +1179,6 @@ "linter": "eslint", "tsConfig": ["libs/remix-ui/vertical-icons-panel/tsconfig.lib.json"], "exclude": ["**/node_modules/**", "!libs/remix-ui/vertical-icons-panel/**/*"] - } } } From d1609a4ed98845ebac5ef3fd54d4ef36634df267 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 23 Dec 2021 18:39:17 +0530 Subject: [PATCH 077/103] targetDependencies --- nx.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nx.json b/nx.json index 2e96853523..e1bc0d858a 100644 --- a/nx.json +++ b/nx.json @@ -154,5 +154,13 @@ "remix-ui-editor-context-view": { "tags": [] } + }, + "targetDependencies": { + "build": [ + { + "target": "build", + "projects": "dependencies" + } + ] } } From a3e32d1baa27ea08d3d1a6a16ba9bc8447dc8ef2 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 24 Dec 2021 12:39:52 +0530 Subject: [PATCH 078/103] linting fix --- .../solidity-unit-testing/.eslintrc.json | 3 ++ .../lib/actions/solidityUnitTestingAction.ts | 2 - .../src/lib/logic/testTabLogic.ts | 5 +-- .../reducers/solidityUnitTestingReducer.ts | 1 - .../src/lib/solidity-unit-testing.tsx | 44 +++++++++---------- 5 files changed, 26 insertions(+), 29 deletions(-) delete mode 100644 libs/remix-ui/solidity-unit-testing/src/lib/actions/solidityUnitTestingAction.ts delete mode 100644 libs/remix-ui/solidity-unit-testing/src/lib/reducers/solidityUnitTestingReducer.ts diff --git a/libs/remix-ui/solidity-unit-testing/.eslintrc.json b/libs/remix-ui/solidity-unit-testing/.eslintrc.json index 50e59482cf..5e100bf955 100644 --- a/libs/remix-ui/solidity-unit-testing/.eslintrc.json +++ b/libs/remix-ui/solidity-unit-testing/.eslintrc.json @@ -1,6 +1,9 @@ { "extends": ["plugin:@nrwl/nx/react", "../../../.eslintrc.json"], "ignorePatterns": ["!**/*"], + "rules": { + "@typescript-eslint/no-explicit-any": "off" + }, "overrides": [ { "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/actions/solidityUnitTestingAction.ts b/libs/remix-ui/solidity-unit-testing/src/lib/actions/solidityUnitTestingAction.ts deleted file mode 100644 index c5728e9dec..0000000000 --- a/libs/remix-ui/solidity-unit-testing/src/lib/actions/solidityUnitTestingAction.ts +++ /dev/null @@ -1,2 +0,0 @@ -import React from 'react' - diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts index df19fb665d..31e34cf50f 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts +++ b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts @@ -1,5 +1,4 @@ -// const modalDialogCustom = require('../../ui/modal-dialog-custom') -const remixPath = require('path') +import remixPath from 'path' export class TestTabLogic { @@ -75,7 +74,7 @@ export class TestTabLogic { } catch (e: any) { cb(e.message) } - for (var file in files) { + for (const file in files) { const filepath = provider && provider.type ? provider.type + '/' + file : file if (/.(_test.sol)$/.exec(file)) tests.push(filepath) } diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/reducers/solidityUnitTestingReducer.ts b/libs/remix-ui/solidity-unit-testing/src/lib/reducers/solidityUnitTestingReducer.ts deleted file mode 100644 index bb73474209..0000000000 --- a/libs/remix-ui/solidity-unit-testing/src/lib/reducers/solidityUnitTestingReducer.ts +++ /dev/null @@ -1 +0,0 @@ -export const solidityUnitTestingReducer = (state, action) => {} \ No newline at end of file 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 1dbdf5a5d2..ae4f89272b 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,11 +1,11 @@ import React, { useState, useRef, useEffect } from 'react' // eslint-disable-line -import { eachOfSeries } from 'async' +import { eachOfSeries } from 'async' // eslint-disable-line import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { Renderer } from '@remix-ui/renderer' // eslint-disable-line import { format } from 'util' import './css/style.css' -const _paq = (window as any)._paq = (window as any)._paq || [] +const _paq = (window as any)._paq = (window as any)._paq || [] // eslint-disable-line /* eslint-disable-next-line */ export interface SolidityUnitTestingProps {} @@ -15,10 +15,9 @@ interface TestObject { checked: boolean } -export const SolidityUnitTesting = (props: any) => { +export const SolidityUnitTesting = (props: Record) => { const {helper, testTab} = props - const { testTabLogic } = testTab const [defaultPath, setDefaultPath] = useState('tests') @@ -36,16 +35,16 @@ export const SolidityUnitTesting = (props: any) => { const [progressBarHidden, setProgressBarHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) - let [testFiles, setTestFiles] = useState([]) + const [testFiles, setTestFiles] = useState([]) const [pathOptions, setPathOptions] = useState(['']) - let [selectedTests, setSelectedTests] = useState([]) + let [selectedTests, setSelectedTests] = useState([]) // eslint-disable-line const [inputPathValue, setInputPathValue] = useState('tests') - let [readyTestsNumber, setReadyTestsNumber] = useState(0) - let [runningTestsNumber, setRunningTestsNumber] = useState(0) + const [readyTestsNumber, setReadyTestsNumber] = useState(0) + const [runningTestsNumber, setRunningTestsNumber] = useState(0) - let hasBeenStopped = useRef(false) + const hasBeenStopped = useRef(false) let areTestsRunning = false let isDebugging = false @@ -53,9 +52,9 @@ export const SolidityUnitTesting = (props: any) => { let currentErrors: any let runningTestFileName: any - let filesContent: any = {} + const filesContent: any = {} - let testsResultByFilename:Record = {} + const testsResultByFilename:Record = {} const trimTestDirInput = (input:string) => { if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') @@ -75,7 +74,7 @@ export const SolidityUnitTesting = (props: any) => { // Test result, which is compilation error in this case, is not cleared if (currentErrors) { if (Array.isArray(currentErrors) && currentErrors.length > 0) { - const errFiles = currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) + const errFiles = currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) // eslint-disable-line if (errFiles.includes(file)) return } else if (currentErrors.sourceLocation && currentErrors.sourceLocation.file && currentErrors.sourceLocation.file === file) return } @@ -102,7 +101,7 @@ export const SolidityUnitTesting = (props: any) => { useEffect(() => { updateDirList('/') updateForNewCurrent() - }, []) + }) const updateDirList = (path: string) => { testTabLogic.dirList(path).then((options: any) => { @@ -211,21 +210,21 @@ export const SolidityUnitTesting = (props: any) => { await testTab.call('editor', 'discardHighlight') } - const highlightLocation = async (location: any, fileName: any) => { + const highlightLocation = async (location: string, fileName: string) => { if (location) { - var split = location.split(':') - var file = split[2] - location = { + const split = location.split(':') + const file = split[2] + const parsedLocation = { start: parseInt(split[0]), length: parseInt(split[1]) } - location = testTab.offsetToLineColumnConverter.offsetToLineColumnWithContent( - location, + const locationToHighlight = testTab.offsetToLineColumnConverter.offsetToLineColumnWithContent( + parsedLocation, parseInt(file), filesContent[fileName].content ) await testTab.call('editor', 'discardHighlight') - await testTab.call('editor', 'highlight', location, fileName, '', { focus: true }) + await testTab.call('editor', 'highlight', locationToHighlight, fileName, '', { focus: true }) } } @@ -351,7 +350,7 @@ export const SolidityUnitTesting = (props: any) => { } const showTestsResult = () => { - let filenames = Object.keys(testsResultByFilename) + const filenames = Object.keys(testsResultByFilename) for(const filename of filenames) { const fileTestsResult = testsResultByFilename[filename] const contracts = Object.keys(fileTestsResult) @@ -544,7 +543,7 @@ export const SolidityUnitTesting = (props: any) => { } const getCurrentSelectedTests = () => { - let selectedTestsList: TestObject[] = testFiles.filter(testFileObj => testFileObj.checked) + const selectedTestsList: TestObject[] = testFiles.filter(testFileObj => testFileObj.checked) return selectedTestsList.map(testFileObj => testFileObj.fileName) } @@ -663,7 +662,6 @@ export const SolidityUnitTesting = (props: any) => { data-id="testTabCheckAllTests" onClick={checkAll} checked={checkSelectAll} - onChange={() => {}} />
From 023e99d5beb9907918c72f7a6967a0e93d3e3631 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 24 Dec 2021 12:46:38 +0530 Subject: [PATCH 079/103] build fix --- .../solidity-unit-testing/src/lib/solidity-unit-testing.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 ae4f89272b..767325f906 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 @@ -35,14 +35,14 @@ export const SolidityUnitTesting = (props: Record) => { const [progressBarHidden, setProgressBarHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) - const [testFiles, setTestFiles] = useState([]) + let [testFiles, setTestFiles] = useState([]) // eslint-disable-line const [pathOptions, setPathOptions] = useState(['']) let [selectedTests, setSelectedTests] = useState([]) // eslint-disable-line const [inputPathValue, setInputPathValue] = useState('tests') - const [readyTestsNumber, setReadyTestsNumber] = useState(0) - const [runningTestsNumber, setRunningTestsNumber] = useState(0) + let [readyTestsNumber, setReadyTestsNumber] = useState(0) // eslint-disable-line + let [runningTestsNumber, setRunningTestsNumber] = useState(0) // eslint-disable-line const hasBeenStopped = useRef(false) From f528bc1656f0869744cf95890ae80a2cb3c6bc5b Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 24 Dec 2021 13:09:11 +0530 Subject: [PATCH 080/103] warning fixes --- .../solidity-unit-testing/src/lib/solidity-unit-testing.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 767325f906..80ee2c0ad2 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 @@ -101,7 +101,7 @@ export const SolidityUnitTesting = (props: Record) => { useEffect(() => { updateDirList('/') updateForNewCurrent() - }) + }, []) // eslint-disable-line const updateDirList = (path: string) => { testTabLogic.dirList(path).then((options: any) => { @@ -662,13 +662,14 @@ export const SolidityUnitTesting = (props: Record) => { data-id="testTabCheckAllTests" onClick={checkAll} checked={checkSelectAll} + onChange={() => {}} // eslint-disable-line />
{testFiles?.length ? testFiles.map((testFileObj: any, index) => { const elemId = `singleTest${testFileObj.fileName}` return ( -
+
toggleCheckbox(e.target.checked, index)} type="checkbox" checked={testFileObj.checked}/>
From c5337d2ceff08931350ccf74469a7f578b1ae4f6 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 24 Dec 2021 14:40:01 +0530 Subject: [PATCH 081/103] code cleaning --- apps/remix-ide/src/app/tabs/test-tab.js | 543 ------------------ .../remix-ide/src/app/tabs/testTab/testTab.js | 138 ----- .../src/lib/solidity-unit-testing.tsx | 6 +- 3 files changed, 3 insertions(+), 684 deletions(-) delete mode 100644 apps/remix-ide/src/app/tabs/testTab/testTab.js diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 1267b585aa..8dfe2c8615 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -17,8 +17,6 @@ var { UnitTestRunner, assertLibCode } = require('@remix-project/remix-tests') const _paq = window._paq = window._paq || [] -// const TestTabLogic = require('./testTab/testTab') - const profile = { name: 'solidityUnitTesting', displayName: 'Solidity unit testing', @@ -43,15 +41,8 @@ module.exports = class TestTab extends ViewPlugin { this.renderer = new Renderer(this) this.testRunner = new UnitTestRunner() this.testTabLogic = new TestTabLogic(this.fileManager, helper) - this.hasBeenStopped = false - this.runningTestsNumber = 0 - this.readyTestsNumber = 0 - this.areTestsRunning = false - this.defaultPath = 'tests' this.offsetToLineColumnConverter = offsetToLineColumnConverter this.allFilesInvolved = ['.deps/remix-tests/remix_tests.sol', '.deps/remix-tests/remix_accounts.sol'] - this.isDebugging = false - this.currentErrors = [] this.element = document.createElement('div') appManager.event.on('activate', (name) => { @@ -150,300 +141,6 @@ module.exports = class TestTab extends ViewPlugin { this.fileManager.events.on('currentFileChanged', (file, provider) => this.updateForNewCurrent(file)) } - async updateForNewCurrent (file) { - // Ensure that when someone clicks on compilation error and that opens a new file - // Test result, which is compilation error in this case, is not cleared - if (this.currentErrors) { - if (Array.isArray(this.currentErrors) && this.currentErrors.length > 0) { - const errFiles = this.currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) - if (errFiles.includes(file)) return - } else if (this.currentErrors.sourceLocation && this.currentErrors.sourceLocation.file && this.currentErrors.sourceLocation.file === file) return - } - // if current file is changed while debugging and one of the files imported in test file are opened - // do not clear the test results in SUT plugin - if (this.isDebugging && this.allFilesInvolved.includes(file)) return - this.data.allTests = [] - this.updateTestFileList() - this.clearResults() - this.updateGenerateFileAction() - if (!this.areTestsRunning) this.updateRunAction(file) - try { - await this.testTabLogic.getTests((error, tests) => { - if (error) return tooltip(error) - this.data.allTests = tests - this.data.selectedTests = [...this.data.allTests] - this.updateTestFileList(tests) - if (!this.testsOutput) return // eslint-disable-line - }) - } catch (e) { - console.log(e) - } - } - - createSingleTest (testFile) { - return yo` -
- this.toggleCheckbox(e.target.checked, testFile)} type="checkbox" checked="true"> - -
- ` - } - - listTests () { - if (!this.data.allTests || !this.data.allTests.length) return [] - return this.data.allTests.map( - testFile => this.createSingleTest(testFile) - ) - } - - async startDebug (txHash, web3) { - this.isDebugging = true - if (!await this.appManager.isActive('debugger')) await this.appManager.activatePlugin('debugger') - this.call('menuicons', 'select', 'debugger') - this.call('debugger', 'debug', txHash, web3) - } - - printHHLogs (logsArr, testName) { - let finalLogs = `${testName}:\n` - for (const log of logsArr) { - let formattedLog - // Hardhat implements the same formatting options that can be found in Node.js' console.log, - // which in turn uses util.format: https://nodejs.org/dist/latest-v12.x/docs/api/util.html#util_util_format_format_args - // For example: console.log("Name: %s, Age: %d", remix, 6) will log 'Name: remix, Age: 6' - // We check first arg to determine if 'util.format' is needed - if (typeof log[0] === 'string' && (log[0].includes('%s') || log[0].includes('%d'))) { - formattedLog = format(log[0], ...log.slice(1)) - } else { - formattedLog = log.join(' ') - } - finalLogs = finalLogs + ' ' + formattedLog + '\n' - } - _paq.push(['trackEvent', 'solidityUnitTesting', 'hardhat', 'console.log']) - this.call('terminal', 'log', { type: 'info', value: finalLogs }) - } - - testCallback (result, runningTests) { - this.testsOutput.hidden = false - let debugBtn = yo`` - if ((result.type === 'testPass' || result.type === 'testFailure') && result.debugTxHash) { - const { web3, debugTxHash } = result - debugBtn = yo`
this.startDebug(debugTxHash, web3)}> - -
` - debugBtn.style.cursor = 'pointer' - } - if (result.type === 'contract') { - this.testSuite = result.value - if (this.testSuites) { - this.testSuites.push(this.testSuite) - } else { - this.testSuites = [this.testSuite] - } - this.rawFileName = result.filename - this.runningTestFileName = this.cleanFileName(this.rawFileName, this.testSuite) - this.outputHeader = yo` -
- ${this.testSuite} (${this.rawFileName}) -
- ` - this.testsOutput.appendChild(this.outputHeader) - } else if (result.type === 'testPass') { - if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) - this.testsOutput.appendChild(yo` -
this.discardHighlight()} - > -
- ✓ ${result.value} - ${debugBtn} -
-
- `) - } else if (result.type === 'testFailure') { - if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) - if (!result.assertMethod) { - this.testsOutput.appendChild(yo` -
this.highlightLocation(result.location, runningTests, result.filename)} - > -
- ✘ ${result.value} - ${debugBtn} -
- Error Message: - "${result.errMsg}" -
- `) - } else { - const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' - const method = result.assertMethod === 'ok' ? '' : result.assertMethod - const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected - this.testsOutput.appendChild(yo` -
this.highlightLocation(result.location, runningTests, result.filename)} - > -
- ✘ ${result.value} - ${debugBtn} -
- Error Message: - "${result.errMsg}" - Assertion: -
- Expected value should be -
${method}
-
${preposition} ${expected}
-
- Received value: - ${result.returned} - Skipping the remaining tests of the function. -
- `) - } - } else if (result.type === 'logOnly') { - if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) - } - } - - resultsCallback (_err, result, cb) { - // total stats for the test - // result.passingNum - // result.failureNum - // result.timePassed - cb() - } - - cleanFileName (fileName, testSuite) { - return fileName ? fileName.replace(/\//g, '_').replace(/\./g, '_') + testSuite : fileName - } - - setHeader (status) { - if (status) { - const label = yo` -
- PASS -
- ` - - this.outputHeader && yo.update(this.outputHeader, yo` -
- ${label} ${this.testSuite} (${this.rawFileName}) -
- `) - } else { - const label = yo` -
- FAIL -
- ` - - this.outputHeader && yo.update(this.outputHeader, yo` -
- ${label} ${this.testSuite} (${this.rawFileName}) -
- `) - } - } - - updateFinalResult (_errors, result, filename) { - ++this.readyTestsNumber - this.testsOutput.hidden = false - if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { - this.testCallback({ type: 'contract', filename }) - this.currentErrors = _errors.errors - this.setHeader(false) - } - if (_errors && _errors.errors) { - _errors.errors.forEach((err) => this.renderer.error(err.formattedMessage || err.message, this.testsOutput, { type: err.severity, errorType: err.type })) - } else if (_errors && Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage)) { - _errors.forEach((err) => this.renderer.error(err.formattedMessage || err.message, this.testsOutput, { type: err.severity, errorType: err.type })) - } else if (_errors && !_errors.errors && !Array.isArray(_errors)) { - // To track error like this: https://github.com/ethereum/remix/pull/1438 - this.renderer.error(_errors.formattedMessage || _errors.message, this.testsOutput, { type: 'error' }) - } - yo.update(this.resultStatistics, this.createResultLabel()) - if (result) { - const totalTime = parseFloat(result.totalTime).toFixed(2) - - if (result.totalPassing > 0 && result.totalFailing > 0) { - this.testsOutput.appendChild(yo` -
- Result for ${filename} - Passing: ${result.totalPassing} - Failing: ${result.totalFailing} - Total time: ${totalTime}s -
- `) - } else if (result.totalPassing > 0 && result.totalFailing <= 0) { - this.testsOutput.appendChild(yo` -
- Result for ${filename} - Passing: ${result.totalPassing} - Total time: ${totalTime}s -
- `) - } else if (result.totalPassing <= 0 && result.totalFailing > 0) { - this.testsOutput.appendChild(yo` -
- Result for ${filename} - Failing: ${result.totalFailing} - Total time: ${totalTime}s -
- `) - } - // fix for displaying right label for multiple tests (testsuites) in a single file - this.testSuites.forEach(testSuite => { - this.testSuite = testSuite - this.runningTestFileName = this.cleanFileName(filename, this.testSuite) - this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) - this.setHeader(true) - }) - - result.errors.forEach((error, index) => { - this.testSuite = error.context - this.runningTestFileName = this.cleanFileName(filename, error.context) - this.outputHeader = document.querySelector(`#${this.runningTestFileName}`) - const isFailingLabel = document.querySelector(`.failed_${this.runningTestFileName}`) - if (!isFailingLabel) this.setHeader(false) - }) - this.testsOutput.appendChild(yo` -
-

-
- `) - } - if (this.hasBeenStopped && (this.readyTestsNumber !== this.runningTestsNumber)) { - // if all tests has been through before stopping no need to print this. - this.testsExecutionStopped.hidden = false - } - if (_errors) this.testsExecutionStoppedError.hidden = false - if (_errors || this.hasBeenStopped || this.readyTestsNumber === this.runningTestsNumber) { - // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files. - const stopBtn = document.getElementById('runTestsTabStopAction') - stopBtn.setAttribute('disabled', 'disabled') - const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel') - stopBtnLabel.innerText = 'Stop' - if (this.data.selectedTests.length !== 0) { - const runBtn = document.getElementById('runTestsTabRunAction') - runBtn.removeAttribute('disabled') - } - this.areTestsRunning = false - } - } - async testFromPath (path) { const fileContent = await this.fileManager.readFile(path) return this.testFromSource(fileContent, path) @@ -485,167 +182,6 @@ module.exports = class TestTab extends ViewPlugin { }) } - runTest (testFilePath, callback) { - this.isDebugging = false - if (this.hasBeenStopped) { - this.updateFinalResult() - return - } - this.resultStatistics.hidden = false - this.fileManager.readFile(testFilePath).then((content) => { - const runningTests = {} - runningTests[testFilePath] = { content } - const { currentVersion, evmVersion, optimize, runs, isUrl } = this.compileTab.getCurrentCompilerConfig() - const currentCompilerUrl = isUrl ? currentVersion : urlFromVersion(currentVersion) - const compilerConfig = { - currentCompilerUrl, - evmVersion, - optimize, - usingWorker: canUseWorker(currentVersion), - runs - } - const deployCb = async (file, contractAddress) => { - const compilerData = await this.call('compilerArtefacts', 'getCompilerAbstract', file) - await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compilerData) - } - this.testRunner.runTestSources( - runningTests, - compilerConfig, - (result) => this.testCallback(result, runningTests), - (_err, result, cb) => this.resultsCallback(_err, result, cb), - deployCb, - (error, result) => { - this.updateFinalResult(error, result, testFilePath) - callback(error) - }, (url, cb) => { - return this.contentImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message)) - }, { testFilePath } - ) - }).catch((error) => { - if (error) return // eslint-disable-line - }) - } - - clearResults () { - yo.update(this.resultStatistics, yo``) - this.call('editor', 'clearAnnotations') - this.testsOutput.innerHTML = '' - this.testsOutput.hidden = true - this.testsExecutionStopped.hidden = true - this.testsExecutionStoppedError.hidden = true - } - - runTests () { - this.areTestsRunning = true - this.hasBeenStopped = false - this.readyTestsNumber = 0 - this.runningTestsNumber = this.data.selectedTests.length - const stopBtn = document.getElementById('runTestsTabStopAction') - stopBtn.removeAttribute('disabled') - const runBtn = document.getElementById('runTestsTabRunAction') - runBtn.setAttribute('disabled', 'disabled') - this.clearResults() - yo.update(this.resultStatistics, this.createResultLabel()) - const tests = this.data.selectedTests - if (!tests) return - this.resultStatistics.hidden = tests.length === 0 - _paq.push(['trackEvent', 'solidityUnitTesting', 'runTests']) - async.eachOfSeries(tests, (value, key, callback) => { - if (this.hasBeenStopped) return - this.runTest(value, callback) - }) - } - - stopTests () { - this.hasBeenStopped = true - const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel') - stopBtnLabel.innerText = 'Stopping' - const stopBtn = document.getElementById('runTestsTabStopAction') - stopBtn.setAttribute('disabled', 'disabled') - const runBtn = document.getElementById('runTestsTabRunAction') - runBtn.setAttribute('disabled', 'disabled') - } - - updateRunAction (currentFile) { - const el = yo` - - ` - const isSolidityActive = this.appManager.isActive('solidity') - if (!isSolidityActive || !this.listTests().length) { - el.setAttribute('disabled', 'disabled') - if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { - el.setAttribute('title', 'No solidity file selected') - } else { - el.setAttribute('title', 'The "Solidity Plugin" should be activated') - } - } - if (!this.runActionElement) { - this.runActionElement = el - } else { - yo.update(this.runActionElement, el) - } - return this.runActionElement - } - - updateStopAction () { - return yo` - - ` - } - - updateTestFileList (tests) { - const testsMessage = (tests && tests.length ? this.listTests() : 'No test file available') - const el = yo`
${testsMessage}
` - if (!this.testFilesListElement) { - this.testFilesListElement = el - } else { - yo.update(this.testFilesListElement, el) - } - this.updateRunAction() - return this.testFilesListElement - } - - selectAll () { - return yo` -
- - -
- ` - } - - infoButton () { - return yo` - - - - ` - } - - createResultLabel () { - if (!this.data.selectedTests) return yo`` - const ready = this.readyTestsNumber ? `${this.readyTestsNumber}` : '0' - return yo`Progress: ${ready} finished (of ${this.runningTestsNumber})` - } - - pathAdded (text) { - for (const option of this.uiPathList.querySelectorAll('option')) { - if (option.innerHTML === text) return true - } - return false - } - render () { this.onActivationInternal() this.renderComponent() @@ -657,83 +193,4 @@ module.exports = class TestTab extends ViewPlugin { , this.element) } - - render2 () { - this.onActivationInternal() - this.testsOutput = yo`) +
) else label = (
) => { // show filename and contract renderContract(filename, contract, index) // show tests - for(const test of tests) { - if(!test.rendered) { + for (const test of tests) { + if (!test.rendered) { let debugBtn if (test.debugTxHash) { const { web3, debugTxHash } = test debugBtn = ( -
startDebug(debugTxHash, web3)}> - -
+
startDebug(debugTxHash, web3)}> + +
) - } + } if (test.type === 'testPass') { if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) const testPassCard: any = ( @@ -325,71 +329,71 @@ export const SolidityUnitTesting = (props: Record) => { >
✓ {test.value} - {debugBtn} -
+ {debugBtn} +
) setTestsOutput(prevCards => ([...prevCards, testPassCard])) test.rendered = true } else if (test.type === 'testFailure') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - if (!test.assertMethod) { - const testFailCard1: any = (
highlightLocation(test.location, test.filename)} - > -
- ✘ {test.value} - {debugBtn} -
- Error Message: - "{test.errMsg}" -
) - setTestsOutput(prevCards => ([...prevCards, testFailCard1])) - } else { - const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' - const method = test.assertMethod === 'ok' ? '' : test.assertMethod - const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected - const testFailCard2: any = (
highlightLocation(test.location, test.filename)} - > -
- ✘ {test.value} - {debugBtn} -
- Error Message: - "{test.errMsg}" - Assertion: -
- Expected value should be -
{method}
-
{preposition} {expected}
-
- Received value: - {test.returned} - Skipping the remaining tests of the function. -
) - setTestsOutput(prevCards => ([...prevCards, testFailCard2])) - } - test.rendered = true - } else if (test.type === 'logOnly') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - test.rendered = true - } + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + if (!test.assertMethod) { + const testFailCard1: any = (
highlightLocation(test.location, test.filename)} + > +
+ ✘ {test.value} + {debugBtn} +
+ Error Message: + "{test.errMsg}" +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard1])) + } else { + const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' + const method = test.assertMethod === 'ok' ? '' : test.assertMethod + const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected + const testFailCard2: any = (
highlightLocation(test.location, test.filename)} + > +
+ ✘ {test.value} + {debugBtn} +
+ Error Message: + "{test.errMsg}" + Assertion: +
+ Expected value should be +
{method}
+
{preposition} {expected}
+
+ Received value: + {test.returned} + Skipping the remaining tests of the function. +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard2])) + } + test.rendered = true + } else if (test.type === 'logOnly') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + test.rendered = true + } } } } const showTestsResult = () => { const filenames = Object.keys(testsResultByFilename) - for(const filename of filenames) { + for (const filename of filenames) { const fileTestsResult = testsResultByFilename[filename] const contracts = Object.keys(fileTestsResult) - for(const contract of contracts) { - if(contract && contract !== 'summary' && contract !== 'errors') { + for (const contract of contracts) { + if (contract && contract !== 'summary' && contract !== 'errors') { runningTestFileName = cleanFileName(filename, contract) const tests = fileTestsResult[contract] if (tests?.length) { @@ -402,19 +406,19 @@ export const SolidityUnitTesting = (props: Record) => { const errors = fileTestsResult['errors'] if (errors && errors.errors) { errors.errors.forEach((err: any) => { - const errorCard: any = + const errorCard: any = setTestsOutput(prevCards => ([...prevCards, errorCard])) }) } else if (errors && Array.isArray(errors) && (errors[0].message || errors[0].formattedMessage)) { errors.forEach((err) => { - const errorCard: any = + const errorCard: any = setTestsOutput(prevCards => ([...prevCards, errorCard])) }) } else if (errors && !errors.errors && !Array.isArray(errors)) { // To track error like this: https://github.com/ethereum/remix/pull/1438 const errorCard: any = setTestsOutput(prevCards => ([...prevCards, errorCard])) - } + } } } // show summary @@ -429,17 +433,17 @@ export const SolidityUnitTesting = (props: Record) => { setTestsOutput(prevCards => ([...prevCards, summaryCard])) fileTestsResult['summary']['rendered'] = true } - } + } } const testCallback = (result: any) => { - if(result.filename) { - if(!testsResultByFilename[result.filename]) { + if (result.filename) { + if (!testsResultByFilename[result.filename]) { testsResultByFilename[result.filename] = {} testsResultByFilename[result.filename]['summary'] = {} } - if(result.type === 'contract') { - testsResultByFilename[result.filename][result.value]= {} + if (result.type === 'contract') { + testsResultByFilename[result.filename][result.value] = {} testsResultByFilename[result.filename][result.value] = [] } else { // Set that this test is not rendered on UI @@ -469,17 +473,17 @@ export const SolidityUnitTesting = (props: Record) => { if (result) { const totalTime = parseFloat(result.totalTime).toFixed(2) const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } - testsResultByFilename[filename]['summary']= testsSummary + testsResultByFilename[filename]['summary'] = testsSummary showTestsResult() } else if (_errors) { - if(!testsResultByFilename[filename]) { + if (!testsResultByFilename[filename]) { testsResultByFilename[filename] = {} } testsResultByFilename[filename]['errors'] = _errors setTestsExecutionStoppedErrorHidden(false) showTestsResult() } - + if (hasBeenStopped.current && (readyTestsNumber !== runningTestsNumber)) { // if all tests has been through before stopping no need to print this. setTestsExecutionStoppedHidden(false) @@ -557,7 +561,7 @@ export const SolidityUnitTesting = (props: Record) => { }) } - const updateRunAction = async (currentFile : any = null) => { + const updateRunAction = async (currentFile: any = null) => { const isSolidityActive = await testTab.appManager.isActive('solidity') if (!isSolidityActive || !selectedTests.current?.length) { setDisableRunButton(true) @@ -581,7 +585,7 @@ export const SolidityUnitTesting = (props: Record) => { return selectedTestsList.map(testFileObj => testFileObj.fileName) } - const toggleCheckbox = (eChecked: any, index:any) => { + const toggleCheckbox = (eChecked: any, index: any) => { testFiles[index].checked = eChecked setTestFiles(testFiles) selectedTests.current = getCurrentSelectedTests() @@ -599,10 +603,10 @@ export const SolidityUnitTesting = (props: Record) => { } const checkAll = (event: any) => { - testFiles.forEach((testFileObj) => testFileObj.checked = event.target.checked) + testFiles.forEach((testFileObj) => testFileObj.checked = event.target.checked) setTestFiles(testFiles) setCheckSelectAll(event.target.checked) - if(event.target.checked) { + if (event.target.checked) { selectedTests.current = getCurrentSelectedTests() setDisableRunButton(false) } else { @@ -612,28 +616,28 @@ export const SolidityUnitTesting = (props: Record) => { } const updateTestFileList = () => { - if(allTests.current?.length) { - testFiles = allTests.current.map((testFile: any) => { return {'fileName': testFile, 'checked': true }}) + if (allTests.current?.length) { + testFiles = allTests.current.map((testFile: any) => { return { 'fileName': testFile, 'checked': true } }) setCheckSelectAll(true) } - else + else testFiles = [] setTestFiles(testFiles) } return (
-
-

Test your smart contract in Solidity.

-

Select directory to load and generate test files.

- -
-
+
+

Test your smart contract in Solidity.

+

Select directory to load and generate test files.

+ +
+
{ pathOptions.map(function (path) { return }) - } + } ) => { name="utPath" value={inputPathValue} title="Press 'Enter' to change the path for test files." - style= {{ backgroundImage: "var(--primary)"}} - onKeyUp= {handleTestDirInput} + style={{ backgroundImage: "var(--primary)" }} + onKeyUp={handleTestDirInput} onChange={handleEnter} /> -
-
-
- - - - -
-
- - -
-
- {}} // eslint-disable-line - /> - -
-
{testFiles?.length ? testFiles.map((testFileObj: any, index) => { - const elemId = `singleTest${testFileObj.fileName}` - return ( -
- toggleCheckbox(e.target.checked, index)} type="checkbox" checked={testFileObj.checked}/> - -
- ) - }) - : "No test file available" }
-
- - - -
-
{testsOutput}
+
+
+
+ + + + +
+
+ + +
+
+ { }} // eslint-disable-line + /> + +
+
{testFiles?.length ? testFiles.map((testFileObj: any, index) => { + const elemId = `singleTest${testFileObj.fileName}` + return ( +
+ toggleCheckbox(e.target.checked, index)} type="checkbox" checked={testFileObj.checked} /> + +
+ ) + }) + : "No test file available"}
+
+ + +
+
{testsOutput}
+
) } From 80045af191183573d786dd8095671399c84a4648 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 11:49:49 +0530 Subject: [PATCH 088/103] toaster for error --- .../src/lib/solidity-unit-testing.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 d759fdfcfd..63de9bfb57 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 @@ -2,6 +2,7 @@ import React, { useState, useRef, useEffect } from 'react' // eslint-disable-lin import { eachOfSeries } from 'async' // eslint-disable-line import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { Renderer } from '@remix-ui/renderer' // eslint-disable-line +import { Toaster } from '@remix-ui/toaster' // eslint-disable-line import { format } from 'util' import './css/style.css' @@ -21,6 +22,8 @@ export const SolidityUnitTesting = (props: Record) => { const { testTabLogic } = testTab const [defaultPath, setDefaultPath] = useState('tests') + const [toasterMsg, setToasterMsg] = useState('') + const [disableCreateButton, setDisableCreateButton] = useState(true) const [disableGenerateButton, setDisableGenerateButton] = useState(false) const [disableStopButton, setDisableStopButton] = useState(true) @@ -87,7 +90,7 @@ export const SolidityUnitTesting = (props: Record) => { clearResults() try { testTabLogic.getTests(async (error: any, tests: any) => { - // if (error) return tooltip(error) + if (error) return setToasterMsg(error) allTests.current = tests selectedTests.current = [...allTests.current] updateTestFileList() @@ -120,7 +123,7 @@ export const SolidityUnitTesting = (props: Record) => { testTab.on('filePanel', 'newTestFileCreated', async (file: string) => { try { testTabLogic.getTests((error: any, tests: any) => { - // if (error) return tooltip(error) + if (error) return setToasterMsg(error) allTests.current = tests selectedTests.current = [...allTests.current] updateTestFileList() @@ -627,6 +630,7 @@ export const SolidityUnitTesting = (props: Record) => { return (
+

Test your smart contract in Solidity.

Select directory to load and generate test files.

From d8c48046c3f1a3419754df7f01e99dc19c3a160a Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 12:27:51 +0530 Subject: [PATCH 089/103] toaster for testTabLogic error --- .../solidity-unit-testing/src/lib/logic/testTabLogic.ts | 8 +++----- .../src/lib/solidity-unit-testing.tsx | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts index 6e955c1074..80a65d5f8f 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts +++ b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts @@ -35,8 +35,7 @@ export class TestTabLogic { return res } - generateTestFile () { - console.log('Inside generateTestFile-1SUT-currentFile-', this.fileManager.currentFile(), this.currentPath) + generateTestFile (errorCb: any) { let fileName = this.fileManager.currentFile() const hasCurrent = !!fileName && this.fileManager.currentFile().split('.').pop().toLowerCase() === 'sol' if (!hasCurrent) fileName = this.currentPath + '/newFile.sol' @@ -45,10 +44,9 @@ export class TestTabLogic { const splittedFileName = fileName.split('/') const fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1] this.helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error: any, newFile: any) => { - // if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) + if (error) return errorCb('Failed to create file. ' + newFile + ' ' + error) const isFileCreated = fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName)) - console.log('isFileCreated--->', isFileCreated) - // if (!isFileCreated) return modalDialogCustom.alert('Failed to create test file ' + newFile) + if (!isFileCreated) return errorCb('Failed to create test file ' + newFile) this.fileManager.open(newFile) this.fileManager.syncEditor(newFile) }) 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 63de9bfb57..01627196e1 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 @@ -676,7 +676,7 @@ export const SolidityUnitTesting = (props: Record) => { title="Generate sample test file." disabled={disableGenerateButton} onClick={() => { - testTabLogic.generateTestFile() + testTabLogic.generateTestFile((err:any) => { if (err) setToasterMsg(err)}) updateForNewCurrent() }} > From af78ac0944db6dbe9000fa898c32b2a3f137da27 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 12:43:33 +0530 Subject: [PATCH 090/103] workspace.json update --- workspace.json | 85 -------------------------------------------------- 1 file changed, 85 deletions(-) diff --git a/workspace.json b/workspace.json index ce790524ea..f9b8362e9c 100644 --- a/workspace.json +++ b/workspace.json @@ -1,71 +1,5 @@ { "version": 1, - "cli": { - "defaultCollection": "@nrwl/react" - }, - "defaultProject": "remix-ide", - "schematics": { - "@nrwl/workspace": { - "library": { - "linter": "eslint" - } - }, - "@nrwl/cypress": { - "cypress-project": { - "linter": "eslint" - } - }, - "@nrwl/react": { - "application": { - "style": "css", - "linter": "eslint", - "babel": true - }, - "component": { - "style": "css" - }, - "library": { - "style": "css", - "linter": "eslint" - } - }, - "@nrwl/next": { - "application": { - "linter": "eslint" - } - }, - "@nrwl/web": { - "application": { - "linter": "eslint" - } - }, - "@nrwl/node": { - "application": { - "linter": "eslint" - }, - "library": { - "linter": "eslint" - } - }, - "@nrwl/nx-plugin": { - "plugin": { - "linter": "eslint" - } - }, - "@nrwl/nest": { - "application": { - "linter": "eslint" - } - }, - "@nrwl/express": { - "application": { - "linter": "eslint" - }, - "library": { - "linter": "eslint" - } - } - }, "projects": { "remix-ide": { "root": "apps/remix-ide", @@ -1183,24 +1117,6 @@ } } }, - "solidity-unit-testing": { - "root": "libs/remix-ui/solidity-unit-testing", - "sourceRoot": "libs/remix-ui/solidity-unit-testing/src", - "projectType": "library", - "architect": { - "lint": { - "builder": "@nrwl/linter:lint", - "options": { - "linter": "eslint", - "tsConfig": ["libs/remix-ui/solidity-unit-testing/tsconfig.lib.json"], - "exclude": [ - "**/node_modules/**", - "!libs/remix-ui/solidity-unit-testing/**/*" - ] - } - } - } - }, "remix-ui-editor-context-view": { "root": "libs/remix-ui/editor-context-view", "sourceRoot": "libs/remix-ui/editor-context-view/src", @@ -1253,4 +1169,3 @@ "defaultProject": "remix-ide" } } - From a41f99ecef8e3ae9e3c6fbe2076a3a833a2b9897 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 12:49:49 +0530 Subject: [PATCH 091/103] build fix --- workspace.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/workspace.json b/workspace.json index f9b8362e9c..442f45229f 100644 --- a/workspace.json +++ b/workspace.json @@ -1117,6 +1117,24 @@ } } }, + "solidity-unit-testing": { + "root": "libs/remix-ui/solidity-unit-testing", + "sourceRoot": "libs/remix-ui/solidity-unit-testing/src", + "projectType": "library", + "architect": { + "lint": { + "builder": "@nrwl/linter:lint", + "options": { + "linter": "eslint", + "tsConfig": ["libs/remix-ui/solidity-unit-testing/tsconfig.lib.json"], + "exclude": [ + "**/node_modules/**", + "!libs/remix-ui/solidity-unit-testing/**/*" + ] + } + } + } + }, "remix-ui-editor-context-view": { "root": "libs/remix-ui/editor-context-view", "sourceRoot": "libs/remix-ui/editor-context-view/src", From f256993ba0270ef472515bbf5eb2cc8e69757558 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 13:41:59 +0530 Subject: [PATCH 092/103] tests output class --- .../src/lib/solidity-unit-testing.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 01627196e1..f38725c67b 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 @@ -47,17 +47,15 @@ export const SolidityUnitTesting = (props: Record) => { let [runningTestsNumber, setRunningTestsNumber] = useState(0) // eslint-disable-line const hasBeenStopped = useRef(false) + const allTests: any = useRef([]) + const selectedTests: any = useRef([]) let areTestsRunning = false let isDebugging = false - const allTests: any = useRef([]) - const selectedTests: any = useRef([]) let currentErrors: any = [] - let runningTestFileName: any const filesContent: any = {} - const testsResultByFilename: Record = {} const trimTestDirInput = (input: string) => { @@ -721,7 +719,7 @@ export const SolidityUnitTesting = (props: Record) => {
-
{testsOutput}
+
{testsOutput}
) From 8029dc6b42e557b689349d6d65ea8ce5eba3387b Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 13:58:43 +0530 Subject: [PATCH 093/103] e2e fix for simpleStorage --- apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts index f6ccce0509..a9fec18b2b 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts @@ -64,9 +64,8 @@ module.exports = { .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', '✓ Initial value should be100', 120000) .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', '✓ Value is set200', 120000) .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', '✘ Should fail for wrong value200', 120000) - .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Passing: 2', 120000) - .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Failing: 1', 120000) - .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'FAIL MyTest (tests/simple_storage_test.sol)', 120000) + .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Passed: 2', 120000) + .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Failed: 1', 120000) }, 'Should run advance unit test using natspec and experimental ABIEncoderV2 `ks2b_test.sol` #group2': function (browser: NightwatchBrowser) { From 318d4e280940528b782078b7df9b2a6e23dff6c7 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 16:08:54 +0530 Subject: [PATCH 094/103] fix Changing current path e2e --- apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts index a9fec18b2b..45eb2f28d4 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts @@ -150,6 +150,7 @@ module.exports = { .waitForElementPresent('*[data-id="verticalIconsKindfilePanel"]') .addFile('myTests/simple_storage_test.sol', sources[0]['tests/simple_storage_test.sol']) .clickLaunchIcon('solidityUnitTesting') + .clearValue('*[data-id="uiPathInput"]') .setValue('*[data-id="uiPathInput"]', 'myTests') .click('*[data-id="testTabGenerateTestFolder"]') .clickElementAtPosition('.singleTest', 0, { forceSelectIfUnselected: true }) From 7fbbbd83031c653e5f4db9229a2aae50ae6291eb Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 18:13:18 +0530 Subject: [PATCH 095/103] e2e fix --- .../solidity-unit-testing/src/lib/solidity-unit-testing.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f38725c67b..f1dfc2c01b 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 @@ -565,7 +565,7 @@ export const SolidityUnitTesting = (props: Record) => { const updateRunAction = async (currentFile: any = null) => { const isSolidityActive = await testTab.appManager.isActive('solidity') if (!isSolidityActive || !selectedTests.current?.length) { - setDisableRunButton(true) + // setDisableRunButton(true) if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { setRunButtonTitle('No solidity file selected') } else { From b042193a5a7560694f4802e827409caa9cb30c91 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 28 Dec 2021 18:39:08 +0530 Subject: [PATCH 096/103] renderer linting fix --- libs/remix-ui/renderer/src/lib/renderer.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/remix-ui/renderer/src/lib/renderer.tsx b/libs/remix-ui/renderer/src/lib/renderer.tsx index c2540af801..eae9e0d4b0 100644 --- a/libs/remix-ui/renderer/src/lib/renderer.tsx +++ b/libs/remix-ui/renderer/src/lib/renderer.tsx @@ -1,7 +1,5 @@ import React, { useEffect, useState } from 'react' //eslint-disable-line -import QueryParams from '../../../../../apps/remix-ide/src/lib/query-params' import './renderer.css' -const registry = require('../../../../../apps/remix-ide/src/global/registry') interface RendererProps { message: any; opt?: any, From 385d9bfc65ae9bb7b8a722c8aa8109db976be16e Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 29 Dec 2021 12:04:16 +0530 Subject: [PATCH 097/103] Should stop unit tests fix --- apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts index 45eb2f28d4..16129f4063 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts @@ -93,10 +93,9 @@ module.exports = { .waitForElementPresent('*[data-id="testTabRunTestsTabRunAction"]') .clickElementAtPosition('.singleTestLabel', 0) .scrollAndClick('*[data-id="testTabRunTestsTabRunAction"]') - .pause(2000) .click('*[data-id="testTabRunTestsTabStopAction"]') - .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'tests/ks2b_test.sol', 200000) - .notContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'tests/4_Ballot_test.sol') + .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'tests/4_Ballot_test.sol', 200000) + .notContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'tests/ks2b_test.sol') .notContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'tests/simple_storage_test.sol') .waitForElementContainsText('*[data-id="testTabTestsExecutionStopped"]', 'The test execution has been stopped', 60000) }, From 8cbf8c879fb5fd1e23c78d5de0b8931439f86bbd Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 29 Dec 2021 12:58:11 +0530 Subject: [PATCH 098/103] not disappear error e2e fix --- .../src/lib/solidity-unit-testing.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 f1dfc2c01b..ca3dafbd57 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 @@ -49,11 +49,11 @@ export const SolidityUnitTesting = (props: Record) => { const hasBeenStopped = useRef(false) const allTests: any = useRef([]) const selectedTests: any = useRef([]) + const currentErrors: any = useRef([]) let areTestsRunning = false let isDebugging = false - let currentErrors: any = [] let runningTestFileName: any const filesContent: any = {} const testsResultByFilename: Record = {} @@ -74,11 +74,11 @@ export const SolidityUnitTesting = (props: Record) => { const updateForNewCurrent = async (file = null) => { // Ensure that when someone clicks on compilation error and that opens a new file // Test result, which is compilation error in this case, is not cleared - if (currentErrors) { - if (Array.isArray(currentErrors) && currentErrors.length > 0) { - const errFiles = currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) // eslint-disable-line + if (currentErrors.current) { + if (Array.isArray(currentErrors.current) && currentErrors.current.length > 0) { + const errFiles = currentErrors.current.map((err:any) => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) // eslint-disable-line if (errFiles.includes(file)) return - } else if (currentErrors.sourceLocation && currentErrors.sourceLocation.file && currentErrors.sourceLocation.file === file) return + } else if (currentErrors.current.sourceLocation && currentErrors.current.sourceLocation.file && currentErrors.current.sourceLocation.file === file) return } // if current file is changed while debugging and one of the files imported in test file are opened // do not clear the test results in SUT plugin @@ -469,7 +469,7 @@ export const SolidityUnitTesting = (props: Record) => { if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { // show only file name renderContract(filename, null, -1, true) - currentErrors = _errors.errors + currentErrors.current = _errors.errors } if (result) { const totalTime = parseFloat(result.totalTime).toFixed(2) From be40962acc50e9427827eafdcce06a06cb2e04e1 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 29 Dec 2021 13:37:35 +0530 Subject: [PATCH 099/103] debug tests e2e fixed --- .../src/lib/solidity-unit-testing.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 ca3dafbd57..4ff6721143 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 @@ -47,12 +47,13 @@ export const SolidityUnitTesting = (props: Record) => { let [runningTestsNumber, setRunningTestsNumber] = useState(0) // eslint-disable-line const hasBeenStopped = useRef(false) + const isDebugging = useRef(false) const allTests: any = useRef([]) const selectedTests: any = useRef([]) const currentErrors: any = useRef([]) + let areTestsRunning = false - let isDebugging = false let runningTestFileName: any const filesContent: any = {} @@ -82,7 +83,7 @@ export const SolidityUnitTesting = (props: Record) => { } // if current file is changed while debugging and one of the files imported in test file are opened // do not clear the test results in SUT plugin - if (isDebugging && testTab.allFilesInvolved.includes(file)) return + if (isDebugging.current && testTab.allFilesInvolved.includes(file)) return allTests.current = [] updateTestFileList() clearResults() @@ -220,7 +221,7 @@ export const SolidityUnitTesting = (props: Record) => { } const startDebug = async (txHash: any, web3: any) => { - isDebugging = true + isDebugging.current = true if (!await testTab.appManager.isActive('debugger')) await testTab.appManager.activatePlugin('debugger') testTab.call('menuicons', 'select', 'debugger') testTab.call('debugger', 'debug', txHash, web3) @@ -501,7 +502,7 @@ export const SolidityUnitTesting = (props: Record) => { } const runTest = (testFilePath: any, callback: any) => { - isDebugging = false + isDebugging.current = false if (hasBeenStopped.current) { updateFinalResult(null, null, null) return From bdd18708ddf7ce7d5c450f3242cbe4fc9c036575 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 29 Dec 2021 18:03:39 +0530 Subject: [PATCH 100/103] check fail label --- .../src/tests/solidityUnittests.test.ts | 1 + .../src/lib/solidity-unit-testing.tsx | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts index 16129f4063..200829b039 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts @@ -66,6 +66,7 @@ module.exports = { .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', '✘ Should fail for wrong value200', 120000) .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Passed: 2', 120000) .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Failed: 1', 120000) + .verify.elementPresent('.failed_tests_simple_storage_test_solMyTest') }, 'Should run advance unit test using natspec and experimental ABIEncoderV2 `ks2b_test.sol` #group2': function (browser: NightwatchBrowser) { 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 4ff6721143..97deaec103 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 @@ -279,18 +279,23 @@ export const SolidityUnitTesting = (props: Record) => { return } let label - if (index > -1) label = (
-1) { + const className = "alert-danger d-inline-block mb-1 mr-1 p-1 failed_" + runningTestFileName + label = (
FAIL
) - else label = (
PASS
) + } // show contract and file name with label const ContractCard: any = (
From 80199f2d520f3299ebf2b6ce62cd8a1fd4a976f4 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 29 Dec 2021 18:05:12 +0530 Subject: [PATCH 101/103] comment --- apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts index 200829b039..df2e599fc5 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts @@ -66,6 +66,7 @@ module.exports = { .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', '✘ Should fail for wrong value200', 120000) .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Passed: 2', 120000) .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Failed: 1', 120000) + // '.failed_tests_simple_storage_test_solMyTest' is the class for 'FAIL' label .verify.elementPresent('.failed_tests_simple_storage_test_solMyTest') }, From 23a512ec6996bbb050c6e3340f402524eb217a16 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 30 Dec 2021 19:50:12 +0530 Subject: [PATCH 102/103] check label too in e2e tests --- apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts index df2e599fc5..1ca31687c9 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts @@ -66,6 +66,7 @@ module.exports = { .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', '✘ Should fail for wrong value200', 120000) .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Passed: 2', 120000) .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'Failed: 1', 120000) + .waitForElementContainsText('*[data-id="testTabSolidityUnitTestsOutput"]', 'FAILMyTest (tests/simple_storage_test.sol)', 120000) // '.failed_tests_simple_storage_test_solMyTest' is the class for 'FAIL' label .verify.elementPresent('.failed_tests_simple_storage_test_solMyTest') }, From aaeaa697441accfdd305f576348c46b45641fe9f Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 30 Dec 2021 20:22:21 +0530 Subject: [PATCH 103/103] build fix --- workspace.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workspace.json b/workspace.json index 442f45229f..1718e70f69 100644 --- a/workspace.json +++ b/workspace.json @@ -1149,7 +1149,8 @@ } } } - }, + } + }, "cli": { "defaultCollection": "@nrwl/react" }, @@ -1185,5 +1186,4 @@ } }, "defaultProject": "remix-ide" - } }