Skip to content

Commit 2342216

Browse files
committed
Add a test to cover new peak returning added transactions as a result of retrying potential transactions.
1 parent fb05d17 commit 2342216

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

chia/_tests/core/mempool/test_mempool_manager.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
QUOTE_BYTES,
4242
QUOTE_EXECUTION_COST,
4343
MempoolManager,
44+
NewPeakItem,
4445
TimelockConditions,
4546
can_replace,
4647
check_removals,
@@ -3260,3 +3261,41 @@ async def test_different_ff_versions() -> None:
32603261
latest_singleton_lineage2 = new_mi2.bundle_coin_spends[version2_id].latest_singleton_lineage
32613262
assert latest_singleton_lineage2 is not None
32623263
assert latest_singleton_lineage2.coin_id == new_latest_lineage_id
3264+
3265+
3266+
@pytest.mark.anyio
3267+
@pytest.mark.parametrize("optimized_path", [True, False])
3268+
async def test_new_peak_txs_added(optimized_path: bool) -> None:
3269+
"""
3270+
Tests that deferred transactions because of time-lock are retried once the
3271+
time-lock allows them to be reconsidered.
3272+
"""
3273+
coins = TestCoins([TEST_COIN], {})
3274+
mempool_manager = await setup_mempool(coins)
3275+
# Add an item that should go to the pending cache
3276+
assert mempool_manager.peak is not None
3277+
asserted_abs_height = mempool_manager.peak.height + 1
3278+
sb, sb_name, result = await generate_and_add_spendbundle(
3279+
mempool_manager, [[ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, asserted_abs_height]]
3280+
)
3281+
_, status, error = result
3282+
assert status == MempoolInclusionStatus.PENDING
3283+
assert error == Err.ASSERT_HEIGHT_ABSOLUTE_FAILED
3284+
# Advance the mempool beyond the asserted height to retry the test item
3285+
if optimized_path:
3286+
spent_coins: Optional[list[bytes32]] = []
3287+
new_peak_info = await mempool_manager.new_peak(
3288+
create_test_block_record(height=uint32(asserted_abs_height)), spent_coins
3289+
)
3290+
# We're not there yet (needs to be higher, not equal)
3291+
assert mempool_manager.get_mempool_item(sb_name, include_pending=False) is None
3292+
assert new_peak_info.items == []
3293+
else:
3294+
spent_coins = None
3295+
new_peak_info = await mempool_manager.new_peak(
3296+
create_test_block_record(height=uint32(asserted_abs_height + 1)), spent_coins
3297+
)
3298+
# The item gets retried successfully now
3299+
mi = mempool_manager.get_mempool_item(sb_name, include_pending=False)
3300+
assert mi is not None
3301+
assert new_peak_info.items == [NewPeakItem(sb_name, sb, mi.conds)]

0 commit comments

Comments
 (0)