From 0578fb0179be462c1dcc101aae9497a9bcca8708 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 26 Oct 2021 19:40:30 +0530 Subject: [PATCH 01/33] do not throw error if storage is not available --- libs/remix-lib/src/web3Provider/web3VmProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-lib/src/web3Provider/web3VmProvider.ts b/libs/remix-lib/src/web3Provider/web3VmProvider.ts index f29e225e5a..fa70b9d707 100644 --- a/libs/remix-lib/src/web3Provider/web3VmProvider.ts +++ b/libs/remix-lib/src/web3Provider/web3VmProvider.ts @@ -304,7 +304,7 @@ export class Web3VmProvider { nextKey: null }) } - cb('unable to retrieve storage ' + txIndex + ' ' + address) + cb(null, {}) } getBlockNumber (cb) { cb(null, 'vm provider') } From 4a633d2c5187b8f451e6dc58656047d09a3d3eb1 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 27 Oct 2021 11:44:36 +0530 Subject: [PATCH 02/33] storage as blank obj --- libs/remix-lib/src/web3Provider/web3VmProvider.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/remix-lib/src/web3Provider/web3VmProvider.ts b/libs/remix-lib/src/web3Provider/web3VmProvider.ts index fa70b9d707..e6e9a73bf9 100644 --- a/libs/remix-lib/src/web3Provider/web3VmProvider.ts +++ b/libs/remix-lib/src/web3Provider/web3VmProvider.ts @@ -304,7 +304,9 @@ export class Web3VmProvider { nextKey: null }) } - cb(null, {}) + // Before https://github.com/ethereum/remix-project/pull/1703, it used to throw error as + // 'unable to retrieve storage ' + txIndex + ' ' + address + cb(null, { storage: {}}) } getBlockNumber (cb) { cb(null, 'vm provider') } From dbc4cf3ec1ca17916175d9f11776f78053e17865 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 27 Oct 2021 12:00:04 +0530 Subject: [PATCH 03/33] linting fix --- libs/remix-lib/src/web3Provider/web3VmProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/remix-lib/src/web3Provider/web3VmProvider.ts b/libs/remix-lib/src/web3Provider/web3VmProvider.ts index e6e9a73bf9..49fa4d80a9 100644 --- a/libs/remix-lib/src/web3Provider/web3VmProvider.ts +++ b/libs/remix-lib/src/web3Provider/web3VmProvider.ts @@ -304,9 +304,9 @@ export class Web3VmProvider { nextKey: null }) } - // Before https://github.com/ethereum/remix-project/pull/1703, it used to throw error as + // Before https://github.com/ethereum/remix-project/pull/1703, it used to throw error as // 'unable to retrieve storage ' + txIndex + ' ' + address - cb(null, { storage: {}}) + cb(null, { storage: {} }) } getBlockNumber (cb) { cb(null, 'vm provider') } From 211c7fbbfb04a04a74ba6b91b22c511278d77b0d Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 27 Oct 2021 19:44:13 +0530 Subject: [PATCH 04/33] handle test files --- .../src/lib/compiler-content-imports.ts | 11 ++++++++++- libs/remix-tests/src/compiler.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 2e20d5ebb7..fb21cf0349 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -106,6 +106,13 @@ export class CompilerImports extends Plugin { }) } + async importTestFiles () { + const provider = await this.call('fileManager', 'getProviderOf', null) + const content = remixTests.assertLibCode + if (provider) provider.addExternal('.deps/remix-tests/remix-tests.sol', content, 'remix_tests.sol') + return content + } + /** * import the content of @arg url. * first look in the browser localstorage (browser explorer) or locahost explorer. if the url start with `browser/*` or `localhost/*` @@ -117,7 +124,9 @@ export class CompilerImports extends Plugin { * @returns {Promise} - string content */ async resolveAndSave (url, targetPath) { - if (url.indexOf('remix_tests.sol') !== -1) return remixTests.assertLibCode + if (url.indexOf('remix_tests.sol') !== -1) { + return await this.importTestFiles() + } try { const provider = await this.call('fileManager', 'getProviderOf', url) if (provider) { diff --git a/libs/remix-tests/src/compiler.ts b/libs/remix-tests/src/compiler.ts index e15bb656e4..ee1846b7a3 100644 --- a/libs/remix-tests/src/compiler.ts +++ b/libs/remix-tests/src/compiler.ts @@ -177,7 +177,7 @@ export function compileContractSources (sources: SrcIfc, compilerConfig: Compile // Iterate over sources keys. Inject test libraries. Inject test library import statements. if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) { sources['tests.sol'] = { content: require('../sol/tests.sol.js') } - sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } + // sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } sources['remix_accounts.sol'] = { content: writeTestAccountsContract(accounts) } } const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm From 4f0e42bf725dcd00a04869d537ef3d8b48d6cbd9 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 28 Oct 2021 13:49:22 +0530 Subject: [PATCH 05/33] test files created during compilation in SUT --- .../src/lib/compiler-content-imports.ts | 15 ++++++++------- libs/remix-tests/sol/tests_accounts.sol.ts | 2 +- libs/remix-tests/src/compiler.ts | 19 ++++++++++--------- libs/remix-tests/src/index.ts | 1 + 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index fb21cf0349..3dc0e05778 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -1,7 +1,8 @@ 'use strict' import { Plugin } from '@remixproject/engine' import { RemixURLResolver } from '@remix-project/remix-url-resolver' -const remixTests = require('@remix-project/remix-tests') +// const remixTests = require('@remix-project/remix-tests') +var { assertLibCode, getAccountsLib } = require('@remix-project/remix-tests') const profile = { name: 'contentImport', @@ -106,10 +107,12 @@ export class CompilerImports extends Plugin { }) } - async importTestFiles () { + async importTestFiles (url) { const provider = await this.call('fileManager', 'getProviderOf', null) - const content = remixTests.assertLibCode - if (provider) provider.addExternal('.deps/remix-tests/remix-tests.sol', content, 'remix_tests.sol') + let content + if (url === 'remix_tests.sol' || url === 'tests.sol') content = assertLibCode + else if (url === 'remix_accounts.sol') content = getAccountsLib() + if (provider) provider.addExternal('.deps/remix-tests/' + url, content, url) return content } @@ -124,9 +127,7 @@ export class CompilerImports extends Plugin { * @returns {Promise} - string content */ async resolveAndSave (url, targetPath) { - if (url.indexOf('remix_tests.sol') !== -1) { - return await this.importTestFiles() - } + if (['remix_tests.sol', 'tests.sol', 'remix_accounts.sol'].includes(url)) return await this.importTestFiles(url) try { const provider = await this.call('fileManager', 'getProviderOf', url) if (provider) { diff --git a/libs/remix-tests/sol/tests_accounts.sol.ts b/libs/remix-tests/sol/tests_accounts.sol.ts index d97aae8f34..847e37f083 100644 --- a/libs/remix-tests/sol/tests_accounts.sol.ts +++ b/libs/remix-tests/sol/tests_accounts.sol.ts @@ -3,7 +3,7 @@ module.exports = `// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.4.22 <0.9.0; library TestsAccounts { - function getAccount(uint index) public returns (address) { + function getAccount(uint index) pure public returns (address) { >accounts< return accounts[index]; } diff --git a/libs/remix-tests/src/compiler.ts b/libs/remix-tests/src/compiler.ts index ee1846b7a3..9477034d27 100644 --- a/libs/remix-tests/src/compiler.ts +++ b/libs/remix-tests/src/compiler.ts @@ -6,6 +6,11 @@ import { Compiler as RemixCompiler } from '@remix-project/remix-solidity' import { SrcIfc, CompilerConfiguration, CompilationErrors } from './types' const logger = new Log() const log = logger.logger +var accountsLibCode + +export function getAccountsLib () { + return accountsLibCode +} function regexIndexOf (inputString: string, regex: RegExp, startpos = 0) { const indexOf = inputString.substring(startpos).search(regex) @@ -18,10 +23,10 @@ function writeTestAccountsContract (accounts: string[]) { if (!accounts.length) body += ';' else { accounts.map((address, index) => { - body += `\naccounts[${index}] = ${address};\n` + body += `\n\t\taccounts[${index}] = ${address};\n` }) } - return testAccountContract.replace('>accounts<', body) + accountsLibCode = testAccountContract.replace('>accounts<', body) } /** @@ -87,10 +92,11 @@ const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' elect export function compileFileOrFiles (filename: string, isDirectory: boolean, opts: any, compilerConfig: CompilerConfiguration, cb): void { let compiler: any const accounts: string[] = opts.accounts || [] + writeTestAccountsContract(accounts) const sources: SrcIfc = { 'tests.sol': { content: require('../sol/tests.sol') }, 'remix_tests.sol': { content: require('../sol/tests.sol') }, - 'remix_accounts.sol': { content: writeTestAccountsContract(accounts) } + 'remix_accounts.sol': { content: getAccountsLib() } } const filepath: string = (isDirectory ? filename : path.dirname(filename)) try { @@ -173,13 +179,8 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts export function compileContractSources (sources: SrcIfc, compilerConfig: CompilerConfiguration, importFileCb: any, opts: any, cb): void { let compiler const accounts: string[] = opts.accounts || [] + writeTestAccountsContract(accounts) const filepath = opts.testFilePath || '' - // Iterate over sources keys. Inject test libraries. Inject test library import statements. - if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) { - sources['tests.sol'] = { content: require('../sol/tests.sol.js') } - // sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } - sources['remix_accounts.sol'] = { content: writeTestAccountsContract(accounts) } - } const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm const includeTestLibs = '\nimport \'remix_tests.sol\';\n' diff --git a/libs/remix-tests/src/index.ts b/libs/remix-tests/src/index.ts index 9552d5b5ee..0e979cdc9d 100644 --- a/libs/remix-tests/src/index.ts +++ b/libs/remix-tests/src/index.ts @@ -3,3 +3,4 @@ export { UnitTestRunner } from './runTestSources' export { runTest } from './testRunner' export * from './types' export const assertLibCode = require('../sol/tests.sol') +export { getAccountsLib } from './compiler' From 69995a9782a26bc5245d42d4c010cd6d37500dad Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 28 Oct 2021 13:58:59 +0530 Subject: [PATCH 06/33] linting fixed --- libs/remix-tests/src/compiler.ts | 2 +- libs/remix-tests/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/remix-tests/src/compiler.ts b/libs/remix-tests/src/compiler.ts index 9477034d27..299b121b62 100644 --- a/libs/remix-tests/src/compiler.ts +++ b/libs/remix-tests/src/compiler.ts @@ -9,7 +9,7 @@ const log = logger.logger var accountsLibCode export function getAccountsLib () { - return accountsLibCode + return accountsLibCode } function regexIndexOf (inputString: string, regex: RegExp, startpos = 0) { diff --git a/libs/remix-tests/src/index.ts b/libs/remix-tests/src/index.ts index 0e979cdc9d..986fb061c1 100644 --- a/libs/remix-tests/src/index.ts +++ b/libs/remix-tests/src/index.ts @@ -3,4 +3,4 @@ export { UnitTestRunner } from './runTestSources' export { runTest } from './testRunner' export * from './types' export const assertLibCode = require('../sol/tests.sol') -export { getAccountsLib } from './compiler' +export { getAccountsLib } from './compiler' From d75491b281afee9f10fc6a9652631bd3f179f426 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 28 Oct 2021 18:45:37 +0530 Subject: [PATCH 07/33] add test files to not reset the result --- apps/remix-ide/src/app/tabs/test-tab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 1995abe1f6..313f66c529 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -42,7 +42,7 @@ module.exports = class TestTab extends ViewPlugin { this.areTestsRunning = false this.defaultPath = 'tests' this.offsetToLineColumnConverter = offsetToLineColumnConverter - this.allFilesInvolved = [] + this.allFilesInvolved = ['.deps/remix-tests/remix_tests.sol', '.deps/remix-tests/remix_accounts.sol'] this.isDebugging = false this.currentErrors = [] @@ -112,7 +112,7 @@ module.exports = class TestTab extends ViewPlugin { this.testRunner.event.on('compilationFinished', (success, data, source) => { if (success) { - this.allFilesInvolved = Object.keys(data.sources) + this.allFilesInvolved.push(...Object.keys(data.sources)) // forwarding the event to the appManager infra // This is listened by compilerArtefacts to show data while debugging this.emit('compilationFinished', source.target, source, 'soljson', data) From acaef58da47219f1c2fe6f6cd200997e588b019b Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 28 Oct 2021 18:54:47 +0530 Subject: [PATCH 08/33] e2e updated --- apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts index 36eb781ac7..bc0c3f8e82 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts @@ -276,6 +276,8 @@ module.exports = { .setValue('*[data-id="slider"]', new Array(1).fill(browser.Keys.RIGHT_ARROW)) .waitForElementContainsText('*[data-id="functionPanel"]', 'equal(a, b, message)', 60000) .waitForElementContainsText('*[data-id="functionPanel"]', 'checkWinningProposalPassed()', 60000) + // remix_test.sol should be opened in editor + .getEditorValue((content) => browser.assert.ok(content.indexOf('library Assert {') !== -1)) .pause(1000) .clickLaunchIcon('solidityUnitTesting') .scrollAndClick('#Check_winning_proposal_again') From aefb8d2224310f6090eafd4c5888530debe54424 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 29 Oct 2021 14:49:22 +0530 Subject: [PATCH 09/33] create tests file on SUT activation --- apps/remix-ide/src/app/tabs/test-tab.js | 8 +++- .../src/lib/compiler-content-imports.ts | 12 ------ libs/remix-tests/src/compiler.ts | 14 ++----- libs/remix-tests/src/index.ts | 2 +- libs/remix-tests/src/runTestSources.ts | 40 +++++++++---------- 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 313f66c529..117a88769c 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -7,7 +7,7 @@ var async = require('async') var tooltip = require('../ui/tooltip') var Renderer = require('../ui/renderer') var css = require('./styles/test-tab-styles') -var { UnitTestRunner } = require('@remix-project/remix-tests') +var { UnitTestRunner, assertLibCode } = require('@remix-project/remix-tests') const _paq = window._paq = window._paq || [] @@ -79,6 +79,12 @@ module.exports = class TestTab extends ViewPlugin { if (!isSolidityActive) { await this.call('manager', 'activatePlugin', 'solidity') } + await this.testRunner.init() + const provider = await this.fileManager.getProviderOf() + if (provider) { + provider.addExternal('.deps/remix-tests/remix_tests.sol', assertLibCode, 'remix_tests.sol') + provider.addExternal('.deps/remix-tests/remix_accounts.sol', this.testRunner.accountsLibCode, 'remix_accounts.sol') + } this.updateRunAction() } diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 3dc0e05778..8c243e37a8 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -1,8 +1,6 @@ 'use strict' import { Plugin } from '@remixproject/engine' import { RemixURLResolver } from '@remix-project/remix-url-resolver' -// const remixTests = require('@remix-project/remix-tests') -var { assertLibCode, getAccountsLib } = require('@remix-project/remix-tests') const profile = { name: 'contentImport', @@ -107,15 +105,6 @@ export class CompilerImports extends Plugin { }) } - async importTestFiles (url) { - const provider = await this.call('fileManager', 'getProviderOf', null) - let content - if (url === 'remix_tests.sol' || url === 'tests.sol') content = assertLibCode - else if (url === 'remix_accounts.sol') content = getAccountsLib() - if (provider) provider.addExternal('.deps/remix-tests/' + url, content, url) - return content - } - /** * import the content of @arg url. * first look in the browser localstorage (browser explorer) or locahost explorer. if the url start with `browser/*` or `localhost/*` @@ -127,7 +116,6 @@ export class CompilerImports extends Plugin { * @returns {Promise} - string content */ async resolveAndSave (url, targetPath) { - if (['remix_tests.sol', 'tests.sol', 'remix_accounts.sol'].includes(url)) return await this.importTestFiles(url) try { const provider = await this.call('fileManager', 'getProviderOf', url) if (provider) { diff --git a/libs/remix-tests/src/compiler.ts b/libs/remix-tests/src/compiler.ts index 299b121b62..f4b9250ecf 100644 --- a/libs/remix-tests/src/compiler.ts +++ b/libs/remix-tests/src/compiler.ts @@ -6,18 +6,13 @@ import { Compiler as RemixCompiler } from '@remix-project/remix-solidity' import { SrcIfc, CompilerConfiguration, CompilationErrors } from './types' const logger = new Log() const log = logger.logger -var accountsLibCode - -export function getAccountsLib () { - return accountsLibCode -} function regexIndexOf (inputString: string, regex: RegExp, startpos = 0) { const indexOf = inputString.substring(startpos).search(regex) return (indexOf >= 0) ? (indexOf + (startpos)) : indexOf } -function writeTestAccountsContract (accounts: string[]) { +export function writeTestAccountsContract (accounts: string[]) { const testAccountContract = require('../sol/tests_accounts.sol') let body = `address[${accounts.length}] memory accounts;` if (!accounts.length) body += ';' @@ -26,7 +21,7 @@ function writeTestAccountsContract (accounts: string[]) { body += `\n\t\taccounts[${index}] = ${address};\n` }) } - accountsLibCode = testAccountContract.replace('>accounts<', body) + return testAccountContract.replace('>accounts<', body) } /** @@ -92,11 +87,10 @@ const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' elect export function compileFileOrFiles (filename: string, isDirectory: boolean, opts: any, compilerConfig: CompilerConfiguration, cb): void { let compiler: any const accounts: string[] = opts.accounts || [] - writeTestAccountsContract(accounts) const sources: SrcIfc = { 'tests.sol': { content: require('../sol/tests.sol') }, 'remix_tests.sol': { content: require('../sol/tests.sol') }, - 'remix_accounts.sol': { content: getAccountsLib() } + 'remix_accounts.sol': { content: writeTestAccountsContract(accounts) } } const filepath: string = (isDirectory ? filename : path.dirname(filename)) try { @@ -178,8 +172,6 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts */ export function compileContractSources (sources: SrcIfc, compilerConfig: CompilerConfiguration, importFileCb: any, opts: any, cb): void { let compiler - const accounts: string[] = opts.accounts || [] - writeTestAccountsContract(accounts) const filepath = opts.testFilePath || '' const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm diff --git a/libs/remix-tests/src/index.ts b/libs/remix-tests/src/index.ts index 986fb061c1..37862a47c6 100644 --- a/libs/remix-tests/src/index.ts +++ b/libs/remix-tests/src/index.ts @@ -3,4 +3,4 @@ export { UnitTestRunner } from './runTestSources' export { runTest } from './testRunner' export * from './types' export const assertLibCode = require('../sol/tests.sol') -export { getAccountsLib } from './compiler' +export { writeTestAccountsContract } from './compiler' diff --git a/libs/remix-tests/src/runTestSources.ts b/libs/remix-tests/src/runTestSources.ts index ecc35aa3f2..33825fbc91 100644 --- a/libs/remix-tests/src/runTestSources.ts +++ b/libs/remix-tests/src/runTestSources.ts @@ -1,9 +1,7 @@ import async, { ErrorCallback } from 'async' - -import { compileContractSources } from './compiler' +import { compileContractSources, writeTestAccountsContract } from './compiler' import { deployAll } from './deployer' import { runTest } from './testRunner' - import Web3 from 'web3' import { EventEmitter } from 'events' import { Provider, extend } from '@remix-project/remix-simulator' @@ -15,13 +13,22 @@ require('colors') export class UnitTestRunner { event + accountsLibCode + testsAccounts: string[] | null + web3 constructor () { this.event = new EventEmitter() } - async createWeb3Provider () { - const web3 = new Web3() + async init (web3 = null, accounts = null) { + this.web3 = await this.createWeb3Provider(web3) + this.testsAccounts = accounts || await this.web3.eth.getAccounts() + this.accountsLibCode = writeTestAccountsContract(this.testsAccounts) + } + + async createWeb3Provider (optWeb3) { + const web3 = optWeb3 || new Web3() const provider: any = new Provider() await provider.init() web3.setProvider(provider) @@ -42,30 +49,23 @@ export class UnitTestRunner { async runTestSources (contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback, resultCallback, deployCb:any, finalCallback: any, importFileCb, opts: Options) { opts = opts || {} const sourceASTs: any = {} - const web3 = opts.web3 || await this.createWeb3Provider() - let accounts: string[] | null = opts.accounts || null + if (opts.web3 || opts.accounts) this.init(opts.web3, opts.accounts) + async.waterfall([ - function getAccountList (next) { - if (accounts) return next() - web3.eth.getAccounts((_err, _accounts) => { - accounts = _accounts - next() - }) - }, (next) => { - compileContractSources(contractSources, compilerConfig, importFileCb, { accounts, testFilePath: opts.testFilePath, event: this.event }, next) + compileContractSources(contractSources, compilerConfig, importFileCb, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next) }, - function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) { + (compilationResult: compilationInterface, asts: ASTInterface, next) => { for (const filename in asts) { if (filename.endsWith('_test.sol')) { sourceASTs[filename] = asts[filename].ast } } - deployAll(compilationResult, web3, false, deployCb, (err, contracts) => { + deployAll(compilationResult, this.web3, false, deployCb, (err, contracts) => { if (err) { // If contract deployment fails because of 'Out of Gas' error, try again with double gas // This is temporary, should be removed when remix-tests will have a dedicated UI to // accept deployment params from UI if (err.message.includes('The contract code couldn\'t be stored, please check your gas limit')) { - deployAll(compilationResult, web3, true, deployCb, (error, contracts) => { + deployAll(compilationResult, this.web3, true, deployCb, (error, contracts) => { if (error) next([{ message: 'contract deployment failed after trying twice: ' + error.message, severity: 'error' }]) // IDE expects errors in array else next(null, compilationResult, contracts) }) @@ -88,7 +88,7 @@ export class UnitTestRunner { } next(null, contractsToTest, contractsToTestDetails, contracts) }, - function runTests (contractsToTest: string[], contractsToTestDetails: any[], contracts: any, next) { + (contractsToTest: string[], contractsToTestDetails: any[], contracts: any, next) => { let totalPassing = 0 let totalFailing = 0 let totalTime = 0 @@ -111,7 +111,7 @@ export class UnitTestRunner { async.eachOfLimit(contractsToTest, 1, (contractName: string, index: string | number, cb: ErrorCallback) => { const fileAST: AstNode = sourceASTs[contracts[contractName]['filename']] - runTest(contractName, contracts[contractName], contractsToTestDetails[index], fileAST, { accounts, web3 }, _testCallback, (err, result) => { + runTest(contractName, contracts[contractName], contractsToTestDetails[index], fileAST, { accounts: this.testsAccounts, web3: this.web3 }, _testCallback, (err, result) => { if (err) { return cb(err) } From 314a51ea0bc0f71c2be9594a5108143b1f732317 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 29 Oct 2021 18:44:02 +0530 Subject: [PATCH 10/33] fix content-import --- libs/remix-core-plugin/src/lib/compiler-content-imports.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 8c243e37a8..2e20d5ebb7 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -1,6 +1,7 @@ 'use strict' import { Plugin } from '@remixproject/engine' import { RemixURLResolver } from '@remix-project/remix-url-resolver' +const remixTests = require('@remix-project/remix-tests') const profile = { name: 'contentImport', @@ -116,6 +117,7 @@ export class CompilerImports extends Plugin { * @returns {Promise} - string content */ async resolveAndSave (url, targetPath) { + if (url.indexOf('remix_tests.sol') !== -1) return remixTests.assertLibCode try { const provider = await this.call('fileManager', 'getProviderOf', url) if (provider) { From da3e3dfd556904a9285c625f7f5cb2fe412e85c1 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 29 Oct 2021 19:20:08 +0530 Subject: [PATCH 11/33] fetch test files --- apps/remix-ide/src/app/tabs/test-tab.js | 6 +++++- libs/remix-core-plugin/src/lib/compiler-content-imports.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 117a88769c..21837df752 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -16,7 +16,7 @@ const TestTabLogic = require('./testTab/testTab') const profile = { name: 'solidityUnitTesting', displayName: 'Solidity unit testing', - methods: ['testFromPath', 'testFromSource', 'setTestFolderPath'], + methods: ['testFromPath', 'testFromSource', 'setTestFolderPath', 'getTestlibs'], events: [], icon: 'assets/img/unitTesting.webp', description: 'Fast tool to generate unit tests for your contracts', @@ -74,6 +74,10 @@ module.exports = class TestTab extends ViewPlugin { } } + getTestlibs() { + return { assertLibCode, accountsLibCode: this.testRunner.accountsLibCode} + } + async onActivation () { const isSolidityActive = await this.call('manager', 'isActive', 'solidity') if (!isSolidityActive) { diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 2e20d5ebb7..1d1cacc5ca 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -117,7 +117,11 @@ export class CompilerImports extends Plugin { * @returns {Promise} - string content */ async resolveAndSave (url, targetPath) { - if (url.indexOf('remix_tests.sol') !== -1) return remixTests.assertLibCode + if (url.indexOf('remix_tests.sol') !== -1 || url.indexOf('remix_accounts.sol') !== -1) { + const {assertLibCode, accountsLibCode} = await this.call('solidityUnitTesting', 'getTestlibs') + if (url === 'remix_tests.sol') return assertLibCode + else if (url === 'remix_accounts.sol') return accountsLibCode + } try { const provider = await this.call('fileManager', 'getProviderOf', url) if (provider) { From eaf54ac586f334f6b1b9ebca031a2e841d41587a Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 29 Oct 2021 19:30:39 +0530 Subject: [PATCH 12/33] linting fix --- libs/remix-core-plugin/src/lib/compiler-content-imports.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 1d1cacc5ca..803205868a 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -1,7 +1,6 @@ 'use strict' import { Plugin } from '@remixproject/engine' import { RemixURLResolver } from '@remix-project/remix-url-resolver' -const remixTests = require('@remix-project/remix-tests') const profile = { name: 'contentImport', @@ -118,7 +117,7 @@ export class CompilerImports extends Plugin { */ async resolveAndSave (url, targetPath) { if (url.indexOf('remix_tests.sol') !== -1 || url.indexOf('remix_accounts.sol') !== -1) { - const {assertLibCode, accountsLibCode} = await this.call('solidityUnitTesting', 'getTestlibs') + const { assertLibCode, accountsLibCode } = await this.call('solidityUnitTesting', 'getTestlibs') if (url === 'remix_tests.sol') return assertLibCode else if (url === 'remix_accounts.sol') return accountsLibCode } From 973761224fac34d8710b973ad2afd4b331ce73be Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 29 Oct 2021 19:40:59 +0530 Subject: [PATCH 13/33] linting fix for ide --- apps/remix-ide/src/app/tabs/test-tab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 21837df752..c741025ca5 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -74,8 +74,8 @@ module.exports = class TestTab extends ViewPlugin { } } - getTestlibs() { - return { assertLibCode, accountsLibCode: this.testRunner.accountsLibCode} + getTestlibs () { + return { assertLibCode, accountsLibCode: this.testRunner.accountsLibCode } } async onActivation () { From 9feca14950281c38ee3a95debf791a7655e97f71 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 1 Nov 2021 15:06:05 +0530 Subject: [PATCH 14/33] browser console error fixed by mapping --- apps/remix-ide/src/app/files/fileProvider.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index ea46dd8b72..d5873e43ef 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -17,8 +17,9 @@ class FileProvider { } addNormalizedName (path, url) { - this.providerExternalsStorage.set(this.type + '/' + path, url) - this.providerExternalsStorage.set(this.reverseKey + url, this.type + '/' + path) + if (this.type) path = this.type + '/' + path + this.providerExternalsStorage.set(path, url) + this.providerExternalsStorage.set(this.reverseKey + url, path) } removeNormalizedName (path) { From afb8e519d38c9b379b28ffc15b70b75813796e95 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 1 Nov 2021 16:45:41 +0530 Subject: [PATCH 15/33] create test files while running tests --- .../remix-core-plugin/src/lib/compiler-content-imports.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 803205868a..bab2c15de8 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -118,8 +118,12 @@ export class CompilerImports extends Plugin { async resolveAndSave (url, targetPath) { if (url.indexOf('remix_tests.sol') !== -1 || url.indexOf('remix_accounts.sol') !== -1) { const { assertLibCode, accountsLibCode } = await this.call('solidityUnitTesting', 'getTestlibs') - if (url === 'remix_tests.sol') return assertLibCode - else if (url === 'remix_accounts.sol') return accountsLibCode + let content + if (url === 'remix_tests.sol') content = assertLibCode + else if (url === 'remix_accounts.sol') content = accountsLibCode + const provider = await this.call('fileManager', 'getProviderOf', null) + if (provider) provider.addExternal('.deps/remix-tests/' + url, content, url) + return content } try { const provider = await this.call('fileManager', 'getProviderOf', url) From abeb06143b383c471fa2cf1ac42f3a810fb7b04c Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 1 Nov 2021 16:56:58 +0530 Subject: [PATCH 16/33] linting fix --- libs/remix-core-plugin/src/lib/compiler-content-imports.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index bab2c15de8..d9c8b19e89 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -119,7 +119,7 @@ export class CompilerImports extends Plugin { if (url.indexOf('remix_tests.sol') !== -1 || url.indexOf('remix_accounts.sol') !== -1) { const { assertLibCode, accountsLibCode } = await this.call('solidityUnitTesting', 'getTestlibs') let content - if (url === 'remix_tests.sol') content = assertLibCode + if (url === 'remix_tests.sol') content = assertLibCode else if (url === 'remix_accounts.sol') content = accountsLibCode const provider = await this.call('fileManager', 'getProviderOf', null) if (provider) provider.addExternal('.deps/remix-tests/' + url, content, url) From cfc222c8027c52cb52370cfa2cc1fc23f79652c8 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 2 Nov 2021 11:32:34 +0530 Subject: [PATCH 17/33] current provider --- apps/remix-ide/src/app/tabs/test-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index c741025ca5..86f8938e5b 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -84,7 +84,7 @@ module.exports = class TestTab extends ViewPlugin { await this.call('manager', 'activatePlugin', 'solidity') } await this.testRunner.init() - const provider = await this.fileManager.getProviderOf() + const provider = await this.fileManager.currentFileProvider() if (provider) { provider.addExternal('.deps/remix-tests/remix_tests.sol', assertLibCode, 'remix_tests.sol') provider.addExternal('.deps/remix-tests/remix_accounts.sol', this.testRunner.accountsLibCode, 'remix_accounts.sol') From df93f61838f36e36ce1191e9ae6240f77d7e7d67 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 5 Nov 2021 16:08:09 +0530 Subject: [PATCH 18/33] test accounts for deployment --- libs/remix-tests/src/deployer.ts | 10 ++-------- libs/remix-tests/src/runTestFiles.ts | 4 ++-- libs/remix-tests/src/runTestSources.ts | 4 ++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/libs/remix-tests/src/deployer.ts b/libs/remix-tests/src/deployer.ts index d700b08de5..e2a5e6cb04 100644 --- a/libs/remix-tests/src/deployer.ts +++ b/libs/remix-tests/src/deployer.ts @@ -11,18 +11,12 @@ import { compilationInterface } from './types' * @param callback Callback */ -export function deployAll (compileResult: compilationInterface, web3: Web3, withDoubleGas: boolean, deployCb, callback) { +export function deployAll (compileResult: compilationInterface, web3: Web3, testsAccounts, withDoubleGas: boolean, deployCb, callback) { const compiledObject = {} const contracts = {} - let accounts: string[] = [] + let accounts: string[] = testsAccounts async.waterfall([ - function getAccountList (next) { - web3.eth.getAccounts((_err, _accounts) => { - accounts = _accounts - next() - }) - }, function getContractData (next) { for (const contractFile in compileResult) { for (const contractName in compileResult[contractFile]) { diff --git a/libs/remix-tests/src/runTestFiles.ts b/libs/remix-tests/src/runTestFiles.ts index d9ed0c2b6e..dbf2b16e46 100644 --- a/libs/remix-tests/src/runTestFiles.ts +++ b/libs/remix-tests/src/runTestFiles.ts @@ -61,13 +61,13 @@ export function runTestFiles (filepath: string, isDirectory: boolean, web3: Web3 for (const filename in asts) { if (filename.endsWith('_test.sol')) { sourceASTs[filename] = asts[filename].ast } } - deployAll(compilationResult, web3, false, null, (err, contracts) => { + deployAll(compilationResult, web3, accounts, false, null, (err, contracts) => { if (err) { // If contract deployment fails because of 'Out of Gas' error, try again with double gas // This is temporary, should be removed when remix-tests will have a dedicated UI to // accept deployment params from UI if (err.message.includes('The contract code couldn\'t be stored, please check your gas limit')) { - deployAll(compilationResult, web3, true, null, (error, contracts) => { + deployAll(compilationResult, web3, accounts, true, null, (error, contracts) => { if (error) next([{ message: 'contract deployment failed after trying twice: ' + error.message, severity: 'error' }]) // IDE expects errors in array else next(null, compilationResult, contracts) }) diff --git a/libs/remix-tests/src/runTestSources.ts b/libs/remix-tests/src/runTestSources.ts index 33825fbc91..9d8b8ba400 100644 --- a/libs/remix-tests/src/runTestSources.ts +++ b/libs/remix-tests/src/runTestSources.ts @@ -59,13 +59,13 @@ export class UnitTestRunner { for (const filename in asts) { if (filename.endsWith('_test.sol')) { sourceASTs[filename] = asts[filename].ast } } - deployAll(compilationResult, this.web3, false, deployCb, (err, contracts) => { + deployAll(compilationResult, this.web3, this.testsAccounts, false, deployCb, (err, contracts) => { if (err) { // If contract deployment fails because of 'Out of Gas' error, try again with double gas // This is temporary, should be removed when remix-tests will have a dedicated UI to // accept deployment params from UI if (err.message.includes('The contract code couldn\'t be stored, please check your gas limit')) { - deployAll(compilationResult, this.web3, true, deployCb, (error, contracts) => { + deployAll(compilationResult, this.web3, this.testsAccounts, true, deployCb, (error, contracts) => { if (error) next([{ message: 'contract deployment failed after trying twice: ' + error.message, severity: 'error' }]) // IDE expects errors in array else next(null, compilationResult, contracts) }) From 5ec431b02f54071cc6468638f67e338d31668427 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 11:33:50 +0530 Subject: [PATCH 19/33] linting fix --- libs/remix-tests/src/deployer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-tests/src/deployer.ts b/libs/remix-tests/src/deployer.ts index e2a5e6cb04..505281fe00 100644 --- a/libs/remix-tests/src/deployer.ts +++ b/libs/remix-tests/src/deployer.ts @@ -14,7 +14,7 @@ import { compilationInterface } from './types' export function deployAll (compileResult: compilationInterface, web3: Web3, testsAccounts, withDoubleGas: boolean, deployCb, callback) { const compiledObject = {} const contracts = {} - let accounts: string[] = testsAccounts + const accounts: string[] = testsAccounts async.waterfall([ function getContractData (next) { From cee026f9432f5fb43398216a76b31dd921719938 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 12:18:59 +0530 Subject: [PATCH 20/33] SUT plugin call removed --- .../src/lib/compiler-content-imports.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index d9c8b19e89..227c8cd2f1 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -1,6 +1,7 @@ 'use strict' import { Plugin } from '@remixproject/engine' import { RemixURLResolver } from '@remix-project/remix-url-resolver' +import { UnitTestRunner, assertLibCode } from '@remix-project/remix-tests' const profile = { name: 'contentImport', @@ -12,6 +13,7 @@ const profile = { export class CompilerImports extends Plugin { previouslyHandled: {} urlResolver: any + testRunner: any constructor () { super(profile) this.urlResolver = new RemixURLResolver() @@ -117,10 +119,13 @@ export class CompilerImports extends Plugin { */ async resolveAndSave (url, targetPath) { if (url.indexOf('remix_tests.sol') !== -1 || url.indexOf('remix_accounts.sol') !== -1) { - const { assertLibCode, accountsLibCode } = await this.call('solidityUnitTesting', 'getTestlibs') let content if (url === 'remix_tests.sol') content = assertLibCode - else if (url === 'remix_accounts.sol') content = accountsLibCode + else if (url === 'remix_accounts.sol') { + this.testRunner = new UnitTestRunner() + await this.testRunner.init() + content = this.testRunner.accountsLibCode + } const provider = await this.call('fileManager', 'getProviderOf', null) if (provider) provider.addExternal('.deps/remix-tests/' + url, content, url) return content From e88392f918d0d7482ce41ce7cb0633eb624d35f6 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 12:19:32 +0530 Subject: [PATCH 21/33] remix-tests unit tests fixed --- libs/remix-tests/tests/testRunner.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-tests/tests/testRunner.spec.ts b/libs/remix-tests/tests/testRunner.spec.ts index 928491faa5..95dd221b64 100644 --- a/libs/remix-tests/tests/testRunner.spec.ts +++ b/libs/remix-tests/tests/testRunner.spec.ts @@ -67,7 +67,7 @@ async function compileAndDeploy(filename: string, callback: Function) { } try { compilationData = compilationResult - deployAll(compilationResult, web3, false, null, next) + deployAll(compilationResult, web3, null, false, null, next) } catch (e) { throw e } From 7b8bdd45bfae9231e27ec6376e461cb88e6e9f69 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 12:52:10 +0530 Subject: [PATCH 22/33] accounts passed for unit tests --- libs/remix-tests/tests/testRunner.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-tests/tests/testRunner.spec.ts b/libs/remix-tests/tests/testRunner.spec.ts index 95dd221b64..2f6d363a31 100644 --- a/libs/remix-tests/tests/testRunner.spec.ts +++ b/libs/remix-tests/tests/testRunner.spec.ts @@ -67,7 +67,7 @@ async function compileAndDeploy(filename: string, callback: Function) { } try { compilationData = compilationResult - deployAll(compilationResult, web3, null, false, null, next) + deployAll(compilationResult, web3, accounts, false, null, next) } catch (e) { throw e } From fc5d6f9bee6f39515c06f2a778b00c4d02ece35a Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 16:47:02 +0530 Subject: [PATCH 23/33] instance creation removed --- apps/remix-ide/src/app/tabs/test-tab.js | 2 +- .../remix-core-plugin/src/lib/compiler-content-imports.ts | 8 ++------ 2 files changed, 3 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 86f8938e5b..5a243fae45 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -559,7 +559,7 @@ module.exports = class TestTab extends ViewPlugin { this.updateFinalResult(error, result, testFilePath) callback(error) }, (url, cb) => { - return this.contentImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message)) + return this.contentImport.resolveAndSave(url, null, this.testRunner).then((result) => cb(null, result)).catch((error) => cb(error.message)) }, { testFilePath } ) }).catch((error) => { diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 227c8cd2f1..11c398f0a6 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -117,15 +117,11 @@ export class CompilerImports extends Plugin { * @param {String} targetPath - (optional) internal path where the content should be saved to * @returns {Promise} - string content */ - async resolveAndSave (url, targetPath) { + async resolveAndSave (url, targetPath, testRunner = null) { if (url.indexOf('remix_tests.sol') !== -1 || url.indexOf('remix_accounts.sol') !== -1) { let content if (url === 'remix_tests.sol') content = assertLibCode - else if (url === 'remix_accounts.sol') { - this.testRunner = new UnitTestRunner() - await this.testRunner.init() - content = this.testRunner.accountsLibCode - } + else if (url === 'remix_accounts.sol' && testRunner) content = testRunner.accountsLibCode const provider = await this.call('fileManager', 'getProviderOf', null) if (provider) provider.addExternal('.deps/remix-tests/' + url, content, url) return content From 4d95e3a6c65e0f7c0cb30bd0a0cdf29d53e7bccd Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 17:06:23 +0530 Subject: [PATCH 24/33] linting fix --- libs/remix-core-plugin/src/lib/compiler-content-imports.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 11c398f0a6..670ce0fda7 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -1,7 +1,7 @@ 'use strict' import { Plugin } from '@remixproject/engine' import { RemixURLResolver } from '@remix-project/remix-url-resolver' -import { UnitTestRunner, assertLibCode } from '@remix-project/remix-tests' +import { assertLibCode } from '@remix-project/remix-tests' const profile = { name: 'contentImport', From 682fcdde6f3a39ab6918277de4413336c0ff0b2d Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 18:06:57 +0530 Subject: [PATCH 25/33] use workspace event to create files --- apps/remix-ide/src/app/tabs/test-tab.js | 18 +++++++++++++----- .../src/lib/compiler-content-imports.ts | 8 -------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 5a243fae45..a7d586b025 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -78,17 +78,21 @@ module.exports = class TestTab extends ViewPlugin { return { assertLibCode, accountsLibCode: this.testRunner.accountsLibCode } } + async createTestLibs () { + const provider = await this.fileManager.currentFileProvider() + if (provider) { + provider.addExternal('.deps/remix-tests/remix_tests.sol', assertLibCode, 'remix_tests.sol') + provider.addExternal('.deps/remix-tests/remix_accounts.sol', this.testRunner.accountsLibCode, 'remix_accounts.sol') + } + } + async onActivation () { const isSolidityActive = await this.call('manager', 'isActive', 'solidity') if (!isSolidityActive) { await this.call('manager', 'activatePlugin', 'solidity') } await this.testRunner.init() - const provider = await this.fileManager.currentFileProvider() - if (provider) { - provider.addExternal('.deps/remix-tests/remix_tests.sol', assertLibCode, 'remix_tests.sol') - provider.addExternal('.deps/remix-tests/remix_accounts.sol', this.testRunner.accountsLibCode, 'remix_accounts.sol') - } + await this.createTestLibs() this.updateRunAction() } @@ -120,6 +124,10 @@ module.exports = class TestTab extends ViewPlugin { this.setCurrentPath(this.defaultPath) }) + this.on('filePanel', 'workspaceCreated', async () => { + this.createTestLibs() + }) + this.testRunner.event.on('compilationFinished', (success, data, source) => { if (success) { this.allFilesInvolved.push(...Object.keys(data.sources)) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 670ce0fda7..121e05f864 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -118,14 +118,6 @@ export class CompilerImports extends Plugin { * @returns {Promise} - string content */ async resolveAndSave (url, targetPath, testRunner = null) { - if (url.indexOf('remix_tests.sol') !== -1 || url.indexOf('remix_accounts.sol') !== -1) { - let content - if (url === 'remix_tests.sol') content = assertLibCode - else if (url === 'remix_accounts.sol' && testRunner) content = testRunner.accountsLibCode - const provider = await this.call('fileManager', 'getProviderOf', null) - if (provider) provider.addExternal('.deps/remix-tests/' + url, content, url) - return content - } try { const provider = await this.call('fileManager', 'getProviderOf', url) if (provider) { From b153b1dc459919de5e923fd8f33b6c210525430d Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 18:24:29 +0530 Subject: [PATCH 26/33] linting fix --- libs/remix-core-plugin/src/lib/compiler-content-imports.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 121e05f864..07b1f21213 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -1,7 +1,6 @@ 'use strict' import { Plugin } from '@remixproject/engine' import { RemixURLResolver } from '@remix-project/remix-url-resolver' -import { assertLibCode } from '@remix-project/remix-tests' const profile = { name: 'contentImport', From e0a0c94139fa58694efc492092b105b40a32ddef Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 18:50:04 +0530 Subject: [PATCH 27/33] e2e to check test files creation on SUT activation --- .../remix-ide-e2e/src/tests/solidityUnittests.spec.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts index bc0c3f8e82..3fb1a2bac6 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts @@ -13,7 +13,7 @@ module.exports = { return sources }, - 'Should launch solidity unit test plugin': function (browser: NightwatchBrowser) { + 'Should launch solidity unit test plugin and create test files in FE': function (browser: NightwatchBrowser) { browser.waitForElementPresent('*[data-id="verticalIconsKindfilePanel"]') .clickLaunchIcon('filePanel') .addFile('simple_storage.sol', sources[0]['simple_storage.sol']) @@ -23,6 +23,15 @@ module.exports = { .click('*[data-id="verticalIconsKindsolidityUnitTesting"]') .waitForElementPresent('*[data-id="sidePanelSwapitTitle"]') .assert.containsText('*[data-id="sidePanelSwapitTitle"]', 'SOLIDITY UNIT TESTING') + .clickLaunchIcon('filePanel') + .waitForElementVisible('li[data-id="treeViewLitreeViewItem.deps/remix-tests/remix_tests.sol"]') + .waitForElementVisible('li[data-id="treeViewLitreeViewItem.deps/remix-tests/remix_accounts.sol"]') + .openFile('.deps/remix-tests/remix_tests.sol') + // remix_test.sol should be opened in editor + .getEditorValue((content) => browser.assert.ok(content.indexOf('library Assert {') !== -1)) + .openFile('.deps/remix-tests/remix_accounts.sol') + // remix_accounts.sol should be opened in editor + .getEditorValue((content) => browser.assert.ok(content.indexOf('library TestsAccounts {') !== -1)) }, 'Should generate test file': function (browser: NightwatchBrowser) { From 2cf43652621d862d59ffe1ff877f084c84dbaba5 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 8 Nov 2021 18:55:51 +0530 Subject: [PATCH 28/33] e2e to check test files creation on new workspace --- apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts index 3fb1a2bac6..e5a4136eb5 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts @@ -159,7 +159,7 @@ module.exports = { .click('*[data-id="testTabGenerateTestFolder"]') }, - 'Changing current path when workspace changed': function (browser: NightwatchBrowser) { + 'Changing current path when workspace changed and checking test files creation': function (browser: NightwatchBrowser) { browser .waitForElementPresent('*[data-id="verticalIconsKindfilePanel"]') .clickLaunchIcon('settings') @@ -177,6 +177,14 @@ module.exports = { .waitForElementVisible('*[data-id="fileSystem-modal-footer-ok-react"]') .execute(function () { (document.querySelector('[data-id="fileSystem-modal-footer-ok-react"]') as HTMLElement).click() }) .waitForElementPresent('*[data-id="workspacesSelect"] option[value="workspace_new"]') + .waitForElementVisible('li[data-id="treeViewLitreeViewItem.deps/remix-tests/remix_tests.sol"]') + .waitForElementVisible('li[data-id="treeViewLitreeViewItem.deps/remix-tests/remix_accounts.sol"]') + .openFile('.deps/remix-tests/remix_tests.sol') + // remix_test.sol should be opened in editor + .getEditorValue((content) => browser.assert.ok(content.indexOf('library Assert {') !== -1)) + .openFile('.deps/remix-tests/remix_accounts.sol') + // remix_accounts.sol should be opened in editor + .getEditorValue((content) => browser.assert.ok(content.indexOf('library TestsAccounts {') !== -1)) // end of creating .clickLaunchIcon('solidityUnitTesting') .pause(2000) From e34c5857778605ddefb2ee7d4f1c1af428529a00 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 9 Nov 2021 14:36:42 +0530 Subject: [PATCH 29/33] extra changes removed --- libs/remix-core-plugin/src/lib/compiler-content-imports.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 07b1f21213..8c243e37a8 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -12,7 +12,6 @@ const profile = { export class CompilerImports extends Plugin { previouslyHandled: {} urlResolver: any - testRunner: any constructor () { super(profile) this.urlResolver = new RemixURLResolver() @@ -116,7 +115,7 @@ export class CompilerImports extends Plugin { * @param {String} targetPath - (optional) internal path where the content should be saved to * @returns {Promise} - string content */ - async resolveAndSave (url, targetPath, testRunner = null) { + async resolveAndSave (url, targetPath) { try { const provider = await this.call('fileManager', 'getProviderOf', url) if (provider) { From 66eef9003d3a40f2eb56b13fb7fca37f08195cb6 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 9 Nov 2021 18:32:23 +0530 Subject: [PATCH 30/33] unnecessary changes --- apps/remix-ide/src/app/tabs/test-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index a7d586b025..a50a2a1b9a 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -567,7 +567,7 @@ module.exports = class TestTab extends ViewPlugin { this.updateFinalResult(error, result, testFilePath) callback(error) }, (url, cb) => { - return this.contentImport.resolveAndSave(url, null, this.testRunner).then((result) => cb(null, result)).catch((error) => cb(error.message)) + return this.contentImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message)) }, { testFilePath } ) }).catch((error) => { From c2420dcae63c639d16be4d12bd143a51bc00dbb4 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 9 Nov 2021 15:41:40 +0100 Subject: [PATCH 31/33] Update webpack.config.js --- apps/remix-ide/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/webpack.config.js b/apps/remix-ide/webpack.config.js index 02143af15b..4af33b4f3a 100644 --- a/apps/remix-ide/webpack.config.js +++ b/apps/remix-ide/webpack.config.js @@ -21,7 +21,7 @@ module.exports = config => { mode: 'production', devtool: 'source-map', optimization: { - minimize: true, + minimize: false, minimizer: [new TerserPlugin()] } } From 66d3c11f8b4fbf25c3408e5f56ac534e5cb1d678 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 9 Nov 2021 14:19:26 +0530 Subject: [PATCH 32/33] SUT can load compiler parellel to Solidity Compiler plugin --- apps/remix-ide/src/app/tabs/test-tab.js | 5 +++-- apps/solidity-compiler/src/app/compiler-api.ts | 10 ++++++++-- 2 files changed, 11 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 a50a2a1b9a..5dbedd4448 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -544,8 +544,8 @@ module.exports = class TestTab extends ViewPlugin { this.fileManager.readFile(testFilePath).then((content) => { const runningTests = {} runningTests[testFilePath] = { content } - const { currentVersion, evmVersion, optimize, runs } = this.compileTab.getCurrentCompilerConfig() - const currentCompilerUrl = urlFromVersion(currentVersion) + const { currentVersion, evmVersion, optimize, runs, isUrl } = this.compileTab.getCurrentCompilerConfig() + const currentCompilerUrl = isUrl ? currentVersion : urlFromVersion(currentVersion) const compilerConfig = { currentCompilerUrl, evmVersion, @@ -571,6 +571,7 @@ module.exports = class TestTab extends ViewPlugin { }, { testFilePath } ) }).catch((error) => { + console.log('error in runTest-->', error) if (error) return // eslint-disable-line }) } diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 8082002ff4..733ee0026f 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -143,12 +143,17 @@ export const CompilerApiMixin = (Base) => class extends Base { // This function is used for passing the compiler configuration to 'remix-tests' getCurrentCompilerConfig () { const compilerState = this.getCompilerState() - return { + let compilerDetails: any = { currentVersion: compilerState.currentVersion, evmVersion: compilerState.evmVersion, optimize: compilerState.optimize, runs: compilerState.runs } + if (this.data.loading) { + compilerDetails.currentVersion = this.data.loadingUrl + compilerDetails.isUrl = true + } + return compilerDetails } /** @@ -193,8 +198,9 @@ export const CompilerApiMixin = (Base) => class extends Base { if (this.onContentChanged) this.onContentChanged() }) - this.data.eventHandlers.onLoadingCompiler = () => { + this.data.eventHandlers.onLoadingCompiler = (url) => { this.data.loading = true + this.data.loadingUrl = url this.emit('statusChanged', { key: 'loading', title: 'loading compiler...', type: 'info' }) } this.compiler.event.register('loadingCompiler', this.data.eventHandlers.onLoadingCompiler) From 1dc0f8fe6d1509888a71d2d7b7def7adcb5931b2 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 9 Nov 2021 14:23:33 +0530 Subject: [PATCH 33/33] extra console --- apps/remix-ide/src/app/tabs/test-tab.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 5dbedd4448..c82a2bcc1d 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -571,7 +571,6 @@ module.exports = class TestTab extends ViewPlugin { }, { testFilePath } ) }).catch((error) => { - console.log('error in runTest-->', error) if (error) return // eslint-disable-line }) }