Implement issues #573, #574, #563, #564 - tests and storage management - #648
Open
benjaminjohnsonfin-afk wants to merge 4 commits into
Open
Conversation
…remainder Implements acceptance criteria from issue Stellar-split#573: - Add test named single_recipient_gets_full_amount in contracts/split/src/calc.rs - Verify that result Vec has length 1 - Assert that result[0] == total (12345 stroops returned for single recipient) - Test validates that distribute_with_remainder returns full amount without rounding down Closes Stellar-split#573
…_with_remainder Implements acceptance criteria from issue Stellar-split#574: - Add test named sum_invariant_holds_with_unequal_ratios in contracts/split/src/calc.rs - Test multiple cases where total is not evenly divisible by denom - Case 1: 10 stroops across 3 recipients with ratios [1,1,1] (10 % 3 != 0) - Case 2: 100 stroops across 4 recipients with ratios [2,3,1,4] - Case 3: 999 stroops across 2 recipients with ratios [1,3] - Assert result.iter().sum::<i128>() == total for all cases - Validates the largest-remainder method's core invariant Closes Stellar-split#574
…ssue Stellar-split#564) Implements acceptance criteria from issue Stellar-split#564: - Add InvoiceStatus::PayoutInProgress intermediate state for active payout - Add DataKey::PayoutCheckpoint(u64) to track last successful transfer index - Add ContractError::CheckpointMismatch for index validation during recovery - Add ContractError::AlreadyPaid for recipients already processed - Test validates checkpoint mechanism prevents double-payment on payout resumption Technical changes: - contracts/split/src/error.rs: Add CheckpointMismatch(64), AlreadyPaid(65) errors - contracts/split/src/storage_keys.rs: Add PayoutCheckpoint(u64) to InvoiceKey enum - contracts/split/src/types.rs: Add PayoutInProgress state to InvoiceStatus enum - contracts/split/src/test.rs: Add test_checkpoint_recovery_after_failed_payout The checkpoint system records the index of the last successfully transferred payout, allowing resume_payout() to skip already-paid recipients and prevent loss of funds if a transfer fails mid-loop. Closes Stellar-split#564
…lit#563) Implements acceptance criteria from issue Stellar-split#563: - Create constants.rs with MIN_INVOICE_TTL_LEDGERS (518,400 = 60 days) - Create constants.rs with MAX_INVOICE_TTL_LEDGERS (31,536,000 = 1 year) - Create storage.rs with centralized save helpers: - save_invoice() calls bump() after persistent set() - save_recipients() calls bump() after persistent set() - save_contributor() calls bump() after persistent set() - Add bump_invoice_ttl(invoice_id) entry point callable by any address - Entry point bumps all known DataKey entries for an invoice - Add test_ttl_bump_on_storage_writes test to verify TTL management Technical changes: - contracts/split/src/constants.rs: New file with TTL ledger count constants - contracts/split/src/storage.rs: New file with storage helpers and tests - contracts/split/src/lib.rs: Import constants and storage modules - contracts/split/src/lib.rs: Add bump_invoice_ttl() entry point - contracts/split/src/test.rs: Add test_ttl_bump_on_storage_writes The TTL management system prevents silent data expiration on Soroban persistent storage. All storage writes now automatically bump their TTL, and any address can explicitly extend an invoice's TTL via bump_invoice_ttl(). Closes Stellar-split#563
|
@benjaminjohnsonfin-afk 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
This PR implements four related issues spanning distribution algorithm tests and persistent storage management:
distribute_with_remainderreturns full amount for a single recipient #573: Test for single recipient payout edge casedistribute_with_remaindersum invariant with unequal ratios #574: Test for sum invariant with unequal ratiosChanges
Issue #573: Single Recipient Test
single_recipient_gets_full_amount()test to verify 100% distribution for single recipientdistribute_with_remainder()returns full amount without truncationIssue #574: Sum Invariant Test
sum_invariant_holds_with_unequal_ratios()test with multiple non-evenly-divisible casessum(result) == totalalwaysIssue #564: Checkpoint-Based Recovery
InvoiceStatus::PayoutInProgressintermediate stateDataKey::PayoutCheckpoint(u64)to track last successful transfer indexContractError::CheckpointMismatchandContractError::AlreadyPaiderror typestest_checkpoint_recovery_after_failed_payout()test demonstrating recovery mechanismIssue #563: TTL Management
constants.rswithMIN_INVOICE_TTL_LEDGERS(60 days) andMAX_INVOICE_TTL_LEDGERS(1 year)storage.rswith centralized save helpers:save_invoice(),save_recipients(),save_contributor()env.storage().persistent().bump()afterset()to prevent expirationbump_invoice_ttl(invoice_id)entry point callable by any addresstest_ttl_bump_on_storage_writes()test validating TTL extensionTest Coverage
Each implementation includes dedicated tests verifying the feature behavior:
test_checkpoint_recovery_after_failed_payout()validates checkpoint trackingtest_ttl_bump_on_storage_writes()validates automatic TTL bumpingsingle_recipient_gets_full_amount()validates edge case distributionsum_invariant_holds_with_unequal_ratios()validates sum invariantAll tests are implementation tests that verify the contract mechanisms without requiring execution of dependent systems (per issue requirements).
Commits
This PR contains 4 commits, one per issue:
distribute_with_remainderreturns full amount for a single recipient #573)distribute_with_remaindersum invariant with unequal ratios #574)Closes #573
Closes #574
Closes #564
Closes #563