nim-eth/tests/db/test_kvstore.nim
Jacek Sieka 205b57fe71
port kvstore from nim-beacon-chain (#230)
* port kvstore from nim-beacon-chain
* remove old database backends
* use kvstore in trie database
* add sqlite dep
* avoid template param double evaluation
* clean up heterogenous lookup todo
2020-04-27 15:16:11 +02:00

48 lines
846 B
Nim

{.used.}
import
unittest,
../../eth/db/kvstore
const
key = [0'u8, 1, 2, 3]
value = [3'u8, 2, 1, 0]
value2 = [5'u8, 2, 1, 0]
proc testKvStore*(db: KvStoreRef) =
check:
db != nil
not db.get(key, proc(data: openArray[byte]) = discard)[]
not db.contains(key)[]
db.del(key)[] # does nothing
db.put(key, value)[]
var v: seq[byte]
proc grab(data: openArray[byte]) =
v = @data
check:
db.contains(key)[]
db.get(key, grab)[]
v == value
db.put(key, value2)[] # overwrite old value
check:
db.contains(key)[]
db.get(key, grab)[]
v == value2
db.del(key)[]
check:
not db.get(key, proc(data: openArray[byte]) = discard)[]
not db.contains(key)[]
db.del(key)[] # does nothing
suite "MemoryStoreRef":
test "KvStore interface":
testKvStore(kvStore MemStoreRef.init())