2018-10-05 00:20:12 +00:00
|
|
|
#[
|
|
|
|
import
|
|
|
|
unittest,
|
|
|
|
eth_trie/db,
|
|
|
|
../nimbus/db/backends/caching_backend
|
2018-09-12 11:00:39 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
key1 = [0.byte, 0, 1]
|
|
|
|
key2 = [0.byte, 0, 2]
|
|
|
|
key3 = [0.byte, 0, 3]
|
|
|
|
key4 = [0.byte, 0, 4]
|
|
|
|
value1 = [1.byte, 0, 1]
|
|
|
|
value2 = [1.byte, 0, 2]
|
|
|
|
value3 = [1.byte, 0, 3]
|
|
|
|
value4 = [1.byte, 0, 4]
|
|
|
|
|
|
|
|
suite "Caching DB backend":
|
|
|
|
test "Basic test":
|
|
|
|
let mdb = newMemDB()
|
|
|
|
mdb.put(key1, value1)
|
|
|
|
mdb.put(key2, value2)
|
|
|
|
let cdb = newCachingDB(trieDB(mdb))
|
|
|
|
check:
|
|
|
|
cdb.get(key1) == @value1
|
|
|
|
cdb.get(key2) == @value2
|
|
|
|
|
|
|
|
cdb.del(key1)
|
|
|
|
check:
|
|
|
|
key1 notin cdb
|
|
|
|
mdb.get(key1) == @value1
|
|
|
|
|
|
|
|
cdb.put(key3, value3)
|
|
|
|
check:
|
|
|
|
cdb.get(key3) == @value3
|
|
|
|
key3 notin mdb
|
|
|
|
|
|
|
|
cdb.put(key4, value4)
|
|
|
|
cdb.del(key4)
|
|
|
|
check(key4 notin cdb)
|
|
|
|
|
|
|
|
cdb.commit()
|
|
|
|
|
|
|
|
check:
|
|
|
|
key1 notin mdb
|
|
|
|
mdb.get(key2) == @value2
|
|
|
|
mdb.get(key3) == @value3
|
|
|
|
key4 notin mdb
|
2018-10-05 00:20:12 +00:00
|
|
|
]#
|