mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-08-02 09:53:30 +00:00
* 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
44 lines
1.2 KiB
Nim
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
|