Skip to content

Commit 9d1a7b9

Browse files
authored
CHIA-3706 Cover new peak returning added transactions as a result of retrying potential transactions (#20002)
Add a test to cover new peak returning added transactions as a result of retrying potential transactions.
1 parent 38881d8 commit 9d1a7b9

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

0 commit comments

Comments
 (0)