You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.5 KiB
72 lines
2.5 KiB
9 years ago
|
'use strict'
|
||
5 years ago
|
const tape = require('tape')
|
||
|
const TraceManager = require('../src/trace/traceManager')
|
||
|
const CodeManager = require('../src/code/codeManager')
|
||
|
const web3Test = require('./resources/testWeb3')
|
||
7 years ago
|
|
||
9 years ago
|
tape('CodeManager', function (t) {
|
||
4 years ago
|
const traceManager = new TraceManager({web3: web3Test})
|
||
|
let codeManager = new CodeManager(traceManager)
|
||
|
const contractCode = web3Test.eth.getCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
|
||
|
codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary
|
||
|
const tx = web3Test.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
|
||
|
traceManager.resolveTrace(tx).then(() => {
|
||
|
continueTesting(t, codeManager)
|
||
|
}).catch(() => {
|
||
|
t.fail(' - traceManager.resolveTrace - failed ')
|
||
9 years ago
|
})
|
||
|
})
|
||
|
|
||
|
function continueTesting (t, codeManager) {
|
||
|
t.test('CodeManager.init', function (st) {
|
||
|
st.end()
|
||
|
})
|
||
|
|
||
|
t.test('CodeManager.resolveStep', function (st) {
|
||
|
st.plan(6)
|
||
8 years ago
|
codeManager.event.register('changed', this, function (code, address, index) {
|
||
9 years ago
|
if (index === undefined || index === null) {
|
||
|
st.fail(index)
|
||
|
} else {
|
||
|
st.ok(index === 6 || index === 0)
|
||
|
}
|
||
|
})
|
||
|
|
||
8 years ago
|
codeManager.event.register('changed', this, function (code, address, index) {
|
||
9 years ago
|
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)
|
||
|
}
|
||
|
}
|
||
|
})
|
||
4 years ago
|
const tx = web3Test.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
|
||
9 years ago
|
codeManager.resolveStep(0, tx)
|
||
|
codeManager.resolveStep(70, tx)
|
||
9 years ago
|
})
|
||
|
|
||
|
t.test('CodeManager.getInstructionIndex', function (st) {
|
||
|
st.plan(2)
|
||
4 years ago
|
try {
|
||
4 years ago
|
const result = codeManager.getInstructionIndex('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', 16)
|
||
9 years ago
|
console.log(result)
|
||
4 years ago
|
st.ok(result === 25)
|
||
|
} catch (error) {
|
||
|
st.fail(error)
|
||
|
}
|
||
9 years ago
|
|
||
4 years ago
|
try {
|
||
4 years ago
|
const result = codeManager.getInstructionIndex('(Contract Creation - Step 63)', 70)
|
||
9 years ago
|
console.log(result)
|
||
4 years ago
|
st.ok(result === 6)
|
||
|
} catch (error) {
|
||
|
st.fail(error)
|
||
|
}
|
||
9 years ago
|
})
|
||
4 years ago
|
}
|