From 32edf7b6b9bda20d58faa678a5f33f6b84c2b556 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 26 Aug 2019 18:47:49 +0200 Subject: [PATCH] core: fix unit tests for Bitcoin only firmware --- core/tests/common.py | 2 + core/tests/test_apps.binance.address.py | 7 +- core/tests/test_apps.binance.sign_tx.py | 22 +-- core/tests/test_apps.cardano.address.py | 16 ++- .../tests/test_apps.cardano.get_public_key.py | 2 +- core/tests/test_apps.common.cbor.py | 1 - core/tests/test_apps.common.coins.py | 13 +- core/tests/test_apps.eos.check_action.py | 32 +++-- core/tests/test_apps.eos.conversions.py | 7 +- core/tests/test_apps.eos.get_public_key.py | 8 +- core/tests/test_apps.ethereum.address.py | 7 +- core/tests/test_apps.ethereum.layout.py | 7 +- core/tests/test_apps.ethereum.tokens.py | 5 +- core/tests/test_apps.lisk.address.py | 5 +- core/tests/test_apps.monero.address.py | 5 +- core/tests/test_apps.monero.bulletproof.py | 7 +- core/tests/test_apps.monero.crypto.py | 11 +- core/tests/test_apps.monero.serializer.py | 135 +++++++++--------- core/tests/test_apps.nem.address.py | 8 +- core/tests/test_apps.nem.hdnode.py | 8 +- core/tests/test_apps.nem.mosaic.py | 11 +- core/tests/test_apps.nem.mosaic_creation.py | 16 ++- .../test_apps.nem.mosaic_supply_change.py | 14 +- ...pps.nem.multisig.aggregate_modification.py | 16 ++- core/tests/test_apps.nem.multisig.py | 25 ++-- core/tests/test_apps.nem.namespace.py | 14 +- core/tests/test_apps.nem.transfer.py | 16 ++- core/tests/test_apps.ripple.address.py | 5 +- core/tests/test_apps.ripple.serializer.py | 10 +- core/tests/test_apps.stellar.address.py | 5 +- core/tests/test_apps.tezos.address.py | 13 +- core/tests/test_apps.tezos.encode.py | 20 +-- core/tests/test_apps.wallet.address.py | 4 + core/tests/test_apps.wallet.address_grs.py | 1 + ....wallet.segwit.signtx.native_p2wpkh_grs.py | 1 + ...wallet.segwit.signtx.p2wpkh_in_p2sh_grs.py | 1 + core/tests/test_apps.wallet.signtx_grs.py | 1 + core/tests/test_apps.wallet.zcash.zip143.py | 5 +- core/tests/test_apps.wallet.zcash.zip243.py | 5 +- .../test_trezor.crypto.curve.secp256k1.py | 7 +- 40 files changed, 297 insertions(+), 201 deletions(-) diff --git a/core/tests/common.py b/core/tests/common.py index b41952350..1e699e382 100644 --- a/core/tests/common.py +++ b/core/tests/common.py @@ -5,3 +5,5 @@ sys.path.append('../src') from ubinascii import hexlify, unhexlify # noqa: F401 import unittest # noqa: F401 + +from trezor import utils # noqa: F401 diff --git a/core/tests/test_apps.binance.address.py b/core/tests/test_apps.binance.address.py index 940df6081..7326421a1 100644 --- a/core/tests/test_apps.binance.address.py +++ b/core/tests/test_apps.binance.address.py @@ -1,10 +1,13 @@ from common import * from apps.common.paths import HARDENED -from apps.binance.helpers import address_from_public_key, validate_full_path from trezor.crypto.curve import secp256k1 -from ubinascii import unhexlify +if not utils.BITCOIN_ONLY: + from apps.binance.helpers import address_from_public_key, validate_full_path + + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestBinanceAddress(unittest.TestCase): def test_privkey_to_address(self): #source of test data - binance javascript SDK diff --git a/core/tests/test_apps.binance.sign_tx.py b/core/tests/test_apps.binance.sign_tx.py index c84f3364a..94033018e 100644 --- a/core/tests/test_apps.binance.sign_tx.py +++ b/core/tests/test_apps.binance.sign_tx.py @@ -1,19 +1,21 @@ from common import * -from apps.binance.helpers import produce_json_for_signing -from apps.binance.sign_tx import generate_content_signature, sign_tx - from trezor.crypto.curve import secp256k1 from trezor.crypto.hashlib import sha256 -from trezor.messages.BinanceCancelMsg import BinanceCancelMsg -from trezor.messages.BinanceCoin import BinanceCoin -from trezor.messages.BinanceInputOutput import BinanceInputOutput -from trezor.messages.BinanceOrderMsg import BinanceOrderMsg -from trezor.messages.BinanceSignTx import BinanceSignTx -from trezor.messages.BinanceTransferMsg import BinanceTransferMsg + +if not utils.BITCOIN_ONLY: + from apps.binance.helpers import produce_json_for_signing + from apps.binance.sign_tx import generate_content_signature, sign_tx + from trezor.messages.BinanceCancelMsg import BinanceCancelMsg + from trezor.messages.BinanceCoin import BinanceCoin + from trezor.messages.BinanceInputOutput import BinanceInputOutput + from trezor.messages.BinanceOrderMsg import BinanceOrderMsg + from trezor.messages.BinanceSignTx import BinanceSignTx + from trezor.messages.BinanceTransferMsg import BinanceTransferMsg -class TestBinanceSign(unittest.TestCase): +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") +class TestBinanceSign(unittest.TestCase): def test_order_signature(self): # source of testing data # https://github.com/binance-chain/javascript-sdk/blob/master/__tests__/fixtures/placeOrder.json diff --git a/core/tests/test_apps.cardano.address.py b/core/tests/test_apps.cardano.address.py index 8bd8d2c42..52610e1b1 100644 --- a/core/tests/test_apps.cardano.address.py +++ b/core/tests/test_apps.cardano.address.py @@ -2,16 +2,18 @@ from common import * from apps.common import seed from apps.common import HARDENED -from apps.cardano.address import ( - _get_address_root, - _address_hash, - validate_full_path, - derive_address_and_node -) -from apps.cardano.seed import Keychain from trezor.crypto import bip32, slip39 +if not utils.BITCOIN_ONLY: + from apps.cardano.address import ( + _get_address_root, + _address_hash, + validate_full_path, + derive_address_and_node + ) + from apps.cardano.seed import Keychain +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestCardanoAddress(unittest.TestCase): def test_hardened_address_derivation_scheme(self): mnemonic = "all all all all all all all all all all all all" diff --git a/core/tests/test_apps.cardano.get_public_key.py b/core/tests/test_apps.cardano.get_public_key.py index 50ece18c3..09b87ec10 100644 --- a/core/tests/test_apps.cardano.get_public_key.py +++ b/core/tests/test_apps.cardano.get_public_key.py @@ -3,9 +3,9 @@ from common import * from apps.cardano.seed import Keychain from apps.cardano.get_public_key import _get_public_key from trezor.crypto import bip32, slip39 -from ubinascii import hexlify +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestCardanoGetPublicKey(unittest.TestCase): def test_get_public_key_scheme(self): mnemonic = "all all all all all all all all all all all all" diff --git a/core/tests/test_apps.common.cbor.py b/core/tests/test_apps.common.cbor.py index 12f283522..5b6e882b8 100644 --- a/core/tests/test_apps.common.cbor.py +++ b/core/tests/test_apps.common.cbor.py @@ -6,7 +6,6 @@ from apps.common.cbor import ( decode, encode, ) -from ubinascii import unhexlify class TestCardanoCbor(unittest.TestCase): def test_cbor_encoding(self): diff --git a/core/tests/test_apps.common.coins.py b/core/tests/test_apps.common.coins.py index dc1297975..55471822d 100644 --- a/core/tests/test_apps.common.coins.py +++ b/core/tests/test_apps.common.coins.py @@ -5,9 +5,20 @@ from apps.common import coins class TestCoins(unittest.TestCase): - def test_coins(self): + def test_bitcoin(self): ref = [ ('BTC', 'Bitcoin', 0), + ('TEST', 'Testnet', 111), + ('REGTEST', 'Regtest', 111), + ] + for s, n, a in ref: + c = coins.by_name(n) + self.assertEqual(c.address_type, a) + self.assertEqual(c.coin_shortcut, s) + + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") + def test_altcoins(self): + ref = [ ('NMC', 'Namecoin', 52), ('LTC', 'Litecoin', 48), ('DASH', 'Dash', 76), diff --git a/core/tests/test_apps.eos.check_action.py b/core/tests/test_apps.eos.check_action.py index 75477ed3d..fb8098c8b 100644 --- a/core/tests/test_apps.eos.check_action.py +++ b/core/tests/test_apps.eos.check_action.py @@ -1,22 +1,24 @@ from common import * -from apps.eos.actions import check_action -from trezor.messages.EosTxActionAck import EosTxActionAck -from trezor.messages.EosActionBuyRam import EosActionBuyRam -from trezor.messages.EosActionBuyRamBytes import EosActionBuyRamBytes -from trezor.messages.EosActionDelegate import EosActionDelegate -from trezor.messages.EosActionDeleteAuth import EosActionDeleteAuth -from trezor.messages.EosActionLinkAuth import EosActionLinkAuth -from trezor.messages.EosActionNewAccount import EosActionNewAccount -from trezor.messages.EosActionRefund import EosActionRefund -from trezor.messages.EosActionSellRam import EosActionSellRam -from trezor.messages.EosActionTransfer import EosActionTransfer -from trezor.messages.EosActionUndelegate import EosActionUndelegate -from trezor.messages.EosActionUnlinkAuth import EosActionUnlinkAuth -from trezor.messages.EosActionUpdateAuth import EosActionUpdateAuth -from trezor.messages.EosActionVoteProducer import EosActionVoteProducer +if not utils.BITCOIN_ONLY: + from apps.eos.actions import check_action + from trezor.messages.EosTxActionAck import EosTxActionAck + from trezor.messages.EosActionBuyRam import EosActionBuyRam + from trezor.messages.EosActionBuyRamBytes import EosActionBuyRamBytes + from trezor.messages.EosActionDelegate import EosActionDelegate + from trezor.messages.EosActionDeleteAuth import EosActionDeleteAuth + from trezor.messages.EosActionLinkAuth import EosActionLinkAuth + from trezor.messages.EosActionNewAccount import EosActionNewAccount + from trezor.messages.EosActionRefund import EosActionRefund + from trezor.messages.EosActionSellRam import EosActionSellRam + from trezor.messages.EosActionTransfer import EosActionTransfer + from trezor.messages.EosActionUndelegate import EosActionUndelegate + from trezor.messages.EosActionUnlinkAuth import EosActionUnlinkAuth + from trezor.messages.EosActionUpdateAuth import EosActionUpdateAuth + from trezor.messages.EosActionVoteProducer import EosActionVoteProducer +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestEosActions(unittest.TestCase): def test_check_action(self): # return True diff --git a/core/tests/test_apps.eos.conversions.py b/core/tests/test_apps.eos.conversions.py index 5c6dceef9..381f896a3 100644 --- a/core/tests/test_apps.eos.conversions.py +++ b/core/tests/test_apps.eos.conversions.py @@ -1,8 +1,11 @@ from common import * -from apps.eos import helpers -from trezor.messages.EosAsset import EosAsset +if not utils.BITCOIN_ONLY: + from apps.eos import helpers + from trezor.messages.EosAsset import EosAsset + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestEosConversions(unittest.TestCase): def test_eos_name_to_string(self): names_in = [ diff --git a/core/tests/test_apps.eos.get_public_key.py b/core/tests/test_apps.eos.get_public_key.py index 91e4e9540..23f60c68d 100755 --- a/core/tests/test_apps.eos.get_public_key.py +++ b/core/tests/test_apps.eos.get_public_key.py @@ -1,12 +1,14 @@ from common import * -from apps.eos.get_public_key import _get_public_key, _public_key_to_wif from trezor.crypto import bip32, bip39 -from ubinascii import hexlify, unhexlify from apps.common.paths import HARDENED -from apps.eos.helpers import validate_full_path +if not utils.BITCOIN_ONLY: + from apps.eos.get_public_key import _get_public_key, _public_key_to_wif + from apps.eos.helpers import validate_full_path + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestEosGetPublicKey(unittest.TestCase): def test_get_public_key_scheme(self): mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" diff --git a/core/tests/test_apps.ethereum.address.py b/core/tests/test_apps.ethereum.address.py index 723755e52..816ba7b62 100644 --- a/core/tests/test_apps.ethereum.address.py +++ b/core/tests/test_apps.ethereum.address.py @@ -1,9 +1,12 @@ from common import * from apps.common.paths import HARDENED -from apps.ethereum.address import address_from_bytes, bytes_from_address, validate_full_path -from apps.ethereum.networks import NetworkInfo, by_chain_id +if not utils.BITCOIN_ONLY: + from apps.ethereum.address import address_from_bytes, bytes_from_address, validate_full_path + from apps.ethereum.networks import NetworkInfo, by_chain_id + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestEthereumGetAddress(unittest.TestCase): def test_address_from_bytes_eip55(self): diff --git a/core/tests/test_apps.ethereum.layout.py b/core/tests/test_apps.ethereum.layout.py index 0a9b70f18..e720bec52 100644 --- a/core/tests/test_apps.ethereum.layout.py +++ b/core/tests/test_apps.ethereum.layout.py @@ -1,8 +1,11 @@ from common import * -from apps.ethereum.layout import format_ethereum_amount -from apps.ethereum.tokens import token_by_chain_address +if not utils.BITCOIN_ONLY: + from apps.ethereum.layout import format_ethereum_amount + from apps.ethereum.tokens import token_by_chain_address + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestEthereumLayout(unittest.TestCase): def test_format(self): diff --git a/core/tests/test_apps.ethereum.tokens.py b/core/tests/test_apps.ethereum.tokens.py index c5576d65b..8e8b2ef80 100644 --- a/core/tests/test_apps.ethereum.tokens.py +++ b/core/tests/test_apps.ethereum.tokens.py @@ -1,7 +1,10 @@ from common import * -from apps.ethereum import tokens +if not utils.BITCOIN_ONLY: + from apps.ethereum import tokens + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestEthereumTokens(unittest.TestCase): def test_token_by_chain_address(self): diff --git a/core/tests/test_apps.lisk.address.py b/core/tests/test_apps.lisk.address.py index cb9191204..436118256 100644 --- a/core/tests/test_apps.lisk.address.py +++ b/core/tests/test_apps.lisk.address.py @@ -1,8 +1,11 @@ from common import * from apps.common.paths import HARDENED -from apps.lisk.helpers import validate_full_path +if not utils.BITCOIN_ONLY: + from apps.lisk.helpers import validate_full_path + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestLiskGetAddress(unittest.TestCase): def test_paths(self): diff --git a/core/tests/test_apps.monero.address.py b/core/tests/test_apps.monero.address.py index 3c3376f32..25d2f8424 100644 --- a/core/tests/test_apps.monero.address.py +++ b/core/tests/test_apps.monero.address.py @@ -1,8 +1,11 @@ from common import * from apps.common.paths import HARDENED -from apps.monero.misc import validate_full_path +if not utils.BITCOIN_ONLY: + from apps.monero.misc import validate_full_path + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestMoneroGetAddress(unittest.TestCase): def test_paths(self): diff --git a/core/tests/test_apps.monero.bulletproof.py b/core/tests/test_apps.monero.bulletproof.py index 347cb981a..467da8940 100644 --- a/core/tests/test_apps.monero.bulletproof.py +++ b/core/tests/test_apps.monero.bulletproof.py @@ -1,10 +1,13 @@ from common import * -from apps.monero.xmr import bulletproof as bp, crypto, monero -from apps.monero.xmr.serialize_messages.tx_rsig_bulletproof import Bulletproof +if not utils.BITCOIN_ONLY: + from apps.monero.xmr import bulletproof as bp, crypto, monero + from apps.monero.xmr.serialize_messages.tx_rsig_bulletproof import Bulletproof +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestMoneroBulletproof(unittest.TestCase): + def test_1(self): pass diff --git a/core/tests/test_apps.monero.crypto.py b/core/tests/test_apps.monero.crypto.py index fb589fba2..83aee8002 100644 --- a/core/tests/test_apps.monero.crypto.py +++ b/core/tests/test_apps.monero.crypto.py @@ -1,12 +1,15 @@ from common import * -from apps.monero.xmr import crypto, monero -from apps.monero.xmr.addresses import encode_addr -from apps.monero.xmr.credentials import AccountCreds -from apps.monero.xmr.networks import NetworkTypes, net_version +if not utils.BITCOIN_ONLY: + from apps.monero.xmr import crypto, monero + from apps.monero.xmr.addresses import encode_addr + from apps.monero.xmr.credentials import AccountCreds + from apps.monero.xmr.networks import NetworkTypes, net_version +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestMoneroCrypto(unittest.TestCase): + def test_encoding(self): point = unhexlify( b"2486224797d05cae3cba4be043be2db0df381f3f19cfa113f86ab38e3d8d2bd0" diff --git a/core/tests/test_apps.monero.serializer.py b/core/tests/test_apps.monero.serializer.py index 2dc0f2ea1..18197dc01 100644 --- a/core/tests/test_apps.monero.serializer.py +++ b/core/tests/test_apps.monero.serializer.py @@ -2,72 +2,75 @@ import utest from common import * from trezor import log, loop, utils -from apps.monero.xmr.serialize.int_serialize import ( - dump_uint, - dump_uvarint, - load_uint, - load_uvarint, -) -from apps.monero.xmr.serialize.readwriter import MemoryReaderWriter -from apps.monero.xmr.serialize_messages.base import ECPoint -from apps.monero.xmr.serialize_messages.tx_prefix import ( - TxinGen, - TxinToKey, - TxInV, - TxOut, - TxoutToKey, -) - - -class XmrTstData(object): - """Simple tests data generator""" - - def __init__(self, *args, **kwargs): - super(XmrTstData, self).__init__() - self.ec_offset = 0 - - def reset(self): - self.ec_offset = 0 - - def generate_ec_key(self, use_offset=True): - """ - Returns test EC key, 32 element byte array - :param use_offset: - :return: - """ - offset = 0 - if use_offset: - offset = self.ec_offset - self.ec_offset += 1 - - return bytearray(range(offset, offset + 32)) - - def gen_transaction_prefix(self): - """ - Returns test transaction prefix - :return: - """ - vin = [ - TxinToKey( - amount=123, key_offsets=[1, 2, 3, 2 ** 76], k_image=bytearray(range(32)) - ), - TxinToKey( - amount=456, key_offsets=[9, 8, 7, 6], k_image=bytearray(range(32, 64)) - ), - TxinGen(height=99), - ] - - vout = [ - TxOut(amount=11, target=TxoutToKey(key=bytearray(range(32)))), - TxOut(amount=34, target=TxoutToKey(key=bytearray(range(64, 96)))), - ] - - msg = TransactionPrefix( - version=2, unlock_time=10, vin=vin, vout=vout, extra=list(range(31)) - ) - return msg - - +if not utils.BITCOIN_ONLY: + from apps.monero.xmr.serialize.int_serialize import ( + dump_uint, + dump_uvarint, + load_uint, + load_uvarint, + ) + from apps.monero.xmr.serialize.readwriter import MemoryReaderWriter + from apps.monero.xmr.serialize_messages.base import ECPoint + from apps.monero.xmr.serialize_messages.tx_prefix import ( + TxinGen, + TxinToKey, + TxInV, + TxOut, + TxoutToKey, + ) + + +if not utils.BITCOIN_ONLY: + class XmrTstData(object): + """Simple tests data generator""" + + def __init__(self, *args, **kwargs): + super(XmrTstData, self).__init__() + self.ec_offset = 0 + + def reset(self): + self.ec_offset = 0 + + def generate_ec_key(self, use_offset=True): + """ + Returns test EC key, 32 element byte array + :param use_offset: + :return: + """ + offset = 0 + if use_offset: + offset = self.ec_offset + self.ec_offset += 1 + + return bytearray(range(offset, offset + 32)) + + def gen_transaction_prefix(self): + """ + Returns test transaction prefix + :return: + """ + vin = [ + TxinToKey( + amount=123, key_offsets=[1, 2, 3, 2 ** 76], k_image=bytearray(range(32)) + ), + TxinToKey( + amount=456, key_offsets=[9, 8, 7, 6], k_image=bytearray(range(32, 64)) + ), + TxinGen(height=99), + ] + + vout = [ + TxOut(amount=11, target=TxoutToKey(key=bytearray(range(32)))), + TxOut(amount=34, target=TxoutToKey(key=bytearray(range(64, 96)))), + ] + + msg = TransactionPrefix( + version=2, unlock_time=10, vin=vin, vout=vout, extra=list(range(31)) + ) + return msg + + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestMoneroSerializer(unittest.TestCase): def __init__(self, *args, **kwargs): super(TestMoneroSerializer, self).__init__(*args, **kwargs) diff --git a/core/tests/test_apps.nem.address.py b/core/tests/test_apps.nem.address.py index 20b61ae72..53ac7695f 100644 --- a/core/tests/test_apps.nem.address.py +++ b/core/tests/test_apps.nem.address.py @@ -1,10 +1,12 @@ from common import * -from ubinascii import unhexlify -from trezor.crypto import nem from apps.common import HARDENED -from apps.nem.helpers import check_path, NEM_NETWORK_MAINNET, NEM_NETWORK_TESTNET +if not utils.BITCOIN_ONLY: + from trezor.crypto import nem + from apps.nem.helpers import check_path, NEM_NETWORK_MAINNET, NEM_NETWORK_TESTNET + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemAddress(unittest.TestCase): def test_addresses(self): diff --git a/core/tests/test_apps.nem.hdnode.py b/core/tests/test_apps.nem.hdnode.py index a2082d775..3556b4e4a 100644 --- a/core/tests/test_apps.nem.hdnode.py +++ b/core/tests/test_apps.nem.hdnode.py @@ -1,10 +1,12 @@ from common import * -from ubinascii import unhexlify from trezor.crypto import bip32 -from apps.nem import CURVE -from apps.nem.helpers import NEM_NETWORK_MAINNET +if not utils.BITCOIN_ONLY: + from apps.nem import CURVE + from apps.nem.helpers import NEM_NETWORK_MAINNET + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemHDNode(unittest.TestCase): def test_addresses(self): diff --git a/core/tests/test_apps.nem.mosaic.py b/core/tests/test_apps.nem.mosaic.py index 7f25f5404..d41ea3089 100644 --- a/core/tests/test_apps.nem.mosaic.py +++ b/core/tests/test_apps.nem.mosaic.py @@ -1,10 +1,13 @@ from common import * -from trezor.messages.NEMMosaic import NEMMosaic -from apps.nem.mosaic.helpers import get_mosaic_definition -from apps.nem.transfer import * -from apps.nem.transfer.serialize import * +if not utils.BITCOIN_ONLY: + from trezor.messages.NEMMosaic import NEMMosaic + from apps.nem.mosaic.helpers import get_mosaic_definition + from apps.nem.transfer import * + from apps.nem.transfer.serialize import * + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMosaic(unittest.TestCase): def test_get_mosaic_definition(self): diff --git a/core/tests/test_apps.nem.mosaic_creation.py b/core/tests/test_apps.nem.mosaic_creation.py index ef110c1b5..1c07d2fa3 100644 --- a/core/tests/test_apps.nem.mosaic_creation.py +++ b/core/tests/test_apps.nem.mosaic_creation.py @@ -1,15 +1,17 @@ from common import * -from apps.nem.helpers import * -from apps.nem.mosaic import * -from apps.nem.mosaic.serialize import * - from trezor.crypto import hashlib -from trezor.messages.NEMSignTx import NEMSignTx -from trezor.messages.NEMMosaicCreation import NEMMosaicCreation -from trezor.messages.NEMMosaicDefinition import NEMMosaicDefinition + +if not utils.BITCOIN_ONLY: + from trezor.messages.NEMSignTx import NEMSignTx + from trezor.messages.NEMMosaicCreation import NEMMosaicCreation + from trezor.messages.NEMMosaicDefinition import NEMMosaicDefinition + from apps.nem.helpers import * + from apps.nem.mosaic import * + from apps.nem.mosaic.serialize import * +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMosaicCreation(unittest.TestCase): def test_nem_transaction_mosaic_creation(self): diff --git a/core/tests/test_apps.nem.mosaic_supply_change.py b/core/tests/test_apps.nem.mosaic_supply_change.py index 97a386073..0d9804094 100644 --- a/core/tests/test_apps.nem.mosaic_supply_change.py +++ b/core/tests/test_apps.nem.mosaic_supply_change.py @@ -1,14 +1,16 @@ from common import * -from apps.nem.helpers import * -from apps.nem.mosaic import * -from apps.nem.mosaic.serialize import * - from trezor.crypto import hashlib -from trezor.messages.NEMSignTx import NEMSignTx -from trezor.messages.NEMMosaicSupplyChange import NEMMosaicSupplyChange + +if not utils.BITCOIN_ONLY: + from apps.nem.helpers import * + from apps.nem.mosaic import * + from apps.nem.mosaic.serialize import * + from trezor.messages.NEMSignTx import NEMSignTx + from trezor.messages.NEMMosaicSupplyChange import NEMMosaicSupplyChange +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMosaicSupplyChange(unittest.TestCase): def test_nem_transaction_create_mosaic_supply_change(self): diff --git a/core/tests/test_apps.nem.multisig.aggregate_modification.py b/core/tests/test_apps.nem.multisig.aggregate_modification.py index 39ac36d1b..5d0105f3f 100644 --- a/core/tests/test_apps.nem.multisig.aggregate_modification.py +++ b/core/tests/test_apps.nem.multisig.aggregate_modification.py @@ -1,15 +1,17 @@ from common import * from trezor.crypto import hashlib -from trezor.messages.NEMAggregateModification import NEMAggregateModification -from trezor.messages.NEMCosignatoryModification import NEMCosignatoryModification -from trezor.messages.NEMSignTx import NEMSignTx -from trezor.messages.NEMTransactionCommon import NEMTransactionCommon -from apps.nem.helpers import * -from apps.nem.multisig import * -from apps.nem.multisig.serialize import * +if not utils.BITCOIN_ONLY: + from trezor.messages.NEMAggregateModification import NEMAggregateModification + from trezor.messages.NEMCosignatoryModification import NEMCosignatoryModification + from trezor.messages.NEMSignTx import NEMSignTx + from trezor.messages.NEMTransactionCommon import NEMTransactionCommon + from apps.nem.helpers import * + from apps.nem.multisig import * + from apps.nem.multisig.serialize import * +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMultisigAggregateModification(unittest.TestCase): def test_nem_transaction_aggregate_modification(self): # http://bob.nem.ninja:8765/#/aggregate/6a55471b17159e5b6cd579c421e95a4e39d92e3f78b0a55ee337e785a601d3a2 diff --git a/core/tests/test_apps.nem.multisig.py b/core/tests/test_apps.nem.multisig.py index bc5672ddd..37edc1181 100644 --- a/core/tests/test_apps.nem.multisig.py +++ b/core/tests/test_apps.nem.multisig.py @@ -1,17 +1,18 @@ from common import * -from apps.nem.helpers import * -from apps.nem.multisig import * -from apps.nem.multisig.serialize import * -from apps.nem.namespace import * -from apps.nem.namespace.serialize import * - -from trezor.messages.NEMSignTx import NEMSignTx -from trezor.messages.NEMAggregateModification import NEMAggregateModification -from trezor.messages.NEMProvisionNamespace import NEMProvisionNamespace -from trezor.messages.NEMCosignatoryModification import NEMCosignatoryModification - - +if not utils.BITCOIN_ONLY: + from apps.nem.helpers import * + from apps.nem.multisig import * + from apps.nem.multisig.serialize import * + from apps.nem.namespace import * + from apps.nem.namespace.serialize import * + from trezor.messages.NEMSignTx import NEMSignTx + from trezor.messages.NEMAggregateModification import NEMAggregateModification + from trezor.messages.NEMProvisionNamespace import NEMProvisionNamespace + from trezor.messages.NEMCosignatoryModification import NEMCosignatoryModification + + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMultisig(unittest.TestCase): def test_nem_multisig(self): diff --git a/core/tests/test_apps.nem.namespace.py b/core/tests/test_apps.nem.namespace.py index fa5beac2a..a1ba82c2a 100644 --- a/core/tests/test_apps.nem.namespace.py +++ b/core/tests/test_apps.nem.namespace.py @@ -1,14 +1,16 @@ from common import * -from apps.nem.helpers import * -from apps.nem.namespace import * -from apps.nem.namespace.serialize import * - from trezor.crypto import hashlib -from trezor.messages.NEMProvisionNamespace import NEMProvisionNamespace -from trezor.messages.NEMSignTx import NEMSignTx + +if not utils.BITCOIN_ONLY: + from apps.nem.helpers import * + from apps.nem.namespace import * + from apps.nem.namespace.serialize import * + from trezor.messages.NEMProvisionNamespace import NEMProvisionNamespace + from trezor.messages.NEMSignTx import NEMSignTx +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemNamespace(unittest.TestCase): def test_create_provision_namespace(self): diff --git a/core/tests/test_apps.nem.transfer.py b/core/tests/test_apps.nem.transfer.py index 272055a5b..6c8f159af 100644 --- a/core/tests/test_apps.nem.transfer.py +++ b/core/tests/test_apps.nem.transfer.py @@ -1,15 +1,17 @@ from common import * -from apps.nem.helpers import * -from apps.nem.mosaic import * -from apps.nem.transfer import * -from apps.nem.transfer.serialize import * - from trezor.crypto import hashlib -from trezor.messages.NEMTransfer import NEMTransfer -from trezor.messages.NEMSignTx import NEMSignTx + +if not utils.BITCOIN_ONLY: + from apps.nem.helpers import * + from apps.nem.mosaic import * + from apps.nem.transfer import * + from apps.nem.transfer.serialize import * + from trezor.messages.NEMTransfer import NEMTransfer + from trezor.messages.NEMSignTx import NEMSignTx +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemTransfer(unittest.TestCase): def test_create_transfer(self): diff --git a/core/tests/test_apps.ripple.address.py b/core/tests/test_apps.ripple.address.py index 188769c57..320d44a84 100644 --- a/core/tests/test_apps.ripple.address.py +++ b/core/tests/test_apps.ripple.address.py @@ -1,8 +1,11 @@ from common import * from apps.common.paths import HARDENED -from apps.ripple.helpers import address_from_public_key, validate_full_path +if not utils.BITCOIN_ONLY: + from apps.ripple.helpers import address_from_public_key, validate_full_path + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestRippleAddress(unittest.TestCase): def test_pubkey_to_address(self): diff --git a/core/tests/test_apps.ripple.serializer.py b/core/tests/test_apps.ripple.serializer.py index 619964b25..3fc119ea8 100644 --- a/core/tests/test_apps.ripple.serializer.py +++ b/core/tests/test_apps.ripple.serializer.py @@ -1,11 +1,13 @@ from common import * -from trezor.messages.RipplePayment import RipplePayment -from trezor.messages.RippleSignTx import RippleSignTx -from apps.ripple.serialize import serialize, serialize_amount -from apps.ripple.sign_tx import get_network_prefix +if not utils.BITCOIN_ONLY: + from trezor.messages.RipplePayment import RipplePayment + from trezor.messages.RippleSignTx import RippleSignTx + from apps.ripple.serialize import serialize, serialize_amount + from apps.ripple.sign_tx import get_network_prefix +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestRippleSerializer(unittest.TestCase): def test_amount(self): # https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L2494 diff --git a/core/tests/test_apps.stellar.address.py b/core/tests/test_apps.stellar.address.py index a261def40..2b29b0658 100644 --- a/core/tests/test_apps.stellar.address.py +++ b/core/tests/test_apps.stellar.address.py @@ -1,9 +1,12 @@ from common import * from apps.common.paths import HARDENED -from apps.stellar.helpers import address_from_public_key, public_key_from_address, validate_full_path from trezor.wire import ProcessError +if not utils.BITCOIN_ONLY: + from apps.stellar.helpers import address_from_public_key, public_key_from_address, validate_full_path + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestStellarAddress(unittest.TestCase): def test_address_to_pubkey(self): diff --git a/core/tests/test_apps.tezos.address.py b/core/tests/test_apps.tezos.address.py index c3870fd31..797e1b6b2 100644 --- a/core/tests/test_apps.tezos.address.py +++ b/core/tests/test_apps.tezos.address.py @@ -1,14 +1,15 @@ -from ubinascii import unhexlify - from common import * -from trezor.messages import TezosContractType -from trezor.messages.TezosContractID import TezosContractID -from apps.tezos.sign_tx import _get_address_from_contract -from apps.tezos.helpers import validate_full_path from apps.common.paths import HARDENED +if not utils.BITCOIN_ONLY: + from apps.tezos.sign_tx import _get_address_from_contract + from apps.tezos.helpers import validate_full_path + from trezor.messages import TezosContractType + from trezor.messages.TezosContractID import TezosContractID + +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestTezosAddress(unittest.TestCase): def test_get_address_from_contract(self): contracts = [ diff --git a/core/tests/test_apps.tezos.encode.py b/core/tests/test_apps.tezos.encode.py index 16f1142f4..7a67395a5 100644 --- a/core/tests/test_apps.tezos.encode.py +++ b/core/tests/test_apps.tezos.encode.py @@ -1,17 +1,17 @@ -from ubinascii import unhexlify - from common import * -from trezor.messages import TezosContractType -from trezor.messages.TezosContractID import TezosContractID -from apps.tezos.helpers import base58_decode_check, base58_encode_check, write_bool -from apps.tezos.sign_tx import ( - _encode_contract_id, - _encode_data_with_bool_prefix, - _encode_zarith, -) +if not utils.BITCOIN_ONLY: + from trezor.messages import TezosContractType + from trezor.messages.TezosContractID import TezosContractID + from apps.tezos.helpers import base58_decode_check, base58_encode_check, write_bool + from apps.tezos.sign_tx import ( + _encode_contract_id, + _encode_data_with_bool_prefix, + _encode_zarith, + ) +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestTezosEncoding(unittest.TestCase): def test_tezos_encode_zarith(self): inputs = [2000000, 159066, 200, 60000, 157000000, 0] diff --git a/core/tests/test_apps.wallet.address.py b/core/tests/test_apps.wallet.address.py index d9a9329d0..d7df64013 100644 --- a/core/tests/test_apps.wallet.address.py +++ b/core/tests/test_apps.wallet.address.py @@ -169,6 +169,7 @@ class TestAddress(unittest.TestCase): self.assertFalse(validate_full_path([44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0], coin, InputScriptType.SPENDWITNESS)) self.assertTrue(validate_full_path([44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0], coin, InputScriptType.SPENDWITNESS, validate_script_type=False)) + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") def test_paths_bch(self): incorrect_derivation_paths = [ ([44 | HARDENED], InputScriptType.SPENDADDRESS), # invalid length @@ -201,6 +202,7 @@ class TestAddress(unittest.TestCase): for path, input_type in correct_derivation_paths: self.assertTrue(validate_full_path(path, coin, input_type)) + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") def test_paths_other(self): incorrect_derivation_paths = [ ([44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDMULTISIG), # input type mismatch @@ -244,6 +246,8 @@ class TestAddress(unittest.TestCase): for path in incorrect_derivation_paths: self.assertFalse(validate_path_for_bitcoin_public_key(path, coin)) + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") + def test_paths_public_key_nosegwit(self): incorrect_derivation_paths = [ [49 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0, 0], # no segwit ] diff --git a/core/tests/test_apps.wallet.address_grs.py b/core/tests/test_apps.wallet.address_grs.py index 8aeb173e0..ccabdfda7 100644 --- a/core/tests/test_apps.wallet.address_grs.py +++ b/core/tests/test_apps.wallet.address_grs.py @@ -12,6 +12,7 @@ def node_derive(root, path): return node +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestAddressGRS(unittest.TestCase): # pylint: disable=C0301 diff --git a/core/tests/test_apps.wallet.segwit.signtx.native_p2wpkh_grs.py b/core/tests/test_apps.wallet.segwit.signtx.native_p2wpkh_grs.py index ec963f822..9e13b2483 100644 --- a/core/tests/test_apps.wallet.segwit.signtx.native_p2wpkh_grs.py +++ b/core/tests/test_apps.wallet.segwit.signtx.native_p2wpkh_grs.py @@ -19,6 +19,7 @@ from apps.common.seed import Keychain from apps.wallet.sign_tx import helpers, signing # https://groestlsight-test.groestlcoin.org/api/tx/9b5c4859a8a31e69788cb4402812bb28f14ad71cbd8c60b09903478bc56f79a3 +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): # pylint: disable=C0301 diff --git a/core/tests/test_apps.wallet.segwit.signtx.p2wpkh_in_p2sh_grs.py b/core/tests/test_apps.wallet.segwit.signtx.p2wpkh_in_p2sh_grs.py index 4ab2d29ef..e62080fa8 100644 --- a/core/tests/test_apps.wallet.segwit.signtx.p2wpkh_in_p2sh_grs.py +++ b/core/tests/test_apps.wallet.segwit.signtx.p2wpkh_in_p2sh_grs.py @@ -19,6 +19,7 @@ from apps.common.seed import Keychain from apps.wallet.sign_tx import helpers, signing # https://groestlsight-test.groestlcoin.org/api/tx/4ce0220004bdfe14e3dd49fd8636bcb770a400c0c9e9bff670b6a13bb8f15c72 +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): # pylint: disable=C0301 diff --git a/core/tests/test_apps.wallet.signtx_grs.py b/core/tests/test_apps.wallet.signtx_grs.py index ae33831d3..51f004f9f 100644 --- a/core/tests/test_apps.wallet.signtx_grs.py +++ b/core/tests/test_apps.wallet.signtx_grs.py @@ -19,6 +19,7 @@ from apps.common.seed import Keychain from apps.wallet.sign_tx import helpers, signing +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestSignTx_GRS(unittest.TestCase): # pylint: disable=C0301 diff --git a/core/tests/test_apps.wallet.zcash.zip143.py b/core/tests/test_apps.wallet.zcash.zip143.py index 0d8b17479..4ee999479 100644 --- a/core/tests/test_apps.wallet.zcash.zip143.py +++ b/core/tests/test_apps.wallet.zcash.zip143.py @@ -5,10 +5,13 @@ from trezor.messages.TxInputType import TxInputType from trezor.messages.TxOutputBinType import TxOutputBinType from apps.common import coins -from apps.wallet.sign_tx.zcash import Zip143 + +if not utils.BITCOIN_ONLY: + from apps.wallet.sign_tx.zcash import Zip143 # test vectors inspired from https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0143.py +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestZcashZip143(unittest.TestCase): VECTORS = [ diff --git a/core/tests/test_apps.wallet.zcash.zip243.py b/core/tests/test_apps.wallet.zcash.zip243.py index cb6a9848a..776179b85 100644 --- a/core/tests/test_apps.wallet.zcash.zip243.py +++ b/core/tests/test_apps.wallet.zcash.zip243.py @@ -5,10 +5,13 @@ from trezor.messages.TxInputType import TxInputType from trezor.messages.TxOutputBinType import TxOutputBinType from apps.common import coins -from apps.wallet.sign_tx.zcash import Zip243 + +if not utils.BITCOIN_ONLY: + from apps.wallet.sign_tx.zcash import Zip243 # test vectors inspired from https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0243.py +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestZcashZip243(unittest.TestCase): VECTORS = [ diff --git a/core/tests/test_trezor.crypto.curve.secp256k1.py b/core/tests/test_trezor.crypto.curve.secp256k1.py index a1f8b100b..ef435b91a 100644 --- a/core/tests/test_trezor.crypto.curve.secp256k1.py +++ b/core/tests/test_trezor.crypto.curve.secp256k1.py @@ -1,7 +1,11 @@ from common import * from trezor.crypto import random -from trezor.crypto.curve import secp256k1, secp256k1_zkp +from trezor.crypto.curve import secp256k1 + +if not utils.BITCOIN_ONLY: + from trezor.crypto.curve import secp256k1_zkp + class Secp256k1Common(object): impl = None @@ -137,6 +141,7 @@ class TestCryptoSecp256k1(Secp256k1Common, unittest.TestCase): def __init__(self): self.impl = secp256k1 +@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestCryptoSecp256k1Zkp(Secp256k1Common, unittest.TestCase): def __init__(self): self.impl = secp256k1_zkp.Context()