refactor(tests): replace ganache with anvil for v1–v3 tests - #472
Conversation
Ganache is an npm-maintained tool that has fallen behind foundry's anvil in maintenance and compatibility. Anvil is already used for v4 tests (test_uniswap4.py) and is installed via the foundry-toolchain GitHub Action in CI. - Replace GanacheInstance with AnvilInstance in tests/test_uniswap.py - Swap the ganache fixture for an anvil fixture (same port 10999, Foundry's default test mnemonic account uniswap-python#9 instead of ganache's --wallet.seed account) - Remove `npm install -g ganache@7.5.0` and Node setup from CI workflow - Update README to reference Anvil/Foundry instead of ganache-cli
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #472 +/- ##
==========================================
+ Coverage 63.49% 73.19% +9.70%
==========================================
Files 12 12
Lines 2309 2309
==========================================
+ Hits 1466 1690 +224
+ Misses 843 619 -224 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Greptile SummaryStandardizes the v1–v3 test suite on Anvil.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains, and both previously reported Foundry PATH setup issues are fixed by exporting the installation directory before running Important Files Changed
Reviews (6): Last reviewed commit: "test: re-add xfail for v1 token-to-ETH (..." | Re-trigger Greptile |
|
CI update: v1 test failures ( and ) are due to Anvil's strict EVM handling of the old Vyper-compiled Uniswap v1 exchange contracts — specifically an For context: master CI is also currently red (unrelated v3 The v2, v3, v4 jobs all pass. The Greptile review passed. I'll follow up to investigate the v1 Anvil compatibility issue separately — either by adding |
|
"For context: master CI is also currently red (unrelated v3 test_get_tvl_in_pool_on_chain failure), so neither base nor head are fully green right now" |
|
@greptileai review |
|
You're right — the The remaining blocker here is the reproducible v1 failure under Anvil. I'm investigating that path rather than treating the intermittent v3 failure as related. |
|
@greptileai review |
|
@greptileai review |
Maybe we should drop v1 tests. This version of the protocol is deprecated; no one will touch this part of the codebase ever again. Not sure if there is any sense in keeping these tests and spending resources on maintaining them. |
…idJump web3.py calls eth_estimateGas internally during build_transaction when no gas field is present in tx_params. Anvil's strict EVM rejects this for Vyper v1 exchange contracts with EVM error InvalidJump (computed jump tables used by old Vyper don't pass strict JUMPDEST validation during simulation). The existing use_estimate_gas=False path set a 250k gas fallback AFTER build_transaction had already made — and failed — the estimateGas call. Fix: pre-populate gas in tx_params before calling build_transaction when use_estimate_gas=False, so web3's internal estimate is never triggered.
|
Fix for v1 Root cause: web3.py calls Anvil's EVM correctly rejects Fix: pre-populate v2/v3 are unaffected — they use modern Solidity contracts where |
|
@greptileai review |
|
@liquid-8 Agreed — and the CI confirms it. My fix in e792149 addressed gas estimation ( Dropping v1 tests is the right call:
Happy to implement it: remove |
Anvil's revm enforces strict JUMPDEST validation, which rejects the computed jump tables used by old Vyper-compiled Uniswap v1 exchange contracts in the tokenToEth code path (EvmError: InvalidJump). Ganache was more permissive and executed these without error. The ETH-to-token direction works fine; only token-to-ETH triggers the incompatibility. Mark the two failing test cases as xfail so CI is green while keeping the test coverage visible.
|
Pushed Why xfail instead of waiting: the two token-to-ETH failures are a hard EVM incompatibility (Anvil's revm correctly rejects Vyper v1 computed jump tables in the execution path, not just estimation), so there's no in-PR fix that makes them pass. |
I took a look at the logs for e792149; it seems that failed transactions just ran out of gas. It's worth mentioning that I faced similar issues while testing v4. Could you try setting a higher gas limit, like 500k or something? |
liquid-8 observed out-of-gas in the e792149 CI run rather than a hard InvalidJump at execution. Raise the no-estimate-gas fallback from 250k to 500k — the same direction that resolved similar v4 gas issues — and remove the xfail marks so CI validates the fix directly. If this run still fails, the root cause is confirmed as an EVM bytecode incompatibility rather than insufficient gas, and the xfail approach is the right interim.
|
Good catch — you're right that the logs for e792149 show out-of-gas rather than a hard Pushed 01697f7: raises the |
It still consumes a whole gas limit, which is ridiculous at this point. We have to either use your |
500k gas still hits InvalidJump — it's not a gas issue. Anvil's strict revm rejects the non-standard JUMP patterns in Uniswap v1 Vyper 0.1.x bytecode; Ganache was permissive about these. Gas increase cannot fix this class of failure. xfail on `client.version == 1 and output_token == ETH_ADDRESS` in both test_make_trade and test_make_trade_output, with an explicit reason string pointing at the deprecation track.
|
Pushed With 500k gas, the v1 token-to-ETH transaction still reverts with Root cause: Uniswap v1 Exchange contracts are Vyper 0.1.x bytecode that Ganache's EVM tolerated (it was more permissive about JUMP destinations). Anvil's I've reverted to |
|
@greptileai review |
Summary
Follows up on #471 (v4 docs + example tests), which already used Anvil for
test_uniswap4.py. This PR standardises the whole test suite on the same tool.tests/test_uniswap.py: replaceGanacheInstance/ganachefixture withAnvilInstance/anvilfixture. Same port (10999), same startup/teardown pattern, Foundry default test-mnemonic account Bump bleach from 3.0.2 to 3.1.4 #9 (the same account used intest_uniswap4.py)..github/workflows/test.yml: removenpm install -g ganache@7.5.0and the now-redundantSet up Nodestep. Foundry is already installed viafoundry-rs/foundry-toolchain@v1.README.md: replace ganache-cli install instructions with Foundry install (curl -L https://foundry.paradigm.xyz | bash && foundryup).Why
Test plan
UNISWAP_VERSION=1 PROVIDER=<mainnet_rpc> pytest tests/test_uniswap.py -vpassesUNISWAP_VERSION=2 PROVIDER=<mainnet_rpc> pytest tests/test_uniswap.py -vpassesUNISWAP_VERSION=3 PROVIDER=<mainnet_rpc> pytest tests/test_uniswap.py -vpasses