Skip to content

test(oracle): add missing retry and price bounds test coverage#370

Merged
dev-jodee merged 8 commits intosolana-foundation:release/2.2.0from
raushan728:test/oracle-retry-coverage
Mar 6, 2026
Merged

test(oracle): add missing retry and price bounds test coverage#370
dev-jodee merged 8 commits intosolana-foundation:release/2.2.0from
raushan728:test/oracle-retry-coverage

Conversation

@raushan728
Copy link
Contributor

@raushan728 raushan728 commented Mar 6, 2026

RetryingPriceOracle and JupiterPriceOracle had several untested code paths
— adds 7 tests covering retry exhaustion, partial retry recovery, empty
mint short-circuit, missing mint error, HTTP 429 handling, and price
bounds validation (max/min).


Open with Devin

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR adds 7 new tests across oracle.rs and jupiter.rs to cover previously untested code paths in RetryingPriceOracle and JupiterPriceOracle, including retry exhaustion, partial-retry recovery, empty-mint short-circuiting, missing-mint result handling, HTTP 429 rate-limit responses, and price-bounds validation (max/min).

Key observations:

  • All test assertions align with the actual production error messages and return types — no mismatch between test expectations and validate_price_data/retry-loop semantics.
  • The mock responses for the bounds tests correctly include SOL price data (required by fetch_prices_from_url before token validation proceeds).
  • test_price_oracle_retry_then_succeed relies on mutable state (call_count: u32) inside a move/FnMut closure to simulate a first-call failure — this is valid Rust but could be made more readable using mockall's built-in call sequencing.
  • test_get_token_price_not_found sets .times(1) because the retry loop only retries on Err; an Ok(HashMap::new()) terminates the loop immediately. This is correct but benefits from an explanatory comment (see inline suggestion).
  • Minor style issue: blank lines are missing between consecutive #[tokio::test] blocks in both files.

Confidence Score: 5/5

  • Test-only PR with no production code changes; safe to merge after addressing the minor style suggestions.
  • All changes are confined to #[cfg(test)] modules. The new tests correctly model production behaviour, mock expectations match actual call counts, and error-message assertions align with the existing validate_price_data and retry-loop implementations. The only findings are stylistic (closure counter clarity, missing explanatory comment, missing blank lines between tests).
  • No files require special attention — both files only modify #[cfg(test)] blocks.

Important Files Changed

Filename Overview
crates/lib/src/oracle/oracle.rs Adds 4 tests for RetryingPriceOracle: empty-mint short-circuit, all-retries-fail, partial-retry-recovery, and missing-mint in result. Logic and expectations are correct, though the retry-then-succeed test relies on FnMut closure state mutation that is valid but worth noting.
crates/lib/src/oracle/jupiter.rs Adds 3 tests for JupiterPriceOracle: HTTP 429 rate-limit, price-exceeds-max-bounds, price-below-min-bounds. Assertions are correct against production error messages; mock responses include required SOL price data. One stylistic inconsistency: no blank line between new test functions.

Sequence Diagram

sequenceDiagram
    participant T as Test
    participant R as RetryingPriceOracle
    participant O as PriceOracle (Mock/Jupiter)
    participant H as HTTP Server (mockito)

    Note over T,H: empty_mints — short-circuit
    T->>R: get_token_prices([])
    R-->>T: Ok({})

    Note over T,H: retries_all_fail — 3 attempts
    T->>R: get_token_prices([mint])
    R->>O: get_prices attempt 1
    O-->>R: Err(RpcError)
    R->>O: get_prices attempt 2
    O-->>R: Err(RpcError)
    R->>O: get_prices attempt 3
    O-->>R: Err(RpcError)
    R-->>T: Err(RpcError)

    Note over T,H: retry_then_succeed — 2 attempts
    T->>R: get_token_price(mint)
    R->>O: get_prices attempt 1
    O-->>R: Err(RpcError)
    R->>O: get_prices attempt 2
    O-->>R: Ok({mint: price})
    R-->>T: Ok(TokenPrice)

    Note over T,H: not_found — Ok but key missing
    T->>R: get_token_price(missing)
    R->>O: get_prices (1 call only)
    O-->>R: Ok({}) no error no retry
    R-->>T: Err(InternalServerError)

    Note over T,H: rate_limit_429
    T->>O: get_prices([mint])
    O->>H: GET /price/v3
    H-->>O: 429
    O-->>T: Err(RateLimitExceeded)

    Note over T,H: price_bounds validation
    T->>O: get_prices([out_of_bounds_mint])
    O->>H: GET /price/v3
    H-->>O: 200 with extreme price
    O->>O: validate SOL price — pass
    O->>O: validate token price — fail
    O-->>T: Err(RpcError bounds message)
Loading

Last reviewed commit: 28382cd

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

✅ Fork external live tests passed.

fork-external-live-pass:dff49cbf2337f92ba1aaa58668801ede98816bac
run: https://github.com/solana-foundation/kora/actions/runs/22765922104

@dev-jodee dev-jodee merged commit 041c6b0 into solana-foundation:release/2.2.0 Mar 6, 2026
11 of 12 checks passed
@raushan728 raushan728 deleted the test/oracle-retry-coverage branch March 7, 2026 05:38
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.

2 participants