From 999c6be261a42e793f80d353c742cf9c64c0af39 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Fri, 2 Aug 2019 16:35:46 -0700 Subject: [PATCH] document how to run the tests --- CONTRIBUTING.md | 11 +++++-- binance_transaction/__init__.py | 5 ++++ binance_transaction/base.py | 2 +- binance_transaction/bnb_transaction.py | 8 ++--- binance_transaction/dex.py | 2 +- binance_transaction/exceptions.py | 2 +- binance_transaction/gov.py | 2 +- binance_transaction/msg.py | 10 +++---- binance_transaction/signature.py | 2 +- binance_transaction/tests/test_dex.py | 4 +-- binance_transaction/tests/test_signature.py | 4 +-- binance_transaction/tests/test_token.py | 4 +-- binance_transaction/token.py | 2 +- runtests.py | 33 +++++++++++++++++++++ 14 files changed, 67 insertions(+), 24 deletions(-) create mode 100755 runtests.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4dde81e..77cf355 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,16 +4,21 @@ Start by cloning the repository. git clone git@github.com:trusttoken/bnb-tx-python.git ``` -Install dependencies +### Install dependencies ``` -pipenv install +pipenv install --dev ``` -Run flake8 +### Run flake8 ``` pipenv run flake8 ``` +### Run tests +``` +pipenv run ./runtests.py +``` + # Pull Requests Please try to adhere to the following guidelines. diff --git a/binance_transaction/__init__.py b/binance_transaction/__init__.py index aaa6c42..25d999c 100644 --- a/binance_transaction/__init__.py +++ b/binance_transaction/__init__.py @@ -1 +1,6 @@ +from .bech32 import bech32_encode, address_bytes +from .base import Amino, Repeated, String, Address, StringVarInt, StringToken, Token, VarInt, make_prefix +from .crypto import uncompress_key, compress_key, verify_sig + + name = "binance_transaction" diff --git a/binance_transaction/base.py b/binance_transaction/base.py index 2473e25..4a9a9d9 100644 --- a/binance_transaction/base.py +++ b/binance_transaction/base.py @@ -1,6 +1,6 @@ import base64 -from .bech32 import bech32_encode, address_bytes +from binance_transaction.bech32 import bech32_encode, address_bytes """ diff --git a/binance_transaction/bnb_transaction.py b/binance_transaction/bnb_transaction.py index a47544a..3eb5428 100644 --- a/binance_transaction/bnb_transaction.py +++ b/binance_transaction/bnb_transaction.py @@ -1,7 +1,7 @@ -from .base import Repeated, Amino, String, StringVarInt, VarInt -from .crypto import compress_key, int_to_bytes, int_from_bytes, secp256k1 -from .signature import BnbSignature -from .msg import Msg +from binance_transaction.base import Repeated, Amino, String, StringVarInt, VarInt +from binance_transaction.crypto import compress_key, int_to_bytes, int_from_bytes, secp256k1 +from binance_transaction.signature import BnbSignature +from binance_transaction.msg import Msg import base64 diff --git a/binance_transaction/dex.py b/binance_transaction/dex.py index 3d8259e..7258af9 100644 --- a/binance_transaction/dex.py +++ b/binance_transaction/dex.py @@ -1,4 +1,4 @@ -from .base import Address, Amino, String, VarInt, make_prefix +from binance_transaction.base import Address, Amino, String, VarInt, make_prefix """ diff --git a/binance_transaction/exceptions.py b/binance_transaction/exceptions.py index 8ae9163..1e4bc58 100644 --- a/binance_transaction/exceptions.py +++ b/binance_transaction/exceptions.py @@ -1,2 +1,2 @@ -class UnsupportedBNBMessage(Exception): +class UnsupportedBnbMessage(Exception): pass diff --git a/binance_transaction/gov.py b/binance_transaction/gov.py index 081b41c..ac303df 100644 --- a/binance_transaction/gov.py +++ b/binance_transaction/gov.py @@ -1,4 +1,4 @@ -from .base import Amino, Repeated, String, Address, StringVarInt, StringToken, Token, VarInt, make_prefix +from binance_transaction.base import Amino, Repeated, String, Address, StringVarInt, StringToken, Token, VarInt, make_prefix """ diff --git a/binance_transaction/msg.py b/binance_transaction/msg.py index 60f841f..843627a 100644 --- a/binance_transaction/msg.py +++ b/binance_transaction/msg.py @@ -1,7 +1,7 @@ -from .base import Amino, make_prefix -from .token import Send, Issue, Mint, Burn, Freeze, Unfreeze, TimeLock, TimeRelock, TimeUnlock -from .gov import Proposal, Vote -from .dex import DexList, NewOrder, CancelOrder +from binance_transaction.base import Amino, make_prefix +from binance_transaction.token import Send, Issue, Mint, Burn, Freeze, Unfreeze, TimeLock, TimeRelock, TimeUnlock +from binance_transaction.gov import Proposal, Vote +from binance_transaction.dex import DexList, NewOrder, CancelOrder """ @@ -58,5 +58,5 @@ def decode(data, field_id): @staticmethod def from_msg_obj(msg_obj): - msg_klass = msg_class_by_type(msg_obj['type']) + msg_klass = msg_class_by_type[msg_obj['type']] return msg_klass.from_msg_obj(msg_obj) diff --git a/binance_transaction/signature.py b/binance_transaction/signature.py index 6a265cb..58ac99d 100644 --- a/binance_transaction/signature.py +++ b/binance_transaction/signature.py @@ -1,4 +1,4 @@ -from .base import Amino, Bytes, StringVarInt, VarInt, make_prefix +from binance_transaction.base import Amino, Bytes, StringVarInt, VarInt, make_prefix """ diff --git a/binance_transaction/tests/test_dex.py b/binance_transaction/tests/test_dex.py index 8f0566b..cf17e04 100644 --- a/binance_transaction/tests/test_dex.py +++ b/binance_transaction/tests/test_dex.py @@ -15,7 +15,7 @@ def test_new_order(): '64AC1240CF4D2BE853D8EBA348353A91ED3BCF2C0164004DAF898153444E91E4A2BAC02106E4D1B3686D70F2B756274D90BF' '120BA87A3CCC412E1D20618CAB480CE69A5718C7A00420072002' ) - assert hashlib.sha256(valid_tx) == valid_tx_hash + assert hashlib.sha256(valid_tx).digest() == valid_tx_hash from_address = 'bnb1pyt4vhpv0nq8d9jrt5fmgz6r303cltwxu27xn2' tx = BnbTransaction.from_obj({ 'account_number': 69703, @@ -61,7 +61,7 @@ def test_cancel_order(): '788A7054E48DCA0CB5AEC745467F19AAA46120236C3220D65E2C2801184773DC4E32EE8F33CE87DC13951E5818723CC60318' '98910920022001' ) - assert hashlib.sha256(valid_tx) == valid_tx_hash + assert hashlib.sha256(valid_tx).digest() == valid_tx_hash from_address = 'bnb1j9tnf0vq2rj65qle6ptwes0kjh5xejdle3fpuj' tx = BnbTransaction.from_obj({ 'account_number': 149656, diff --git a/binance_transaction/tests/test_signature.py b/binance_transaction/tests/test_signature.py index 171d9ed..0abcbdf 100644 --- a/binance_transaction/tests/test_signature.py +++ b/binance_transaction/tests/test_signature.py @@ -1,7 +1,7 @@ import base64 -from .signature import PubKeySecp256k1 -from .base import Bytes +from binance_transaction.signature import PubKeySecp256k1 +from binance_transaction.base import Bytes def test_pubkey_encoding(): diff --git a/binance_transaction/tests/test_token.py b/binance_transaction/tests/test_token.py index ff100d8..fdf0c74 100644 --- a/binance_transaction/tests/test_token.py +++ b/binance_transaction/tests/test_token.py @@ -1,8 +1,8 @@ import base64 import hashlib -from .bnb_transaction import BnbTransaction, TestBnbTransaction -from .crypto import uncompress_key, verify_sig +from binance_transaction.bnb_transaction import BnbTransaction, TestBnbTransaction +from binance_transaction.crypto import uncompress_key, verify_sig def test_send_signed_encoding(): diff --git a/binance_transaction/token.py b/binance_transaction/token.py index 544a5c2..b57168c 100644 --- a/binance_transaction/token.py +++ b/binance_transaction/token.py @@ -1,4 +1,4 @@ -from .base import Address, Amino, Bool, Input, Output, Repeated, String, Token, VarInt, make_prefix +from binance_transaction.base import Address, Amino, Bool, Input, Output, Repeated, String, Token, VarInt, make_prefix """ diff --git a/runtests.py b/runtests.py new file mode 100755 index 0000000..f32ddf9 --- /dev/null +++ b/runtests.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +import argparse +import os +import sys + +import pytest + + +def main(): + os.environ['APP_ENV'] = 'testing' + + parser = argparse.ArgumentParser(add_help=False) + parser.add_argument('--debug-level', default='info', choices=('debug', 'info', 'warning', 'error')) + parser.add_argument('--coverage', action='store_true', default=False) + parser.add_argument('--coverage-html', '--cov-html', action='store_true', default=False) + + args, pytest_args = parser.parse_known_args() + + use_coverage = args.coverage or args.coverage_html + + if use_coverage: + pytest_args.extend(['--cov', 'bnbarb']) + + if args.coverage_html: + pytest_args.extend(['--cov-report', 'html', '--cov-report', 'term']) + + print('--> Calling pytest with args: {}'.format(' '.join(pytest_args))) + status = pytest.main(pytest_args) + sys.exit(status) + + +if __name__ == '__main__': + main()