diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9c40f167a9c6174b8801ca062c599ef943cafc85..f904db0cbd97e1903e6387309c3fc8540a12d051 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,5 +1,11 @@ Changelog ========= +0.20.21 +------- +* Fix float entered in Amount will be reduced by 0.001 due to rounding issues +* fix Amount.amount and added Amount.amount_decimal +* Prevent that wrong reputation in a Comment API answer break the Comment object + 0.20.20 ------- * Fix typo (PR #161) diff --git a/beem/amount.py b/beem/amount.py index 251766868c40630d51477f750398c328bdbb40c9..132a55a3a4189300af303f2c05a739acfe36c863 100644 --- a/beem/amount.py +++ b/beem/amount.py @@ -117,30 +117,45 @@ class Amount(dict): self["symbol"] = self["asset"]["symbol"] self["amount"] = Decimal(amount["amount"]) / Decimal(10 ** self["asset"]["precision"]) - elif amount and asset and isinstance(asset, Asset): - self["amount"] = amount - self["symbol"] = asset["symbol"] - self["asset"] = asset - elif amount and asset and isinstance(asset, string_types): - self["amount"] = amount - self["asset"] = Asset(asset, steem_instance=self.steem) - self["symbol"] = self["asset"]["symbol"] - elif isinstance(amount, (integer_types, float, Decimal)) and asset and isinstance(asset, Asset): - self["amount"] = amount + elif isinstance(amount, (float)) and asset and isinstance(asset, Asset): + self["amount"] = str(amount) self["asset"] = asset self["symbol"] = self["asset"]["symbol"] - elif isinstance(amount, (integer_types, float, Decimal)) and asset and isinstance(asset, dict): + elif isinstance(amount, (integer_types, Decimal)) and asset and isinstance(asset, Asset): self["amount"] = amount self["asset"] = asset self["symbol"] = self["asset"]["symbol"] + + elif isinstance(amount, (float)) and asset and isinstance(asset, dict): + self["amount"] = str(amount) + self["asset"] = asset + self["symbol"] = self["asset"]["symbol"] - elif isinstance(amount, (integer_types, float, Decimal)) and asset and isinstance(asset, string_types): + elif isinstance(amount, (integer_types, Decimal)) and asset and isinstance(asset, dict): self["amount"] = amount + self["asset"] = asset + self["symbol"] = self["asset"]["symbol"] + + elif isinstance(amount, (float)) and asset and isinstance(asset, string_types): + self["amount"] = str(amount) self["asset"] = Asset(asset, steem_instance=self.steem) self["symbol"] = asset + + elif isinstance(amount, (integer_types, Decimal)) and asset and isinstance(asset, string_types): + self["amount"] = amount + self["asset"] = Asset(asset, steem_instance=self.steem) + self["symbol"] = asset + elif amount and asset and isinstance(asset, Asset): + self["amount"] = amount + self["symbol"] = asset["symbol"] + self["asset"] = asset + elif amount and asset and isinstance(asset, string_types): + self["amount"] = amount + self["asset"] = Asset(asset, steem_instance=self.steem) + self["symbol"] = self["asset"]["symbol"] else: raise ValueError if self.fixed_point_arithmetic: @@ -155,12 +170,19 @@ class Amount(dict): amount=self["amount"], asset=self["asset"].copy(), new_appbase_format=self.new_appbase_format, + fixed_point_arithmetic=self.fixed_point_arithmetic, steem_instance=self.steem) @property def amount(self): """ Returns the amount as float """ + return float(self["amount"]) + + @property + def amount_decimal(self): + """ Returns the amount as decimal + """ return self["amount"] @property diff --git a/beem/comment.py b/beem/comment.py index 9b640919766405328c57a4bd2423afc6b938b336..06fa6e896316be200ed6a79f582a0abf8ada2972 100644 --- a/beem/comment.py +++ b/beem/comment.py @@ -129,7 +129,10 @@ class Comment(BlockchainObject): ] for p in parse_int: if p in vote and isinstance(vote.get(p), string_types): - vote[p] = int(vote.get(p, "0")) + try: + vote[p] = int(vote.get(p, "0")) + except: + vote[p] = int(0) new_active_votes.append(vote) comment["active_votes"] = new_active_votes return comment diff --git a/beem/version.py b/beem/version.py index 2438e231cc2916012884b67ffe81206bab59c822..bb3e0bd30ad17c91434ef5e04ac0c9388d2192d3 100644 --- a/beem/version.py +++ b/beem/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.20' +version = '0.20.21' diff --git a/beemapi/version.py b/beemapi/version.py index 2438e231cc2916012884b67ffe81206bab59c822..bb3e0bd30ad17c91434ef5e04ac0c9388d2192d3 100644 --- a/beemapi/version.py +++ b/beemapi/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.20' +version = '0.20.21' diff --git a/beembase/version.py b/beembase/version.py index 2438e231cc2916012884b67ffe81206bab59c822..bb3e0bd30ad17c91434ef5e04ac0c9388d2192d3 100644 --- a/beembase/version.py +++ b/beembase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.20' +version = '0.20.21' diff --git a/beemgraphenebase/version.py b/beemgraphenebase/version.py index 2438e231cc2916012884b67ffe81206bab59c822..bb3e0bd30ad17c91434ef5e04ac0c9388d2192d3 100644 --- a/beemgraphenebase/version.py +++ b/beemgraphenebase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.20' +version = '0.20.21' diff --git a/setup.py b/setup.py index ed43a4b8f769bf25f430255e62f7cec5406f0565..1451c567c13c6007b2dcb702325015217fa95aa4 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ except LookupError: ascii = codecs.lookup('ascii') codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs')) -VERSION = '0.20.20' +VERSION = '0.20.21' tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized'] diff --git a/tests/beem/test_amount.py b/tests/beem/test_amount.py index 501d85a29df452f2ac00922f3685a09fbcddaa29..664ef94ea47715539f19462d335889230f2c5fa7 100644 --- a/tests/beem/test_amount.py +++ b/tests/beem/test_amount.py @@ -140,11 +140,36 @@ class Testcases(unittest.TestCase): self.assertEqual( int(Amount("0.9999", self.symbol)), 999) + self.assertEqual( + int(Amount(0.151, self.symbol)), + 151) + self.assertEqual( + int(Amount(round(0.1509,3), self.symbol)), + 151) + self.assertEqual( + int(Amount(round(0.1509,3), self.asset)), + 151) + self.assertEqual( + int(Amount(int(1), self.symbol)), + 1000) + self.assertEqual( + int(Amount(amount=round(0.1509,3), asset=Asset("SBD"))), + 151) + + def test_dict(self): + self.assertEqual(int(Amount({'amount': '150', 'nai': '@@000000021', 'precision': 3})), 150) + def test_float(self): self.assertEqual( float(Amount("1", self.symbol)), 1.00000) + self.assertEqual( + float(Amount(0.151, self.symbol)), + 0.151) + self.assertEqual( + float(Amount(round(0.1509, 3), self.symbol)), + 0.151) def test_plus(self): a1 = Amount(1, self.symbol)