From 6298267ab55ae5d4ebe1b5d22eb77d60f6e37d7d Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:03:18 +0530 Subject: [PATCH] fix: tests --- .../test_rln_group_manager_onchain.nim | 48 ++++++++----------- .../test_rln_group_manager_static.nim | 4 +- .../group_manager/on_chain/group_manager.nim | 2 +- .../group_manager/static/group_manager.nim | 4 +- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim index 45bf55f1d8..aa28c7cf7a 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -175,7 +175,7 @@ proc stopAnvil(runAnvil: Process) {.used.} = proc setup(): Future[OnchainGroupManager] {.async.} = let rlnInstanceRes = createRlnInstance(tree_path = genTempPath("rln_tree", "group_manager_onchain")) - require: + check: rlnInstanceRes.isOk() let rlnInstance = rlnInstanceRes.get() @@ -286,7 +286,7 @@ suite "Onchain group manager": proc generateCallback(fut: Future[void]): OnRegisterCallback = proc callback(registrations: seq[Membership]): Future[void] {.async.} = - require: + check: registrations.len == 1 registrations[0].index == 0 registrations[0].rateCommitment == rateCommitment @@ -302,7 +302,7 @@ suite "Onchain group manager": except Exception, CatchableError: assert false, "exception raised: " & getCurrentExceptionMsg() - check await fut.withTimeout(5.seconds) + await fut let merkleRootAfter = manager.rlnInstance.getMerkleRoot().valueOr: raiseAssert $error @@ -352,7 +352,7 @@ suite "Onchain group manager": except Exception, CatchableError: assert false, "exception raised: " & getCurrentExceptionMsg() - check await allFutures(futures).withTimeout(10.seconds) + await allFutures(futures) let merkleRootAfter = manager.rlnInstance.getMerkleRoot().valueOr: raiseAssert $error @@ -417,7 +417,7 @@ suite "Onchain group manager": proc callback(registrations: seq[Membership]): Future[void] {.async.} = let rateCommitment = getRateCommitment(idCredentials, UserMessageLimit(1)) - require: + check: registrations.len == 1 registrations[0].rateCommitment == rateCommitment.get() registrations[0].index == 0 @@ -437,7 +437,7 @@ suite "Onchain group manager": except Exception, CatchableError: assert false, "exception raised: " & getCurrentExceptionMsg() - check await fut.withTimeout(5.seconds) + await fut await manager.stop() @@ -480,7 +480,7 @@ suite "Onchain group manager": except Exception, CatchableError: assert false, "exception raised: " & getCurrentExceptionMsg() - check await fut.withTimeout(5.seconds) + await fut let messageBytes = "Hello".toBytes() @@ -493,7 +493,7 @@ suite "Onchain group manager": data = messageBytes, epoch = epoch, messageId = MessageId(1) ) - require: + check: validProofRes.isOk() let validProof = validProofRes.get() @@ -525,12 +525,10 @@ suite "Onchain group manager": debug "epoch in bytes", epochHex = epoch.inHex() # generate proof - let validProofRes = manager.generateProof( + let validProof = manager.generateProof( data = messageBytes, epoch = epoch, messageId = MessageId(0) - ) - require: - validProofRes.isOk() - let validProof = validProofRes.get() + ).valueOr: + raiseAssert $error # validate the root (should be false) let validated = manager.validateRoot(validProof.merkleRoot) @@ -564,7 +562,7 @@ suite "Onchain group manager": await manager.register(credentials, UserMessageLimit(1)) except Exception, CatchableError: assert false, "exception raised: " & getCurrentExceptionMsg() - check await fut.withTimeout(5.seconds) + await fut let messageBytes = "Hello".toBytes() @@ -573,20 +571,16 @@ suite "Onchain group manager": debug "epoch in bytes", epochHex = epoch.inHex() # generate proof - let validProofRes = manager.generateProof( + let validProof = manager.generateProof( data = messageBytes, epoch = epoch, messageId = MessageId(0) - ) - require: - validProofRes.isOk() - let validProof = validProofRes.get() + ).valueOr: + raiseAssert $error # verify the proof (should be true) - let verifiedRes = manager.verifyProof(messageBytes, validProof) - require: - verifiedRes.isOk() + let verified = manager.verifyProof(messageBytes, validProof).valueOr: + raiseAssert $error - check: - verifiedRes.get() + check: verified await manager.stop() asyncTest "verifyProof: should reject invalid proof": @@ -623,7 +617,7 @@ suite "Onchain group manager": data = messageBytes, epoch = epoch, messageId = MessageId(0) ) - require: + check: invalidProofRes.isOk() let invalidProof = invalidProofRes.get() @@ -671,10 +665,10 @@ suite "Onchain group manager": except Exception, CatchableError: assert false, "exception raised: " & getCurrentExceptionMsg() - check await allFutures(futures).withTimeout(5.seconds) + await allFutures(futures) # At this point, we should have a full root queue, 5 roots, and partial buffer of 1 root - require: + check: manager.validRoots.len() == credentialCount - 1 manager.validRootBuffer.len() == 1 diff --git a/tests/waku_rln_relay/test_rln_group_manager_static.nim b/tests/waku_rln_relay/test_rln_group_manager_static.nim index a90a56c514..a9f2a71e4c 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_static.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_static.nim @@ -140,7 +140,7 @@ suite "Static group manager": registrations[0].rateCommitment == RateCommitment( idCommitment: idCommitment, userMessageLimit: DefaultUserMessageLimit - ) + ).toLeaf().get() callbackCalled = true fut.complete() @@ -204,7 +204,7 @@ suite "Static group manager": withdrawals[0].rateCommitment == RateCommitment( idCommitment: idCommitment, userMessageLimit: DefaultUserMessageLimit - ) + ).toLeaf().get() callbackCalled = true fut.complete() diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 90d8e9d4cb..a83ae9bb34 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -137,7 +137,7 @@ method atomicBatch*( var membersSeq = newSeq[Membership]() for i in 0 ..< rateCommitments.len: var index = start + MembershipIndex(i) - info "registering member to callback", rateCommitment = rateCommitments[i], index = index + debug "registering member to callback", rateCommitment = rateCommitments[i], index = index let member = Membership(rateCommitment: rateCommitments[i], index: index) membersSeq.add(member) await g.registerCb.get()(membersSeq) diff --git a/waku/waku_rln_relay/group_manager/static/group_manager.nim b/waku/waku_rln_relay/group_manager/static/group_manager.nim index a9fdd5f121..e8590325c9 100644 --- a/waku/waku_rln_relay/group_manager/static/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/static/group_manager.nim @@ -66,7 +66,9 @@ method register*( ): Future[void] {.async: (raises: [Exception]).} = initializedGuard(g) - await g.registerBatch(@[rateCommitment]) + let leaf = rateCommitment.toLeaf().get() + + await g.registerBatch(@[leaf]) method registerBatch*(