Skip to content

Commit 4994b45

Browse files
authored
CHIA-2979 Simplify test_set_spent (#19655)
Simplify test_set_spent.
1 parent 15a4536 commit 4994b45

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

chia/_tests/core/full_node/stores/test_coin_store.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -178,39 +178,31 @@ async def test_set_spent(db_version: int, bt: BlockTools) -> None:
178178

179179
# Save/get block
180180
for block in blocks:
181-
if block.is_transaction_block():
182-
removals: list[bytes32] = []
183-
additions: list[Coin] = []
184-
async with db_wrapper.writer():
185-
if block.is_transaction_block():
186-
assert block.foliage_transaction_block is not None
187-
await coin_store.new_block(
188-
block.height,
189-
block.foliage_transaction_block.timestamp,
190-
block.get_included_reward_coins(),
191-
additions,
192-
removals,
193-
)
194-
195-
coins = block.get_included_reward_coins()
196-
records = [await coin_store.get_coin_record(coin.name()) for coin in coins]
181+
if not block.is_transaction_block():
182+
continue
183+
assert block.foliage_transaction_block is not None
184+
await coin_store.new_block(
185+
block.height, block.foliage_transaction_block.timestamp, block.get_included_reward_coins(), [], []
186+
)
187+
coins = block.get_included_reward_coins()
188+
records = [await coin_store.get_coin_record(coin.name()) for coin in coins]
197189

198-
await coin_store._set_spent([r.name for r in records if r is not None], block.height)
190+
await coin_store._set_spent([r.name for r in records if r is not None], block.height)
199191

200-
if len(records) > 0:
201-
for r in records:
202-
assert r is not None
203-
assert (await coin_store.get_coin_record(r.name)) is not None
192+
if len(records) > 0:
193+
for r in records:
194+
assert r is not None
195+
assert (await coin_store.get_coin_record(r.name)) is not None
204196

205-
# Check that we can't spend a coin twice in DB
206-
with pytest.raises(ValueError, match="Invalid operation to set spent"):
207-
await coin_store._set_spent([r.name for r in records if r is not None], block.height)
197+
# Check that we can't spend a coin twice in DB
198+
with pytest.raises(ValueError, match="Invalid operation to set spent"):
199+
await coin_store._set_spent([r.name for r in records if r is not None], block.height)
208200

209-
records = [await coin_store.get_coin_record(coin.name()) for coin in coins]
210-
for record in records:
211-
assert record is not None
212-
assert record.spent
213-
assert record.spent_block_index == block.height
201+
records = [await coin_store.get_coin_record(coin.name()) for coin in coins]
202+
for record in records:
203+
assert record is not None
204+
assert record.spent
205+
assert record.spent_block_index == block.height
214206

215207

216208
@pytest.mark.limit_consensus_modes(reason="save time")

0 commit comments

Comments
 (0)