Skip to content

Commit 8efc346

Browse files
committed
Merge bitcoin/bitcoin#30278: test: cover more errors for signrawtransactionwithkey RPC
e2779ce test: cover more errors for `signrawtransactionwithkey` RPC (brunoerg) Pull request description: This PR adds test coverage for the following errors for the `signrawtransactionwithkey` RPC: - Invalid private key - TX decode failed For reference: https://maflcko.github.io/b-c-cov/total.coverage/src/rpc/rawtransaction.cpp.gcov.html ACKs for top commit: maflcko: ACK e2779ce kevkevinpal: ACK [e2779ce](bitcoin/bitcoin@e2779ce) tdb3: ACK e2779ce BrandonOdiwuor: Code Review ACK e2779ce Tree-SHA512: 41c7e990684b60645cf4ccec8aad5ebbe61da221871eb3c1685b2bb1eebda58b29358502cb1525b7c7a2b612e2bebf449ed0bae14ab663b4641c528a9c013b5b
2 parents fcc3b65 + e2779ce commit 8efc346

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/functional/rpc_signrawtransactionwithkey.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,20 @@ def invalid_sighashtype_test(self):
126126
privkeys = [self.nodes[0].get_deterministic_priv_key().key]
127127
assert_raises_rpc_error(-8, "'all' is not a valid sighash parameter.", self.nodes[0].signrawtransactionwithkey, tx, privkeys, sighashtype="all")
128128

129+
def invalid_private_key_and_tx(self):
130+
self.log.info("Test signing transaction with an invalid private key")
131+
tx = self.nodes[0].createrawtransaction(INPUTS, OUTPUTS)
132+
privkeys = ["123"]
133+
assert_raises_rpc_error(-5, "Invalid private key", self.nodes[0].signrawtransactionwithkey, tx, privkeys)
134+
self.log.info("Test signing transaction with an invalid tx hex")
135+
privkeys = [self.nodes[0].get_deterministic_priv_key().key]
136+
assert_raises_rpc_error(-22, "TX decode failed. Make sure the tx has at least one input.", self.nodes[0].signrawtransactionwithkey, tx + "00", privkeys)
137+
129138
def run_test(self):
130139
self.successful_signing_test()
131140
self.witness_script_test()
132141
self.invalid_sighashtype_test()
142+
self.invalid_private_key_and_tx()
133143

134144

135145
if __name__ == '__main__':

0 commit comments

Comments
 (0)