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

Function test_utxopsbt

tests/test_wallet.py:814–948  ·  view source on GitHub ↗
(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

812
813
814def test_utxopsbt(node_factory, bitcoind, chainparams):
815 amount = 1000000
816 l1 = node_factory.get_node()
817
818 # CLN returns PSBTv0 and PSETv2, for now
819 is_psbt_v2 = chainparams['elements']
820
821 outputs = []
822 # Add a funds to withdraw later
823 for _ in range(2):
824 txid = bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('bech32')['bech32'],
825 amount / 10**8)
826 outputs.append((txid, bitcoind.rpc.gettransaction(txid)['details'][0]['vout']))
827
828 bitcoind.generate_block(1)
829 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == len(outputs))
830
831 fee_val = 7500
832 feerate = '{}perkw'.format(fee_val)
833
834 # Explicitly spend the first output above.
835 funding = l1.rpc.utxopsbt(amount // 2, feerate, 0,
836 ['{}:{}'.format(outputs[0][0], outputs[0][1])],
837 reserve=0)
838 psbt = bitcoind.rpc.decodepsbt(funding['psbt'])
839 # We can fuzz this up to 99 blocks back.
840 assert funding['excess_msat'] > Millisatoshi(0)
841 assert funding['excess_msat'] < Millisatoshi(amount // 2 * 1000)
842 assert funding['feerate_per_kw'] == 7500
843 assert 'estimated_final_weight' in funding
844 assert 'reservations' not in funding
845
846 if is_psbt_v2:
847 assert psbt['fallback_locktime'] > bitcoind.rpc.getblockcount() - 100
848 assert psbt['fallback_locktime'] <= bitcoind.rpc.getblockcount()
849 assert psbt['input_count'] == 1
850 else:
851 assert psbt['tx']['locktime'] > bitcoind.rpc.getblockcount() - 100
852 assert psbt['tx']['locktime'] <= bitcoind.rpc.getblockcount()
853 assert len(psbt['tx']['vin']) == 1
854
855 # This should add 99 to the weight, but otherwise be identical except for locktime.
856 start_weight = 99
857 funding2 = l1.rpc.utxopsbt(amount // 2, feerate, start_weight,
858 ['{}:{}'.format(outputs[0][0], outputs[0][1])],
859 reserve=0, locktime=bitcoind.rpc.getblockcount() + 1)
860 psbt2 = bitcoind.rpc.decodepsbt(funding2['psbt'])
861
862 if is_psbt_v2:
863 assert psbt2['fallback_locktime'] == bitcoind.rpc.getblockcount() + 1
864 assert psbt2['inputs'] == psbt['inputs']
865 else:
866 assert psbt2['tx']['locktime'] == bitcoind.rpc.getblockcount() + 1
867 assert psbt2['tx']['vin'] == psbt['tx']['vin']
868
869 if chainparams['elements']:
870 assert is_psbt_v2
871 # elements includes the fee as an output

Callers

nothing calls this directly

Calls 8

to_btcMethod · 0.95
wait_forFunction · 0.90
MillisatoshiClass · 0.90
generate_blockMethod · 0.80
utxopsbtMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
listfundsMethod · 0.45

Tested by

no test coverage detected