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

Function test_v2_replay_bookkeeping

tests/test_opening.py:1521–1580  ·  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

1519
1520@pytest.mark.openchannel('v2')
1521def test_v2_replay_bookkeeping(node_factory, bitcoind):
1522 """ Test that your bookkeeping for a liquidity ad is good
1523 even if we replay the opening and locking tx!
1524 """
1525
1526 opts = [{'funder-policy': 'match', 'funder-policy-mod': 100,
1527 'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100,
1528 'rescan': 10, 'funding-confirms': 6, 'may_reconnect': True},
1529 {'funder-policy': 'match', 'funder-policy-mod': 100,
1530 'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100,
1531 'may_reconnect': True}]
1532 l1, l2, = node_factory.get_nodes(2, opts=opts)
1533 amount = 500000
1534 feerate = 2000
1535
1536 l1.fundwallet(amount * 100)
1537 l2.fundwallet(amount * 100)
1538
1539 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1540 rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
1541 wait_for(lambda: len(l1.rpc.listpeers(l2.info['id'])['peers']) == 0)
1542 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1543
1544 # l1 leases a channel from l2
1545 l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount,
1546 feerate='{}perkw'.format(feerate),
1547 compact_lease=rates['compact_lease'])
1548
1549 # add the funding transaction
1550 bitcoind.generate_block(4, wait_for_mempool=1)
1551
1552 l1.restart()
1553
1554 bitcoind.generate_block(2)
1555 l1.daemon.wait_for_log('to CHANNELD_NORMAL')
1556
1557 chan_id = first_channel_id(l1, l2)
1558 ev_tags = [e['tag'] for e in l1.rpc.bkpr_listaccountevents(chan_id)['events']]
1559 assert 'lease_fee' in ev_tags
1560
1561 # This should work ok
1562 l1.rpc.bkpr_listbalances()
1563
1564 bitcoind.generate_block(2)
1565 sync_blockheight(bitcoind, [l1])
1566
1567 l1.restart()
1568
1569 chan_id = first_channel_id(l1, l2)
1570 ev_tags = [e['tag'] for e in l1.rpc.bkpr_listaccountevents(chan_id)['events']]
1571 assert 'lease_fee' in ev_tags
1572
1573 l1.rpc.close(l2.info['id'], 1)
1574 bitcoind.generate_block(6, wait_for_mempool=1)
1575
1576 l1.daemon.wait_for_log(' to ONCHAIN')
1577 l2.daemon.wait_for_log(' to ONCHAIN')
1578

Callers

nothing calls this directly

Calls 12

wait_forFunction · 0.90
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
listpeersMethod · 0.45
fundchannelMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected