diff --git a/CHANGELOG.md b/CHANGELOG.md index d79b79636..171061144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/tests/unit/models/currencies/test_xrp.py b/tests/unit/models/currencies/test_xrp.py index c823f5ee1..473cd0969 100644 --- a/tests/unit/models/currencies/test_xrp.py +++ b/tests/unit/models/currencies/test_xrp.py @@ -1,6 +1,7 @@ from unittest import TestCase from xrpl.models.currencies import XRP +from xrpl.utils import xrp_to_drops class TestXRP(TestCase): @@ -8,7 +9,8 @@ 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) diff --git a/xrpl/models/currencies/xrp.py b/xrpl/models/currencies/xrp.py index 1f928c860..c3af77328 100644 --- a/xrpl/models/currencies/xrp.py +++ b/xrpl/models/currencies/xrp.py @@ -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. @@ -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)