diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index dc2a9e584b..cda299cd72 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -14,7 +14,7 @@ class TxRunner { this.runAsync = true if (executionContext.isVM()) { //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.pendingTxs = {} diff --git a/remix-simulator/src/genesis.js b/remix-simulator/src/genesis.js new file mode 100644 index 0000000000..40bf11e8a7 --- /dev/null +++ b/remix-simulator/src/genesis.js @@ -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 \ No newline at end of file diff --git a/remix-simulator/src/provider.js b/remix-simulator/src/provider.js index cf38200d4c..3a28adfd9f 100644 --- a/remix-simulator/src/provider.js +++ b/remix-simulator/src/provider.js @@ -8,6 +8,8 @@ const Net = require('./methods/net.js') const Transactions = require('./methods/transactions.js') const Whisper = require('./methods/whisper.js') +const generateBlock = require('./genesis.js') + var Provider = function (options) { 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 Transactions(this.Accounts.accounts)).methods()) this.methods = merge(this.methods, (new Whisper()).methods()) + + generateBlock() } Provider.prototype.sendAsync = function (payload, callback) { @@ -44,4 +48,4 @@ Provider.prototype.isConnected = function () { return true } -module.exports = Provider +module.exports = Provider \ No newline at end of file diff --git a/remix-simulator/test/blocks.js b/remix-simulator/test/blocks.js index d56deee4c8..60b87dbb55 100644 --- a/remix-simulator/test/blocks.js +++ b/remix-simulator/test/blocks.js @@ -16,22 +16,20 @@ describe('blocks', function () { let block = await web3.eth.getBlock(1) let expectedBlock = { - difficulty: '0', - extraData: '0x', - gasLimit: 8000000, + difficulty: '69762765929000', + extraData: '0x0', + gasLimit: 5000000, gasUsed: 0, - hash: '0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f', - logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + hash: block.hash.toString('hex'), + logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', miner: '0x0000000000000000000000000000000000000001', - mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', - nonce: '0x0000000000000042', - number: 0, + nonce: '0x0000000000000000', + number: 1, parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', - receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', - size: 504, - stateRoot: '0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff', - timestamp: 0, + size: 163591, + stateRoot: '0xa633ca0e8f0ae4e86d4d572b048ea93d84eb4b11e2c988b48cb3a5f6f10b3c68', + timestamp: block.timestamp, totalDifficulty: '0', transactions: [], transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',