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

Function test_bip86_psbt_integration

tests/test_wallet.py:2009–2061  ·  view source on GitHub ↗

Test BIP86 addresses in PSBT workflows

(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

2007
2008@unittest.skipIf(TEST_NETWORK != 'regtest', "BIP86 tests are regtest-specific")
2009def test_bip86_psbt_integration(node_factory, bitcoind, chainparams):
2010 """Test BIP86 addresses in PSBT workflows"""
2011 l1 = setup_bip86_node(node_factory)
2012
2013 # Fund BIP86 address
2014 bip86_addr = l1.rpc.newaddr('p2tr')['p2tr']
2015 amount_sats = 1000000 # 0.01 BTC
2016
2017 # Send funds to the BIP86 address
2018 bitcoind.rpc.sendtoaddress(bip86_addr, amount_sats / 10**8)
2019 bitcoind.generate_block(1)
2020
2021 # Wait for the node to see the transaction
2022 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
2023
2024 # Verify the funds are visible and confirmed
2025 funds = l1.rpc.listfunds()
2026 bip86_outputs = [out for out in funds['outputs'] if out['address'] == bip86_addr]
2027 assert len(bip86_outputs) == 1, f"Expected 1 BIP86 output, got {len(bip86_outputs)}"
2028 assert bip86_outputs[0]['amount_msat'] == amount_sats * 1000
2029 assert bip86_outputs[0]['status'] == 'confirmed'
2030
2031 # Create PSBT with BIP86 input
2032 dest_addr = bitcoind.rpc.getnewaddress()
2033 send_amount = 500000 # 0.005 BTC
2034
2035 # Use txprepare to create a PSBT
2036 psbt_result = l1.rpc.txprepare([{dest_addr: send_amount}])
2037 psbt_str = psbt_result['psbt']
2038
2039 # Verify PSBT was created successfully
2040 assert psbt_str is not None and len(psbt_str) > 0, "PSBT creation failed"
2041
2042 # Sign the PSBT
2043 signed_result = l1.rpc.signpsbt(psbt_str)
2044 assert 'signed_psbt' in signed_result, "PSBT signing failed - no signed_psbt returned"
2045 assert len(signed_result['signed_psbt']) > 0, "PSBT signing failed - empty signed_psbt"
2046
2047 # Send the signed PSBT
2048 send_result = l1.rpc.sendpsbt(signed_result['signed_psbt'])
2049 sent_txid = send_result['txid']
2050
2051 # Mine the transaction
2052 bitcoind.generate_block(1)
2053
2054 # Wait for the transaction to be confirmed (blockheight > 0)
2055 wait_for(lambda: len([tx for tx in l1.rpc.listtransactions()['transactions']
2056 if tx['hash'] == sent_txid and tx['blockheight'] > 0]) > 0)
2057
2058 # Verify the transaction exists in the blockchain and is confirmed
2059 transactions = l1.rpc.listtransactions()['transactions']
2060 sent_tx = [tx for tx in transactions if tx['hash'] == sent_txid][0]
2061 assert sent_tx['blockheight'] > 0, "Transaction should be confirmed in a block"
2062
2063
2064@unittest.skipIf(TEST_NETWORK != 'regtest', "BIP86 tests are regtest-specific")

Callers

nothing calls this directly

Calls 10

wait_forFunction · 0.90
setup_bip86_nodeFunction · 0.85
generate_blockMethod · 0.80
txprepareMethod · 0.80
signpsbtMethod · 0.80
sendpsbtMethod · 0.80
listtransactionsMethod · 0.80
newaddrMethod · 0.45
listfundsMethod · 0.45
getnewaddressMethod · 0.45

Tested by

no test coverage detected