diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index 0f99518e78..8528759d14 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -16,6 +16,7 @@ export const DebuggerApiMixin = (Base) => class extends Base { } } this._web3 = new Web3(this.web3Provider) + remixDebug.init.extendWeb3(this._web3) this.offsetToLineColumnConverter = { async offsetToLineColumn (rawLocation, file, sources, asts) { diff --git a/apps/debugger/src/app/debugger.ts b/apps/debugger/src/app/debugger.ts index 4c14f6a3d2..95712fb2ac 100644 --- a/apps/debugger/src/app/debugger.ts +++ b/apps/debugger/src/app/debugger.ts @@ -23,6 +23,7 @@ export class DebuggerClientApi extends DebuggerApiMixin(PluginClient) { fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise getFile: (path: string) => Promise setFile: (path: string, content: string) => Promise - getDebugWeb3: () => any // returns an instance of web3.js + getDebugWeb3: () => any // returns an instance of web3.js, if applicable (mainet, goerli, ...) it returns a reference to a node from devops (so we are sure debug endpoint is available) + web3: () => any // returns an instance of web3.js } diff --git a/apps/remix-ide-e2e/src/tests/publishContract.test.ts b/apps/remix-ide-e2e/src/tests/publishContract.test.ts index fb931a1c35..03987555c5 100644 --- a/apps/remix-ide-e2e/src/tests/publishContract.test.ts +++ b/apps/remix-ide-e2e/src/tests/publishContract.test.ts @@ -32,6 +32,7 @@ module.exports = { .click('[data-id="publishToStorage-modal-footer-ok-react"]') }, + /* Disableing the test untill refactoring and the new swarm usage 'Publish on Swarm': '' + function (browser: NightwatchBrowser) { browser .click('#publishOnSwarm') @@ -47,6 +48,7 @@ module.exports = { }) .click('[data-id="publishToStorage-modal-footer-ok-react"]') }, + */ 'Should publish contract metadata to ipfs on deploy': function (browser: NightwatchBrowser) { browser diff --git a/libs/remix-debug/src/Ethdebugger.ts b/libs/remix-debug/src/Ethdebugger.ts index 3c492e1812..0026c97ee9 100644 --- a/libs/remix-debug/src/Ethdebugger.ts +++ b/libs/remix-debug/src/Ethdebugger.ts @@ -33,7 +33,6 @@ export class Ethdebugger { storageResolver callTree breakpointManager - statusMessage constructor (opts) { this.compilationResult = opts.compilationResult || function (contractAddress) { return null } @@ -151,22 +150,19 @@ export class Ethdebugger { this.event.trigger('traceUnloaded') } - debug (tx) { + async debug (tx) { if (this.traceManager.isLoading) { return } tx.to = tx.to || contractCreationToken('0') this.tx = tx - this.traceManager.resolveTrace(tx).then(async (result) => { - this.setCompilationResult(await this.compilationResult(tx.to)) - this.event.trigger('newTraceLoaded', [this.traceManager.trace]) - if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { - this.breakpointManager.jumpNextBreakpoint(false) - } - this.storageResolver = new StorageResolver({ web3: this.traceManager.web3 }) - }).catch((error) => { - this.statusMessage = error ? error.message : 'Trace not loaded' - }) + await this.traceManager.resolveTrace(tx) + this.setCompilationResult(await this.compilationResult(tx.to)) + this.event.trigger('newTraceLoaded', [this.traceManager.trace]) + if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { + this.breakpointManager.jumpNextBreakpoint(false) + } + this.storageResolver = new StorageResolver({ web3: this.traceManager.web3 }) } } diff --git a/libs/remix-debug/src/debugger/debugger.ts b/libs/remix-debug/src/debugger/debugger.ts index 11395026b3..7a82d358fb 100644 --- a/libs/remix-debug/src/debugger/debugger.ts +++ b/libs/remix-debug/src/debugger/debugger.ts @@ -99,44 +99,31 @@ export class Debugger { this.debugger.web3 = web3 } - debug (blockNumber, txNumber, tx, loadingCb): Promise { + async debug (blockNumber, txNumber, tx, loadingCb) { const web3 = this.debugger.web3 - return new Promise((resolve, reject) => { - if (this.debugger.traceManager.isLoading) { - return resolve() - } + if (this.debugger.traceManager.isLoading) { + return + } - if (tx) { - if (!tx.to) { - tx.to = contractCreationToken('0') - } - this.debugTx(tx, loadingCb) - return resolve() + if (tx) { + if (!tx.to) { + tx.to = contractCreationToken('0') } + return await this.debugTx(tx, loadingCb) + } - try { - if (txNumber.indexOf('0x') !== -1) { - return web3.eth.getTransaction(txNumber, (_error, tx) => { - if (_error) return reject(_error) - if (!tx) return reject(new Error('cannot find transaction ' + txNumber)) - this.debugTx(tx, loadingCb) - return resolve() - }) - } - web3.eth.getTransactionFromBlock(blockNumber, txNumber, (_error, tx) => { - if (_error) return reject(_error) - if (!tx) return reject(new Error('cannot find transaction ' + blockNumber + ' ' + txNumber)) - this.debugTx(tx, loadingCb) - return resolve() - }) - } catch (e) { - return reject(e.message) - } - }) + if (txNumber.indexOf('0x') !== -1) { + tx = await web3.eth.getTransaction(txNumber) + if (!tx) throw new Error('cannot find transaction ' + txNumber) + } else { + tx = await web3.eth.getTransactionFromBlock(blockNumber, txNumber) + if (!tx) throw new Error('cannot find transaction ' + blockNumber + ' ' + txNumber) + } + return await this.debugTx(tx, loadingCb) } - debugTx (tx, loadingCb) { + async debugTx (tx, loadingCb) { this.step_manager = new DebuggerStepManager(this.debugger, this.debugger.traceManager) this.debugger.codeManager.event.register('changed', this, (code, address, instIndex) => { @@ -162,7 +149,7 @@ export class Debugger { }) loadingCb() - this.debugger.debug(tx) + await this.debugger.debug(tx) } unload () { diff --git a/libs/remix-debug/src/trace/traceManager.ts b/libs/remix-debug/src/trace/traceManager.ts index 49ba500889..1c72ac96eb 100644 --- a/libs/remix-debug/src/trace/traceManager.ts +++ b/libs/remix-debug/src/trace/traceManager.ts @@ -30,9 +30,8 @@ export class TraceManager { this.init() if (!this.web3) throw new Error('web3 not loaded') this.isLoading = true + const result = await this.getTrace(tx.hash) try { - const result = await this.getTrace(tx.hash) - if (result['structLogs'].length > 0) { this.trace = result['structLogs'] 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 7adc8a9312..ac802457e2 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -15,7 +15,6 @@ export const DebuggerUI = (props: DebuggerUIProps) => { const debuggerModule = props.debuggerAPI const [state, setState] = useState({ isActive: false, - statusMessage: '', debugger: null, currentReceipt: { contractAddress: null, @@ -25,7 +24,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { txNumber: '', debugging: false, opt: { - debugWithGeneratedSources: false + debugWithGeneratedSources: false, + debugWithLocalNode: false }, toastMessage: '', validationError: '', @@ -132,7 +132,6 @@ export const DebuggerUI = (props: DebuggerUIProps) => { return { ...prevState, isActive: false, - statusMessage: '', debugger: null, currentReceipt: { contractAddress: null, @@ -166,7 +165,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { return } - const web3 = await debuggerModule.getDebugWeb3() + const web3 = state.opt.debugWithLocalNode ? await debuggerModule.web3() : await debuggerModule.getDebugWeb3() try { const networkId = await web3.eth.net.getId() _paq.push(['trackEvent', 'debugger', 'startDebugging', networkId]) @@ -211,33 +210,31 @@ export const DebuggerUI = (props: DebuggerUIProps) => { debugWithGeneratedSources: state.opt.debugWithGeneratedSources }) - debuggerInstance.debug(blockNumber, txNumber, tx, () => { - listenToEvents(debuggerInstance, currentReceipt) - setState(prevState => { - return { - ...prevState, - blockNumber, - txNumber, - debugging: true, - currentReceipt, - debugger: debuggerInstance, - toastMessage: `debugging ${txNumber}`, - validationError: '' - } - }) - }).catch((error) => { - if (JSON.stringify(error) !== '{}') { - let message = 'Error: ' + JSON.stringify(error) - message = message.split('\\"').join('\'') + try { + await debuggerInstance.debug(blockNumber, txNumber, tx, () => { + listenToEvents(debuggerInstance, currentReceipt) setState(prevState => { return { ...prevState, - validationError: message + blockNumber, + txNumber, + debugging: true, + currentReceipt, + debugger: debuggerInstance, + toastMessage: `debugging ${txNumber}`, + validationError: '' } }) - } + }) + } catch (error) { unLoad() - }) + setState(prevState => { + return { + ...prevState, + validationError: error.message || error + } + }) + } } const debug = (txHash) => { @@ -277,18 +274,25 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
{ setState(prevState => { - return { ...prevState, opt: { debugWithGeneratedSources: checked } } + return { ...prevState, opt: { ...prevState.opt, debugWithGeneratedSources: checked } } }) }} type="checkbox" title="Debug with generated sources" />
+
+ { + setState(prevState => { + return { ...prevState, opt: { ...prevState.opt, debugWithLocalNode: checked } } + }) + }} type="checkbox" title="Force the debugger to use the current local node" /> + +
{ state.validationError && {state.validationError} } { state.debugging && } { state.debugging && } - { state.debugging &&
{ state.statusMessage }
} { state.debugging && } ) diff --git a/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts b/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts index e2d62d37fc..4e31ce7360 100644 --- a/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts +++ b/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts @@ -62,6 +62,7 @@ export interface IDebuggerApi { fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise getFile: (path: string) => Promise setFile: (path: string, content: string) => Promise - getDebugWeb3: () => any // returns an instance of web3.js + getDebugWeb3: () => any // returns an instance of web3.js, if applicable (mainet, goerli, ...) it returns a reference to a node from devops (so we are sure debug endpoint is available) + web3: () => any // returns an instance of web3.js showMessage (title: string, message: string): void } diff --git a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx index e86689f94e..489707b28e 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx @@ -203,10 +203,6 @@ export const ContractSelection = (props: ContractSelectionProps) => {
-