pytest: allow pushed after onchain_fee in test_bookkeeping_missed_chans_pushed
It can happen, and it's perfectly reasonable. If this happens in other places, we might need to allow
arbitrary reordering?
```
2026-01-29T05:55:58.5474967Z exp_events = [{'tag': 'channel_open', 'credit_msat': open_amt * 1000, 'debit_msat': 0},
2026-01-29T05:55:58.5475765Z {'tag': 'pushed', 'credit_msat': 0, 'debit_msat': push_amt},
2026-01-29T05:55:58.5476454Z {'tag': 'onchain_fee', 'credit_msat': 4927000, 'debit_msat': 0},
2026-01-29T05:55:58.5477168Z {'tag': 'invoice', 'credit_msat': 0, 'debit_msat': invoice_msat}]
2026-01-29T05:55:58.5477797Z > check_events(l1, channel_id, exp_events)
2026-01-29T05:55:58.5478120Z
2026-01-29T05:55:58.5478282Z tests/test_bookkeeper.py:402:
2026-01-29T05:55:58.5478777Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2026-01-29T05:55:58.5479162Z
2026-01-29T05:55:58.5479396Z node = <fixtures.LightningNode object at 0x7fa3660a6140>
2026-01-29T05:55:58.5480158Z channel_id = 'a4e913b2d143efc3d90cfa66a56aeed3eb9e1533b350c8e84124bdec37bcf74a'
2026-01-29T05:55:58.5481929Z exp_events = [{'credit_msat': 10000000000, 'debit_msat': 0, 'tag': 'channel_open'}, {'credit_msat': 0, 'debit_msat': 1000000000, 'tag': 'pushed'}, {'credit_msat': 4927000, 'debit_msat': 0, 'tag': 'onchain_fee'}, {'credit_msat': 0, 'debit_msat': 11000000, 'tag': 'invoice'}]
2026-01-29T05:55:58.5483442Z
2026-01-29T05:55:58.5483671Z def check_events(node, channel_id, exp_events):
2026-01-29T05:55:58.5484551Z chan_events = [ev for ev in node.rpc.bkpr_listaccountevents()['events'] if ev['account'] == channel_id]
2026-01-29T05:55:58.5485684Z stripped = [{k: d[k] for k in ('tag', 'credit_msat', 'debit_msat') if k in d} for d in chan_events]
2026-01-29T05:55:58.5486455Z > assert stripped == exp_events
2026-01-29T05:55:58.5489277Z E AssertionError: assert [{'tag': 'channel_open', 'credit_msat': 10000000000, 'debit_msat': 0}, {'tag': 'onchain_fee', 'credit_msat': 4927000, 'debit_msat': 0}, {'tag': 'pushed', 'credit_msat': 0, 'debit_msat': 1000000000}, {'tag': 'invoice', 'credit_msat': 0, 'debit_msat': 11000000}] == [{'tag': 'channel_open', 'credit_msat': 10000000000, 'debit_msat': 0}, {'tag': 'pushed', 'credit_msat': 0, 'debit_msat': 1000000000}, {'tag': 'onchain_fee', 'credit_msat': 4927000, 'debit_msat': 0}, {'tag': 'invoice', 'credit_msat': 0, 'debit_msat': 11000000}]
2026-01-29T05:55:58.5492021Z E
2026-01-29T05:55:58.5492767Z E At index 1 diff: {'tag': 'onchain_fee', 'credit_msat': 4927000, 'debit_msat': 0} != {'tag': 'pushed', 'credit_msat': 0, 'debit_msat': 1000000000}
2026-01-29T05:55:58.5493812Z E
2026-01-29T05:55:58.5494078Z E Full diff:
2026-01-29T05:55:58.5494373Z E [
2026-01-29T05:55:58.5494863Z E {
2026-01-29T05:55:58.5495166Z E 'credit_msat': 10000000000,
2026-01-29T05:55:58.5495565Z E 'debit_msat': 0,
2026-01-29T05:55:58.5495946Z E 'tag': 'channel_open',
2026-01-29T05:55:58.5496330Z E - },
2026-01-29T05:55:58.5496613Z E - {
2026-01-29T05:55:58.5496906Z E - 'credit_msat': 0,
2026-01-29T05:55:58.5497285Z E - 'debit_msat': 1000000000,
2026-01-29T05:55:58.5497900Z E - 'tag': 'pushed',
2026-01-29T05:55:58.5498264Z E },
2026-01-29T05:55:58.5498531Z E {
2026-01-29T05:55:58.5498818Z E 'credit_msat': 4927000,
2026-01-29T05:55:58.5499200Z E 'debit_msat': 0,
2026-01-29T05:55:58.5499563Z E 'tag': 'onchain_fee',
2026-01-29T05:55:58.5499925Z E },
2026-01-29T05:55:58.5500190Z E {
2026-01-29T05:55:58.5500477Z E 'credit_msat': 0,
2026-01-29T05:55:58.5500863Z E + 'debit_msat': 1000000000,
2026-01-29T05:55:58.5501255Z E + 'tag': 'pushed',
2026-01-29T05:55:58.5501592Z E + },
2026-01-29T05:55:58.5501853Z E + {
2026-01-29T05:55:58.5502141Z E + 'credit_msat': 0,
2026-01-29T05:55:58.5502511Z E 'debit_msat': 11000000,
2026-01-29T05:55:58.5502889Z E 'tag': 'invoice',
2026-01-29T05:55:58.5503424Z E },
2026-01-29T05:55:58.5503698Z E ]
2026-01-29T05:55:58.5503861Z
2026-01-29T05:55:58.5504027Z tests/test_bookkeeper.py:29: AssertionError
```
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -23,10 +23,10 @@ def find_first_tag(evs, tag):
|
||||
return ev[0]
|
||||
|
||||
|
||||
def check_events(node, channel_id, exp_events):
|
||||
def check_events(node, channel_id, exp_events, alt_events=None):
|
||||
chan_events = [ev for ev in node.rpc.bkpr_listaccountevents()['events'] if ev['account'] == channel_id]
|
||||
stripped = [{k: d[k] for k in ('tag', 'credit_msat', 'debit_msat') if k in d} for d in chan_events]
|
||||
assert stripped == exp_events
|
||||
assert stripped == exp_events or stripped == alt_events
|
||||
|
||||
|
||||
@unittest.skipIf(TEST_NETWORK != 'regtest', "fixme: broadcast fails, dusty")
|
||||
@@ -399,7 +399,12 @@ def test_bookkeeping_missed_chans_pushed(node_factory, bitcoind):
|
||||
{'tag': 'pushed', 'credit_msat': 0, 'debit_msat': push_amt},
|
||||
{'tag': 'onchain_fee', 'credit_msat': 4927000, 'debit_msat': 0},
|
||||
{'tag': 'invoice', 'credit_msat': 0, 'debit_msat': invoice_msat}]
|
||||
check_events(l1, channel_id, exp_events)
|
||||
# We sometimes see onchain_fee first:
|
||||
alt_events = [{'tag': 'channel_open', 'credit_msat': open_amt * 1000, 'debit_msat': 0},
|
||||
{'tag': 'onchain_fee', 'credit_msat': 4927000, 'debit_msat': 0},
|
||||
{'tag': 'pushed', 'credit_msat': 0, 'debit_msat': push_amt},
|
||||
{'tag': 'invoice', 'credit_msat': 0, 'debit_msat': invoice_msat}]
|
||||
check_events(l1, channel_id, exp_events, alt_events)
|
||||
|
||||
# l2 events
|
||||
exp_events = [{'tag': 'channel_open', 'credit_msat': 0, 'debit_msat': 0},
|
||||
|
||||
Reference in New Issue
Block a user