示例#1
0
 def test_encrypt_decrypt(self, mock_save_db):
     wallet = restore_wallet_from_text('p2wpkh:TAgoypi14k5Y54svysG62xp5QFRWiF1W64zxaFRFPo2jMPSMoa5D',
                                       path='if_this_exists_mocking_failed_648151893',
                                       config=self.config)['wallet']
     cmds = Commands(config=self.config)
     cleartext = "asdasd this is the message"
     pubkey = "021f110909ded653828a254515b58498a6bafc96799fb0851554463ed44ca7d9da"
     ciphertext = cmds._run('encrypt', (pubkey, cleartext))
     self.assertEqual(cleartext, cmds._run('decrypt', (pubkey, ciphertext), wallet=wallet))
示例#2
0
 def test_restore_wallet_from_text_xpub(self):
     text = 'zpub6nydoME6CFdJtMpzHW5BNoPz6i6XbeT9qfz72wsRqGdgGEYeivso6xjfw8cGcCyHwF7BNW4LDuHF35XrZsovBLWMF4qXSjmhTXYiHbWqGLt'
     d = restore_wallet_from_text(text,
                                  path=self.wallet_path,
                                  gap_limit=1,
                                  config=self.config)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(text, wallet.keystore.get_master_public_key())
     self.assertEqual('ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7',
                      wallet.get_receiving_addresses()[0])
示例#3
0
 def test_restore_wallet_from_text_xprv(self):
     text = 'zprvAZzHPqhCMt51fskXBUYB1fTFYgG3CBjJUT4WEZTpGw6hPSDWBPZYZARC5sE9xAcX8NeWvvucFws8vZxEa65RosKAhy7r5MsmKTxr3hmNmea'
     d = restore_wallet_from_text(text,
                                  path=self.wallet_path,
                                  gap_limit=1,
                                  config=self.config)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(text,
                      wallet.keystore.get_master_private_key(password=None))
     self.assertEqual('ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7',
                      wallet.get_receiving_addresses()[0])
示例#4
0
 def test_restore_wallet_from_text_addresses(self):
     text = 'ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7 ltc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu7xl7hg'
     d = restore_wallet_from_text(text,
                                  path=self.wallet_path,
                                  config=self.config)
     wallet = d['wallet']  # type: Imported_Wallet
     self.assertEqual('ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7',
                      wallet.get_receiving_addresses()[0])
     self.assertEqual(2, len(wallet.get_receiving_addresses()))
     # also test addr deletion
     wallet.delete_address('ltc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu7xl7hg')
     self.assertEqual(1, len(wallet.get_receiving_addresses()))
示例#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,
                                  gap_limit=1,
                                  config=self.config)
     wallet = d['wallet']  # type: Standard_Wallet
     self.assertEqual(text,
                      wallet.keystore.get_master_private_key(password=None))
     self.assertEqual('MVnD1Yo1HNNGNY4ZvaXv4kdxzKtzPzA8FT',
                      wallet.get_receiving_addresses()[0])
示例#6
0
 def test_getprivatekeyforpath(self, mock_save_db):
     wallet = restore_wallet_from_text('north rent dawn bunker hamster invest wagon market romance pig either squeeze',
                                       gap_limit=2,
                                       path='if_this_exists_mocking_failed_648151893',
                                       config=self.config)['wallet']
     cmds = Commands(config=self.config)
     self.assertEqual("p2wpkh:cUzm7zPpWgLYeURgff4EsoMjhskCpsviBH4Y3aZcrBX8UJSRPjC2",
                      cmds._run('getprivatekeyforpath', ([0, 10000],), wallet=wallet))
     self.assertEqual("p2wpkh:cUzm7zPpWgLYeURgff4EsoMjhskCpsviBH4Y3aZcrBX8UJSRPjC2",
                      cmds._run('getprivatekeyforpath', ("m/0/10000",), wallet=wallet))
     self.assertEqual("p2wpkh:cQAj4WGf1socCPCJNMjXYCJ8Bs5JUAk5pbDr4ris44QdgAXcV24S",
                      cmds._run('getprivatekeyforpath', ("m/5h/100000/88h/7",), wallet=wallet))
