Repository navigation
test(contracts): align StreamClaimed events with partial claim state - #1422
Merged
github-actions[bot] merged 1 commit intoOct 23, 2026
Conversation
Add an event-only reconstruction guarantee for the partial claim workflow and document the invariant in the contract source and ABI. The existing ritik4ever#1138 tests check claim mechanics and per-event field values. This adds a test that replays the emitted StreamClaimed events exactly the way the backend indexer does, without reading contract storage, across a one-unit claim, a partial claim, a failed payout, and the completing claim. It asserts the running payout sum equals each event's claimed_amount and advances monotonically, that the rolled-back claim contributes no event, and that StreamCompleted is never counted as payout. StreamClaimed already carries amount (recipient payout) and claimed_amount (cumulative balance after the call), and is published only after the token transfer and accounting update succeed, so the committed action is reconstructable exactly once from event data; this is confirmed rather than changed. The StreamClaimed struct doc, the claim() ordering doc, and CONTRACT_ABI.md now spell this out.
|
@melanindebbie is attempting to deploy a commit to the ritik4ever's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #1137 asks to align the emitted contract events with the Partial claim state so that an indexer can reconstruct the committed action exactly once from event data alone. This PR confirms the current behavior and locks it in with a targeted regression test, plus documentation of the invariant. No contract logic changes are needed or made.
closes #1137
What was checked
The
Partial claimworkflow named two scenarios to confirm: aone-unit claim followed by remaining claim, and atransfer failing after authorization.Both were reviewed against
contracts/src/lib.rsand the backend indexer (backend/src/services/indexer.ts), which deserializesStreamClaimedby field name.claim()computes the payout, callstoken_client.transfer(contract, recipient, amount)at lib.rs:906, updatesstream.claimed_amount, persists state, and only then publishesStreamClaimedat lib.rs:916.StreamCompletedis published immediately after, only when the claim completes the stream.StreamClaimedcarriesamount(the recipient payout for this call) andclaimed_amount(the cumulative claimed balance after the call), so the event is already a complete, self-describing record of a single committed claim.The existing
#1138tests already cover the claim mechanics and per-event field values, and the#1136test covers recipient authority. None of them asserted the property the indexer actually depends on: that the event stream ALONE reconstructs the committed state exactly once.What changed
contracts/src/test.rs— addedtest_1137_events_reconstruct_partial_claim_state_exactly_once. It replays the emittedStreamClaimedevents the way the indexer does, without ever reading contract storage, across a one-unit claim, a partial claim, a failed payout, and the completing claim. It asserts:claimed_amountequals the running sum of theamountfields, and the balance advances monotonically, so no payout is missed or double-counted;StreamClaimedappears per committed claim;StreamCompletedis never treated as a payout (summing it alongside the claims would over-report the balance).contracts/src/lib.rs— expanded theStreamClaimedstruct doc and theclaim()ordering doc to state thatStreamClaimedis the authoritative partial-claim record and how a failed payout produces no event.contracts/CONTRACT_ABI.md— added a subsection documenting the partial-claim reconstruction invariant and pointing to the new and existing tests.Alternatives considered
claim()to emit an additional payout or remaining-balance field. Rejected: the existingamountplusclaimed_amountalready reconstruct payout and balance, and adding a field is unnecessary churn that the indexer does not currently consume.#1138already does that. The distinct acceptance criterion in [CONTRACT] Align events with Partial claim state #1137 is exactly-once reconstruction from events alone, which is what the new test encodes.get_streamstorage reads in the test. Rejected: the acceptance criterion is specifically that event data (not storage) lets the indexer reconstruct the action, so the test derives everything from the emitted events and only cross-checks against storage.Verification
cargo test --libon the contracts crate: the newtest_1137_...passes, along with the adjacent#1133,#1136, and#1138claim tests.Note for reviewers: the contracts test binary does not currently compile on
mainas checked out, independent of this change.test_1136_partial_claim_authority_is_checked_again_for_remainderandtest_1138_transfer_failure_after_authorization_rolls_backcallassert_eq!onVec<(Symbol, Val)>, andsoroban_sdk::Valdoes not implementPartialEq. That is pre-existing breakage outside the scope of #1137, so this PR leaves those lines untouched.