Skip to content

[Bug]: Padded swap rate strings break calculate_to_amount #427

@techforgeworks

Description

@techforgeworks

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

  1. Initiate a swap whose on-chain rate field is stored with surrounding spaces (e.g. " 345 ").
  2. Run validator fulfillment verification or miner to_amount math via calculate_to_amount.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions