Skip to content

Commit

Permalink
Added API test case to check if state manager instance works with tri…
Browse files Browse the repository at this point in the history
…e provided on VM instantiation (opts.state)
  • Loading branch information
holgerd77 committed Jan 10, 2019
1 parent f6b8615 commit 240dab6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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 240dab6

Please sign in to comment.