Skip to content
Snippets Groups Projects
Commit e41389f7 authored by Holger's avatar Holger
Browse files

Fix error in check_asset in amount, custom_chain example added

parent 909b6dff
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,15 @@ from beem.instance import shared_steem_instance ...@@ -10,6 +10,15 @@ from beem.instance import shared_steem_instance
from beem.asset import Asset from beem.asset import Asset
def check_asset(other, self):
if isinstance(other, dict) and "asset" in other and isinstance(self, dict) and "asset" in self:
if not other["asset"] == self["asset"]:
raise AssertionError()
else:
if not other == self:
raise AssertionError()
@python_2_unicode_compatible @python_2_unicode_compatible
class Amount(dict): class Amount(dict):
""" This class deals with Amounts of any asset to simplify dealing with the tuple:: """ This class deals with Amounts of any asset to simplify dealing with the tuple::
...@@ -190,8 +199,7 @@ class Amount(dict): ...@@ -190,8 +199,7 @@ class Amount(dict):
def __add__(self, other): def __add__(self, other):
a = self.copy() a = self.copy()
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
a["amount"] += other["amount"] a["amount"] += other["amount"]
else: else:
a["amount"] += float(other) a["amount"] += float(other)
...@@ -200,8 +208,7 @@ class Amount(dict): ...@@ -200,8 +208,7 @@ class Amount(dict):
def __sub__(self, other): def __sub__(self, other):
a = self.copy() a = self.copy()
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
a["amount"] -= other["amount"] a["amount"] -= other["amount"]
else: else:
a["amount"] -= float(other) a["amount"] -= float(other)
...@@ -210,8 +217,7 @@ class Amount(dict): ...@@ -210,8 +217,7 @@ class Amount(dict):
def __mul__(self, other): def __mul__(self, other):
a = self.copy() a = self.copy()
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
a["amount"] *= other["amount"] a["amount"] *= other["amount"]
else: else:
a["amount"] *= other a["amount"] *= other
...@@ -220,8 +226,7 @@ class Amount(dict): ...@@ -220,8 +226,7 @@ class Amount(dict):
def __floordiv__(self, other): def __floordiv__(self, other):
a = self.copy() a = self.copy()
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
from .price import Price from .price import Price
return Price(self, other, steem_instance=self.steem) return Price(self, other, steem_instance=self.steem)
else: else:
...@@ -231,8 +236,7 @@ class Amount(dict): ...@@ -231,8 +236,7 @@ class Amount(dict):
def __div__(self, other): def __div__(self, other):
a = self.copy() a = self.copy()
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
from .price import Price from .price import Price
return Price(self, other, steem_instance=self.steem) return Price(self, other, steem_instance=self.steem)
else: else:
...@@ -242,8 +246,7 @@ class Amount(dict): ...@@ -242,8 +246,7 @@ class Amount(dict):
def __mod__(self, other): def __mod__(self, other):
a = self.copy() a = self.copy()
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
a["amount"] %= other["amount"] a["amount"] %= other["amount"]
else: else:
a["amount"] %= other a["amount"] %= other
...@@ -252,8 +255,7 @@ class Amount(dict): ...@@ -252,8 +255,7 @@ class Amount(dict):
def __pow__(self, other): def __pow__(self, other):
a = self.copy() a = self.copy()
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
a["amount"] **= other["amount"] a["amount"] **= other["amount"]
else: else:
a["amount"] **= other a["amount"] **= other
...@@ -261,8 +263,7 @@ class Amount(dict): ...@@ -261,8 +263,7 @@ class Amount(dict):
def __iadd__(self, other): def __iadd__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
self["amount"] += other["amount"] self["amount"] += other["amount"]
else: else:
self["amount"] += other self["amount"] += other
...@@ -270,8 +271,7 @@ class Amount(dict): ...@@ -270,8 +271,7 @@ class Amount(dict):
def __isub__(self, other): def __isub__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
self["amount"] -= other["amount"] self["amount"] -= other["amount"]
else: else:
self["amount"] -= other self["amount"] -= other
...@@ -279,8 +279,7 @@ class Amount(dict): ...@@ -279,8 +279,7 @@ class Amount(dict):
def __imul__(self, other): def __imul__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
self["amount"] *= other["amount"] self["amount"] *= other["amount"]
else: else:
self["amount"] *= other self["amount"] *= other
...@@ -288,8 +287,7 @@ class Amount(dict): ...@@ -288,8 +287,7 @@ class Amount(dict):
def __idiv__(self, other): def __idiv__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
return self["amount"] / other["amount"] return self["amount"] / other["amount"]
else: else:
self["amount"] /= other self["amount"] /= other
...@@ -304,8 +302,7 @@ class Amount(dict): ...@@ -304,8 +302,7 @@ class Amount(dict):
def __imod__(self, other): def __imod__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
self["amount"] %= other["amount"] self["amount"] %= other["amount"]
else: else:
self["amount"] %= other self["amount"] %= other
...@@ -317,48 +314,42 @@ class Amount(dict): ...@@ -317,48 +314,42 @@ class Amount(dict):
def __lt__(self, other): def __lt__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
return self["amount"] < other["amount"] return self["amount"] < other["amount"]
else: else:
return self["amount"] < float(other or 0) return self["amount"] < float(other or 0)
def __le__(self, other): def __le__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
return self["amount"] <= other["amount"] return self["amount"] <= other["amount"]
else: else:
return self["amount"] <= float(other or 0) return self["amount"] <= float(other or 0)
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
return self["amount"] == other["amount"] return self["amount"] == other["amount"]
else: else:
return self["amount"] == float(other or 0) return self["amount"] == float(other or 0)
def __ne__(self, other): def __ne__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
return self["amount"] != other["amount"] return self["amount"] != other["amount"]
else: else:
return self["amount"] != float(other or 0) return self["amount"] != float(other or 0)
def __ge__(self, other): def __ge__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
return self["amount"] >= other["amount"] return self["amount"] >= other["amount"]
else: else:
return self["amount"] >= float(other or 0) return self["amount"] >= float(other or 0)
def __gt__(self, other): def __gt__(self, other):
if isinstance(other, Amount): if isinstance(other, Amount):
if not other["asset"] == self["asset"]: check_asset(other["asset"], self["asset"])
raise AssertionError()
return self["amount"] > other["amount"] return self["amount"] > other["amount"]
else: else:
return self["amount"] > float(other or 0) return self["amount"] > float(other or 0)
......
"""THIS FILE IS GENERATED FROM beem SETUP.PY.""" """THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.19.54' version = '0.19.55'
"""THIS FILE IS GENERATED FROM beem SETUP.PY.""" """THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.19.54' version = '0.19.55'
"""THIS FILE IS GENERATED FROM beem SETUP.PY.""" """THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.19.54' version = '0.19.55'
"""THIS FILE IS GENERATED FROM beem SETUP.PY.""" """THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.19.54' version = '0.19.55'
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import sys
from datetime import datetime, timedelta
import time
import io
import logging
from beem.blockchain import Blockchain
from beem.block import Block
from beem.account import Account
from beem.amount import Amount
from beemgraphenebase.account import PasswordKey, PrivateKey, PublicKey
from beem.steem import Steem
from beem.utils import parse_time, formatTimedelta
from beemapi.exceptions import NumRetriesReached
from beem.nodelist import NodeList
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
if __name__ == "__main__":
stm = Steem(node=["https://testnet.steemitdev.com"],
custom_chains={"TESTNETHF20":
{'chain_assets':
[
{"asset": "@@000000013", "symbol": "SBD", "precision": 3, "id": 0},
{"asset": "@@000000021", "symbol": "STEEM", "precision": 3, "id": 1},
{"asset": "@@000000037", "symbol": "VESTS", "precision": 6, "id": 2}
],
'chain_id': '46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32',
'min_version': '0.20.0',
'prefix': 'TST'}})
print(stm.get_blockchain_version())
print(stm.get_config()["STEEM_CHAIN_ID"])
...@@ -16,7 +16,7 @@ except LookupError: ...@@ -16,7 +16,7 @@ except LookupError:
ascii = codecs.lookup('ascii') ascii = codecs.lookup('ascii')
codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs')) codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs'))
VERSION = '0.19.54' VERSION = '0.19.55'
tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized'] tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized']
......
...@@ -226,6 +226,23 @@ class Testcases(unittest.TestCase): ...@@ -226,6 +226,23 @@ class Testcases(unittest.TestCase):
break break
self.assertTrue(len(ops_blocks) == 1) self.assertTrue(len(ops_blocks) == 1)
@parameterized.expand([
("non_appbase"),
("appbase"),
])
def test_stream2(self, node_param):
if node_param == "non_appbase":
bts = self.bts
else:
bts = self.appbase
b = Blockchain(steem_instance=bts)
stop_block = b.get_current_block_num()
start_block = stop_block - 10
ops_stream = []
for op in b.stream(start=start_block, stop=stop_block):
ops_stream.append(op)
self.assertTrue(len(ops_stream) > 0)
@parameterized.expand([ @parameterized.expand([
("non_appbase"), ("non_appbase"),
("appbase"), ("appbase"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment