fix eth_getBlockByNumber when param is latest

pull/7/head
Iuri Matias 5 years ago
parent 782d79e508
commit 9703013b0e
  1. 2
      remix-lib/src/execution/execution-context.js
  2. 3
      remix-lib/src/execution/txRunner.js
  3. 12
      remix-simulator/src/methods/accounts.js
  4. 8
      remix-simulator/src/methods/blocks.js
  5. 4
      remix-simulator/src/provider.js
  6. 2
      remix-simulator/test/blocks.js

@ -115,6 +115,7 @@ function ExecutionContext () {
this.blockGasLimit = this.blockGasLimitDefault
this.customNetWorks = {}
this.blocks = {}
this.latestBlockNumber = 0;
this.txs = {}
this.init = function (config) {
@ -309,6 +310,7 @@ function ExecutionContext () {
self.blocks['0x' + block.hash().toString('hex')] = block
self.blocks[blockNumber] = block
self.latestBlockNumber = blockNumber
this.logsManager.checkBlock(blockNumber, block, this.web3())
}

@ -133,9 +133,6 @@ class TxRunner {
++self.blockNumber
this.runBlockInVm(tx, block, callback)
} else {
console.dir("============")
console.dir("========= useCall")
console.dir("============")
executionContext.vm().stateManager.checkpoint(() => {
this.runBlockInVm(tx, block, (err, result) => {
executionContext.vm().stateManager.revert(() => {

@ -17,18 +17,6 @@ var Accounts = function () {
Accounts.prototype.init = async function () {
let setBalance = (account) => {
return new Promise((resolve, reject) => {
// this.accountsKeys[ethJSUtil.toChecksumAddress(account.address).toLowerCase()] = account.privateKey
// this.accounts[ethJSUtil.toChecksumAddress(account.address).toLowerCase()] = { privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'), nonce: 0 }
// executionContext.vm().stateManager.getAccount(Buffer.from(account.address.toLowerCase().replace('0x', ''), 'hex'), (err, account) => {
// if (err) {
// throw new Error(err)
// }
// var balance = '0x56BC75E2D63100000'
// account.balance = balance || '0xf00000000000000001'
// resolve()
// })
this.accountsKeys[ethJSUtil.toChecksumAddress(account.address)] = account.privateKey
this.accounts[ethJSUtil.toChecksumAddress(account.address)] = { privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'), nonce: 0 }

@ -25,14 +25,10 @@ Blocks.prototype.methods = function () {
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
let blockIndex = payload.params[0]
if (blockIndex === 'latest') {
blockIndex = (Object.keys(executionContext.blocks).length / 2) - 1
blockIndex = executionContext.latestBlockNumber
}
// =======
// TODO: FIX ME
// var block = executionContext.blocks[blockIndex]
var block = Object.values(executionContext.blocks)[0]
// =======
var block = executionContext.blocks[blockIndex]
if (!block) {
return cb(new Error('block not found'))

@ -23,7 +23,6 @@ var Provider = function (options) {
this.methods = merge(this.methods, (new Misc()).methods())
this.methods = merge(this.methods, (new Filters()).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, this.Transactions.methods())
generateBlock()
@ -39,11 +38,8 @@ Provider.prototype.sendAsync = function (payload, callback) {
log.info('payload method is ', payload.method)
let method = this.methods[payload.method]
console.dir(payload)
if (method) {
return method.call(method, payload, (err, result) => {
console.dir(err)
console.dir(result)
if (err) {
return callback(err)
}

@ -29,7 +29,7 @@ describe('blocks', function () {
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
size: 163591,
stateRoot: '0xa633ca0e8f0ae4e86d4d572b048ea93d84eb4b11e2c988b48cb3a5f6f10b3c68',
stateRoot: '0x63e1738ea12d4e7d12b71f0f4604706417921eb6a62c407ca5f1d66b9e67f579',
timestamp: block.timestamp,
totalDifficulty: '0',
transactions: [],

Loading…
Cancel
Save