Skip to content

reader::get_claimable_funding_amount has zero test coverage #598

Description

@abayomicornelius

Problem

reader::get_claimable_funding_amount (contracts/reader/src/lib.rs:536-586) has zero test coverage anywhere in the repository:

grep -rn "get_claimable_funding_amount" --include="*.rs" . | grep -v reader/src/lib.rs
# no output

The function computes claimable funding for both long and short collateral token sides by diffing the position's stored long_claim_fnd_per_size/short_claim_fnd_per_size trackers against the latest funding_amount_per_size_key value, scaling by mul_div_wide, and then subtracting the position's own funding_fee_amount (from get_position_fees) from whichever side matches the position's actual collateral token. This is genuinely intricate arithmetic — two independent per-token computations merged with a conditional subtraction — none of which is exercised by any test.

Why it matters

This is the query a UI would call to show a trader how much funding they can claim. A sign error in the claimable_per_size subtraction, or applying the funding_fee_amount deduction to the wrong side (long vs short) when position.collateral_token doesn't match either token exactly, would silently misreport claimable funding with no test to catch it.

Suggested fix

Add a test with known funding accrual on both sides of a market, call get_claimable_funding_amount for both a long-collateral and a short-collateral position, and assert the returned FundingAmountResult matches independently-computed expected values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions