Skip to content

Commit

Permalink
Merge bitcoin#30278: test: cover more errors for `signrawtransactionw…
Browse files Browse the repository at this point in the history
…ithkey` 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@e2779ce)
  tdb3:
    ACK e2779ce
  BrandonOdiwuor:
    Code Review ACK e2779ce

Tree-SHA512: 41c7e990684b60645cf4ccec8aad5ebbe61da221871eb3c1685b2bb1eebda58b29358502cb1525b7c7a2b612e2bebf449ed0bae14ab663b4641c528a9c013b5b
  • Loading branch information
fanquake committed Jun 14, 2024
2 parents fcc3b65 + e2779ce commit 8efc346
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/functional/rpc_signrawtransactionwithkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,20 @@ def invalid_sighashtype_test(self):
privkeys = [self.nodes[0].get_deterministic_priv_key().key]
assert_raises_rpc_error(-8, "'all' is not a valid sighash parameter.", self.nodes[0].signrawtransactionwithkey, tx, privkeys, sighashtype="all")

def invalid_private_key_and_tx(self):
self.log.info("Test signing transaction with an invalid private key")
tx = self.nodes[0].createrawtransaction(INPUTS, OUTPUTS)
privkeys = ["123"]
assert_raises_rpc_error(-5, "Invalid private key", self.nodes[0].signrawtransactionwithkey, tx, privkeys)
self.log.info("Test signing transaction with an invalid tx hex")
privkeys = [self.nodes[0].get_deterministic_priv_key().key]
assert_raises_rpc_error(-22, "TX decode failed. Make sure the tx has at least one input.", self.nodes[0].signrawtransactionwithkey, tx + "00", privkeys)

def run_test(self):
self.successful_signing_test()
self.witness_script_test()
self.invalid_sighashtype_test()
self.invalid_private_key_and_tx()


if __name__ == '__main__':
Expand Down

0 comments on commit 8efc346

Please sign in to comment.