Exemplo n.º 1
0
 def test_encrypt_decrypt(self, mock_write):
     wallet = restore_wallet_from_text('p2wpkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN',
                                       path='if_this_exists_mocking_failed_648151893')['wallet']
     cmds = Commands(config=None, wallet=wallet, network=None)
     cleartext = "asdasd this is the message"
     pubkey = "021f110909ded653828a254515b58498a6bafc96799fb0851554463ed44ca7d9da"
     ciphertext = cmds.encrypt(pubkey, cleartext)
     self.assertEqual(cleartext, cmds.decrypt(pubkey, ciphertext))
Exemplo n.º 2
0
 def test_restore_wallet_from_text_addresses(self):
     text = 'bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw bc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu66960c'
     d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
     wallet = d['wallet']  # type: Imported_Wallet
     self.assertEqual('bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw',
                      wallet.get_receiving_addresses()[0])
     self.assertEqual(2, len(wallet.get_receiving_addresses()))
     # also test addr deletion
     wallet.delete_address('bc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu66960c')
     self.assertEqual(1, len(wallet.get_receiving_addresses()))
Exemplo n.º 3
0
 def test_restore_wallet_from_text_xpub(self):
     text = 'zpub6nydoME6CFdJtMpzHW5BNoPz6i6XbeT9qfz72wsRqGdgGEYeivso6xjfw8cGcCyHwF7BNW4LDuHF35XrZsovBLWMF4qXSjmhTXYiHbWqGLt'
     d = restore_wallet_from_text(text,
                                  path=self.wallet_path,
                                  network=None,
                                  gap_limit=1)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(text, wallet.keystore.get_master_public_key())
     self.assertEqual('bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw',
                      wallet.get_receiving_addresses()[0])
Exemplo n.º 4
0
 def test_restore_wallet_from_text_xprv(self):
     text = 'zprvAZzHPqhCMt51fskXBUYB1fTFYgG3CBjJUT4WEZTpGw6hPSDWBPZYZARC5sE9xAcX8NeWvvucFws8vZxEa65RosKAhy7r5MsmKTxr3hmNmea'
     d = restore_wallet_from_text(text,
                                  path=self.wallet_path,
                                  network=None,
                                  gap_limit=1)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(text,
                      wallet.keystore.get_master_private_key(password=None))
     self.assertEqual('bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw',
                      wallet.get_receiving_addresses()[0])
Exemplo n.º 5
0
 def test_restore_wallet_from_text_xkey_that_is_also_a_valid_electrum_seed_by_chance(
         self):
     text = 'yprvAJBpuoF4FKpK92ofzQ7ge6VJMtorow3maAGPvPGj38ggr2xd1xCrC9ojUVEf9jhW5L9SPu6fU2U3o64cLrRQ83zaQGNa6YP3ajZS6hHNPXj'
     d = restore_wallet_from_text(text,
                                  path=self.wallet_path,
                                  network=None,
                                  gap_limit=1)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(text,
                      wallet.keystore.get_master_private_key(password=None))
     self.assertEqual('3Pa4hfP3LFWqa2nfphYaF7PZfdJYNusAnp',
                      wallet.get_receiving_addresses()[0])
Exemplo n.º 6
0
 def test_restore_wallet_from_text_privkeys(self):
     text = 'p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL p2wpkh:L24GxnN7NNUAfCXA6hFzB1jt59fYAAiFZMcLaJ2ZSawGpM3uqhb1'
     d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
     wallet = d['wallet']  # type: Imported_Wallet
     addr0 = wallet.get_receiving_addresses()[0]
     self.assertEqual('bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', addr0)
     self.assertEqual(
         'p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL',
         wallet.export_private_key(addr0, password=None)[0])
     self.assertEqual(2, len(wallet.get_receiving_addresses()))
     # also test addr deletion
     wallet.delete_address('bc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu66960c')
     self.assertEqual(1, len(wallet.get_receiving_addresses()))
Exemplo n.º 7
0
 def test_export_private_key_imported(self, mock_write):
     wallet = restore_wallet_from_text('p2wpkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL',
                                       path='if_this_exists_mocking_failed_648151893')['wallet']
     cmds = Commands(config=None, wallet=wallet, network=None)
     # single address tests
     with self.assertRaises(Exception):
         cmds.getprivatekeys("asdasd")  # invalid addr, though might raise "not in wallet"
     with self.assertRaises(Exception):
         cmds.getprivatekeys("bc1qgfam82qk7uwh5j2xxmcd8cmklpe0zackyj6r23")  # not in wallet
     self.assertEqual("p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL",
                      cmds.getprivatekeys("bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw"))
     # list of addresses tests
     with self.assertRaises(Exception):
         cmds.getprivatekeys(['bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', 'asd'])
     self.assertEqual(['p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL', 'p2wpkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN'],
                      cmds.getprivatekeys(['bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', 'bc1q9pzjpjq4nqx5ycnywekcmycqz0wjp2nq604y2n']))
Exemplo n.º 8
0
 def test_export_private_key_deterministic(self, mock_write):
     wallet = restore_wallet_from_text('bitter grass shiver impose acquire brush forget axis eager alone wine silver',
                                       gap_limit=2,
                                       path='if_this_exists_mocking_failed_648151893')['wallet']
     cmds = Commands(config=None, wallet=wallet, network=None)
     # single address tests
     with self.assertRaises(Exception):
         cmds.getprivatekeys("asdasd")  # invalid addr, though might raise "not in wallet"
     with self.assertRaises(Exception):
         cmds.getprivatekeys("bc1qgfam82qk7uwh5j2xxmcd8cmklpe0zackyj6r23")  # not in wallet
     self.assertEqual("p2wpkh:L15oxP24NMNAXxq5r2aom24pHPtt3Fet8ZutgL155Bad93GSubM2",
                      cmds.getprivatekeys("bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af"))
     # list of addresses tests
     with self.assertRaises(Exception):
         cmds.getprivatekeys(['bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af', 'asd'])
     self.assertEqual(['p2wpkh:L15oxP24NMNAXxq5r2aom24pHPtt3Fet8ZutgL155Bad93GSubM2', 'p2wpkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN'],
                      cmds.getprivatekeys(['bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af', 'bc1q9pzjpjq4nqx5ycnywekcmycqz0wjp2nq604y2n']))
Exemplo n.º 9
0
 def test_restore_wallet_from_text_mnemonic(self):
     text = 'bitter grass shiver impose acquire brush forget axis eager alone wine silver'
     passphrase = 'mypassphrase'
     password = '******'
     encrypt_file = True
     d = restore_wallet_from_text(text,
                                  path=self.wallet_path,
                                  network=None,
                                  passphrase=passphrase,
                                  password=password,
                                  encrypt_file=encrypt_file,
                                  gap_limit=1)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(passphrase, wallet.keystore.get_passphrase(password))
     self.assertEqual(text, wallet.keystore.get_seed(password))
     self.assertEqual(encrypt_file, wallet.storage.is_encrypted())
     self.assertEqual('bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw',
                      wallet.get_receiving_addresses()[0])