mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-27 01:48:17 +00:00
445f56d387
- core/bitcoin: move common files to the app's root - core/bitcoin: use require_confirm instead of confirm - core: move bitcoin unrelated functions from 'bitcoin' to a new 'misc' app - core/bitcoin: use relative imports inside the app - core: rename wallet app to bitcoin - core/wallet: replace SigningErrors and the other exception classes with wire.Errors
109 lines
3.3 KiB
Python
109 lines
3.3 KiB
Python
from common import *
|
|
from storage import cache
|
|
from trezor import wire
|
|
from trezor.crypto import bip39
|
|
from apps.common.paths import HARDENED
|
|
|
|
from apps.bitcoin.keychain import get_keychain_for_coin
|
|
|
|
|
|
class TestBitcoinKeychain(unittest.TestCase):
|
|
def setUp(self):
|
|
cache.start_session()
|
|
seed = bip39.seed(" ".join(["all"] * 12), "")
|
|
cache.set(cache.APP_COMMON_SEED, seed)
|
|
|
|
def test_bitcoin(self):
|
|
keychain, coin = await_result(
|
|
get_keychain_for_coin(wire.DUMMY_CONTEXT, "Bitcoin")
|
|
)
|
|
self.assertEqual(coin.coin_name, "Bitcoin")
|
|
|
|
valid_addresses = (
|
|
[44 | HARDENED, 0 | HARDENED],
|
|
[45 | HARDENED, 123456],
|
|
[48 | HARDENED, 0 | HARDENED],
|
|
[49 | HARDENED, 0 | HARDENED],
|
|
[84 | HARDENED, 0 | HARDENED],
|
|
)
|
|
invalid_addresses = (
|
|
[43 | HARDENED, 0 | HARDENED],
|
|
[44 | HARDENED, 1 | HARDENED],
|
|
)
|
|
|
|
for addr in valid_addresses:
|
|
keychain.derive(addr)
|
|
|
|
for addr in invalid_addresses:
|
|
self.assertRaises(wire.DataError, keychain.derive, addr)
|
|
|
|
def test_testnet(self):
|
|
keychain, coin = await_result(
|
|
get_keychain_for_coin(wire.DUMMY_CONTEXT, "Testnet")
|
|
)
|
|
self.assertEqual(coin.coin_name, "Testnet")
|
|
|
|
valid_addresses = (
|
|
[44 | HARDENED, 1 | HARDENED],
|
|
[45 | HARDENED, 123456],
|
|
[48 | HARDENED, 1 | HARDENED],
|
|
[49 | HARDENED, 1 | HARDENED],
|
|
[84 | HARDENED, 1 | HARDENED],
|
|
)
|
|
invalid_addresses = (
|
|
[43 | HARDENED, 1 | HARDENED],
|
|
[44 | HARDENED, 0 | HARDENED],
|
|
)
|
|
|
|
for addr in valid_addresses:
|
|
keychain.derive(addr)
|
|
|
|
for addr in invalid_addresses:
|
|
self.assertRaises(wire.DataError, keychain.derive, addr)
|
|
|
|
def test_unspecified(self):
|
|
keychain, coin = await_result(get_keychain_for_coin(wire.DUMMY_CONTEXT, None))
|
|
self.assertEqual(coin.coin_name, "Bitcoin")
|
|
keychain.derive([44 | HARDENED, 0 | HARDENED])
|
|
|
|
def test_unknown(self):
|
|
with self.assertRaises(wire.DataError):
|
|
await_result(get_keychain_for_coin(wire.DUMMY_CONTEXT, "MadeUpCoin2020"))
|
|
|
|
|
|
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
|
class TestAltcoinKeychains(unittest.TestCase):
|
|
def setUp(self):
|
|
cache.start_session()
|
|
seed = bip39.seed(" ".join(["all"] * 12), "")
|
|
cache.set(cache.APP_COMMON_SEED, seed)
|
|
|
|
def test_bcash(self):
|
|
keychain, coin = await_result(
|
|
get_keychain_for_coin(wire.DUMMY_CONTEXT, "Bcash")
|
|
)
|
|
self.assertEqual(coin.coin_name, "Bcash")
|
|
|
|
self.assertFalse(coin.segwit)
|
|
valid_addresses = (
|
|
[44 | HARDENED, 145 | HARDENED],
|
|
[45 | HARDENED, 123456],
|
|
[48 | HARDENED, 145 | HARDENED],
|
|
)
|
|
invalid_addresses = (
|
|
[43 | HARDENED, 145 | HARDENED],
|
|
[44 | HARDENED, 0 | HARDENED],
|
|
[49 | HARDENED, 145 | HARDENED],
|
|
[84 | HARDENED, 145 | HARDENED],
|
|
)
|
|
|
|
for addr in valid_addresses:
|
|
keychain.derive(addr)
|
|
|
|
for addr in invalid_addresses:
|
|
self.assertRaises(wire.DataError, keychain.derive, addr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|