test: cover withdraw() dust reconciliation at stream end (#328) - #383
Merged
Chuks-coderr merged 1 commit intoJul 30, 2026
Merged
Conversation
…ream#328) Covers the final withdrawal at/after end_time for a deposit/duration combination where flow_rate = deposit / duration truncates and leaves rounding dust. Verifies the recipient receives the streamed share, the dust is refunded to the sender, the contract's balance for that stream reaches zero, and that claiming long after end_time settles identically to claiming right at end_time + 1.
|
@Frezechi9999 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! 🚀 |
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
Closes #328.
At stream end,
withdraw()'s claimable amount is derived fromflow_rate = deposit / duration_seconds(integer division), which can truncate and leave a few stroops of "dust" that don't divide evenly. This adds explicit test coverage for that final reconciliation.What was verified
Reading
withdraw()incontracts/stream/src/lib.rs(thestream_endedbranch, ~line 1776 onmain), the contract's actual design is:flow_rate * duration(the streamed amount).dust = deposit - flow_rate * durationis refunded to the sender, in the same call, right after the recipient's transfer.recipient_amount + dust == deposit, and the contract's token balance for that stream drops to zero — no value is permanently stranded.Note this is a deliberate difference from the issue's literal wording ("recipient receives 100% of the deposit"): the contract returns unclaimed dust to the sender (the depositor), not the recipient. The acceptance criteria that matter operationally — no dust left in the contract, and a stream/duration/rate combination that produces fractional dust — are what these tests pin down.
Tests added (
contracts/stream/src/test.rs)test_withdraw_at_end_time_reconciles_full_deposit_with_dust— creates a stream withdeposit = 100_003,duration = 1000(flow_rate = 100,dust = 3), withdraws atend_time + 1, and asserts:test_withdraw_long_after_end_time_matches_withdraw_at_end_time— same setup, but withdraws atend_time + 1000instead ofend_time + 1, and asserts an identical outcome (elapsed time is capped atend_time, so claiming later doesn't change the settled amounts).Notes / caveats
cargo test/ try to get CI green. Separately (and unrelated to this PR's diff),maincurrently has pre-existing compile errors incontracts/stream/src/errors.rs(duplicateStreamErrorvariant names from what looks like a bad merge) andlib.rs(batch_create_stream's struct literal listsmilestonestwice) — neither touched by this change, but worth a follow-up fix so the crate builds again.