def test_generate_invalid_arguments(self):
     # noinspection PyTypeChecker
     for test_entropy in self.TESTING_TYPES + ['some string']:
         with self.assertRaisesRegex(TypeError, 'argument `entropy` should be of type Entropy'):
             generate(test_entropy, VALID_PASSWORD_TREZOR)
     # noinspection PyTypeChecker
     for test_password in self.TESTING_TYPES + [b'\xff']:
         with self.assertRaisesRegex(TypeError, 'argument `seed_password` should be of type str'):
             generate(VALID_ENTROPY_TREZOR, test_password)
 def test_generate(self):
     for i in range(self.SUBTEST_COUNT):
         password = get_random_valid_password()
         entropy_bytes = get_random_valid_entropy_bytes()
         with self.subTest(i=i,
                           entropy_bytes=entropy_bytes,
                           password=password):
             mnemonic_slytherin, seed__slytherin = generate(
                 Entropy(entropy_bytes), password)
             mnemonic_trezor = self.trezor.to_mnemonic(entropy_bytes)
             seed_trezor = self.trezor.to_seed(mnemonic_trezor, password)
             self.assertEqual(mnemonic_trezor, mnemonic_slytherin)
             # `bytes(seed__slytherin)` cant use secure seed compare here hence the conversion to bytes
             self.assertEqual(seed_trezor, bytes(seed__slytherin))
 def test_generate_invalid_password_invalid_utf8(self):
     with self.assertRaises(UnicodeError):
         generate(VALID_ENTROPY_TREZOR, INVALID_PASSWORD_INVALID_UTF8)
 def test_generate_invalid_password_too_long(self):
     password = '******' * 1024 * 1024  # 1 MB
     with self.assertRaises(ValueError):
         generate(VALID_ENTROPY_TREZOR, password)
 def test_generate(self):
     for test_vector in TREZOR_TEST_VECTORS['english']:
         mnemonic, seed = generate(Entropy(unhexlify(test_vector[0])), TREZOR_PASSWORD)
         self.assertEqual(Mnemonic(test_vector[1]), mnemonic)
         self.assertEqual(Seed(unhexlify(test_vector[2])), seed)