Repository navigation
test: add DexSetup and FeeAmmSetup - #9382
Merged
Merged
Conversation
Contributor
|
0xrusowsky
marked this pull request as ready for review
November 16, 2026 13:42
0xrusowsky
requested review from
0xKitsune,
joshieDo,
klkvr,
legion2002,
mattsse,
rakita and
shekhirin
as code owners
November 16, 2026 13:42
Contributor
✅ Cyclops Security Review: safe to merge✅ Reviewed 2cfe48d (latest) · Coverage: full · no open findings · report |
joshieDo
previously approved these changes
Nov 16, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 16, 2026
0xrusowsky
enabled auto-merge
November 16, 2026 15:33
joshieDo
approved these changes
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
DEX and fee AMM tests each built their own tokens, pairs and pools: 40 callers of a local
setup_test_tokens, inline mint/approve blocks approvingU256::MAX, and fee AMM tests writing pool reserves and LP supply straight into storage. Those writes can produce pools no provider could reach, and MAX approvals hide an escrow that pulls too much.Solution
Add
test_util::DexSetupandtest_util::FeeAmmSetup, followingTIP20Setup: a builder,apply()in the entered storage context, andcalls()lowering to ABI calls in the same order.calls_match_applynow covers both.DexSetup::new(admin).trader(user, amount).apply()creates BASE over pathUSD, mintsamountof both to each trader with an exact approval to the DEX, and creates the pair unless.without_pair().FeeAmmSetup::new(admin).liquidity(provider, amount).apply()creates a USD user token and validator token and adds liquidity only throughTipFeeManager::mint.The DEX and fee AMM unit tests in
tempo-precompiles, plus one evm handler test, use them. No test writespools[..]directly anymore; tests that need user-side reserves reach them through a fee swap. MAX approvals in the migrated DEX tests became exact, and unused MAX approvals to the fee manager (fee collection checks no allowance) were dropped.Test inputs and assertions that changed
Mint-only pools start with zero user reserve, and mint requires more than
2 * MIN_LIQUIDITY:test_execute_fee_swap,test_multiple_consecutive_fee_swaps,test_collect_fee_pre_tx_different_tokens(10000 → 0),test_collect_fee_post_tx_immediate_swap(10000 + 800 → 800), the two-hop compound-fee and route-immutability tests (reserve + x→x), and the untouched direct pool(1, 0)→(0, 0).test_execute_fee_swapfirst case 1_000 → 10_000 liquidity;test_execute_fee_swap_insufficient_liquidity100/200 → 10000/20000;test_collect_fee_pre_tx_insufficient_liquidity100 reserve / 1000 fee → 5000 / 10000;test_collect_fee_pre_tx_two_hop_no_side_effectsfee 1_000 → 10_000 and "2nd hop too small" 50 → 5_000;test_two_hop_reservation_blocks_mid_tx_burn_on_both_hopsfee 1_000 → 10_000, since a full burn now leaves the locked minimum.test_two_hop_intermediate_does_not_survive_across_txno longer drains the hop pools for tx2 (mint can't empty a pool); itscollected_fees == out2 + out_singleassertion still catches a stale route.test_add_liquidity,test_burn*andtest_mint_subsequent_depositread the first deposit's LP fromliquidity_balancesinstead ofmint's return value.Not migrated: the node RPC tests (they test mint/burn themselves or use the genesis pathUSD as validator token), the
stablecoin_dex/order/storage.rsfixture (fixed salts, per-version pair hardforks), and the raw pool slot inevm.rs's gas-snapshot test.