Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions allways/utils/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def calculate_to_amount(
to_decimals: Decimal places for canonical dest chain (e.g. 9 for TAO)
from_decimals: Decimal places for canonical source chain (e.g. 8 for BTC)
"""
rate = rate.strip()
rate_fixed = int(Decimal(rate) * RATE_PRECISION)
if rate_fixed == 0:
return 0
Expand Down
10 changes: 10 additions & 0 deletions tests/test_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
class TestBtcToTao:
"""BTC → TAO: forward direction, multiply by rate."""

def test_rate_string_whitespace_stripped(self):
source = int(Decimal('0.01') * BTC_TO_SAT)
padded = calculate_to_amount(
source, ' 345 ', is_reverse=False, to_decimals=TAO_DEC, from_decimals=BTC_DEC
)
plain = calculate_to_amount(
source, '345', is_reverse=False, to_decimals=TAO_DEC, from_decimals=BTC_DEC
)
assert padded == plain

def test_standard_rate(self):
# 0.01 BTC @ rate 345 (1 BTC = 345 TAO) → 3.45 TAO
source = int(Decimal('0.01') * BTC_TO_SAT) # 1_000_000 sat
Expand Down