Skip to content

Commit b511704

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

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

chia/_tests/core/mempool/test_mempool_manager.py

Lines changed: 45 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,47 @@ 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(
3268+
"condition_and_error",
3269+
[
3270+
(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, Err.ASSERT_HEIGHT_RELATIVE_FAILED),
3271+
(ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, Err.ASSERT_HEIGHT_ABSOLUTE_FAILED),
3272+
],
3273+
)
3274+
@pytest.mark.parametrize("optimized_path", [True, False])
3275+
async def test_new_peak_txs_added(condition_and_error: tuple[ConditionOpcode, Err], optimized_path: bool) -> None:
3276+
"""
3277+
Tests that deferred transactions because of time-lock are retried once the
3278+
time-lock allows them to be reconsidered.
3279+
"""
3280+
coins = TestCoins([TEST_COIN], {})
3281+
mempool_manager = await setup_mempool(coins)
3282+
# Add an item that should go to the pending cache
3283+
assert mempool_manager.peak is not None
3284+
condition_height = mempool_manager.peak.height + 1
3285+
condition, expected_error = condition_and_error
3286+
sb, sb_name, result = await generate_and_add_spendbundle(mempool_manager, [[condition, condition_height]])
3287+
_, status, error = result
3288+
assert status == MempoolInclusionStatus.PENDING
3289+
assert error == expected_error
3290+
# Advance the mempool beyond the asserted height to retry the test item
3291+
if optimized_path:
3292+
spent_coins: Optional[list[bytes32]] = []
3293+
new_peak_info = await mempool_manager.new_peak(
3294+
create_test_block_record(height=uint32(condition_height)), spent_coins
3295+
)
3296+
# We're not there yet (needs to be higher, not equal)
3297+
assert mempool_manager.get_mempool_item(sb_name, include_pending=False) is None
3298+
assert new_peak_info.items == []
3299+
else:
3300+
spent_coins = None
3301+
new_peak_info = await mempool_manager.new_peak(
3302+
create_test_block_record(height=uint32(condition_height + 1)), spent_coins
3303+
)
3304+
# The item gets retried successfully now
3305+
mi = mempool_manager.get_mempool_item(sb_name, include_pending=False)
3306+
assert mi is not None
3307+
assert new_peak_info.items == [NewPeakItem(sb_name, sb, mi.conds)]

0 commit comments

Comments
 (0)