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

Function test_onchain_unwatch

tests/test_closing.py:1842–1899  ·  view source on GitHub ↗

Onchaind should not watch random spends

(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

1840
1841
1842def test_onchain_unwatch(node_factory, bitcoind, chainparams):
1843 """Onchaind should not watch random spends"""
1844 # We track channel balances, to verify that accounting is ok.
1845 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1846 l1, l2 = node_factory.line_graph(2, opts={'plugin': coin_mvt_plugin})
1847 channel_id = first_channel_id(l1, l2)
1848
1849 l1.pay(l2, 200000000)
1850 # If the HTLC isn't completely removed, we will use an anchor to bump
1851 # the commitment tx. Under valgrind we tend to resolve the HTLC
1852 # before getting to dev_fail. Unify the cases by waiting a bit.
1853 wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['htlcs'] == [])
1854
1855 l1.rpc.dev_fail(l2.info['id'])
1856 l1.daemon.wait_for_log('Failing due to dev-fail command')
1857 l1.wait_for_channel_onchain(l2.info['id'])
1858
1859 l1.bitcoin.generate_block(1, wait_for_mempool=1)
1860 l1.daemon.wait_for_log(' to ONCHAIN')
1861 l2.daemon.wait_for_log(' to ONCHAIN')
1862
1863 _, txid, blocks = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
1864 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
1865 assert blocks == 4
1866
1867 # 5 later, l1 should collect its to-self payment.
1868 bitcoind.generate_block(4)
1869
1870 # First time it sees it, onchaind cares.
1871 bitcoind.generate_block(1, wait_for_mempool=txid)
1872 l1.daemon.wait_for_log('Resolved OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by our proposal '
1873 'OUR_DELAYED_RETURN_TO_WALLET')
1874
1875 # Now test unrelated onchain churn.
1876 # Daemon gets told about wallet; says it doesn't care.
1877 l1.rpc.withdraw(l1.rpc.newaddr('bech32')['bech32'], 'all')
1878 bitcoind.generate_block(1)
1879
1880 l1.daemon.wait_for_log("but we don't care")
1881
1882 # And lightningd should respect that!
1883 assert not l1.daemon.is_in_log("Can't unwatch txid")
1884
1885 # So these should not generate further messages
1886 for i in range(5):
1887 l1.rpc.withdraw(l1.rpc.newaddr('bech32')['bech32'], 'all')
1888 bitcoind.generate_block(1)
1889 # Make sure it digests the block
1890 sync_blockheight(bitcoind, [l1])
1891
1892 # We won't see this again.
1893 assert not l1.daemon.is_in_log("but we don't care",
1894 start=l1.daemon.logsearch_start)
1895
1896 assert account_balance(l1, channel_id) == 0
1897 assert account_balance(l2, channel_id) == 0
1898 # Note: for this test we leave onchaind running, so we can detect
1899 # any leaks!

Callers

nothing calls this directly

Calls 15

first_channel_idFunction · 0.90
wait_forFunction · 0.90
only_oneFunction · 0.90
sync_blockheightFunction · 0.90
account_balanceFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
dev_failMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80

Tested by

no test coverage detected