fix tests; add method to generate empty block

pull/5370/head
Iuri Matias 6 years ago
parent c6f72c4eda
commit f88a15cdea
  1. 2
      remix-lib/src/execution/txRunner.js
  2. 40
      remix-simulator/src/genesis.js
  3. 4
      remix-simulator/src/provider.js
  4. 22
      remix-simulator/test/blocks.js

@ -14,7 +14,7 @@ class TxRunner {
this.runAsync = true this.runAsync = true
if (executionContext.isVM()) { if (executionContext.isVM()) {
//this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. //this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block.
this.blockNumber = 1 // The VM is running in Homestead mode, which started at this block. this.blockNumber = 2 // The VM is running in Homestead mode, which started at this block.
this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time. this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time.
} }
this.pendingTxs = {} this.pendingTxs = {}

@ -0,0 +1,40 @@
var EthJSBlock = require('ethereumjs-block')
var RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext
var ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN
function checkpointAndCommit (cb) {
if (executionContext.vm().stateManager._checkpointCount > 0) {
return executionContext.vm().stateManager.commit(() => {
cb()
})
}
executionContext.vm().stateManager.checkpoint(() => {
executionContext.vm().stateManager.commit(() => {
cb()
})
})
}
function generateBlock () {
var block = new EthJSBlock({
header: {
timestamp: (new Date().getTime() / 1000 | 0),
number: 1,
coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a',
difficulty: (new BN('69762765929000', 10)),
gasLimit: new BN('5000000').imuln(1)
},
transactions: [],
uncleHeaders: []
})
checkpointAndCommit(() => {
executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }, function () {
executionContext.addBlock(block)
})
})
}
module.exports = generateBlock

@ -8,6 +8,8 @@ const Net = require('./methods/net.js')
const Transactions = require('./methods/transactions.js') const Transactions = require('./methods/transactions.js')
const Whisper = require('./methods/whisper.js') const Whisper = require('./methods/whisper.js')
const generateBlock = require('./genesis.js')
var Provider = function (options) { var Provider = function (options) {
this.Accounts = new Accounts() this.Accounts = new Accounts()
@ -18,6 +20,8 @@ var Provider = function (options) {
this.methods = merge(this.methods, (new Net()).methods()) this.methods = merge(this.methods, (new Net()).methods())
this.methods = merge(this.methods, (new Transactions(this.Accounts.accounts)).methods()) this.methods = merge(this.methods, (new Transactions(this.Accounts.accounts)).methods())
this.methods = merge(this.methods, (new Whisper()).methods()) this.methods = merge(this.methods, (new Whisper()).methods())
generateBlock()
} }
Provider.prototype.sendAsync = function (payload, callback) { Provider.prototype.sendAsync = function (payload, callback) {

@ -16,22 +16,20 @@ describe('blocks', function () {
let block = await web3.eth.getBlock(1) let block = await web3.eth.getBlock(1)
let expectedBlock = { let expectedBlock = {
difficulty: '0', difficulty: '69762765929000',
extraData: '0x', extraData: '0x0',
gasLimit: 8000000, gasLimit: 5000000,
gasUsed: 0, gasUsed: 0,
hash: '0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f', hash: block.hash.toString('hex'),
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
miner: '0x0000000000000000000000000000000000000001', miner: '0x0000000000000000000000000000000000000001',
mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', nonce: '0x0000000000000000',
nonce: '0x0000000000000042', number: 1,
number: 0,
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
size: 504, size: 163591,
stateRoot: '0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff', stateRoot: '0xa633ca0e8f0ae4e86d4d572b048ea93d84eb4b11e2c988b48cb3a5f6f10b3c68',
timestamp: 0, timestamp: block.timestamp,
totalDifficulty: '0', totalDifficulty: '0',
transactions: [], transactions: [],
transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',

Loading…
Cancel
Save