Skip to content

Commit ea022d9

Browse files
author
MarcoFalke
committed
Merge #15378: tests: Added missing tests for RPC wallet errors
dc3b2cc tests: Added missing tests for RPC wallet errors (Ben Carman) Pull request description: Tree-SHA512: b18dcd4f7547c974c93ae67dcd92a168bdb55951b164cf174cb1e59e0daa463187068aec43108309a75d65721a5c0bcdf10a16a9869620f160121e2287559926
2 parents 7d3f255 + dc3b2cc commit ea022d9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/functional/wallet_basic.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,38 @@ def run_test(self):
327327
tx_obj = self.nodes[0].gettransaction(txid)
328328
assert_equal(tx_obj['amount'], Decimal('-0.0001'))
329329

330+
# General checks for errors from incorrect inputs
330331
# This will raise an exception because the amount type is wrong
331332
assert_raises_rpc_error(-3, "Invalid amount", self.nodes[0].sendtoaddress, self.nodes[2].getnewaddress(), "1f-4")
332333

333334
# This will raise an exception since generate does not accept a string
334335
assert_raises_rpc_error(-1, "not an integer", self.nodes[0].generate, "2")
335336

337+
# This will raise an exception for the invalid private key format
338+
assert_raises_rpc_error(-5, "Invalid private key encoding", self.nodes[0].importprivkey, "invalid")
339+
340+
# This will raise an exception for importing an address with the PS2H flag
341+
temp_address = self.nodes[1].getnewaddress()
342+
assert_raises_rpc_error(-5, "Cannot use the p2sh flag with an address - use a script instead", self.nodes[0].importaddress, temp_address, "label", False, True)
343+
344+
# This will raise an exception for attempting to dump the private key of an address you do not own
345+
assert_raises_rpc_error(-3, "Address does not refer to a key", self.nodes[0].dumpprivkey, temp_address)
346+
347+
# This will raise an exception for attempting to get the private key of an invalid Bitcoin address
348+
assert_raises_rpc_error(-5, "Invalid Bitcoin address", self.nodes[0].dumpprivkey, "invalid")
349+
350+
# This will raise an exception for attempting to set a label for an invalid Bitcoin address
351+
assert_raises_rpc_error(-5, "Invalid Bitcoin address", self.nodes[0].setlabel, "invalid address", "label")
352+
353+
# This will raise an exception for importing an invalid address
354+
assert_raises_rpc_error(-5, "Invalid Bitcoin address or script", self.nodes[0].importaddress, "invalid")
355+
356+
# This will raise an exception for attempting to import a pubkey that isn't in hex
357+
assert_raises_rpc_error(-5, "Pubkey must be a hex string", self.nodes[0].importpubkey, "not hex")
358+
359+
# This will raise an exception for importing an invalid pubkey
360+
assert_raises_rpc_error(-5, "Pubkey is not a valid public key", self.nodes[0].importpubkey, "5361746f736869204e616b616d6f746f")
361+
336362
# Import address and private key to check correct behavior of spendable unspents
337363
# 1. Send some coins to generate new UTXO
338364
address_to_import = self.nodes[2].getnewaddress()

0 commit comments

Comments
 (0)