fix remix simulator tests

pull/1122/head
yann300 4 years ago
parent 3c377a6656
commit 815f78cd90
  1. 8
      libs/remix-lib/src/execution/txRunner.ts
  2. 29
      libs/remix-simulator/src/genesis.ts
  3. 4
      libs/remix-simulator/src/methods/blocks.ts
  4. 7
      libs/remix-simulator/src/provider.ts
  5. 3
      libs/remix-simulator/test/accounts.ts
  6. 5
      libs/remix-simulator/test/blocks.ts
  7. 3
      libs/remix-simulator/test/misc.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)
})
}

@ -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))
})
}

@ -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)
}

@ -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)
}

@ -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)
})

@ -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: [],

@ -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)
})

Loading…
Cancel
Save