chore(testing): add Anvil-based EVM integration harness - #231
Open
Markodiba wants to merge 1 commit into
Open
Conversation
Gives EVM work the local-devnet story Stellar already has via StellarNetwork::Standalone, with per-test isolated instances on random ports and deterministic funded accounts. Exposes anvil_snapshot/anvil_revert so reorg handling (Octo-Protocol-org#222) is testable at all -- a reorg cannot be induced on a public testnet on demand. Skips cleanly when Foundry is absent so `just test` stays green. The upstream evm-rpc client (Octo-Protocol-org#218) doesn't exist yet, so this lands as a standalone octo-evm-test-support crate per the issue's own fallback ("or a small test-support crate if Octo-Protocol-org#221/Octo-Protocol-org#224 also need it") rather than under crates/evm-rpc/tests/common. Refs Octo-Protocol-org#219 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
Implements issue #219 (doc
Issue #7indocs/ethereum-expansion-issues.md): a local Anvil(Foundry) devnet harness for EVM integration tests, giving EVM work the same local-devnet story
Stellar already has via
StellarNetwork::Standalone(
crates/wallet-core/src/signer.rs).octo-evm-test-supportcrate (crates/evm-test-support):AnvilInstance: spawnsanvil --port 0per test (random free port, own process), parses thereal bound port from its startup banner, confirms readiness by polling
eth_chainId, andkills the process in
Drop— including on panic, sinceDropruns during unwind.MockErc20: deploys a constructor-configurable-decimalsERC-20(
contracts/MockERC20.sol, precompiled bytecode checked in ascontracts/MockERC20.binsoonly
anvil, notsolc, needs to be onPATH), withmint/transfer/balance_ofhelpersthat produce real
Transferlogs.snapshot()/revert_to(id)(anvil_snapshot/anvil_revert),mine(n)(
evm_mine),set_base_fee(wei)(anvil_setNextBlockBaseFeePerGas) — the primitive feat(ingest): Confirmation depth and reorg handling for EVM deposits #222(reorg handling) depends on, since a reorg can't be induced on demand on a public testnet.
gate()mirrors theOCTO_LIVE_TESTSpattern incrates/api/tests/horizon_live_tests.rs: tests skipcleanly (not fail) unless
OCTO_EVM_TESTS=1andanvilis onPATH, sojust teststaysgreen with no Foundry installed.
just test-evmrecipe; CI installs Foundry (foundry-rs/foundry-toolchain@v1) and runs it.CONTRIBUTING.md: documents the optional Foundry install.Scope note: the issue says "Depends on #218" (
octo-evm-rpc, the resilient typed JSON-RPCclient) and suggests
crates/evm-rpc/tests/common/anvil.rs, but neithercrates/evm-core(#217)nor
crates/evm-rpc(#218) exist in this repo yet. The issue itself anticipates this and offers afallback — "or a small test-support crate if #221/#224 also need it" — which is what this PR does:
a standalone crate with its own minimal JSON-RPC client (
src/rpc.rs, just enough to drive Anvil,including the HTTP-200-with-
error-member check #218 will also need) and no dependency onunbuilt crates. Transactions go through plain
eth_sendTransactionagainst Anvil's pre-unlockeddefault accounts (derived from Anvil's own default deterministic mnemonic — no
--mnemonicflagneeded), so no client-side secp256k1 signing dependency was pulled in; that's #217/#218's job, not
this harness's.
Test plan
cargo build --workspaceandcargo test --workspace— new crate's tests skip cleanly withno
OCTO_EVM_TESTS/no Foundry, rest of the workspace unaffected.just test-evm(Foundry installed locally) — all pass:anvil_boots_and_mining_advances_the_chain— boots Anvil,mine(3), assertseth_blockNumberadvances by exactly 3.snapshot_and_revert_undoes_a_mined_transfer— deploysMockErc20, mines aTransfer,snapshots, mines more, reverts, asserts the transfer's receipt is gone — the reorg proof feat(ingest): Confirmation depth and reorg handling for EVM deposits #222
needs.
mock_erc20_supports_usdc_dai_and_zero_decimal_configs— exercises 6/18/0 decimals end to end.drop_kills_the_anvil_process_even_when_the_test_panics(#[cfg(unix)]) — panics insidecatch_unwindwith the instance moved in, then confirms viakill -0that the process isdead.
suite_skips_cleanly_when_the_env_var_is_unsetplus deterministic unit tests of the skippredicate in
src/lib.rs(noPATH/env mutation, so no flakiness under parallel tests).anvilprocesses after a full test run (pgrep anvil).cargo fmt --all -- --check,cargo clippy -p octo-evm-test-support --all-targets -- -D warnings.cast keccak(Foundry) for the standardERC-20 signatures.
closes #219