Skip to content

Commit

Permalink
[BREAKING] fix: XRP().to_amount now expects XRP instead of drops (#554)
Browse files Browse the repository at this point in the history
* fix XRP.to_amount

* update changelog

* fix circular dependency

* fix circular dependency

* add comment

* fix test

* improve comment
  • Loading branch information
mvadari authored and JST5000 committed Jun 28, 2023
1 parent 960d90d commit 8c95e55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `AccountSetFlagInterface` now operates on transaction `tf` flags (as opposed to `asf` flags)
- `sign` is now synchronous instead of async (done by removing the optional `check_fee` param & moving checks up to other functions)
- In order to be internally consistent, all signing/submitting functions will follow the parameter order of `transaction`, `client`, `wallet`, and then other parameters. (This is because `wallet` is optional for `submit_and_wait` and so must come after `client`)
- `XRP.to_amount` now converts from XRP to drops, instead of expecting a drops amount

### Fixed:
- Added a sort of the account IDs in `multisign`, so that the `multisign` always works.
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/models/currencies/test_xrp.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from unittest import TestCase

from xrpl.models.currencies import XRP
from xrpl.utils import xrp_to_drops


class TestXRP(TestCase):
def test_to_dict(self):
self.assertEqual(XRP().to_dict()["currency"], "XRP")

def test_to_amount(self):
amount = "12"
issued_currency_amount = XRP().to_amount(amount)
amount = 12
expected = xrp_to_drops(amount)
result = XRP().to_amount(amount)

self.assertEqual(issued_currency_amount, amount)
self.assertEqual(result, expected)
9 changes: 7 additions & 2 deletions xrpl/models/currencies/xrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def to_dict(self: XRP) -> Dict[str, Any]:
"""
return {**super().to_dict(), "currency": "XRP"}

def to_amount(self: XRP, value: Union[str, int]) -> str:
def to_amount(self: XRP, value: Union[str, int, float]) -> str:
"""
Converts value to XRP.
Expand All @@ -71,4 +71,9 @@ def to_amount(self: XRP, value: Union[str, int]) -> str:
Returns:
A string representation of XRP amount.
"""
return str(value)
# import needed here to avoid circular dependency
from xrpl.utils.xrp_conversions import xrp_to_drops

if isinstance(value, str):
return xrp_to_drops(float(value))
return xrp_to_drops(value)

0 comments on commit 8c95e55

Please sign in to comment.