Skip to content

Commit

Permalink
should throw on invalid stateRoots
Browse files Browse the repository at this point in the history
  • Loading branch information
wanderer committed Jun 18, 2018
1 parent cb3acc5 commit 5f2f196
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ module.exports = class Hypervisor {
async setStateRoot (stateRoot) {
this.tree.root = stateRoot
const node = await this.tree.get(Buffer.from([0]))
this.nonce = node.value || 0
if (!node.value) {
throw new Error('invalid state root')
}
this.nonce = node.value
}

/**
Expand Down
8 changes: 7 additions & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ tape('three communicating actors, with tick counting', async t => {
})

tape('errors', async t => {
t.plan(3)
t.plan(4)
const expectedState = Buffer.from('25bc7e81511bfded44a1846f4bca1acc99f24273', 'hex')
const tree = new RadixTree({
db
Expand Down Expand Up @@ -306,6 +306,12 @@ tape('errors', async t => {
hypervisor.send(message)
const stateRoot = await hypervisor.createStateRoot()
t.deepEquals(stateRoot, expectedState, 'expected root!')

try {
await hypervisor.setStateRoot(Buffer.from([0]))
} catch (e) {
t.pass('should catch invalid state roots')
}
})

tape('out-of-gas', async t => {
Expand Down

0 comments on commit 5f2f196

Please sign in to comment.