Skip to content

test: add DexSetup and FeeAmmSetup - #9382

Merged
0xrusowsky merged 7 commits into
mainfrom
rus/dex-amm-setups
Nov 16, 2026
Merged

0xrusowsky merged 7 commits into
mainfrom
rus/dex-amm-setups

Conversation

@0xrusowsky

Copy link
Copy Markdown
Contributor

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 approving U256::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::DexSetup and test_util::FeeAmmSetup, following TIP20Setup: a builder, apply() in the entered storage context, and calls() lowering to ABI calls in the same order. calls_match_apply now covers both.

  • DexSetup::new(admin).trader(user, amount).apply() creates BASE over pathUSD, mints amount of 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 through TipFeeManager::mint.

The DEX and fee AMM unit tests in tempo-precompiles, plus one evm handler test, use them. No test writes pools[..] 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:

  • Expected user reserves drop the old seeded reserve: 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).
  • Larger amounts where the old pools were below the mint minimum: test_execute_fee_swap first case 1_000 → 10_000 liquidity; test_execute_fee_swap_insufficient_liquidity 100/200 → 10000/20000; test_collect_fee_pre_tx_insufficient_liquidity 100 reserve / 1000 fee → 5000 / 10000; test_collect_fee_pre_tx_two_hop_no_side_effects fee 1_000 → 10_000 and "2nd hop too small" 50 → 5_000; test_two_hop_reservation_blocks_mid_tx_burn_on_both_hops fee 1_000 → 10_000, since a full burn now leaves the locked minimum.
  • test_two_hop_intermediate_does_not_survive_across_tx no longer drains the hop pools for tx2 (mint can't empty a pool); its collected_fees == out2 + out_single assertion still catches a stale route.
  • test_add_liquidity, test_burn* and test_mint_subsequent_deposit read the first deposit's LP from liquidity_balances instead of mint'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.rs fixture (fixed salts, per-version pair hardforks), and the raw pool slot in evm.rs's gas-snapshot test.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Changelog not found.

A changelog entry is required before merging. We've generated a suggested changelog based on your changes:

Preview
---
tempo-contracts: patch
---

Moved the stablecoin DEX, fee manager, and EVM handler tests onto the shared `DexSetup` and `FeeAmmSetup` test helpers in place of hand-written token setup. Only test code changed.

Add changelog to commit this to your branch.

@0xrusowsky
0xrusowsky marked this pull request as ready for review November 16, 2026 13:42
@tempoxyz-bot

tempoxyz-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Cyclops Security Review: safe to merge

✅ Reviewed 2cfe48d (latest) · Coverage: full · no open findings · report
ℹ️ Not verifiable from the source alone (needs running code or deployed state): The offline, locked invocation of test_util::calls::tests::calls_match_apply failed before compilation because Cargo could not check out pinned inkwell revision c9d9734ae17dbaf1d9902dab3b8ee9d2041781f

joshieDo
joshieDo previously approved these changes Nov 16, 2026
@0xrusowsky
0xrusowsky added this pull request to the merge queue Nov 16, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread crates/precompiles/src/test_util.rs Resolved
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 16, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new blocking issues. 1 optional suggestion (a nit or a note on pre-existing code) was found and not posted. Nothing in this review needs a push before merging.

@0xrusowsky
0xrusowsky enabled auto-merge November 16, 2026 15:33
@0xrusowsky
0xrusowsky added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit fd63096 Nov 16, 2026
95 checks passed
@0xrusowsky
0xrusowsky deleted the rus/dex-amm-setups branch November 16, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants