From b8c96d616c5cda4479424c158f96863c797390a8 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 4 Mar 2022 08:02:22 +0100 Subject: [PATCH 01/22] fifx calc error --- apps/remix-ide/src/app/plugins/storage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/plugins/storage.ts b/apps/remix-ide/src/app/plugins/storage.ts index d52e2302eb..32d5c90387 100644 --- a/apps/remix-ide/src/app/plugins/storage.ts +++ b/apps/remix-ide/src/app/plugins/storage.ts @@ -39,7 +39,7 @@ export class StoragePlugin extends Plugin { if (!localStorage.hasOwnProperty(_x)) { continue } - _xLen = ((localStorage[_x].length + _x.length) * 2) + _xLen = ((localStorage[_x].length + _x.length)) _lsTotal += _xLen } return (_lsTotal / 1024).toFixed(2) From a6c69d4ec41673fdabe1b36081e52fb6f4ccfb1f Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 12:24:02 +0100 Subject: [PATCH 02/22] clear cache --- apps/debugger/src/app/debugger-api.ts | 5 +++++ .../src/lib/compiler-fetch-and-compile.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index 6163ee766c..3a4a0f5145 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -127,6 +127,11 @@ export const DebuggerApiMixin = (Base) => class extends Base { } debug (hash, web3?) { + try { + this.call('fetchAndCompile', 'clearCache') + } catch (e) { + console.error(e) + } this.debugHash = hash if (web3) this._web3 = web3 else this._web3 = this.initialWeb3 diff --git a/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts b/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts index bf8b87bf55..f8446886b7 100644 --- a/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts +++ b/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts @@ -8,7 +8,7 @@ import { fetchContractFromSourcify } from './helpers/fetch-sourcify' const profile = { name: 'fetchAndCompile', - methods: ['resolve'], + methods: ['resolve', 'clearCache'], version: '0.0.1' } @@ -21,6 +21,14 @@ export class FetchAndCompile extends Plugin { this.sourceVerifierNetWork = ['Main', 'Rinkeby', 'Ropsten', 'Goerli'] } + /** + * Clear the cache + * + */ + async clearCache () { + this.unresolvedAddresses = [] + } + /** * Fetch compiliation metadata from source-Verify from a given @arg contractAddress - https://github.com/ethereum/source-verify * Put the artifacts in the file explorer From 921fa123a4e022a383a8e74a521c27c13d6aa1bf Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 12:24:32 +0100 Subject: [PATCH 03/22] try getting content from the compilation targets --- .../src/lib/compiler-fetch-and-compile.ts | 12 ++++++++++-- .../src/lib/helpers/fetch-etherscan.ts | 4 ++-- .../src/lib/helpers/fetch-sourcify.ts | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts b/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts index f8446886b7..3d5910d377 100644 --- a/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts +++ b/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts @@ -1,4 +1,3 @@ - import { Plugin } from '@remixproject/engine' import { compile } from '@remix-project/remix-solidity' import { util } from '@remix-project/remix-lib' @@ -76,6 +75,7 @@ export class FetchAndCompile extends Plugin { } } + targetPath = `${targetPath}/${network.id}/${contractAddress}` let data try { data = await fetchContractFromSourcify(this, network, contractAddress, targetPath) @@ -108,7 +108,15 @@ export class FetchAndCompile extends Plugin { const compData = await compile( compilationTargets, settings, - async (url, cb) => await this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))) + async (url, cb) => { + // we first try to resolve the content from the compilation target using a more appropiate path + const path = `${targetPath}/${url}` + if (compilationTargets[path] && compilationTargets[path].content) { + return cb(null, compilationTargets[path].content) + } else { + await this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message)) + } + }) await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compData) return compData } catch (e) { diff --git a/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts b/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts index 647547ba47..25ddfc44ef 100644 --- a/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts +++ b/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts @@ -23,7 +23,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres } if (typeof data.result[0].SourceCode === 'string') { - const fileName = `${targetPath}/${network.id}/${contractAddress}/${data.result[0].ContractName}.sol` + const fileName = `${targetPath}/${data.result[0].ContractName}.sol` await plugin.call('fileManager', 'setFile', fileName , data.result[0].SourceCode) compilationTargets[fileName] = { content: data.result[0].SourceCode } } else if (data.result[0].SourceCode && typeof data.result[0].SourceCode == 'object') { @@ -34,7 +34,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres if (await plugin.call('contentImport', 'isExternalUrl', file)) { // nothing to do, the compiler callback will handle those } else { - const path = `${targetPath}/${network.id}/${contractAddress}/${file}` + const path = `${targetPath}/${file}` const content = (source as any).content await plugin.call('fileManager', 'setFile', path, content) compilationTargets[path] = { content } diff --git a/libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts b/libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts index 698c062b44..5765e7e9d6 100644 --- a/libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts +++ b/libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts @@ -13,7 +13,7 @@ export const fetchContractFromSourcify = async (plugin, network, contractAddress } // set the solidity contract code using metadata - await plugin.call('fileManager', 'setFile', `${targetPath}/${network.id}/${contractAddress}/metadata.json`, JSON.stringify(data.metadata, null, '\t')) + await plugin.call('fileManager', 'setFile', `${targetPath}/metadata.json`, JSON.stringify(data.metadata, null, '\t')) for (let file in data.metadata.sources) { const urls = data.metadata.sources[file].urls for (const url of urls) { @@ -24,7 +24,7 @@ export const fetchContractFromSourcify = async (plugin, network, contractAddress if (await plugin.call('contentImport', 'isExternalUrl', file)) { // nothing to do, the compiler callback will handle those } else { - const path = `${targetPath}/${network.id}/${contractAddress}/${file}` + const path = `${targetPath}/${file}` await plugin.call('fileManager', 'setFile', path, source.content) compilationTargets[path] = { content: source.content } } From 2d1023e600b4c3703851506718735aa4c8e8d672 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 14:04:19 +0100 Subject: [PATCH 04/22] fix setting line --- libs/remix-debug/src/code/breakpointManager.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/remix-debug/src/code/breakpointManager.ts b/libs/remix-debug/src/code/breakpointManager.ts index f6f20e6f45..2f7323eeee 100644 --- a/libs/remix-debug/src/code/breakpointManager.ts +++ b/libs/remix-debug/src/code/breakpointManager.ts @@ -172,6 +172,7 @@ export class BreakpointManager { * @param {Object} sourceLocation - position of the breakpoint { file: '', row: '', row: ' Date: Wed, 9 Mar 2022 14:34:45 +0100 Subject: [PATCH 05/22] fix breakpoint events --- libs/remix-debug/src/code/breakpointManager.ts | 3 ++- libs/remix-debug/src/debugger/debugger.ts | 9 +++++++++ libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libs/remix-debug/src/code/breakpointManager.ts b/libs/remix-debug/src/code/breakpointManager.ts index 2f7323eeee..1c2de4a838 100644 --- a/libs/remix-debug/src/code/breakpointManager.ts +++ b/libs/remix-debug/src/code/breakpointManager.ts @@ -87,6 +87,7 @@ export class BreakpointManager { * */ async jump (fromStep, direction, defaultToLimit, trace) { + this.event.trigger('locatingBreakpoint', []) let sourceLocation let previousSourceLocation let currentStep = fromStep + direction @@ -120,7 +121,7 @@ export class BreakpointManager { } currentStep += direction } - this.event.trigger('NoBreakpointHit', []) + this.event.trigger('noBreakpointHit', []) if (!defaultToLimit) { return } diff --git a/libs/remix-debug/src/debugger/debugger.ts b/libs/remix-debug/src/debugger/debugger.ts index b77963d302..8c78569353 100644 --- a/libs/remix-debug/src/debugger/debugger.ts +++ b/libs/remix-debug/src/debugger/debugger.ts @@ -47,9 +47,18 @@ export class Debugger { }) this.breakPointManager.event.register('breakpointStep', (step) => { + this.event.trigger('breakpointStep', []) this.step_manager.jumpTo(step) }) + this.breakPointManager.event.register('noBreakpointHit', (step) => { + this.event.trigger('noBreakpointHit', []) + }) + + this.breakPointManager.event.register('locatingBreakpoint', () => { + this.event.trigger('locatingBreakpoint', []) + }) + this.debugger.setBreakpointManager(this.breakPointManager) this.debugger.event.register('newTraceLoaded', this, () => { diff --git a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx index 0524f22170..25dd08705b 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -87,6 +87,18 @@ export const DebuggerUI = (props: DebuggerUIProps) => { }) }) + debuggerInstance.event.register('locatingBreakpoint', async (isActive) => { + setState(prevState => { + return { ...prevState, sourceLocationStatus: 'Locating breakpoint, this might take a while...' } + }) + }) + + debuggerInstance.event.register('noBreakpointHit', async (isActive) => { + setState(prevState => { + return { ...prevState, sourceLocationStatus: '' } + }) + }) + debuggerInstance.event.register('newSourceLocation', async (lineColumnPos, rawLocation, generatedSources, address) => { if (!lineColumnPos) { await debuggerModule.discardHighlight() From a8c4393cfd228de88bb8cb92ecc2e39b7a580fca Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 15:14:53 +0100 Subject: [PATCH 06/22] remove uneeded managersChanged --- libs/remix-debug/src/Ethdebugger.ts | 1 - libs/remix-debug/src/debugger/debugger.ts | 5 ----- libs/remix-debug/test/debugger.ts | 5 ----- 3 files changed, 11 deletions(-) diff --git a/libs/remix-debug/src/Ethdebugger.ts b/libs/remix-debug/src/Ethdebugger.ts index e0f1a92ab5..644a98e57a 100644 --- a/libs/remix-debug/src/Ethdebugger.ts +++ b/libs/remix-debug/src/Ethdebugger.ts @@ -64,7 +64,6 @@ export class Ethdebugger { this.solidityProxy, this.codeManager, { ...this.opts, includeLocalVariables }) - this.event.trigger('managersChanged') } resolveStep (index) { diff --git a/libs/remix-debug/src/debugger/debugger.ts b/libs/remix-debug/src/debugger/debugger.ts index 8c78569353..71a7289e0a 100644 --- a/libs/remix-debug/src/debugger/debugger.ts +++ b/libs/remix-debug/src/debugger/debugger.ts @@ -41,11 +41,6 @@ export class Debugger { } }) - this.breakPointManager.event.register('managersChanged', () => { - const { traceManager, callTree, solidityProxy } = this.debugger - this.breakPointManager.setManagers({ traceManager, callTree, solidityProxy }) - }) - this.breakPointManager.event.register('breakpointStep', (step) => { this.event.trigger('breakpointStep', []) this.step_manager.jumpTo(step) diff --git a/libs/remix-debug/test/debugger.ts b/libs/remix-debug/test/debugger.ts index 8ce4bed268..c837ed1c01 100644 --- a/libs/remix-debug/test/debugger.ts +++ b/libs/remix-debug/test/debugger.ts @@ -277,11 +277,6 @@ function testDebugging (debugManager) { return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot)) }}) - breakPointManager.event.register('managersChanged', () => { - const {traceManager, callTree, solidityProxy} = debugManager - breakPointManager.setManagers({traceManager, callTree, solidityProxy}) - }) - breakPointManager.add({fileName: 'test.sol', row: 38}) breakPointManager.event.register('breakpointHit', function (sourceLocation, step) { From 9f9c4118b21eae41ed7f820f8dffaa2c36c722d7 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 15:27:13 +0100 Subject: [PATCH 07/22] fix unit test --- libs/remix-debug/test/debugger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-debug/test/debugger.ts b/libs/remix-debug/test/debugger.ts index c837ed1c01..9e0690883a 100644 --- a/libs/remix-debug/test/debugger.ts +++ b/libs/remix-debug/test/debugger.ts @@ -277,7 +277,7 @@ function testDebugging (debugManager) { return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot)) }}) - breakPointManager.add({fileName: 'test.sol', row: 38}) + breakPointManager.add({fileName: 0, row: 38}) breakPointManager.event.register('breakpointHit', function (sourceLocation, step) { console.log('breakpointHit') From ca8d4ab2152c4ed9270aecab0f29befda3d20896 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 15:59:35 +0100 Subject: [PATCH 08/22] fix stopping at breakpoing --- libs/remix-debug/src/code/breakpointManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-debug/src/code/breakpointManager.ts b/libs/remix-debug/src/code/breakpointManager.ts index 1c2de4a838..dff9d639dc 100644 --- a/libs/remix-debug/src/code/breakpointManager.ts +++ b/libs/remix-debug/src/code/breakpointManager.ts @@ -114,7 +114,7 @@ export class BreakpointManager { } if (this.hasBreakpointAtLine(sourceLocation.file, lineColumn.start.line)) { lineHadBreakpoint = true - if (direction === 1 && this.hitLine(currentStep, sourceLocation, previousSourceLocation, trace)) { + if (this.hitLine(currentStep, sourceLocation, previousSourceLocation, trace)) { return } } From e0396cb4a56680743838677e9dd9cb5fd8f15229 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 15:59:44 +0100 Subject: [PATCH 09/22] fix test --- libs/remix-debug/test/debugger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-debug/test/debugger.ts b/libs/remix-debug/test/debugger.ts index 9e0690883a..af541bccda 100644 --- a/libs/remix-debug/test/debugger.ts +++ b/libs/remix-debug/test/debugger.ts @@ -277,7 +277,7 @@ function testDebugging (debugManager) { return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot)) }}) - breakPointManager.add({fileName: 0, row: 38}) + breakPointManager.add({fileName: 'test.sol', row: 39}) breakPointManager.event.register('breakpointHit', function (sourceLocation, step) { console.log('breakpointHit') From a0b211ec7a6b05db071e24d4bcfa244e06b6230d Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 7 Mar 2022 14:59:50 +0100 Subject: [PATCH 10/22] readd gist prefix --- apps/remix-ide-e2e/src/tests/gist.test.ts | 12 ++++++------ libs/remix-core-plugin/src/lib/gist-handler.ts | 2 +- .../remix-ui/workspace/src/lib/reducers/workspace.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/gist.test.ts b/apps/remix-ide-e2e/src/tests/gist.test.ts index ce348cbdae..0fd6efa234 100644 --- a/apps/remix-ide-e2e/src/tests/gist.test.ts +++ b/apps/remix-ide-e2e/src/tests/gist.test.ts @@ -36,9 +36,9 @@ module.exports = { .addFile('File.sol', { content: '' }) .executeScript(`remix.loadgist('${gistid}')`) // .perform((done) => { if (runtimeBrowser === 'chrome') { browser.openFile('gists') } done() }) - .waitForElementVisible(`[data-id="treeViewLitreeViewItem${gistid}"]`) - .click(`[data-id="treeViewLitreeViewItem${gistid}"]`) - .openFile(`${gistid}/README.txt`) + .waitForElementVisible(`[data-id="treeViewLitreeViewItemgist-${gistid}"]`) + .click(`[data-id="treeViewLitreeViewItemgist-${gistid}"]`) + .openFile(`gist-${gistid}/README.txt`) // Remix publish to gist /* .click('*[data-id="fileExplorerNewFilepublishToGist"]') .pause(2000) @@ -140,9 +140,9 @@ module.exports = { }) .setValue('*[data-id="gisthandlerModalDialogModalBody-react"] input[data-id="modalDialogCustomPromp"]', testData.validGistId) .modalFooterOKClick('gisthandler') - .openFile(`${testData.validGistId}/README.txt`) - .waitForElementVisible(`div[title='default_workspace/${testData.validGistId}/README.txt']`) - .assert.containsText(`div[title='default_workspace/${testData.validGistId}/README.txt'] > span`, 'README.txt') + .openFile(`gist-${testData.validGistId}/README.txt`) + .waitForElementVisible(`div[title='default_workspace/gist-${testData.validGistId}/README.txt']`) + .assert.containsText(`div[title='default_workspace/gist-${testData.validGistId}/README.txt'] > span`, 'README.txt') .end() } } diff --git a/libs/remix-core-plugin/src/lib/gist-handler.ts b/libs/remix-core-plugin/src/lib/gist-handler.ts index 0ef36a62ec..7c0ed92542 100644 --- a/libs/remix-core-plugin/src/lib/gist-handler.ts +++ b/libs/remix-core-plugin/src/lib/gist-handler.ts @@ -116,7 +116,7 @@ export class GistHandler extends Plugin { const obj: StringByString = {} Object.keys(data.files).forEach((element) => { const path = element.replace(/\.\.\./g, '/') - obj['/' + gistId + '/' + path] = data.files[element] + obj['/gist-' + gistId + '/' + path] = data.files[element] }) this.call('fileManager', 'setBatchFiles', obj, 'workspace', true, async (errorSavingFiles: any) => { if (errorSavingFiles) { diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index df80d46ee0..8d33cb226d 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -641,7 +641,7 @@ const removeInputField = (state: BrowserState, path: string): { [x: string]: Rec files = _.setWith(files, _path, { isDirectory: true, path, - name: extractNameFromKey(path).indexOf('gist-') === 0 ? extractNameFromKey(path).split('-')[1] : extractNameFromKey(path), + name: extractNameFromKey(path), type: extractNameFromKey(path).indexOf('gist-') === 0 ? 'gist' : 'folder', child: prevFiles ? prevFiles.child : {} }, Object) @@ -742,7 +742,7 @@ const normalize = (filesList, directory?: string, newInputType?: 'folder' | 'fil if (filesList[key].isDirectory) { folders[extractNameFromKey(key)] = { path, - name: extractNameFromKey(path).indexOf('gist-') === 0 ? extractNameFromKey(path).split('-')[1] : extractNameFromKey(path), + name: extractNameFromKey(path), isDirectory: filesList[key].isDirectory, type: extractNameFromKey(path).indexOf('gist-') === 0 ? 'gist' : 'folder' } From cd4e934cc7cf23d6736cbbef3223b54be1b49891 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 10:58:40 +0100 Subject: [PATCH 11/22] fix reference in test module --- 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 7f634bd9d1..606bc2821b 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -146,7 +146,7 @@ module.exports = class TestTab extends ViewPlugin { renderComponent (testDirPath) { this.dispatch({ testTab: this, - helper: this.helper, + helper: helper, testDirPath: testDirPath }) } From dd71b4c46f2898ed33d49ff3171e49bc1b3a59b9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 11:00:01 +0100 Subject: [PATCH 12/22] ensure default value --- libs/remix-ui/editor/src/lib/remix-ui-editor.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 769abf9528..23c0128b01 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -271,7 +271,10 @@ export const EditorUI = (props: EditorUIProps) => { props.editorAPI.clearDecorationsByPlugin = (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => { const model = editorModelsState[filePath]?.model - if (!model) return + if (!model) return { + currentDecorations: [], + registeredDecorations: [] + } const decorations = [] const newRegisteredDecorations = [] if (registeredDecorations) { @@ -290,7 +293,9 @@ export const EditorUI = (props: EditorUIProps) => { props.editorAPI.keepDecorationsFor = (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => { const model = editorModelsState[filePath]?.model - if (!model) return + if (!model) return { + currentDecorations: [] + } const decorations = [] if (registeredDecorations) { for (const decoration of registeredDecorations) { From 7d1eb940d35f34dc784da947a0f37628cdbe4f36 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 11:57:37 +0530 Subject: [PATCH 13/22] e2e for mocha testing added --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index f56dccf174..129ec1bc1c 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -104,7 +104,7 @@ module.exports = { .click('[data-id="treeViewDivtreeViewItemcontracts"]') .openFile('contracts/2_Owner.sol') .clickLaunchIcon('solidity') - .click('*[data-id="compilerContainerCompileBtn"]').pause(5000) // compile Owner + .click('*[data-id="compilerContainerCompileBtn"]').pause(20000) // compile Owner .executeScript('remix.execute(\'deployWithEthersJs.js\')') .waitForElementContainsText('*[data-id="terminalJournal"]', 'Contract Address:', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) @@ -119,6 +119,28 @@ module.exports = { .waitForElementContainsText('*[data-id="terminalJournal"]', 'newOwner', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) }, + 'Run tests using Mocha script and check result is logged in the terminal #group4': function (browser: NightwatchBrowser) { + browser + .click('*[data-id="treeViewDivtreeViewItem"]') + .addFile('scripts/storage.test.js', { content: storageMochaTests }) + .pause(1000) + .click('[data-id="treeViewDivtreeViewItemcontracts"]') + .openFile('contracts/1_Storage.sol') + .clickLaunchIcon('solidity') + .click('*[data-id="compilerContainerCompileBtn"]') + .pause(10000) // compile Storage + .executeScript('remix.execute(\'scripts/storage.test.js\')') + .pause(5000) + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Running tests....') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'storage contract Address:') + .waitForElementContainsText('*[data-id="terminalJournal"]', '✓ test initial value') + .waitForElementContainsText('*[data-id="terminalJournal"]', '✓ test updating and retrieving updated value') + .waitForElementContainsText('*[data-id="terminalJournal"]', '✘ fail test updating and retrieving updated value') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Expected: 55') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Actual: 56') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Message: incorrect number: expected 56 to equal 55') + .waitForElementContainsText('*[data-id="terminalJournal"]', '2 passing, 1 failing') + }, 'Should print hardhat logs #group4': function (browser: NightwatchBrowser) { browser @@ -261,6 +283,44 @@ const deployWithEthersJs = ` } })()` +const storageMochaTests = ` +const { expect } = require("chai"); + +describe("Storage", function () { + it("test initial value", async function () { + // Make sure contract is compiled and artifacts are generated + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); + let storage = await Storage.deploy(); + console.log('storage contract Address: ' + storage.address); + await storage.deployed() + expect((await storage.retrieve()).toNumber()).to.equal(0); + }); + + it("test updating and retrieving updated value", async function () { + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); + let storage = await Storage.deploy(); + await storage.deployed() + const setValue = await storage.store(56); + await setValue.wait(); + expect((await storage.retrieve()).toNumber()).to.equal(56); + }); + + it("fail test updating and retrieving updated value", async function () { + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); + let storage = await Storage.deploy(); + await storage.deployed() + const setValue = await storage.store(56); + await setValue.wait(); + expect((await storage.retrieve()).toNumber(), 'incorrect number').to.equal(55); + }); +});` + const hardhatLog = ` // SPDX-License-Identifier: GPL-3.0 From 11529f0b2de923abc5c6cce6e3401024e4c9d999 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 12:37:56 +0530 Subject: [PATCH 14/22] fix e2e --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index 129ec1bc1c..c574eef214 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -119,12 +119,11 @@ module.exports = { .waitForElementContainsText('*[data-id="terminalJournal"]', 'newOwner', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) }, - 'Run tests using Mocha script and check result is logged in the terminal #group4': function (browser: NightwatchBrowser) { + 'Run tests using Mocha script and check result logging in the terminal #group4': function (browser: NightwatchBrowser) { browser .click('*[data-id="treeViewDivtreeViewItem"]') .addFile('scripts/storage.test.js', { content: storageMochaTests }) .pause(1000) - .click('[data-id="treeViewDivtreeViewItemcontracts"]') .openFile('contracts/1_Storage.sol') .clickLaunchIcon('solidity') .click('*[data-id="compilerContainerCompileBtn"]') From e8bdb01d2b6bd57fd1086abd9faa11f4c41518bd Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 13:31:20 +0530 Subject: [PATCH 15/22] pause --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index c574eef214..a71cffd13b 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -104,7 +104,7 @@ module.exports = { .click('[data-id="treeViewDivtreeViewItemcontracts"]') .openFile('contracts/2_Owner.sol') .clickLaunchIcon('solidity') - .click('*[data-id="compilerContainerCompileBtn"]').pause(20000) // compile Owner + .click('*[data-id="compilerContainerCompileBtn"]').pause(5000) // compile Owner .executeScript('remix.execute(\'deployWithEthersJs.js\')') .waitForElementContainsText('*[data-id="terminalJournal"]', 'Contract Address:', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) @@ -127,9 +127,9 @@ module.exports = { .openFile('contracts/1_Storage.sol') .clickLaunchIcon('solidity') .click('*[data-id="compilerContainerCompileBtn"]') - .pause(10000) // compile Storage + .pause(2000) // compile Storage .executeScript('remix.execute(\'scripts/storage.test.js\')') - .pause(5000) + .pause(1000) .waitForElementContainsText('*[data-id="terminalJournal"]', 'Running tests....') .waitForElementContainsText('*[data-id="terminalJournal"]', 'storage contract Address:') .waitForElementContainsText('*[data-id="terminalJournal"]', '✓ test initial value') From ad3870af0e2fbdce197a7aebb4e0697e6ab1f77a Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Mar 2022 09:27:38 +0100 Subject: [PATCH 16/22] fix decoding events --- libs/remix-lib/src/execution/eventsDecoder.ts | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/libs/remix-lib/src/execution/eventsDecoder.ts b/libs/remix-lib/src/execution/eventsDecoder.ts index 4622b245fd..cdb794fd71 100644 --- a/libs/remix-lib/src/execution/eventsDecoder.ts +++ b/libs/remix-lib/src/execution/eventsDecoder.ts @@ -56,21 +56,22 @@ export class EventsDecoder { return eventsABI } - _event (hash: string, eventsABI: Record, contractName: string) { - const events = eventsABI[contractName] - if (!events) return null - - if (events[hash]) { - const event = events[hash] - for (const input of event.inputs) { - if (input.type === 'function') { - input.type = 'bytes24' - input.baseType = 'bytes24' + _event (hash, eventsABI) { + // get all the events responding to that hash. + const contracts = [] + for (const k in eventsABI) { + if (eventsABI[k][hash]) { + const event = eventsABI[k][hash] + for (const input of event.inputs) { + if (input.type === 'function') { + input.type = 'bytes24' + input.baseType = 'bytes24' + } } + contracts.push(event) } - return event } - return null + return contracts } _stringifyBigNumber (value): string { @@ -95,16 +96,23 @@ export class EventsDecoder { // [address, topics, mem] const log = logs[i] const topicId = log.topics[0] - const eventAbi = this._event(topicId.replace('0x', ''), eventsABI, contractName) - if (eventAbi) { - const decodedlog = eventAbi.abi.parseLog(log) - const decoded = {} - for (const v in decodedlog.args) { - decoded[v] = this._stringifyEvent(decodedlog.args[v]) + const eventAbis = this._event(topicId.replace('0x', ''), eventsABI) + for (const eventAbi of eventAbis) { + try { + if (eventAbi) { + const decodedlog = eventAbi.abi.parseLog(log) + const decoded = {} + for (const v in decodedlog.args) { + decoded[v] = this._stringifyEvent(decodedlog.args[v]) + } + events.push({ from: log.address, topic: topicId, event: eventAbi.event, args: decoded }) + } else { + events.push({ from: log.address, data: log.data, topics: log.topics }) + } + break // if one of the iteration is successful + } catch (e) { + continue } - events.push({ from: log.address, topic: topicId, event: eventAbi.event, args: decoded }) - } else { - events.push({ from: log.address, data: log.data, topics: log.topics }) } } cb(null, { decoded: events, raw: logs }) From 588744ff0442ba5d7cd49a33ad1f7ccff84caed6 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Mar 2022 13:00:57 +0100 Subject: [PATCH 17/22] remove uneeded event --- libs/remix-debug/src/debugger/debugger.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/remix-debug/src/debugger/debugger.ts b/libs/remix-debug/src/debugger/debugger.ts index 71a7289e0a..ae04204a5e 100644 --- a/libs/remix-debug/src/debugger/debugger.ts +++ b/libs/remix-debug/src/debugger/debugger.ts @@ -42,7 +42,6 @@ export class Debugger { }) this.breakPointManager.event.register('breakpointStep', (step) => { - this.event.trigger('breakpointStep', []) this.step_manager.jumpTo(step) }) From 25e9900774cd5f11a04770121b88d6e6471c8415 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Mar 2022 13:02:21 +0100 Subject: [PATCH 18/22] remove uneeded console.log --- libs/remix-debug/test/debugger.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/remix-debug/test/debugger.ts b/libs/remix-debug/test/debugger.ts index af541bccda..4486760f1b 100644 --- a/libs/remix-debug/test/debugger.ts +++ b/libs/remix-debug/test/debugger.ts @@ -280,14 +280,12 @@ function testDebugging (debugManager) { breakPointManager.add({fileName: 'test.sol', row: 39}) breakPointManager.event.register('breakpointHit', function (sourceLocation, step) { - console.log('breakpointHit') t.equal(JSON.stringify(sourceLocation), JSON.stringify({ start: 1153, length: 6, file: 0, jump: '-' })) t.equal(step, 212) }) breakPointManager.event.register('noBreakpointHit', function () { t.end('noBreakpointHit') - console.log('noBreakpointHit') }) breakPointManager.jumpNextBreakpoint(0, true) }) From 0cadea9798b4b582b3e67944681c462d25b82eed Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 17:57:54 +0530 Subject: [PATCH 19/22] removed click --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index a71cffd13b..5913e4bf63 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -121,13 +121,12 @@ module.exports = { }, 'Run tests using Mocha script and check result logging in the terminal #group4': function (browser: NightwatchBrowser) { browser - .click('*[data-id="treeViewDivtreeViewItem"]') .addFile('scripts/storage.test.js', { content: storageMochaTests }) .pause(1000) .openFile('contracts/1_Storage.sol') .clickLaunchIcon('solidity') .click('*[data-id="compilerContainerCompileBtn"]') - .pause(2000) // compile Storage + .pause(1000) // compile Storage .executeScript('remix.execute(\'scripts/storage.test.js\')') .pause(1000) .waitForElementContainsText('*[data-id="terminalJournal"]', 'Running tests....') From 458e4abe09a0f4e3d389354acfb11377c3cb6602 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Mar 2022 13:51:56 +0100 Subject: [PATCH 20/22] set annotations from the compiler api --- .../solidity-compiler/src/app/compiler-api.ts | 19 +++++++++- .../src/compiler/compiler-abstract.ts | 6 +-- libs/remix-solidity/src/compiler/compiler.ts | 2 +- .../src/compiler/{txHelper.ts => helper.ts} | 23 +++++++++++- libs/remix-solidity/src/index.ts | 1 + libs/remix-ui/renderer/src/lib/renderer.tsx | 37 ++----------------- 6 files changed, 47 insertions(+), 41 deletions(-) rename libs/remix-solidity/src/compiler/{txHelper.ts => helper.ts} (52%) diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 174d40f910..6c327c8393 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -1,4 +1,4 @@ -import { compile } from '@remix-project/remix-solidity' +import { compile, helper } from '@remix-project/remix-solidity' import { CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line import type { ConfigurationSettings } from '@remix-project/remix-lib-ts' @@ -261,7 +261,7 @@ export const CompilerApiMixin = (Base) => class extends Base { this.on('fileManager', 'fileClosed', this.data.eventHandlers.onFileClosed) - this.data.eventHandlers.onCompilationFinished = (success, data, source, input, version) => { + this.data.eventHandlers.onCompilationFinished = async (success, data, source, input, version) => { this.compileErrors = data if (success) { // forwarding the event to the appManager infra @@ -291,6 +291,21 @@ export const CompilerApiMixin = (Base) => class extends Base { if (success) this.compiler.visitContracts((contract) => { this.compilationDetails.contractMap[contract.name] = contract }) this.compilationDetails.target = source.target if (this.onCompilationFinished) this.onCompilationFinished(this.compilationDetails) + // set annotations + if (data.errors) { + for (let error of data.errors) { + let pos = helper.getPositionDetails(error.formattedMessage) + if (pos.errFile) { + pos = { + row: pos.errLine, + column: pos.errCol, + text: error.formattedMessage, + type: error.severity + } + await this.call('editor', 'addAnnotation', pos, pos.errFile) + } + } + } } this.compiler.event.register('compilationFinished', this.data.eventHandlers.onCompilationFinished) diff --git a/libs/remix-solidity/src/compiler/compiler-abstract.ts b/libs/remix-solidity/src/compiler/compiler-abstract.ts index 8a7c25f72f..7471816fea 100644 --- a/libs/remix-solidity/src/compiler/compiler-abstract.ts +++ b/libs/remix-solidity/src/compiler/compiler-abstract.ts @@ -1,5 +1,5 @@ 'use strict' -import txHelper from './txHelper' +import helper from './helper' export class CompilerAbstract { languageversion: any @@ -18,11 +18,11 @@ export class CompilerAbstract { } getContract (name) { - return txHelper.getContract(name, this.data.contracts) + return helper.getContract(name, this.data.contracts) } visitContracts (calllback) { - return txHelper.visitContracts(this.data.contracts, calllback) + return helper.visitContracts(this.data.contracts, calllback) } getData () { diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index dc2421ff9c..a10fa6fce2 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -4,7 +4,7 @@ import { update } from 'solc/abi' import * as webworkify from 'webworkify-webpack' import compilerInput from './compiler-input' import EventManager from '../lib/eventManager' -import txHelper from './txHelper' +import txHelper from './helper' import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult, visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError, diff --git a/libs/remix-solidity/src/compiler/txHelper.ts b/libs/remix-solidity/src/compiler/helper.ts similarity index 52% rename from libs/remix-solidity/src/compiler/txHelper.ts rename to libs/remix-solidity/src/compiler/helper.ts index c50bf4c7e6..f4eb8e3f21 100644 --- a/libs/remix-solidity/src/compiler/txHelper.ts +++ b/libs/remix-solidity/src/compiler/helper.ts @@ -35,6 +35,27 @@ export default { if (cb(param)) return } } - } + }, + + // ^ e.g: + // browser/gm.sol: Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.6.12 + // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.2.0/contracts/introspection/IERC1820Registry.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.7.4+commit.3f05b770.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version + getPositionDetails: (msg: string) => { + const result = { } as Record + + // To handle some compiler warning without location like SPDX license warning etc + if (!msg.includes(':')) return { errLine: -1, errCol: -1, errFile: '' } + if (msg.includes('-->')) msg = msg.split('-->')[1].trim() + + // extract line / column + let pos = msg.match(/^(.*?):([0-9]*?):([0-9]*?)?/) + result.errLine = pos ? parseInt(pos[2]) - 1 : -1 + result.errCol = pos ? parseInt(pos[3]) : -1 + + // extract file + pos = msg.match(/^(https:.*?|http:.*?|.*?):/) + result.errFile = pos ? pos[1] : msg + return result + } } diff --git a/libs/remix-solidity/src/index.ts b/libs/remix-solidity/src/index.ts index d5878a0f85..ac9db0e167 100644 --- a/libs/remix-solidity/src/index.ts +++ b/libs/remix-solidity/src/index.ts @@ -4,3 +4,4 @@ export { default as CompilerInput, getValidLanguage } from './compiler/compiler- export { CompilerAbstract } from './compiler/compiler-abstract' export * from './compiler/types' export { promisedMiniXhr, pathToURL, baseURLBin, baseURLWasm, canUseWorker, urlFromVersion } from './compiler/compiler-utils' +export { default as helper } from './compiler/helper' diff --git a/libs/remix-ui/renderer/src/lib/renderer.tsx b/libs/remix-ui/renderer/src/lib/renderer.tsx index 9121f432c6..679d26c490 100644 --- a/libs/remix-ui/renderer/src/lib/renderer.tsx +++ b/libs/remix-ui/renderer/src/lib/renderer.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react' //eslint-disable-line +import { helper } from '@remix-project/remix-solidity' import './renderer.css' interface RendererProps { message: any; @@ -29,51 +30,19 @@ export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => { // ^ e.g: // browser/gm.sol: Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.6.12 // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.2.0/contracts/introspection/IERC1820Registry.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.7.4+commit.3f05b770.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version - const positionDetails = getPositionDetails(text) + const positionDetails = helper.getPositionDetails(text) opt.errLine = positionDetails.errLine opt.errCol = positionDetails.errCol opt.errFile = positionDetails.errFile ? (positionDetails.errFile as string).trim() : '' - if (!opt.noAnnotations && opt.errFile && opt.errFile !== '') { - addAnnotation(opt.errFile, { - row: opt.errLine, - column: opt.errCol, - text: text, - type: opt.type - }) - } - setMessageText(text) setEditorOptions(opt) setClose(false) setClassList(opt.type === 'error' ? 'alert alert-danger' : 'alert alert-warning') }, [message, opt]) - const getPositionDetails = (msg: string) => { - const result = { } as Record - - // To handle some compiler warning without location like SPDX license warning etc - if (!msg.includes(':')) return { errLine: -1, errCol: -1, errFile: '' } - - if (msg.includes('-->')) msg = msg.split('-->')[1].trim() - - // extract line / column - let pos = msg.match(/^(.*?):([0-9]*?):([0-9]*?)?/) - result.errLine = pos ? parseInt(pos[2]) - 1 : -1 - result.errCol = pos ? parseInt(pos[3]) : -1 - - // extract file - pos = msg.match(/^(https:.*?|http:.*?|.*?):/) - result.errFile = pos ? pos[1] : msg - return result - } - - const addAnnotation = async (file, error) => { - if (file === await plugin.call('config', 'getAppParameter', 'currentFile')) { - await plugin.call('editor', 'addAnnotation', error, file) - } - } + const handleErrorClick = (opt) => { if (opt.click) { From 1a3a24ddbcd2bbddcc43f81dcbb50c9a31c26a2c Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 19:22:51 +0530 Subject: [PATCH 21/22] e2e for contract wiht lib --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 112 +++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index 5913e4bf63..0f90f84199 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -139,7 +139,27 @@ module.exports = { .waitForElementContainsText('*[data-id="terminalJournal"]', 'Message: incorrect number: expected 56 to equal 55') .waitForElementContainsText('*[data-id="terminalJournal"]', '2 passing, 1 failing') }, - + 'Run tests using Mocha for a contract with library deployment and check result logging in the terminal #group4': function (browser: NightwatchBrowser) { + browser + .addFile('scripts/storageWithLib.test.js', { content: storageWithLibMochaTests }) + .pause(1000) + .click('[data-id="treeViewDivtreeViewItemcontracts"]') + .addFile('contracts/StorageWithLib.sol', { content: storageWithLibContract }) + .openFile('contracts/StorageWithLib.sol') + .clickLaunchIcon('solidity') + .click('*[data-id="compilerContainerCompileBtn"]') + .pause(1000) // compile StorageWithLib + .executeScript('remix.execute(\'scripts/storageWithLib.test.js\')') + .pause(1000) + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Running tests....') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Storage with lib') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'deploying lib:') + .waitForElementContainsText('*[data-id="terminalJournal"]', '✘ test library integration by calling a lib method') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Expected: 34') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Actual: 14') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Message: expected \'14\' to equal \'34\'') + .waitForElementContainsText('*[data-id="terminalJournal"]', '0 passing, 1 failing') + }, 'Should print hardhat logs #group4': function (browser: NightwatchBrowser) { browser .click('*[data-id="terminalClearConsole"]') // clear the terminal @@ -284,7 +304,7 @@ const deployWithEthersJs = ` const storageMochaTests = ` const { expect } = require("chai"); -describe("Storage", function () { +describe("Storage with lib", function () { it("test initial value", async function () { // Make sure contract is compiled and artifacts are generated const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) @@ -319,6 +339,94 @@ describe("Storage", function () { }); });` +const storageWithLibContract = ` +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; + +library Lib { + function test () public view returns (uint) { + return 14; + } +} +/** + * @title Storage + * @dev Store & retrieve value inr a variable + */ +contract StorageWithLib { + + uint256 number; + + /** + * @dev Store valrue in variable + * @param num value to store + */ + function store(uint256 num) public { + number = num; + } + + /** + * @dev Return value + * @return value of 'number' + */ + function retrieve() public view returns (uint256){ + return number; + } + + function getFromLib() public view returns (uint) { + return Lib.test(); + } +} +` + +const storageWithLibMochaTests = ` +const { expect } = require("chai"); +const { ethers } = require("hardhat"); + +describe("Storage", function () { + it("test library integration by calling a lib method", async function () { + const metadataLib = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/Lib.json')) + console.log('deploying lib:') + const artifactLib = { + contractName: 'Lib', + sourceName: 'contracts/StorageWithLib.sol', + abi: metadataLib.abi, + bytecode: '0x' + metadataLib.data.bytecode.object, + deployedBytecode: '0x' + metadataLib.data.deployedBytecode.object, + linkReferences: metadataLib.data.bytecode.linkReferences, + deployedLinkReferences: metadataLib.data.deployedBytecode.linkReferences, + } + + const optionsLib = {} + const factoryLib = await ethers.getContractFactoryFromArtifact(artifactLib, optionsLib) + const lib = await factoryLib.deploy(); + await lib.deployed() + + const metadata = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/StorageWithLib.json')) + const artifact = { + contractName: 'StorageWithLib', + sourceName: 'contracts/StorageWithLib.sol', + abi: metadata.abi, + bytecode: '0x' + metadata.data.bytecode.object, + deployedBytecode: '0x' + metadata.data.deployedBytecode.object, + linkReferences: metadata.data.bytecode.linkReferences, + deployedLinkReferences: metadata.data.deployedBytecode.linkReferences, + } + const options = { + libraries: { + 'Lib': lib.address + } + } + + const factory = await ethers.getContractFactoryFromArtifact(artifact, options) + const storage = await factory.deploy(); + await storage.deployed() + const storeValue = await storage.store(333); + await storeValue.wait(); + expect((await storage.getFromLib()).toString()).to.equal('34'); + }); +});` + const hardhatLog = ` // SPDX-License-Identifier: GPL-3.0 From 60ea0b4b33d342735d98ca80708719dbcd9c1b80 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Mar 2022 23:02:43 +0100 Subject: [PATCH 22/22] linting --- apps/solidity-compiler/src/app/compiler-api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 6c327c8393..7d5188be6b 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -293,7 +293,7 @@ export const CompilerApiMixin = (Base) => class extends Base { if (this.onCompilationFinished) this.onCompilationFinished(this.compilationDetails) // set annotations if (data.errors) { - for (let error of data.errors) { + for (const error of data.errors) { let pos = helper.getPositionDetails(error.formattedMessage) if (pos.errFile) { pos = {