Example #1
0
 def test_export_private_key_imported(self, mock_write):
     wallet = restore_wallet_from_text(
         'p2pkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN p2pkh: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(
             "15fvqmvaHt8bMeokezknBSCwdvaex5cj3p")  # not in wallet
     self.assertEqual(
         "p2pkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN",
         cmds.getprivatekeys("14fvqmvaHt8bMeokezknBSCwdvaex5cj3p"))
     # list of addresses tests
     with self.assertRaises(Exception):
         cmds.getprivatekeys(['19rit2FRjckycUM6Xeu7K3ib1VUnWaKGHE', 'asd'])
     self.assertEqual([
         'p2pkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL',
         'p2pkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN'
     ],
                      cmds.getprivatekeys([
                          '18rit2FRjckycUM6Xeu7K3ib1VUnWaKGHE',
                          '14fvqmvaHt8bMeokezknBSCwdvaex5cj3p'
                      ]))
Example #2
0
 def test_export_private_key_deterministic(self, mock_write):
     wallet = restore_wallet_from_text(
         'hint shock chair puzzle shock traffic drastic note dinosaur mention suggest sweet',
         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(
             "1M5TAikkAhJ1myQY5ihAXqHWrFE5iVkh7d")  # not in wallet
     self.assertEqual(
         "p2pkh:Kz1ZnW7x6jgdJnk2KuwDpccQu1yNsi5LGcyySMS1vpgCu2b75HBn",
         cmds.getprivatekeys("1M5TAikkAhJ1myQY5ihAXqHWrFE5iVkh7c"))
     # list of addresses tests
     with self.assertRaises(Exception):
         cmds.getprivatekeys(['1M5TBikkAhJ1myQY5ihAXqHWrFE5iVkh7c', 'asd'])
     self.assertEqual([
         'p2pkh:L2pttW6uTtoLcbRYbJr5wR36Up3EGLeEJBLUnggs5HXDUQ5ti2kF',
         'p2pkh:L2byajxJ6neJDs4PNYULGpuW8G72wzU7XPSPSDqUK6EAZDZ6jQ3i'
     ],
                      cmds.getprivatekeys([
                          '1DYdV8jpRXF5W4qUwXTaCkadBWyANc1sQ1',
                          '1DRbTcu9dNE7WiAYMejjCZGYgo9n2qqz6o'
                      ]))
Example #3
0
 def test_restore_wallet_from_text_addresses(self):
     text = '17azqT8T16coRmWKYFj3UjzJuxiYrYFRBR 1GXgZ5Qi6gmXTHVSpUPZLy4Ci2nbfb3ZNb'
     d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
     wallet = d['wallet']  # type: Imported_Wallet
     self.assertEqual('17azqT8T16coRmWKYFj3UjzJuxiYrYFRBR', wallet.get_receiving_addresses()[0])
     self.assertEqual(2, len(wallet.get_receiving_addresses()))
     # also test addr deletion
     wallet.delete_address('1GXgZ5Qi6gmXTHVSpUPZLy4Ci2nbfb3ZNb')
     self.assertEqual(1, len(wallet.get_receiving_addresses()))
Example #4
0
 def test_encrypt_decrypt(self, mock_write):
     wallet = restore_wallet_from_text(
         'p2pkh: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))
 def test_restoring_wallet_without_manual_delete(self, mock_write):
     w = restore_wallet_from_text("hint shock chair puzzle shock traffic drastic note dinosaur mention suggest sweet",
                                  path='if_this_exists_mocking_failed_648151893',
                                  gap_limit=5)['wallet']
     for txid in self.transactions:
         tx = Transaction(self.transactions[txid])
         w.add_transaction(tx.txid(), tx)
     # txn A is an external incoming txn funding the wallet
     # txn B is an outgoing payment to an external address
     # txn C is double-spending txn B, to a wallet address
     self.assertEqual(83500163, sum(w.get_balance()))
Example #6
0
 def test_restore_wallet_from_text_privkeys(self):
     text = 'p2pkh:KzMFjMC2MPadjvX5Cd7b8AKKjjpBSoRKUTpoAtN6B3J9ezWYyXS6 p2pkh:Kzj8VjwpZ99bQqVeUiRXrKuX9mLr1o6sWxFMCBJn1umC38BMiQTD'
     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('17azqT8T16coRmWKYFj3UjzJuxiYrYFRBR', addr0)
     self.assertEqual('p2pkh:KzMFjMC2MPadjvX5Cd7b8AKKjjpBSoRKUTpoAtN6B3J9ezWYyXS6',
                      wallet.export_private_key(addr0, password=None)[0])
     self.assertEqual(2, len(wallet.get_receiving_addresses()))
     # also test addr deletion
     wallet.delete_address('1GXgZ5Qi6gmXTHVSpUPZLy4Ci2nbfb3ZNb')
     self.assertEqual(1, len(wallet.get_receiving_addresses()))
Example #7
0
 def test_restore_wallet_from_text_mnemonic(self):
     text = 'hint shock chair puzzle shock traffic drastic note dinosaur mention suggest sweet'
     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('13XTAFSgVwgpiuynfkveYSPtLaS6XShvMW', wallet.get_receiving_addresses()[0])
 def test_restoring_wallet_with_manual_delete(self, mock_write):
     w = restore_wallet_from_text("hint shock chair puzzle shock traffic drastic note dinosaur mention suggest sweet",
                                  path='if_this_exists_mocking_failed_648151893',
                                  gap_limit=5)['wallet']
     # txn A is an external incoming txn funding the wallet
     txA = Transaction(self.transactions["0cce62d61ec87ad3e391e8cd752df62e0c952ce45f52885d6d10988e02794060"])
     w.add_transaction(txA.txid(), txA)
     # txn B is an outgoing payment to an external address
     txB = Transaction(self.transactions["e7f4e47f41421e37a8600b6350befd586f30db60a88d0992d54df280498f0968"])
     w.add_transaction(txB.txid(), txB)
     # now the user manually deletes txn B to attempt the double spend
     # txn C is double-spending txn B, to a wallet address
     # rationale1: user might do this with opt-in RBF transactions
     # rationale2: this might be a local transaction, in which case the GUI even allows it
     w.remove_transaction(txB)
     txC = Transaction(self.transactions["a04328fbc9f28268378a8b9cf103db21ca7d673bf1cc7fa4d61b6a7265f07a6b"])
     w.add_transaction(txC.txid(), txC)
     self.assertEqual(83500163, sum(w.get_balance()))
Example #9
0
 def test_restore_wallet_from_text_xprv(self):
     text = 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
     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('1BiCdXSDHyeXSzmx2paVPFVTrmyx7BeCGD', wallet.get_receiving_addresses()[0])
Example #10
0
 def test_restore_wallet_from_text_xpub(self):
     text = 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
     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('1BiCdXSDHyeXSzmx2paVPFVTrmyx7BeCGD', wallet.get_receiving_addresses()[0])