logos-messaging-go-bindings/tests/waku_archive/test_driver_queue_index.nim
Ivan Folgueira Bande 2f6de9187f Squashed 'third-party/nwaku/' content from commit d94cb7c7
git-subtree-dir: third-party/nwaku
git-subtree-split: d94cb7c73631ffd4b934839ba58bc622d331a135
2025-10-02 11:52:12 +02:00

48 lines
1.1 KiB
Nim

{.used.}
import std/random, testutils/unittests
import waku/waku_core, waku/waku_archive/driver/queue_driver/index
var rng = initRand()
## Helpers
proc randomHash(): WakuMessageHash =
var hash: WakuMessageHash
for i in 0 ..< hash.len:
let numb: byte = byte(rng.next())
hash[i] = numb
hash
suite "Queue Driver - index":
## Test vars
let
hash = randomHash()
eqIndex1 = Index(time: getNanosecondTime(54321), hash: hash)
eqIndex2 = Index(time: getNanosecondTime(54321), hash: hash)
eqIndex3 = Index(time: getNanosecondTime(54321), hash: randomHash())
eqIndex4 = Index(time: getNanosecondTime(65432), hash: hash)
test "Index comparison":
check:
# equality
cmp(eqIndex1, eqIndex2) == 0
cmp(eqIndex1, eqIndex3) != 0
cmp(eqIndex1, eqIndex4) != 0
# ordering
cmp(eqIndex3, eqIndex4) < 0
cmp(eqIndex4, eqIndex3) > 0 # Test symmetry
cmp(eqIndex2, eqIndex4) < 0
cmp(eqIndex4, eqIndex2) > 0 # Test symmetry
test "Index equality":
check:
eqIndex1 == eqIndex2
eqIndex1 == eqIndex4
eqIndex2 != eqIndex3
eqIndex4 != eqIndex3