mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-09 22:06:21 +00:00
2a67ac3c05
* simplify data storage to key-value, tries are not relevant for NBC * locked-down version of lmdb dependency * easier to build / maintain on various platforms
46 lines
843 B
Nim
46 lines
843 B
Nim
{.used.}
|
|
|
|
import
|
|
unittest,
|
|
../beacon_chain/kvstore
|
|
|
|
proc testKVStore*(db: KVStoreRef) =
|
|
let
|
|
key = [0'u8, 1, 2, 3]
|
|
value = [3'u8, 2, 1, 0]
|
|
value2 = [5'u8, 2, 1, 0]
|
|
|
|
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)
|
|
|
|
check:
|
|
db.contains(key)
|
|
db.get(key, proc(data: openArray[byte]) =
|
|
check data == value
|
|
)
|
|
|
|
db.put(key, value2) # overwrite old value
|
|
check:
|
|
db.contains(key)
|
|
db.get(key, proc(data: openArray[byte]) =
|
|
check data == 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 MemoryStoreRef.init())
|