Skip to content

fix(deposit_handler): InvalidMarket for unregistered markets; test coverage for allowance expiry and auth-audit generator - #502

Merged
abayomicornelius merged 1 commit into
SO4-Markets:mainfrom
leojay-net:fix/issues-362-371-356
Jul 25, 2026
Merged

fix(deposit_handler): InvalidMarket for unregistered markets; test coverage for allowance expiry and auth-audit generator#502
abayomicornelius merged 1 commit into
SO4-Markets:mainfrom
leojay-net:fix/issues-362-371-356

Conversation

@leojay-net

Copy link
Copy Markdown
Contributor

Summary

  • deposit_handler: load_market_props raises DepositNotFound for an unregistered market during create_deposit #371 (deposit_handler misclassifies unregistered market as DepositNotFound): load_market_props panicked with Error::DepositNotFound when a market's index/long/short token keys were absent from data_store — but this runs during create_deposit before any deposit exists, so DepositNotFound (which means "no such deposit id" everywhere else it's used) was the wrong error. 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 a regression test asserting the specific error code.
  • market_token: allowance-expiration branches in allowance() and spend_allowance are untested #362 (market_token allowance-expiration branches untested): no test ever advanced env.ledger() past an approval's expiration_ledger before reading allowance() or spending it, so the expiry branches in allowance() and spend_allowance were never exercised. Added three tests that advance the ledger sequence past expiration and assert allowance() returns 0, and that transfer_from/burn_from both revert with AllowanceExpired.
  • docs/auth-audit.md certifies data_store access controls that do not exist / describes nonexistent functions #356 (auth-audit.md certified nonexistent functions): the doc previously listed set_account_principal_delta / get_account_principal_delta, neither of which exist in data_store, and mis-stated get_position_manager as an auth-checked ✅ PASS when 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 + the Auth Audit Check CI job), but that generator script had no test of its own. Added scripts/test_gen_auth_audit.py, which fabricates a source/doc pair containing both a phantom entry and a missing entry and asserts validate_against_source() catches both — plus a direct check that get_position_manager classifies as read-only, not PASS. Wired it into .github/workflows/auth-audit.yml so it runs on every relevant PR.

Verification

  • cargo test -p deposit-handler — 34 passed
  • cargo test -p market-token — 15 passed
  • python3 scripts/test_gen_auth_audit.py -v — 4 passed
  • python3 scripts/gen_auth_audit.py --check — in sync

Note: as with #501, cargo fmt --all -- --check and the WASM Size Budget build currently fail on main itself for pre-existing, unrelated reasons (repo-wide formatting drift, a wasm32-unknown-unknown/soroban-sdk toolchain incompatibility, and — independently discovered while verifying this PR — oracle::register_market_for_circuit_breaker exceeding Soroban's 32-character contract-function-name limit, which also breaks cargo clippy --workspace and a plain cargo check --workspace today via the tests integration crate's dependency on oracle's testutils feature). None of these are touched or worsened by this change.

Closes #371
Closes #362
Closes #356

…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
@drips-wave

drips-wave Bot commented Jul 25, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@abayomicornelius
abayomicornelius merged commit 164fbe3 into SO4-Markets:main Jul 25, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants