diff options
author | stickies-v <stickies-v@protonmail.com> | 2023-06-23 11:32:10 +0100 |
---|---|---|
committer | stickies-v <stickies-v@protonmail.com> | 2023-06-23 16:46:32 +0100 |
commit | f1b99ac94fb77340c4d3a5b4bbc3df28009bc773 (patch) | |
tree | 0d8804b026d68353562c4afb848a607d554fbbf4 /test/functional/interface_usdt_utxocache.py | |
parent | ad90ba36bd930f00753643cd1fe0af72d1c828c2 (diff) |
test: refactor: deduplicate handle_utxocache_* logic
Carve out the comparison logic into a helper function to avoid
code duplication.
Diffstat (limited to 'test/functional/interface_usdt_utxocache.py')
-rwxr-xr-x | test/functional/interface_usdt_utxocache.py | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/test/functional/interface_usdt_utxocache.py b/test/functional/interface_usdt_utxocache.py index 5f2ba49026..7988ff2364 100755 --- a/test/functional/interface_usdt_utxocache.py +++ b/test/functional/interface_usdt_utxocache.py @@ -258,37 +258,33 @@ class UTXOCacheTracepointTest(BitcoinTestFramework): expected_utxocache_spents = [] expected_utxocache_adds = [] + def compare_utxo_with_event(utxo, event): + """Returns 1 if a utxo is identical to the event produced by BPF, otherwise""" + try: + assert_equal(utxo["txid"], bytes(event.txid[::-1]).hex()) + assert_equal(utxo["index"], event.index) + assert_equal(utxo["height"], event.height) + assert_equal(utxo["value"], event.value) + assert_equal(utxo["is_coinbase"], event.is_coinbase) + except AssertionError: + self.log.exception("Assertion failed") + return 0 + else: + return 1 + def handle_utxocache_add(_, data, __): nonlocal handle_add_succeeds event = ctypes.cast(data, ctypes.POINTER(UTXOCacheChange)).contents self.log.info(f"handle_utxocache_add(): {event}") add = expected_utxocache_adds.pop(0) - try: - assert_equal(add["txid"], bytes(event.txid[::-1]).hex()) - assert_equal(add["index"], event.index) - assert_equal(add["height"], event.height) - assert_equal(add["value"], event.value) - assert_equal(add["is_coinbase"], event.is_coinbase) - except AssertionError: - self.log.exception("Assertion failed") - else: - handle_add_succeeds += 1 + handle_add_succeeds += compare_utxo_with_event(add, event) def handle_utxocache_spent(_, data, __): nonlocal handle_spent_succeeds event = ctypes.cast(data, ctypes.POINTER(UTXOCacheChange)).contents self.log.info(f"handle_utxocache_spent(): {event}") spent = expected_utxocache_spents.pop(0) - try: - assert_equal(spent["txid"], bytes(event.txid[::-1]).hex()) - assert_equal(spent["index"], event.index) - assert_equal(spent["height"], event.height) - assert_equal(spent["value"], event.value) - assert_equal(spent["is_coinbase"], event.is_coinbase) - except AssertionError: - self.log.exception("Assertion failed") - else: - handle_spent_succeeds += 1 + handle_spent_succeeds += compare_utxo_with_event(spent, event) bpf["utxocache_add"].open_perf_buffer(handle_utxocache_add) bpf["utxocache_spent"].open_perf_buffer(handle_utxocache_spent) |