Skip to content

Commit 0495082

Browse files
authored
test(collateral): add edge-case unit suite for CollateralManager (#348)
Covers all five boundary cases from issue #260: - collateral_value == 0 → health factor is INFINITE_HEALTH (no debt) - borrowed_value == 0 → health factor is INFINITE_HEALTH - collateral_factor == 1 → calculate_max_leverage raises ValueError - liquidation_threshold == 0 → calculate_liquidation_price raises ValueError - max_withdraw > collateral_value → result clamped to Decimal(0) Also adds: - Negative input guard tests for all calculation methods - evaluate_position integration smoke tests - XLM_ASSET_ID / USDC_ASSET_ID / ETH_ASSET_ID / IS_MAINNET constants in contract_tools/constants.py (required by CollateralManager) 34 tests added, all passing. Closes #260 Co-authored-by: Spaully <Spaully@users.noreply.github.com>
1 parent 976aad3 commit 0495082

2 files changed

Lines changed: 455 additions & 0 deletions

File tree

quantara/web_app/contract_tools/constants.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@
3838
# Testnet USDC issuer – replace for mainnet
3939
)
4040

41+
# ------------------------------------------------------------------ #
42+
# Network detection
43+
# ------------------------------------------------------------------ #
44+
45+
#: True when the node URL points at the Stellar mainnet, False for testnet /
46+
#: futurenet. Used by CollateralManager to enable assets that are only safe
47+
#: to use on mainnet (e.g. ETH until testnet liquidity is confirmed).
48+
IS_MAINNET: bool = os.getenv("STELLAR_NETWORK", "testnet").lower() == "mainnet"
49+
50+
# ------------------------------------------------------------------ #
51+
# Canonical Stellar asset identifiers for CollateralManager
52+
# ------------------------------------------------------------------ #
53+
54+
#: XLM is always the Stellar native asset.
55+
XLM_ASSET_ID: str = "native"
56+
57+
#: USDC canonical identifier: "USDC:<issuer>" or just USDC_ASSET_CODE for
58+
#: environments where the issuer is implicit.
59+
USDC_ASSET_ID: str = f"{USDC_ASSET_CODE}:{USDC_ASSET_ISSUER}"
60+
61+
#: ETH bridged token on Stellar (testnet stub; override via ETH_ASSET_ID env).
62+
ETH_ASSET_ID: str = os.getenv(
63+
"ETH_ASSET_ID",
64+
"ETH:GBDEVU63Y6NTHJQQZIKVTC23NWLQVP3WJ2RI2OTSJTNYOIGICST6DUXR",
65+
)
66+
4167

4268
@dataclass(frozen=True)
4369
class TokenConfig:

0 commit comments

Comments
 (0)