Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Jun 4, 2024
1 parent c67a659 commit a9f0a9b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
40 changes: 17 additions & 23 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -493,7 +493,7 @@ suite "Onchain group manager":
data = messageBytes, epoch = epoch, messageId = MessageId(1)
)

require:
check:
validProofRes.isOk()
let validProof = validProofRes.get()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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":
Expand Down Expand Up @@ -623,7 +617,7 @@ suite "Onchain group manager":
data = messageBytes, epoch = epoch, messageId = MessageId(0)
)

require:
check:
invalidProofRes.isOk()
let invalidProof = invalidProofRes.get()

Expand Down Expand Up @@ -674,7 +668,7 @@ suite "Onchain group manager":
check await allFutures(futures).withTimeout(5.seconds)

# 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

Expand Down
4 changes: 2 additions & 2 deletions tests/waku_rln_relay/test_rln_group_manager_static.nim
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ suite "Static group manager":
registrations[0].rateCommitment ==
RateCommitment(
idCommitment: idCommitment, userMessageLimit: DefaultUserMessageLimit
)
).toLeaf().get()
callbackCalled = true
fut.complete()

Expand Down Expand Up @@ -204,7 +204,7 @@ suite "Static group manager":
withdrawals[0].rateCommitment ==
RateCommitment(
idCommitment: idCommitment, userMessageLimit: DefaultUserMessageLimit
)
).toLeaf().get()

callbackCalled = true
fut.complete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion waku/waku_rln_relay/group_manager/static/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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*(
Expand Down

0 comments on commit a9f0a9b

Please sign in to comment.