test(vault): claim when the balance is smaller than the tip - #14
Merged
Merged
Conversation
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.
Closes #10
Summary
Adds two tests to
contracts/rent_vault/src/test.rscovering the claim path when a vault's balance is at or below its tip — the state every underfunded vault ends in.claimalready guards this withVaultError::InsufficientBalance(207) whenvault.balance < vault.tip, checked after the keeper/timing verifications and before any mutation or transfer. This PR asserts that behavior explicitly rather than leaving it implied.What changed
test::claim_rejects_underfunded_vault— funds a vault with50against a100tip, performs real maintenance (extend_allafter a full interval), then claims. Asserts:InsufficientBalance(207, a2xxerror),50),last_claimis unchanged (the failed claim does not consume the interval),0tokens and the vault still holds50— it never pays out more than it holds.test::claim_at_exact_tip_balance— funds exactly the tip (100), the boundary case of the balance check, then claims. Asserts a full payout of100, a drained balance of0, the token leaves the vault, andlast_claimadvances to the payout ledger.Key design decisions
balance < tipcheck already runs beforebalance -= tip, so no underflow path exists (overflow-checksis on); the tests lock in that ordering.try_claim(...).err() == Some(Ok(VaultError::InsufficientBalance))) and the sameFixture/ledger-advance conventions as the rest of the module.last_claimbefore the attempt and asserts it is unchanged, which is the direct evidence that a failed claim cannot silently consume the interval.Acceptance criteria checklist
tip, performs real maintenance, and claims —claim_rejects_underfunded_vault.2xxerror —InsufficientBalance(207).50, unchanged.last_claimis asserted — unchanged after the failed claim.tip—claim_at_exact_tip_balance.Test output
cargo test --all(rent_vault suite):cargo fmt --all -- --check— clean.cargo clippy --all-targets -- -D warnings— clean.stellar contract build— complete (all three contracts build to wasm).Follow-ups
None in scope. A partial-payout alternative was considered and rejected: paying a pro-rata amount would violate the fixed
tipterms without a corresponding production change, so the existing explicitInsufficientBalancerejection is the behavior worth locking in.Security note
No new trust assumptions or money-movement code paths are introduced; the changes are test-only. The tests confirm a vault can never pay out more than it holds and that a rejected claim does not advance the payout clock.