Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for opts.state overwrite #415

Merged
merged 2 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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