Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
Bandit passes now, added to travis
Bugfix in chain detection
  • Loading branch information
holgern committed Mar 8, 2018
1 parent bb09a10 commit 8804bf3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Expand Up @@ -13,6 +13,14 @@ matrix:
python: 3.6
env:
- TOXENV=flake8
- os: linux
python: 3.6
env:
- TOXENV=bandit
- os: linux
python: 3.6
env:
- TOXENV=readme
- os: linux
python: 2.7
env:
Expand Down
2 changes: 1 addition & 1 deletion beem/asset.py
Expand Up @@ -41,7 +41,7 @@ def __init__(
)
self.refresh()
if "asset" not in self or self["asset"] is None or len(self["asset"]) == 0:
raise AssetDoesNotExistsException(self.identifier+" "+self.steem.chain_params["chain_assets"])
raise AssetDoesNotExistsException(self.identifier + " chain_assets:" + str(self.steem.chain_params["chain_assets"]))

def refresh(self):
""" Refresh the data from the API server
Expand Down
2 changes: 1 addition & 1 deletion beem/transactionbuilder.py
Expand Up @@ -150,7 +150,7 @@ def fetchkeys(account, perm, level=0):
wif = self.steem.wallet.getPrivateKeyForPublicKey(
authority[0])
r.append([wif, authority[1]])
except Exception:
except ValueError:
pass

if sum([x[1] for x in r]) < required_treshold:
Expand Down
5 changes: 3 additions & 2 deletions beem/wallet.py
Expand Up @@ -18,6 +18,7 @@
WrongMasterPasswordException,
NoWalletException,
RPCConnectionRequired,
AccountDoesNotExistsException,
)
from beemapi.exceptions import NoAccessApi

Expand Down Expand Up @@ -261,7 +262,7 @@ def decrypt_wif(self, encwif):
# Try to decode as wif
PrivateKey(encwif, prefix=self.prefix)
return encwif
except:
except ValueError:
pass
if self.locked():
raise AssertionError()
Expand Down Expand Up @@ -456,7 +457,7 @@ def getAllAccounts(self, pub):
for name in self.getAccountsFromPublicKey(pub):
try:
account = Account(name, steem_instance=self.steem)
except:
except AccountDoesNotExistsException:
continue
yield {"name": account["name"],
"account": account,
Expand Down
11 changes: 9 additions & 2 deletions beemapi/steemnoderpc.py
Expand Up @@ -105,7 +105,14 @@ def get_network(self):
network_version = props['STEEM_BLOCKCHAIN_VERSION']
else:
raise("Connecting to unknown network!")
highest_version_chain = None
for k, v in list(known_chains.items()):
if v["chain_id"] == chain_id and v["min_version"] <= network_version:
return v
raise("Connecting to unknown network!")
if highest_version_chain is None:
highest_version_chain = v
elif v["min_version"] > highest_version_chain["min_version"]:
highest_version_chain = v
if highest_version_chain is None:
raise("Connecting to unknown network!")
else:
return highest_version_chain
10 changes: 3 additions & 7 deletions beemgrapheneapi/graphenerpc.py
Expand Up @@ -293,6 +293,7 @@ def rpcexec(self, payload):
cnt > self.num_retries):
raise NumRetriesReached()
sleeptime = (cnt - 1) * 2 if cnt < 10 else 10
self.rpcclose()
if sleeptime:
log.warning(
"Lost connection to node during rpcexec(): %s (%d/%d) "
Expand All @@ -302,13 +303,8 @@ def rpcexec(self, payload):
time.sleep(sleeptime)

# retry
try:
self.rpcclose()
time.sleep(sleeptime)
self.rpcconnect()
self.register_apis()
except Exception:
pass
self.rpcconnect()
self.register_apis()

ret = {}
try:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_steemnoderpc.py
Expand Up @@ -12,6 +12,7 @@
import itertools
from pprint import pprint
from beem import Steem
from beemapi.steemnoderpc import SteemNodeRPC
from beemapi.websocket import SteemWebsocket
from beemapi import exceptions
from beem.instance import set_shared_steem_instance
Expand All @@ -24,6 +25,8 @@
"wss://rpc.steemviz.com", "wss://seed.bitcoiner.me", "wss://node.steem.ws", "wss://steemd.steemgigs.org", "wss://steemd.steemit.com",
"wss://steemd.minnowsupportproject.org"]
nodes_appbase = ["https://api.steemitstage.com", "wss://appbasetest.timcliff.com"]
test_list = ["wss://steemd.doesnot.exists", "wss://api.steemit.com", "wss://steemd.pevo.science", "wss://gtg.steem.house:8090",
"https://api.steemit.com", "https://api.steemitstage.com", "wss://appbasetest.timcliff.com"]


class Testcases(unittest.TestCase):
Expand Down Expand Up @@ -70,3 +73,11 @@ def test_appbase(self):
):
bts.rpc.get_config_abc()
bts.rpc.register_apis(apis=["database"])

def test_connect_test_node(self):
rpc = SteemNodeRPC(urls=test_list)
self.assertIn(rpc.url, nodes + nodes_appbase)
rpc.rpcclose()
rpc.rpcconnect()
rpc.register_apis()
self.assertIn(rpc.url, nodes + nodes_appbase)

0 comments on commit 8804bf3

Please sign in to comment.