1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-28 00:58:09 +00:00

core: fix unit tests for Bitcoin only firmware

This commit is contained in:
Pavol Rusnak 2019-08-26 18:47:49 +02:00
parent 908bbfffef
commit 32edf7b6b9
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
40 changed files with 284 additions and 188 deletions

View File

@ -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

View File

@ -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

View File

@ -1,10 +1,11 @@
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
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
@ -13,6 +14,7 @@ from trezor.messages.BinanceSignTx import BinanceSignTx
from trezor.messages.BinanceTransferMsg import BinanceTransferMsg
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestBinanceSign(unittest.TestCase):
def test_order_signature(self):
# source of testing data

View File

@ -2,6 +2,8 @@ from common import *
from apps.common import seed
from apps.common import HARDENED
from trezor.crypto import bip32, slip39
if not utils.BITCOIN_ONLY:
from apps.cardano.address import (
_get_address_root,
_address_hash,
@ -9,9 +11,9 @@ from apps.cardano.address import (
derive_address_and_node
)
from apps.cardano.seed import Keychain
from trezor.crypto import bip32, slip39
@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"

View File

@ -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"

View File

@ -6,7 +6,6 @@ from apps.common.cbor import (
decode,
encode,
)
from ubinascii import unhexlify
class TestCardanoCbor(unittest.TestCase):
def test_cbor_encoding(self):

View File

@ -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),

View File

@ -1,5 +1,6 @@
from common import *
if not utils.BITCOIN_ONLY:
from apps.eos.actions import check_action
from trezor.messages.EosTxActionAck import EosTxActionAck
from trezor.messages.EosActionBuyRam import EosActionBuyRam
@ -17,6 +18,7 @@ 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

View File

@ -1,8 +1,11 @@
from common import *
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 = [

View File

@ -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
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"

View File

@ -1,9 +1,12 @@
from common import *
from apps.common.paths import HARDENED
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):

View File

@ -1,8 +1,11 @@
from common import *
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):

View File

@ -1,7 +1,10 @@
from common import *
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):

View File

@ -1,8 +1,11 @@
from common import *
from apps.common.paths import HARDENED
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):

View File

@ -1,8 +1,11 @@
from common import *
from apps.common.paths import HARDENED
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):

View File

@ -1,10 +1,13 @@
from common import *
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

View File

@ -1,12 +1,15 @@
from common import *
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"

View File

@ -2,6 +2,7 @@ import utest
from common import *
from trezor import log, loop, utils
if not utils.BITCOIN_ONLY:
from apps.monero.xmr.serialize.int_serialize import (
dump_uint,
dump_uvarint,
@ -19,6 +20,7 @@ from apps.monero.xmr.serialize_messages.tx_prefix import (
)
if not utils.BITCOIN_ONLY:
class XmrTstData(object):
"""Simple tests data generator"""
@ -68,6 +70,7 @@ class XmrTstData(object):
return msg
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestMoneroSerializer(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(TestMoneroSerializer, self).__init__(*args, **kwargs)

View File

@ -1,10 +1,12 @@
from common import *
from ubinascii import unhexlify
from trezor.crypto import nem
from apps.common import HARDENED
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):

View File

@ -1,10 +1,12 @@
from common import *
from ubinascii import unhexlify
from trezor.crypto import bip32
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):

View File

@ -1,10 +1,13 @@
from common 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):

View File

@ -1,15 +1,17 @@
from common import *
from trezor.crypto import hashlib
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 *
from trezor.crypto import hashlib
from trezor.messages.NEMSignTx import NEMSignTx
from trezor.messages.NEMMosaicCreation import NEMMosaicCreation
from trezor.messages.NEMMosaicDefinition import NEMMosaicDefinition
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestNemMosaicCreation(unittest.TestCase):
def test_nem_transaction_mosaic_creation(self):

View File

@ -1,14 +1,16 @@
from common import *
from trezor.crypto import hashlib
if not utils.BITCOIN_ONLY:
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
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestNemMosaicSupplyChange(unittest.TestCase):
def test_nem_transaction_create_mosaic_supply_change(self):

View File

@ -1,15 +1,17 @@
from common import *
from trezor.crypto import hashlib
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

View File

@ -1,17 +1,18 @@
from common import *
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):

View File

@ -1,14 +1,16 @@
from common import *
from trezor.crypto import hashlib
if not utils.BITCOIN_ONLY:
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
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestNemNamespace(unittest.TestCase):
def test_create_provision_namespace(self):

View File

@ -1,15 +1,17 @@
from common import *
from trezor.crypto import hashlib
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.crypto import hashlib
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):

View File

@ -1,8 +1,11 @@
from common import *
from apps.common.paths import HARDENED
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):

View File

@ -1,11 +1,13 @@
from common import *
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

View File

@ -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):

View File

@ -1,14 +1,15 @@
from ubinascii import unhexlify
from common import *
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
from apps.tezos.sign_tx import _get_address_from_contract
from apps.tezos.helpers import validate_full_path
from apps.common.paths import HARDENED
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestTezosAddress(unittest.TestCase):
def test_get_address_from_contract(self):
contracts = [

View File

@ -1,9 +1,8 @@
from ubinascii import unhexlify
from common import *
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,
@ -12,6 +11,7 @@ from apps.tezos.sign_tx import (
)
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestTezosEncoding(unittest.TestCase):
def test_tezos_encode_zarith(self):
inputs = [2000000, 159066, 200, 60000, 157000000, 0]

View File

@ -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
]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -5,10 +5,13 @@ from trezor.messages.TxInputType import TxInputType
from trezor.messages.TxOutputBinType import TxOutputBinType
from apps.common import coins
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 = [

View File

@ -5,10 +5,13 @@ from trezor.messages.TxInputType import TxInputType
from trezor.messages.TxOutputBinType import TxOutputBinType
from apps.common import coins
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 = [

View File

@ -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()