|
41 | 41 | QUOTE_BYTES,
|
42 | 42 | QUOTE_EXECUTION_COST,
|
43 | 43 | MempoolManager,
|
| 44 | + NewPeakItem, |
44 | 45 | TimelockConditions,
|
45 | 46 | can_replace,
|
46 | 47 | check_removals,
|
@@ -3265,3 +3266,47 @@ async def test_different_ff_versions() -> None:
|
3265 | 3266 | latest_singleton_lineage2 = new_mi2.bundle_coin_spends[version2_id].latest_singleton_lineage
|
3266 | 3267 | assert latest_singleton_lineage2 is not None
|
3267 | 3268 | 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