Skip to content

Commit ec71171

Browse files
committed
simplify
1 parent bcb1588 commit ec71171

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

chia/_tests/blockchain/test_blockchain.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,8 +2076,7 @@ async def test_timelock_conditions(
20762076

20772077
if expected == AddBlockResult.NEW_PEAK:
20782078
# ensure coin was in fact spent
2079-
recs = await b.consensus_store.get_coin_records([coin.name()])
2080-
c = recs[0] if len(recs) > 0 else None
2079+
c = await b.consensus_store.get_coin_record(coin.name())
20812080
assert c is not None and c.spent
20822081

20832082
@pytest.mark.anyio
@@ -2287,12 +2286,10 @@ async def test_ephemeral_timelock(
22872286

22882287
if expected == AddBlockResult.NEW_PEAK:
22892288
# ensure coin1 was in fact spent
2290-
recs1 = await b.consensus_store.get_coin_records([coin1.name()])
2291-
c = recs1[0] if len(recs1) > 0 else None
2289+
c = await b.consensus_store.get_coin_record(coin1.name())
22922290
assert c is not None and c.spent
22932291
# ensure coin2 was NOT spent
2294-
recs2 = await b.consensus_store.get_coin_records([coin2.name()])
2295-
c = recs2[0] if len(recs2) > 0 else None
2292+
c = await b.consensus_store.get_coin_record(coin2.name())
22962293
assert c is not None and not c.spent
22972294

22982295
@pytest.mark.anyio
@@ -3106,11 +3103,9 @@ async def test_double_spent_in_reorg(self, empty_blockchain: Blockchain, bt: Blo
31063103
)
31073104

31083105
# ephemeral coin is spent
3109-
recs_first = await b.consensus_store.get_coin_records([new_coin.name()])
3110-
first_coin = recs_first[0] if len(recs_first) > 0 else None
3106+
first_coin = await b.consensus_store.get_coin_record(new_coin.name())
31113107
assert first_coin is not None and first_coin.spent
3112-
recs_second = await b.consensus_store.get_coin_records([tx_2.additions()[0].name()])
3113-
second_coin = recs_second[0] if len(recs_second) > 0 else None
3108+
second_coin = await b.consensus_store.get_coin_record(tx_2.additions()[0].name())
31143109
assert second_coin is not None and not second_coin.spent
31153110

31163111
farmer_coin = create_farmer_coin(
@@ -3126,8 +3121,7 @@ async def test_double_spent_in_reorg(self, empty_blockchain: Blockchain, bt: Blo
31263121
)
31273122
await _validate_and_add_block(b, blocks_reorg[-1])
31283123

3129-
recs_farmer = await b.consensus_store.get_coin_records([farmer_coin.name()])
3130-
farmer_coin_record = recs_farmer[0] if len(recs_farmer) > 0 else None
3124+
farmer_coin_record = await b.consensus_store.get_coin_record(farmer_coin.name())
31313125
assert farmer_coin_record is not None and farmer_coin_record.spent
31323126

31333127
@pytest.mark.anyio
@@ -3882,14 +3876,14 @@ async def test_chain_failed_rollback(empty_blockchain: Blockchain, bt: BlockTool
38823876
await _validate_and_add_block(b, block, expected_result=AddBlockResult.ADDED_AS_ORPHAN, fork_info=fork_info)
38833877

38843878
# Incorrectly set the height as spent in DB to trigger an error
3885-
recs_dbg1 = await b.consensus_store.get_coin_records([spend_bundle.coin_spends[0].coin.name()])
3886-
print(f"{recs_dbg1[0] if len(recs_dbg1) > 0 else None}")
3879+
coin_record_dbg1 = await b.consensus_store.get_coin_record(spend_bundle.coin_spends[0].coin.name())
3880+
print(f"{coin_record_dbg1}")
38873881
print(spend_bundle.coin_spends[0].coin.name())
38883882
# await b.consensus_store._set_spent([spend_bundle.coin_spends[0].coin.name()], 8)
38893883
async with b.consensus_store as writer:
38903884
await writer.rollback_to_block(2)
3891-
recs_dbg2 = await b.consensus_store.get_coin_records([spend_bundle.coin_spends[0].coin.name()])
3892-
print(f"{recs_dbg2[0] if len(recs_dbg2) > 0 else None}")
3885+
coin_record_dbg2 = await b.consensus_store.get_coin_record(spend_bundle.coin_spends[0].coin.name())
3886+
print(f"{coin_record_dbg2}")
38933887

38943888
fork_block = blocks_reorg_chain[10 - 1]
38953889
# fork_info = ForkInfo(fork_block.height, fork_block.height, fork_block.header_hash)

chia/_tests/core/full_node/ram_db.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
from chia_rs import ConsensusConstants
99

10-
from chia.consensus.block_height_map import BlockHeightMap
1110
from chia.consensus.blockchain import Blockchain
12-
from chia.full_node.block_store import BlockStore
13-
from chia.full_node.coin_store import CoinStore
1411
from chia.full_node.consensus_store_sqlite3 import ConsensusStoreSQLite3
1512
from chia.util.db_wrapper import DBWrapper2
1613

chia/_tests/util/blockchain.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
from chia_rs import ConsensusConstants, FullBlock
1111
from chia_rs.sized_ints import uint64
1212

13-
from chia.consensus.block_height_map import BlockHeightMap
1413
from chia.consensus.blockchain import Blockchain
15-
from chia.full_node.block_store import BlockStore
16-
from chia.full_node.coin_store import CoinStore
1714
from chia.full_node.consensus_store_sqlite3 import ConsensusStoreSQLite3
1815
from chia.simulator.block_tools import BlockTools
1916
from chia.util.db_wrapper import DBWrapper2, generate_in_memory_db_uri

chia/consensus/consensus_store_protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def get_block_heights_in_main_chain(self) -> AsyncIterator[int]: ...
8989

9090
# Coin store reads
9191
async def get_coin_records(self, names: Collection[bytes32]) -> list[CoinRecord]: ...
92+
async def get_coin_record(self, coin_name: bytes32) -> Optional[CoinRecord]: ...
9293
async def get_coins_added_at_height(self, height: uint32) -> list[CoinRecord]: ...
9394
async def get_coins_removed_at_height(self, height: uint32) -> list[CoinRecord]: ...
9495

chia/full_node/consensus_store_sqlite3.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ async def get_generators_at(self, heights: set[uint32]) -> dict[uint32, bytes]:
177177
async def get_coin_records(self, names: Collection[bytes32]) -> list[CoinRecord]:
178178
return await self.coin_store.get_coin_records(names)
179179

180+
async def get_coin_record(self, coin_name: bytes32) -> Optional[CoinRecord]:
181+
return await self.coin_store.get_coin_record(coin_name)
182+
180183
async def get_coins_added_at_height(self, height: uint32) -> list[CoinRecord]:
181184
return await self.coin_store.get_coins_added_at_height(height)
182185

0 commit comments

Comments
 (0)