From 246cc234c48295d0c25f0c3c896f382b88900d22 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Fri, 25 May 2018 13:19:54 -0400 Subject: [PATCH] test fixes to get it running on travis --- setup.py | 7 +++---- tests/unit/test_account.py | 22 +++++++++++----------- tests/unit/test_hash.py | 6 +++++- tests/unit/test_wallet.py | 4 ++-- torba/account.py | 8 ++++---- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index f8cfa7c17..57a7fe88e 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,11 @@ import os import re from setuptools import setup, find_packages -init_file = open(os.path.join(os.path.dirname(__path__), 'torba', '__init__.py')).read() -version = re.search('\d+\.\d+\.\d+', init_file).group() +import torba setup( name='torba', - version=version, + version=torba.__version__, url='https://github.com/lbryio/torba', license='MIT', author='LBRY Inc.', @@ -29,7 +28,7 @@ setup( ), packages=find_packages(exclude=('tests',)), include_package_data=True, - python_requires='>=2.7,>=3.6', + python_requires='>=2.7', install_requires=( 'twisted', 'ecdsa', diff --git a/tests/unit/test_account.py b/tests/unit/test_account.py index a01aacbdd..3648c5fe4 100644 --- a/tests/unit/test_account.py +++ b/tests/unit/test_account.py @@ -39,25 +39,25 @@ class TestAccount(unittest.TestCase): ) self.assertEqual( account.private_key.extended_key_string(), - 'xprv9s21ZrQH143K2dyhK7SevfRG72bYDRNv25yKPWWm6dqApNxm1Zb1m5gGcBWYfbsPjTr2v5joit8Af2Zp5P' - '6yz3jMbycrLrRMpeAJxR8qDg8' + b'xprv9s21ZrQH143K2dyhK7SevfRG72bYDRNv25yKPWWm6dqApNxm1Zb1m5gGcBWYfbsPjTr2v5joit8Af2Zp5P' + b'6yz3jMbycrLrRMpeAJxR8qDg8' ) self.assertEqual( account.public_key.extended_key_string(), - 'xpub661MyMwAqRbcF84AR8yfHoMzf4S2ct6mPJtvBtvNeyN9hBHuZ6uGJszkTSn5fQUCdz3XU17eBzFeAUwV6f' - 'iW44g14WF52fYC5J483wqQ5ZP' + b'xpub661MyMwAqRbcF84AR8yfHoMzf4S2ct6mPJtvBtvNeyN9hBHuZ6uGJszkTSn5fQUCdz3XU17eBzFeAUwV6f' + b'iW44g14WF52fYC5J483wqQ5ZP' ) self.assertEqual( account.receiving_keys.generate_next_address(), - '1PmX9T3sCiDysNtWszJa44SkKcpGc2NaXP' + b'1PmX9T3sCiDysNtWszJa44SkKcpGc2NaXP' ) - private_key = account.get_private_key_for_address('1PmX9T3sCiDysNtWszJa44SkKcpGc2NaXP') + private_key = account.get_private_key_for_address(b'1PmX9T3sCiDysNtWszJa44SkKcpGc2NaXP') self.assertEqual( private_key.extended_key_string(), - 'xprv9xNEfQ296VTRaEUDZ8oKq74xw2U6kpj486vFUB4K1wT9U25GX4UwuzFgJN1YuRrqkQ5TTwCpkYnjNpSoHS' - 'BaEigNHPkoeYbuPMRo6mRUjxg' + b'xprv9xNEfQ296VTRaEUDZ8oKq74xw2U6kpj486vFUB4K1wT9U25GX4UwuzFgJN1YuRrqkQ5TTwCpkYnjNpSoHS' + b'BaEigNHPkoeYbuPMRo6mRUjxg' ) - self.assertIsNone(account.get_private_key_for_address('BcQjRlhDOIrQez1WHfz3whnB33Bp34sUgX')) + self.assertIsNone(account.get_private_key_for_address(b'BcQjRlhDOIrQez1WHfz3whnB33Bp34sUgX')) self.assertEqual( hexlify(private_key.wif()), @@ -92,12 +92,12 @@ class TestAccount(unittest.TestCase): self.assertEqual(len(account.receiving_keys.addresses), 2) self.assertEqual( account.receiving_keys.addresses[0], - '1PmX9T3sCiDysNtWszJa44SkKcpGc2NaXP' + b'1PmX9T3sCiDysNtWszJa44SkKcpGc2NaXP' ) self.assertEqual(len(account.change_keys.addresses), 1) self.assertEqual( account.change_keys.addresses[0], - '1PUbu1D1f3c244JPRSJKBCxRqui5NT6geR' + b'1PUbu1D1f3c244JPRSJKBCxRqui5NT6geR' ) self.maxDiff = None diff --git a/tests/unit/test_hash.py b/tests/unit/test_hash.py index 896337eba..8c7f09c53 100644 --- a/tests/unit/test_hash.py +++ b/tests/unit/test_hash.py @@ -1,7 +1,11 @@ -import mock from unittest import TestCase from torba.hash import aes_decrypt, aes_encrypt +try: + from unittest import mock +except ImportError: + import mock + class TestAESEncryptDecrypt(TestCase): diff --git a/tests/unit/test_wallet.py b/tests/unit/test_wallet.py index 992a6dee6..09d0bf884 100644 --- a/tests/unit/test_wallet.py +++ b/tests/unit/test_wallet.py @@ -86,12 +86,12 @@ class TestWalletCreation(unittest.TestCase): self.assertEqual(len(account.receiving_keys.addresses), 2) self.assertEqual( account.receiving_keys.addresses[0], - '1PmX9T3sCiDysNtWszJa44SkKcpGc2NaXP' + b'1PmX9T3sCiDysNtWszJa44SkKcpGc2NaXP' ) self.assertEqual(len(account.change_keys.addresses), 1) self.assertEqual( account.change_keys.addresses[0], - '1PUbu1D1f3c244JPRSJKBCxRqui5NT6geR' + b'1PUbu1D1f3c244JPRSJKBCxRqui5NT6geR' ) wallet_dict['coins'] = {'btc_mainnet': {'fee_per_byte': 50}} self.assertDictEqual(wallet_dict, wallet.to_dict()) diff --git a/torba/account.py b/torba/account.py index ea480c505..b166fcd3b 100644 --- a/torba/account.py +++ b/torba/account.py @@ -102,11 +102,11 @@ class Account: 'seed': self.seed, 'encrypted': self.encrypted, 'private_key': self.private_key if self.encrypted else - self.private_key.extended_key_string(), - 'public_key': self.public_key.extended_key_string(), - 'receiving_keys': [hexlify(k).decode('iso-8859-1') for k in self.receiving_keys.child_keys], + self.private_key.extended_key_string().decode(), + 'public_key': self.public_key.extended_key_string().decode(), + 'receiving_keys': [hexlify(k).decode() for k in self.receiving_keys.child_keys], 'receiving_gap': self.receiving_keys.minimum_gap, - 'change_keys': [hexlify(k).decode('iso-8859-1') for k in self.change_keys.child_keys], + 'change_keys': [hexlify(k).decode() for k in self.change_keys.child_keys], 'change_gap': self.change_keys.minimum_gap }