mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-06 04:38:22 +00:00
Merge pull request #138 from Routstr/132-fix-v1balancerefund-bugs
132 fix v1balancerefund bugs
This commit is contained in:
+7
-6
@@ -85,7 +85,7 @@ async def refund_wallet_endpoint(
|
||||
key.refund_mint_url or PRIMARY_MINT_URL,
|
||||
key.refund_address,
|
||||
)
|
||||
result = {"recipient": key.refund_address, "msats": remaining_balance_msats}
|
||||
result = {"recipient": key.refund_address}
|
||||
else:
|
||||
refund_amount = (
|
||||
remaining_balance_msats // 1000
|
||||
@@ -96,12 +96,13 @@ async def refund_wallet_endpoint(
|
||||
token = await send_token(
|
||||
refund_amount, refund_currency, key.refund_mint_url
|
||||
)
|
||||
result = {"token": token}
|
||||
|
||||
if key.refund_currency == "sat":
|
||||
result["sats"] = str(remaining_balance_msats // 1000)
|
||||
else:
|
||||
result["msats"] = str(remaining_balance_msats)
|
||||
|
||||
result = {
|
||||
"msats": remaining_balance_msats,
|
||||
"recipient": None,
|
||||
"token": token,
|
||||
}
|
||||
except HTTPException:
|
||||
# Re-raise HTTP exceptions (like 400 for balance too small)
|
||||
raise
|
||||
|
||||
@@ -176,6 +176,6 @@ async def update_sats_pricing() -> None:
|
||||
|
||||
|
||||
@models_router.get("/v1/models")
|
||||
@models_router.get("/models")
|
||||
@models_router.get("/models", include_in_schema=False)
|
||||
async def models() -> dict:
|
||||
return {"data": MODELS}
|
||||
|
||||
+5
-1
@@ -234,6 +234,8 @@ async def fetch_all_balances(
|
||||
)
|
||||
proofs = await slow_filter_spend_proofs(proofs, wallet)
|
||||
user_balance = await db.balances_for_mint_and_unit(session, mint_url, unit)
|
||||
if unit == "sat":
|
||||
user_balance = user_balance // 1000
|
||||
proofs_balance = sum(proof.amount for proof in proofs)
|
||||
|
||||
result: BalanceDetail = {
|
||||
@@ -317,12 +319,14 @@ async def periodic_payout() -> None:
|
||||
user_balance = await db.balances_for_mint_and_unit(
|
||||
session, mint_url, unit
|
||||
)
|
||||
if unit == "sat":
|
||||
user_balance = user_balance // 1000
|
||||
proofs_balance = sum(proof.amount for proof in proofs)
|
||||
available_balance = proofs_balance - user_balance
|
||||
print(f"Balance: {proofs_balance} {unit}")
|
||||
print(f"User balance: {user_balance} {unit}")
|
||||
print(f"Available balance: {available_balance} {unit}")
|
||||
min_amount = 5 if unit == "sat" else 5000
|
||||
min_amount = 210 if unit == "sat" else 210000
|
||||
if proofs_balance > min_amount:
|
||||
amount_received = await raw_send_to_lnurl(
|
||||
wallet, proofs, RECEIVE_LN_ADDRESS, unit
|
||||
|
||||
@@ -105,7 +105,15 @@ async def test_full_wallet_flow(
|
||||
assert refund_response.status_code == 200
|
||||
refund_data = refund_response.json()
|
||||
assert "token" in refund_data
|
||||
assert refund_data["msats"] == (initial_amount + topup_amount) * 1000
|
||||
|
||||
# Check for either sats or msats depending on refund_currency
|
||||
total_amount = initial_amount + topup_amount
|
||||
if "sats" in refund_data:
|
||||
assert refund_data["sats"] == str(total_amount)
|
||||
elif "msats" in refund_data:
|
||||
assert refund_data["msats"] == str(total_amount * 1000)
|
||||
else:
|
||||
pytest.fail("Response should contain either 'sats' or 'msats'")
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
|
||||
@@ -41,14 +41,18 @@ async def test_full_balance_refund_returns_cashu_token(
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
# Should return msats, recipient (None), and token
|
||||
assert "msats" in data
|
||||
assert "recipient" in data
|
||||
# Should return either sats or msats (as string), and token
|
||||
assert "token" in data
|
||||
assert data["msats"] == initial_balance
|
||||
assert data["recipient"] is None
|
||||
assert data["token"].startswith("cashuA")
|
||||
|
||||
# Check for either sats or msats depending on refund_currency
|
||||
if "sats" in data:
|
||||
assert data["sats"] == str(initial_balance // 1000) # Convert msats to sats
|
||||
elif "msats" in data:
|
||||
assert data["msats"] == str(initial_balance)
|
||||
else:
|
||||
pytest.fail("Response should contain either 'sats' or 'msats'")
|
||||
|
||||
# Validate token format
|
||||
token = data["token"]
|
||||
try:
|
||||
@@ -88,7 +92,14 @@ async def test_partial_refund_not_supported(
|
||||
# Should still refund full balance (endpoint ignores the parameter)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["msats"] == 10_000_000 # Full balance
|
||||
|
||||
# Check for either sats or msats
|
||||
if "sats" in data:
|
||||
assert data["sats"] == "10000" # Full balance in sats
|
||||
elif "msats" in data:
|
||||
assert data["msats"] == "10000000" # Full balance in msats
|
||||
else:
|
||||
pytest.fail("Response should contain either 'sats' or 'msats'")
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@@ -432,13 +443,17 @@ async def test_refund_response_format(
|
||||
|
||||
data = response.json()
|
||||
assert isinstance(data, dict)
|
||||
assert "msats" in data
|
||||
assert "recipient" in data
|
||||
assert "token" in data
|
||||
assert isinstance(data["msats"], int)
|
||||
assert data["recipient"] is None
|
||||
assert isinstance(data["token"], str)
|
||||
|
||||
# Should have either sats or msats (both as strings)
|
||||
if "sats" in data:
|
||||
assert isinstance(data["sats"], str)
|
||||
elif "msats" in data:
|
||||
assert isinstance(data["msats"], str)
|
||||
else:
|
||||
pytest.fail("Response should contain either 'sats' or 'msats'")
|
||||
|
||||
# Test 2: Test with refund address would require creating key via proxy endpoint
|
||||
# Since refund address headers only work on proxy endpoints, not wallet endpoints
|
||||
# Skip this part as it's already tested in test_refund_with_lightning_address
|
||||
|
||||
Reference in New Issue
Block a user