Skip to content

test(v4): poll Anvil startup instead of a fixed sleep - #486

Merged
ErikBjare merged 2 commits into
uniswap-python:masterfrom
TimeToBuildBob:fix/anvil-startup-poll
Oct 13, 2026
Merged

ErikBjare merged 2 commits into
uniswap-python:masterfrom
TimeToBuildBob:fix/anvil-startup-poll

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Summary

Both v4 test modules start anvil and then sleep(3) before connecting. On a slow fork 3s is not enough and the matrix fails with ConnectionRefusedError; on a fast machine it wastes time; and when anvil dies at genesis the fixture still waits out the sleep and then fails on the connection instead of the real cause.

This replaces the sleep in tests/test_uniswap4.py and tests/test_v4_examples.py with a bounded poll of the RPC port (up to 60s) that fails immediately with the exit code if the process exits first and kills it on timeout. No behaviour change once anvil is up; the fixture just stops guessing.

The same fixture change ran green on the v1–v4 matrix on my fork (TimeToBuildBob#1, since closed because it was bundled with the v1 xfail that #479 declined). Only the two fixture files change here.

Test plan

  • ruff check / ruff format --check and the repo pre-commit hooks pass on both files
  • pytest --collect-only collects all 96 tests in the two modules
  • v4 mainnet matrix green on CI (no local anvil/PROVIDER here)

Both v4 test modules started anvil and then slept 3 seconds before
connecting. On a slow fork that is not enough and the matrix fails with
ConnectionRefusedError; on a fast machine it wastes time; and when anvil
dies at genesis the fixture still waits out the sleep and then fails on
the connection instead of the real cause.

Poll the RPC port for up to 60s, fail immediately with the exit code if
the process exits first, and kill it on timeout.

Git-Session-Id: 9d44438c-8705-491c-9930-947968df9a94
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.26%. Comparing base (43420bc) to head (44371ed).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #486   +/-   ##
=======================================
  Coverage   73.26%   73.26%           
=======================================
  Files          12       12           
  Lines        2319     2319           
=======================================
  Hits         1699     1699           
  Misses        620      620           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Low impact] Test setup replaces fixed sleep with connection polling.

The PR appears safe to merge, with non-blocking improvements to timeout cleanup and elapsed-time measurement.

Findings

  1. P2 Timeout skips child cleanup ▶
  2. P2 Clock changes alter the wait ▶

Summary

Both V4 test modules replace the fixed startup sleep with a connection poll.

  • The v4 test fixtures wait for Anvil to accept connections.

Reviews (1) · Last reviewed commit: "test(v4): poll Anvil startup instead of ..." · Reviewed by Greptile

Comment thread tests/test_uniswap4.py
Comment thread tests/test_uniswap4.py Outdated
Git-Session-Id: 0fead8e2-e37e-58e4-b158-56598d831c9d
@ErikBjare
ErikBjare merged commit aa2c09a into uniswap-python:master Oct 13, 2026
6 checks passed
TimeToBuildBob added a commit to TimeToBuildBob/uniswap-python that referenced this pull request Oct 14, 2026
- Restore @check_approval on make_trade/make_trade_output/add_liquidity/
  remove_liquidity (P1: first token trades fail without router allowance)
- Remove path overwrite after cost calculation in V2 exact-output branch
  (P1: custom route was silently replaced with default WETH route)
- Raise ValueError when V3 route is given without fees in get_price and
  make_trade (P1: incomplete routes silently fell back to single-pool quote)
- Fix async client init to derive provider URL from supplied AsyncWeb3
  so PROVIDER env var is not required when web3 is given (P1)
- Add asyncio.Lock (_nonce_lock) in AsyncUniswap4 and reserve nonce
  inside the lock before yielding to prevent concurrent trades sharing
  a nonce (P1)
- Remove incorrect await on bytes32 _name.decode()/_symbol.decode() in
  AsyncUniswap4.get_token — decode() returns str, not awaitable (P2)
- Restore Anvil startup readiness poll in test_uniswap4.py fixture,
  replacing sleep(3) that was reverted from uniswap-python#486 (P2)
- Cache get_weth_address result per client instance to avoid repeated
  RPC calls on every quote/swap path (P2)

Co-Authored-By: Bob <bob@superuserlabs.org>
Git-Session-Id: d44b7f42-192e-588b-98db-435d6ad11d1c
ErikBjare pushed a commit that referenced this pull request Oct 14, 2026
…(clean branch) (#491)

* feat(v4): UF grant work — async clients, ReservesLens, CI/test fixes

Clean branch off master containing liquid-8's changes from dev/v4-fin:
- Async Uniswap v2/v3/v4 clients (asyncuniswap.py, asyncuniswap4.py)
- ReservesLens support and getPoolTVLBatch improvements
- Universal Router and single/multi-hop swap fixes
- Test suite fixes (RPC switch, Anvil startup, fixture fixes)
- Adoption metrics snapshot script + daily workflow (UF grant D3/D4)
- README updates

Clean squash of dev/v4-fin changes reapplied on top of current master,
resolving the 244-commit ancestry confusion from the original v4-fin
squash merge (4c42f1f). Also fixes duplicate Generator import in
tests/test_uniswap.py (ruff F811).

Git-Session-Id: 15b18137-18fa-53a4-92e2-759ce27705c7

* fix: address Greptile P1/P2 findings from review

- Restore @check_approval on make_trade/make_trade_output/add_liquidity/
  remove_liquidity (P1: first token trades fail without router allowance)
- Remove path overwrite after cost calculation in V2 exact-output branch
  (P1: custom route was silently replaced with default WETH route)
- Raise ValueError when V3 route is given without fees in get_price and
  make_trade (P1: incomplete routes silently fell back to single-pool quote)
- Fix async client init to derive provider URL from supplied AsyncWeb3
  so PROVIDER env var is not required when web3 is given (P1)
- Add asyncio.Lock (_nonce_lock) in AsyncUniswap4 and reserve nonce
  inside the lock before yielding to prevent concurrent trades sharing
  a nonce (P1)
- Remove incorrect await on bytes32 _name.decode()/_symbol.decode() in
  AsyncUniswap4.get_token — decode() returns str, not awaitable (P2)
- Restore Anvil startup readiness poll in test_uniswap4.py fixture,
  replacing sleep(3) that was reverted from #486 (P2)
- Cache get_weth_address result per client instance to avoid repeated
  RPC calls on every quote/swap path (P2)

Co-Authored-By: Bob <bob@superuserlabs.org>
Git-Session-Id: d44b7f42-192e-588b-98db-435d6ad11d1c

* fix(typecheck): remove unused type: ignore[return-value] on get_weth_address

_weth_address_cache is typed as ChecksumAddress (same as return type),
so the ignore comment is now redundant and mypy correctly flags it.

Git-Session-Id: c95ac4a4-64bd-42b3-9f79-c55ca4dfb9cf
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.

2 participants