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

Function test_bwatch_rescan_notifies_lightningd

tests/test_plugin.py:5403–5433  ·  view source on GitHub ↗

Test that matches found during rescan also trigger watch_found

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

5401
5402@pytest.mark.slow_test
5403def test_bwatch_rescan_notifies_lightningd(node_factory, bitcoind):
5404 """Test that matches found during rescan also trigger watch_found"""
5405 l1 = node_factory.get_node(options=BWATCH_OPTS)
5406
5407 # Get an address
5408 addr = l1.rpc.newaddr('bech32')['bech32']
5409 addr_info = bitcoind.rpc.getaddressinfo(addr)
5410 scriptpubkey = addr_info['scriptPubKey']
5411
5412 # Send coins FIRST (before adding the watch)
5413 bitcoind.rpc.sendtoaddress(addr, 0.01)
5414 bitcoind.generate_block(1)
5415
5416 # Wait for bwatch to fully sync to the new block
5417 import time
5418 time.sleep(2)
5419 l1.daemon.wait_for_log(r'No block change')
5420
5421 # Now get current height and add watch with start_block in the past
5422 info = l1.rpc.getinfo()
5423 start_block = info['blockheight'] - 1 # The block we just mined
5424
5425 # Add watch - should trigger rescan and find the tx
5426 l1.rpc.addscriptpubkeywatch(owner='wallet/p2wpkh/0', scriptpubkey=scriptpubkey,
5427 start_block=start_block)
5428
5429 # Should trigger rescan
5430 l1.daemon.wait_for_log(r'Starting rescan')
5431
5432 # Rescan should find the match and notify lightningd
5433 l1.daemon.wait_for_log(r'watch_found at block', timeout=60)
5434
5435
5436def test_bwatch_watches_persist_across_restart(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 5

generate_blockMethod · 0.80
wait_for_logMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
getinfoMethod · 0.45

Tested by

no test coverage detected