Description
Swap rate strings read from the contract can include leading or trailing whitespace. calculate_to_amount passes the value straight into Decimal(rate), which can raise InvalidOperation or diverge from the normalized rate used when the swap was initiated.
Steps to Reproduce
- Initiate a swap whose on-chain
rate field is stored with surrounding spaces (e.g. " 345 ").
- Run validator fulfillment verification or miner
to_amount math via calculate_to_amount.
- Compare with the same swap using a trimmed rate.
Expected Behavior
Amount math treats " 345 " the same as "345" so miner and validator agree with the committed rate.
Actual Behavior
Whitespace-padded rates can fail parsing or produce inconsistent to_amount results.
Environment
- Component:
allways.utils.rate.calculate_to_amount
- Python 3.x
Additional Context
Rate normalization should happen at the shared calculation entry point so miner, validator, and CLI stay aligned.
Description
Swap
ratestrings read from the contract can include leading or trailing whitespace.calculate_to_amountpasses the value straight intoDecimal(rate), which can raiseInvalidOperationor diverge from the normalized rate used when the swap was initiated.Steps to Reproduce
ratefield is stored with surrounding spaces (e.g." 345 ").to_amountmath viacalculate_to_amount.Expected Behavior
Amount math treats
" 345 "the same as"345"so miner and validator agree with the committed rate.Actual Behavior
Whitespace-padded rates can fail parsing or produce inconsistent
to_amountresults.Environment
allways.utils.rate.calculate_to_amountAdditional Context
Rate normalization should happen at the shared calculation entry point so miner, validator, and CLI stay aligned.