diff --git a/libs/remix-lib/src/execution/txRunner.ts b/libs/remix-lib/src/execution/txRunner.ts index fd288b35eb..ddc2456fb5 100644 --- a/libs/remix-lib/src/execution/txRunner.ts +++ b/libs/remix-lib/src/execution/txRunner.ts @@ -111,6 +111,10 @@ export class TxRunner { return callback('Invalid account selected') } + if (Number.isInteger(gasLimit)) { + gasLimit = '0x' + gasLimit.toString(16) + } + this.executionContext.vm().stateManager.getAccount(Address.fromString(from)).then((res) => { // See https://github.com/ethereumjs/ethereumjs-tx/blob/master/docs/classes/transaction.md#constructor // for initialization fields and their types @@ -150,8 +154,8 @@ export class TxRunner { }) }) } - }).catch(() => { - callback('Account not found') + }).catch((e) => { + callback(e) }) } diff --git a/libs/remix-simulator/src/genesis.ts b/libs/remix-simulator/src/genesis.ts index a0a20cec78..e7176e8a77 100644 --- a/libs/remix-simulator/src/genesis.ts +++ b/libs/remix-simulator/src/genesis.ts @@ -2,17 +2,20 @@ import { Block } from '@ethereumjs/block' import { BN } from 'ethereumjs-util' export function generateBlock (executionContext) { - const block: Block = Block.fromBlockData({ - header: { - timestamp: (new Date().getTime() / 1000 | 0), - number: 0, - coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', - difficulty: new BN('69762765929000', 10), - gasLimit: new BN('8000000').imuln(1) - } - }, { common: executionContext.vmObject().common }) - - executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(() => { - executionContext.addBlock(block) - }) + return new Promise((resolve, reject) => { + const block: Block = Block.fromBlockData({ + header: { + timestamp: (new Date().getTime() / 1000 | 0), + number: 0, + coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', + difficulty: new BN('69762765929000', 10), + gasLimit: new BN('8000000').imuln(1) + } + }, { common: executionContext.vmObject().common }) + + executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(() => { + executionContext.addBlock(block) + resolve({}) + }).catch((e) => reject(e)) + }) } diff --git a/libs/remix-simulator/src/methods/blocks.ts b/libs/remix-simulator/src/methods/blocks.ts index fc66a22892..bfed840284 100644 --- a/libs/remix-simulator/src/methods/blocks.ts +++ b/libs/remix-simulator/src/methods/blocks.ts @@ -31,6 +31,9 @@ export class Blocks { blockIndex = this.executionContext.latestBlockNumber } + if (Number.isInteger(blockIndex)) { + blockIndex = '0x' + blockIndex.toString(16) + } const block = this.executionContext.blocks[blockIndex] if (!block) { @@ -57,7 +60,6 @@ export class Blocks { transactions: block.transactions.map((t) => '0x' + t.hash().toString('hex')), uncles: [] } - cb(null, b) } diff --git a/libs/remix-simulator/src/provider.ts b/libs/remix-simulator/src/provider.ts index afd6696a17..b5c62daa4f 100644 --- a/libs/remix-simulator/src/provider.ts +++ b/libs/remix-simulator/src/provider.ts @@ -38,13 +38,12 @@ export class Provider { this.methods = merge(this.methods, (new Filters(this.executionContext)).methods()) this.methods = merge(this.methods, netMethods()) this.methods = merge(this.methods, this.Transactions.methods()) - this.methods = merge(this.methods, (new Debug(this.executionContext)).methods()) - - generateBlock(this.executionContext) - this.init() + this.methods = merge(this.methods, (new Debug(this.executionContext)).methods()) + // this.init() } async init () { + await generateBlock(this.executionContext) await this.Accounts.resetAccounts() this.Transactions.init(this.Accounts.accounts) } diff --git a/libs/remix-simulator/test/accounts.ts b/libs/remix-simulator/test/accounts.ts index 471cacfd72..0c36c38191 100644 --- a/libs/remix-simulator/test/accounts.ts +++ b/libs/remix-simulator/test/accounts.ts @@ -5,8 +5,9 @@ const web3 = new Web3() import * as assert from 'assert' describe('Accounts', () => { - before(function () { + before(async function () { const provider = new Provider() + await provider.init() web3.setProvider(provider) }) diff --git a/libs/remix-simulator/test/blocks.ts b/libs/remix-simulator/test/blocks.ts index 5a404ee722..827c4dc726 100644 --- a/libs/remix-simulator/test/blocks.ts +++ b/libs/remix-simulator/test/blocks.ts @@ -5,10 +5,11 @@ const web3 = new Web3() import * as assert from 'assert' describe('blocks', () => { - before(() => { + before(async () => { const provider = new Provider('vm', { coinbase: '0x0000000000000000000000000000000000000001' }) + await provider.init() web3.setProvider(provider) }) @@ -29,7 +30,7 @@ describe('blocks', () => { parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', size: 163591, - stateRoot: '0x63e1738ea12d4e7d12b71f0f4604706417921eb6a62c407ca5f1d66b9e67f579', + stateRoot: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: block.timestamp, totalDifficulty: '0', transactions: [], diff --git a/libs/remix-simulator/test/misc.ts b/libs/remix-simulator/test/misc.ts index 6d8f57ef49..cf38ce8740 100644 --- a/libs/remix-simulator/test/misc.ts +++ b/libs/remix-simulator/test/misc.ts @@ -5,8 +5,9 @@ const web3 = new Web3() import * as assert from 'assert' describe('Misc', () => { - before(() => { + before(async () => { const provider = new Provider() + await provider.init() web3.setProvider(provider) })