logos-delivery/tests/waku_rln_relay/test_rln_nonce_manager.nim
Tanya S 57ff24760f
chore: phase 2 — rename/restructure waku_rln_relay → waku_rln (#3978)
* move rln specific procs and types

* Renaming and restructuring RLN module

* Rename waku_rln_relay to waku_rln

* rename rln-relay types to rln

* Fix linting

* update logScope topics to match new rln module name

* Rename waku_rln module to rln

* Rename WakuRln type to Rln, rename FFI raw type to RlnRaw to avoid collision

* Apply nph formatting

* Rename local rlnRelay to rln in mountRlnRelay
2026-06-27 12:28:59 +02:00

44 lines
1.2 KiB
Nim

{.used.}
import testutils/unittests, chronos, os
import logos_delivery/waku/rln/nonce_manager
suite "Nonce manager":
test "should initialize successfully":
let nm = NonceManager.init(nonceLimit = 100.uint)
check:
nm.nonceLimit == 100.uint
nm.nextNonce == 0.uint
test "should generate a new nonce":
let nm = NonceManager.init(nonceLimit = 100.uint)
let nonce = nm.getNonce().valueOr:
raiseAssert $error
check:
nonce == 0.uint
nm.nextNonce == 1.uint
test "should fail to generate a new nonce if limit is reached":
let nm = NonceManager.init(nonceLimit = 1.uint)
let nonce = nm.getNonce().valueOr:
raiseAssert $error
let failedNonceRes = nm.getNonce()
check:
failedNonceRes.isErr()
failedNonceRes.error.kind == NonceManagerErrorKind.NonceLimitReached
test "should generate a new nonce if epoch is crossed":
let nm = NonceManager.init(nonceLimit = 1.uint, epoch = float(0.000001))
let nonce = nm.getNonce().valueOr:
raiseAssert $error
sleep(1)
let nonce2 = nm.getNonce().valueOr:
raiseAssert $error
check:
nonce == 0.uint
nonce2 == 0.uint