Fix yarn nx run remix-debug:test

pull/5370/head
Wyatt Barnes 2 years ago
parent 3d75e0cefc
commit 568283d939
  1. 9
      libs/remix-debug/src/code/codeManager.ts
  2. 67
      libs/remix-debug/src/init.ts
  3. 10
      libs/remix-debug/test/debugger.ts
  4. 9
      libs/remix-debug/test/decoder/localsTests/calldata.ts
  5. 9
      libs/remix-debug/test/decoder/localsTests/int.ts
  6. 9
      libs/remix-debug/test/decoder/localsTests/misc.ts
  7. 9
      libs/remix-debug/test/decoder/localsTests/misc2.ts
  8. 9
      libs/remix-debug/test/decoder/localsTests/structArray.ts
  9. 26
      libs/remix-debug/test/decoder/stateTests/mapping.ts
  10. 2
      libs/remix-debug/test/vmCall.ts

@ -26,12 +26,9 @@ export class CodeManager {
this.codeResolver = new CodeResolver({
getCode: async (address) => {
return new Promise((resolve, reject) => {
this.traceManager.web3.eth.getCode(address, (error, code) => {
if (error) {
return reject(error)
}
return resolve(code)
})
this.traceManager.web3.eth.getCode(address)
.then(code => resolve(code))
.catch(error => reject(error))
})
},
fork: this.traceManager.getCurrentFork()

@ -1,16 +1,16 @@
'use strict'
import Web3 from 'web3'
import Web3, { Web3PluginBase } from 'web3'
export function loadWeb3 (url) {
if (!url) url = 'http://localhost:8545'
const web3 = new Web3()
web3.setProvider(new Web3.providers.HttpProvider(url))
extend(web3)
web3.registerPlugin(new Web3DebugPlugin(web3))
return web3
}
export function extendWeb3 (web3) {
extend(web3)
web3.registerPlugin(new Web3DebugPlugin(web3))
}
export function setProvider (web3, url) {
@ -31,43 +31,40 @@ export function web3DebugNode (network) {
return null
}
export function extend (web3) {
if (!web3.extend) {
return
}
// DEBUG
const methods = []
if (!(web3.debug && web3.debug.preimage)) {
methods.push(new web3.extend.Method({
name: 'preimage',
call: 'debug_preimage',
inputFormatter: [null],
params: 1
}))
class Web3DebugPlugin extends Web3PluginBase {
public pluginNamespace = 'debug'
private _web3;
constructor(web3) {
super()
this._web3 = web3;
}
if (!(web3.debug && web3.debug.traceTransaction)) {
methods.push(new web3.extend.Method({
name: 'traceTransaction',
call: 'debug_traceTransaction',
inputFormatter: [null, null],
params: 2
}))
public preimage(key, cb) {
this._web3.requestManager.send({
method: 'debug_preimage',
params: [key]
})
.then(result => cb(null, result))
.catch(error => cb(error))
}
if (!(web3.debug && web3.debug.storageRangeAt)) {
methods.push(new web3.extend.Method({
name: 'storageRangeAt',
call: 'debug_storageRangeAt',
inputFormatter: [null, null, null, null, null],
params: 5
}))
public traceTransaction(txHash, options, cb) {
this._web3.requestManager.send({
method: 'debug_traceTransaction',
params: [txHash, options]
})
.then(result => cb(null, result))
.catch(error => cb(error))
}
if (methods.length > 0) {
web3.extend({
property: 'debug',
methods: methods,
properties: []
public storageRangeAt(txBlockHash, txIndex, address, start, maxSize, cb) {
this._web3.requestManager.send({
method: 'debug_storageRangeAt',
params: [txBlockHash, txIndex, address, start, maxSize]
})
.then(result => cb(null, result))
.catch(error => cb(error))
}
}

@ -156,15 +156,13 @@ contract Ballot {
output = JSON.parse(output)
const param = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000148656c6c6f20576f726c64210000000000000000000000000000000000000000'
const web3 = await vmCall.getWeb3()
vmCall.sendTx(web3, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['Ballot'].evm.bytecode.object + param, (error, hash) => {
vmCall.sendTx(web3, {nonce: 0, privateKey: privateKey}, undefined, 0, output.contracts['test.sol']['Ballot'].evm.bytecode.object + param, (error, hash) => {
console.log(error, hash)
if (error) {
throw error
} else {
web3.eth.getTransaction(hash, (error, tx) => {
if (error) {
throw error
} else {
web3.eth.getTransaction(hash)
.then(tx => {
const sources = {
target: 'test.sol',
sources: { 'test.sol': { content: ballot } }
@ -193,8 +191,8 @@ contract Ballot {
})
debugManager.debug(tx)
}
})
.catch(error => { throw error })
}
})
})()

@ -15,7 +15,7 @@ module.exports = async function (st, privateKey, contractBytecode, compilationRe
let web3
try {
web3 = await (vmCall as any).getWeb3()
const hash = await (vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode)
const hash = await (vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, undefined, 0, contractBytecode)
const receipt = await web3.eth.getTransactionReceipt(hash)
const to = receipt.contractAddress
console.log('to', to)
@ -25,10 +25,8 @@ module.exports = async function (st, privateKey, contractBytecode, compilationRe
return st.fail(e)
}
return new Promise((resolve) => {
web3.eth.getTransaction(txHash, function (error, tx) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(txHash)
.then(tx => {
const traceManager = new TraceManager({ web3 })
const codeManager = new CodeManager(traceManager)
codeManager.clear()
@ -72,5 +70,6 @@ module.exports = async function (st, privateKey, contractBytecode, compilationRe
st.fail(error)
})
})
.catch(error => st.fail(error))
})
}

@ -14,14 +14,12 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(hash, function (error, tx) {
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, undefined, 0, contractBytecode, function (error, hash) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(hash)
.then(tx => {
tx.to = contractCreationToken('0')
const traceManager = new TraceManager({ web3 })
const codeManager = new CodeManager(traceManager)
@ -144,6 +142,7 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,
st.fail(error)
})
})
.catch(error => st.fail(error))
})
})
}

@ -13,14 +13,12 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(hash, function (error, tx) {
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, undefined, 0, contractBytecode, function (error, hash) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(hash)
.then(tx => {
tx.to = contractCreationToken('0')
const traceManager = new TraceManager({ web3 })
const codeManager = new CodeManager(traceManager)
@ -84,6 +82,7 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,
st.fail(error)
})
})
.catch(error => st.fail(error))
})
})
}

@ -13,14 +13,12 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(hash, function (error, tx) {
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, undefined, 0, contractBytecode, function (error, hash) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(hash)
.then(tx => {
tx.to = contractCreationToken('0')
const traceManager = new TraceManager({ web3 })
const codeManager = new CodeManager(traceManager)
@ -70,6 +68,7 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,
st.fail(error)
})
})
.catch(error => st.fail(error))
})
})
}

@ -13,14 +13,12 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,c
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(hash, function (error, tx) {
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, undefined, 0, contractBytecode, function (error, hash) {
if (error) {
return st.fail(error)
}
web3.eth.getTransaction(hash)
.then(tx => {
tx.to = contractCreationToken('0')
const traceManager = new TraceManager({ web3 })
const codeManager = new CodeManager(traceManager)
@ -130,6 +128,7 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,c
st.fail(error)
})
})
.catch(error => st.fail(error))
})
})
}

@ -23,22 +23,22 @@ module.exports = async function testMappingStorage (st, cb) {
}
const compilationResults = new CompilerAbstract('json', output, sources)
const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, hash) {
if (error) {
console.log(error)
st.end(error)
} else {
web3.eth.getTransactionReceipt(hash, (error, tx) => {
(vmCall as any).sendTx(web3, {nonce: 0, privateKey: privateKey}, undefined, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, hash) {
if (error) {
console.log(error)
st.end(error)
} else {
web3.eth.getTransactionReceipt(hash)
.then(tx =>
// const storage = await this.vm.stateManager.dumpStorage(data.to)
// (vmCall as any).web3().eth.getCode(tx.contractAddress).then((code) => console.log('code:', code))
// (vmCall as any).web3().debug.traceTransaction(hash).then((code) => console.log('trace:', code))
testMapping(st, privateKey, tx.contractAddress, output, compilationResults, web3, cb)
// st.end()
}
)
.catch(error => {
console.log(error)
st.end(error)
})
}
})
@ -51,11 +51,8 @@ function testMapping (st, privateKey, contractAddress, output, compilationResult
console.log(error)
st.end(error)
} else {
web3.eth.getTransaction(hash, (error, tx) => {
if (error) {
console.log(error)
st.end(error)
} else {
web3.eth.getTransaction(hash)
.then(tx => {
const traceManager = new TraceManager({ web3 })
const codeManager = new CodeManager(traceManager)
codeManager.clear()
@ -101,7 +98,10 @@ function testMapping (st, privateKey, contractAddress, output, compilationResult
}).catch((error) => {
st.fail(error)
})
}
})
.catch(error => {
console.log(error)
st.end(error)
})
}
})

@ -1,8 +1,8 @@
'use strict'
import { extendWeb3 } from '../src/init'
import { Address } from '@ethereumjs/util'
import { Web3 } from 'web3';
const { Provider } = require('@remix-project/remix-simulator')
const Web3 = require('web3')
async function getWeb3 () {

Loading…
Cancel
Save