diff --git a/core/tests/test_apps.binance.address.py b/core/tests/test_apps.binance.address.py index 7326421a1..381deb6e1 100644 --- a/core/tests/test_apps.binance.address.py +++ b/core/tests/test_apps.binance.address.py @@ -4,7 +4,7 @@ from apps.common.paths import HARDENED from trezor.crypto.curve import secp256k1 if not utils.BITCOIN_ONLY: - from apps.binance.helpers import address_from_public_key, validate_full_path + from apps.binance.helpers import address_from_public_key @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @@ -20,33 +20,5 @@ class TestBinanceAddress(unittest.TestCase): self.assertEqual(address, expected_address) - def test_paths(self): - # 44'/714'/a'/0/0 is correct - incorrect_paths = [ - [44 | HARDENED], - [44 | HARDENED, 714 | HARDENED], - [44 | HARDENED, 714 | HARDENED, 0], - [44 | HARDENED, 714 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 714 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 714 | HARDENED, 0 | HARDENED, 1, 0], - [44 | HARDENED, 714 | HARDENED, 0 | HARDENED, 0, 5], - [44 | HARDENED, 714 | HARDENED, 9999 | HARDENED], - [44 | HARDENED, 714 | HARDENED, 9999000 | HARDENED, 0, 0], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0], - [1 | HARDENED, 1 | HARDENED, 1 | HARDENED], - ] - correct_paths = [ - [44 | HARDENED, 714 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 714 | HARDENED, 3 | HARDENED, 0, 0], - [44 | HARDENED, 714 | HARDENED, 9 | HARDENED, 0, 0], - ] - - for path in incorrect_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_paths: - self.assertTrue(validate_full_path(path)) - - if __name__ == '__main__': unittest.main() diff --git a/core/tests/test_apps.bitcoin.address.py b/core/tests/test_apps.bitcoin.address.py index 5a7a080b8..7d80112e6 100644 --- a/core/tests/test_apps.bitcoin.address.py +++ b/core/tests/test_apps.bitcoin.address.py @@ -1,12 +1,12 @@ from common import * from trezor.crypto import bip32, bip39 +from trezor.messages.GetAddress import GetAddress from trezor.utils import HashWriter -from apps.bitcoin.addresses import validate_full_path -from apps.common.paths import HARDENED from apps.common import coins from apps.bitcoin import scripts from apps.bitcoin.addresses import * +from apps.bitcoin.keychain import validate_path_against_script_type from apps.bitcoin.writers import * @@ -32,17 +32,17 @@ class TestAddress(unittest.TestCase): seed = bip39.seed(' '.join(['all'] * 12), '') root = bip32.from_seed(seed, 'secp256k1') - node = node_derive(root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0]) + node = node_derive(root, [H_(49), H_(1), H_(0), 1, 0]) address = address_p2wpkh_in_p2sh(node.public_key(), coin) self.assertEqual(address, '2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX') - node = node_derive(root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 1]) + node = node_derive(root, [H_(49), H_(1), H_(0), 1, 1]) address = address_p2wpkh_in_p2sh(node.public_key(), coin) self.assertEqual(address, '2NFWLCJQBSpz1oUJwwLpX8ECifFWGznBVqs') - node = node_derive(root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0]) + node = node_derive(root, [H_(49), H_(1), H_(0), 0, 0]) address = address_p2wpkh_in_p2sh(node.public_key(), coin) self.assertEqual(address, '2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp') @@ -129,96 +129,102 @@ class TestAddress(unittest.TestCase): # def test_multisig_address_p2wsh(self): # todo couldn't find test data + def validate(self, address_n, coin, script_type): + msg = GetAddress(address_n=address_n, script_type=script_type) + if script_type == InputScriptType.SPENDMULTISIG: + msg.multisig = True + return validate_path_against_script_type(coin, msg) + def test_paths_btc(self): incorrect_derivation_paths = [ - ([49 | HARDENED], InputScriptType.SPENDP2SHWITNESS), # invalid length - ([49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], InputScriptType.SPENDP2SHWITNESS), # too many HARDENED - ([49 | HARDENED, 0 | HARDENED], InputScriptType.SPENDP2SHWITNESS), # invalid length - ([49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0, 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid length - ([49 | HARDENED, 123 | HARDENED, 0 | HARDENED, 0, 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid slip44 - ([49 | HARDENED, 0 | HARDENED, 1000 | HARDENED, 0, 0], InputScriptType.SPENDP2SHWITNESS), # account too high - ([49 | HARDENED, 0 | HARDENED, 1 | HARDENED, 2, 0], InputScriptType.SPENDP2SHWITNESS), # invalid y - ([49 | HARDENED, 0 | HARDENED, 1 | HARDENED, 0, 10000000], InputScriptType.SPENDP2SHWITNESS), # address index too high - ([84 | HARDENED, 0 | HARDENED, 1 | HARDENED, 0, 10000000], InputScriptType.SPENDWITNESS), # address index too high - ([49 | HARDENED, 0 | HARDENED, 1 | HARDENED, 0, 0], InputScriptType.SPENDWITNESS), # invalid input type - ([84 | HARDENED, 0 | HARDENED, 1 | HARDENED, 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid input type - ([49 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 10], InputScriptType.SPENDMULTISIG), # invalid input type + ([H_(49)], InputScriptType.SPENDP2SHWITNESS), # invalid length + ([H_(49), H_(0), H_(0), H_(0), H_(0)], InputScriptType.SPENDP2SHWITNESS), # too many HARDENED + ([H_(49), H_(0)], InputScriptType.SPENDP2SHWITNESS), # invalid length + ([H_(49), H_(0), H_(0), 0, 0, 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid length + ([H_(49), H_(123), H_(0), 0, 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid slip44 + ([H_(49), H_(0), H_(1000), 0, 0], InputScriptType.SPENDP2SHWITNESS), # account too high + ([H_(49), H_(0), H_(1), 2, 0], InputScriptType.SPENDP2SHWITNESS), # invalid y + ([H_(49), H_(0), H_(1), 0, 10000000], InputScriptType.SPENDP2SHWITNESS), # address index too high + ([H_(84), H_(0), H_(1), 0, 10000000], InputScriptType.SPENDWITNESS), # address index too high + ([H_(49), H_(0), H_(1), 0, 0], InputScriptType.SPENDWITNESS), # invalid input type + ([H_(84), H_(0), H_(1), 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid input type + ([H_(49), H_(0), H_(5), 0, 10], InputScriptType.SPENDMULTISIG), # invalid input type ] correct_derivation_paths = [ - ([44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDADDRESS), # btc is segwit coin, but non-segwit paths are allowed as well - ([44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 1], InputScriptType.SPENDADDRESS), - ([44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0], InputScriptType.SPENDADDRESS), - ([49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDP2SHWITNESS), - ([49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0], InputScriptType.SPENDP2SHWITNESS), - ([49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 1123], InputScriptType.SPENDP2SHWITNESS), - ([49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 44444], InputScriptType.SPENDP2SHWITNESS), - ([49 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 0], InputScriptType.SPENDP2SHWITNESS), - ([84 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDWITNESS), - ([84 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 0], InputScriptType.SPENDWITNESS), - ([84 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 10], InputScriptType.SPENDWITNESS), - ([48 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 10], InputScriptType.SPENDMULTISIG), + ([H_(44), H_(0), H_(0), 0, 0], InputScriptType.SPENDADDRESS), # btc is segwit coin, but non-segwit paths are allowed as well + ([H_(44), H_(0), H_(0), 0, 1], InputScriptType.SPENDADDRESS), + ([H_(44), H_(0), H_(0), 1, 0], InputScriptType.SPENDADDRESS), + ([H_(49), H_(0), H_(0), 0, 0], InputScriptType.SPENDP2SHWITNESS), + ([H_(49), H_(0), H_(0), 1, 0], InputScriptType.SPENDP2SHWITNESS), + ([H_(49), H_(0), H_(0), 0, 1123], InputScriptType.SPENDP2SHWITNESS), + ([H_(49), H_(0), H_(0), 1, 44444], InputScriptType.SPENDP2SHWITNESS), + ([H_(49), H_(0), H_(5), 0, 0], InputScriptType.SPENDP2SHWITNESS), + ([H_(84), H_(0), H_(0), 0, 0], InputScriptType.SPENDWITNESS), + ([H_(84), H_(0), H_(5), 0, 0], InputScriptType.SPENDWITNESS), + ([H_(84), H_(0), H_(5), 0, 10], InputScriptType.SPENDWITNESS), + ([H_(48), H_(0), H_(5), H_(0), 0, 10], InputScriptType.SPENDMULTISIG), ] coin = coins.by_name('Bitcoin') + for path, input_type in incorrect_derivation_paths: - self.assertFalse(validate_full_path(path, coin, input_type)) + self.assertFalse(self.validate(path, coin, input_type)) for path, input_type in correct_derivation_paths: - self.assertTrue(validate_full_path(path, coin, input_type)) + self.assertTrue(self.validate(path, coin, input_type)) - self.assertTrue(validate_full_path([44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0], coin, InputScriptType.SPENDADDRESS)) - 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)) + self.assertTrue(self.validate([H_(44), H_(0), H_(0), 0, 0], coin, InputScriptType.SPENDADDRESS)) + self.assertFalse(self.validate([H_(44), H_(0), H_(0), 0, 0], coin, InputScriptType.SPENDWITNESS)) @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") def test_paths_bch(self): incorrect_derivation_paths = [ - ([44 | HARDENED], InputScriptType.SPENDADDRESS), # invalid length - ([44 | HARDENED, 145 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], InputScriptType.SPENDADDRESS), # too many HARDENED - ([49 | HARDENED, 145 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDP2SHWITNESS), # bch is not segwit coin so 49' is not allowed - ([84 | HARDENED, 145 | HARDENED, 1 | HARDENED, 0, 1], InputScriptType.SPENDWITNESS), # and neither is 84' - ([44 | HARDENED, 145 | HARDENED], InputScriptType.SPENDADDRESS), # invalid length - ([44 | HARDENED, 145 | HARDENED, 0 | HARDENED, 0, 0, 0, 0], InputScriptType.SPENDADDRESS), # invalid length - ([44 | HARDENED, 123 | HARDENED, 0 | HARDENED, 0, 0, 0], InputScriptType.SPENDADDRESS), # invalid slip44 - ([44 | HARDENED, 145 | HARDENED, 1000 | HARDENED, 0, 0], InputScriptType.SPENDADDRESS), # account too high - ([44 | HARDENED, 145 | HARDENED, 1 | HARDENED, 2, 0], InputScriptType.SPENDADDRESS), # invalid y - ([44 | HARDENED, 145 | HARDENED, 1 | HARDENED, 0, 10000000], InputScriptType.SPENDADDRESS), # address index too high - ([84 | HARDENED, 145 | HARDENED, 1 | HARDENED, 0, 10000000], InputScriptType.SPENDWITNESS), # address index too high - ([44 | HARDENED, 145 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDWITNESS), # input type mismatch + ([H_(44)], InputScriptType.SPENDADDRESS), # invalid length + ([H_(44), H_(145), H_(0), H_(0), H_(0)], InputScriptType.SPENDADDRESS), # too many HARDENED + ([H_(49), H_(145), H_(0), 0, 0], InputScriptType.SPENDP2SHWITNESS), # bch is not segwit coin so 49' is not allowed + ([H_(84), H_(145), H_(1), 0, 1], InputScriptType.SPENDWITNESS), # and neither is 84' + ([H_(44), H_(145)], InputScriptType.SPENDADDRESS), # invalid length + ([H_(44), H_(145), H_(0), 0, 0, 0, 0], InputScriptType.SPENDADDRESS), # invalid length + ([H_(44), H_(123), H_(0), 0, 0, 0], InputScriptType.SPENDADDRESS), # invalid slip44 + ([H_(44), H_(145), H_(1000), 0, 0], InputScriptType.SPENDADDRESS), # account too high + ([H_(44), H_(145), H_(1), 2, 0], InputScriptType.SPENDADDRESS), # invalid y + ([H_(44), H_(145), H_(1), 0, 10000000], InputScriptType.SPENDADDRESS), # address index too high + ([H_(84), H_(145), H_(1), 0, 10000000], InputScriptType.SPENDWITNESS), # address index too high + ([H_(44), H_(145), H_(0), 0, 0], InputScriptType.SPENDWITNESS), # input type mismatch ] correct_derivation_paths = [ - ([44 | HARDENED, 145 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDADDRESS), - ([44 | HARDENED, 145 | HARDENED, 0 | HARDENED, 1, 0], InputScriptType.SPENDADDRESS), - ([44 | HARDENED, 145 | HARDENED, 0 | HARDENED, 0, 1123], InputScriptType.SPENDADDRESS), - ([44 | HARDENED, 145 | HARDENED, 0 | HARDENED, 1, 44444], InputScriptType.SPENDADDRESS), - ([44 | HARDENED, 145 | HARDENED, 5 | HARDENED, 0, 0], InputScriptType.SPENDADDRESS), - ([48 | HARDENED, 145 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDMULTISIG), - ([48 | HARDENED, 145 | HARDENED, 5 | HARDENED, 0, 0], InputScriptType.SPENDMULTISIG), - ([48 | HARDENED, 145 | HARDENED, 5 | HARDENED, 0, 10], InputScriptType.SPENDMULTISIG), + ([H_(44), H_(145), H_(0), 0, 0], InputScriptType.SPENDADDRESS), + ([H_(44), H_(145), H_(0), 1, 0], InputScriptType.SPENDADDRESS), + ([H_(44), H_(145), H_(0), 0, 1123], InputScriptType.SPENDADDRESS), + ([H_(44), H_(145), H_(0), 1, 44444], InputScriptType.SPENDADDRESS), + ([H_(44), H_(145), H_(5), 0, 0], InputScriptType.SPENDADDRESS), + ([H_(48), H_(145), H_(0), H_(0), 0, 0], InputScriptType.SPENDMULTISIG), + ([H_(48), H_(145), H_(5), H_(0), 0, 0], InputScriptType.SPENDMULTISIG), + ([H_(48), H_(145), H_(5), H_(0), 0, 10], InputScriptType.SPENDMULTISIG), ] coin = coins.by_name('Bcash') # segwit is disabled for path, input_type in incorrect_derivation_paths: - self.assertFalse(validate_full_path(path, coin, input_type)) + self.assertFalse(self.validate(path, coin, input_type)) for path, input_type in correct_derivation_paths: - self.assertTrue(validate_full_path(path, coin, input_type)) + self.assertTrue(self.validate(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 + ([H_(44), H_(3), H_(0), 0, 0], InputScriptType.SPENDMULTISIG), # input type mismatch ] correct_derivation_paths = [ - ([44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0, 0], InputScriptType.SPENDADDRESS), - ([44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 1, 0], InputScriptType.SPENDADDRESS), - ([44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0, 1123], InputScriptType.SPENDADDRESS), - ([44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 1, 44444], InputScriptType.SPENDADDRESS), + ([H_(44), H_(3), H_(0), 0, 0], InputScriptType.SPENDADDRESS), + ([H_(44), H_(3), H_(0), 1, 0], InputScriptType.SPENDADDRESS), + ([H_(44), H_(3), H_(0), 0, 1123], InputScriptType.SPENDADDRESS), + ([H_(44), H_(3), H_(0), 1, 44444], InputScriptType.SPENDADDRESS), ] coin = coins.by_name('Dogecoin') # segwit is disabled for path, input_type in correct_derivation_paths: - self.assertTrue(validate_full_path(path, coin, input_type)) + self.assertTrue(self.validate(path, coin, input_type)) for path, input_type in incorrect_derivation_paths: - self.assertFalse(validate_full_path(path, coin, input_type)) + self.assertFalse(self.validate(path, coin, input_type)) if __name__ == '__main__': diff --git a/core/tests/test_apps.wallet.keychain.py b/core/tests/test_apps.bitcoin.keychain.py similarity index 53% rename from core/tests/test_apps.wallet.keychain.py rename to core/tests/test_apps.bitcoin.keychain.py index 6808992b0..611c73fe3 100644 --- a/core/tests/test_apps.wallet.keychain.py +++ b/core/tests/test_apps.bitcoin.keychain.py @@ -20,15 +20,23 @@ class TestBitcoinKeychain(unittest.TestCase): 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], + [H_(44), H_(0), H_(0), 0, 0], + [H_(45), 99, 1, 1000], + [H_(48), H_(0), H_(0), H_(2), 1, 1000], + [H_(49), H_(0), H_(0), 0, 10], + [H_(84), H_(0), H_(0), 0, 10], + # Casa: + [49, 0, 0, 0, 10], + # Green: + [1, 1000], + [H_(3), H_(10), 4, 1000], ) invalid_addresses = ( - [43 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 1 | HARDENED], + [H_(43), H_(0), H_(0), 0, 0], + [H_(44), H_(1), H_(0), 0, 0], + [44, 0, 0, 0, 0], + [H_(44), H_(0), H_(0)], + [H_(44), H_(0), H_(0), 0, 0, 0], ) for addr in valid_addresses: @@ -44,15 +52,23 @@ class TestBitcoinKeychain(unittest.TestCase): 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], + [H_(44), H_(1), H_(0), 0, 0], + [H_(45), 99, 1, 1000], + [H_(48), H_(1), H_(0), H_(2), 1, 1000], + [H_(49), H_(1), H_(0), 0, 10], + [H_(84), H_(1), H_(0), 0, 10], + # Casa: + [49, 1, 0, 0, 10], + # Green: + [1, 1000], + [H_(3), H_(10), 4, 1000], ) invalid_addresses = ( - [43 | HARDENED, 1 | HARDENED], - [44 | HARDENED, 0 | HARDENED], + [H_(43), H_(1), H_(0), 0, 0], + [H_(44), H_(0), H_(0), 0, 0], + [44, 1, 0, 0, 0], + [H_(44), H_(1), H_(0)], + [H_(44), H_(1), H_(0), 0, 0, 0], ) for addr in valid_addresses: @@ -64,7 +80,7 @@ class TestBitcoinKeychain(unittest.TestCase): 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]) + keychain.derive([H_(44), H_(0), H_(0), 0, 0]) def test_unknown(self): with self.assertRaises(wire.DataError): @@ -85,20 +101,29 @@ class TestAltcoinKeychains(unittest.TestCase): self.assertEqual(coin.coin_name, "Bcash") self.assertFalse(coin.segwit) + self.assertIsNotNone(coin.fork_id) + valid_addresses = ( - [44 | HARDENED, 145 | HARDENED], - [44 | HARDENED, 0 | HARDENED], - [45 | HARDENED, 123456], - [48 | HARDENED, 145 | HARDENED], - [48 | HARDENED, 0 | HARDENED], + [H_(44), H_(145), H_(0), 0, 0], + # Bitcoin paths should be allowed, as Bcash has strong replay protection + [H_(44), H_(0), H_(0), 0, 0], + [H_(45), 99, 1, 1000], + [H_(48), H_(145), H_(0), H_(0), 1, 1000], + [H_(48), H_(0), H_(0), H_(0), 1, 1000], ) invalid_addresses = ( - [43 | HARDENED, 145 | HARDENED], - [43 | HARDENED, 0 | HARDENED], - [49 | HARDENED, 145 | HARDENED], - [49 | HARDENED, 0 | HARDENED], - [84 | HARDENED, 145 | HARDENED], - [84 | HARDENED, 0 | HARDENED], + [H_(43), H_(145), H_(0), 0, 0], + [44, 145, 0, 0, 0], + [H_(44), H_(145), H_(0)], + [H_(44), H_(145), H_(0), 0, 0, 0], + # segwit: + [H_(49), H_(145), H_(0), 0, 10], + [H_(84), H_(145), H_(0), 0, 10], + # Casa: + [49, 145, 0, 0, 10], + # Green: + [1, 1000], + [H_(3), 10, 4, 1000], ) for addr in valid_addresses: @@ -115,18 +140,27 @@ class TestAltcoinKeychains(unittest.TestCase): self.assertTrue(coin.segwit) valid_addresses = ( - [44 | HARDENED, 2 | HARDENED], - [45 | HARDENED, 123456], - [48 | HARDENED, 2 | HARDENED], - [49 | HARDENED, 2 | HARDENED], - [84 | HARDENED, 2 | HARDENED], + [H_(44), H_(2), H_(0), 0, 0], + [H_(45), 99, 1, 1000], + [H_(48), H_(2), H_(0), H_(2), 1, 1000], + [H_(49), H_(2), H_(0), 0, 10], + [H_(84), H_(2), H_(0), 0, 10], ) invalid_addresses = ( - [43 | HARDENED, 2 | HARDENED], - [44 | HARDENED, 0 | HARDENED], - [48 | HARDENED, 0 | HARDENED], - [49 | HARDENED, 0 | HARDENED], - [84 | HARDENED, 0 | HARDENED], + [H_(43), H_(2), H_(0), 0, 0], + # Bitcoin paths: + [H_(44), H_(0), H_(0), 0, 0], + [H_(49), H_(0), H_(0), 0, 0], + [H_(84), H_(0), H_(0), 0, 0], + + [44, 2, 0, 0, 0], + [H_(44), H_(2), H_(0)], + [H_(44), H_(2), H_(0), 0, 0, 0], + # Casa: + [49, 2, 0, 0, 10], + # Green: + [1, 1000], + [H_(3), 10, 4, 1000], ) for addr in valid_addresses: diff --git a/core/tests/test_apps.bitcoin.ownership_proof.py b/core/tests/test_apps.bitcoin.ownership_proof.py index 3ed3152b3..8598084f8 100644 --- a/core/tests/test_apps.bitcoin.ownership_proof.py +++ b/core/tests/test_apps.bitcoin.ownership_proof.py @@ -6,7 +6,7 @@ from trezor.messages.HDNodeType import HDNodeType from apps.common import coins from apps.common.keychain import Keychain -from apps.common.paths import HARDENED +from apps.common.paths import HARDENED, AlwaysMatchingSchema from apps.bitcoin import ownership, scripts from apps.bitcoin.addresses import address_p2wpkh, address_p2wpkh_in_p2sh, address_multisig_p2wsh, address_multisig_p2wsh_in_p2sh, address_multisig_p2sh from apps.bitcoin.multisig import multisig_get_pubkeys @@ -17,7 +17,7 @@ class TestOwnershipProof(unittest.TestCase): def test_p2wpkh_gen_proof(self): coin = coins.by_name('Bitcoin') seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [[84 | HARDENED]], [[b"SLIP-0019"]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) commitment_data = b"" node = keychain.derive([84 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0]) @@ -43,7 +43,7 @@ class TestOwnershipProof(unittest.TestCase): def test_p2wpkh_in_p2sh_gen_proof(self): coin = coins.by_name('Bitcoin') seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [[49 | HARDENED]], [[b"SLIP-0019"]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) commitment_data = b"" node = keychain.derive([49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0]) @@ -70,7 +70,7 @@ class TestOwnershipProof(unittest.TestCase): def test_p2pkh_gen_proof(self): coin = coins.by_name('Bitcoin') seed = bip39.seed(' '.join(['all'] * 12), 'TREZOR') - keychain = Keychain(seed, coin.curve_name, [[44 | HARDENED]], [[b"SLIP-0019"]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) commitment_data = b"" node = keychain.derive([44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0]) @@ -96,7 +96,7 @@ class TestOwnershipProof(unittest.TestCase): def test_p2wpkh_verify_proof(self): coin = coins.by_name('Bitcoin') seed = bip39.seed(' '.join(['all'] * 12), 'TREZOR') - keychain = Keychain(seed, coin.curve_name, [], [[b"SLIP-0019"]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) commitment_data = b"" # Proof for "all all ... all" seed without passphrase. @@ -107,7 +107,7 @@ class TestOwnershipProof(unittest.TestCase): def test_p2wsh_gen_proof(self): coin = coins.by_name('Bitcoin') seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [[84 | HARDENED]], [[b"SLIP-0019"]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) commitment_data = b"TREZOR" nodes = [] @@ -167,7 +167,7 @@ class TestOwnershipProof(unittest.TestCase): def test_p2wsh_in_p2sh_gen_proof(self): coin = coins.by_name('Bitcoin') seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [[49 | HARDENED]], [[b"SLIP-0019"]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) commitment_data = b"" nodes = [] @@ -241,7 +241,7 @@ class TestOwnershipProof(unittest.TestCase): def test_p2sh_gen_proof(self): coin = coins.by_name('Bitcoin') seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [[48 | HARDENED]], [[b"SLIP-0019"]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) commitment_data = b"TREZOR" nodes = [] diff --git a/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py b/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py index 80c780e2d..9ab84aaa3 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py @@ -6,6 +6,7 @@ from apps.bitcoin.sign_tx.bitcoin import Hash143 from apps.bitcoin.writers import get_tx_hash from apps.common import coins from apps.common.keychain import Keychain +from apps.common.paths import AlwaysMatchingSchema from trezor.messages.SignTx import SignTx from trezor.messages.TxInput import TxInput from trezor.messages.TxOutput import TxOutput @@ -89,7 +90,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase): txo_bin = PrevOutput(amount=txo.amount, script_pubkey=script_pubkey) bip143.add_output(txo_bin, script_pubkey) - keychain = Keychain(seed, coin.curve_name, [[]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema]) node = keychain.derive(self.inp2.address_n) # test data public key hash diff --git a/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py b/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py index 87d62ef20..4c232d55c 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py +++ b/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py @@ -6,6 +6,7 @@ from apps.bitcoin.sign_tx.bitcoin import Hash143 from apps.bitcoin.writers import get_tx_hash from apps.common import coins from apps.common.keychain import Keychain +from apps.common.paths import AlwaysMatchingSchema from trezor.messages.SignTx import SignTx from trezor.messages.TxInput import TxInput from trezor.messages.TxOutput import TxOutput @@ -75,7 +76,7 @@ class TestSegwitBip143(unittest.TestCase): txo_bin = PrevOutput(amount=txo.amount, script_pubkey=script_pubkey) bip143.add_output(txo_bin, script_pubkey) - keychain = Keychain(seed, coin.curve_name, [[]]) + keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema]) node = keychain.derive(self.inp1.address_n) # test data public key hash diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py index 5bb851a52..2b98d5368 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py @@ -27,7 +27,7 @@ from trezor import wire from apps.common import coins from apps.common.keychain import Keychain -from apps.bitcoin.keychain import get_namespaces_for_coin +from apps.bitcoin.keychain import get_schemas_for_coin from apps.bitcoin.sign_tx import helpers, bitcoin from apps.bitcoin.sign_tx.approvers import BasicApprover @@ -157,7 +157,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() @@ -286,7 +286,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() @@ -347,7 +347,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): None ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py index ff2e1eb15..1cfea6e2a 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py @@ -26,7 +26,7 @@ from trezor.messages import OutputScriptType from apps.common import coins from apps.common.keychain import Keychain -from apps.bitcoin.keychain import get_namespaces_for_coin +from apps.bitcoin.keychain import get_schemas_for_coin from apps.bitcoin.sign_tx import bitcoinlike, helpers from apps.bitcoin.sign_tx.approvers import BasicApprover @@ -158,7 +158,7 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() @@ -287,7 +287,7 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py index 3b207d4b8..d87812460 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py @@ -27,7 +27,7 @@ from trezor import wire from apps.common import coins from apps.common.keychain import Keychain -from apps.bitcoin.keychain import get_namespaces_for_coin +from apps.bitcoin.keychain import get_schemas_for_coin from apps.bitcoin.sign_tx import bitcoin, helpers from apps.bitcoin.sign_tx.approvers import BasicApprover @@ -154,7 +154,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() @@ -291,7 +291,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() @@ -398,7 +398,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py index 7ca517bed..6b4822aab 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py @@ -26,7 +26,7 @@ from trezor.messages import OutputScriptType from apps.common import coins from apps.common.keychain import Keychain -from apps.bitcoin.keychain import get_namespaces_for_coin +from apps.bitcoin.keychain import get_schemas_for_coin from apps.bitcoin.sign_tx import bitcoinlike, helpers from apps.bitcoin.sign_tx.approvers import BasicApprover @@ -158,7 +158,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() @@ -295,7 +295,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): )), ] - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() diff --git a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py index 99e18197b..cf72803e5 100644 --- a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py +++ b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py @@ -25,6 +25,7 @@ from trezor.messages import OutputScriptType from apps.common import coins from apps.common.keychain import Keychain +from apps.common.paths import AlwaysMatchingSchema from apps.bitcoin.sign_tx import bitcoin, helpers from apps.bitcoin.sign_tx.approvers import BasicApprover @@ -161,7 +162,7 @@ class TestSignTxFeeThreshold(unittest.TestCase): seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '') - keychain = Keychain(seed, coin_bitcoin.curve_name, [[]]) + keychain = Keychain(seed, coin_bitcoin.curve_name, [AlwaysMatchingSchema]) approver = BasicApprover(tx, coin_bitcoin) signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin, approver).signer() for request, response in chunks(messages, 2): diff --git a/core/tests/test_apps.bitcoin.signtx.py b/core/tests/test_apps.bitcoin.signtx.py index 261d68e26..e94d9fe75 100644 --- a/core/tests/test_apps.bitcoin.signtx.py +++ b/core/tests/test_apps.bitcoin.signtx.py @@ -25,7 +25,7 @@ from trezor.messages import OutputScriptType from apps.common import coins from apps.common.keychain import Keychain -from apps.bitcoin.keychain import get_namespaces_for_coin +from apps.bitcoin.keychain import get_schemas_for_coin from apps.bitcoin.sign_tx import bitcoin, helpers from apps.bitcoin.sign_tx.approvers import BasicApprover @@ -107,7 +107,7 @@ class TestSignTx(unittest.TestCase): ] seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '') - ns = get_namespaces_for_coin(coin_bitcoin) + ns = get_schemas_for_coin(coin_bitcoin) keychain = Keychain(seed, coin_bitcoin.curve_name, ns) approver = BasicApprover(tx, coin_bitcoin) signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin, approver).signer() diff --git a/core/tests/test_apps.bitcoin.signtx_grs.py b/core/tests/test_apps.bitcoin.signtx_grs.py index 564de49ba..97f8a02b2 100644 --- a/core/tests/test_apps.bitcoin.signtx_grs.py +++ b/core/tests/test_apps.bitcoin.signtx_grs.py @@ -25,7 +25,7 @@ from trezor.messages import OutputScriptType from apps.common import coins from apps.common.keychain import Keychain -from apps.bitcoin.keychain import get_namespaces_for_coin +from apps.bitcoin.keychain import get_schemas_for_coin from apps.bitcoin.sign_tx import bitcoinlike, helpers from apps.bitcoin.sign_tx.approvers import BasicApprover @@ -101,7 +101,7 @@ class TestSignTx_GRS(unittest.TestCase): ] seed = bip39.seed(' '.join(['all'] * 12), '') - ns = get_namespaces_for_coin(coin) + ns = get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) approver = BasicApprover(tx, coin) signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() diff --git a/core/tests/test_apps.cardano.address.py b/core/tests/test_apps.cardano.address.py index 7c141d527..73f799149 100644 --- a/core/tests/test_apps.cardano.address.py +++ b/core/tests/test_apps.cardano.address.py @@ -8,14 +8,8 @@ from trezor.messages.CardanoBlockchainPointerType import CardanoBlockchainPointe from apps.common import HARDENED, seed if not utils.BITCOIN_ONLY: - from apps.cardano.address import ( - derive_human_readable_address, - validate_full_path, - ) - from apps.cardano.byron_address import ( - _get_address_root, - _address_hash, - ) + from apps.cardano.address import derive_human_readable_address + from apps.cardano.byron_address import _address_hash from apps.cardano.helpers import network_ids, protocol_magics from apps.cardano.seed import Keychain @@ -156,33 +150,6 @@ class TestCardanoAddress(unittest.TestCase): self.assertEqual(result, b'\x1c\xca\xee\xc9\x80\xaf}\xb0\x9a\xa8\x96E\xd6\xa4\xd1\xb4\x13\x85\xb9\xc2q\x1d5/{\x12"\xca') - def test_paths(self): - incorrect_derivation_paths = [ - [HARDENED | 44], - [HARDENED | 44, HARDENED | 1815, HARDENED | 1815, HARDENED | 1815, HARDENED | 1815, HARDENED | 1815], - [HARDENED | 43, HARDENED | 1815, HARDENED | 1815, HARDENED | 1815, HARDENED | 1815], - [HARDENED | 44, HARDENED | 1816, HARDENED | 1815, HARDENED | 1815, HARDENED | 1815], - [HARDENED | 44, HARDENED | 1815, 0], - [HARDENED | 44, HARDENED | 1815, 0, 0], - [HARDENED | 44, HARDENED | 1815], - [HARDENED | 44, HARDENED | 1815, HARDENED | 0], - [HARDENED | 44, HARDENED | 1815, HARDENED | 1815, 1, 1], - [HARDENED | 44, HARDENED | 1815, HARDENED | 1815, 0, 0], # a too large - ] - correct_derivation_paths = [ - [HARDENED | 44, HARDENED | 1815, HARDENED | 0, 0, 1], - [HARDENED | 44, HARDENED | 1815, HARDENED | 9, 0, 4], - [HARDENED | 44, HARDENED | 1815, HARDENED | 0, 0, 9], - [HARDENED | 44, HARDENED | 1815, HARDENED | 0, 1, 1], - [HARDENED | 44, HARDENED | 1815, HARDENED | 0, 1, 9], - ] - - for path in incorrect_derivation_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_derivation_paths: - self.assertTrue(validate_full_path(path)) - def test_slip39_128(self): mnemonics = [ "extra extend academic bishop cricket bundle tofu goat apart victim " diff --git a/core/tests/test_apps.common.paths.py b/core/tests/test_apps.common.paths.py index 35ac9e937..d9a9ae579 100644 --- a/core/tests/test_apps.common.paths.py +++ b/core/tests/test_apps.common.paths.py @@ -43,7 +43,7 @@ class TestPathSchemas(unittest.TestCase): def is_equal(a, b): if isinstance(a, range) and isinstance(b, range): return a.start == b.start and a.step == b.step and a.stop == b.stop - return a == b + return set(a) == set(b) ensure( all(is_equal(a, b) for a, b in zip(schema_a.schema, schema_b.schema)) @@ -63,8 +63,8 @@ class TestPathSchemas(unittest.TestCase): [H_(44), H_(0), H_(0), H_(0), H_(0)] * 10, ] for path in paths: - self.assertMatch(SCHEMA_ANY_PATH, path) - self.assertMismatch(SCHEMA_NO_MATCH, path) + self.assertMatch(AlwaysMatchingSchema, path) + self.assertMismatch(NeverMatchingSchema, path) def test_pattern_fixed(self): pattern = "m/44'/0'/0'/0/0" diff --git a/core/tests/test_apps.eos.get_public_key.py b/core/tests/test_apps.eos.get_public_key.py index 0cb48fa55..517aeb16d 100644 --- a/core/tests/test_apps.eos.get_public_key.py +++ b/core/tests/test_apps.eos.get_public_key.py @@ -5,7 +5,7 @@ from apps.common.paths import HARDENED if not utils.BITCOIN_ONLY: from apps.eos.get_public_key import _get_public_key - from apps.eos.helpers import validate_full_path, public_key_to_wif + from apps.eos.helpers import public_key_to_wif @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @@ -44,31 +44,6 @@ class TestEosGetPublicKey(unittest.TestCase): self.assertEqual(wif, wif_keys[index]) self.assertEqual(public_key_to_wif(public_key), wif_keys[index]) - def test_paths(self): - # 44'/194'/a'/0/0 is correct - incorrect_paths = [ - [44 | HARDENED], - [44 | HARDENED, 194 | HARDENED], - [44 | HARDENED, 194 | HARDENED, 0 | HARDENED, 0, 0, 0], - [44 | HARDENED, 194 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 194 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 194 | HARDENED, 0 | HARDENED, 1, 0], - [44 | HARDENED, 194 | HARDENED, 0 | HARDENED, 0, 1], - [44 | HARDENED, 160 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 199 | HARDENED, 0 | HARDENED, 0, 9999], - ] - correct_paths = [ - [44 | HARDENED, 194 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 194 | HARDENED, 9 | HARDENED, 0, 0], - [44 | HARDENED, 194 | HARDENED, 9999 | HARDENED, 0, 0], - ] - - for path in incorrect_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_paths: - self.assertTrue(validate_full_path(path)) - if __name__ == '__main__': unittest.main() diff --git a/core/tests/test_apps.ethereum.address.py b/core/tests/test_apps.ethereum.address.py index 816ba7b62..0db45db87 100644 --- a/core/tests/test_apps.ethereum.address.py +++ b/core/tests/test_apps.ethereum.address.py @@ -2,8 +2,8 @@ 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 + from apps.ethereum.address import address_from_bytes + from apps.ethereum.networks import NetworkInfo @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @@ -54,34 +54,6 @@ class TestEthereumGetAddress(unittest.TestCase): h = address_from_bytes(b, n) self.assertEqual(h, '0x' + s) - def test_paths(self): - # 44'/60'/0'/0/i is correct - incorrect_paths = [ - [44 | HARDENED], - [44 | HARDENED, 60 | HARDENED], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0, 0], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 1, 0], - [44 | HARDENED, 60 | HARDENED, 1 | HARDENED, 0, 0], - [44 | HARDENED, 160 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 199 | HARDENED, 0 | HARDENED, 0, 9999], # slip44 not one of ETH chains - ] - correct_paths = [ - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 9], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 9999], - [44 | HARDENED, 6060 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 5718350 | HARDENED, 0 | HARDENED, 0, 0], - ] - - for path in incorrect_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_paths: - self.assertTrue(validate_full_path(path)) - if __name__ == '__main__': unittest.main() diff --git a/core/tests/test_apps.ethereum.keychain.py b/core/tests/test_apps.ethereum.keychain.py index 7bfdc1239..ab40f8309 100644 --- a/core/tests/test_apps.ethereum.keychain.py +++ b/core/tests/test_apps.ethereum.keychain.py @@ -2,11 +2,14 @@ from common import * from storage import cache from trezor import wire from trezor.crypto import bip39 +from apps.common.keychain import get_keychain from apps.common.paths import HARDENED if not utils.BITCOIN_ONLY: + from apps.ethereum import CURVE from apps.ethereum.keychain import ( - from_address_n, + PATTERNS_ADDRESS, + _schemas_from_address_n, with_keychain_from_path, with_keychain_from_chain_id, ) @@ -21,19 +24,23 @@ class TestEthereumKeychain(unittest.TestCase): def _check_keychain(self, keychain, slip44_id): # valid address should succeed valid_addresses = ( - [44 | HARDENED, slip44_id | HARDENED], [44 | HARDENED, slip44_id | HARDENED, 0 | HARDENED], [44 | HARDENED, slip44_id | HARDENED, 19 | HARDENED], [44 | HARDENED, slip44_id | HARDENED, 0 | HARDENED, 0, 0], + [44 | HARDENED, slip44_id | HARDENED, 0 | HARDENED, 0, 999], ) for addr in valid_addresses: keychain.derive(addr) # invalid address should fail invalid_addresses = ( [44 | HARDENED], - [44 | HARDENED, 0 | HARDENED], - [42 | HARDENED, slip44_id | HARDENED], + [44 | HARDENED, slip44_id | HARDENED], + [44 | HARDENED, 0 | HARDENED, 0 | HARDENED], + [42 | HARDENED, slip44_id | HARDENED, 0 | HARDENED], [0 | HARDENED, slip44_id | HARDENED, 0 | HARDENED], + [44 | HARDENED, slip44_id | HARDENED, 0 | HARDENED, 0], + [44 | HARDENED, slip44_id | HARDENED, 0 | HARDENED, 0 | HARDENED, 0], + [44 | HARDENED, slip44_id | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], ) for addr in invalid_addresses: self.assertRaises( @@ -45,35 +52,27 @@ class TestEthereumKeychain(unittest.TestCase): seed = bip39.seed(" ".join(["all"] * 12), "") cache.set(cache.APP_COMMON_SEED, seed) + def from_address_n(self, address_n): + schemas = _schemas_from_address_n(PATTERNS_ADDRESS, address_n) + return await_result(get_keychain(wire.DUMMY_CONTEXT, CURVE, schemas)) + def test_from_address_n(self): # valid keychain m/44'/60'/0' - keychain = await_result( - from_address_n( - wire.DUMMY_CONTEXT, [44 | HARDENED, 60 | HARDENED, 0 | HARDENED] - ) - ) + keychain = self.from_address_n([44 | HARDENED, 60 | HARDENED, 0 | HARDENED]) self._check_keychain(keychain, 60) def test_from_address_n_unknown(self): # try Bitcoin slip44 id m/44'/0'/0' - with self.assertRaises(wire.DataError): - await_result( - from_address_n( - wire.DUMMY_CONTEXT, [44 | HARDENED, 0 | HARDENED, 0 | HARDENED] - ) - ) + schemas = tuple(_schemas_from_address_n(PATTERNS_ADDRESS, [44 | HARDENED, 0 | HARDENED, 0 | HARDENED])) + self.assertEqual(schemas, ()) def test_bad_address_n(self): # keychain generated from valid slip44 id but invalid address m/0'/60'/0' - keychain = await_result( - from_address_n( - wire.DUMMY_CONTEXT, [0 | HARDENED, 60 | HARDENED, 0 | HARDENED] - ) - ) + keychain = self.from_address_n([0 | HARDENED, 60 | HARDENED, 0 | HARDENED]) self._check_keychain(keychain, 60) def test_with_keychain_from_path(self): - @with_keychain_from_path + @with_keychain_from_path(*PATTERNS_ADDRESS) async def handler(ctx, msg, keychain): self._check_keychain(keychain, msg.address_n[1] & ~HARDENED) @@ -107,9 +106,9 @@ class TestEthereumKeychain(unittest.TestCase): def test_with_keychain_from_chain_id(self): @with_keychain_from_chain_id async def handler_chain_id(ctx, msg, keychain): - network = by_chain_id(msg.chain_id) + slip44_id = msg.address_n[1] & ~HARDENED # standard tests - self._check_keychain(keychain, network.slip44) + self._check_keychain(keychain, slip44_id) # provided address should succeed too keychain.derive(msg.address_n) @@ -133,6 +132,19 @@ class TestEthereumKeychain(unittest.TestCase): ) ) + # Known chain-ids are allowed to use Ethereum derivation paths too, as there is + # no risk of replaying the transaction on the Ethereum chain + await_result( # ETH slip44 with ETC chain-id + handler_chain_id( + wire.DUMMY_CONTEXT, + EthereumSignTx( + address_n=[44 | HARDENED, 60 | HARDENED, 0 | HARDENED], + chain_id=61, + ), + ) + ) + + with self.assertRaises(wire.DataError): await_result( # unknown chain_id handler_chain_id( @@ -149,7 +161,7 @@ class TestEthereumKeychain(unittest.TestCase): handler_chain_id( wire.DUMMY_CONTEXT, EthereumSignTx( - address_n=[44 | HARDENED, 60 | HARDENED, 0 | HARDENED], + address_n=[44 | HARDENED, 61 | HARDENED, 0 | HARDENED], chain_id=2, ), ) @@ -158,9 +170,9 @@ class TestEthereumKeychain(unittest.TestCase): def test_missing_chain_id(self): @with_keychain_from_chain_id async def handler_chain_id(ctx, msg, keychain): - network = by_slip44(msg.address_n[1] & ~HARDENED) + slip44_id = msg.address_n[1] & ~HARDENED # standard tests - self._check_keychain(keychain, network.slip44) + self._check_keychain(keychain, slip44_id) # provided address should succeed too keychain.derive(msg.address_n) diff --git a/core/tests/test_apps.lisk.address.py b/core/tests/test_apps.lisk.address.py deleted file mode 100644 index 436118256..000000000 --- a/core/tests/test_apps.lisk.address.py +++ /dev/null @@ -1,39 +0,0 @@ -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): - # 44'/134'/a' is correct - incorrect_paths = [ - [44 | HARDENED], - [44 | HARDENED, 134 | HARDENED], - [44 | HARDENED, 134 | HARDENED, 0], - [44 | HARDENED, 134 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 134 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 134 | HARDENED, 0 | HARDENED, 1, 0], - [44 | HARDENED, 134 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 134 | HARDENED, 9999000 | HARDENED], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0], - [1 | HARDENED, 1 | HARDENED, 1 | HARDENED], - ] - correct_paths = [ - [44 | HARDENED, 134 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 134 | HARDENED, 3 | HARDENED], - [44 | HARDENED, 134 | HARDENED, 9 | HARDENED], - ] - - for path in incorrect_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_paths: - self.assertTrue(validate_full_path(path)) - - -if __name__ == '__main__': - unittest.main() diff --git a/core/tests/test_apps.monero.address.py b/core/tests/test_apps.monero.address.py deleted file mode 100644 index 25d2f8424..000000000 --- a/core/tests/test_apps.monero.address.py +++ /dev/null @@ -1,39 +0,0 @@ -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): - # 44'/128'/a' is correct - incorrect_paths = [ - [44 | HARDENED], - [44 | HARDENED, 128 | HARDENED], - [44 | HARDENED, 128 | HARDENED, 0], - [44 | HARDENED, 128 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 128 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 128 | HARDENED, 0 | HARDENED, 1, 0], - [44 | HARDENED, 128 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 128 | HARDENED, 9999000 | HARDENED], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0], - [1 | HARDENED, 1 | HARDENED, 1 | HARDENED], - ] - correct_paths = [ - [44 | HARDENED, 128 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 128 | HARDENED, 3 | HARDENED], - [44 | HARDENED, 128 | HARDENED, 9 | HARDENED], - ] - - for path in incorrect_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_paths: - self.assertTrue(validate_full_path(path)) - - -if __name__ == '__main__': - unittest.main() diff --git a/core/tests/test_apps.nem.address.py b/core/tests/test_apps.nem.address.py index 53ac7695f..945c24488 100644 --- a/core/tests/test_apps.nem.address.py +++ b/core/tests/test_apps.nem.address.py @@ -3,7 +3,7 @@ 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 + from apps.nem.helpers import check_path, NEM_NETWORK_MAINNET, NEM_NETWORK_TESTNET, NEM_NETWORK_MIJIN @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @@ -35,46 +35,26 @@ class TestNemAddress(unittest.TestCase): validity = nem.validate_address('NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP', NEM_NETWORK_TESTNET) self.assertFalse(validity) - def test_paths(self): - # 44'/43'/0'/0'/0' - self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED])) - # 44'/43'/0'/0'/0' - self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0 | HARDENED])) - # 44'/1'/0'/0'/0' testnet - self.assertTrue(check_path([44 | HARDENED, 1 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0 | HARDENED], network=0x98)) - # 44'/43'/0' - self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED])) - # 44'/43'/2' - self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED, 2 | HARDENED])) - # 44'/1'/0' testnet - self.assertTrue(check_path([44 | HARDENED, 1 | HARDENED, 0 | HARDENED], network=0x98)) - - # 44'/43'/0'/0'/1' - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1 | HARDENED])) - # 44'/43'/0'/1'/1' - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 1 | HARDENED, 1 | HARDENED])) - # 44'/43'/0'/1'/0' - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 1 | HARDENED, 0 | HARDENED])) - # 44'/43'/99999'/0'/0' - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 99999000 | HARDENED, 0 | HARDENED, 0 | HARDENED])) - # 44'/99'/0'/0'/0' - self.assertFalse(check_path([44 | HARDENED, 99 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED])) - # 1'/43'/0'/0'/0' - self.assertFalse(check_path([1 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED])) - # 44'/43'/0'/0/0 - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0, 0])) - # 44'/43'/0'/0/5 - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0, 5])) - # 44'/1'/3'/0'/1' testnet - self.assertFalse(check_path([44 | HARDENED, 1 | HARDENED, 3 | HARDENED, 0 | HARDENED, 1 | HARDENED], network=0x98)) - - # 44'/43'/0/0/1 - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0, 0, 1])) - # 44'/43'/0/0/0 - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0, 0, 0])) - # 44'/43'/0/0'/0' - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0, 0 | HARDENED, 0 | HARDENED])) - + def test_check_path(self): + # mainnet path: + self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_MAINNET)) + # should be valid on mijin as well: + self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_MIJIN)) + # testnet path: + self.assertTrue(check_path([44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_TESTNET)) + # short path (check_path does not validate pattern match): + self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED], NEM_NETWORK_MAINNET)) + + # testnet path on mainnet: + self.assertFalse(check_path([44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_MAINNET)) + # mainnet path on testnet: + self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_TESTNET)) + # path too short to extract SLIP44: + self.assertFalse(check_path([44 | HARDENED], NEM_NETWORK_TESTNET)) + # unknown SLIP44: + self.assertFalse(check_path([44 | HARDENED, 0 | HARDENED], NEM_NETWORK_MAINNET)) + # unhardened SLIP44: + self.assertFalse(check_path([44 | HARDENED, 43, 0], NEM_NETWORK_MAINNET)) if __name__ == '__main__': diff --git a/core/tests/test_apps.ripple.address.py b/core/tests/test_apps.ripple.address.py index 320d44a84..69d7dfad4 100644 --- a/core/tests/test_apps.ripple.address.py +++ b/core/tests/test_apps.ripple.address.py @@ -1,8 +1,7 @@ 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 + from apps.ripple.helpers import address_from_public_key @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @@ -18,33 +17,6 @@ class TestRippleAddress(unittest.TestCase): addr = address_from_public_key(unhexlify('0282ee731039929e97db6aec242002e9aa62cd62b989136df231f4bb9b8b7c7eb2')) self.assertEqual(addr, 'rKzE5DTyF9G6z7k7j27T2xEas2eMo85kmw') - def test_paths(self): - # 44'/144'/a'/0/0 is correct - incorrect_paths = [ - [44 | HARDENED], - [44 | HARDENED, 144 | HARDENED], - [44 | HARDENED, 144 | HARDENED, 0], - [44 | HARDENED, 144 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 144 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 144 | HARDENED, 0 | HARDENED, 1, 0], - [44 | HARDENED, 144 | HARDENED, 0 | HARDENED, 0, 5], - [44 | HARDENED, 144 | HARDENED, 9999 | HARDENED], - [44 | HARDENED, 144 | HARDENED, 9999000 | HARDENED, 0, 0], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0], - [1 | HARDENED, 1 | HARDENED, 1 | HARDENED], - ] - correct_paths = [ - [44 | HARDENED, 144 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 144 | HARDENED, 3 | HARDENED, 0, 0], - [44 | HARDENED, 144 | HARDENED, 9 | HARDENED, 0, 0], - ] - - for path in incorrect_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_paths: - self.assertTrue(validate_full_path(path)) - if __name__ == '__main__': unittest.main() diff --git a/core/tests/test_apps.stellar.address.py b/core/tests/test_apps.stellar.address.py index 2b29b0658..bb59e9a83 100644 --- a/core/tests/test_apps.stellar.address.py +++ b/core/tests/test_apps.stellar.address.py @@ -1,9 +1,8 @@ from common import * -from apps.common.paths import HARDENED 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 + from apps.stellar.helpers import address_from_public_key, public_key_from_address @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @@ -37,32 +36,6 @@ class TestStellarAddress(unittest.TestCase): with self.assertRaises(ProcessError): public_key_from_address('GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2AA') # invalid checksum - def test_paths(self): - # 44'/148'/a' is correct - incorrect_paths = [ - [44 | HARDENED], - [44 | HARDENED, 148 | HARDENED], - [44 | HARDENED, 148 | HARDENED, 0], - [44 | HARDENED, 148 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 148 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 148 | HARDENED, 0 | HARDENED, 1, 0], - [44 | HARDENED, 148 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 148 | HARDENED, 9999000 | HARDENED], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0], - [1 | HARDENED, 1 | HARDENED, 1 | HARDENED], - ] - correct_paths = [ - [44 | HARDENED, 148 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 148 | HARDENED, 3 | HARDENED], - [44 | HARDENED, 148 | HARDENED, 9 | HARDENED], - ] - - for path in incorrect_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_paths: - self.assertTrue(validate_full_path(path)) - if __name__ == '__main__': unittest.main() diff --git a/core/tests/test_apps.tezos.address.py b/core/tests/test_apps.tezos.address.py index 797e1b6b2..ac353c074 100644 --- a/core/tests/test_apps.tezos.address.py +++ b/core/tests/test_apps.tezos.address.py @@ -4,7 +4,6 @@ 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 @@ -41,36 +40,6 @@ class TestTezosAddress(unittest.TestCase): for i, contract in enumerate(contracts): self.assertEqual(_get_address_from_contract(contract), outputs[i]) - def test_paths(self): - # 44'/1729'/a' is correct - incorrect_paths = [ - [44 | HARDENED], - [44 | HARDENED, 1729 | HARDENED], - [44 | HARDENED, 1729 | HARDENED, 0], - [44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0], - [44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 1, 0], - [44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0, 0], - [44 | HARDENED, 1729 | HARDENED, 1 | HARDENED, 1 | HARDENED], - [44 | HARDENED, 1729 | HARDENED, 9999000 | HARDENED], - [44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0], - [1 | HARDENED, 1 | HARDENED, 1 | HARDENED], - ] - correct_paths = [ - [44 | HARDENED, 1729 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 1729 | HARDENED, 3 | HARDENED], - [44 | HARDENED, 1729 | HARDENED, 9 | HARDENED], - [44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 3 | HARDENED], - [44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 9 | HARDENED], - ] - - for path in incorrect_paths: - self.assertFalse(validate_full_path(path)) - - for path in correct_paths: - self.assertTrue(validate_full_path(path)) - if __name__ == "__main__": unittest.main()