remix-project mirror
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.
remix-project/libs/remix-debug/test/codeManager.ts

72 lines
2.5 KiB

9 years ago
'use strict'
import tape from 'tape'
4 years ago
import { TraceManager } from '../src/trace/traceManager'
import { CodeManager } from '../src/code/codeManager'
const web3Test = require('./resources/testWeb3.ts')
9 years ago
tape('CodeManager', function (t) {
const traceManager = new TraceManager({web3: web3Test})
# This is a combination of 50 commits. # This is the 1st commit message: executors # This is the commit message #2: libs # This is the commit message #3: remixd # This is the commit message #4: add react app # This is the commit message #5: debugging # This is the commit message #6: debug + sol # This is the commit message #7: fixes # This is the commit message #8: tsconfig # This is the commit message #9: ast walker # This is the commit message #10: as walker # This is the commit message #11: remixd etc # This is the commit message #12: commander # This is the commit message #13: remove jest # This is the commit message #14: rm ui files # This is the commit message #15: rm reserved keywords # This is the commit message #16: testrunner # This is the commit message #17: compiler # This is the commit message #18: production build # This is the commit message #19: config # This is the commit message #20: config # This is the commit message #21: web types # This is the commit message #22: update react # This is the commit message #23: add vm # This is the commit message #24: add workers # This is the commit message #25: worker2 # This is the commit message #26: rm react app # This is the commit message #27: remixd # This is the commit message #28: worker fix # This is the commit message #29: fix detection # This is the commit message #30: revert react # This is the commit message #31: rename type # This is the commit message #32: loading handler # This is the commit message #33: remove import # This is the commit message #34: rename # This is the commit message #35: local plugin # This is the commit message #36: etherscan # This is the commit message #37: revert react # This is the commit message #38: port # This is the commit message #39: rm worker # This is the commit message #40: publicpath # This is the commit message #41: fix test # This is the commit message #42: 112 # This is the commit message #43: show version # This is the commit message #44: "axios": "1.1.2", # This is the commit message #45: config # This is the commit message #46: lint # This is the commit message #47: fix build # This is the commit message #48: lint # This is the commit message #49: error on purpose # This is the commit message #50: test error
2 years ago
const 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)
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)
}
})
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)
}
}
})
const tx = web3Test.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
codeManager.resolveStep(0, tx)
codeManager.resolveStep(70, tx)
9 years ago
})
t.test('CodeManager.getInstructionIndex', function (st) {
st.plan(2)
try {
const result = codeManager.getInstructionIndex('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', 16)
9 years ago
console.log(result)
st.ok(result === 25)
} catch (error) {
st.fail(error)
}
9 years ago
try {
const result = codeManager.getInstructionIndex('(Contract Creation - Step 63)', 70)
9 years ago
console.log(result)
st.ok(result === 6)
} catch (error) {
st.fail(error)
}
9 years ago
})
}