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

Function test_bwatch_listwatch

tests/test_plugin.py:5753–5821  ·  view source on GitHub ↗

Test that listwatch RPC returns all active watches

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

5751
5752@pytest.mark.slow_test
5753def test_bwatch_listwatch(node_factory, bitcoind):
5754 """Test that listwatch RPC returns all active watches"""
5755 l1 = node_factory.get_node(options=BWATCH_OPTS)
5756
5757 # Record the baseline — the wallet registers scriptpubkey watches on startup.
5758 initial_count = len(l1.rpc.listwatch()['watches'])
5759
5760 # Add an outpoint watch — clearly not a real UTXO.
5761 test_outpoint_a_txid = "a" * 64
5762 test_outpoint_a = f"{test_outpoint_a_txid}:0"
5763 l1.rpc.addoutpointwatch(owner='wallet/p2wpkh/0', outpoint=test_outpoint_a, start_block=100)
5764
5765 # Add a P2PKH scriptpubkey watch — not used by the wallet (P2WPKH/P2TR/P2SH-P2WPKH only).
5766 test_scriptpubkey = "76a914" + "b" * 40 + "88ac"
5767 l1.rpc.addscriptpubkeywatch(owner='wallet/p2tr/0', scriptpubkey=test_scriptpubkey, start_block=200)
5768
5769 # Add a second outpoint watch
5770 test_outpoint_c_txid = "c" * 64
5771 test_outpoint_c = f"{test_outpoint_c_txid}:1"
5772 l1.rpc.addoutpointwatch(owner='wallet/p2sh_p2wpkh/0', outpoint=test_outpoint_c, start_block=150)
5773
5774 # Add a second owner to the first outpoint watch
5775 l1.rpc.addoutpointwatch(owner='wallet/p2tr/0', outpoint=test_outpoint_a, start_block=50)
5776
5777 result = l1.rpc.listwatch()
5778 watches = result['watches']
5779
5780 # 3 new unique watches added on top of the wallet's initial set
5781 assert len(watches) == initial_count + 3
5782
5783 # Find each test watch by its unique identifier
5784 outpoint_a_watch = next((w for w in watches if w.get('outpoint') == test_outpoint_a), None)
5785 scriptpubkey_watch = next((w for w in watches if w.get('scriptpubkey') == test_scriptpubkey), None)
5786 outpoint_c_watch = next((w for w in watches if w.get('outpoint') == test_outpoint_c), None)
5787
5788 # Verify first outpoint watch (two owners, start_block is the minimum)
5789 assert outpoint_a_watch is not None
5790 assert outpoint_a_watch['start_block'] == 50 # minimum of 100 and 50
5791 assert len(outpoint_a_watch['owners']) == 2
5792 assert 'wallet/p2wpkh/0' in outpoint_a_watch['owners']
5793 assert 'wallet/p2tr/0' in outpoint_a_watch['owners']
5794
5795 # Verify scriptpubkey watch
5796 assert scriptpubkey_watch is not None
5797 assert scriptpubkey_watch['start_block'] == 200
5798 assert len(scriptpubkey_watch['owners']) == 1
5799 assert scriptpubkey_watch['owners'][0] == 'wallet/p2tr/0'
5800
5801 # Verify second outpoint watch
5802 assert outpoint_c_watch is not None
5803 assert outpoint_c_watch['start_block'] == 150
5804 assert len(outpoint_c_watch['owners']) == 1
5805 assert outpoint_c_watch['owners'][0] == 'wallet/p2sh_p2wpkh/0'
5806
5807 # Remove one owner from first outpoint watch — watch itself should remain
5808 l1.rpc.deloutpointwatch(owner='wallet/p2wpkh/0', outpoint=test_outpoint_a)
5809
5810 watches = l1.rpc.listwatch()['watches']

Callers

nothing calls this directly

Calls 4

nextFunction · 0.85
anyClass · 0.50
get_nodeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected