Skip to content

test: pin hashlock payment count and reserved escrow keys - #808

Merged
mergekeeper[bot] merged 3 commits into
accensa:mainfrom
aojomo:test/622-hashlock-reserve-invariant
Oct 16, 2026
Merged

mergekeeper[bot] merged 3 commits into
accensa:mainfrom
aojomo:test/622-hashlock-reserve-invariant

Conversation

@aojomo

@aojomo aojomo commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #622

Summary

Appends a reserve-bookkeeping section to contracts/state-channel/src/hashlock_test.rs, reusing the file's existing setup() harness. Test-only change: hashlock.rs, lib.rs and the sibling test files (htlc_test.rs, multi_asset_test.rs, watchtower_test.rs) are untouched, and no error variants or gates were relaxed.

Three new cases:

  • count_key_allocates_distinct_sequential_ids — pins DataKey::HashlockPaymentCount (lib.rs:126) as the allocation cursor: ids start at 1, advance by exactly one per add_hashlock_payment so two payments on one channel never collide, and a resolve neither rewinds the cursor nor reuses a settled slot (the next add still gets the next id).
  • hashlock_reserved_equals_pending_sum_after_every_transition — after every add and resolve, recomputes the pending sum from the DataKey::HashlockPayment records themselves and asserts DataKey::HashlockReserved (lib.rs:129) equals it exactly — so a resolve that leaves the reserve stale, in either direction, fails. A double reveal is rejected with HtlcNotPending and the reserve is left exactly at the pending sum; a second reveal attempt can neither re-release nor keep escrow reserved.
  • refund_and_resolve_each_release_exactly_their_own_amount — a hashlock invoice (120) and an HTLC hop (300) share one channel's escrow under separate reserve keys. Refunding the timed-out hop releases exactly its own 300 (the hashlock reserve and the pending invoice are untouched, and a second refund is rejected); revealing the invoice releases exactly its own 120 into the receiver's balance.

Verification

All three CI gates were run locally on this branch and are green:

  • cargo fmt --all -- --check
  • cargo clippy --locked --all-targets -- -D warnings
  • cargo test --locked --workspace — full workspace green; state-channel suite: 105 passed, 0 failed, naming the new cases hashlock_test::count_key_allocates_distinct_sequential_ids, hashlock_test::hashlock_reserved_equals_pending_sum_after_every_transition, hashlock_test::refund_and_resolve_each_release_exactly_their_own_amount.

The test that proves contracts/state-channel/src/lib.rs:129 (HashlockReserved) is handled: hashlock_test::hashlock_reserved_equals_pending_sum_after_every_transition. It derives the expected reserve from the payment records after every transition and asserts get_hashlock_reserved matches — and count_key_allocates_distinct_sequential_ids pins lib.rs:126's cursor the same way.

