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

Function test_psbt_version

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

Source from the content-addressed store, hash-verified

992
993
994def test_psbt_version(node_factory, bitcoind, chainparams):
995
996 sats_amount = 10**8
997
998 # CLN returns PSBTv0 and PSETv2, for now
999 is_elements = chainparams['elements']
1000
1001 l1 = node_factory.get_node()
1002 bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('bech32')['bech32'],
1003 sats_amount / 100000000)
1004
1005 bitcoind.generate_block(1)
1006 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1)
1007
1008 funding = l1.rpc.fundpsbt(satoshi=int(sats_amount / 2),
1009 feerate=7500,
1010 startweight=42)['psbt']
1011
1012 # Short elements test
1013 if is_elements:
1014 # Only v2 is allowed, and is a no-op
1015 for i in [0, 1, 3, 4, 5]:
1016 with pytest.raises(RpcError, match=r"Could not set PSBT version"):
1017 l1.rpc.setpsbtversion(funding, i)
1018 assert funding == l1.rpc.setpsbtversion(funding, 2)['psbt']
1019 # And elementsd can understand it
1020 bitcoind.rpc.decodepsbt(funding)
1021 return
1022
1023 # Non-elements test
1024 v2_funding = l1.rpc.setpsbtversion(funding, 2)['psbt']
1025
1026 # Bitcoind cannot understand PSBTv2 yet
1027 with pytest.raises(JSONRPCError, match=r"TX decode failed Unsupported version number"):
1028 bitcoind.rpc.decodepsbt(v2_funding)
1029
1030 # But it round-trips fine enough
1031 v0_funding = l1.rpc.setpsbtversion(v2_funding, 0)['psbt']
1032
1033 # CLN returns v0 for now
1034 assert funding == v0_funding
1035
1036 # And we reject non-0/2 args
1037 for i in [1, 3, 4, 5]:
1038 with pytest.raises(RpcError, match=r"Could not set PSBT version"):
1039 l1.rpc.setpsbtversion(v2_funding, i)
1040
1041
1042@unittest.skipIf(TEST_NETWORK == 'liquid-regtest', 'Core/Elements need joinpsbt support for v2')

Callers

nothing calls this directly

Calls 6

wait_forFunction · 0.90
generate_blockMethod · 0.80
fundpsbtMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
listfundsMethod · 0.45

Tested by

no test coverage detected