Ejemplo n.º 1
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()))
Ejemplo n.º 2
0
 def test_restore_wallet_from_text_xpub(self):
     text = 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
     d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(text, wallet.keystore.get_master_public_key())
     self.assertEqual('PKJNnVq4Lu8iRqSiNtu249TjUX9qELpRmH',
                      wallet.get_receiving_addresses()[0])
Ejemplo n.º 3
0
 def test_export_private_key_imported(self, mock_write):
     wallet = restore_wallet_from_text(
         'p2pkh:XGx8LpkmLRv9RiMvpYx965BCaQKQbeMVVqgAh7B5SQVdosQiKJ4i p2pkh:XEn9o6oayjsRmoEQwDbvkrWVvjRNqPj3xNskJJPAKraJTrWuutwd',
         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(
             "XdDHzW6aTeuQsraNXeEsPy5gAv1nUz7Y7Q")  # not in wallet
     self.assertEqual(
         "p2pkh:XEn9o6oayjsRmoEQwDbvkrWVvjRNqPj3xNskJJPAKraJTrWuutwd",
         cmds.getprivatekeys("PAcQeW6SqW8S1JpL6f53m9GnT6AeRFndWo"))
     # list of addresses tests
     with self.assertRaises(Exception):
         cmds.getprivatekeys(['PKJNnVq4Lu8iRqSiNtu249TjUX9qELpRmH', 'asd'])
     self.assertEqual([
         'p2pkh:XGx8LpkmLRv9RiMvpYx965BCaQKQbeMVVqgAh7B5SQVdosQiKJ4i',
         'p2pkh:XEn9o6oayjsRmoEQwDbvkrWVvjRNqPj3xNskJJPAKraJTrWuutwd'
     ],
                      cmds.getprivatekeys([
                          'PKJNnVq4Lu8iRqSiNtu249TjUX9qELpRmH',
                          'PAcQeW6SqW8S1JpL6f53m9GnT6AeRFndWo'
                      ]))
Ejemplo n.º 4
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(
             "XdDHzW6aTeuQsraNXeEsPy5gAv1nUz7Y7Q")  # not in wallet
     self.assertEqual(
         "p2pkh:XE5VEmWKQRK5N7kQMfw6KqoRp3ExKWgaeCKsxsmDFBxJJBgdQdTH",
         cmds.getprivatekeys("PUfdKh9bDcnCkp5JRo1hCjFnTzPxq77fVk"))
     # list of addresses tests
     with self.assertRaises(Exception):
         cmds.getprivatekeys(['PUfdKh9bDcnCkp5JRo1hCjFnTzPxq77fVk', 'asd'])
     self.assertEqual([
         'p2pkh:XE5VEmWKQRK5N7kQMfw6KqoRp3ExKWgaeCKsxsmDFBxJJBgdQdTH',
         'p2pkh:XGtpLmVGmaRnfvRvd4qxSeE7PqJoi9FUfkgPKD24PeoJsZCh1EXg'
     ],
                      cmds.getprivatekeys([
                          'PUfdKh9bDcnCkp5JRo1hCjFnTzPxq77fVk',
                          'PM8oe78fUSjGUuWFHbn6seYtoG93SynJy1'
                      ]))
Ejemplo n.º 5
0
 def test_restore_wallet_from_text_xprv(self):
     text = 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
     d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(text,
                      wallet.keystore.get_master_private_key(password=None))
     self.assertEqual('PKJNnVq4Lu8iRqSiNtu249TjUX9qELpRmH',
                      wallet.get_receiving_addresses()[0])
Ejemplo n.º 6
0
 def test_encrypt_decrypt(self, mock_write):
     wallet = restore_wallet_from_text(
         'p2pkh:XJvTzLoBy3jPMZFSTzK6KqTiNR3n5xbreSScEy7u9C8fEf1GZG3X',
         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))
Ejemplo n.º 7
0
 def test_restore_wallet_from_text_addresses(self):
     text = 'PJxmSv9QS2JwQhRSFMqiH37Nc6HUhgM99a PS9UztHduw2QjTZcAhn7JpHR1zLcHGqTQb'
     d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
     wallet = d['wallet']  # type: Imported_Wallet
     self.assertEqual('PJxmSv9QS2JwQhRSFMqiH37Nc6HUhgM99a', wallet.get_receiving_addresses()[0])
     self.assertEqual(2, len(wallet.get_receiving_addresses()))
     # also test addr deletion
     wallet.delete_address('PS9UztHduw2QjTZcAhn7JpHR1zLcHGqTQb')
     self.assertEqual(1, len(wallet.get_receiving_addresses()))
Ejemplo n.º 8
0
 def test_restore_wallet_from_text_privkeys(self):
     text = 'p2pkh:XGx8LpkmLRv9RiMvpYx965BCaQKQbeMVVqgAh7B5SQVdosQiKJ4i p2pkh:XEn9o6oayjsRmoEQwDbvkrWVvjRNqPj3xNskJJPAKraJTrWuutwd'
     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('PAcQeW6SqW8S1JpL6f53m9GnT6AeRFndWo', addr0)
     self.assertEqual('p2pkh:XEn9o6oayjsRmoEQwDbvkrWVvjRNqPj3xNskJJPAKraJTrWuutwd',
                      wallet.export_private_key(addr0, password=None)[0])
     self.assertEqual(2, len(wallet.get_receiving_addresses()))
     # also test addr deletion
     wallet.delete_address('PAcQeW6SqW8S1JpL6f53m9GnT6AeRFndWo')
     self.assertEqual(1, len(wallet.get_receiving_addresses()))
Ejemplo n.º 9
0
 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()))
Ejemplo n.º 10
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)
     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('PB7dKDqXYsB1hkeZ1qFBDLN9xKbyXupWQX',
                      wallet.get_receiving_addresses()[0])