Skip to content

v4 test prototype#429

Merged
liquid-8 merged 5 commits intouniswap-python:dev/v4-finfrom
liquid-8:uniswap4_RC
Mar 19, 2026
Merged

v4 test prototype#429
liquid-8 merged 5 commits intouniswap-python:dev/v4-finfrom
liquid-8:uniswap4_RC

Conversation

@liquid-8
Copy link
Member

No description provided.

@greptile-apps
Copy link

greptile-apps bot commented Mar 19, 2026

Greptile Summary

This PR adds a new manual test script for the Uniswap v4 integration (tests/v4tests.py) and makes a one-line correction to estimate_price_impact in uniswap/uniswap4.py. The production-code change introduces an inconsistency in how token addresses are converted before being passed to get_token, and the test file has a copy-paste output bug plus several portability issues.

Key findings:

  • _str_to_addr inconsistency in estimate_price_impact (uniswap4.py:1487): _str_to_addr() was removed from the token0 call but left in place for token1. Because _load_contract is decorated with @functools.lru_cache() and uses the raw argument as a cache key before converting it, passing a str for one token and Address bytes for the other can produce duplicate cache entries for the same contract. Every other get_token call in the file wraps the argument in _str_to_addr first — this change deviates from that pattern.
  • Wrong variable printed in state_view_tests (v4tests.py:227): the slot0 sub-test prints test_result (from the previous liquidity call) instead of test_result1, silently displaying incorrect output.
  • Hardcoded developer-specific absolute paths (v4tests.py:20, 36): paths like /home/yohan/src/Uniswap/... will fail on any other machine or in CI.
  • Hardcoded RPC endpoint and wallet address: the __main__ block hard-codes a public RPC URL and a specific wallet address, making this unsuitable for CI without parameterization.

Confidence Score: 3/5

  • Not ready to merge — the production fix has a type inconsistency that can silently corrupt the lru_cache, and the test file has a copy-paste output bug and non-portable paths.
  • The production change is a single line that could work at runtime due to Web3.to_checksum_address accepting strings, but it creates an lru_cache key inconsistency that can cause hard-to-diagnose performance regressions. The test file is prototype-level quality with a wrong-variable bug, hardcoded developer paths, and hardcoded credentials — it cannot run unmodified on any other machine.
  • uniswap/uniswap4.py line 1487 (lru_cache key inconsistency) and tests/v4tests.py lines 20, 36, 227 (hardcoded paths, wrong variable).

Important Files Changed

Filename Overview
uniswap/uniswap4.py Single-line fix to estimate_price_impact: removes _str_to_addr() wrapper from the token0 call to get_token, but leaves token1 still wrapped — creating an asymmetry that can cause duplicate lru_cache entries in _load_contract and violates the established codebase pattern.
tests/v4tests.py New manual test script for Uniswap v4; contains a copy-paste bug where test_result is printed instead of test_result1 for the slot0 test, hardcoded developer-specific absolute file paths, and hardcoded public RPC endpoint and wallet address — making the file non-portable and unsuitable for CI as-is.

Sequence Diagram

sequenceDiagram
    participant T as Test Script
    participant U4 as Uniswap4
    participant Q as QuoterV2 Contract
    participant SV as StateView Contract
    participant LC as _load_contract (lru_cache)

    T->>U4: estimate_price_impact(token0, token1, qty)
    U4->>U4: get_token_token_spot_price(token0, token1)
    U4->>Q: getQuoteExactInputSingle(...)
    Q-->>U4: quote_amount
    U4->>U4: get_token(token0) ← str passed (no _str_to_addr)
    U4->>LC: _load_contract(w3, "erc20", "0xABC..." str key)
    Note over LC: Cache miss – different key type than Address bytes
    LC-->>U4: contract
    U4->>U4: get_token(_str_to_addr(token1)) ← Address bytes
    U4->>LC: _load_contract(w3, "erc20", b'\xAB\xC...' bytes key)
    LC-->>U4: contract
    U4-->>T: price_impact_real

    T->>U4: get_liquidity_stateview(token0, token1, fee, tick_spacing, hooks)
    U4->>SV: getLiquidity(poolId)
    SV-->>U4: liquidity
    U4-->>T: test_result

    T->>U4: get_slot0_stateview(token0, token1, fee, tick_spacing, hooks)
    U4->>SV: getSlot0(poolId)
    SV-->>U4: slot0 data (test_result1)
    U4-->>T: test_result1
    Note over T: BUG: prints test_result instead of test_result1
Loading

Last reviewed commit: "v4 test prototype"

liquid-8 and others added 4 commits March 20, 2026 00:33
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@liquid-8 liquid-8 merged commit 4d08576 into uniswap-python:dev/v4-fin Mar 19, 2026
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.

1 participant