forked from ethereumjs/merkle-patricia-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy.js
34 lines (30 loc) · 965 Bytes
/
copy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const tape = require('tape')
const Trie = require('../src/index.js')
tape('SecureTrie.copy', function (it) {
it.test('created copy includes values added after checkpoint', function (t) {
const trie = new Trie();
trie.put('key1', 'value1', function () {
trie.checkpoint()
trie.put('key2', 'value2', function () {
const trieCopy = trie.copy();
trieCopy.get('key2', function (err, value) {
t.equal(value && value.toString(), 'value2')
t.end(err)
})
})
})
})
it.test('created copy includes values added before checkpoint', function (t) {
const trie = new Trie();
trie.put('key1', 'value1', function () {
trie.checkpoint()
trie.put('key2', 'value2', function () {
const trieCopy = trie.copy();
trieCopy.get('key1', function (err, value) {
t.equal(value && value.toString(), 'value1')
t.end(err)
})
})
})
})
})