Skip to content

Commit 4d027d0

Browse files
authored
CHIA-2776 Simplify DB checks in invariant_check_mempool (#19526)
Simplify DB checks in invariant_check_mempool.
1 parent fcd20ce commit 4d027d0

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

chia/_tests/util/misc.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -477,24 +477,22 @@ def create_logger(file: TextIO = sys.stdout) -> logging.Logger:
477477

478478

479479
def invariant_check_mempool(mempool: Mempool) -> None:
480-
with mempool._db_conn as conn:
481-
cursor = conn.execute("SELECT COALESCE(SUM(cost), 0), COALESCE(SUM(fee), 0) FROM tx")
482-
val = cursor.fetchone()
483-
assert (mempool._total_cost, mempool._total_fee) == val
484-
485-
with mempool._db_conn as conn:
486-
cursor = conn.execute("SELECT coin_id, tx FROM spends")
487-
for coin_id, item_id in cursor.fetchall():
488-
item = mempool._items.get(item_id)
489-
assert item is not None
490-
# item is expected to contain a spend of coin_id, but it might be a
491-
# fast-forward spend, in which case the dictionary won't help us,
492-
# but we'll have to do a linear search
493-
if coin_id in item.bundle_coin_spends:
494-
assert item.bundle_coin_spends[coin_id].coin_spend.coin.name() == coin_id
495-
continue
496-
497-
assert any(i.latest_singleton_coin == coin_id for i in item.bundle_coin_spends.values())
480+
cursor = mempool._db_conn.execute("SELECT COALESCE(SUM(cost), 0), COALESCE(SUM(fee), 0) FROM tx")
481+
val = cursor.fetchone()
482+
assert (mempool._total_cost, mempool._total_fee) == val
483+
484+
cursor = mempool._db_conn.execute("SELECT coin_id, tx FROM spends")
485+
for coin_id, item_id in cursor.fetchall():
486+
item = mempool._items.get(item_id)
487+
assert item is not None
488+
# item is expected to contain a spend of coin_id, but it might be a
489+
# fast-forward spend, in which case the dictionary won't help us,
490+
# but we'll have to do a linear search
491+
if coin_id in item.bundle_coin_spends:
492+
assert item.bundle_coin_spends[coin_id].coin_spend.coin.name() == coin_id
493+
continue
494+
495+
assert any(i.latest_singleton_coin == coin_id for i in item.bundle_coin_spends.values())
498496

499497

500498
async def wallet_height_at_least(wallet_node: WalletNode, h: uint32) -> bool:

0 commit comments

Comments
 (0)