From 4420bf3124ca3ed28a9312a09df51e76ce0021fb Mon Sep 17 00:00:00 2001 From: MrNaif2018 Date: Tue, 29 Jun 2021 13:33:32 +0300 Subject: [PATCH] Version 1.3.2.2: better handle None rate --- CHANGELOG.md | 12 ++++++++---- bitcart/utils.py | 2 ++ setup.py | 2 +- tests/coins/btc/test_without_wallet.py | 7 +++++-- tests/test_utils.py | 1 + 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ca37d2..2d3521c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Latest changes +## 1.3.2.2 + +Handle None values better in `convert_amount_type` to always return Decimal. + ## 1.3.2.1 PyPI readme fixes @@ -384,7 +388,7 @@ This bugfix fixes xpub sending, and exception raising. Structural improvements and more -**Structural improvements** +### Structural improvements This version makes async version the default one used in the repo. @@ -397,7 +401,7 @@ It means less time spent, and instead of porting new features to sync/async vers The async branch will be deleted. -**Sending transactions improvements** +### Sending transactions improvements Also, the long awaited `pay_to_many` function to do batch transactions is there! Both `pay_to` and `pay_to_many` now have optional `feerate`, which is sat/vbyte rate. @@ -502,7 +506,7 @@ btc.poll_updates() The following code would print -``` +```text new_transaction some_tx_hash dict of tx hash data @@ -560,7 +564,7 @@ This adds in new LN class and related methods. Also, now it is not needed to fill in all values, some defaults are used: -``` +```text rpc_user="electrum" rpc_pass="electrumz" rpc_url="http://localhost:5000" for bitcoin daemon and "http://localhost:5001" for lightning daemon. diff --git a/bitcart/utils.py b/bitcart/utils.py index 81b4337..f67c9cf 100644 --- a/bitcart/utils.py +++ b/bitcart/utils.py @@ -15,6 +15,8 @@ def convert_amount_type(amount: str) -> Decimal: Returns: Decimal """ + if amount == "None": + return Decimal("Nan") return Decimal(amount) diff --git a/setup.py b/setup.py index 17aad21..b5b936f 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ def main() -> None: setup( name="bitcart", packages=find_packages(), - version="1.3.2.1", + version="1.3.2.2", license="LGPLv3+", description="BitcartCC coins support library", long_description=open("README.md").read(), diff --git a/tests/coins/btc/test_without_wallet.py b/tests/coins/btc/test_without_wallet.py index 1cdc21a..3a67d7c 100644 --- a/tests/coins/btc/test_without_wallet.py +++ b/tests/coins/btc/test_without_wallet.py @@ -28,10 +28,13 @@ async def test_help(btc): assert "help" in data -@pytest.mark.parametrize("currency", ["USD", "RUB", "JPY"]) +@pytest.mark.parametrize("currency", ["USD", "RUB", "JPY", "nonexisting"]) async def test_rate(btc, currency): price = await btc.rate(currency) - assert price > 0 + if currency == "nonexisting": + assert price.is_nan() + else: + assert price > 0 assert isinstance(price, decimal.Decimal) diff --git a/tests/test_utils.py b/tests/test_utils.py index 12f74b8..3d71ea3 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -25,6 +25,7 @@ def test_convertability(): def test_convert_amount_type(): assert convert_amount_type("1") == Decimal("1") + assert convert_amount_type("None").is_nan() @pytest.mark.asyncio