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'
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 TraceManager = remixLib.trace.TraceManager
const CodeManager = remixLib.code.CodeManager
const traceHelper = remixLib.helpers.trace
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
*
@ -58,17 +54,11 @@ Ethdebugger.prototype.resolveStep = function (index) {
}
Ethdebugger.prototype.setCompilationResult = function (compilationResult) {
if (compilationResult && compilationResult.data) {
this.solidityProxy.reset(compilationResult.data)
} else {
this.solidityProxy.reset({})
}
this.solidityProxy.reset((compilationResult && compilationResult.data) || {})
}
Ethdebugger.prototype.sourceLocationFromVMTraceIndex = function (address, stepIndex, callback) {
this.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, stepIndex, this.solidityProxy.contracts).then((rawLocation) => {
callback(null, rawLocation)
}).catch(callback)
Ethdebugger.prototype.sourceLocationFromVMTraceIndex = async function (address, stepIndex) {
return this.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, stepIndex, this.solidityProxy.contracts)
}
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)
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 {
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)
debugManager.decodeLocalsAt(330, location, (error, decodedlocals) => {
if (error) return t.end(error)
t.equal(JSON.stringify(decodedlocals), JSON.stringify(tested))
})
t.equal(JSON.stringify(decodedlocals), JSON.stringify(tested))
})
// })
} catch (error) {
return t.end(error)
}

Loading…
Cancel
Save