refactor decodeStateAt

pull/5370/head
Iuri Matias 4 years ago
parent 7040895cf7
commit 09a5f6b643
  1. 17
      libs/remix-debug/src/Ethdebugger.js
  2. 20
      libs/remix-debug/test/debugger.js

@ -100,21 +100,12 @@ Ethdebugger.prototype.extractStateAt = async function (step) {
return this.solidityProxy.extractStateVariablesAt(step)
}
Ethdebugger.prototype.decodeStateAt = function (step, stateVars, callback) {
Ethdebugger.prototype.decodeStateAt = async function (step, stateVars, callback) {
try {
const address = this.traceManager.getCurrentCalledAddressAt(step)
const storageViewer = new StorageViewer({
stepIndex: step,
tx: this.tx,
address: address
}, this.storageResolver, this.traceManager)
stateDecoder.decodeState(stateVars, storageViewer).then((result) => {
if (!result.error) {
callback(null, result)
} else {
callback(result.error)
}
})
const storageViewer = new StorageViewer({stepIndex: step, tx: this.tx, address: address}, this.storageResolver, this.traceManager)
const result = await stateDecoder.decodeState(stateVars, storageViewer)
return result
} catch (error) {
callback(error)
}

@ -239,17 +239,15 @@ function testDebugging (debugManager) {
t.plan(7)
try {
const state = await debugManager.extractStateAt(312)
debugManager.decodeStateAt(312, state, (error, decodedState) => {
if (error) return t.end(error)
console.log(decodedState)
t.equal(decodedState['chairperson'].value, '0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB')
t.equal(decodedState['chairperson'].type, 'address')
t.equal(decodedState['proposals'].value[0].value.voteCount.value, '0')
t.equal(decodedState['proposals'].value[0].value.voteCount.type, 'uint256')
t.equal(decodedState['proposals'].value[0].type, 'struct Ballot.Proposal')
t.equal(decodedState['proposals'].length, '0x1')
t.equal(decodedState['proposals'].type, 'struct Ballot.Proposal[]')
})
const decodedState = await debugManager.decodeStateAt(312, state)
console.log(decodedState)
t.equal(decodedState['chairperson'].value, '0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB')
t.equal(decodedState['chairperson'].type, 'address')
t.equal(decodedState['proposals'].value[0].value.voteCount.value, '0')
t.equal(decodedState['proposals'].value[0].value.voteCount.type, 'uint256')
t.equal(decodedState['proposals'].value[0].type, 'struct Ballot.Proposal')
t.equal(decodedState['proposals'].length, '0x1')
t.equal(decodedState['proposals'].type, 'struct Ballot.Proposal[]')
} catch (error) {
if (error) return t.end(error)
}

Loading…
Cancel
Save