diff --git a/README.rst b/README.rst index 71ed3cce9b3ba35e464a9a160164736915f83986..a6c47a450a42191d7412213f55bed8ad9a7a611e 100644 --- a/README.rst +++ b/README.rst @@ -156,6 +156,13 @@ before transmitting the packed file. Please check the hash-sum after downloading Changelog ========= +0.19.47 +------- +* Some bug fixes +* Unit tests using testnet fixed +* beem.snapshot improved +* Example account_sp_over_time added + 0.19.46 ------- * Force refresh of chain_params on node switch diff --git a/beem/cli.py b/beem/cli.py index 0d2e2738195224271b359950d98eee0cb009c2a2..9961c950a676c804f1b89269147cc09260729be7 100644 --- a/beem/cli.py +++ b/beem/cli.py @@ -1638,18 +1638,18 @@ def buy(amount, asset, price, account, orderid): stm = shared_steem_instance() if stm.rpc is not None: stm.rpc.rpcconnect() - if not account: + if account is None: account = stm.config["default_account"] if asset == "SBD": market = Market(base=Asset("STEEM"), quote=Asset("SBD"), steem_instance=stm) else: market = Market(base=Asset("SBD"), quote=Asset("STEEM"), steem_instance=stm) - if not price: + if price is None: orderbook = market.orderbook(limit=1, raw_data=False) if asset == "STEEM" and len(orderbook["bids"]) > 0: p = Price(orderbook["bids"][0]["base"], orderbook["bids"][0]["quote"], steem_instance=stm).invert() p_show = p - else: + elif len(orderbook["asks"]) > 0: p = Price(orderbook["asks"][0]["base"], orderbook["asks"][0]["quote"], steem_instance=stm).invert() p_show = p price_ok = click.prompt("Is the following Price ok: %s [y/n]" % (str(p_show))) diff --git a/beem/nodelist.py b/beem/nodelist.py index 8e922e8ee72f0fcf278977db0b0032bb559a7e72..09903146f185dfb3828e5f2c76f0c4e5782de9f9 100644 --- a/beem/nodelist.py +++ b/beem/nodelist.py @@ -228,6 +228,13 @@ class NodeList(list): "type": "testnet", "owner": "almost-digital", "score": 5 + }, + { + "url": "https://testnet.steemitdev.com", + "version": "0.21.0", + "type": "testnet-dev", + "owner": "steemit", + "score": 5 }] super(NodeList, self).__init__(nodes) @@ -305,13 +312,14 @@ class NodeList(list): new_nodes.append(new_node) super(NodeList, self).__init__(new_nodes) - def get_nodes(self, normal=True, appbase=True, dev=False, testnet=False, wss=True, https=True): + def get_nodes(self, normal=True, appbase=True, dev=False, testnet=False, testnetdev=False, wss=True, https=True): """ Returns nodes as list :param bool normal: when True, nodes with version 0.19.5 are included :param bool appbase: when True, nodes with version 0.19.10 are included :param bool dev: when True, dev nodes with version 0.19.10 are included :param bool testnet: when True, testnet nodes are included + :param bool testnetdev: When True, testnet-dev nodes are included """ node_list = [] @@ -324,6 +332,8 @@ class NodeList(list): node_type_list.append("appbase-dev") if testnet: node_type_list.append("testnet") + if testnetdev: + node_type_list.append("testnet-dev") for node in self: if node["type"] in node_type_list and node["score"] >= 0: if not https and node["url"][:5] == 'https': @@ -334,6 +344,6 @@ class NodeList(list): return [node["url"] for node in sorted(node_list, key=lambda self: self['score'], reverse=True)] - def get_testnet(self): + def get_testnet(self, testnet=True, testnetdev=False): """Returns testnet nodes""" - return self.get_nodes(normal=False, appbase=False, testnet=True) + return self.get_nodes(normal=False, appbase=False, testnet=testnet, testnetdev=testnetdev) diff --git a/beem/snapshot.py b/beem/snapshot.py index ed6049ac686acb74589272593d250b39c9bdc443..8c54743e7f2fbffc21a51c8ee88cb934b0425d98 100644 --- a/beem/snapshot.py +++ b/beem/snapshot.py @@ -19,35 +19,98 @@ log = logging.getLogger(__name__) class AccountSnapshot(list): - def __init__(self, account, steem_instance=None): + """ This class allows to easily access Account history + + :param str account_name: Name of the account + :param beem.steem.Steem steem_instance: Steem + instance + """ + def __init__(self, account, account_history=[], steem_instance=None): self.steem = steem_instance or shared_steem_instance() self.account = Account(account, steem_instance=self.steem) + self.reset() + super(AccountSnapshot, self).__init__(account_history) + + def reset(self): + """ Resets the arrays not the stored account history + """ self.own_vests = [Amount("0 VESTS", steem_instance=self.steem)] + self.own_steem = [Amount("0 STEEM", steem_instance=self.steem)] + self.own_sbd = [Amount("0 SBD", steem_instance=self.steem)] self.delegated_vests_in = [{}] self.delegated_vests_out = [{}] self.timestamps = [addTzInfo(datetime(1970, 1, 1, 0, 0, 0, 0))] - self.own_sp = [] - self.eff_sp = [] + import beembase.operationids + self.ops_statistics = beembase.operationids.operations.copy() + for key in self.ops_statistics: + self.ops_statistics[key] = 0 + + def get_data(self, timestamp=None): + """ Returns snapshot for given timestamp""" + if timestamp is None: + timestamp = datetime.utcnow() + timestamp = addTzInfo(timestamp) + for (ts, own, din, dout, steem, sbd) in zip(self.timestamps, self.own_vests, + self.delegated_vests_in, + self.delegated_vests_out, + self.own_steem, + self.own_sbd): + sum_in = sum([din[key].amount for key in din]) + sum_out = sum([dout[key].amount for key in dout]) + sp_in = self.steem.vests_to_sp(sum_in, timestamp=ts) + sp_out = self.steem.vests_to_sp(sum_out, timestamp=ts) + sp_own = self.steem.vests_to_sp(own, timestamp=ts) + sp_eff = sp_own + sp_in - sp_out + if timestamp < ts: + continue + else: + return {"timestamp": ts, "vests": own, "delegated_vests_in": din, "delegated_vests_out": dout, + "sp_own": sp_own, "sp_eff": sp_eff, "steem": steem, "sbd": sbd} + return {} - def get_account_history(self): + def get_account_history(self, start=None, stop=None, use_block_num=True): + """ Uses account history to fetch all related ops + + :param int/datetime start: start number/date of transactions to + return (*optional*) + :param int/datetime stop: stop number/date of transactions to + return (*optional*) + :param bool use_block_num: if true, start and stop are block numbers, + otherwise virtual OP count numbers. + + """ super(AccountSnapshot, self).__init__( [ h - for h in self.account.history() + for h in self.account.history(start=start, stop=stop, use_block_num=use_block_num) ] ) - def update(self, timestamp, own, delegated_in, delegated_out): + def update(self, timestamp, own, delegated_in=None, delegated_out=None, steem=0, sbd=0): + """ Updates the internal state arrays + + :param datetime timestamp: datetime of the update + :param Amount/float own: vests + :param dict delegated_in: Incoming delegation + :param dict delegated_out: Outgoing delegation + :param Amount/float steem: steem + :param Amount/float sbd: sbd + + """ self.timestamps.append(timestamp - timedelta(seconds=1)) self.own_vests.append(self.own_vests[-1]) + self.own_steem.append(self.own_steem[-1]) + self.own_sbd.append(self.own_sbd[-1]) self.delegated_vests_in.append(self.delegated_vests_in[-1]) self.delegated_vests_out.append(self.delegated_vests_out[-1]) self.timestamps.append(timestamp) self.own_vests.append(self.own_vests[-1] + own) + self.own_steem.append(self.own_steem[-1] + steem) + self.own_sbd.append(self.own_sbd[-1] + sbd) new_deleg = dict(self.delegated_vests_in[-1]) - if delegated_in: + if delegated_in is not None and delegated_in: if delegated_in['amount'] == 0: del new_deleg[delegated_in['account']] else: @@ -55,7 +118,7 @@ class AccountSnapshot(list): self.delegated_vests_in.append(new_deleg) new_deleg = dict(self.delegated_vests_out[-1]) - if delegated_out: + if delegated_out is not None and delegated_out: if delegated_out['account'] is None: # return_vesting_delegation for delegatee in new_deleg: @@ -72,21 +135,42 @@ class AccountSnapshot(list): self.delegated_vests_out.append(new_deleg) - def build_vests_history(self): + def build(self, only_ops=[], exclude_ops=[]): + """ Builds the account history based on all account operations + + :param array only_ops: Limit generator by these + operations (*optional*) + :param array exclude_ops: Exclude thse operations from + generator (*optional*) + + """ + if len(self.timestamps) > 0: + start_timestamp = self.timestamps[-1] + else: + start_timestamp = None for op in sorted(self, key=lambda k: k['timestamp']): ts = parse_time(op['timestamp']) + if start_timestamp is not None and start_timestamp > ts: + continue # print(op) + if op['type'] in exclude_ops: + continue + if len(only_ops) > 0 and op['type'] not in only_ops: + continue + self.ops_statistics[op['type']] += 1 if op['type'] == "account_create": + fee_steem = Amount(op['fee'], steem_instance=self.steem).amount fee_vests = self.steem.sp_to_vests(Amount(op['fee'], steem_instance=self.steem).amount, timestamp=ts) # print(fee_vests) if op['new_account_name'] == self.account["name"]: self.update(ts, fee_vests, 0, 0) continue if op['creator'] == self.account["name"]: - self.update(ts, fee_vests * (-1), 0, 0) + self.update(ts, 0, 0, 0, fee_steem * (-1), 0) continue if op['type'] == "account_create_with_delegation": + fee_steem = Amount(op['fee'], steem_instance=self.steem).amount fee_vests = self.steem.sp_to_vests(Amount(op['fee'], steem_instance=self.steem).amount, timestamp=ts) if op['new_account_name'] == self.account["name"]: if Amount(op['delegation'], steem_instance=self.steem).amount > 0: @@ -96,16 +180,16 @@ class AccountSnapshot(list): delegation = None self.update(ts, fee_vests, delegation, 0) continue + if op['creator'] == self.account["name"]: delegation = {'account': op['new_account_name'], 'amount': Amount(op['delegation'], steem_instance=self.steem)} - self.update(ts, fee_vests * (-1), 0, delegation) + self.update(ts, 0, 0, delegation, fee_steem * (-1), 0) continue if op['type'] == "delegate_vesting_shares": vests = Amount(op['vesting_shares'], steem_instance=self.steem) # print(op) - if op['delegator'] == self.account["name"]: delegation = {'account': op['delegatee'], 'amount': vests} self.update(ts, 0, 0, delegation) @@ -115,11 +199,48 @@ class AccountSnapshot(list): self.update(ts, 0, delegation, 0) continue + if op['type'] == "transfer": + amount = Amount(op['amount'], steem_instance=self.steem) + # print(op) + if op['from'] == self.account["name"]: + if amount.symbol == "STEEM": + self.update(ts, 0, 0, 0, amount * (-1), 0) + elif amount.symbol == "SBD": + self.update(ts, 0, 0, 0, 0, amount * (-1)) + if op['to'] == self.account["name"]: + if amount.symbol == "STEEM": + self.update(ts, 0, 0, 0, amount, 0) + elif amount.symbol == "SBD": + self.update(ts, 0, 0, 0, 0, amount) + # print(op, vests) + # self.update(ts, vests, 0, 0) + continue + + if op['type'] == "fill_order": + current_pays = Amount(op["current_pays"], steem_instance=self.steem) + open_pays = Amount(op["open_pays"], steem_instance=self.steem) + if op["current_owner"] == self.account["name"]: + if current_pays.symbol == "STEEM": + self.update(ts, 0, 0, 0, current_pays * (-1), open_pays) + elif current_pays.symbol == "SBD": + self.update(ts, 0, 0, 0, open_pays, current_pays * (-1)) + if op["open_owner"] == self.account["name"]: + if current_pays.symbol == "STEEM": + self.update(ts, 0, 0, 0, current_pays, open_pays * (-1)) + elif current_pays.symbol == "SBD": + self.update(ts, 0, 0, 0, open_pays * (-1), current_pays) + # print(op) + continue + if op['type'] == "transfer_to_vesting": - vests = self.steem.sp_to_vests(Amount(op['amount'], steem_instance=self.steem).amount, timestamp=ts) + steem = Amount(op['amount'], steem_instance=self.steem) + vests = self.steem.sp_to_vests(steem.amount, timestamp=ts) + if op['from'] == self.account["name"]: + self.update(ts, vests, 0, 0, steem * (-1), 0) + else: + self.update(ts, vests, 0, 0, 0, 0) # print(op) # print(op, vests) - self.update(ts, vests, 0, 0) continue if op['type'] == "fill_vesting_withdraw": @@ -136,7 +257,24 @@ class AccountSnapshot(list): if op['type'] == "claim_reward_balance": vests = Amount(op['reward_vests'], steem_instance=self.steem) - self.update(ts, vests, 0, 0) + steem = Amount(op['reward_steem'], steem_instance=self.steem) + sbd = Amount(op['reward_sbd'], steem_instance=self.steem) + self.update(ts, vests, 0, 0, steem, sbd) + continue + + if op['type'] == "curation_reward": + if "curation_reward" in only_ops: + vests = Amount(op['reward'], steem_instance=self.steem) + self.update(ts, vests, 0, 0) + continue + + if op['type'] == "author_reward": + if "author_reward" in only_ops: + # print(op) + vests = Amount(op['vesting_payout'], steem_instance=self.steem) + steem = Amount(op['steem_payout'], steem_instance=self.steem) + sbd = Amount(op['sbd_payout'], steem_instance=self.steem) + self.update(ts, vests, 0, 0, steem, sbd) continue if op['type'] == "producer_reward": @@ -152,20 +290,35 @@ class AccountSnapshot(list): else: continue - if op['type'] in ['comment', 'vote', 'curation_reward', 'transfer', - 'author_reward', 'feed_publish', 'shutdown_witness', + if op['type'] == "fill_convert_request": + amount_in = Amount(op["amount_in"], steem_instance=self.steem) + amount_out = Amount(op["amount_out"], steem_instance=self.steem) + if op["owner"] == self.account["name"]: + self.update(ts, 0, 0, 0, amount_out, amount_in * (-1)) + continue + + if op['type'] == "interest": + interest = Amount(op["interest"], steem_instance=self.steem) + self.update(ts, 0, 0, 0, 0, interest) + continue + + if op['type'] in ['comment', 'vote', 'feed_publish', 'shutdown_witness', 'account_witness_vote', 'witness_update', 'custom_json', - 'fill_order', 'limit_order_create', 'account_update', + 'limit_order_create', 'account_update', 'account_witness_proxy', 'limit_order_cancel', 'comment_options', - 'delete_comment']: + 'delete_comment', 'interest', 'recover_account', 'pow', + 'fill_convert_request', 'convert', 'request_account_recovery']: continue # if "vests" in str(op).lower(): # print(op) # else: - # print(op) + # print(op) - def build_arrays(self): + def build_sp_arrays(self): + """ Builds the own_sp and eff_sp array""" + self.own_sp = [] + self.eff_sp = [] for (ts, own, din, dout) in zip(self.timestamps, self.own_vests, self.delegated_vests_in, self.delegated_vests_out): @@ -177,3 +330,10 @@ class AccountSnapshot(list): sp_eff = sp_own + sp_in - sp_out self.own_sp.append(sp_own) self.eff_sp.append(sp_eff) + + def __str__(self): + return self.__repr__() + + def __repr__(self): + return "<%s %s>" % ( + self.__class__.__name__, str(self.account["name"])) diff --git a/beem/version.py b/beem/version.py index b8bff7261bc1c3ec040d13ce29daf88078befb09..3c216ba68a07bdf2151db5393539e7b87dc18985 100644 --- a/beem/version.py +++ b/beem/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.19.46' +version = '0.19.47' diff --git a/beemapi/version.py b/beemapi/version.py index b8bff7261bc1c3ec040d13ce29daf88078befb09..3c216ba68a07bdf2151db5393539e7b87dc18985 100644 --- a/beemapi/version.py +++ b/beemapi/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.19.46' +version = '0.19.47' diff --git a/beembase/version.py b/beembase/version.py index b8bff7261bc1c3ec040d13ce29daf88078befb09..3c216ba68a07bdf2151db5393539e7b87dc18985 100644 --- a/beembase/version.py +++ b/beembase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.19.46' +version = '0.19.47' diff --git a/beemgraphenebase/base58.py b/beemgraphenebase/base58.py index bf1cc8139417be78d311f73e7726b3e052906158..605695c0afd8e8429db5434f552e83b15795d99a 100644 --- a/beemgraphenebase/base58.py +++ b/beemgraphenebase/base58.py @@ -21,6 +21,7 @@ known_prefixes = [ "BTS", "MUSE", "TEST", + "TST", "STM", "STX", "GLX", diff --git a/beemgraphenebase/version.py b/beemgraphenebase/version.py index b8bff7261bc1c3ec040d13ce29daf88078befb09..3c216ba68a07bdf2151db5393539e7b87dc18985 100644 --- a/beemgraphenebase/version.py +++ b/beemgraphenebase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.19.46' +version = '0.19.47' diff --git a/docs/beem.snapshot.rst b/docs/beem.snapshot.rst new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/docs/modules.rst b/docs/modules.rst index 6d18c4d55de7f1b0b24a9a4e0b084178ee22f5e3..cfb750d37c614eb3c9984a2be26a2b04763dd3c2 100644 --- a/docs/modules.rst +++ b/docs/modules.rst @@ -27,6 +27,7 @@ beem Modules beem.message beem.notify beem.price + beem.snapshot beem.storage beem.transactionbuilder beem.utils diff --git a/examples/account_sp_over_time.py b/examples/account_sp_over_time.py index 87061bd8e799d92f03b5069add317b99b8137172..742050bcdf16d3b71c9c3d7b444ee0cc6a5b016c 100644 --- a/examples/account_sp_over_time.py +++ b/examples/account_sp_over_time.py @@ -21,8 +21,11 @@ if __name__ == "__main__": account = sys.argv[1] acc_snapshot = AccountSnapshot(account) acc_snapshot.get_account_history() - acc_snapshot.build_vests_history() - acc_snapshot.build_arrays() + acc_snapshot.build() + # acc_snapshot.build(only_ops=["producer_reward"]) + # acc_snapshot.build(only_ops=["curation_reward"]) + # acc_snapshot.build(only_ops=["author_reward"]) + acc_snapshot.build_sp_arrays() timestamps = acc_snapshot.timestamps own_sp = acc_snapshot.own_sp eff_sp = acc_snapshot.eff_sp diff --git a/setup.py b/setup.py index 63819a001c234d8d549c051b284d6cdd723219f6..7042cd1efb47d47f69bd30100b4afa880149b3b2 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.19.46' +VERSION = '0.19.47' tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized'] diff --git a/tests/beem/test_cli.py b/tests/beem/test_cli.py index 35d394442579bfa1c3f3d2bb9220bcfd32615b9b..3a29ff2ee312e3707c6b04bbd1af9282a7e84cd4 100644 --- a/tests/beem/test_cli.py +++ b/tests/beem/test_cli.py @@ -206,13 +206,14 @@ class Testcases(unittest.TestCase): def test_permissions(self): runner = CliRunner() - result = runner.invoke(cli, ['permissions', 'test']) + runner.invoke(cli, ['-o', 'set', 'nodes', str(self.nodelist.get_testnet())]) + result = runner.invoke(cli, ['permissions', 'beem']) self.assertEqual(result.exit_code, 0) def test_follower(self): runner = CliRunner() runner.invoke(cli, ['-o', 'set', 'nodes', str(self.nodelist.get_testnet())]) - result = runner.invoke(cli, ['follower', 'beem2']) + result = runner.invoke(cli, ['follower', 'beem1']) self.assertEqual(result.exit_code, 0) def test_following(self): @@ -224,7 +225,7 @@ class Testcases(unittest.TestCase): def test_muter(self): runner = CliRunner() runner.invoke(cli, ['-o', 'set', 'nodes', str(self.nodelist.get_testnet())]) - result = runner.invoke(cli, ['muter', 'beem2']) + result = runner.invoke(cli, ['muter', 'beem1']) self.assertEqual(result.exit_code, 0) def test_muting(self): @@ -278,7 +279,7 @@ class Testcases(unittest.TestCase): def test_importaccount(self): runner = CliRunner() runner.invoke(cli, ['-o', 'set', 'nodes', str(self.nodelist.get_testnet())]) - result = runner.invoke(cli, ['importaccount', '--roles', '["owner", "active", "posting", "memo"]', 'beem2'], input="test\ntest\n") + result = runner.invoke(cli, ['importaccount', '--roles', '["owner", "active", "posting", "memo"]', 'beem2'], input="test\numybjvCafrt8LdoCjEimQiQ4\n") self.assertEqual(result.exit_code, 0) result = runner.invoke(cli, ['delkey', '--confirm', 'STX7mLs2hns87f7kbf3o2HBqNoEaXiTeeU89eVF6iUCrMQJFzBsPo'], input="test\n") self.assertEqual(result.exit_code, 0) @@ -302,24 +303,28 @@ class Testcases(unittest.TestCase): def test_buy(self): runner = CliRunner() - result = runner.invoke(cli, ['-d', 'buy', '1', 'STEEM', '2.2'], input="test\n") + runner.invoke(cli, ['-o', 'set', 'nodes', self.nodelist.get_nodes()]) + result = runner.invoke(cli, ['-d', '-x', 'buy', '1', 'STEEM', '2.2'], input="test\n") self.assertEqual(result.exit_code, 0) - result = runner.invoke(cli, ['-d', 'buy', '1', 'STEEM'], input="y\ntest\n") + result = runner.invoke(cli, ['-d', '-x', 'buy', '1', 'STEEM'], input="y\ntest\n") self.assertEqual(result.exit_code, 0) - result = runner.invoke(cli, ['-d', 'buy', '1', 'SBD', '2.2'], input="test\n") + result = runner.invoke(cli, ['-d', '-x', 'buy', '1', 'SBD', '2.2'], input="test\n") self.assertEqual(result.exit_code, 0) - result = runner.invoke(cli, ['-d', 'buy', '1', 'SBD'], input="y\ntest\n") + result = runner.invoke(cli, ['-d', '-x', 'buy', '1', 'SBD'], input="y\ntest\n") + runner.invoke(cli, ['-o', 'set', 'nodes', str(self.nodelist.get_testnet())]) self.assertEqual(result.exit_code, 0) def test_sell(self): runner = CliRunner() - result = runner.invoke(cli, ['-d', 'sell', '1', 'STEEM', '2.2'], input="test\n") + runner.invoke(cli, ['-o', 'set', 'nodes', self.nodelist.get_nodes()]) + result = runner.invoke(cli, ['-d', '-x', 'sell', '1', 'STEEM', '2.2'], input="test\n") self.assertEqual(result.exit_code, 0) - result = runner.invoke(cli, ['-d', 'sell', '1', 'SBD', '2.2'], input="test\n") + result = runner.invoke(cli, ['-d', '-x', 'sell', '1', 'SBD', '2.2'], input="test\n") self.assertEqual(result.exit_code, 0) - result = runner.invoke(cli, ['-d', 'sell', '1', 'STEEM'], input="y\ntest\n") + result = runner.invoke(cli, ['-d', '-x', 'sell', '1', 'STEEM'], input="y\ntest\n") self.assertEqual(result.exit_code, 0) - result = runner.invoke(cli, ['-d', 'sell', '1', 'SBD'], input="y\ntest\n") + result = runner.invoke(cli, ['-d', '-x', 'sell', '1', 'SBD'], input="y\ntest\n") + runner.invoke(cli, ['-o', 'set', 'nodes', str(self.nodelist.get_testnet())]) self.assertEqual(result.exit_code, 0) def test_cancel(self): diff --git a/tests/beem/test_connection.py b/tests/beem/test_connection.py index 6356ad8c595c75caadc9640b97d756c5c2151a1e..0187c68bd0a5345340fe23f34b3bba75d5a63378 100644 --- a/tests/beem/test_connection.py +++ b/tests/beem/test_connection.py @@ -15,7 +15,7 @@ class Testcases(unittest.TestCase): nodelist = NodeList() nodelist.update_nodes(steem_instance=Steem(node=nodelist.get_nodes(normal=True, appbase=True), num_retries=10)) b1 = Steem( - node=nodelist.get_testnet(), + node=nodelist.get_testnet(testnet=False, testnetdev=True), nobroadcast=True, num_retries=10 ) @@ -32,7 +32,7 @@ class Testcases(unittest.TestCase): nodelist = NodeList() nodelist.update_nodes(steem_instance=Steem(node=nodelist.get_nodes(normal=True, appbase=True), num_retries=10)) b1 = Steem( - node=nodelist.get_testnet(), + node=nodelist.get_testnet(testnet=False, testnetdev=True), nobroadcast=True, ) set_shared_steem_instance(b1) @@ -46,5 +46,5 @@ class Testcases(unittest.TestCase): bts = Account("test") - self.assertEqual(test.steem.prefix, "STX") + self.assertEqual(test.steem.prefix, "TST") self.assertEqual(bts.steem.prefix, "STM") diff --git a/tests/beem/test_testnet.py b/tests/beem/test_testnet.py index 14e4e008f6e0960a211c14d508656bdaa94f8956..d37009694298e6466ac840295281fed1d82f069d 100644 --- a/tests/beem/test_testnet.py +++ b/tests/beem/test_testnet.py @@ -78,10 +78,10 @@ class Testcases(unittest.TestCase): stm.wallet.addPrivateKey(self.memo_key1) stm.wallet.addPrivateKey(self.posting_key1) - self.active_private_key_of_steemfiles = '5HvwMUj7phRn6JeWi8HNHC9FuNEhaATt3PHWZoKPXouvb4wBmz1' - self.active_private_key_of_elf = '5JeUg6eXYLKqESf2dyP8bshK3YZGKo4UCsvZAP4GW9yDrxzySSK' - stm.wallet.addPrivateKey(self.active_private_key_of_steemfiles) - stm.wallet.addPrivateKey(self.active_private_key_of_elf) + self.active_private_key_of_beem4 = '5JkZZEUWrDsu3pYF7aknSo7BLJx7VfxB3SaRtQaHhsPouDYjxzi' + self.active_private_key_of_beem5 = '5Hvbm9VjRbd1B3ft8Lm81csaqQudwFwPGdiRKrCmTKcomFS3Z9J' + stm.wallet.addPrivateKey(self.active_private_key_of_beem4) + stm.wallet.addPrivateKey(self.active_private_key_of_beem5) @classmethod def tearDownClass(cls): @@ -98,15 +98,15 @@ class Testcases(unittest.TestCase): priv_key = stm.wallet.getKeyForAccount("beem1", "posting") self.assertEqual(str(priv_key), self.posting_key1) - priv_key = stm.wallet.getPrivateKeyForPublicKey(str(PrivateKey(self.active_private_key_of_steemfiles, prefix=stm.prefix).pubkey)) - self.assertEqual(str(priv_key), self.active_private_key_of_steemfiles) - priv_key = stm.wallet.getKeyForAccount("steemfiles", "active") - self.assertEqual(str(priv_key), self.active_private_key_of_steemfiles) + priv_key = stm.wallet.getPrivateKeyForPublicKey(str(PrivateKey(self.active_private_key_of_beem4, prefix=stm.prefix).pubkey)) + self.assertEqual(str(priv_key), self.active_private_key_of_beem4) + priv_key = stm.wallet.getKeyForAccount("beem4", "active") + self.assertEqual(str(priv_key), self.active_private_key_of_beem4) - priv_key = stm.wallet.getPrivateKeyForPublicKey(str(PrivateKey(self.active_private_key_of_elf, prefix=stm.prefix).pubkey)) - self.assertEqual(str(priv_key), self.active_private_key_of_elf) - priv_key = stm.wallet.getKeyForAccount("elf", "active") - self.assertEqual(str(priv_key), self.active_private_key_of_elf) + priv_key = stm.wallet.getPrivateKeyForPublicKey(str(PrivateKey(self.active_private_key_of_beem5, prefix=stm.prefix).pubkey)) + self.assertEqual(str(priv_key), self.active_private_key_of_beem5) + priv_key = stm.wallet.getKeyForAccount("beem5", "active") + self.assertEqual(str(priv_key), self.active_private_key_of_beem5) def test_transfer(self): bts = self.bts @@ -115,7 +115,7 @@ class Testcases(unittest.TestCase): # bts.prefix ="STX" acc = Account("beem", steem_instance=bts) tx = acc.transfer( - "test1", 1.33, "SBD", memo="Foobar") + "beem1", 1.33, "SBD", memo="Foobar") self.assertEqual( tx["operations"][0][0], "transfer" @@ -124,7 +124,7 @@ class Testcases(unittest.TestCase): op = tx["operations"][0][1] self.assertIn("memo", op) self.assertEqual(op["from"], "beem") - self.assertEqual(op["to"], "test1") + self.assertEqual(op["to"], "beem1") amount = Amount(op["amount"], steem_instance=bts) self.assertEqual(float(amount), 1.33) bts.nobroadcast = True @@ -135,7 +135,7 @@ class Testcases(unittest.TestCase): bts.wallet.unlock("123") acc = Account("beem", steem_instance=bts) tx = acc.transfer( - "test1", 1.33, "SBD", memo="#Foobar") + "beem1", 1.33, "SBD", memo="#Foobar") self.assertEqual( tx["operations"][0][0], "transfer" @@ -148,7 +148,7 @@ class Testcases(unittest.TestCase): self.assertEqual(memo, "Foobar") self.assertEqual(op["from"], "beem") - self.assertEqual(op["to"], "test1") + self.assertEqual(op["to"], "beem1") amount = Amount(op["amount"], steem_instance=bts) self.assertEqual(float(amount), 1.33) bts.nobroadcast = True @@ -158,7 +158,7 @@ class Testcases(unittest.TestCase): steem.nobroadcast = False tx = TransactionBuilder(steem_instance=steem) tx.appendOps(Transfer(**{"from": 'beem', - "to": 'leprechaun', + "to": 'beem1', "amount": '0.01 SBD', "memo": '1 of 1 transaction'})) self.assertEqual( @@ -173,70 +173,70 @@ class Testcases(unittest.TestCase): steem.nobroadcast = True def test_transfer_2of2_simple(self): - # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send funds + # Send a 2 of 2 transaction from elf which needs beem4's cosign to send funds steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(steem_instance=steem) - tx.appendOps(Transfer(**{"from": 'elf', - "to": 'leprechaun', + tx.appendOps(Transfer(**{"from": 'beem5', + "to": 'beem1', "amount": '0.01 SBD', "memo": '2 of 2 simple transaction'})) - tx.appendWif(self.active_private_key_of_elf) + tx.appendWif(self.active_private_key_of_beem5) tx.sign() tx.clearWifs() - tx.appendWif(self.active_private_key_of_steemfiles) + tx.appendWif(self.active_private_key_of_beem4) tx.sign(reconstruct_tx=False) self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True def test_transfer_2of2_wallet(self): - # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send - # priv key of elf and steemfiles are stored in the wallet + # Send a 2 of 2 transaction from elf which needs beem4's cosign to send + # priv key of elf and beem4 are stored in the wallet # appendSigner fetches both keys and signs automatically with both keys. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") tx = TransactionBuilder(steem_instance=steem) - tx.appendOps(Transfer(**{"from": 'elf', - "to": 'leprechaun', + tx.appendOps(Transfer(**{"from": 'beem5', + "to": 'beem1', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction'})) - tx.appendSigner("elf", "active") + tx.appendSigner("beem5", "active") tx.sign() self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True def test_transfer_2of2_serialized_deserialized(self): - # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send - # funds but sign the transaction with elf's key and then serialize the transaction - # and deserialize the transaction. After that, sign with steemfiles's key. + # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send + # funds but sign the transaction with beem5's key and then serialize the transaction + # and deserialize the transaction. After that, sign with beem4's key. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") - steem.wallet.removeAccount("steemfiles") + steem.wallet.removeAccount("beem4") tx = TransactionBuilder(steem_instance=steem) - tx.appendOps(Transfer(**{"from": 'elf', - "to": 'leprechaun', + tx.appendOps(Transfer(**{"from": 'beem5', + "to": 'beem1', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction'})) - tx.appendSigner("elf", "active") - tx.addSigningInformation("elf", "active") + tx.appendSigner("beem5", "active") + tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) - steem.wallet.removeAccount("elf") + steem.wallet.removeAccount("beem5") tx_json = tx.json() del tx new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem) self.assertEqual(len(new_tx['signatures']), 1) - steem.wallet.addPrivateKey(self.active_private_key_of_steemfiles) + steem.wallet.addPrivateKey(self.active_private_key_of_beem4) new_tx.appendMissingSignatures() new_tx.sign(reconstruct_tx=False) self.assertEqual(len(new_tx['signatures']), 2) @@ -244,54 +244,54 @@ class Testcases(unittest.TestCase): steem.nobroadcast = True def test_transfer_2of2_offline(self): - # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send - # funds but sign the transaction with elf's key and then serialize the transaction - # and deserialize the transaction. After that, sign with steemfiles's key. + # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send + # funds but sign the transaction with beem5's key and then serialize the transaction + # and deserialize the transaction. After that, sign with beem4's key. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") - steem.wallet.removeAccount("steemfiles") + steem.wallet.removeAccount("beem4") tx = TransactionBuilder(steem_instance=steem) - tx.appendOps(Transfer(**{"from": 'elf', - "to": 'leprechaun', + tx.appendOps(Transfer(**{"from": 'beem5', + "to": 'beem', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction'})) - tx.appendSigner("elf", "active") - tx.addSigningInformation("elf", "active") + tx.appendSigner("beem5", "active") + tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) - steem.wallet.removeAccount("elf") - steem.wallet.addPrivateKey(self.active_private_key_of_steemfiles) + steem.wallet.removeAccount("beem5") + steem.wallet.addPrivateKey(self.active_private_key_of_beem4) tx.appendMissingSignatures() tx.sign(reconstruct_tx=False) self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True - steem.wallet.addPrivateKey(self.active_private_key_of_elf) + steem.wallet.addPrivateKey(self.active_private_key_of_beem5) def test_transfer_2of2_wif(self): nodelist = NodeList() - # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send + # Send a 2 of 2 transaction from elf which needs beem4's cosign to send # funds but sign the transaction with elf's key and then serialize the transaction - # and deserialize the transaction. After that, sign with steemfiles's key. + # and deserialize the transaction. After that, sign with beem4's key. steem = Steem( node=nodelist.get_testnet(), num_retries=10, - keys=[self.active_private_key_of_elf], + keys=[self.active_private_key_of_beem5], expiration=360, ) tx = TransactionBuilder(steem_instance=steem) - tx.appendOps(Transfer(**{"from": 'elf', - "to": 'leprechaun', + tx.appendOps(Transfer(**{"from": 'beem5', + "to": 'beem', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction'})) - tx.appendSigner("elf", "active") - tx.addSigningInformation("elf", "active") + tx.appendSigner("beem5", "active") + tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) @@ -302,7 +302,7 @@ class Testcases(unittest.TestCase): steem = Steem( node=nodelist.get_testnet(), num_retries=10, - keys=[self.active_private_key_of_steemfiles], + keys=[self.active_private_key_of_beem4], expiration=360, ) new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem) @@ -316,7 +316,7 @@ class Testcases(unittest.TestCase): stm.wallet.unlock("123") tx = TransactionBuilder(steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", - "to": "test1", + "to": "beem1", "amount": "1.33 STEEM", "memo": "Foobar"})) account = Account("beem", steem_instance=stm) @@ -343,8 +343,8 @@ class Testcases(unittest.TestCase): memo_key=format(key4.pubkey, core_unit), additional_owner_keys=[format(key5.pubkey, core_unit)], additional_active_keys=[format(key5.pubkey, core_unit)], - additional_owner_accounts=["test1"], # 1.2.0 - additional_active_accounts=["test1"], + additional_owner_accounts=["beem1"], # 1.2.0 + additional_active_accounts=["beem1"], storekeys=False ) self.assertEqual( @@ -360,7 +360,7 @@ class Testcases(unittest.TestCase): format(key5.pubkey, core_unit), [x[0] for x in op[role]["key_auths"]]) self.assertIn( - "test1", + "beem1", [x[0] for x in op[role]["account_auths"]]) role = "owner" self.assertIn( @@ -370,7 +370,7 @@ class Testcases(unittest.TestCase): format(key5.pubkey, core_unit), [x[0] for x in op[role]["key_auths"]]) self.assertIn( - "test1", + "beem1", [x[0] for x in op[role]["account_auths"]]) self.assertEqual( op["creator"], @@ -403,9 +403,9 @@ class Testcases(unittest.TestCase): tx2 = bts.new_tx() acc = Account("beem", steem_instance=bts) - acc.transfer("test1", 1, "STEEM", append_to=tx1) - acc.transfer("test1", 2, "STEEM", append_to=tx2) - acc.transfer("test1", 3, "STEEM", append_to=tx1) + acc.transfer("beem1", 1, "STEEM", append_to=tx1) + acc.transfer("beem1", 2, "STEEM", append_to=tx2) + acc.transfer("beem1", 3, "STEEM", append_to=tx1) tx1 = tx1.json() tx2 = tx2.json() ops1 = tx1["operations"] @@ -495,14 +495,14 @@ class Testcases(unittest.TestCase): def test_approvewitness(self): bts = self.bts w = Account("beem", steem_instance=bts) - tx = w.approvewitness("test1") + tx = w.approvewitness("beem1") self.assertEqual( (tx["operations"][0][0]), "account_witness_vote" ) op = tx["operations"][0][1] self.assertIn( - "test1", + "beem1", op["witness"]) def test_appendWif(self): @@ -513,7 +513,7 @@ class Testcases(unittest.TestCase): num_retries=10) tx = TransactionBuilder(steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", - "to": "test1", + "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) with self.assertRaises( @@ -537,7 +537,7 @@ class Testcases(unittest.TestCase): num_retries=10) tx = TransactionBuilder(steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", - "to": "test1", + "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) account = Account("beem", steem_instance=stm) @@ -559,10 +559,10 @@ class Testcases(unittest.TestCase): num_retries=10) tx = TransactionBuilder(steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", - "to": "test1", + "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) - account = Account("test", steem_instance=stm) + account = Account("beem2", steem_instance=stm) tx.appendSigner(account, "active") tx.appendWif(self.posting_key) self.assertTrue(len(tx.wifs) > 0) @@ -583,7 +583,7 @@ class Testcases(unittest.TestCase): tx = TransactionBuilder(expiration=10, steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", - "to": "test1", + "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) tx.appendSigner("beem", "active") @@ -593,7 +593,7 @@ class Testcases(unittest.TestCase): def test_TransactionConstructor(self): stm = self.bts opTransfer = Transfer(**{"from": "beem", - "to": "test1", + "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""}) tx1 = TransactionBuilder(steem_instance=stm)