diff --git a/libs/remix-debug/test/debugger.ts b/libs/remix-debug/test/debugger.ts index 684d9a01fd..ff859f7d4d 100644 --- a/libs/remix-debug/test/debugger.ts +++ b/libs/remix-debug/test/debugger.ts @@ -148,48 +148,50 @@ contract Ballot { winnerName_ = proposals[winningProposal()].name; } } -` +`; -var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') -var vm = vmCall.initVM(privateKey) -var output = compiler.compile(compilerInput(ballot)) -output = JSON.parse(output) -var web3VM = new remixLib.vm.Web3VMProvider() -web3VM.setVM(vm) -const param = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000148656c6c6f20576f726c64210000000000000000000000000000000000000000' -vmCall.sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['Ballot'].evm.bytecode.object + param, (error, txHash) => { - console.log(error, txHash) - if (error) { - throw error - } else { - web3VM.eth.getTransaction(txHash, (error, tx) => { - if (error) { - throw error - } else { - var debugManager = new Debugger({ - compilationResult: function () { - return { data: output } - }, - web3: web3VM - }) - - debugManager.callTree.event.register('callTreeReady', () => { - testDebugging(debugManager) - }) - debugManager.callTree.event.register('callTreeNotReady', (error) => { - console.error(error) - throw error - }) - debugManager.callTree.event.register('callTreeBuildFailed', (error) => { - console.error(error) +(async () => { + var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') + var vm = await vmCall.initVM(privateKey) + var output = compiler.compile(compilerInput(ballot)) + output = JSON.parse(output) + var web3VM = new remixLib.vm.Web3VMProvider() + web3VM.setVM(vm) + const param = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000148656c6c6f20576f726c64210000000000000000000000000000000000000000' + vmCall.sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['Ballot'].evm.bytecode.object + param, (error, txHash) => { + console.log(error, txHash) + if (error) { + throw error + } else { + web3VM.eth.getTransaction(txHash, (error, tx) => { + if (error) { throw error - }) - - debugManager.debug(tx) - } - }) - } -}) + } else { + var debugManager = new Debugger({ + compilationResult: function () { + return { data: output } + }, + web3: web3VM + }) + + debugManager.callTree.event.register('callTreeReady', () => { + testDebugging(debugManager) + }) + debugManager.callTree.event.register('callTreeNotReady', (error) => { + console.error(error) + throw error + }) + debugManager.callTree.event.register('callTreeBuildFailed', (error) => { + console.error(error) + throw error + }) + + debugManager.debug(tx) + } + }) + } + }) +})() function testDebugging (debugManager) { // stack diff --git a/libs/remix-debug/test/decoder/localDecoder.ts b/libs/remix-debug/test/decoder/localDecoder.ts index a9c82b1649..d76ff4c2c0 100644 --- a/libs/remix-debug/test/decoder/localDecoder.ts +++ b/libs/remix-debug/test/decoder/localDecoder.ts @@ -12,9 +12,9 @@ var structArrayLocalTest = require('./localsTests/structArray') var compilerInput = require('../helpers/compilerHelper').compilerInput tape('solidity', function (t) { - t.test('local decoder', function (st) { + t.test('local decoder', async function (st) { var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') - var vm = vmCall.initVM(st, privateKey) + var vm = await vmCall.initVM(st, privateKey) test(st, vm, privateKey) }) }) diff --git a/libs/remix-debug/test/decoder/stateTests/mapping.ts b/libs/remix-debug/test/decoder/stateTests/mapping.ts index 58875f9e25..eb2a0115b6 100644 --- a/libs/remix-debug/test/decoder/stateTests/mapping.ts +++ b/libs/remix-debug/test/decoder/stateTests/mapping.ts @@ -6,10 +6,10 @@ import { sendTx, initVM } from '../vmCall' import { StorageResolver } from '../../../src/storage/storageResolver' import { StorageViewer } from '../../../src/storage/storageViewer' -module.exports = function testMappingStorage (st, cb) { +module.exports = async function testMappingStorage (st, cb) { var mappingStorage = require('../contracts/mappingStorage') var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') - var vm = initVM(st, privateKey) + var vm = await initVM(st, privateKey) var output = compile(compilerInput(mappingStorage.contract)) output = JSON.parse(output) sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, txHash) { diff --git a/libs/remix-debug/test/decoder/vmCall.ts b/libs/remix-debug/test/decoder/vmCall.ts index 91d6810dd3..eae3c94b9f 100644 --- a/libs/remix-debug/test/decoder/vmCall.ts +++ b/libs/remix-debug/test/decoder/vmCall.ts @@ -16,7 +16,7 @@ export function sendTx (vm, from, to, value, data, cb) { value: new BN(value, 10), data: Buffer.from(data, 'hex') }) - tx.sign(from.privateKey) + tx = tx.sign(from.privateKey) var block = Block.fromBlockData({ header: { @@ -39,9 +39,10 @@ export function sendTx (vm, from, to, value, data, cb) { } } -function createVm (hardfork) { +async function createVm (hardfork) { const common = new Common({ chain: 'mainnet', hardfork }) const vm = new VM({ common }) + await vm.init() // vm.blockchain.validate = false return { vm, stateManager: vm.stateManager } } @@ -49,12 +50,11 @@ function createVm (hardfork) { /* Init VM / Send Transaction */ -export function initVM (st, privateKey) { - var VM = createVm('berlin') +export async function initVM (st, privateKey) { + var VM = await createVm('berlin') const vm = VM.vm - var address = utileth.privateToAddress(privateKey) - + var address = utileth.Address.fromPrivateKey(privateKey) vm.stateManager.getAccount(address).then((account) => { account.balance = new BN('f00000000000000001', 16) vm.stateManager.putAccount(address, account).catch((error) => { diff --git a/libs/remix-debug/test/vmCall.ts b/libs/remix-debug/test/vmCall.ts index 912ed68fd0..ddba208a10 100644 --- a/libs/remix-debug/test/vmCall.ts +++ b/libs/remix-debug/test/vmCall.ts @@ -15,7 +15,7 @@ function sendTx (vm, from, to, value, data, cb) { value: new BN(value, 10), data: Buffer.from(data, 'hex') }) - tx.sign(from.privateKey) + tx = tx.sign(from.privateKey) var block = Block.fromBlockData({ header: { @@ -36,12 +36,12 @@ function sendTx (vm, from, to, value, data, cb) { /* Init VM / Send Transaction */ -function initVM (privateKey) { - var address = utileth.privateToAddress(privateKey) +async function initVM (privateKey) { + var address = utileth.Address.fromPrivateKey(privateKey) var vm = new VM({ activatePrecompiles: true }) - + await vm.init() vm.stateManager.getAccount(address).then((account) => { account.balance = new BN('f00000000000000001', 16) vm.stateManager.putAccount(address, account).catch((error) => { diff --git a/libs/remix-lib/src/util.ts b/libs/remix-lib/src/util.ts index f55e5a31b6..d17129d958 100644 --- a/libs/remix-lib/src/util.ts +++ b/libs/remix-lib/src/util.ts @@ -1,5 +1,5 @@ 'use strict' -import { BN, bufferToHex, keccak, setLengthLeft, intToBuffer } from 'ethereumjs-util' +import { BN, bufferToHex, keccak, setLengthLeft, toBuffer } from 'ethereumjs-util' /* contains misc util: @TODO should be splitted @@ -165,12 +165,7 @@ export function buildCallPath (index, rootCall) { */ // eslint-disable-next-line camelcase export function sha3_256 (value) { - if (typeof value === 'string') { - value = Buffer.from(value.replace('0x', ''), 'hex') - } - if (Number.isInteger(value)) { - value = intToBuffer(value) - } + value = toBuffer(value) const retInBuffer: Buffer = keccak(setLengthLeft(value, 32)) return bufferToHex(retInBuffer) }