Skip to content

Commit

Permalink
Merge pull request #415 from ethereumjs/fix-trie-overwrite-issue-on-a…
Browse files Browse the repository at this point in the history
…ctiveprecompiles

Bugfix for opts.state overwrite
  • Loading branch information
holgerd77 authored Jan 10, 2019
2 parents 1587bef + 240dab6 commit 1270116
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function VM (opts = {}) {
} else {
var trie = opts.state || new Trie()
if (opts.activatePrecompiles) {
trie = new Trie()
for (var i = 1; i <= 8; i++) {
trie.put(new BN(i).toArrayLike(Buffer, 'be', 20), new Account().serialize())
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"ethereumjs-util": "^6.0.0",
"fake-merkle-patricia-tree": "^1.0.1",
"functional-red-black-tree": "^1.0.1",
"merkle-patricia-tree": "^2.1.2",
"merkle-patricia-tree": "^2.3.2",
"rustbn.js": "~0.2.0",
"safe-buffer": "^5.1.1"
},
Expand Down
12 changes: 11 additions & 1 deletion tests/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const { promisify } = require('util')
const tape = require('tape')
const util = require('ethereumjs-util')
const Block = require('ethereumjs-block')
const Trie = require('merkle-patricia-tree/secure')
const VM = require('../../lib/index')
const { setupVM } = require('./utils')
const { setupPreConditions } = require('../util')
const testData = require('./testdata.json')

tape('VM with fake blockchain', (t) => {
t.test('should insantiate without params', (st) => {
t.test('should instantiate without params', (st) => {
const vm = new VM()
st.ok(vm.stateManager)
st.deepEqual(vm.stateManager._trie.root, util.KECCAK256_RLP, 'it has default trie')
Expand All @@ -22,6 +23,15 @@ tape('VM with fake blockchain', (t) => {
st.end()
})

t.test('should work with trie (state) provided', (st) => {
let trie = new Trie()
trie.isTestTrie = true
let vm = new VM({ state: trie, activatePrecompiles: true })
st.notEqual(vm.stateManager._trie.root, util.KECCAK256_RLP, 'it has different root')
st.ok(vm.stateManager._trie.isTestTrie, 'it works on trie provided')
st.end()
})

t.test('should only accept valid chain and fork', (st) => {
let vm = new VM({ chain: 'ropsten', hardfork: 'byzantium' })
st.equal(vm.stateManager._common.param('gasPrices', 'ecAdd'), 500)
Expand Down

0 comments on commit 1270116

Please sign in to comment.