From 27ff87c045db07f1391caa10e62c50c94ec2f318 Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 1 Dec 2021 10:08:32 -0600 Subject: [PATCH] coin_moves: de-dupe moves as they come in test_onchain_dust_out restarts a node, which produces duplicate events. this is expected, but we need to de-duplicate the events stream to get accurate results --- tests/utils.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 960305e57..74bf7d2b3 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -143,7 +143,7 @@ def check_coin_moves_idx(n): def account_balance(n, account_id): - moves = n.rpc.call('listcoinmoves_plugin')['coin_moves'] + moves = dedupe_moves(n.rpc.call('listcoinmoves_plugin')['coin_moves']) chan_moves = [m for m in moves if m['account_id'] == account_id] assert len(chan_moves) > 0 m_sum = 0 @@ -268,10 +268,27 @@ def matchup_events(u_set, evs, chans, tag_list): return txid +def dedupe_moves(moves): + move_set = {} + deduped_moves = [] + for move in moves: + # Dupes only pertain to onchain moves? + if 'utxo_txid' not in move: + deduped_moves.append(move) + continue + + outpoint = '{}:{};{}'.format(move['utxo_txid'], move['vout'], move['txid'] if 'txid' in move else 'xx') + if outpoint not in move_set: + deduped_moves.append(move) + move_set[outpoint] = move + return deduped_moves + + def check_utxos_channel(n, chans, expected, exp_tag_list=None, filter_channel=None): tag_list = {} moves = n.rpc.call('listcoinmoves_plugin')['coin_moves'] - utxos = extract_utxos(moves) + + utxos = extract_utxos(dedupe_moves(moves)) if filter_channel: utxos = utxos_for_channel(utxos, filter_channel)