示例#7
0
 def test_restore_wallet_from_text_privkeys(self):
     text = 'p2wpkh:TAa25Tq4PdzhDKBoVaFaCdV3yxvLrRikQviNkuFQLeYopsVvNTV3 p2wpkh:T7tYQXfHmkSmS3A2eLCrPNHG21JrEFj9NZWbS6f71Z7SLEgRqD97'
     d = restore_wallet_from_text(text,
                                  path=self.wallet_path,
                                  config=self.config)
     wallet = d['wallet']  # type: Imported_Wallet
     addr0 = wallet.get_receiving_addresses()[0]
     self.assertEqual('ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7', addr0)
     self.assertEqual(
         'p2wpkh:TAa25Tq4PdzhDKBoVaFaCdV3yxvLrRikQviNkuFQLeYopsVvNTV3',
         wallet.export_private_key(addr0, password=None))
     self.assertEqual(2, len(wallet.get_receiving_addresses()))
     # also test addr deletion
     wallet.delete_address('ltc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu7xl7hg')
     self.assertEqual(1, len(wallet.get_receiving_addresses()))
示例#8
0
 def test_export_private_key_imported(self, mock_save_db):
     wallet = restore_wallet_from_text('p2wpkh:TAgoypi14k5Y54svysG62xp5QFRWiF1W64zxaFRFPo2jMPSMoa5D p2wpkh:TAa25Tq4PdzhDKBoVaFaCdV3yxvLrRikQviNkuFQLeYopsVvNTV3',
                                       path='if_this_exists_mocking_failed_648151893',
                                       config=self.config)['wallet']
     cmds = Commands(config=self.config)
     # single address tests
     with self.assertRaises(Exception):
         cmds._run('getprivatekeys', ("asdasd",), wallet=wallet)  # invalid addr, though might raise "not in wallet"
     with self.assertRaises(Exception):
         cmds._run('getprivatekeys', ("ltc1qgfam82qk7uwh5j2xxmcd8cmklpe0zackqwq8jp",), wallet=wallet)  # not in wallet
     self.assertEqual("p2wpkh:TAa25Tq4PdzhDKBoVaFaCdV3yxvLrRikQviNkuFQLeYopsVvNTV3",
                      cmds._run('getprivatekeys', ("ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7",), wallet=wallet))
     # list of addresses tests
     with self.assertRaises(Exception):
         cmds._run('getprivatekeys', (['ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7', 'asd'], ), wallet=wallet)
     self.assertEqual(['p2wpkh:TAa25Tq4PdzhDKBoVaFaCdV3yxvLrRikQviNkuFQLeYopsVvNTV3', 'p2wpkh:TAgoypi14k5Y54svysG62xp5QFRWiF1W64zxaFRFPo2jMPSMoa5D'],
                      cmds._run('getprivatekeys', (['ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7', 'ltc1q9pzjpjq4nqx5ycnywekcmycqz0wjp2nq7n0qjr'], ), wallet=wallet))
示例#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,
                                  passphrase=passphrase,
                                  password=password,
                                  encrypt_file=encrypt_file,
                                  gap_limit=1,
                                  config=self.config)
     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('ltc1q2ccr34wzep58d4239tl3x3734ttle92arvely7',
                      wallet.get_receiving_addresses()[0])
示例#10
0
 def test_export_private_key_deterministic(self, mock_save_db):
     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',
                                       config=self.config)['wallet']
     cmds = Commands(config=self.config)
     # single address tests
     with self.assertRaises(Exception):
         cmds._run('getprivatekeys', ("asdasd",), wallet=wallet)  # invalid addr, though might raise "not in wallet"
     with self.assertRaises(Exception):
         cmds._run('getprivatekeys', ("ltc1qgfam82qk7uwh5j2xxmcd8cmklpe0zackqwq8jp",), wallet=wallet)  # not in wallet
     self.assertEqual("p2wpkh:T6v5Q8KEmjLmJoTxPfXfyNcCEFYC7Lfmwmp9Y8dce9knevo9ZkPk",
                      cmds._run('getprivatekeys', ("ltc1q3g5tmkmlvxryhh843v4dz026avatc0zz8xd49e",), wallet=wallet))
     # list of addresses tests
     with self.assertRaises(Exception):
         cmds._run('getprivatekeys', (['ltc1q3g5tmkmlvxryhh843v4dz026avatc0zz8xd49e', 'asd'],), wallet=wallet)
     self.assertEqual(['p2wpkh:T6v5Q8KEmjLmJoTxPfXfyNcCEFYC7Lfmwmp9Y8dce9knevo9ZkPk', 'p2wpkh:TAgoypi14k5Y54svysG62xp5QFRWiF1W64zxaFRFPo2jMPSMoa5D'],
                      cmds._run('getprivatekeys', (['ltc1q3g5tmkmlvxryhh843v4dz026avatc0zz8xd49e', 'ltc1q9pzjpjq4nqx5ycnywekcmycqz0wjp2nq7n0qjr'], ), wallet=wallet))