make sourceLocationFromVMTraceIndex a promise

pull/5370/head
Iuri Matias 4 years ago
parent d95be9f42b
commit 62aac4ac84
  1. 26
      libs/remix-debug/src/Ethdebugger.js
  2. 11
      libs/remix-debug/test/debugger.js

@ -1,20 +1,16 @@
'use strict' 'use strict'
const StorageViewer = require('./storage/storageViewer')
const StorageResolver = require('./storage/storageResolver')
const SolidityDecoder = require('./solidity-decoder')
const SolidityProxy = SolidityDecoder.SolidityProxy
const stateDecoder = SolidityDecoder.stateDecoder
const localDecoder = SolidityDecoder.localDecoder
const InternalCallTree = SolidityDecoder.InternalCallTree
const remixLib = require('@remix-project/remix-lib') const remixLib = require('@remix-project/remix-lib')
const TraceManager = remixLib.trace.TraceManager const TraceManager = remixLib.trace.TraceManager
const CodeManager = remixLib.code.CodeManager const CodeManager = remixLib.code.CodeManager
const traceHelper = remixLib.helpers.trace const traceHelper = remixLib.helpers.trace
const EventManager = remixLib.EventManager const EventManager = remixLib.EventManager
const {SolidityProxy, stateDecoder, localDecoder, InternalCallTree} = require('./solidity-decoder')
const StorageViewer = require('./storage/storageViewer')
const StorageResolver = require('./storage/storageResolver')
/** /**
* Ethdebugger is a wrapper around a few classes that helps debugging a transaction * Ethdebugger is a wrapper around a few classes that helps debugging a transaction
* *
@ -58,17 +54,11 @@ Ethdebugger.prototype.resolveStep = function (index) {
} }
Ethdebugger.prototype.setCompilationResult = function (compilationResult) { Ethdebugger.prototype.setCompilationResult = function (compilationResult) {
if (compilationResult && compilationResult.data) { this.solidityProxy.reset((compilationResult && compilationResult.data) || {})
this.solidityProxy.reset(compilationResult.data)
} else {
this.solidityProxy.reset({})
}
} }
Ethdebugger.prototype.sourceLocationFromVMTraceIndex = function (address, stepIndex, callback) { Ethdebugger.prototype.sourceLocationFromVMTraceIndex = async function (address, stepIndex) {
this.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, stepIndex, this.solidityProxy.contracts).then((rawLocation) => { return this.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, stepIndex, this.solidityProxy.contracts)
callback(null, rawLocation)
}).catch(callback)
} }
Ethdebugger.prototype.sourceLocationFromInstructionIndex = function (address, instIndex, callback) { Ethdebugger.prototype.sourceLocationFromInstructionIndex = function (address, instIndex, callback) {

@ -253,19 +253,16 @@ function testDebugging (debugManager) {
}) })
}) })
tape('traceManager.decodeLocalsAt', (t) => { tape('traceManager.decodeLocalsAt', async (t) => {
t.plan(1) t.plan(1)
const tested = JSON.parse('{"proposalNames":{"value":[{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"}],"length":"0x1","type":"bytes32[]"},"p":{"value":"45","type":"uint256"},"addressLocal":{"value":"0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB","type":"address"},"i":{"value":"2","type":"uint256"},"proposalsLocals":{"value":[{"value":{"name":{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"},"voteCount":{"value":"0","type":"uint256"}},"type":"struct Ballot.Proposal"}],"length":"0x1","type":"struct Ballot.Proposal[]"}}') const tested = JSON.parse('{"proposalNames":{"value":[{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"}],"length":"0x1","type":"bytes32[]"},"p":{"value":"45","type":"uint256"},"addressLocal":{"value":"0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB","type":"address"},"i":{"value":"2","type":"uint256"},"proposalsLocals":{"value":[{"value":{"name":{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"},"voteCount":{"value":"0","type":"uint256"}},"type":"struct Ballot.Proposal"}],"length":"0x1","type":"struct Ballot.Proposal[]"}}')
try { try {
const address = debugManager.traceManager.getCurrentCalledAddressAt(330) const address = debugManager.traceManager.getCurrentCalledAddressAt(330)
debugManager.sourceLocationFromVMTraceIndex(address, 330, (error, location) => { const location = await debugManager.sourceLocationFromVMTraceIndex(address, 330)
debugManager.decodeLocalsAt(330, location, (error, decodedlocals) => {
if (error) return t.end(error) if (error) return t.end(error)
debugManager.decodeLocalsAt(330, location, (error, decodedlocals) => { t.equal(JSON.stringify(decodedlocals), JSON.stringify(tested))
if (error) return t.end(error)
t.equal(JSON.stringify(decodedlocals), JSON.stringify(tested))
})
}) })
// })
} catch (error) { } catch (error) {
return t.end(error) return t.end(error)
} }

Loading…
Cancel
Save