From 1ff3f2f4938146327fe063ecc76a980898f1e390 Mon Sep 17 00:00:00 2001 From: Holger Nahrstaedt <holger@nahrstaedt.de> Date: Fri, 11 May 2018 22:33:49 +0200 Subject: [PATCH] Bug fixes, use_condenser is set to False again --- beem/blockchain.py | 6 +-- beem/comment.py | 4 +- beemgrapheneapi/graphenerpc.py | 6 ++- tests/beem/test_account.py | 5 +- tests/beem/test_amount.py | 1 + tests/beem/test_blockchain.py | 8 +++- tests/beem/test_blockchain_batch.py | 11 ++++- tests/beem/test_comment.py | 5 +- tests/beem/test_golos.py | 73 ----------------------------- 9 files changed, 33 insertions(+), 86 deletions(-) delete mode 100644 tests/beem/test_golos.py diff --git a/beem/blockchain.py b/beem/blockchain.py index 7410ec39..a50ac179 100644 --- a/beem/blockchain.py +++ b/beem/blockchain.py @@ -464,10 +464,10 @@ class Blockchain(object): if len(op_type) > 10 and op_type[len(op_type) - 10:] == "_operation": op_type = op_type[:-10] op = event["value"] - trx_id = event.get("trx_id") - block_num = event.get("block") + trx_id = block["transaction_ids"][trx_nr] + block_num = block.get("id") _id = self.hash_op(event) - timestamp = formatTimeString(event.get("timestamp")) + timestamp = formatTimeString(block.get("timestamp")) else: op_type, op = event["op"] trx_id = event.get("trx_id") diff --git a/beem/comment.py b/beem/comment.py index 182c1311..3a45eabc 100644 --- a/beem/comment.py +++ b/beem/comment.py @@ -482,7 +482,7 @@ class Comment(BlockchainObject): """ if self.get('net_rshares', None) is None: raise VotingInvalidOnArchivedPost - return self.vote(weight, voter=voter) + return self.vote(weight, account=voter) def downvote(self, weight=-100, voter=None): """ Downvote the post @@ -494,7 +494,7 @@ class Comment(BlockchainObject): """ if self.get('net_rshares', None) is None: raise VotingInvalidOnArchivedPost - return self.vote(weight, voter=voter) + return self.vote(weight, account=voter) def vote(self, weight, account=None, identifier=None, **kwargs): """ Vote for a post diff --git a/beemgrapheneapi/graphenerpc.py b/beemgrapheneapi/graphenerpc.py index 43a36c7d..3d7ad148 100644 --- a/beemgrapheneapi/graphenerpc.py +++ b/beemgrapheneapi/graphenerpc.py @@ -148,7 +148,7 @@ class GrapheneRPC(object): self.rpc_queue = [] self.timeout = kwargs.get('timeout', 60) self.num_retries = kwargs.get("num_retries", -1) - self.use_condenser = kwargs.get("use_condenser", True) + self.use_condenser = kwargs.get("use_condenser", False) self.error_cnt = {} self.num_retries_call = kwargs.get("num_retries_call", 5) self.error_cnt_call = 0 @@ -275,7 +275,9 @@ class GrapheneRPC(object): if v["chain_id"] == chain_id and v["min_version"] <= network_version: if highest_version_chain is None: highest_version_chain = v - elif v["min_version"] > highest_version_chain["min_version"]: + elif v["min_version"] == '0.0.0' and self.use_condenser: + highest_version_chain = v + elif v["min_version"] > highest_version_chain["min_version"] and not self.use_condenser: highest_version_chain = v if highest_version_chain is None: raise("Connecting to unknown network!") diff --git a/tests/beem/test_account.py b/tests/beem/test_account.py index c8831072..e7f5719e 100644 --- a/tests/beem/test_account.py +++ b/tests/beem/test_account.py @@ -442,11 +442,12 @@ class Testcases(unittest.TestCase): def test_json_export(self, node_param): if node_param == "non_appbase": account = self.account - content = self.bts.rpc.get_accounts([account["name"]])[0] else: account = self.account_appbase + if account.steem.rpc.get_use_appbase(): content = self.appbase.rpc.find_accounts({'accounts': [account["name"]]}, api="database")["accounts"][0] - + else: + content = self.bts.rpc.get_accounts([account["name"]])[0] keys = list(content.keys()) json_content = account.json() diff --git a/tests/beem/test_amount.py b/tests/beem/test_amount.py index e0bc036a..4bc20a53 100644 --- a/tests/beem/test_amount.py +++ b/tests/beem/test_amount.py @@ -23,6 +23,7 @@ class Testcases(unittest.TestCase): cls.appbase = Steem( node=get_node_list(appbase=True), nobroadcast=True, + use_condenser=False, num_retries=10 ) set_shared_steem_instance(cls.bts) diff --git a/tests/beem/test_blockchain.py b/tests/beem/test_blockchain.py index e223e847..c278a9a2 100644 --- a/tests/beem/test_blockchain.py +++ b/tests/beem/test_blockchain.py @@ -202,8 +202,14 @@ class Testcases(unittest.TestCase): for block in ops_blocks: for tran in block["transactions"]: for op in tran['operations']: - if op[0] in opNames: + if isinstance(op, list) and op[0] in opNames: op_stat4[op[0]] += 1 + elif isinstance(op, dict): + op_type = op["type"] + if len(op_type) > 10 and op_type[len(op_type) - 10:] == "_operation": + op_type = op_type[:-10] + if op_type in opNames: + op_stat4[op_type] += 1 self.assertTrue(block.identifier >= self.start) self.assertTrue(block.identifier <= self.stop) self.assertEqual(op_stat["transfer"], op_stat4["transfer"]) diff --git a/tests/beem/test_blockchain_batch.py b/tests/beem/test_blockchain_batch.py index 7746c04e..18891fd1 100644 --- a/tests/beem/test_blockchain_batch.py +++ b/tests/beem/test_blockchain_batch.py @@ -22,9 +22,10 @@ class Testcases(unittest.TestCase): @classmethod def setUpClass(cls): cls.bts = Steem( - node=get_node_list(appbase=True, testing=False), + node=get_node_list(appbase=True, testing=True), nobroadcast=True, num_retries=10, + use_condenser=False, keys={"active": wif}, ) # from getpass import getpass @@ -55,7 +56,13 @@ class Testcases(unittest.TestCase): for block in ops_blocks: for tran in block["transactions"]: for op in tran['operations']: - if op[0] in opNames: + if isinstance(op, dict) and "type" in op and "value" in op: + op_type = op["type"] + if len(op_type) > 10 and op_type[len(op_type) - 10:] == "_operation": + op_type = op_type[:-10] + if op_type in opNames: + op_stat4[op_type] += 1 + elif op[0] in opNames: op_stat4[op[0]] += 1 self.assertTrue(block.identifier >= self.start) self.assertTrue(block.identifier <= self.stop) diff --git a/tests/beem/test_comment.py b/tests/beem/test_comment.py index b36b2b98..4eb831c1 100644 --- a/tests/beem/test_comment.py +++ b/tests/beem/test_comment.py @@ -138,10 +138,13 @@ class Testcases(unittest.TestCase): def test_export(self, node_param): if node_param == "non_appbase": bts = self.bts - content = bts.rpc.get_content(self.author, self.permlink) else: bts = self.appbase + + if bts.rpc.get_use_appbase(): content = bts.rpc.get_discussion({'author': self.author, 'permlink': self.permlink}, api="tags") + else: + content = bts.rpc.get_content(self.author, self.permlink) c = Comment(self.authorperm, steem_instance=bts) keys = list(content.keys()) diff --git a/tests/beem/test_golos.py b/tests/beem/test_golos.py deleted file mode 100644 index 06d78016..00000000 --- a/tests/beem/test_golos.py +++ /dev/null @@ -1,73 +0,0 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals -from builtins import range -from builtins import super -import mock -import string -import unittest -import random -from pprint import pprint -from beem import Steem -from beem.amount import Amount -from beem.witness import Witness -from beem.account import Account -from beem.instance import set_shared_steem_instance -from beem.blockchain import Blockchain -from beem.block import Block -from beem.wallet import Wallet -from beemgraphenebase.account import PasswordKey, PrivateKey, PublicKey -from beem.utils import parse_time, formatTimedelta, get_node_list -from beemgrapheneapi.rpcutils import NumRetriesReached - -# Py3 compatibility -import sys -wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" -core_unit = "GLS" - - -class Testcases(unittest.TestCase): - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - set_shared_steem_instance(None) - self.stm = Steem( - node=get_node_list(appbase=False), - nobroadcast=True, - bundle=False, - # Overwrite wallet to use this list of wifs only - wif={"active": wif}, - num_retries=10 - ) - self.bts = Steem( - node=["wss://ws.golos.io"], - keys={"active": wif, "owner": wif, "posting": wif}, - nobroadcast=True, - num_retries=10 - ) - # from getpass import getpass - # self.bts.wallet.unlock(getpass()) - - def test_connect(self): - bts = self.bts - self.assertEqual(bts.prefix, "GLS") - - def test_weight_threshold(self): - bts = self.bts - auth = {'account_auths': [['test', 1]], - 'extensions': [], - 'key_auths': [ - ['GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n', 1], - ['GLS7GM9YXcsoAJAgKbqW2oVj7bnNXFNL4pk9NugqKWPmuhoEDbkDv', 1]], - 'weight_threshold': 3} # threshold fine - bts._test_weights_treshold(auth) - auth = {'account_auths': [['test', 1]], - 'extensions': [], - 'key_auths': [ - ['GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n', 1], - ['GLS7GM9YXcsoAJAgKbqW2oVj7bnNXFNL4pk9NugqKWPmuhoEDbkDv', 1]], - 'weight_threshold': 4} # too high - - with self.assertRaises(ValueError): - bts._test_weights_treshold(auth) -- GitLab