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

Code and coverage improments part II

parent fba87a07
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ jobs:
- run:
name: run tests
command: |
tox -e py36,pyflakes,coverage
tox -e py36,pylint
- deploy:
name: Push coverage
......
This diff is collapsed.
[run]
branch = True
source =
beem
beembase
beemapi
beemgrapheneapi
beemgraphenebase
beem/
beembase/
beemapi/
beemgrapheneapi/
beemgraphenebase/
omit =
*/.eggs/*
*/.tox/*
......@@ -17,10 +17,10 @@ omit =
[paths]
source =
beem
beembase
beemapi
beemgrapheneapi
beemgraphenebase
beem/
beembase/
beemapi/
beemgrapheneapi/
beemgraphenebase/
.tox/*/lib/python*/site-packages/beem
.tox/pypy/site-packages/beem
......@@ -124,7 +124,8 @@ class TransactionBuilder(dict):
""" Try to obtain the wif key from the wallet by telling which account
and permission is supposed to sign the transaction
"""
assert permission in ["active", "owner", "posting"], "Invalid permission"
if permission not in ["active", "owner", "posting"]:
raise AssertionError("Invalid permission")
account = Account(account, steem_instance=self.steem)
if permission not in account:
account = Account(account, steem_instance=self.steem, lazy=False, full=True)
......@@ -132,7 +133,8 @@ class TransactionBuilder(dict):
account.refresh()
if permission not in account:
account = Account(account, steem_instance=self.steem)
assert permission in account, "Could not access permission"
if permission not in account:
raise AssertionError("Could not access permission")
required_treshold = account[permission]["weight_threshold"]
......
......@@ -216,7 +216,8 @@ def decode_memo(priv, message):
aes, checksum = init_aes(shared_secret, nonce)
# Check
assert check == checksum, "Checksum failure"
if not check == checksum:
raise AssertionError("Checksum failure")
# Encryption
# remove the varint prefix (FIXME, long messages!)
......
......@@ -122,7 +122,8 @@ class BrainKey(object):
word_count = 16
brainkey = [None] * word_count
dict_lines = BrainKeyDictionary.split(',')
assert len(dict_lines) == 49744
if not len(dict_lines) == 49744:
raise AssertionError()
for j in range(0, word_count):
num = int.from_bytes(os.urandom(2), byteorder="little")
rndMult = num / 2 ** 16 # returns float between 0..1 (inclusive)
......@@ -256,7 +257,8 @@ class PublicKey(Address):
prefix = public_key[0:2]
if prefix == "04":
return public_key
assert prefix == "02" or prefix == "03"
if not (prefix == "02" or prefix == "03"):
raise AssertionError()
x = int(public_key[2:], 16)
y = self._derive_y_from_x(x, (prefix == "02"))
key = '04' + '%064x' % x + '%064x' % y
......
......@@ -184,7 +184,8 @@ def base58CheckDecode(s):
s = unhexlify(base58decode(s))
dec = hexlify(s[:-4]).decode('ascii')
checksum = doublesha256(dec)[:4]
assert(s[-4:] == checksum)
if not (s[-4:] == checksum):
raise AssertionError()
return dec[2:]
......@@ -198,5 +199,6 @@ def gphBase58CheckDecode(s):
s = unhexlify(base58decode(s))
dec = hexlify(s[:-4]).decode('ascii')
checksum = ripemd160(dec)[:4]
assert(s[-4:] == checksum)
if not (s[-4:] == checksum):
raise AssertionError()
return dec
......@@ -113,7 +113,8 @@ def sign_message(message, wif, hashfn=hashlib.sha256):
secp256k1.ffi.NULL,
ndata
)
assert signed == 1
if not signed == 1:
raise AssertionError()
signature, i = privkey.ecdsa_recoverable_serialize(sig)
if _is_canonical(signature):
i += 4 # compressed
......@@ -177,8 +178,10 @@ def verify_message(message, signature, hashfn=hashlib.sha256):
message = py23_bytes(message, "utf-8")
if not isinstance(signature, bytes_types):
signature = py23_bytes(signature, "utf-8")
assert isinstance(message, bytes_types)
assert isinstance(signature, bytes_types)
if not isinstance(message, bytes_types):
raise AssertionError()
if not isinstance(signature, bytes_types):
raise AssertionError()
digest = hashfn(message).digest()
sig = signature[1:]
recoverParameter = bytearray(signature)[0] - 4 - 27 # recover parameter only
......
......@@ -102,7 +102,8 @@ class Signed_Transaction(GrapheneObject):
s, junk = ecdsa.der.remove_sequence(unhexlify(s))
if junk:
log.debug('JUNK: %s', hexlify(junk).decode('ascii'))
assert(junk == b'')
if not (junk == b''):
raise AssertionError()
x, s = ecdsa.der.remove_integer(s)
y, s = ecdsa.der.remove_integer(s)
return '%064x%064x' % (x, y)
......
......@@ -6,6 +6,7 @@ from __future__ import unicode_literals
from builtins import str
from builtins import bytes
from builtins import object
from builtins import int
from future.utils import python_2_unicode_compatible
import json
import struct
......@@ -349,7 +350,8 @@ class Id(object):
class VoteId(object):
def __init__(self, vote):
parts = vote.split(":")
assert len(parts) == 2
if not len(parts) == 2:
raise AssertionError()
self.type = int(parts[0])
self.instance = int(parts[1])
......@@ -373,10 +375,10 @@ class ObjectId(object):
self.instance = Id(int(id))
self.Id = object_str
if type_verify:
assert object_type[type_verify] == int(type),\
"Object id does not match object type! " +\
"Excpected %d, got %d" %\
(object_type[type_verify], int(type))
if not object_type[type_verify] == int(type):
raise AssertionError("Object id does not match object type! " +\
"Excpected %d, got %d" %\
(object_type[type_verify], int(type)))
else:
raise Exception("Object id is invalid")
......@@ -414,10 +416,10 @@ class FullObjectId(object):
@python_2_unicode_compatible
class Enum8(Uint8):
def __init__(self, selection):
assert selection in self.options or \
isinstance(selection, int) and len(self.options) < selection, \
"Options are %s. Given '%s'" % (
self.options, selection)
if selection not in self.options and \
not (isinstance(selection, int) and len(self.options) < selection):
raise AssertionError("Options are %s. Given '%s'" % (
self.options, selection))
if selection in self.options:
super(Enum8, self).__init__(self.options.index(selection))
else:
......
graphenelib
bitshares
autobahn>=0.14
pycryptodome==3.4.6
appdirs==1.4.0
\ No newline at end of file
future
ecdsa
requests
websocket-client
pytz
pycryptodomex>=3.4.6
scrypt>=0.7.1
Events>=0.2.2
pyyaml
pytest
pytest-mock
coverage
mock
appdirs
Click
prettytable
......@@ -3,7 +3,6 @@
import os
import sys
import io
import subprocess
from setuptools import setup
# Work around mbcs bug in distutils.
......@@ -19,7 +18,7 @@ VERSION = '0.19.11'
tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock']
requires = [
requires = [
"future",
"ecdsa",
"requests",
......@@ -52,7 +51,6 @@ def get_long_description():
return '\n\n'.join(descr)
if __name__ == '__main__':
# Rewrite the version file everytime
......
......@@ -3,6 +3,7 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from builtins import str
import unittest
from beemgraphenebase.base58 import Base58
from beemgraphenebase.account import BrainKey, Address, PublicKey, PrivateKey, PasswordKey
......
......@@ -12,7 +12,6 @@ from beem.account import Account
from beem.amount import Amount
from beem.asset import Asset
from beem.instance import set_shared_steem_instance
from beembase.operationids import getOperationNameForId
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
nodes = ["wss://steemd.pevo.science", "wss://gtg.steem.house:8090", "wss://rpc.steemliberator.com", "wss://rpc.buildteam.io",
......
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from builtins import super
import unittest
from pprint import pprint
from beem import Steem
from beem.block import Block
from datetime import datetime
from beem.instance import set_shared_steem_instance
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
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"]
class Testcases(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bts = Steem(
node=nodes,
nobroadcast=True,
keys={"active": wif},
)
# from getpass import getpass
# self.bts.wallet.unlock(getpass())
set_shared_steem_instance(self.bts)
self.bts.set_default_account("test")
def test_block(self):
bts = self.bts
block = Block(1, steem_instance=bts)
self.assertEqual(block.identifier, 1)
self.assertTrue(isinstance(block.time(), datetime))
block2 = Block(2, steem_instance=bts)
self.assertTrue(block2.time() > block.time())
block2.change_block_number(3)
self.assertEqual(block2.identifier, 3)
def test_block_ops(self):
bts = self.bts
block = Block(20000000, steem_instance=bts)
self.assertTrue(len(block.ops))
self.assertTrue(isinstance(block.ops_statistics(), dict))
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from builtins import super
import unittest
from pprint import pprint
from beem import Steem
from beem.blockchain import Blockchain
from beem.block import Block
from datetime import datetime
from beem.instance import set_shared_steem_instance
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
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"]
class Testcases(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bts = Steem(
node=nodes,
nobroadcast=True,
keys={"active": wif},
)
# from getpass import getpass
# self.bts.wallet.unlock(getpass())
set_shared_steem_instance(self.bts)
self.bts.set_default_account("test")
def test_blockchain(self):
bts = self.bts
b = Blockchain(steem_instance=bts)
num = b.get_current_block_num()
self.assertTrue(num > 0)
block = b.get_current_block()
self.assertTrue(isinstance(block, Block))
self.assertEqual(num, block.identifier)
......@@ -3,11 +3,14 @@ envlist = py{27,34,35,36,37},lint,pyflakes
skip_missing_interpreters = true
[testenv]
deps=-rrequirements-test.txt
commands=
coverage run -a setup.py test
coverage report --show-missing --ignore-errors
coverage html -i
deps =
mock>=2.0.0
pytest
coverage
commands =
coverage run --parallel-mode -m pytest {posargs}
coverage combine
coverage report -m
coverage xml
[testenv:flake8]
......@@ -82,12 +85,6 @@ deps=-rdocs/requirements.txt
commands=
sphinx-build -b html ./ ./html
[testenv:coverage]
deps=-rrequirements-test.txt
commands =
{envpython} -m coverage run -a setup.py test
{envpython} -m coverage xml
[testenv:upload_coverage]
deps = coverage
passenv = CODACY_PROJECT_TOKEN
......
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