Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
add null-value in DB test
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Nov 30, 2020
1 parent f4c6493 commit a536e12
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/util/walkStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class WalkStrategy {
}

private async startWalk(root: Buffer): Promise<void> {
return await new Promise((resolve) => {
return await new Promise((resolve, reject) => {
this.resolve = resolve
this.trie
._lookupNode(root)
Expand All @@ -51,7 +51,7 @@ export default class WalkStrategy {
}
})
.catch((e) => {
throw e
reject(e)
})
})
}
Expand Down
34 changes: 33 additions & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tape from 'tape'
import * as rlp from 'rlp'
import { KECCAK256_NULL } from 'ethereumjs-util'
import { CheckpointTrie } from '../src'
import { BaseTrie, CheckpointTrie } from '../src'

tape('simple save and retrieve', function (tester) {
const it = tester.test
Expand Down Expand Up @@ -208,6 +208,38 @@ tape('testing deletion cases', function (tester) {
})
})

tape('shall handle the case of node not found correctly', async (t) => {
const trie = new BaseTrie()
await trie.put(Buffer.from('a'), Buffer.from('value1'))
await trie.put(Buffer.from('aa'), Buffer.from('value2'))
await trie.put(Buffer.from('aaa'), Buffer.from('value3'))

/* Setups a trie which consists of
ExtensionNode ->
BranchNode -> value1
ExtensionNode ->
BranchNode -> value2
LeafNode -> value3
*/

let path = await trie.findPath(Buffer.from('aaa'))

t.ok(path.node != null, 'findPath should find a node')

const { stack } = await trie.findPath(Buffer.from('aaa'))
await trie.db.del(stack[1].hash()) // delete the BranchNode -> value1 from the DB

path = await trie.findPath(Buffer.from('aaa'))

t.ok(path.node === null, 'findPath should not return a node now')
t.ok(
path.stack.length == 2,
'findPath should find the first extension node which is still in the DB and report the null, non existent node'
)

t.end()
})

tape('it should create the genesis state root from ethereum', function (tester) {
const it = tester.test
const trie4 = new CheckpointTrie()
Expand Down

0 comments on commit a536e12

Please sign in to comment.