feat(contracts): implement subscription contract invariant testing suite#292
Closed
morelucks wants to merge 3 commits intoSmartdevs17:mainfrom
Closed
feat(contracts): implement subscription contract invariant testing suite#292morelucks wants to merge 3 commits intoSmartdevs17:mainfrom
morelucks wants to merge 3 commits intoSmartdevs17:mainfrom
Conversation
Closes Smartdevs17#221 - Define 10 key invariants covering plan/subscription count monotonicity, total_paid conservation, plan subscriber count accuracy, paused_at consistency, refund amount bounds, total_collected non-negativity, and user subscription index consistency - Implement deterministic scenario tests for all lifecycle transitions: basic flow, multi-plan/subscriber, cancel, pause/resume, auto-resume, refund approve/reject, subscription transfer, plan deactivation, multiple charges, all billing intervals, and authorization rules - Add property-based fuzz tests using proptest (50 cases each): random action sequences, plan count equals create_plan calls, subscription count equals subscribe calls, total_paid equals price x charge_count - Add state-machine invariant tests (30 cases) covering the full lifecycle with weighted random actions including pause, resume, cancel, refund, and time advancement - Register real Stellar asset token contracts in ContractHandler so charge_subscription token transfers succeed in tests - Add [[test]] entries in Cargo.toml for invariants and integration_soroban - Add .github/workflows/invariant-tests.yml CI job running invariant tests on every contracts/ change, with an extended 1000-case fuzz run on pushes to main/dev - Update contracts/.gitignore to exclude generated test_snapshots/ and *.proptest-regressions files
Contributor
Author
|
@Smartdevs17 kindly review |
|
@morelucks 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
Implements a comprehensive invariant testing suite for the SubTrackr subscription contract, addressing #221.
What's included
Invariants defined (10 total)
get_plan_count()equals ghost counter and never decreasesget_subscription_count()equals ghost counter and never decreasestotal_paid= sum of charges − approved refundsplan.subscriber_countmatches ghost count of active/paused subsstatus == Pausedthenpaused_at > 0andpause_duration > 0refund_requested_amount <= total_paidfor every subscriptiontotal_collectedis always >= 0Test layers (19 tests total)
Infrastructure
ContractHandlerextended with real Stellar asset token contracts socharge_subscriptiontoken transfers work correctly in tests[[test]]entries added toCargo.tomlfor proper test binary registrationcontracts/.gitignoreupdated to exclude generatedtest_snapshots/and*.proptest-regressionsfiles.github/workflows/invariant-tests.ymlruns invariant tests on everycontracts/change, with an extended 1000-case fuzz run on pushes tomain/devTest results
Files changed
contracts/tests/invariants.rs— test entry point (all 3 layers)contracts/tests/invariants/mod.rs— invariant definitions andassert_invariants()contracts/tests/invariants/handler.rs—ContractHandlerghost-state wrappercontracts/Cargo.toml—[[test]]registrationscontracts/.gitignore— exclude generated files.github/workflows/invariant-tests.yml— CI workflowCloses #221