diff --git a/tests/test_framework/utils.py b/tests/test_framework/utils.py index c0b959c7..e506e676 100644 --- a/tests/test_framework/utils.py +++ b/tests/test_framework/utils.py @@ -75,6 +75,14 @@ def spend_coins(lianad, bitcoind, coins): return tx +def sign_and_broadcast(lianad, bitcoind, psbt, recovery=False): + """Sign a PSBT, finalize it, extract the transaction and broadcast it.""" + signed_psbt = lianad.sign_psbt(psbt, recovery) + finalized_psbt = lianad.finalize_psbt(signed_psbt) + tx = finalized_psbt.tx.serialize_with_witness().hex() + return bitcoind.rpc.sendrawtransaction(tx) + + class RpcError(ValueError): def __init__(self, method: str, params: dict, error: str): super(ValueError, self).__init__( diff --git a/tests/test_rpc.py b/tests/test_rpc.py index 3ba4e6f5..fb16defe 100644 --- a/tests/test_rpc.py +++ b/tests/test_rpc.py @@ -8,7 +8,14 @@ from test_framework.serializations import ( PSBT_IN_PARTIAL_SIG, PSBT_IN_NON_WITNESS_UTXO, ) -from test_framework.utils import wait_for, COIN, RpcError, get_txid, spend_coins +from test_framework.utils import ( + wait_for, + COIN, + RpcError, + get_txid, + spend_coins, + sign_and_broadcast, +) def test_getinfo(lianad): @@ -123,10 +130,7 @@ def test_create_spend(lianad, bitcoind): ) # We can sign it and broadcast it. - signed_psbt = lianad.sign_psbt(PSBT.from_base64(res["psbt"])) - finalized_psbt = lianad.finalize_psbt(signed_psbt) - tx = finalized_psbt.tx.serialize_with_witness().hex() - bitcoind.rpc.sendrawtransaction(tx) + sign_and_broadcast(PSBT.from_base64(res["psbt"])) def test_list_spend(lianad, bitcoind):