commit
6432e80788
@ -0,0 +1,19 @@ |
||||
'use strict' |
||||
var Web3 = require('web3') |
||||
var Web3Admin = require('../util/web3Admin') |
||||
var TraceManager = require('../trace/traceManager') |
||||
var CodeManager = require('../code/codeManager') |
||||
|
||||
module.exports = { |
||||
loadContext: function () { |
||||
var web3 = new Web3() |
||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) |
||||
Web3Admin.extend(web3) |
||||
var traceManager = new TraceManager(web3) |
||||
return { |
||||
web3: web3, |
||||
traceManager: traceManager, |
||||
codeManager: new CodeManager(web3, traceManager) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
'use strict' |
||||
module.exports = { |
||||
formatMemory: function (mem, width) { |
||||
var ret = '' |
||||
if (!mem) { |
||||
return ret |
||||
} |
||||
|
||||
if (!mem.substr) { |
||||
mem = mem.join('') // geth returns an array, eth return raw string
|
||||
} |
||||
|
||||
for (var k = 0; k < mem.length; k += (width * 2)) { |
||||
var memory = mem.substr(k, width * 2) |
||||
var content = this.tryConvertAsciiFormat(memory) |
||||
ret += '0x' + k.toString(16) + ' ' + content.raw + ' ' + content.ascii + '\n' |
||||
} |
||||
return ret |
||||
}, |
||||
|
||||
tryConvertAsciiFormat: function (memorySlot) { |
||||
var ret = { ascii: '', raw: '' } |
||||
for (var k = 0; k < memorySlot.length; k += 2) { |
||||
var raw = memorySlot.substr(k, 2) |
||||
var ascii = String.fromCharCode(parseInt(raw, 16)) |
||||
ascii = ascii.replace(/\W/g, '?') |
||||
if (ascii === '') { |
||||
ascii = '?' |
||||
} |
||||
ret.ascii += ascii |
||||
ret.raw += ' ' + raw |
||||
} |
||||
return ret |
||||
} |
||||
} |
@ -1,26 +1,10 @@ |
||||
'use strict' |
||||
var ReactDOM = require('react-dom') |
||||
var React = require('react') |
||||
var Web3 = require('web3') |
||||
var Web3Admin = require('./web3Admin') |
||||
var TraceManager = require('./traceManager') |
||||
var CodeManager = require('./codeManager') |
||||
|
||||
function loadContext () { |
||||
var web3 = new Web3() |
||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) |
||||
Web3Admin.extend(web3) |
||||
var traceManager = new TraceManager(web3) |
||||
return { |
||||
web3: web3, |
||||
traceManager: traceManager, |
||||
codeManager: new CodeManager(web3, traceManager) |
||||
} |
||||
} |
||||
|
||||
var util = require('./helpers/init') |
||||
var Debugger = require('./debugger') |
||||
|
||||
ReactDOM.render( |
||||
<Debugger context={loadContext()} />, |
||||
<Debugger context={util.loadContext()} />, |
||||
document.getElementById('app') |
||||
) |
||||
|
@ -0,0 +1,7 @@ |
||||
module.exports = { |
||||
'Page Load': function (browser) { |
||||
browser |
||||
.url('http://127.0.0.1:8080') |
||||
.end() |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
'use strict' |
||||
var traceHelper = require('../src/helpers/traceHelper') |
||||
var traceInvokation = require('./resources/contractInvokationTrace') |
||||
|
||||
function TestTraceRetriever () { |
||||
this.storages = {} // contains all intial storage (by addresses)
|
||||
} |
||||
|
||||
TestTraceRetriever.prototype.getTrace = function (txHash, callback) { |
||||
console.log(traceInvokation) |
||||
callback(null, traceInvokation) |
||||
} |
||||
|
||||
/* not used */ |
||||
TestTraceRetriever.prototype.getStorage = function (tx, address, callback) { |
||||
if (traceHelper.isContractCreation(address)) { |
||||
callback(null, {}) |
||||
} else if (this.storages[address]) { |
||||
callback(null, this.storages[address]) |
||||
} else { |
||||
/* |
||||
return storage |
||||
*/ |
||||
/* |
||||
var self = this |
||||
this.web3.debug.storageAt(tx.blockNumber.toString(), tx.transactionIndex, address, function (error, result) { |
||||
self.storages[address] = result |
||||
callback(error, result) |
||||
}) |
||||
*/ |
||||
} |
||||
} |
||||
|
||||
TestTraceRetriever.prototype.debugStorageAtAvailable = function () { |
||||
return false // storageAt not available if using geth
|
||||
} |
||||
|
||||
module.exports = TestTraceRetriever |
@ -0,0 +1,77 @@ |
||||
'use strict' |
||||
var tape = require('tape') |
||||
var init = require('../src/helpers/init') |
||||
var txInvokation = require('./resources/contractInvokationTx') |
||||
var TestTraceRetriever = require('./TestTraceRetriever') |
||||
var contractCode = require('./resources/contractInvokationCode') |
||||
|
||||
tape('CodeManager', function (t) { |
||||
var codeManager |
||||
var context = init.loadContext() |
||||
codeManager = context.codeManager |
||||
context.traceManager.traceRetriever = new TestTraceRetriever() |
||||
codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary
|
||||
context.traceManager.resolveTrace(txInvokation, function (success) { |
||||
if (!success) { |
||||
t.fail(' - traceManager.resolveTrace - failed') |
||||
} else { |
||||
continueTesting(t, codeManager) |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
function continueTesting (t, codeManager) { |
||||
t.test('CodeManager.init', function (st) { |
||||
st.end() |
||||
}) |
||||
|
||||
t.test('CodeManager.resolveStep', function (st) { |
||||
st.plan(6) |
||||
codeManager.register('indexChanged', this, function (index) { |
||||
if (index === undefined || index === null) { |
||||
st.fail(index) |
||||
} else { |
||||
st.ok(index === 6 || index === 0) |
||||
} |
||||
}) |
||||
|
||||
codeManager.register('codeChanged', this, function (code, address, index) { |
||||
console.log(address + ' ' + index + ' ' + code) |
||||
if (!code) { |
||||
st.fail('no codes') |
||||
} else { |
||||
st.ok(address === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5' || address === '(Contract Creation - Step 63)') |
||||
if (address === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5') { |
||||
console.log(address + ' ' + code[25]) |
||||
st.ok(code[25].indexOf('DUP') !== -1) |
||||
} else if (address === '(Contract Creation - Step 63)') { |
||||
console.log(address + ' ' + code[25]) |
||||
st.ok(code[25].indexOf('JUMPDEST') !== -1) |
||||
} |
||||
} |
||||
}) |
||||
codeManager.resolveStep(0, txInvokation) |
||||
codeManager.resolveStep(70, txInvokation) |
||||
}) |
||||
|
||||
t.test('CodeManager.getInstructionIndex', function (st) { |
||||
st.plan(2) |
||||
codeManager.getInstructionIndex('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', 16, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === 25) |
||||
} |
||||
}) |
||||
|
||||
codeManager.getInstructionIndex('(Contract Creation - Step 63)', 70, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === 6) |
||||
} |
||||
}) |
||||
}) |
||||
} |
@ -0,0 +1,11 @@ |
||||
'use strict' |
||||
var tape = require('tape') |
||||
var init = require('../src/helpers/init') |
||||
tape('index', function (t) { |
||||
t.test('loadContext - web3', function (st) { |
||||
var context = init.loadContext() |
||||
st.notEqual(context.web3, undefined) |
||||
st.notEqual(context.web3, null) |
||||
st.end() |
||||
}) |
||||
}) |
@ -0,0 +1 @@ |
||||
module.exports = '0x60606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b11460415780636d4ce63c14605757603f565b005b605560048080359060200190919050506089565b005b606260048050506078565b6040518082815260200191505060405180910390f35b600060006000505490506086565b90565b80600060005081905550602d6040516045806100f083390180828152602001915050604051809103906000f0600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550602281016000600050819055505b505660606040526040516020806045833981016040528080519060200190919050505b806001016000600050819055505b50600a80603b6000396000f360606040526008565b00' |
File diff suppressed because one or more lines are too long
@ -0,0 +1,2 @@ |
||||
module.exports = |
||||
{'blockHash':'0xd1d34932f8733e0485b7d9bf8500c4046d650f20ed7792508c304304fa7bbfac','blockNumber':89,'from':'0x00101c5bfa3fc8bad02c9f5fd65b069306251915','gas':105967,'gasPrice':'20000000000','hash':'0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51','input':'0x60fe47b10000000000000000000000000000000000000000000000000000000000000038','nonce':3,'to':'0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5','transactionIndex':0,'value':'0'} |
@ -0,0 +1,4 @@ |
||||
'use strict' |
||||
require('./index.js') |
||||
require('./traceManager.js') |
||||
require('./codeManager.js') |
@ -0,0 +1,298 @@ |
||||
'use strict' |
||||
var TraceManager = require('../src/trace/traceManager') |
||||
var tape = require('tape') |
||||
var init = require('../src/helpers/init') |
||||
var TestTraceRetriever = require('./TestTraceRetriever') |
||||
var txInvokation = require('./resources/contractInvokationTx') |
||||
|
||||
tape('TraceManager', function (t) { |
||||
var traceManager |
||||
|
||||
t.test('TraceManager.init', function (st) { |
||||
var context = init.loadContext() |
||||
traceManager = new TraceManager(context.web3) |
||||
traceManager.traceRetriever = new TestTraceRetriever() |
||||
st.end() |
||||
}) |
||||
|
||||
t.test('TraceManager.resolveTrace', function (st) { |
||||
traceManager.resolveTrace(txInvokation, function (success) { |
||||
if (!success) { |
||||
st.fail(' - traceManager.resolveTrace - failed') |
||||
} else { |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getLength ', function (st) { |
||||
traceManager.getLength(function (error, result) { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.inRange ', function (st) { |
||||
st.notOk(traceManager.inRange(-1)) |
||||
st.ok(traceManager.inRange(10)) |
||||
st.notOk(traceManager.inRange(142)) |
||||
st.ok(traceManager.inRange(141)) |
||||
st.end() |
||||
}) |
||||
|
||||
t.test('TraceManager.getStorageAt', function (st) { |
||||
traceManager.getStorageAt(0, txInvokation, function (error, result) { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result['0x00'] === '0x2d') |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getCallData', function (st) { |
||||
traceManager.getCallDataAt(0, function (error, result) { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result[0] === '0x60fe47b10000000000000000000000000000000000000000000000000000000000000038') |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getCallStackAt', function (st) { |
||||
st.plan(3) |
||||
traceManager.getCallStackAt(0, function (error, result) { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result[0] === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5') |
||||
} |
||||
}) |
||||
|
||||
traceManager.getCallStackAt(64, function (error, result) { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result.length === 2) |
||||
st.ok(result[1] === '(Contract Creation - Step 63)') |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getStackAt', function (st) { |
||||
st.plan(3) |
||||
traceManager.getStackAt(0, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result.length === 0) |
||||
} |
||||
}) |
||||
|
||||
traceManager.getStackAt(28, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result.length === 4) |
||||
st.ok(result[3] === '0x60fe47b1') |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getLastCallChangeSince', function (st) { |
||||
st.plan(3) |
||||
traceManager.getLastCallChangeSince(10, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === 0) |
||||
} |
||||
}) |
||||
|
||||
traceManager.getLastCallChangeSince(70, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === 64) |
||||
} |
||||
}) |
||||
|
||||
traceManager.getLastCallChangeSince(111, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === 109) |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getCurrentCalledAddressAt', function (st) { |
||||
st.plan(3) |
||||
traceManager.getCurrentCalledAddressAt(10, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5') |
||||
} |
||||
}) |
||||
|
||||
traceManager.getCurrentCalledAddressAt(70, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === '(Contract Creation - Step 63)') |
||||
} |
||||
}) |
||||
|
||||
traceManager.getCurrentCalledAddressAt(111, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5') |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getContractCreationCode', function (st) { // contract code has been retrieved from the memory
|
||||
traceManager.getContractCreationCode('(Contract Creation - Step 63)', function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === '0x60606040526040516020806045833981016040528080519060200190919050505b806001016000600050819055505b50600a80603b6000396000f360606040526008565b00000000000000000000000000000000000000000000000000000000000000002d') |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getMemoryAt', function (st) { |
||||
st.plan(3) |
||||
traceManager.getMemoryAt(0, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result.length === 0) |
||||
} |
||||
}) |
||||
|
||||
traceManager.getMemoryAt(34, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result.length === 3) |
||||
st.ok(result[2] === '0000000000000000000000000000000000000000000000000000000000000060') |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getCurrentPC', function (st) { |
||||
traceManager.getCurrentPC(13, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === '65') |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getCurrentStep', function (st) { |
||||
traceManager.getCurrentStep(66, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === 2) |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getMemExpand', function (st) { |
||||
traceManager.getMemExpand(2, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === '3') |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getStepCost', function (st) { |
||||
traceManager.getStepCost(34, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === '3') |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.getRemainingGas', function (st) { |
||||
traceManager.getRemainingGas(55, function (error, result) { |
||||
console.log(result) |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
st.ok(result === '79306') |
||||
st.end() |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
t.test('TraceManager.findStepOverBack', function (st) { |
||||
var result = traceManager.findStepOverBack(116) |
||||
console.log(result) |
||||
st.ok(result === -1) |
||||
st.end() |
||||
}) |
||||
|
||||
t.test('TraceManager.findStepOverForward', function (st) { |
||||
var result = traceManager.findStepOverForward(66) |
||||
console.log(result) |
||||
st.ok(result === 108) |
||||
st.end() |
||||
}) |
||||
|
||||
t.test('TraceManager.findStepOutBack', function (st) { |
||||
var result = traceManager.findStepOutBack(70) |
||||
console.log(result) |
||||
st.ok(result === 63) |
||||
st.end() |
||||
}) |
||||
|
||||
t.test('TraceManager.findStepOutForward', function (st) { |
||||
var result = traceManager.findStepOutForward(15) |
||||
console.log(result) |
||||
st.ok(result === 142) |
||||
st.end() |
||||
}) |
||||
|
||||
t.test('TraceManager.findNextCall', function (st) { |
||||
var result = traceManager.findNextCall(10) |
||||
console.log(result) |
||||
st.ok(result === 63) |
||||
st.end() |
||||
}) |
||||
}) |
Loading…
Reference in new issue