Browse Source

commands: try to fix tests

master
SomberNight 6 years ago
parent
commit
712c3f1248
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/commands.py
  2. 22
      electrum/tests/test_commands.py

4
electrum/commands.py

@ -662,7 +662,7 @@ class Commands:
return out return out
@command('n') @command('n')
async def gettransaction(self, txid): async def gettransaction(self, txid, wallet=None):
"""Retrieve a transaction. """ """Retrieve a transaction. """
tx = None tx = None
if wallet: if wallet:
@ -689,7 +689,7 @@ class Commands:
return encrypted.decode('utf-8') return encrypted.decode('utf-8')
@command('wp') @command('wp')
async def decrypt(self, pubkey, encrypted, password=None) -> str: async def decrypt(self, pubkey, encrypted, password=None, wallet=None) -> str:
"""Decrypt a message encrypted with a public key.""" """Decrypt a message encrypted with a public key."""
if not is_hex_str(pubkey): if not is_hex_str(pubkey):
raise Exception(f"pubkey must be a hex string instead of {repr(pubkey)}") raise Exception(f"pubkey must be a hex string instead of {repr(pubkey)}")

22
electrum/tests/test_commands.py

@ -83,7 +83,7 @@ class TestCommands(unittest.TestCase):
cleartext = "asdasd this is the message" cleartext = "asdasd this is the message"
pubkey = "021f110909ded653828a254515b58498a6bafc96799fb0851554463ed44ca7d9da" pubkey = "021f110909ded653828a254515b58498a6bafc96799fb0851554463ed44ca7d9da"
ciphertext = cmds._run('encrypt', (pubkey, cleartext)) ciphertext = cmds._run('encrypt', (pubkey, cleartext))
self.assertEqual(cleartext, cmds._run('decrypt', (pubkey, ciphertext))) self.assertEqual(cleartext, cmds._run('decrypt', (pubkey, ciphertext), wallet=wallet))
@mock.patch.object(storage.WalletStorage, '_write') @mock.patch.object(storage.WalletStorage, '_write')
def test_export_private_key_imported(self, mock_write): def test_export_private_key_imported(self, mock_write):
@ -92,16 +92,16 @@ class TestCommands(unittest.TestCase):
cmds = Commands(config=None) cmds = Commands(config=None)
# single address tests # single address tests
with self.assertRaises(Exception): with self.assertRaises(Exception):
cmds._run('getprivatekeys', ("asdasd",)) # invalid addr, though might raise "not in wallet" cmds._run('getprivatekeys', ("asdasd",), wallet=wallet) # invalid addr, though might raise "not in wallet"
with self.assertRaises(Exception): with self.assertRaises(Exception):
cmds._run('getprivatekeys', ("bc1qgfam82qk7uwh5j2xxmcd8cmklpe0zackyj6r23",)) # not in wallet cmds._run('getprivatekeys', ("bc1qgfam82qk7uwh5j2xxmcd8cmklpe0zackyj6r23",), wallet=wallet) # not in wallet
self.assertEqual("p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL", self.assertEqual("p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL",
cmds._run('getprivatekeys', ("bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw",))) cmds._run('getprivatekeys', ("bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw",), wallet=wallet))
# list of addresses tests # list of addresses tests
with self.assertRaises(Exception): with self.assertRaises(Exception):
cmds._run('getprivatekeys', (['bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', 'asd'], )) cmds._run('getprivatekeys', (['bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', 'asd'], ), wallet=wallet)
self.assertEqual(['p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL', 'p2wpkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN'], self.assertEqual(['p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL', 'p2wpkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN'],
cmds._run('getprivatekeys', (['bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', 'bc1q9pzjpjq4nqx5ycnywekcmycqz0wjp2nq604y2n'], ))) cmds._run('getprivatekeys', (['bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', 'bc1q9pzjpjq4nqx5ycnywekcmycqz0wjp2nq604y2n'], ), wallet=wallet))
@mock.patch.object(storage.WalletStorage, '_write') @mock.patch.object(storage.WalletStorage, '_write')
def test_export_private_key_deterministic(self, mock_write): def test_export_private_key_deterministic(self, mock_write):
@ -111,16 +111,16 @@ class TestCommands(unittest.TestCase):
cmds = Commands(config=None) cmds = Commands(config=None)
# single address tests # single address tests
with self.assertRaises(Exception): with self.assertRaises(Exception):
cmds._run('getprivatekeys', ("asdasd",)) # invalid addr, though might raise "not in wallet" cmds._run('getprivatekeys', ("asdasd",), wallet=wallet) # invalid addr, though might raise "not in wallet"
with self.assertRaises(Exception): with self.assertRaises(Exception):
cmds._run('getprivatekeys', ("bc1qgfam82qk7uwh5j2xxmcd8cmklpe0zackyj6r23",)) # not in wallet cmds._run('getprivatekeys', ("bc1qgfam82qk7uwh5j2xxmcd8cmklpe0zackyj6r23",), wallet=wallet) # not in wallet
self.assertEqual("p2wpkh:L15oxP24NMNAXxq5r2aom24pHPtt3Fet8ZutgL155Bad93GSubM2", self.assertEqual("p2wpkh:L15oxP24NMNAXxq5r2aom24pHPtt3Fet8ZutgL155Bad93GSubM2",
cmds._run('getprivatekeys', ("bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af",))) cmds._run('getprivatekeys', ("bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af",), wallet=wallet))
# list of addresses tests # list of addresses tests
with self.assertRaises(Exception): with self.assertRaises(Exception):
cmds._run('getprivatekeys', (['bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af', 'asd'],)) cmds._run('getprivatekeys', (['bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af', 'asd'],), wallet=wallet)
self.assertEqual(['p2wpkh:L15oxP24NMNAXxq5r2aom24pHPtt3Fet8ZutgL155Bad93GSubM2', 'p2wpkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN'], self.assertEqual(['p2wpkh:L15oxP24NMNAXxq5r2aom24pHPtt3Fet8ZutgL155Bad93GSubM2', 'p2wpkh:L4rYY5QpfN6wJEF4SEKDpcGhTPnCe9zcGs6hiSnhpprZqVywFifN'],
cmds._run('getprivatekeys', (['bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af', 'bc1q9pzjpjq4nqx5ycnywekcmycqz0wjp2nq604y2n'], ))) cmds._run('getprivatekeys', (['bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af', 'bc1q9pzjpjq4nqx5ycnywekcmycqz0wjp2nq604y2n'], ), wallet=wallet))
class TestCommandsTestnet(TestCaseForTestnet): class TestCommandsTestnet(TestCaseForTestnet):

Loading…
Cancel
Save