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