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

Function test_v2_replay_bookkeeping

tests/test_opening.py:1849–1908  ·  view source on GitHub ↗

Test that your bookkeeping for a liquidity ad is good even if we replay the opening and locking tx!

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1847
1848@pytest.mark.openchannel('v2')
1849def test_v2_replay_bookkeeping(node_factory, bitcoind):
1850 """ Test that your bookkeeping for a liquidity ad is good
1851 even if we replay the opening and locking tx!
1852 """
1853
1854 opts = [{'funder-policy': 'match', 'funder-policy-mod': 100,
1855 'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100,
1856 'rescan': 10, 'funding-confirms': 6, 'may_reconnect': True,
1857 'broken_log': 'channeld.*current blockheight [0-9]* less than last'},
1858 {'funder-policy': 'match', 'funder-policy-mod': 100,
1859 'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100,
1860 'may_reconnect': True}]
1861
1862 l1, l2, = node_factory.get_nodes(2, opts=opts)
1863 amount = 500000
1864 feerate = 2000
1865
1866 l1.fundwallet(amount * 100)
1867 l2.fundwallet(amount * 100)
1868
1869 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1870 rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
1871
1872 # l1 leases a channel from l2
1873 l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount,
1874 feerate='{}perkw'.format(feerate),
1875 compact_lease=rates['compact_lease'])
1876
1877 # add the funding transaction
1878 bitcoind.generate_block(4, wait_for_mempool=1)
1879
1880 l1.restart()
1881
1882 bitcoind.generate_block(2)
1883 l1.daemon.wait_for_log('to CHANNELD_NORMAL')
1884
1885 chan_id = first_channel_id(l1, l2)
1886 ev_tags = [e['tag'] for e in l1.rpc.bkpr_listaccountevents(chan_id)['events']]
1887 assert 'lease_fee' in ev_tags
1888
1889 # This should work ok
1890 l1.rpc.bkpr_listbalances()
1891
1892 bitcoind.generate_block(2)
1893 sync_blockheight(bitcoind, [l1])
1894
1895 l1.restart()
1896
1897 chan_id = first_channel_id(l1, l2)
1898 ev_tags = [e['tag'] for e in l1.rpc.bkpr_listaccountevents(chan_id)['events']]
1899 assert 'lease_fee' in ev_tags
1900
1901 l1.rpc.close(l2.info['id'], 1)
1902 bitcoind.generate_block(6, wait_for_mempool=1)
1903
1904 l1.daemon.wait_for_log(' to ONCHAIN')
1905 l2.daemon.wait_for_log(' to ONCHAIN')
1906

Callers

nothing calls this directly

Calls 10

first_channel_idFunction · 0.90
sync_blockheightFunction · 0.90
get_nodesMethod · 0.80
fundwalletMethod · 0.80
generate_blockMethod · 0.80
restartMethod · 0.80
wait_for_logMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected