Commit 815f78cd authored by yann300's avatar yann300

fix remix simulator tests

parent 3c377a66
...@@ -111,6 +111,10 @@ export class TxRunner { ...@@ -111,6 +111,10 @@ export class TxRunner {
return callback('Invalid account selected') return callback('Invalid account selected')
} }
if (Number.isInteger(gasLimit)) {
gasLimit = '0x' + gasLimit.toString(16)
}
this.executionContext.vm().stateManager.getAccount(Address.fromString(from)).then((res) => { this.executionContext.vm().stateManager.getAccount(Address.fromString(from)).then((res) => {
// See https://github.com/ethereumjs/ethereumjs-tx/blob/master/docs/classes/transaction.md#constructor // See https://github.com/ethereumjs/ethereumjs-tx/blob/master/docs/classes/transaction.md#constructor
// for initialization fields and their types // for initialization fields and their types
...@@ -150,8 +154,8 @@ export class TxRunner { ...@@ -150,8 +154,8 @@ export class TxRunner {
}) })
}) })
} }
}).catch(() => { }).catch((e) => {
callback('Account not found') callback(e)
}) })
} }
......
...@@ -2,17 +2,20 @@ import { Block } from '@ethereumjs/block' ...@@ -2,17 +2,20 @@ import { Block } from '@ethereumjs/block'
import { BN } from 'ethereumjs-util' import { BN } from 'ethereumjs-util'
export function generateBlock (executionContext) { export function generateBlock (executionContext) {
const block: Block = Block.fromBlockData({ return new Promise((resolve, reject) => {
header: { const block: Block = Block.fromBlockData({
timestamp: (new Date().getTime() / 1000 | 0), header: {
number: 0, timestamp: (new Date().getTime() / 1000 | 0),
coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', number: 0,
difficulty: new BN('69762765929000', 10), coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a',
gasLimit: new BN('8000000').imuln(1) difficulty: new BN('69762765929000', 10),
} gasLimit: new BN('8000000').imuln(1)
}, { common: executionContext.vmObject().common }) }
}, { common: executionContext.vmObject().common })
executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(() => {
executionContext.addBlock(block) executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(() => {
}) executionContext.addBlock(block)
resolve({})
}).catch((e) => reject(e))
})
} }
...@@ -31,6 +31,9 @@ export class Blocks { ...@@ -31,6 +31,9 @@ export class Blocks {
blockIndex = this.executionContext.latestBlockNumber blockIndex = this.executionContext.latestBlockNumber
} }
if (Number.isInteger(blockIndex)) {
blockIndex = '0x' + blockIndex.toString(16)
}
const block = this.executionContext.blocks[blockIndex] const block = this.executionContext.blocks[blockIndex]
if (!block) { if (!block) {
...@@ -57,7 +60,6 @@ export class Blocks { ...@@ -57,7 +60,6 @@ export class Blocks {
transactions: block.transactions.map((t) => '0x' + t.hash().toString('hex')), transactions: block.transactions.map((t) => '0x' + t.hash().toString('hex')),
uncles: [] uncles: []
} }
cb(null, b) cb(null, b)
} }
......
...@@ -38,13 +38,12 @@ export class Provider { ...@@ -38,13 +38,12 @@ export class Provider {
this.methods = merge(this.methods, (new Filters(this.executionContext)).methods()) this.methods = merge(this.methods, (new Filters(this.executionContext)).methods())
this.methods = merge(this.methods, netMethods()) this.methods = merge(this.methods, netMethods())
this.methods = merge(this.methods, this.Transactions.methods()) this.methods = merge(this.methods, this.Transactions.methods())
this.methods = merge(this.methods, (new Debug(this.executionContext)).methods()) this.methods = merge(this.methods, (new Debug(this.executionContext)).methods())
// this.init()
generateBlock(this.executionContext)
this.init()
} }
async init () { async init () {
await generateBlock(this.executionContext)
await this.Accounts.resetAccounts() await this.Accounts.resetAccounts()
this.Transactions.init(this.Accounts.accounts) this.Transactions.init(this.Accounts.accounts)
} }
......
...@@ -5,8 +5,9 @@ const web3 = new Web3() ...@@ -5,8 +5,9 @@ const web3 = new Web3()
import * as assert from 'assert' import * as assert from 'assert'
describe('Accounts', () => { describe('Accounts', () => {
before(function () { before(async function () {
const provider = new Provider() const provider = new Provider()
await provider.init()
web3.setProvider(provider) web3.setProvider(provider)
}) })
......
...@@ -5,10 +5,11 @@ const web3 = new Web3() ...@@ -5,10 +5,11 @@ const web3 = new Web3()
import * as assert from 'assert' import * as assert from 'assert'
describe('blocks', () => { describe('blocks', () => {
before(() => { before(async () => {
const provider = new Provider('vm', { const provider = new Provider('vm', {
coinbase: '0x0000000000000000000000000000000000000001' coinbase: '0x0000000000000000000000000000000000000001'
}) })
await provider.init()
web3.setProvider(provider) web3.setProvider(provider)
}) })
...@@ -29,7 +30,7 @@ describe('blocks', () => { ...@@ -29,7 +30,7 @@ describe('blocks', () => {
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
size: 163591, size: 163591,
stateRoot: '0x63e1738ea12d4e7d12b71f0f4604706417921eb6a62c407ca5f1d66b9e67f579', stateRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
timestamp: block.timestamp, timestamp: block.timestamp,
totalDifficulty: '0', totalDifficulty: '0',
transactions: [], transactions: [],
......
...@@ -5,8 +5,9 @@ const web3 = new Web3() ...@@ -5,8 +5,9 @@ const web3 = new Web3()
import * as assert from 'assert' import * as assert from 'assert'
describe('Misc', () => { describe('Misc', () => {
before(() => { before(async () => {
const provider = new Provider() const provider = new Provider()
await provider.init()
web3.setProvider(provider) web3.setProvider(provider)
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment