MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_sign_and_send_psbt

Function test_sign_and_send_psbt

tests/test_wallet.py:1044–1249  ·  view source on GitHub ↗

Tests for the sign + send psbt RPCs

(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

1042
1043@unittest.skipIf(TEST_NETWORK == 'liquid-regtest', 'Core/Elements need joinpsbt support for v2')
1044def test_sign_and_send_psbt(node_factory, bitcoind, chainparams):
1045 """
1046 Tests for the sign + send psbt RPCs
1047 """
1048 # CLN returns PSBTv0 and PSETv2, for now
1049 is_psbt_v2 = chainparams['elements']
1050
1051 # Once support for v2 joinpsbt is added, below test should work verbatim
1052 assert not is_psbt_v2
1053
1054 amount = 1000000
1055 total_outs = 12
1056 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1057 l1 = node_factory.get_node(options={'plugin': coin_mvt_plugin},
1058 feerates=(7500, 7500, 7500, 7500))
1059 l2 = node_factory.get_node()
1060 addr = chainparams['example_addr']
1061 out_total = Millisatoshi(amount * 3 * 1000)
1062
1063 # Add a medley of funds to withdraw later
1064 for i in range(total_outs):
1065 bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('bech32')['bech32'],
1066 amount / 10**8)
1067 bitcoind.generate_block(1)
1068 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == total_outs)
1069
1070 # Make a PSBT out of our inputs
1071 funding = l1.rpc.fundpsbt(satoshi=out_total,
1072 feerate=7500,
1073 startweight=42)
1074 assert len([x for x in l1.rpc.listfunds()['outputs'] if x['reserved']]) == 4
1075 psbt = bitcoind.rpc.decodepsbt(funding['psbt'])
1076 if is_psbt_v2:
1077 saved_input = psbt['inputs'][0]
1078 else:
1079 saved_input = psbt['tx']['vin'][0]
1080
1081 # Go ahead and unreserve the UTXOs, we'll use a smaller
1082 # set of them to create a second PSBT that we'll attempt to sign
1083 # and broadcast (to disastrous results)
1084 l1.rpc.unreserveinputs(funding['psbt'])
1085
1086 # Re-reserve one of the utxos we just unreserved
1087 if is_psbt_v2:
1088 psbt = bitcoind.rpc.createpsbt([{'txid': saved_input['previous_txid'],
1089 'vout': saved_input['previous_vout']}], [])
1090 else:
1091 psbt = bitcoind.rpc.createpsbt([{'txid': saved_input['txid'],
1092 'vout': saved_input['vout']}], [])
1093
1094 l1.rpc.reserveinputs(psbt)
1095
1096 # We require the utxos be reserved before signing them
1097 with pytest.raises(RpcError, match=r"Aborting PSBT signing. UTXO .* is not reserved"):
1098 l1.rpc.signpsbt(funding['psbt'])['signed_psbt']
1099
1100 # Now we unreserve the singleton, so we can reserve it again
1101 l1.rpc.unreserveinputs(psbt)

Callers

nothing calls this directly

Calls 15

to_btcMethod · 0.95
MillisatoshiClass · 0.90
wait_forFunction · 0.90
sync_blockheightFunction · 0.90
check_coin_movesFunction · 0.90
joinMethod · 0.80
generate_blockMethod · 0.80
fundpsbtMethod · 0.80
unreserveinputsMethod · 0.80
reserveinputsMethod · 0.80
signpsbtMethod · 0.80
sendpsbtMethod · 0.80

Tested by

no test coverage detected