From eae7f2d0cfd4e134a7ede073d9064c62ae7db9da Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 29 Sep 2021 09:39:43 +0200 Subject: [PATCH 01/16] refactor and fix remix-debug tests --- libs/remix-debug/package.json | 1 + libs/remix-debug/test/debugger.ts | 25 +++--- libs/remix-debug/test/decoder/localDecoder.ts | 19 ++--- .../test/decoder/localsTests/calldata.ts | 21 +++-- .../test/decoder/localsTests/int.ts | 16 ++-- .../test/decoder/localsTests/misc.ts | 16 ++-- .../test/decoder/localsTests/misc2.ts | 14 ++-- .../test/decoder/localsTests/structArray.ts | 14 ++-- .../test/decoder/stateTests/mapping.ts | 39 +++++---- libs/remix-debug/test/decoder/vmCall.ts | 76 ----------------- libs/remix-debug/test/tests.ts | 2 +- libs/remix-debug/test/vmCall.ts | 83 ++++++++----------- .../src/web3Provider/web3VmProvider.ts | 5 ++ libs/remix-simulator/src/vm-context.ts | 62 +++++++------- 14 files changed, 157 insertions(+), 236 deletions(-) delete mode 100644 libs/remix-debug/test/decoder/vmCall.ts diff --git a/libs/remix-debug/package.json b/libs/remix-debug/package.json index 3659c0d4ae..5be0192f86 100644 --- a/libs/remix-debug/package.json +++ b/libs/remix-debug/package.json @@ -24,6 +24,7 @@ "@ethereumjs/vm": "^5.5.0", "@remix-project/remix-astwalker": "^0.0.37", "@remix-project/remix-lib": "^0.5.7", + "@remix-project/remix-simulator": "^0.2.7", "async": "^2.6.2", "commander": "^2.19.0", "deep-equal": "^1.0.1", diff --git a/libs/remix-debug/test/debugger.ts b/libs/remix-debug/test/debugger.ts index ff859f7d4d..e98f24d839 100644 --- a/libs/remix-debug/test/debugger.ts +++ b/libs/remix-debug/test/debugger.ts @@ -7,7 +7,6 @@ import { BreakpointManager } from '../src/code/breakpointManager' var compiler = require('solc') var vmCall = require('./vmCall') -var remixLib = require('@remix-project/remix-lib') var ballot = `pragma solidity >=0.4.22 <0.8.0; @@ -151,19 +150,17 @@ contract Ballot { `; (async () => { - var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') - var vm = await vmCall.initVM(privateKey) + var privateKey = Buffer.from('503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb', 'hex') 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) + 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) => { + console.log(error, hash) if (error) { throw error } else { - web3VM.eth.getTransaction(txHash, (error, tx) => { + web3.eth.getTransaction(hash, (error, tx) => { if (error) { throw error } else { @@ -171,7 +168,7 @@ contract Ballot { compilationResult: function () { return { data: output } }, - web3: web3VM + web3: web3 }) debugManager.callTree.event.register('callTreeReady', () => { @@ -230,7 +227,7 @@ function testDebugging (debugManager) { var storageView = debugManager.storageViewAt(196, address) storageView.storageRange().then((storage) => { - t.equal(JSON.stringify(storage), JSON.stringify({ '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563': { key: '0x0000000000000000000000000000000000000000000000000000000000000000', value: '0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db' } })) + t.equal(JSON.stringify(storage), JSON.stringify({ '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563': { key: '0x0000000000000000000000000000000000000000000000000000000000000000', value: '0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4' } })) }).catch((error) => { if (error) return t.end(error) }) @@ -245,7 +242,7 @@ function testDebugging (debugManager) { const state = await debugManager.extractStateAt(312) const decodedState = await debugManager.decodeStateAt(312, state) console.log(decodedState) - t.equal(decodedState['chairperson'].value, '0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB') + t.equal(decodedState['chairperson'].value, '0x5B38DA6A701C568545DCFCB03FCB875F56BEDDC4') t.equal(decodedState['chairperson'].type, 'address') t.equal(decodedState['proposals'].value[0].value.voteCount.value, '0') t.equal(decodedState['proposals'].value[0].value.voteCount.type, 'uint256') @@ -259,13 +256,15 @@ function testDebugging (debugManager) { tape('traceManager.decodeLocalsAt', async (t) => { t.plan(1) - const tested = JSON.parse('{"proposalNames":{"value":[{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"}],"length":"0x1","type":"bytes32[]","cursor":1,"hasNext":false},"p":{"value":"45","type":"uint256"},"addressLocal":{"value":"0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB","type":"address"},"i":{"value":"2","type":"uint256"},"proposalsLocals":{"value":[{"value":{"name":{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"},"voteCount":{"value":"0","type":"uint256"}},"type":"struct Ballot.Proposal"}],"length":"0x1","type":"struct Ballot.Proposal[]"}}') + const tested = JSON.parse('{"proposalNames":{"value":[{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"}],"length":"0x1","type":"bytes32[]","cursor":1,"hasNext":false},"p":{"value":"45","type":"uint256"},"addressLocal":{"value":"0x5B38DA6A701C568545DCFCB03FCB875F56BEDDC4","type":"address"},"i":{"value":"2","type":"uint256"},"proposalsLocals":{"value":[{"value":{"name":{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"},"voteCount":{"value":"0","type":"uint256"}},"type":"struct Ballot.Proposal"}],"length":"0x1","type":"struct Ballot.Proposal[]"}}') try { const address = debugManager.traceManager.getCurrentCalledAddressAt(327) const location = await debugManager.sourceLocationFromVMTraceIndex(address, 327) debugManager.decodeLocalsAt(327, location, (error, decodedlocals) => { if (error) return t.end(error) - t.ok(deepequal(decodedlocals, tested), `locals does not match. expected: ${JSON.stringify(tested)} - current: ${decodedlocals}`) + const res = deepequal(decodedlocals, tested) + console.log(res) + t.ok(res, `test if locals does match. expected: ${JSON.stringify(tested)} - current: ${JSON.stringify(decodedlocals)}`) }) } catch (error) { return t.end(error) diff --git a/libs/remix-debug/test/decoder/localDecoder.ts b/libs/remix-debug/test/decoder/localDecoder.ts index 2a8f4f8997..fc79752e08 100644 --- a/libs/remix-debug/test/decoder/localDecoder.ts +++ b/libs/remix-debug/test/decoder/localDecoder.ts @@ -5,7 +5,7 @@ var intLocal = require('./contracts/intLocal') var miscLocal = require('./contracts/miscLocal') var structArrayLocal = require('./contracts/structArrayLocal') var calldataLocal = require('./contracts/calldata') -var vmCall = require('./vmCall') +var vmCall = require('../vmCall') var intLocalTest = require('./localsTests/int') var miscLocalTest = require('./localsTests/misc') var misc2LocalTest = require('./localsTests/misc2') @@ -15,29 +15,28 @@ var compilerInput = require('../helpers/compilerHelper').compilerInput tape('solidity', function (t) { t.test('local decoder', async function (st) { - var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') - var vm = await vmCall.initVM(st, privateKey) - await test(st, vm, privateKey) + var privateKey = Buffer.from('503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb', 'hex') + await test(st, privateKey) }) }) -async function test (st, vm, privateKey) { +async function test (st, privateKey) { var output = compiler.compile(compilerInput(intLocal.contract)) output = JSON.parse(output) - await intLocalTest(st, vm, privateKey, output.contracts['test.sol']['intLocal'].evm.bytecode.object, output) + await intLocalTest(st, privateKey, output.contracts['test.sol']['intLocal'].evm.bytecode.object, output) output = compiler.compile(compilerInput(miscLocal.contract)) output = JSON.parse(output) - await miscLocalTest(st, vm, privateKey, output.contracts['test.sol']['miscLocal'].evm.bytecode.object, output) + await miscLocalTest(st, privateKey, output.contracts['test.sol']['miscLocal'].evm.bytecode.object, output) output = compiler.compile(compilerInput(miscLocal.contract)) output = JSON.parse(output) - await misc2LocalTest(st, vm, privateKey, output.contracts['test.sol']['miscLocal2'].evm.bytecode.object, output) + await misc2LocalTest(st, privateKey, output.contracts['test.sol']['miscLocal2'].evm.bytecode.object, output) output = compiler.compile(compilerInput(structArrayLocal.contract)) output = JSON.parse(output) - await structArrayLocalTest(st, vm, privateKey, output.contracts['test.sol']['structArrayLocal'].evm.bytecode.object, output) + await structArrayLocalTest(st, privateKey, output.contracts['test.sol']['structArrayLocal'].evm.bytecode.object, output) output = compiler.compile(compilerInput(calldataLocal.contract)) output = JSON.parse(output) - await calldataLocalTest(st, vm, privateKey, output.contracts['test.sol']['calldataLocal'].evm.bytecode.object, output) + await calldataLocalTest(st, privateKey, output.contracts['test.sol']['calldataLocal'].evm.bytecode.object, output) st.end() } diff --git a/libs/remix-debug/test/decoder/localsTests/calldata.ts b/libs/remix-debug/test/decoder/localsTests/calldata.ts index 8f7d3b5fa8..2cab6ced8d 100644 --- a/libs/remix-debug/test/decoder/localsTests/calldata.ts +++ b/libs/remix-debug/test/decoder/localsTests/calldata.ts @@ -1,7 +1,7 @@ 'use strict' import deepequal from 'deep-equal' -import { sendTx } from '../vmCall' +import * as vmCall from '../../vmCall' import { TraceManager } from '../../../src/trace/traceManager' import { CodeManager } from '../../../src/code/codeManager' import { SolidityProxy } from '../../../src/solidity-decoder/solidityProxy' @@ -9,23 +9,26 @@ import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree import { EventManager } from '../../../src/eventManager' import * as helper from './helper' -module.exports = async function (st, vm, privateKey, contractBytecode, compilationResult) { +module.exports = async function (st, privateKey, contractBytecode, compilationResult) { let txHash + let web3 try { - let data = await sendTx(vm, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode) - const to = (data as any).result.createdAddress.toString() + web3 = await (vmCall as any).getWeb3() + let hash = await (vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode) + const receipt = await web3.eth.getTransactionReceipt(hash) + const to = receipt.contractAddress + console.log('to', to) // call to level11 - data = await sendTx(vm, { nonce: 1, privateKey: privateKey }, to, 0, 'a372a595000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015400000000000000000000000000000000000000000000000000000000000000') - txHash = (data as any).hash + txHash = await (vmCall as any).sendTx(web3, { nonce: 1, privateKey: privateKey }, to, 0, 'a372a595000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015400000000000000000000000000000000000000000000000000000000000000') } catch (e) { return st.fail(e) } - return new Promise((resolve) => { - vm.web3.eth.getTransaction(txHash, function (error, tx) { + return new Promise((resolve) => { + web3.eth.getTransaction(txHash, function (error, tx) { if (error) { return st.fail(error) } - var traceManager = new TraceManager({ web3: vm.web3 }) + var traceManager = new TraceManager({ web3 }) var codeManager = new CodeManager(traceManager) codeManager.clear() var solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager), getCode: codeManager.getCode.bind(codeManager) }) diff --git a/libs/remix-debug/test/decoder/localsTests/int.ts b/libs/remix-debug/test/decoder/localsTests/int.ts index b8e0200ff5..9bf1c4307f 100644 --- a/libs/remix-debug/test/decoder/localsTests/int.ts +++ b/libs/remix-debug/test/decoder/localsTests/int.ts @@ -1,6 +1,6 @@ 'use strict' -import { sendTx } from '../vmCall' +import * as vmCall from '../../vmCall' import { TraceManager } from '../../../src/trace/traceManager' import { CodeManager } from '../../../src/code/codeManager' import { contractCreationToken } from '../../../src/trace/traceHelper' @@ -9,19 +9,19 @@ import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree import { EventManager } from '../../../src/eventManager' import * as helper from './helper' -module.exports = function (st, vm, privateKey, contractBytecode, compilationResult) { - return new Promise((resolve) => { - sendTx(vm, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, data) { +module.exports = function (st, privateKey, contractBytecode, compilationResult) { + return new Promise(async (resolve) => { + let 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) } - const txHash = data.hash - vm.web3.eth.getTransaction(txHash, function (error, tx) { + web3.eth.getTransaction(hash, function (error, tx) { if (error) { return st.fail(error) } tx.to = contractCreationToken('0') - var traceManager = new TraceManager({ web3: vm.web3 }) + var traceManager = new TraceManager({ web3 }) var codeManager = new CodeManager(traceManager) codeManager.clear() var solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager), getCode: codeManager.getCode.bind(codeManager) }) @@ -125,6 +125,6 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu }) }) }) - }) + }) } diff --git a/libs/remix-debug/test/decoder/localsTests/misc.ts b/libs/remix-debug/test/decoder/localsTests/misc.ts index 7d59d2fbe7..6caaa01311 100644 --- a/libs/remix-debug/test/decoder/localsTests/misc.ts +++ b/libs/remix-debug/test/decoder/localsTests/misc.ts @@ -1,5 +1,5 @@ 'use strict' -import { sendTx } from '../vmCall' +import * as vmCall from '../../vmCall' import { contractCreationToken } from '../../../src/trace/traceHelper' import { SolidityProxy } from '../../../src/solidity-decoder/solidityProxy' import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree' @@ -8,19 +8,19 @@ import * as helper from './helper' import { TraceManager } from '../../../src/trace/traceManager' import { CodeManager } from '../../../src/code/codeManager' -module.exports = function (st, vm, privateKey, contractBytecode, compilationResult) { - return new Promise((resolve) => { - sendTx(vm, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, data) { +module.exports = function (st, privateKey, contractBytecode, compilationResult) { + 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) } - const txHash = data.hash - vm.web3.eth.getTransaction(txHash, function (error, tx) { + web3.eth.getTransaction(hash, function (error, tx) { if (error) { return st.fail(error) } tx.to = contractCreationToken('0') - var traceManager = new TraceManager({ web3: vm.web3 }) + var traceManager = new TraceManager({ web3 }) var codeManager = new CodeManager(traceManager) codeManager.clear() var solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager), getCode: codeManager.getCode.bind(codeManager) }) @@ -36,7 +36,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu st.equals(locals['boolFalse'].value, false) st.equals(locals['boolTrue'].value, true) st.equals(locals['testEnum'].value, 'three') - st.equals(locals['sender'].value, '0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB') + st.equals(locals['sender'].value, '0x5B38DA6A701C568545DCFCB03FCB875F56BEDDC4') st.equals(locals['_bytes1'].value, '0x99') st.equals(locals['__bytes1'].value, '0x99') st.equals(locals['__bytes2'].value, '0x99AB') diff --git a/libs/remix-debug/test/decoder/localsTests/misc2.ts b/libs/remix-debug/test/decoder/localsTests/misc2.ts index f28e0a2cde..813db7542a 100644 --- a/libs/remix-debug/test/decoder/localsTests/misc2.ts +++ b/libs/remix-debug/test/decoder/localsTests/misc2.ts @@ -1,5 +1,5 @@ 'use strict' -import { sendTx } from '../vmCall' +import * as vmCall from '../../vmCall' import { contractCreationToken } from '../../../src/trace/traceHelper' import { SolidityProxy } from '../../../src/solidity-decoder/solidityProxy' import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree' @@ -8,19 +8,19 @@ import * as helper from './helper' import { TraceManager } from '../../../src/trace/traceManager' import { CodeManager } from '../../../src/code/codeManager' -module.exports = function (st, vm, privateKey, contractBytecode, compilationResult) { - return new Promise((resolve) => { - sendTx(vm, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, data) { +module.exports = function (st, privateKey, contractBytecode, compilationResult) { + 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) } - const txHash = data.hash - vm.web3.eth.getTransaction(txHash, function (error, tx) { + web3.eth.getTransaction(hash, function (error, tx) { if (error) { return st.fail(error) } tx.to = contractCreationToken('0') - var traceManager = new TraceManager({ web3: vm.web3 }) + var traceManager = new TraceManager({ web3 }) var codeManager = new CodeManager(traceManager) codeManager.clear() var solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager), getCode: codeManager.getCode.bind(codeManager) }) diff --git a/libs/remix-debug/test/decoder/localsTests/structArray.ts b/libs/remix-debug/test/decoder/localsTests/structArray.ts index 9041e9ea7b..725674ee8c 100644 --- a/libs/remix-debug/test/decoder/localsTests/structArray.ts +++ b/libs/remix-debug/test/decoder/localsTests/structArray.ts @@ -1,5 +1,5 @@ 'use strict' -import { sendTx } from '../vmCall' +import * as vmCall from '../../vmCall' import { contractCreationToken } from '../../../src/trace/traceHelper' import { SolidityProxy } from '../../../src/solidity-decoder/solidityProxy' import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree' @@ -8,19 +8,19 @@ import * as helper from './helper' import { TraceManager } from '../../../src/trace/traceManager' import { CodeManager } from '../../../src/code/codeManager' -module.exports = function (st, vm, privateKey, contractBytecode, compilationResult) { - return new Promise((resolve) => { - sendTx(vm, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, data) { +module.exports = function (st, privateKey, contractBytecode, compilationResult) { + 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) } - const txHash = data.hash - vm.web3.eth.getTransaction(txHash, function (error, tx) { + web3.eth.getTransaction(hash, function (error, tx) { if (error) { return st.fail(error) } tx.to = contractCreationToken('0') - var traceManager = new TraceManager({ web3: vm.web3 }) + var traceManager = new TraceManager({ web3 }) var codeManager = new CodeManager(traceManager) codeManager.clear() var solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager), getCode: codeManager.getCode.bind(codeManager) }) diff --git a/libs/remix-debug/test/decoder/stateTests/mapping.ts b/libs/remix-debug/test/decoder/stateTests/mapping.ts index 671bf4b9b6..9f82c7b495 100644 --- a/libs/remix-debug/test/decoder/stateTests/mapping.ts +++ b/libs/remix-debug/test/decoder/stateTests/mapping.ts @@ -2,57 +2,62 @@ import { compilerInput } from '../../helpers/compilerHelper' import { TraceManager } from '../../../src/trace/traceManager' import { compile } from 'solc' import * as stateDecoder from '../../../src/solidity-decoder/stateDecoder' -import { sendTx, initVM } from '../vmCall' +import * as vmCall from '../../vmCall' import { StorageResolver } from '../../../src/storage/storageResolver' import { StorageViewer } from '../../../src/storage/storageViewer' +import { Address, bufferToHex } from 'ethereumjs-util' module.exports = async function testMappingStorage (st, cb) { + console.log('start testMappingStorage') var mappingStorage = require('../contracts/mappingStorage') - var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') - var vm = await initVM(st, privateKey) + var privateKey = Buffer.from('503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb', 'hex') 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, data) { + output = JSON.parse(output); + console.log('BYTECODE', output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object); + 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 { - const txHash = data.hash - vm.web3.eth.getTransaction(txHash, (error, tx) => { + web3.eth.getTransactionReceipt(hash, (error, tx) => { if (error) { console.log(error) st.end(error) } else { - testMapping(st, vm, privateKey, tx.contractAddress, output, cb) + // const storage = await this.vm.stateManager.dumpStorage(data.to) + console.log(tx); + // (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, web3, cb) + // st.end() } }) } }) } -function testMapping (st, vm, privateKey, contractAddress, output, cb) { - sendTx(vm, {nonce: 1, privateKey: privateKey}, contractAddress, 0, '2fd0a83a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001074686973206973206120737472696e6700000000000000000000000000000000', - function (error, data) { +function testMapping (st, privateKey, contractAddress, output, web3, cb) { + (vmCall as any).sendTx(web3, {nonce: 1, privateKey: privateKey}, contractAddress, 0, '2fd0a83a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001074686973206973206120737472696e6700000000000000000000000000000000', + function (error, hash) { if (error) { console.log(error) st.end(error) - } else { - const txHash = data.hash - vm.web3.eth.getTransaction(txHash, (error, tx) => { + } else { + web3.eth.getTransaction(hash, (error, tx) => { if (error) { console.log(error) st.end(error) } else { - var traceManager = new TraceManager({web3: vm.web3}) + var traceManager = new TraceManager({web3}) traceManager.resolveTrace(tx).then(() => { var storageViewer = new StorageViewer({ stepIndex: 268, tx: tx, address: contractAddress - }, new StorageResolver({web3: vm.web3}), traceManager) + }, new StorageResolver({web3}), traceManager) var stateVars = stateDecoder.extractStateVariables('SimpleMappingState', output.sources) stateDecoder.decodeState(stateVars, storageViewer).then((result) => { - console.log('ok', JSON.stringify(result)) st.equal(result['_num'].value, '1') st.equal(result['_num'].type, 'uint256') st.equal(result['_iBreakSolidityState'].type, 'mapping(string => uint256)') diff --git a/libs/remix-debug/test/decoder/vmCall.ts b/libs/remix-debug/test/decoder/vmCall.ts deleted file mode 100644 index a0d2040e7c..0000000000 --- a/libs/remix-debug/test/decoder/vmCall.ts +++ /dev/null @@ -1,76 +0,0 @@ -'use strict' -import { Transaction as Tx } from '@ethereumjs/tx' -import { Block } from '@ethereumjs/block' -import { BN, bufferToHex, Address } from 'ethereumjs-util' -import { vm as remixlibVM } from '@remix-project/remix-lib' -import VM from '@ethereumjs/vm' -import Common from '@ethereumjs/common' - -export function sendTx (vm, from, to, value, data, cb?) { - cb = cb || (() => {}) - return new Promise ((resolve, reject) => { - var tx = new Tx({ - nonce: new BN(from.nonce++), - // gasPrice: new BN(1), - gasLimit: new BN(3000000, 10), - to: to, - value: new BN(value, 10), - data: Buffer.from(data, 'hex') - }) - tx = tx.sign(from.privateKey) - - var block = Block.fromBlockData({ - header: { - timestamp: new Date().getTime() / 1000 | 0, - number: 0 - } - }) // still using default common - - try { - vm.runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}).then(function (result) { - setTimeout(() => { - const hash = bufferToHex(tx.hash()) - cb(null, { hash, result }) - resolve({ hash, result }) - }, 500) - }).catch((error) => { - console.error(error) - cb(error) - reject(error) - }) - } catch (e) { - console.error(e) - } - }) -} - -async function createVm (hardfork) { - const common = new Common({ chain: 'mainnet', hardfork }) - const vm = new VM({ common }) - await vm.init() - return { vm, stateManager: vm.stateManager } -} - -/* - Init VM / Send Transaction -*/ -export async function initVM (st, privateKey) { - var VM = await createVm('berlin') - const vm = VM.vm - - var address = Address.fromPrivateKey(privateKey) - - try { - let account = await vm.stateManager.getAccount(address) - account.balance = new BN('f00000000000000001', 16) - await vm.stateManager.putAccount(address, account) - } catch (error) { - console.log(error) - } - - var web3Provider = new remixlibVM.Web3VMProvider() - web3Provider.setVM(vm) - vm.web3 = web3Provider - return vm -} - diff --git a/libs/remix-debug/test/tests.ts b/libs/remix-debug/test/tests.ts index b105d02f12..87f8c01972 100644 --- a/libs/remix-debug/test/tests.ts +++ b/libs/remix-debug/test/tests.ts @@ -1,5 +1,5 @@ 'use strict' - +require('./vmCall') require('./traceManager') require('./codeManager') require('./disassembler') diff --git a/libs/remix-debug/test/vmCall.ts b/libs/remix-debug/test/vmCall.ts index a640c4d1b8..351563c0b3 100644 --- a/libs/remix-debug/test/vmCall.ts +++ b/libs/remix-debug/test/vmCall.ts @@ -1,63 +1,52 @@ 'use strict' import { Block } from '@ethereumjs/block' +import { Transaction } from '@ethereumjs/tx' import VM from '@ethereumjs/vm' +import { rlp, keccak, bufferToHex } from 'ethereumjs-util' +import { extendWeb3 } from '../src/init' var utileth = require('ethereumjs-util') var Tx = require('@ethereumjs/tx').Transaction var BN = require('ethereumjs-util').BN var remixLib = require('@remix-project/remix-lib') +const { Provider, extend } = require('@remix-project/remix-simulator') +const Web3 = require('web3') -function sendTx (vm, from, to, value, data, cb) { - var tx = new Tx({ - nonce: new BN(from.nonce++), - // gasPrice: new BN(1), - gasLimit: new BN(3000000, 10), - to: to, - value: new BN(value, 10), - data: Buffer.from(data, 'hex') - }) - tx = tx.sign(from.privateKey) - var block = Block.fromBlockData({ - header: { - timestamp: new Date().getTime() / 1000 | 0, - number: 0 - } - }) // still using default common - vm.runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}).then(function (result) { - setTimeout(() => { - cb(null, utileth.bufferToHex(tx.hash())) - }, 500) - }).catch((error) => { - console.error(error) - cb(error) - }) +async function getWeb3 () { + const remixSimulatorProvider = new Provider({ fork: 'berlin' }) + await remixSimulatorProvider.init() + await remixSimulatorProvider.Accounts.resetAccounts() + const web3 = new Web3(remixSimulatorProvider) + extendWeb3(web3) + return web3 } -/* - Init VM / Send Transaction -*/ -async function initVM (privateKey) { - var address = utileth.Address.fromPrivateKey(privateKey) - var vm = new VM({ - activatePrecompiles: true - }) - await vm.init() - +async function sendTx (web3, from, to, value, data, cb) { try { - let account = await vm.stateManager.getAccount(address) - account.balance = new BN('f00000000000000001', 16) - await vm.stateManager.putAccount(address, account) - } catch (error) { - console.log(error) - } - - var web3Provider = new remixLib.vm.Web3VMProvider() - web3Provider.setVM(vm) - vm.web3 = web3Provider - return vm + cb = cb || (() => {}) + console.log('TX', { + from: utileth.Address.fromPrivateKey(from.privateKey).toString('hex'), + to, + value, + data, + gas: 7000000 + }) + const receipt = await web3.eth.sendTransaction({ + from: utileth.Address.fromPrivateKey(from.privateKey).toString('hex'), + to, + value, + data, + gas: 7000000 + }) + console.log('end tx') + cb(null, receipt.transactionHash) + return receipt.transactionHash + } catch (e) { + cb(e) + } } module.exports = { - sendTx: sendTx, - initVM: initVM + sendTx, + getWeb3 } diff --git a/libs/remix-lib/src/web3Provider/web3VmProvider.ts b/libs/remix-lib/src/web3Provider/web3VmProvider.ts index a431507687..f5b5d9f92a 100644 --- a/libs/remix-lib/src/web3Provider/web3VmProvider.ts +++ b/libs/remix-lib/src/web3Provider/web3VmProvider.ts @@ -107,6 +107,7 @@ export class Web3VmProvider { async txWillProcess (data) { this.incr++ this.processingHash = bufferToHex(data.hash()) + this.vmTraces[this.processingHash] = { gas: '0x0', return: '0x0', @@ -114,19 +115,23 @@ export class Web3VmProvider { } const tx = {} tx['hash'] = this.processingHash + tx['from'] = toChecksumAddress(data.getSenderAddress().toString()) if (data.to) { tx['to'] = toChecksumAddress(data.to.toString()) } + this.processingAddress = tx['to'] tx['input'] = bufferToHex(data.data) tx['gas'] = data.gasLimit.toString(10) if (data.value) { tx['value'] = data.value.toString(10) } + this.txs[this.processingHash] = tx this.txsReceipt[this.processingHash] = tx this.storageCache[this.processingHash] = {} + if (data.to) { try { // dumpStorage throws error as 'Missing Node in DB' diff --git a/libs/remix-simulator/src/vm-context.ts b/libs/remix-simulator/src/vm-context.ts index b9cb6a4151..a9f7c7eeec 100644 --- a/libs/remix-simulator/src/vm-context.ts +++ b/libs/remix-simulator/src/vm-context.ts @@ -24,31 +24,27 @@ class StateManagerCommonStorageDump extends StateManager { return super.putContractStorage(address, key, value) } - async dumpStorage (address) { - let trie - try { - trie = await this._getStorageTrie(address) - } catch (e) { - console.log(e) - throw e - } - return new Promise((resolve, reject) => { - try { - const storage = {} - const stream = trie.createReadStream() - stream.on('data', (val) => { - const value = rlp.decode(val.value) - storage['0x' + val.key.toString('hex')] = { - key: this.keyHashes[val.key.toString('hex')], - value: '0x' + value.toString('hex') - } + async dumpStorage (address): Promise { + return new Promise((resolve, reject) => { + this._getStorageTrie(address) + .then((trie) => { + const storage = {} + const stream = trie.createReadStream() + + stream.on('data', (val) => { + const value = rlp.decode(val.value) + storage['0x' + val.key.toString('hex')] = { + key: this.keyHashes[val.key.toString('hex')], + value: '0x' + value.toString('hex') + } + }) + stream.on('end', () => { + resolve(storage) + }) }) - stream.on('end', function () { - resolve(storage) + .catch((e) => { + reject(e) }) - } catch (e) { - reject(e) - } }) } @@ -60,18 +56,18 @@ class StateManagerCommonStorageDump extends StateManager { } async setStateRoot (stateRoot) { - await this._cache.flush() - - if (stateRoot === this._trie.EMPTY_TRIE_ROOT) { - this._trie.root = stateRoot - this._cache.clear() - this._storageTries = {} - return + console.log('setstateroot', stateRoot.toString('hex')) + if (this._checkpointCount !== 0) { + throw new Error('Cannot set state root with uncommitted checkpoints') } - const hasRoot = await this._trie.checkRoot(stateRoot) - if (!hasRoot) { - throw new Error('State trie does not contain state root') + await this._cache.flush() + + if (!stateRoot.equals(this._trie.EMPTY_TRIE_ROOT)) { + const hasRoot = await this._trie.checkRoot(stateRoot) + if (!hasRoot) { + throw new Error('State trie does not contain state root') + } } this._trie.root = stateRoot From 0d99cd281c72f5c9d43a16779ea6f3fcdfcf31ce Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 4 Oct 2021 10:23:48 +0200 Subject: [PATCH 02/16] remove uneeded space --- libs/remix-lib/src/web3Provider/web3VmProvider.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libs/remix-lib/src/web3Provider/web3VmProvider.ts b/libs/remix-lib/src/web3Provider/web3VmProvider.ts index f5b5d9f92a..a431507687 100644 --- a/libs/remix-lib/src/web3Provider/web3VmProvider.ts +++ b/libs/remix-lib/src/web3Provider/web3VmProvider.ts @@ -107,7 +107,6 @@ export class Web3VmProvider { async txWillProcess (data) { this.incr++ this.processingHash = bufferToHex(data.hash()) - this.vmTraces[this.processingHash] = { gas: '0x0', return: '0x0', @@ -115,23 +114,19 @@ export class Web3VmProvider { } const tx = {} tx['hash'] = this.processingHash - tx['from'] = toChecksumAddress(data.getSenderAddress().toString()) if (data.to) { tx['to'] = toChecksumAddress(data.to.toString()) } - this.processingAddress = tx['to'] tx['input'] = bufferToHex(data.data) tx['gas'] = data.gasLimit.toString(10) if (data.value) { tx['value'] = data.value.toString(10) } - this.txs[this.processingHash] = tx this.txsReceipt[this.processingHash] = tx this.storageCache[this.processingHash] = {} - if (data.to) { try { // dumpStorage throws error as 'Missing Node in DB' From fb8393b3655e7c2219f76dd35dd2a28667d9f431 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 4 Oct 2021 10:25:33 +0200 Subject: [PATCH 03/16] remove console.log --- libs/remix-simulator/src/vm-context.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/remix-simulator/src/vm-context.ts b/libs/remix-simulator/src/vm-context.ts index a9f7c7eeec..a562331f9c 100644 --- a/libs/remix-simulator/src/vm-context.ts +++ b/libs/remix-simulator/src/vm-context.ts @@ -56,7 +56,6 @@ class StateManagerCommonStorageDump extends StateManager { } async setStateRoot (stateRoot) { - console.log('setstateroot', stateRoot.toString('hex')) if (this._checkpointCount !== 0) { throw new Error('Cannot set state root with uncommitted checkpoints') } From a8cccdd043e80909adb04ed960e837b9b42d1c1a Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 4 Oct 2021 12:28:52 +0200 Subject: [PATCH 04/16] remove console.log --- libs/remix-debug/test/debugger.ts | 1 - libs/remix-debug/test/decoder/stateTests/mapping.ts | 3 --- libs/remix-debug/test/vmCall.ts | 8 -------- 3 files changed, 12 deletions(-) diff --git a/libs/remix-debug/test/debugger.ts b/libs/remix-debug/test/debugger.ts index e98f24d839..8ce4bed268 100644 --- a/libs/remix-debug/test/debugger.ts +++ b/libs/remix-debug/test/debugger.ts @@ -263,7 +263,6 @@ function testDebugging (debugManager) { debugManager.decodeLocalsAt(327, location, (error, decodedlocals) => { if (error) return t.end(error) const res = deepequal(decodedlocals, tested) - console.log(res) t.ok(res, `test if locals does match. expected: ${JSON.stringify(tested)} - current: ${JSON.stringify(decodedlocals)}`) }) } catch (error) { diff --git a/libs/remix-debug/test/decoder/stateTests/mapping.ts b/libs/remix-debug/test/decoder/stateTests/mapping.ts index 9f82c7b495..f2467efb29 100644 --- a/libs/remix-debug/test/decoder/stateTests/mapping.ts +++ b/libs/remix-debug/test/decoder/stateTests/mapping.ts @@ -8,12 +8,10 @@ import { StorageViewer } from '../../../src/storage/storageViewer' import { Address, bufferToHex } from 'ethereumjs-util' module.exports = async function testMappingStorage (st, cb) { - console.log('start testMappingStorage') var mappingStorage = require('../contracts/mappingStorage') var privateKey = Buffer.from('503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb', 'hex') var output = compile(compilerInput(mappingStorage.contract)) output = JSON.parse(output); - console.log('BYTECODE', output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object); 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) { @@ -26,7 +24,6 @@ module.exports = async function testMappingStorage (st, cb) { st.end(error) } else { // const storage = await this.vm.stateManager.dumpStorage(data.to) - console.log(tx); // (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, web3, cb) diff --git a/libs/remix-debug/test/vmCall.ts b/libs/remix-debug/test/vmCall.ts index 351563c0b3..d8d400c58c 100644 --- a/libs/remix-debug/test/vmCall.ts +++ b/libs/remix-debug/test/vmCall.ts @@ -24,13 +24,6 @@ async function getWeb3 () { async function sendTx (web3, from, to, value, data, cb) { try { cb = cb || (() => {}) - console.log('TX', { - from: utileth.Address.fromPrivateKey(from.privateKey).toString('hex'), - to, - value, - data, - gas: 7000000 - }) const receipt = await web3.eth.sendTransaction({ from: utileth.Address.fromPrivateKey(from.privateKey).toString('hex'), to, @@ -38,7 +31,6 @@ async function sendTx (web3, from, to, value, data, cb) { data, gas: 7000000 }) - console.log('end tx') cb(null, receipt.transactionHash) return receipt.transactionHash } catch (e) { From 8c94d6deead2029c1699c4f5a4a5ca166ac58d27 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 23 Sep 2021 14:33:53 +0200 Subject: [PATCH 05/16] make sure latest block number is updated --- libs/remix-simulator/src/methods/blocks.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libs/remix-simulator/src/methods/blocks.ts b/libs/remix-simulator/src/methods/blocks.ts index d40f13c491..a58319b916 100644 --- a/libs/remix-simulator/src/methods/blocks.ts +++ b/libs/remix-simulator/src/methods/blocks.ts @@ -1,13 +1,10 @@ export class Blocks { vmContext coinbase: string - blockNumber: number - constructor (vmContext, _options) { this.vmContext = vmContext const options = _options || {} this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000' - this.blockNumber = 0 } methods (): Record { @@ -107,7 +104,7 @@ export class Blocks { } eth_blockNumber (payload, cb) { - cb(null, this.blockNumber) + cb(null, parseInt(this.vmContext.latestBlockNumber)) } eth_getBlockTransactionCountByHash (payload, cb) { From c20b877908e659dbd28df916e31bd03d81b306dd Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 23 Sep 2021 14:36:00 +0200 Subject: [PATCH 06/16] make sure nonce, transactionIndex and logs are returned --- libs/remix-lib/src/execution/logsManager.ts | 23 ++++++++++++-- .../src/methods/transactions.ts | 31 ++++++++++++------- libs/remix-simulator/src/vm-context.ts | 11 ++++--- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/libs/remix-lib/src/execution/logsManager.ts b/libs/remix-lib/src/execution/logsManager.ts index 86f07bf099..6420d53028 100644 --- a/libs/remix-lib/src/execution/logsManager.ts +++ b/libs/remix-lib/src/execution/logsManager.ts @@ -55,10 +55,11 @@ export class LogsManager { if (queryFilter.topics.filter((logTopic) => changeEvent.log.topics.indexOf(logTopic) >= 0).length === 0) return false if (queryType === 'logs') { - if ((queryFilter.address === ('0x' + changeEvent.tx.to.toString('hex'))) && (queryFilter.address === ('0x' + changeEvent.tx.from.toString('hex')))) { + + if ((queryFilter.address === (changeEvent.tx.to || '').toString()) || queryFilter.address === (changeEvent.tx.getSenderAddress().toString())) { if (!queryFilter.toBlock) { return true - } else if (parseInt(queryFilter.toBlock) > parseInt(changeEvent.blockNumber)) { + } else if (parseInt(queryFilter.toBlock) >= parseInt(changeEvent.blockNumber)) { return true } } @@ -144,6 +145,24 @@ export class LogsManager { } } + getLogsByTxHash (hash) { + return this.oldLogs.filter((log) => '0x' + log.tx.hash().toString('hex') === hash) + .map((log) => { + return { + logIndex: '0x1', // 1 + blockNumber: log.blockNumber, + blockHash: ('0x' + log.block.hash().toString('hex')), + transactionHash: ('0x' + log.tx.hash().toString('hex')), + transactionIndex: '0x' + log.txNumber.toString(16), + // TODO: if it's a contract deploy, it should be that address instead + address: log.log.address, + data: log.log.data, + topics: log.log.topics + } + }) + + } + getLogsFor (params) { const results = [] for (const log of this.oldLogs) { diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index 44786c6f62..b0e3e4e3e7 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -71,7 +71,7 @@ export class Transactions { if (!error && result) { this.vmContext.addBlock(result.block) const hash = '0x' + result.tx.hash().toString('hex') - this.vmContext.trackTx(hash, result.block) + this.vmContext.trackTx(hash, result.block, result.tx) this.vmContext.trackExecResult(hash, result.result.execResult) return cb(null, result.transactionHash) } @@ -95,17 +95,19 @@ export class Transactions { return cb(error) } - const txBlock = this.vmContext.txs[receipt.hash] + const txBlock = this.vmContext.blockByTxHash[receipt.hash] + + const logs = this.vmContext.logsManager.getLogsByTxHash(receipt.hash) const r: Record = { transactionHash: receipt.hash, - transactionIndex: '0x00', + transactionIndex: '0x0', blockHash: '0x' + txBlock.hash().toString('hex'), blockNumber: '0x' + txBlock.header.number.toString('hex'), gasUsed: receipt.gasUsed, cumulativeGasUsed: receipt.gasUsed, // only 1 tx per block contractAddress: receipt.contractAddress, - logs: receipt.logs, + logs, status: receipt.status, to: receipt.to } @@ -151,7 +153,7 @@ export class Transactions { if (!error && result) { this.vmContext.addBlock(result.block) const hash = '0x' + result.tx.hash().toString('hex') - this.vmContext.trackTx(hash, result.block) + this.vmContext.trackTx(hash, result.block, result.tx) this.vmContext.trackExecResult(hash, result.result.execResult) this.tags[tag] = result.transactionHash // calls are not supposed to return a transaction hash. we do this for keeping track of it and allowing debugging calls. @@ -185,7 +187,8 @@ export class Transactions { return cb(error) } - const txBlock = this.vmContext.txs[receipt.transactionHash] + const txBlock = this.vmContext.blockByTxHash[receipt.transactionHash] + const tx = this.vmContext.txByHash[receipt.transactionHash] // TODO: params to add later const r: Record = { @@ -198,9 +201,9 @@ export class Transactions { gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, input: receipt.input, - nonce: 2, // 0x15 // the nonce should be updated - // "transactionIndex": 0, - value: receipt.value + nonce: '0x' + tx.nonce.toString('hex'), + transactionIndex: '0x0', + value: receipt.value, // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", @@ -234,6 +237,8 @@ export class Transactions { return cb(error) } + const tx = this.vmContext.txByHash[receipt.transactionHash] + // TODO: params to add later const r: Record = { blockHash: '0x' + txBlock.hash().toString('hex'), @@ -245,7 +250,7 @@ export class Transactions { gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, input: receipt.input, - nonce: 2, // 0x15 // the nonce should be updated + nonce: '0x' + tx.nonce.toString('hex'), // "transactionIndex": 0, value: receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 @@ -277,6 +282,8 @@ export class Transactions { return cb(error) } + const tx = this.vmContext.txByHash[receipt.transactionHash] + // TODO: params to add later const r: Record = { blockHash: '0x' + txBlock.hash().toString('hex'), @@ -288,8 +295,8 @@ export class Transactions { gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, input: receipt.input, - nonce: 2, // 0x15 // the nonce should be updated - // "transactionIndex": 0, + nonce: '0x' + tx.nonce.toString('hex'), + transactionIndex: '0x0', value: receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 diff --git a/libs/remix-simulator/src/vm-context.ts b/libs/remix-simulator/src/vm-context.ts index a562331f9c..e862fd0e3f 100644 --- a/libs/remix-simulator/src/vm-context.ts +++ b/libs/remix-simulator/src/vm-context.ts @@ -85,7 +85,8 @@ export class VMContext { customNetWorks blocks latestBlockNumber - txs + blockByTxHash + txByHash currentVm web3vm logsManager @@ -98,7 +99,8 @@ export class VMContext { this.currentVm = this.createVm(this.currentFork) this.blocks = {} this.latestBlockNumber = 0 - this.txs = {} + this.blockByTxHash = {} + this.txByHash = {} this.exeResults = {} this.logsManager = new execution.LogsManager() } @@ -151,8 +153,9 @@ export class VMContext { this.logsManager.checkBlock(blockNumber, block, this.web3()) } - trackTx (tx, block) { - this.txs[tx] = block + trackTx (txHash, block, tx) { + this.blockByTxHash[txHash] = block + this.txByHash[txHash] = tx } trackExecResult (tx, execReult) { From 2e5f689058564bc170a2740978309e15731ea13e Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 23 Sep 2021 14:36:19 +0200 Subject: [PATCH 07/16] remove uneeded property --- libs/remix-lib/src/execution/txRunnerVM.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/remix-lib/src/execution/txRunnerVM.ts b/libs/remix-lib/src/execution/txRunnerVM.ts index ac6e629b89..901652da0d 100644 --- a/libs/remix-lib/src/execution/txRunnerVM.ts +++ b/libs/remix-lib/src/execution/txRunnerVM.ts @@ -13,7 +13,6 @@ export class TxRunnerVM { vmaccounts queusTxs blocks - txs logsManager commonContext getVMObject: () => any From 785c53001fecf402fcfcd904b9e6458ccf673807 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 23 Sep 2021 14:36:29 +0200 Subject: [PATCH 08/16] add e2e tests --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index 1870db35c8..f026662729 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -106,7 +106,24 @@ module.exports = { .pause(1000) .executeScript('remix.execute(\'resolveExternalUrlAndSaveToaPath.js\')') .waitForElementContainsText('*[data-id="terminalJournal"]', 'abstract contract ERC20Burnable', 60000) - .openFile('.deps/github/newFile.sol') + .openFile('.deps/github/newFile.sol') + }, + + 'Deploy "Owner" using an ether.js script listen to event and check event are logged in the terminal': function (browser: NightwatchBrowser) { + browser + .click('*[data-id="terminalClearConsole"]') // clear the terminal + .addFile('deployWithEthersJs.js', { content: deployWithEthersJs }) + .openFile('deployWithEthersJs.js') + .pause(1000) + .executeScript('remix.execute(\'deployWithEthersJs.js\')') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Deployment successful.', 60000) + .openFile('contracts/2_Owner.sol') + .verifyContracts(['Owner']) + .addAtAddressInstance('0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', true, true) + .click('*[data-id="terminalClearConsole"]') // clear the terminal + .clickFunction('changeOwner - transact (not payable)', { types: 'address newOwner', values: '0xd9145CCE52D386f254917e481eB44e9943F39138' }) // execute the "changeOwner" function + .waitForElementContainsText('*[data-id="terminalJournal"]', 'previousOwner 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', 60000) // check that the script is logging the event + .waitForElementContainsText('*[data-id="terminalJournal"]', 'newOwner 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', 60000) .end() } } @@ -180,3 +197,40 @@ const resolveUrl = ` } })() ` + +const deployWithEthersJs = ` +// Right click on the script name and hit "Run" to execute +(async () => { + try { + console.log('Running deployWithEthers script...') + + const constructorArgs = [] // Put constructor args (if any) here for your contract + + // Note that the script needs the ABI which is generated from the compilation artifact. + // Make sure contract is compiled and artifacts are generated + const artifactsPath = 'contracts/artifacts/Owner.json' // Change this for different path + + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) + // 'web3Provider' is a remix global variable object + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + + let factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); + + let contract = await factory.deploy(...constructorArgs); + + console.log('Contract Address: ', contract.address); + + // The contract is NOT deployed yet; we must wait until it is mined + await contract.deployed() + console.log('Deployment successful.') + + contract.on('OwnerSet', (previousOwner, newOwner) => { + console.log('previousOwner' , previousOwner) + console.log('newOwner' , newOwner) + }) + + console.log('ok') + } catch (e) { + console.log(e.message) + } +})()` From 7f98ff82921909900a5968379ebdec3243ba6dbb Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 23 Sep 2021 15:15:18 +0200 Subject: [PATCH 09/16] make sure fromBlock and toBlockare used while querying --- libs/remix-lib/src/execution/logsManager.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/remix-lib/src/execution/logsManager.ts b/libs/remix-lib/src/execution/logsManager.ts index 6420d53028..39705e7342 100644 --- a/libs/remix-lib/src/execution/logsManager.ts +++ b/libs/remix-lib/src/execution/logsManager.ts @@ -55,11 +55,10 @@ export class LogsManager { if (queryFilter.topics.filter((logTopic) => changeEvent.log.topics.indexOf(logTopic) >= 0).length === 0) return false if (queryType === 'logs') { - + const fromBlock = queryFilter.fromBlock || '0x0' + const toBlock = queryFilter.toBlock || this.oldLogs.length ? this.oldLogs[this.oldLogs.length - 1].blockNumber : '0x0' if ((queryFilter.address === (changeEvent.tx.to || '').toString()) || queryFilter.address === (changeEvent.tx.getSenderAddress().toString())) { - if (!queryFilter.toBlock) { - return true - } else if (parseInt(queryFilter.toBlock) >= parseInt(changeEvent.blockNumber)) { + if ((parseInt(toBlock) >= parseInt(changeEvent.blockNumber)) && (parseInt(fromBlock) <= parseInt(changeEvent.blockNumber))) { return true } } From cd6907e48d04aea8abececcc9413b1393e220bbb Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 23 Sep 2021 15:19:14 +0200 Subject: [PATCH 10/16] linting --- libs/remix-lib/src/execution/logsManager.ts | 23 +++++++++---------- .../src/methods/transactions.ts | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/libs/remix-lib/src/execution/logsManager.ts b/libs/remix-lib/src/execution/logsManager.ts index 39705e7342..4fcb0b224c 100644 --- a/libs/remix-lib/src/execution/logsManager.ts +++ b/libs/remix-lib/src/execution/logsManager.ts @@ -147,19 +147,18 @@ export class LogsManager { getLogsByTxHash (hash) { return this.oldLogs.filter((log) => '0x' + log.tx.hash().toString('hex') === hash) .map((log) => { - return { - logIndex: '0x1', // 1 - blockNumber: log.blockNumber, - blockHash: ('0x' + log.block.hash().toString('hex')), - transactionHash: ('0x' + log.tx.hash().toString('hex')), - transactionIndex: '0x' + log.txNumber.toString(16), - // TODO: if it's a contract deploy, it should be that address instead - address: log.log.address, - data: log.log.data, - topics: log.log.topics - } + return { + logIndex: '0x1', // 1 + blockNumber: log.blockNumber, + blockHash: ('0x' + log.block.hash().toString('hex')), + transactionHash: ('0x' + log.tx.hash().toString('hex')), + transactionIndex: '0x' + log.txNumber.toString(16), + // TODO: if it's a contract deploy, it should be that address instead + address: log.log.address, + data: log.log.data, + topics: log.log.topics + } }) - } getLogsFor (params) { diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index b0e3e4e3e7..9d93231e55 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -203,7 +203,7 @@ export class Transactions { input: receipt.input, nonce: '0x' + tx.nonce.toString('hex'), transactionIndex: '0x0', - value: receipt.value, + value: receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", From bf5b6d3e9fb369d1580985c0ecbaf9c65415ad89 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 23 Sep 2021 15:33:12 +0200 Subject: [PATCH 11/16] linting --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 2 +- libs/remix-lib/src/execution/logsManager.ts | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index f026662729..bc6f29c13b 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -106,7 +106,7 @@ module.exports = { .pause(1000) .executeScript('remix.execute(\'resolveExternalUrlAndSaveToaPath.js\')') .waitForElementContainsText('*[data-id="terminalJournal"]', 'abstract contract ERC20Burnable', 60000) - .openFile('.deps/github/newFile.sol') + .openFile('.deps/github/newFile.sol') }, 'Deploy "Owner" using an ether.js script listen to event and check event are logged in the terminal': function (browser: NightwatchBrowser) { diff --git a/libs/remix-lib/src/execution/logsManager.ts b/libs/remix-lib/src/execution/logsManager.ts index 4fcb0b224c..e852d9a742 100644 --- a/libs/remix-lib/src/execution/logsManager.ts +++ b/libs/remix-lib/src/execution/logsManager.ts @@ -146,19 +146,19 @@ export class LogsManager { getLogsByTxHash (hash) { return this.oldLogs.filter((log) => '0x' + log.tx.hash().toString('hex') === hash) - .map((log) => { - return { - logIndex: '0x1', // 1 - blockNumber: log.blockNumber, - blockHash: ('0x' + log.block.hash().toString('hex')), - transactionHash: ('0x' + log.tx.hash().toString('hex')), - transactionIndex: '0x' + log.txNumber.toString(16), - // TODO: if it's a contract deploy, it should be that address instead - address: log.log.address, - data: log.log.data, - topics: log.log.topics - } - }) + .map((log) => { + return { + logIndex: '0x1', // 1 + blockNumber: log.blockNumber, + blockHash: ('0x' + log.block.hash().toString('hex')), + transactionHash: ('0x' + log.tx.hash().toString('hex')), + transactionIndex: '0x' + log.txNumber.toString(16), + // TODO: if it's a contract deploy, it should be that address instead + address: log.log.address, + data: log.log.data, + topics: log.log.topics + } + }) } getLogsFor (params) { From 6e66b992a74ce38986baeea6750b92b1ba257cbb Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 23 Sep 2021 16:51:37 +0200 Subject: [PATCH 12/16] fix E2E --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index bc6f29c13b..7ff5017f24 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -112,13 +112,13 @@ module.exports = { 'Deploy "Owner" using an ether.js script listen to event and check event are logged in the terminal': function (browser: NightwatchBrowser) { browser .click('*[data-id="terminalClearConsole"]') // clear the terminal + .openFile('contracts/2_Owner.sol') + .verifyContracts(['Owner']) .addFile('deployWithEthersJs.js', { content: deployWithEthersJs }) .openFile('deployWithEthersJs.js') .pause(1000) .executeScript('remix.execute(\'deployWithEthersJs.js\')') .waitForElementContainsText('*[data-id="terminalJournal"]', 'Deployment successful.', 60000) - .openFile('contracts/2_Owner.sol') - .verifyContracts(['Owner']) .addAtAddressInstance('0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', true, true) .click('*[data-id="terminalClearConsole"]') // clear the terminal .clickFunction('changeOwner - transact (not payable)', { types: 'address newOwner', values: '0xd9145CCE52D386f254917e481eB44e9943F39138' }) // execute the "changeOwner" function From b88a5df25aabcfb40cc808748af2d0aa1803f34a Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 24 Sep 2021 22:08:21 +0200 Subject: [PATCH 13/16] fix e2e --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 5 +++-- libs/remix-debug/src/storage/storageResolver.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index 7ff5017f24..a9d010fe20 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -109,11 +109,12 @@ module.exports = { .openFile('.deps/github/newFile.sol') }, - 'Deploy "Owner" using an ether.js script listen to event and check event are logged in the terminal': function (browser: NightwatchBrowser) { + 'Deploy "Owner" using an ether.js script, listen to event and check event are logged in the terminal': function (browser: NightwatchBrowser) { browser .click('*[data-id="terminalClearConsole"]') // clear the terminal .openFile('contracts/2_Owner.sol') - .verifyContracts(['Owner']) + .clickLaunchIcon('solidity') + .click('*[data-id="compilerContainerCompileBtn"]') // compile Owner .addFile('deployWithEthersJs.js', { content: deployWithEthersJs }) .openFile('deployWithEthersJs.js') .pause(1000) diff --git a/libs/remix-debug/src/storage/storageResolver.ts b/libs/remix-debug/src/storage/storageResolver.ts index dfe97c5ec5..c0090c8b52 100644 --- a/libs/remix-debug/src/storage/storageResolver.ts +++ b/libs/remix-debug/src/storage/storageResolver.ts @@ -133,7 +133,7 @@ export class StorageResolver { resolve([{}, null]) } else { this.web3.debug.storageRangeAt( - tx.blockHash, tx.transactionIndex === undefined ? tx.hash : tx.transactionIndex, + tx.blockHash, tx.hash, address, start, maxSize, From 9dbb4d02102116901d3341dd8448ed5c9c27a2c9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 24 Sep 2021 23:27:07 +0200 Subject: [PATCH 14/16] fix e2e --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 20 +++++++++++++------ package.json | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index a9d010fe20..0f2f0928e7 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -111,20 +111,28 @@ module.exports = { 'Deploy "Owner" using an ether.js script, listen to event and check event are logged in the terminal': function (browser: NightwatchBrowser) { browser + .clickLaunchIcon('settings') + .clickLaunchIcon('udapp') + .click('*[data-id="settingsVMLondonMode"]') .click('*[data-id="terminalClearConsole"]') // clear the terminal - .openFile('contracts/2_Owner.sol') - .clickLaunchIcon('solidity') - .click('*[data-id="compilerContainerCompileBtn"]') // compile Owner + .clickLaunchIcon('filePanel') + .click('*[data-id="treeViewDivtreeViewItem"]') // make sure we create the file at the root folder .addFile('deployWithEthersJs.js', { content: deployWithEthersJs }) .openFile('deployWithEthersJs.js') .pause(1000) + .openFile('contracts/2_Owner.sol') + .clickLaunchIcon('solidity') + .click('*[data-id="compilerContainerCompileBtn"]') // compile Owner .executeScript('remix.execute(\'deployWithEthersJs.js\')') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Contract Address: 0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', 'Deployment successful.', 60000) - .addAtAddressInstance('0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', true, true) + .addAtAddressInstance('0xd9145CCE52D386f254917e481eB44e9943F39138', true, true) .click('*[data-id="terminalClearConsole"]') // clear the terminal + .waitForElementPresent('*[data-id="universalDappUiContractActionWrapper"]', 60000) + .click('*[data-id="universalDappUiTitleExpander"]') .clickFunction('changeOwner - transact (not payable)', { types: 'address newOwner', values: '0xd9145CCE52D386f254917e481eB44e9943F39138' }) // execute the "changeOwner" function - .waitForElementContainsText('*[data-id="terminalJournal"]', 'previousOwner 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', 60000) // check that the script is logging the event - .waitForElementContainsText('*[data-id="terminalJournal"]', 'newOwner 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', 60000) + .waitForElementContainsText('*[data-id="terminalJournal"]', 'previousOwner0x5B38Da6a701c568545dCfcB03FcB875f56beddC4', 60000) // check that the script is logging the event + .waitForElementContainsText('*[data-id="terminalJournal"]', 'newOwner0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) .end() } } diff --git a/package.json b/package.json index 7560f7e22e..1cc28b8aef 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "nightwatch_local_specialFunctions": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/specialFunctions.test.js --env=chrome", "nightwatch_local_solidityUnitTests": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.js --env=chrome", "nightwatch_local_remixd": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/remixd.test.js --env=chrome", - "nightwatch_local_terminal": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/terminal.test.js --env=chrome", + "nightwatch_local_terminal": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/terminal.test.js --env=firefox", "nightwatch_local_gist": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/gist.spec.js --env=chrome", "nightwatch_local_workspace": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/workspace.test.js --env=chrome", "nightwatch_local_defaultLayout": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/defaultLayout.test.js --env=chrome", From 167ef04c2be9c2b4b8d5182694c4626ec895435a Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 4 Oct 2021 13:17:17 +0200 Subject: [PATCH 15/16] fix e2e running browser --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1cc28b8aef..7560f7e22e 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "nightwatch_local_specialFunctions": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/specialFunctions.test.js --env=chrome", "nightwatch_local_solidityUnitTests": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.js --env=chrome", "nightwatch_local_remixd": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/remixd.test.js --env=chrome", - "nightwatch_local_terminal": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/terminal.test.js --env=firefox", + "nightwatch_local_terminal": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/terminal.test.js --env=chrome", "nightwatch_local_gist": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/gist.spec.js --env=chrome", "nightwatch_local_workspace": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/workspace.test.js --env=chrome", "nightwatch_local_defaultLayout": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/defaultLayout.test.js --env=chrome", From 405ca58ac3a4f98cadf8d1b2fd98b4b2daaff2ab Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 4 Oct 2021 13:17:29 +0200 Subject: [PATCH 16/16] hardcode txindex --- libs/remix-simulator/src/methods/transactions.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index 9d93231e55..93b6850812 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -11,6 +11,7 @@ export class Transactions { tags txRunnerVMInstance txRunnerInstance + TX_INDEX = '0x0' // currently there's always only 1 tx per block, so the transaction index will always be 0x0 constructor (vmContext) { this.vmContext = vmContext @@ -101,7 +102,7 @@ export class Transactions { const r: Record = { transactionHash: receipt.hash, - transactionIndex: '0x0', + transactionIndex: this.TX_INDEX, blockHash: '0x' + txBlock.hash().toString('hex'), blockNumber: '0x' + txBlock.header.number.toString('hex'), gasUsed: receipt.gasUsed, @@ -202,7 +203,7 @@ export class Transactions { hash: receipt.transactionHash, input: receipt.input, nonce: '0x' + tx.nonce.toString('hex'), - transactionIndex: '0x0', + transactionIndex: this.TX_INDEX, value: receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 @@ -251,7 +252,7 @@ export class Transactions { hash: receipt.transactionHash, input: receipt.input, nonce: '0x' + tx.nonce.toString('hex'), - // "transactionIndex": 0, + transactionIndex: this.TX_INDEX, value: receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 @@ -296,7 +297,7 @@ export class Transactions { hash: receipt.transactionHash, input: receipt.input, nonce: '0x' + tx.nonce.toString('hex'), - transactionIndex: '0x0', + transactionIndex: this.TX_INDEX, value: receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37