Repository navigation
test(relay): pin the handler's PoW rate conversion at non-zero rates (#1263) - #1343
Conversation
🦋 Changeset detectedLatest commit: e92993f The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
[Low impact] The PR appears safe to merge.
|
Description
Pins the event handler's dynamic PoW rate conversion at a non-zero rate with a socket-level test where accepted events advance
context.powand raise required difficulty above the floor.Related Issue
Closes #1263
Motivation and Context
In
crates/nostream-relay/src/handlers/event.rs,context.powcomputes the current events-per-second rate and passes it torequired_difficulty(Some(limits), rate, None). Previously, all socket-level tests ran at a rate of zero (HandlerContext.powstarts empty and was never advanced in tests), meaning substituting the literal0.0for that conversion would leave the whole suite green.This PR adds:
tests/handlers.rswhere an accepted event advancescontext.powundertarget_events_per_second: 0.01, verifying that the gate dynamically raises required difficulty above the floor and rejects a subsequent event.handlers/event.rsverifyingrequired_difficultyscaling at rates above target.How Has This Been Tested?
crates/nostream-relay/tests/handlers.rs:cargo test -p nostream-relay --test handlers -- the_handler_scales_difficulty_above_floor_as_accepted_events_arrive(passed)cargo test -p nostream-relay --test handlers(67/67 passed)cargo test -p nostream-relay --lib(30/30 passed)cargo fmt --all --checkcargo clippy -p nostream-relay --all-targets --all-features -- -D warnings-D clippy::unwrap_used -D clippy::expect_usedTypes of changes
Checklist: