fix(deposit_handler): InvalidMarket for unregistered markets; test coverage for allowance expiry and auth-audit generator - #502
Merged
abayomicornelius merged 1 commit intoJul 25, 2026
Conversation
…verage for SO4-Markets#362, SO4-Markets#356 Issue SO4-Markets#371: deposit_handler::load_market_props panicked with Error::DepositNotFound when a market's index/long/short token keys were absent from data_store during create_deposit — before any deposit exists. DepositNotFound is reused elsewhere to mean "no such deposit id", so a caller passing an unregistered/malformed market got a misleading error code. withdrawal_handler already has the correct pattern. Added Error::InvalidMarket to deposit_handler and switched load_market_props to use it, reserving DepositNotFound for actual deposit-key lookups. Added create_deposit_unregistered_market_rejected_with_invalid_market to lock in the distinction. Issue SO4-Markets#362: market_token had no test exercising the allowance-expiration branches in allowance() and spend_allowance — every existing test spends an approval within the same ledger it was granted, so the expiry check was never reached. Added three tests that advance env.ledger().set_sequence_number() past an approval's expiration_ledger and assert: allowance() returns 0, transfer_from panics with AllowanceExpired, and burn_from panics with AllowanceExpired. Issue SO4-Markets#356: docs/auth-audit.md previously certified two functions (set_account_principal_delta / get_account_principal_delta) that don't exist in data_store, and mis-stated get_position_manager as an auth-checked PASS when it's an unrestricted public read. This was already fixed by regenerating the doc from source (scripts/gen_auth_audit.py, merged separately), but the generator itself had no test of its own. Added scripts/test_gen_auth_audit.py, which fabricates a source/doc pair with both a phantom entry and a missing entry and asserts validate_against_source() catches both, plus a check that get_position_manager classifies as read-only rather than PASS. Wired the test into .github/workflows/auth-audit.yml so it runs on every PR that touches contract source or the audit tooling. Verified: cargo test -p deposit-handler (34 passed), cargo test -p market-token (15 passed), python3 scripts/test_gen_auth_audit.py (4 passed), python3 scripts/gen_auth_audit.py --check (in sync). Closes SO4-Markets#371 Closes SO4-Markets#362 Closes SO4-Markets#356
|
@leojay-net 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
load_market_propspanicked withError::DepositNotFoundwhen a market's index/long/short token keys were absent fromdata_store— but this runs duringcreate_depositbefore any deposit exists, soDepositNotFound(which means "no such deposit id" everywhere else it's used) was the wrong error.withdrawal_handleralready has the correct pattern. AddedError::InvalidMarkettodeposit_handlerand switchedload_market_propsto use it, reservingDepositNotFoundfor actual deposit-key lookups. Added a regression test asserting the specific error code.env.ledger()past an approval'sexpiration_ledgerbefore readingallowance()or spending it, so the expiry branches inallowance()andspend_allowancewere never exercised. Added three tests that advance the ledger sequence past expiration and assertallowance()returns0, and thattransfer_from/burn_fromboth revert withAllowanceExpired.set_account_principal_delta/get_account_principal_delta, neither of which exist indata_store, and mis-statedget_position_manageras an auth-checked✅ PASSwhen it's actually an unrestricted public read. This was already fixed by regenerating the doc from source in a separate merged PR (scripts/gen_auth_audit.py+ theAuth Audit CheckCI job), but that generator script had no test of its own. Addedscripts/test_gen_auth_audit.py, which fabricates a source/doc pair containing both a phantom entry and a missing entry and assertsvalidate_against_source()catches both — plus a direct check thatget_position_managerclassifies as read-only, not PASS. Wired it into.github/workflows/auth-audit.ymlso it runs on every relevant PR.Verification
cargo test -p deposit-handler— 34 passedcargo test -p market-token— 15 passedpython3 scripts/test_gen_auth_audit.py -v— 4 passedpython3 scripts/gen_auth_audit.py --check— in syncNote: as with #501,
cargo fmt --all -- --checkand the WASM Size Budget build currently fail onmainitself for pre-existing, unrelated reasons (repo-wide formatting drift, awasm32-unknown-unknown/soroban-sdk toolchain incompatibility, and — independently discovered while verifying this PR —oracle::register_market_for_circuit_breakerexceeding Soroban's 32-character contract-function-name limit, which also breakscargo clippy --workspaceand a plaincargo check --workspacetoday via thetestsintegration crate's dependency onoracle'stestutilsfeature). None of these are touched or worsened by this change.Closes #371
Closes #362
Closes #356