Skip to content

fix: restore main to a compiling, fully testable state - #669

Merged
IbrahimIjai merged 9 commits into
SO4-Markets:mainfrom
EmmanuelOchaje:fix/restore-main-compilation
Aug 23, 2026
Merged

fix: restore main to a compiling, fully testable state#669
IbrahimIjai merged 9 commits into
SO4-Markets:mainfrom
EmmanuelOchaje:fix/restore-main-compilation

Conversation

@EmmanuelOchaje

Copy link
Copy Markdown

Summary

main has not compiled since 25 Jul 2026 (009cefb). This restores it to a compiling, fully testable state — mechanical fixes only, no behavioural or logic changes.

Class 1 — oracle wouldn't compile

Soroban caps contract function names at 32 characters. register_market_for_circuit_breaker (35 chars) exceeded that, and since most of the workspace depends on oracle, this single error stopped the entire build.

⚠️ Breaking ABI change: the function is renamed to register_market_for_breaker (27 chars). It's an uncalled, dead public entrypoint (kept per the issue's instructions — not removed, since that's a separate API decision), so nothing in this repo invokes it, but it is a public contract entrypoint and its name is part of the on-chain ABI. docs/auth-audit.md is regenerated (python3 scripts/gen_auth_audit.py) to reflect the new name and pick up other drift that had accumulated since the doc was last generated. If any off-chain caller (frontend, indexer, keeper script) invokes this function by name, it needs updating.

Class 2 — test-only compilation errors, once Class 1 cleared

market_token::initialize gained two parameters (long_token, short_token) without updating its ~35 #[cfg(test)] call sites across the workspace. Fixed each one — mostly reordering token creation to happen before market-token registration, since the new params need the token addresses up front.

Cargo halts at the first failing crate, so fixing that cascaded into a long tail of further test-only breakage that had been silently accumulating (570 test functions were added between 18 Jun and 28 Jul, none of which had run since). Iterated until cargo check --workspace --all-targets was clean:

  • Two documented oracle test failures (soroban-sdk 25.3.1 event-testing API: Events::all() renamed, Val: From<Symbol> no longer holds — now uses topics.contains(&symbol_short!(..).to_val()) and asserts the emitted event via soroban_sdk::vec![...] equality instead of decoding it back out).
  • Stale CreateOrderParams/PositionProps struct literals (missing/extra expiry_ledger field) left behind by an earlier field addition.
  • Several call sites left behind by unrelated signature changes: reader::initialize, fee_handler::initialize, liquidation_handler::liquidate_position, adl_handler::execute_adl, fee_handler::claim_fees, order_cleanup::cancel_expired_order, data_store::set_u128's key type, order_handler::create_order's now-explicit caller argument.
  • Missing soroban_sdk::testutils::{Ledger, Events, BytesN} trait imports for methods that had always needed them but were never reached because compilation failed earlier.

Clippy

cargo clippy --workspace --all-targets -- -D warnings was not passing before this PR either (400+ pre-existing warnings, unrelated to the two classes above — mostly literal digit-grouping style, a few genuinely dead test-fixture fields, deprecated SDK renames). Since it's in this issue's acceptance criteria, fixed all of it:

  • 183 inconsistent digit-grouping literals reformatted (e.g. 1_000_000010_000_000) — same value, different underscore placement.
  • Deprecated SDK renames with identical behaviour: env.budget()env.cost_estimate().budget(), register_contract(None, X)register(X, ()), deployer.deploy(hash)deploy_v2(hash, ()).
  • #[allow(clippy::too_many_arguments)] added to the dozen functions already at 8–9 params, matching the existing precedent in libs/swap_utils and libs/pricing_utils.
  • #[allow(dead_code)] on test-fixture World/TestWorld structs whose fields aren't all read by every test in the file — matches this codebase's existing precedent for the same lint on contractclient trait stubs.
  • Two manual if/else zero-checks before division rewritten as checked_div (same behaviour).
  • A stray duplicate doc-comment block in reader.rs removed, and one helper function moved above its #[cfg(test)] mod tests block (clippy::items_after_test_module) — pure relocation/dedup, same code.
  • One deliberate deviation, called out explicitly: ~50 call sites still use the deprecated env.events().publish((topic,), data) API instead of the newer #[contractevent] macro (which roughly half the codebase's events already use). Migrating the rest changes the on-chain topic/data encoding for each event — a real ABI-facing change, not a lint fix, and out of scope for a compilation-restoration PR per the issue's own "no behavioural changes" instruction. Suppressed with #![allow(deprecated)] at the crate level (with an explanatory comment), matching this repo's own existing precedent for the same lint in test_faucet/test_token.

Test results

cargo test --workspace --no-fail-fast:

528 passed; 37 failed; 5 ignored  (570 total)

None of the 37 are new — they were unreachable before this PR (the crate wouldn't compile), so there was no way to know whether they were live bugs or untested. Per the issue's scope, no assertions were changed to force a green suite. Full breakdown, grouped by crate/root-cause cluster, is tracked in #668.

Verification

  • cargo check --workspace exits 0
  • cargo clippy --workspace --all-targets -- -D warnings exits 0
  • cargo test --workspace compiles and runs to completion (528 passed / 37 failed / 5 ignored — see Triage the 37 pre-existing test failures uncovered by #529 #668)
  • stellar contract build succeeds for all 23 contracts in CONTRACTS (mx/common.mk)
  • docs/auth-audit.md regenerated and in sync (python3 scripts/gen_auth_audit.py --check)

Closes #529

EmmanuelOchaje added 9 commits August 22, 2026 19:42
- Rename oracle::register_market_for_circuit_breaker to
  register_market_for_breaker (35 chars exceeded Soroban's 32-char
  contract function name limit). Regenerated docs/auth-audit.md.
- Update all market_token::initialize test call sites for the new
  long_token/short_token parameters, reordering token creation before
  market token registration where needed.
- Fix cascading test-only compilation errors surfaced once the above
  compiled: stale CreateOrderParams/PositionProps field lists, oracle
  event-testing API (soroban-sdk 25.3.1), missing Ledger/Events trait
  imports, and several call sites left behind by unrelated signature
  changes (reader::initialize, fee_handler::initialize,
  liquidation_handler::liquidate_position, adl_handler::execute_adl,
  fee_handler::claim_fees, order_cleanup::cancel_expired_order,
  data_store::set_u128 key type).
Restored one import (max_pnl_factor_for_adl_key) that clippy --fix
incorrectly removed as unused — it's only referenced from the
#[cfg(test)] module, which the fix pass analyzed separately from the
lib target.
Mechanical literal reformatting only (e.g. 1_000_0000 -> 10_000_000);
no numeric values changed.
env.budget() -> env.cost_estimate().budget(), register_contract() ->
register(), deployer.deploy() -> deploy_v2(wasm_hash, ()). All
same-behavior renames per soroban-sdk 25.3.1 deprecation notices.
…ent lints

- Add #[allow(clippy::too_many_arguments)] to functions already at 8-9
  params, matching the existing precedent in libs/swap_utils and
  libs/pricing_utils.
- Rewrite two manual if/else zero-checks before division as
  checked_div (data_store::record_keeper_execution, funding_rate.rs
  test helper) — same behavior, clippy-preferred idiom.
- Remove a stray duplicate doc-comment block in reader.rs left behind
  by an earlier edit; its real function (get_protocol_stats) already
  has its own doc a few lines down.
World/TestWorld structs commonly hold addresses (role_store, vaults)
that individual tests don't read directly but that keep the deployed
contracts alive for the call graph under test. Matches this file's
own #[allow(dead_code)] precedent already used on contractclient
trait declarations.
- Deduplicate a repeated Ledger trait import in order_handler's test
  module (two use statements brought in the same trait).
- Move adl_handler's max_pnl_factor_for_adl_key import into its
  #[cfg(test)] module — it's only used there, so clippy's --lib pass
  (which excludes cfg(test)) correctly flagged it unused at crate
  scope; the earlier crate-level fix for this kept recurring across
  fix passes for that reason.
- Add the missing #[allow(dead_code)] to reader's IMarketToken client
  trait, matching every sibling trait in the same file.
- Move adl_handler's load_market_props helper above its test module
  (clippy::items_after_test_module) — a pure relocation, same body.
- Silence dead_code on zero_amount_validation.rs's World struct and
  an unused bench constant, consistent with the other test fixtures.
Roughly half this codebase's events already use the newer
#[contractevent] macro (role_store, fee_handler, data_store,
referral_storage, insurance_fund_router, order_cleanup, ...); the
rest still call the deprecated env.events().publish((topic,), data)
directly (market_token, oracle, deposit/withdrawal/order/liquidation/
adl handlers, exchange_router, market_factory, order_cleanup helper
libs). Migrating the remainder to #[contractevent] changes the
on-chain topic/data encoding for each event — a real ABI-facing
change that belongs in its own reviewed PR, not folded into a
compilation-restoration fix. Suppressing the warning at the crate
level (with an explanatory comment) matches this repo's own existing
precedent for the deprecated lint in test_faucet/test_token.
@IbrahimIjai
IbrahimIjai merged commit 8c6d674 into SO4-Markets:main Aug 23, 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

Development

Successfully merging this pull request may close these issues.

Restore main to a compiling, fully testable state

2 participants