From 9717b121292b54cea51ec342b41f243dc43e5934 Mon Sep 17 00:00:00 2001
From: Holger Nahrstaedt <holger@nahrstaedt.de>
Date: Sat, 10 Mar 2018 17:09:44 +0100
Subject: [PATCH] Fix flake8

test_testnet improved
---
 beemgraphenebase/account.py |   2 +-
 examples/benchmark_nodes.py |  18 +++----
 examples/op_on_testnet.py   |  14 ++---
 tests/test_steem.py         |   1 +
 tests/test_testnet.py       |  70 +++++++++++++------------
 tests/test_txbuffers.py     | 100 ++----------------------------------
 6 files changed, 58 insertions(+), 147 deletions(-)

diff --git a/beemgraphenebase/account.py b/beemgraphenebase/account.py
index 51c24eff..9e825df7 100644
--- a/beemgraphenebase/account.py
+++ b/beemgraphenebase/account.py
@@ -39,7 +39,7 @@ class PasswordKey(object):
         """
         a = py23_bytes(self.account + self.role + self.password, 'utf8')
         s = hashlib.sha256(a).digest()
-        return PrivateKey(hexlify(s).decode('ascii'), prefix = self.prefix)
+        return PrivateKey(hexlify(s).decode('ascii'), prefix=self.prefix)
 
     def get_public(self):
         return self.get_private().pubkey
diff --git a/examples/benchmark_nodes.py b/examples/benchmark_nodes.py
index 3a3f438e..27153496 100644
--- a/examples/benchmark_nodes.py
+++ b/examples/benchmark_nodes.py
@@ -18,14 +18,12 @@ logging.basicConfig(level=logging.INFO)
 
 nodes = ["wss://steemd.pevo.science", "wss://gtg.steem.house:8090", "wss://rpc.steemliberator.com", "wss://rpc.buildteam.io",
          "wss://rpc.steemviz.com", "wss://seed.bitcoiner.me", "wss://node.steem.ws", "wss://steemd.steemgigs.org", "wss://steemd.steemit.com",
-         "wss://steemd.minnowsupportproject.org", "https://api.steemitstage.com", "https://api.steemit.com","https://rpc.buildteam.io",
+         "wss://steemd.minnowsupportproject.org", "https://api.steemitstage.com", "https://api.steemit.com", "https://rpc.buildteam.io",
          "https://steemd.minnowsupportproject.org", "https://steemd.pevo.science", "https://rpc.steemviz.com", "https://seed.bitcoiner.me",
          "https://rpc.steemliberator.com", "https://api.steemit.com", "https://steemd.privex.io"]
 
 if __name__ == "__main__":
     how_many_minutes = 10
-
-    
     max_batch_size = None
     threading = False
     thread_num = 16
@@ -34,26 +32,26 @@ if __name__ == "__main__":
         try:
             stm = Steem(node=node, num_retries=2)
             blockchain = Blockchain(steem_instance=stm)
-            
+
             last_block_id = 19273700
             last_block = Block(last_block_id, steem_instance=stm)
             startTime = datetime.now()
-        
+
             stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60)
             ltime = time.time()
             cnt = 0
             total_transaction = 0
-        
+
             start_time = time.time()
             last_node = blockchain.steem.rpc.url
-            
+
             for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num):
                 block_no = entry.identifier
                 if "block" in entry:
                     trxs = entry["block"]["transactions"]
                 else:
                     trxs = entry["transactions"]
-        
+
                 for tx in trxs:
                     for op in tx["operations"]:
                         total_transaction += 1
@@ -61,7 +59,7 @@ if __name__ == "__main__":
                     block_time = parse_time(entry["block"]["timestamp"])
                 else:
                     block_time = parse_time(entry["timestamp"])
-        
+
                 if block_time > stopTime:
                     total_duration = formatTimedelta(datetime.now() - startTime)
                     last_block_id = block_no
@@ -74,5 +72,3 @@ if __name__ == "__main__":
         except Exception as e:
             print("Error: " + str(e))
             continue
-
-
diff --git a/examples/op_on_testnet.py b/examples/op_on_testnet.py
index 1cdcd769..d03f0d00 100644
--- a/examples/op_on_testnet.py
+++ b/examples/op_on_testnet.py
@@ -12,7 +12,7 @@ from beem.blockchain import Blockchain
 from beem.block import Block
 from beem.account import Account
 from beem.amount import Amount
-from beembase.account import PasswordKey, PrivateKey, PublicKey
+from beemgraphenebase.account import PasswordKey, PrivateKey, PublicKey
 from beem.steem import Steem
 from beem.utils import parse_time, formatTimedelta
 from beemgrapheneapi.rpcutils import NumRetriesReached
@@ -25,6 +25,7 @@ password1 = "4JkeGCG3HghMMdwCpHyXpiZqoXbWuv"
 if __name__ == "__main__":
     stm = Steem(node=["wss://testnet.steem.vc"])
     prefix = stm.prefix
+    # curl --data "username=beem&password=yfABsiDXWcCVyDC2udXGYD2psFUiQy" https://testnet.steem.vc/create
     account = Account("beem", steem_instance=stm)
     stm.wallet.purge()
     stm.wallet.create("123")
@@ -42,20 +43,19 @@ if __name__ == "__main__":
     posting_privkey = posting_key.get_private_key()
     owner_privkey = owner_key.get_private_key()
     memo_privkey = memo_key.get_private_key()
-    
+
     stm.wallet.addPrivateKey(owner_privkey)
     stm.wallet.addPrivateKey(active_privkey)
     stm.wallet.addPrivateKey(memo_privkey)
     stm.wallet.addPrivateKey(posting_privkey)
-    
+
     stm.wallet.getAccountFromPrivateKey(str(active_privkey))
 
-    
     # stm.create_account("beem1", creator=account, password=password1)
-    
+
     account1 = Account("beem1", steem_instance=stm)
     b = Blockchain(steem_instance=stm)
     blocknum = b.get_current_block().identifier
-  
+
     account.transfer("beem1", 1, "SBD", "test")
-    b1 = Block(blocknum, steem_instance=stm)    
+    b1 = Block(blocknum, steem_instance=stm)
diff --git a/tests/test_steem.py b/tests/test_steem.py
index 3a27e1b4..4c005d95 100644
--- a/tests/test_steem.py
+++ b/tests/test_steem.py
@@ -64,6 +64,7 @@ class Testcases(unittest.TestCase):
             tx["operations"][0][0],
             "transfer"
         )
+        self.assertEqual(len(tx["operations"]), 1)
         op = tx["operations"][0][1]
         self.assertIn("memo", op)
         self.assertEqual(op["memo"], "Foobar")
diff --git a/tests/test_testnet.py b/tests/test_testnet.py
index c05f38d8..f9fac9cd 100644
--- a/tests/test_testnet.py
+++ b/tests/test_testnet.py
@@ -13,12 +13,17 @@ from beem import Steem
 from beem.amount import Amount
 from beem.witness import Witness
 from beem.account import Account
-from beemgraphenebase.account import PrivateKey
 from beem.instance import set_shared_steem_instance
+from beem.blockchain import Blockchain
+from beem.block import Block
+from beemgraphenebase.account import PasswordKey, PrivateKey, PublicKey
+from beem.utils import parse_time, formatTimedelta
+from beemgrapheneapi.rpcutils import NumRetriesReached
+
 # Py3 compatibility
 import sys
 
-wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
+password = "yfABsiDXWcCVyDC2udXGYD2psFUiQy"
 core_unit = "STX"
 
 
@@ -26,41 +31,52 @@ class Testcases(unittest.TestCase):
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
-        bts = Steem()
-        bts.wallet.purge()
         set_shared_steem_instance(None)
         self.bts = Steem(
             node=["wss://testnet.steem.vc"],
             nobroadcast=True,
-            keys={"active": wif, "owner": wif, "memo": wif},
         )
         # from getpass import getpass
         # self.bts.wallet.unlock(getpass())
         set_shared_steem_instance(self.bts)
-        self.bts.set_default_account("test")
+        self.bts.set_default_account("beem")
+        stm = self.bts
+        stm.wallet.purge()
+        stm.wallet.create("123")
+        stm.wallet.unlock("123")
+        account_name = "beem"
+        active_key = PasswordKey(account_name, password, role="active", prefix=stm.prefix)
+        owner_key = PasswordKey(account_name, password, role="owner", prefix=stm.prefix)
+        posting_key = PasswordKey(account_name, password, role="posting", prefix=stm.prefix)
+        memo_key = PasswordKey(account_name, password, role="memo", prefix=stm.prefix)
+        active_privkey = active_key.get_private_key()
+        posting_privkey = posting_key.get_private_key()
+        owner_privkey = owner_key.get_private_key()
+        memo_privkey = memo_key.get_private_key()
+        stm.wallet.addPrivateKey(owner_privkey)
+        stm.wallet.addPrivateKey(active_privkey)
+        stm.wallet.addPrivateKey(memo_privkey)
+        stm.wallet.addPrivateKey(posting_privkey)
 
     def test_transfer(self):
         bts = self.bts
-        bts.wallet.setKeys({"active": wif, "owner": wif, "memo": wif})
         # bts.prefix ="STX"
-        acc = Account("test", steem_instance=bts)
-        acc.steem = bts
+        acc = Account("beem", steem_instance=bts)
         tx = acc.transfer(
-            "test", 1.33, "SBD", memo="Foobar", account="test1")
+            "test1", 1.33, "SBD", memo="Foobar")
         self.assertEqual(
             tx["operations"][0][0],
             "transfer"
         )
         op = tx["operations"][0][1]
         self.assertIn("memo", op)
-        self.assertEqual(op["from"], "test1")
-        self.assertEqual(op["to"], "test")
+        self.assertEqual(op["from"], "beem")
+        self.assertEqual(op["to"], "test1")
         amount = Amount(op["amount"])
         self.assertEqual(float(amount), 1.33)
 
     def test_create_account(self):
         bts = self.bts
-        bts.wallet.setKeys({"active": wif, "owner": wif, "memo": wif})
         name = ''.join(random.choice(string.ascii_lowercase) for _ in range(12))
         key1 = PrivateKey()
         key2 = PrivateKey()
@@ -69,7 +85,7 @@ class Testcases(unittest.TestCase):
         key5 = PrivateKey()
         tx = bts.create_account(
             name,
-            creator="test",   # 1.2.7
+            creator="beem",
             owner_key=format(key1.pubkey, core_unit),
             active_key=format(key2.pubkey, core_unit),
             posting_key=format(key3.pubkey, core_unit),
@@ -107,7 +123,7 @@ class Testcases(unittest.TestCase):
             [x[0] for x in op[role]["account_auths"]])
         self.assertEqual(
             op["creator"],
-            "test")
+            "beem")
 
     def test_connect(self):
         self.bts.connect(node=["wss://testnet.steem.vc"])
@@ -115,7 +131,7 @@ class Testcases(unittest.TestCase):
         self.assertEqual(bts.prefix, "STX")
 
     def test_set_default_account(self):
-        self.bts.set_default_account("test")
+        self.bts.set_default_account("beem")
 
     def test_info(self):
         info = self.bts.info()
@@ -134,7 +150,7 @@ class Testcases(unittest.TestCase):
         tx1 = bts.new_tx()
         tx2 = bts.new_tx()
 
-        acc = Account("test1", steem_instance=bts)
+        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)
@@ -147,7 +163,6 @@ class Testcases(unittest.TestCase):
 
     def test_weight_threshold(self):
         bts = self.bts
-
         auth = {'account_auths': [['test', 1]],
                 'extensions': [],
                 'key_auths': [
@@ -167,14 +182,12 @@ class Testcases(unittest.TestCase):
 
     def test_allow(self):
         bts = self.bts
-        bts.wallet.setKeys({"active": wif, "owner": wif, "memo": wif})
         self.assertIn(bts.prefix, "STX")
-        acc = Account("test", steem_instance=bts)
-        acc.steem = bts
+        acc = Account("beem", steem_instance=bts)
         self.assertIn(acc.steem.prefix, "STX")
         tx = acc.allow(
             "STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n",
-            account="test",
+            account="beem",
             weight=1,
             threshold=1,
             permission="owner",
@@ -192,9 +205,7 @@ class Testcases(unittest.TestCase):
 
     def test_disallow(self):
         bts = self.bts
-        bts.wallet.setKeys({"active": wif, "owner": wif, "memo": wif})
-        acc = Account("test", steem_instance=bts)
-        acc.steem = bts
+        acc = Account("beem", steem_instance=bts)
         if sys.version > '3':
             _assertRaisesRegex = self.assertRaisesRegex
         else:
@@ -216,11 +227,8 @@ class Testcases(unittest.TestCase):
 
     def test_update_memo_key(self):
         bts = self.bts
-        bts.wallet.setKeys({"active": wif, "owner": wif, "memo": wif})
-        set_shared_steem_instance(bts)
         self.assertEqual(bts.prefix, "STX")
-        acc = Account("test", steem_instance=bts)
-        acc.steem = bts
+        acc = Account("beem", steem_instance=bts)
         tx = acc.update_memo_key("STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n")
         self.assertEqual(
             (tx["operations"][0][0]),
@@ -233,9 +241,7 @@ class Testcases(unittest.TestCase):
 
     def test_approvewitness(self):
         bts = self.bts
-        bts.wallet.setKeys({"active": wif, "owner": wif, "memo": wif})
-        w = Account("test", steem_instance=bts)
-        w.steem = bts
+        w = Account("beem", steem_instance=bts)
         tx = w.approvewitness("test1")
         self.assertEqual(
             (tx["operations"][0][0]),
diff --git a/tests/test_txbuffers.py b/tests/test_txbuffers.py
index 8a899b64..7e5ae1e4 100644
--- a/tests/test_txbuffers.py
+++ b/tests/test_txbuffers.py
@@ -31,102 +31,10 @@ class Testcases(unittest.TestCase):
     def test_appendSigner(self):
         stm = self.stm
         tx = TransactionBuilder(steem_instance=stm)
-        tx.appendOps(Transfer(**{
-                 "from": "test",
-                 "to": "test1",
-                 "amount": "1 STEEM",
-                 "memo": ""
-             }))
+        tx.appendOps(Transfer(**{"from": "test",
+                                 "to": "test1",
+                                 "amount": "1 STEEM",
+                                 "memo": ""}))
         tx.appendWif(wif)
         tx.sign()
         self.assertTrue(len(tx["signatures"]) > 0)
-
-
-"""
-    def test_add_one_proposal_one_op(self):
-        bts = self.bts
-        tx1 = bts.new_tx()
-        proposal1 = bts.new_proposal(tx1, proposer="test")
-        op = operations.Transfer(**{
-            "fee": {"amount": 0, "asset_id": "SBD"},
-            "from": "1.2.0",
-            "to": "1.2.0",
-            "amount": {"amount": 0, "asset_id": "SBD"},
-            "prefix": "TEST"
-        })
-        proposal1.appendOps(op)
-        tx = tx1.json()
-        self.assertEqual(tx["operations"][0][0], 22)
-        self.assertEqual(len(tx["operations"]), 1)
-        ps = tx["operations"][0][1]
-        self.assertEqual(len(ps["proposed_ops"]), 1)
-        self.assertEqual(ps["proposed_ops"][0]["op"][0], 0)
-
-    def test_add_one_proposal_two_ops(self):
-        bts = self.bts
-        tx1 = bts.new_tx()
-        proposal1 = bts.new_proposal(tx1, proposer="test")
-        op = operations.Transfer(**{
-            "fee": {"amount": 0, "asset_id": "SBD"},
-            "from": "1.2.0",
-            "to": "1.2.0",
-            "amount": {"amount": 0, "asset_id": "SBD"},
-            "prefix": "TEST"
-        })
-        proposal1.appendOps(op)
-        proposal1.appendOps(op)
-        tx = tx1.json()
-        self.assertEqual(tx["operations"][0][0], 22)
-        self.assertEqual(len(tx["operations"]), 1)
-        ps = tx["operations"][0][1]
-        self.assertEqual(len(ps["proposed_ops"]), 2)
-        self.assertEqual(ps["proposed_ops"][0]["op"][0], 0)
-        self.assertEqual(ps["proposed_ops"][1]["op"][0], 0)
-
-    def test_have_two_proposals(self):
-        bts = self.bts
-        tx1 = bts.new_tx()
-
-        # Proposal 1
-        proposal1 = bts.new_proposal(tx1, proposer="test")
-        op = operations.Transfer(**{
-            "fee": {"amount": 0, "asset_id": "SBD"},
-            "from": "1.2.0",
-            "to": "1.2.0",
-            "amount": {"amount": 0, "asset_id": "SBD"},
-            "prefix": "TEST"
-        })
-        for i in range(0, 3):
-            proposal1.appendOps(op)
-
-        # Proposal 1
-        proposal2 = bts.new_proposal(tx1, proposer="test")
-        op = operations.Transfer(**{
-            "fee": {"amount": 0, "asset_id": "SBD"},
-            "from": "1.2.0",
-            "to": "1.2.0",
-            "amount": {"amount": 5555555, "asset_id": "SBD"},
-            "prefix": "TEST"
-        })
-        for i in range(0, 2):
-            proposal2.appendOps(op)
-        tx = tx1.json()
-
-        self.assertEqual(len(tx["operations"]), 2)  # 2 proposals
-
-        # Test proposal 1
-        prop = tx["operations"][0]
-        self.assertEqual(prop[0], 22)
-        ps = prop[1]
-        self.assertEqual(len(ps["proposed_ops"]), 3)
-        for i in range(0, 3):
-            self.assertEqual(ps["proposed_ops"][i]["op"][0], 0)
-
-        # Test proposal 2
-        prop = tx["operations"][1]
-        self.assertEqual(prop[0], 22)
-        ps = prop[1]
-        self.assertEqual(len(ps["proposed_ops"]), 2)
-        for i in range(0, 2):
-            self.assertEqual(ps["proposed_ops"][i]["op"][0], 0)
-"""
-- 
GitLab