refactor resolveTrace into a promise

pull/5370/head
Iuri Matias 4 years ago
parent 09a5f6b643
commit 0d78f1a156
  1. 29
      libs/remix-debug/src/Ethdebugger.js
  2. 10
      libs/remix-debug/test/decoder/localsTests/int.js
  3. 10
      libs/remix-debug/test/decoder/localsTests/misc.js
  4. 10
      libs/remix-debug/test/decoder/localsTests/misc2.js
  5. 10
      libs/remix-debug/test/decoder/localsTests/structArray.js
  6. 3
      libs/remix-debug/test/decoder/stateTests/mapping.js
  7. 46
      libs/remix-lib/src/trace/traceManager.js
  8. 10
      libs/remix-lib/test/codeManager.js
  9. 10
      libs/remix-lib/test/traceManager.js

@ -112,11 +112,7 @@ Ethdebugger.prototype.decodeStateAt = async function (step, stateVars, callback)
}
Ethdebugger.prototype.storageViewAt = function (step, address) {
return new StorageViewer({
stepIndex: step,
tx: this.tx,
address: address
}, this.storageResolver, this.traceManager)
return new StorageViewer({stepIndex: step, tx: this.tx, address: address}, this.storageResolver, this.traceManager)
}
Ethdebugger.prototype.updateWeb3 = function (web3) {
@ -134,21 +130,18 @@ Ethdebugger.prototype.debug = function (tx) {
if (this.traceManager.isLoading) {
return
}
if (!tx.to) {
tx.to = traceHelper.contractCreationToken('0')
}
tx.to = tx.to || traceHelper.contractCreationToken('0')
this.tx = tx
this.traceManager.resolveTrace(tx, async (error, result) => {
if (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})
} else {
this.statusMessage = error ? error.message : 'Trace not loaded'
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'
})
}

@ -119,12 +119,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
cb()
})
})
traceManager.resolveTrace(tx, (error, result) => {
if (error) {
st.fail(error)
} else {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}
traceManager.resolveTrace(tx).then(() => {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}).catch((error) => {
st.fail(error)
})
}
})

@ -65,12 +65,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
cb()
})
})
traceManager.resolveTrace(tx, (error, result) => {
if (error) {
st.fail(error)
} else {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}
traceManager.resolveTrace(tx).then(() => {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}).catch((error) => {
st.fail(error)
})
}
})

@ -51,12 +51,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
cb()
})
})
traceManager.resolveTrace(tx, (error, result) => {
if (error) {
st.fail(error)
} else {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}
traceManager.resolveTrace(tx).then(() => {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}).catch((error) => {
st.fail(error)
})
}
})

@ -109,12 +109,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
cb()
})
})
traceManager.resolveTrace(tx, (error, result) => {
if (error) {
st.fail(error)
} else {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}
traceManager.resolveTrace(tx).then(() => {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}).catch((error) => {
st.fail(error)
})
}
})

@ -46,7 +46,8 @@ function testMapping (st, vm, privateKey, contractAddress, output, cb) {
st.end(error)
} else {
var traceManager = new TraceManager({web3: vm.web3})
traceManager.resolveTrace(tx, () => {
traceManager.resolveTrace(tx).then(() => {
var storageViewer = new StorageViewer({
stepIndex: 268,
tx: tx,

@ -17,30 +17,32 @@ function TraceManager (options) {
}
// init section
TraceManager.prototype.resolveTrace = async function (tx, callback) {
this.tx = tx
this.init()
if (!this.web3) callback('web3 not loaded', false)
this.isLoading = true
try {
const result = await this.getTrace(tx.hash)
if (result.structLogs.length > 0) {
this.trace = result.structLogs
this.traceAnalyser.analyse(result.structLogs, tx)
TraceManager.prototype.resolveTrace = async function (tx) {
return new Promise(async (resolve, reject) => {
this.tx = tx
this.init()
if (!this.web3) reject('web3 not loaded')
this.isLoading = true
try {
const result = await this.getTrace(tx.hash)
if (result.structLogs.length > 0) {
this.trace = result.structLogs
this.traceAnalyser.analyse(result.structLogs, tx)
this.isLoading = false
return resolve(true)
}
var mes = tx.hash + ' is not a contract invocation or contract creation.'
console.log(mes)
this.isLoading = false
reject(mes)
} catch (error) {
console.log(error)
this.isLoading = false
return callback(null, true)
reject(error)
}
var mes = tx.hash + ' is not a contract invocation or contract creation.'
console.log(mes)
this.isLoading = false
callback(mes, false)
} catch (error) {
console.log(error)
this.isLoading = false
callback(error, false)
}
})
}
TraceManager.prototype.getTrace = function (txHash) {

@ -23,12 +23,10 @@ tape('CodeManager', function (t) {
const contractCode = web3.eth.getCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary
const tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
traceManager.resolveTrace(tx, function (error, result) {
if (error) {
t.fail(' - traceManager.resolveTrace - failed ' + result)
} else {
continueTesting(t, codeManager)
}
traceManager.resolveTrace(tx).then(() => {
continueTesting(t, codeManager)
}).catch(() => {
t.fail(' - traceManager.resolveTrace - failed ')
})
}
})

@ -27,12 +27,10 @@ tape('TraceManager', function (t) {
t.test('TraceManager.resolveTrace', function (st) {
const tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
traceManager.resolveTrace(tx, function (error, result) {
if (error) {
st.fail(' - traceManager.resolveTrace - failed ' + result)
} else {
st.end()
}
traceManager.resolveTrace(tx).then(() => {
st.end()
}).catch(() => {
st.fail(' - traceManager.resolveTrace - failed ')
})
})

Loading…
Cancel
Save