@@ -75,6 +75,43 @@ class TestCommands(unittest.TestCase):
|
||||
ciphertext = cmds.encrypt(pubkey, cleartext)
|
||||
self.assertEqual(cleartext, cmds.decrypt(pubkey, ciphertext))
|
||||
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
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']))
|
||||
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
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']))
|
||||
|
||||
|
||||
class TestCommandsTestnet(TestCaseForTestnet):
|
||||
|
||||
|
||||
@@ -156,7 +156,8 @@ class TestCreateRestoreWallet(WalletTestCase):
|
||||
passphrase=passphrase,
|
||||
password=password,
|
||||
encrypt_file=encrypt_file,
|
||||
segwit=True)
|
||||
segwit=True,
|
||||
gap_limit=1)
|
||||
wallet = d['wallet'] # type: Standard_Wallet
|
||||
wallet.check_password(password)
|
||||
self.assertEqual(passphrase, wallet.keystore.get_passphrase(password))
|
||||
@@ -173,7 +174,8 @@ class TestCreateRestoreWallet(WalletTestCase):
|
||||
network=None,
|
||||
passphrase=passphrase,
|
||||
password=password,
|
||||
encrypt_file=encrypt_file)
|
||||
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))
|
||||
@@ -182,14 +184,14 @@ class TestCreateRestoreWallet(WalletTestCase):
|
||||
|
||||
def test_restore_wallet_from_text_xpub(self):
|
||||
text = 'zpub6nydoME6CFdJtMpzHW5BNoPz6i6XbeT9qfz72wsRqGdgGEYeivso6xjfw8cGcCyHwF7BNW4LDuHF35XrZsovBLWMF4qXSjmhTXYiHbWqGLt'
|
||||
d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
|
||||
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])
|
||||
|
||||
def test_restore_wallet_from_text_xprv(self):
|
||||
text = 'zprvAZzHPqhCMt51fskXBUYB1fTFYgG3CBjJUT4WEZTpGw6hPSDWBPZYZARC5sE9xAcX8NeWvvucFws8vZxEa65RosKAhy7r5MsmKTxr3hmNmea'
|
||||
d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
|
||||
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])
|
||||
|
||||
Reference in New Issue
Block a user