From a6c69d4ec41673fdabe1b36081e52fb6f4ccfb1f Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Mar 2022 12:24:02 +0100 Subject: [PATCH 01/10] 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 02/10] 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 03/10] 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 04/10] 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 05/10] 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 06/10] 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 07/10] 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 08/10] 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 588744ff0442ba5d7cd49a33ad1f7ccff84caed6 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Mar 2022 13:00:57 +0100 Subject: [PATCH 09/10] 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 10/10] 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) })