test: add test coverage for subscription registry - #566
Merged
Naomi-Gift merged 1 commit intoAug 20, 2026
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.
🚀 Feature: Comprehensive Unit Test Coverage for Subscription Registry
📝 Description
This Pull Request addresses Issue #493 by introducing a robust suite of inline unit tests directly within the
SubscriptionRegistrymodule (dongle-smartcontract/src/subscription_registry.rs).Closes #493
Previously, test coverage for the subscription logic was primarily driven by high-level integration tests (
tests/subscriptions.rs). While valuable, those tests evaluated the contract's outermost layer (the Client Wrapper) and left the direct mechanics ofSubscriptionRegistryuntested in isolation.This PR bridges that gap by directly validating the core mechanisms governing project follows, unfollows, and pagination limits at the struct level, bringing deep confidence to the
SubscriptionRegistryimplementation. Every logical pathway, including state transitions and authorization edge cases within the Soroban VM, is now explicitly tested.🔍 Detailed Changes & Additions
1. State Mutation & Integrity Tests
test_follow_project: Validates the happy path of a user successfully following a project. Ensures that:follower_countcorrectly increments.is_followingboolean check returnstrue.PROJECT_FOLLOWED) would be triggered implicitly by maintaining the expected state.test_unfollow_project: Validates the happy path of a user removing a follow. Ensures that:follower_countsafely decrements.is_followingboolean correctly reflects the unfollow asfalse.2. Error Boundary & Edge Case Tests
Ensures the contract safely halts execution and returns deterministic errors when bad state changes are attempted.
test_duplicate_follow_error: Asserts that a user attempting to follow a project they are already following triggers a gracefulContractError::AlreadyFollowinginstead of appending duplicate addresses to persistent storage.test_unfollow_not_following_error: Asserts that an attempt to unfollow a project that the user has never followed cleanly triggersContractError::NotFollowing, preventing underflows or missing index panics.3. Pagination & Limit Boundaries
Because smart contracts must minimize execution cost (gas/compute) on state iteration, pagination is mission-critical.
test_get_project_followers_pagination: Mocks 5 distinct users following a single project and tests retrieving them via theget_project_followersmethod in discrete chunks. Validates chunk sizing (limit=2), boundary conditions on the final page (length=1), and out-of-bounds start indices returning empty pages.test_get_user_subscriptions_pagination: Mocks a single user subscribing to 4 distinct projects. Verifies thatget_user_subscriptionscorrectly slices the array of project IDs and bounds-checks the maximum items returned against the internalMAX_PAGE_LIMIT.4. Soroban Execution Context Fidelity
A major technical challenge addressed in this PR is the
HostError: Error(Auth, ExistingValue)panic that arises frommock_all_auths()reusing the same invocation frame for multiple state mutations in Soroban.env.as_contract(&client.address, || { ... })closures. This accurately mimics the distinct boundaries of external contract invocations, ensuring perfectly isolated authentication frames and preventing synthetic test crashes.🔗 Related Issues
🧪 Testing and Verification
cargo test -p dongle-contracton the workspace.tests/subscriptions.rs) pass flawlessly alongside the newly introduced inline unit tests.cargo fmt) and clippy requirements.💡 Reviewer Notes
When reviewing, pay special attention to the
env.as_contractboundaries within the newmod tests. These scopes are required becauseSubscriptionRegistrymethods act directly onenv.storage(), which requires an active contract host ID context—something the native test environment lacks unless explicitly supplied via closure execution.