diff --git a/chia/_tests/util/misc.py b/chia/_tests/util/misc.py index fbeec607a4..d65bf8fb63 100644 --- a/chia/_tests/util/misc.py +++ b/chia/_tests/util/misc.py @@ -477,24 +477,22 @@ def create_logger(file: TextIO = sys.stdout) -> logging.Logger: def invariant_check_mempool(mempool: Mempool) -> None: - with mempool._db_conn as conn: - cursor = conn.execute("SELECT COALESCE(SUM(cost), 0), COALESCE(SUM(fee), 0) FROM tx") - val = cursor.fetchone() - assert (mempool._total_cost, mempool._total_fee) == val + cursor = mempool._db_conn.execute("SELECT COALESCE(SUM(cost), 0), COALESCE(SUM(fee), 0) FROM tx") + val = cursor.fetchone() + assert (mempool._total_cost, mempool._total_fee) == val - with mempool._db_conn as conn: - cursor = conn.execute("SELECT coin_id, tx FROM spends") - for coin_id, item_id in cursor.fetchall(): - item = mempool._items.get(item_id) - assert item is not None - # item is expected to contain a spend of coin_id, but it might be a - # fast-forward spend, in which case the dictionary won't help us, - # but we'll have to do a linear search - if coin_id in item.bundle_coin_spends: - assert item.bundle_coin_spends[coin_id].coin_spend.coin.name() == coin_id - continue + cursor = mempool._db_conn.execute("SELECT coin_id, tx FROM spends") + for coin_id, item_id in cursor.fetchall(): + item = mempool._items.get(item_id) + assert item is not None + # item is expected to contain a spend of coin_id, but it might be a + # fast-forward spend, in which case the dictionary won't help us, + # but we'll have to do a linear search + if coin_id in item.bundle_coin_spends: + assert item.bundle_coin_spends[coin_id].coin_spend.coin.name() == coin_id + continue - assert any(i.latest_singleton_coin == coin_id for i in item.bundle_coin_spends.values()) + assert any(i.latest_singleton_coin == coin_id for i in item.bundle_coin_spends.values()) async def wallet_height_at_least(wallet_node: WalletNode, h: uint32) -> bool: