fix remix-simulator tests

pull/1122/head
yann300 4 years ago
parent 7bb6589903
commit e0501a12cb
  1. 84
      libs/remix-debug/test/debugger.ts
  2. 4
      libs/remix-debug/test/decoder/localDecoder.ts
  3. 4
      libs/remix-debug/test/decoder/stateTests/mapping.ts
  4. 12
      libs/remix-debug/test/decoder/vmCall.ts
  5. 8
      libs/remix-debug/test/vmCall.ts
  6. 9
      libs/remix-lib/src/util.ts

@ -148,48 +148,50 @@ contract Ballot {
winnerName_ = proposals[winningProposal()].name; winnerName_ = proposals[winningProposal()].name;
} }
} }
` `;
var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') (async () => {
var vm = vmCall.initVM(privateKey) var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex')
var output = compiler.compile(compilerInput(ballot)) var vm = await vmCall.initVM(privateKey)
output = JSON.parse(output) var output = compiler.compile(compilerInput(ballot))
var web3VM = new remixLib.vm.Web3VMProvider() output = JSON.parse(output)
web3VM.setVM(vm) var web3VM = new remixLib.vm.Web3VMProvider()
const param = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000148656c6c6f20576f726c64210000000000000000000000000000000000000000' web3VM.setVM(vm)
vmCall.sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['Ballot'].evm.bytecode.object + param, (error, txHash) => { const param = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000148656c6c6f20576f726c64210000000000000000000000000000000000000000'
console.log(error, txHash) vmCall.sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['Ballot'].evm.bytecode.object + param, (error, txHash) => {
if (error) { console.log(error, txHash)
throw error if (error) {
} else { throw error
web3VM.eth.getTransaction(txHash, (error, tx) => { } else {
if (error) { web3VM.eth.getTransaction(txHash, (error, tx) => {
throw error if (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 throw error
}) } else {
debugManager.callTree.event.register('callTreeBuildFailed', (error) => { var debugManager = new Debugger({
console.error(error) compilationResult: function () {
throw error return { data: output }
}) },
web3: web3VM
debugManager.debug(tx) })
}
}) 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) { function testDebugging (debugManager) {
// stack // stack

@ -12,9 +12,9 @@ var structArrayLocalTest = require('./localsTests/structArray')
var compilerInput = require('../helpers/compilerHelper').compilerInput var compilerInput = require('../helpers/compilerHelper').compilerInput
tape('solidity', function (t) { tape('solidity', function (t) {
t.test('local decoder', function (st) { t.test('local decoder', async function (st) {
var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex')
var vm = vmCall.initVM(st, privateKey) var vm = await vmCall.initVM(st, privateKey)
test(st, vm, privateKey) test(st, vm, privateKey)
}) })
}) })

@ -6,10 +6,10 @@ import { sendTx, initVM } from '../vmCall'
import { StorageResolver } from '../../../src/storage/storageResolver' import { StorageResolver } from '../../../src/storage/storageResolver'
import { StorageViewer } from '../../../src/storage/storageViewer' 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 mappingStorage = require('../contracts/mappingStorage')
var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex')
var vm = initVM(st, privateKey) var vm = await initVM(st, privateKey)
var output = compile(compilerInput(mappingStorage.contract)) var output = compile(compilerInput(mappingStorage.contract))
output = JSON.parse(output) output = JSON.parse(output)
sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, txHash) { sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, txHash) {

@ -16,7 +16,7 @@ export function sendTx (vm, from, to, value, data, cb) {
value: new BN(value, 10), value: new BN(value, 10),
data: Buffer.from(data, 'hex') data: Buffer.from(data, 'hex')
}) })
tx.sign(from.privateKey) tx = tx.sign(from.privateKey)
var block = Block.fromBlockData({ var block = Block.fromBlockData({
header: { 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 common = new Common({ chain: 'mainnet', hardfork })
const vm = new VM({ common }) const vm = new VM({ common })
await vm.init()
// vm.blockchain.validate = false // vm.blockchain.validate = false
return { vm, stateManager: vm.stateManager } return { vm, stateManager: vm.stateManager }
} }
@ -49,12 +50,11 @@ function createVm (hardfork) {
/* /*
Init VM / Send Transaction Init VM / Send Transaction
*/ */
export function initVM (st, privateKey) { export async function initVM (st, privateKey) {
var VM = createVm('berlin') var VM = await createVm('berlin')
const vm = VM.vm const vm = VM.vm
var address = utileth.privateToAddress(privateKey) var address = utileth.Address.fromPrivateKey(privateKey)
vm.stateManager.getAccount(address).then((account) => { vm.stateManager.getAccount(address).then((account) => {
account.balance = new BN('f00000000000000001', 16) account.balance = new BN('f00000000000000001', 16)
vm.stateManager.putAccount(address, account).catch((error) => { vm.stateManager.putAccount(address, account).catch((error) => {

@ -15,7 +15,7 @@ function sendTx (vm, from, to, value, data, cb) {
value: new BN(value, 10), value: new BN(value, 10),
data: Buffer.from(data, 'hex') data: Buffer.from(data, 'hex')
}) })
tx.sign(from.privateKey) tx = tx.sign(from.privateKey)
var block = Block.fromBlockData({ var block = Block.fromBlockData({
header: { header: {
@ -36,12 +36,12 @@ function sendTx (vm, from, to, value, data, cb) {
/* /*
Init VM / Send Transaction Init VM / Send Transaction
*/ */
function initVM (privateKey) { async function initVM (privateKey) {
var address = utileth.privateToAddress(privateKey) var address = utileth.Address.fromPrivateKey(privateKey)
var vm = new VM({ var vm = new VM({
activatePrecompiles: true activatePrecompiles: true
}) })
await vm.init()
vm.stateManager.getAccount(address).then((account) => { vm.stateManager.getAccount(address).then((account) => {
account.balance = new BN('f00000000000000001', 16) account.balance = new BN('f00000000000000001', 16)
vm.stateManager.putAccount(address, account).catch((error) => { vm.stateManager.putAccount(address, account).catch((error) => {

@ -1,5 +1,5 @@
'use strict' '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 contains misc util: @TODO should be splitted
@ -165,12 +165,7 @@ export function buildCallPath (index, rootCall) {
*/ */
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
export function sha3_256 (value) { export function sha3_256 (value) {
if (typeof value === 'string') { value = toBuffer(value)
value = Buffer.from(value.replace('0x', ''), 'hex')
}
if (Number.isInteger(value)) {
value = intToBuffer(value)
}
const retInBuffer: Buffer = keccak(setLengthLeft(value, 32)) const retInBuffer: Buffer = keccak(setLengthLeft(value, 32))
return bufferToHex(retInBuffer) return bufferToHex(retInBuffer)
} }

Loading…
Cancel
Save