fix remix-simulator tests

pull/1122/head
yann300 4 years ago
parent 7bb6589903
commit e0501a12cb
  1. 6
      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,10 +148,11 @@ contract Ballot {
winnerName_ = proposals[winningProposal()].name; winnerName_ = proposals[winningProposal()].name;
} }
} }
` `;
(async () => {
var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex')
var vm = vmCall.initVM(privateKey) var vm = await vmCall.initVM(privateKey)
var output = compiler.compile(compilerInput(ballot)) var output = compiler.compile(compilerInput(ballot))
output = JSON.parse(output) output = JSON.parse(output)
var web3VM = new remixLib.vm.Web3VMProvider() var web3VM = new remixLib.vm.Web3VMProvider()
@ -190,6 +191,7 @@ vmCall.sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts[
}) })
} }
}) })
})()
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