Add tests for lightpush force refresh regenerates proof

This commit is contained in:
stubbsta 2026-07-02 13:45:49 +02:00
parent 5659ab61ec
commit 1473301b09
No known key found for this signature in database
2 changed files with 65 additions and 0 deletions

View File

@ -180,6 +180,38 @@ suite "RLN Proofs as a Lightpush Service":
assert publishResponse.isErr(), "We expect an error response" assert publishResponse.isErr(), "We expect an error response"
check publishResponse.error == protocol_metrics.notPublishedAnyPeer check publishResponse.error == protocol_metrics.notPublishedAnyPeer
asyncTest "force refresh regenerates proof and refetches merkle path":
# Exercises the primitive that legacyLightpushPublish leans on after a
# "RLN validation failed" rejection: an already attached proof must NOT
# short-circuit checkAndGenerateRLNProof when forceMerkleProofRefresh=true,
# and the cache must be refetched from chain instead of trusted.
let firstMsg =
(await checkAndGenerateRLNProof(some(server.rln), message)).get()
check firstMsg.proof.len > 0
# Corrupt the cache to model a stale/invalid witness — the same state a
# server-side "RLN validation failed" rejection would leave us in.
let manager = cast[OnchainGroupManager](server.rln.groupManager)
let goodCache = manager.merkleProofCache
manager.merkleProofCache = newSeq[byte](goodCache.len)
check manager.merkleProofCache != goodCache
# Force-regenerate. The existing proof must be discarded, the cache
# refetched from chain, and a fresh proof produced.
let secondMsg = (
await checkAndGenerateRLNProof(
some(server.rln), firstMsg, forceMerkleProofRefresh = true
)
).get()
check:
secondMsg.proof.len > 0
# Regenerated, not passed through — nonce manager consumes a new id
# per call, so the two proofs cannot be byte-equal.
secondMsg.proof != firstMsg.proof
# Cache was refetched from chain, overwriting the corruption.
manager.merkleProofCache == goodCache
suite "Waku Legacy Lightpush message delivery": suite "Waku Legacy Lightpush message delivery":
asyncTest "Legacy lightpush message flow succeed": asyncTest "Legacy lightpush message flow succeed":
## Setup ## Setup

View File

@ -177,6 +177,39 @@ suite "RLN Proofs as a Lightpush Service":
assert publishResponse.isErr(), "We expect an error response" assert publishResponse.isErr(), "We expect an error response"
check publishResponse.error.code == LightPushErrorCode.NO_PEERS_TO_RELAY check publishResponse.error.code == LightPushErrorCode.NO_PEERS_TO_RELAY
asyncTest "force refresh regenerates proof and refetches merkle path":
# Exercises the primitive that lightpushPublish leans on after a 420
# (INVALID_MESSAGE) or 504 (OUT_OF_RLN_PROOF) rejection: an already
# attached proof must NOT short-circuit checkAndGenerateRLNProof when
# forceMerkleProofRefresh=true, and the cache must be refetched from
# chain instead of trusted.
let firstMsg =
(await checkAndGenerateRLNProof(some(server.rln), message)).get()
check firstMsg.proof.len > 0
# Corrupt the cache to model a stale/invalid witness — the same state a
# 420/504 rejection would leave us in.
let manager = cast[OnchainGroupManager](server.rln.groupManager)
let goodCache = manager.merkleProofCache
manager.merkleProofCache = newSeq[byte](goodCache.len)
check manager.merkleProofCache != goodCache
# Force-regenerate. The existing proof must be discarded, the cache
# refetched from chain, and a fresh proof produced.
let secondMsg = (
await checkAndGenerateRLNProof(
some(server.rln), firstMsg, forceMerkleProofRefresh = true
)
).get()
check:
secondMsg.proof.len > 0
# Regenerated, not passed through — nonce manager consumes a new id
# per call, so the two proofs cannot be byte-equal.
secondMsg.proof != firstMsg.proof
# Cache was refetched from chain, overwriting the corruption.
manager.merkleProofCache == goodCache
suite "Waku Lightpush message delivery": suite "Waku Lightpush message delivery":
asyncTest "lightpush message flow succeed": asyncTest "lightpush message flow succeed":
## Setup ## Setup