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.
93 lines
3.0 KiB
93 lines
3.0 KiB
9 years ago
|
'use strict'
|
||
|
var tape = require('tape')
|
||
7 years ago
|
var remixLib = require('remix-lib')
|
||
|
var Web3Providers = remixLib.vm.Web3Providers
|
||
8 years ago
|
var TraceManager = require('../src/trace/traceManager')
|
||
|
var CodeManager = require('../src/code/codeManager')
|
||
8 years ago
|
var web3Test = require('./resources/testWeb3')
|
||
6 years ago
|
|
||
|
let web3 = null
|
||
9 years ago
|
|
||
|
tape('CodeManager', function (t) {
|
||
|
var codeManager
|
||
8 years ago
|
var web3Providers = new Web3Providers()
|
||
|
web3Providers.addProvider('TEST', web3Test)
|
||
|
web3Providers.get('TEST', function (error, obj) {
|
||
9 years ago
|
if (error) {
|
||
8 years ago
|
var mes = 'provider TEST not defined'
|
||
|
console.log(mes)
|
||
|
t.fail(mes)
|
||
9 years ago
|
} else {
|
||
6 years ago
|
web3 = obj
|
||
6 years ago
|
var traceManager = new TraceManager({web3: web3})
|
||
8 years ago
|
codeManager = new CodeManager(traceManager)
|
||
6 years ago
|
var contractCode = web3.eth.getCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
|
||
8 years ago
|
codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary
|
||
6 years ago
|
var tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
|
||
8 years ago
|
traceManager.resolveTrace(tx, function (error, result) {
|
||
|
if (error) {
|
||
|
t.fail(' - traceManager.resolveTrace - failed ' + result)
|
||
|
} else {
|
||
|
continueTesting(t, codeManager)
|
||
|
}
|
||
|
})
|
||
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)
|
||
|
}
|
||
|
}
|
||
|
})
|
||
6 years ago
|
var tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
|
||
8 years ago
|
codeManager.resolveStep(0, tx)
|
||
|
codeManager.resolveStep(70, tx)
|
||
9 years ago
|
})
|
||
|
|
||
|
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)
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
}
|