Mutation check (temporary, reverted; hashlock.rs/lib.rs are byte-identical to main in this PR's diff):

  • deleting set_reserved(...) from resolve_payment → the pending-sum test fails (stale reserve detected);
  • making the id cursor jump by two → the sequential-ids test fails.

Notes

Summary by CodeRabbit

  • Tests
    • Expanded coverage of state-channel hashlock payment IDs and reserve tracking, including add, reveal, refund, and rejected double-reveal scenarios.
    • Added checks that resolving or refunding a payment releases only its reserve and that payment IDs increase without being reused.

aojomo and others added 2 commits October 16, 2026 12:36
…variant (issue accensa#622)

Appends three tests to hashlock_test.rs that assert, after every
add/resolve/refund transition, that HashlockReserved equals the sum of
the still-pending payments' amounts; that HashlockPaymentCount hands out
distinct sequential ids that a resolve never rewinds or reuses; and that
a reveal and a timed-out HTLC refund each release exactly their own
amount, with double reveal/refund rejected and the reserve left at the
pending sum. Test-only: hashlock.rs, lib.rs and sibling test files are
untouched.

Verified with a mutation check: stalling the resolve's set_reserved and
making the cursor jump by two both turn the new tests red.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
…ccensa#622)

The changelog gate requires an entry for any contracts/**/src/** change;
the PR carries the skip-changelog option only for changes with no
user-facing record, and this one pins two published storage keys.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Oct 16, 2026

Copy link
Copy Markdown

@aojomo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@mergekeeper

mergekeeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

MergeKeeper review unavailable

AI provider failed: gemini-3.5-flash-lite (503)

No approval or merge action was taken.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 65e9486a-5856-4760-ba87-d6bc470bbdc0
📥 Commits

Reviewing files that changed from the base of the PR and between ee49689 and 4f43198.

📒 Files selected for processing: 3
  • contracts/state-channel/test_snapshots/hashlock_test/count_key_allocates_distinct_sequential_ids.1.json
  • contracts/state-channel/test_snapshots/hashlock_test/hashlock_reserved_equals_pending_sum_after_every_transition.1.json
  • contracts/state-channel/test_snapshots/hashlock_test/refund_and_resolve_each_release_exactly_their_own_amount.1.json

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ff305e39-7ccc-4247-b9fe-e43226b8861d
📥 Commits

Reviewing files that changed from the base of the PR and between bb4c341 and ee49689.

📒 Files selected for processing: 2
  • CHANGELOG.md
  • contracts/state-channel/src/hashlock_test.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Adds tests for hashlock payment ID allocation and reserve bookkeeping. The tests cover additions, reveals, rejected double reveals, and timed-out HTLC refunds.

Changes: Hashlock reserve tests

Layer / File(s) Summary
Payment IDs and reserve transitions
contracts/state-channel/src/hashlock_test.rs, CHANGELOG.md
Adds checks that payment IDs advance without reuse and that the stored reserve matches pending hashlock amounts after payment transitions. Covers rejected double reveals and a timed-out HTLC refund that releases only its reserve. The changelog identifies the change as test-only.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: chase3020

Merge Risk: ⚪ Minimal · up to ee496

The added tests and changelog entry present no identified merge-blocking risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Out of Scope Changes check Warning Issue [#622] defines a hard file boundary: changes belong in contracts/state-channel/src/hashlock_test.rs and needed test fixtures, and files outside those regions are not included. The PR adds a `C… Remove the CHANGELOG.md change, or obtain an explicit issue-scope exception from the maintainer before merging. Keep the implementation changes confined to the permitted test files.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description clearly explains the test-only changes, affected files, verification results, related issue, and contract-safety impact. It does not reproduce the template checklist headings or checkb…
Title check Passed The title clearly identifies the main change: tests that pin hashlock payment-count allocation and reserved escrow keys.
Linked Issues check Passed Issue [#622] requires tests for sequential payment IDs, the pending-payment reserve invariant, exact resolve/refund releases, rejected repeat settlement, reuse of setup(), and a green workspace test…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. (1 skipped: 1 …
Full details: Description check

Explanation

The description clearly explains the test-only changes, affected files, verification results, related issue, and contract-safety impact. It does not reproduce the template checklist headings or checkbox state, but it provides the required information in prose.

Full details: Linked Issues check

Explanation

Issue [#622] requires tests for sequential payment IDs, the pending-payment reserve invariant, exact resolve/refund releases, rejected repeat settlement, reuse of setup(), and a green workspace test. The PR summary reports three named tests that cover these cases. The reviewed hashlock_test.rs contains setup(), the reserve recomputation helper, and the sequential-ID test. The reported workspace test result is green. No dependency, contract-source, sibling-test, epoch.rs, or ROADMAP.md change is reported.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. (1 skipped: 1 unsupported.)

Full details: Out of Scope Changes check

Explanation

Issue [#622] defines a hard file boundary: changes belong in contracts/state-channel/src/hashlock_test.rs and needed test fixtures, and files outside those regions are not included. The PR adds a CHANGELOG.md entry. The entry documents the test work, but it is still outside the issue's permitted regions. The supplied whole-PR diff was unavailable, so this conclusion relies on the PR summary and the reviewed CHANGELOG.md and hashlock_test.rs blobs.

Resolution

Remove the CHANGELOG.md change, or obtain an explicit issue-scope exception from the maintainer before merging. Keep the implementation changes confined to the permitted test files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

… (issue accensa#622)

Fixtures only this change needs: the three new hashlock bookkeeping cases
record their golden invocation snapshots alongside the existing
hashlock_test goldens. Other crates' re-recorded goldens are deliberately
left alone.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
@mergekeeper

mergekeeper Bot commented Oct 16, 2026

Copy link
Copy Markdown

MergeKeeper review

Scope: in scope for linked issue #622.
Verdict: clean

The PR successfully implements the required test coverage for issue #622 by pinning hashlock payment counts and reserved escrow keys in contracts/state-channel/src/hashlock_test.rs, including appropriate test snapshot JSON files and a minimal changelog update. All changes adhere strictly to the defined file ownership boundaries and operational constraints.

Reviewed commit: 4f431982da894f77f2e525c5342fec66797ac0e0.
CI and merge eligibility are checked separately.

@mergekeeper mergekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

The PR successfully implements the required test coverage for issue #622 by pinning hashlock payment counts and reserved escrow keys in contracts/state-channel/src/hashlock_test.rs, including appropriate test snapshot JSON files and a minimal changelog update. All changes adhere strictly to the defined file ownership boundaries and operational constraints.

@mergekeeper
mergekeeper Bot merged commit 98abe64 into accensa:main Oct 16, 2026
3 checks passed
@mergekeeper

mergekeeper Bot commented Oct 16, 2026

Copy link
Copy Markdown

Merged

Merged with squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: pin hashlock payment count and reserved escrow keys

1 participant