Repository navigation
test(node): anvil e2e harness for on-chain PaymentChannel settlement (#745) - #752
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a live, anvil-backed end-to-end test suite for the on-chain PaymentChannel seller settlement path, gated behind a new anvil-e2e feature flag. It includes a test-only MintableUSDC mock contract and refactors the existing loopback tests by extracting shared test helpers into a new support module. The review feedback highlights several improvement opportunities: resolving a potential port-binding race condition when spawning anvil, replacing a hardcoded sleep with a robust synchronization mechanism, using a standard u64 instead of U256 for evm_increaseTime to ensure compatibility, and avoiding .expect in deploy_mock_usdc to prevent panics.
There was a problem hiding this comment.
Pull request overview
Adds an opt-in Anvil-backed Rust e2e test for live on-chain PaymentChannel seller settlement, covering voucher signature acceptance and event watcher decode paths that were previously only statically verified.
Changes:
- Adds
anvil-e2egated settlement lifecycle test and shared iroh/client-handler test helpers. - Refactors
client_loopback.rsto consume the shared support module. - Adds a mintable test USDC mock and wires a gated CI job into the required CI aggregate.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/node/tests/anvil_settlement_e2e.rs |
Adds live Anvil settlement e2e covering open, withdraw, close, settle, and watcher persistence transitions. |
crates/node/tests/support/mod.rs |
Extracts reusable paid-delivery loopback helpers for integration tests. |
crates/node/tests/client_loopback.rs |
Refactors existing loopback tests to use shared support helpers. |
crates/node/Cargo.toml |
Adds the opt-in anvil-e2e feature gate. |
contracts/test/mocks/MintableUSDC.sol |
Adds a test-only mintable 6-decimal USDC stand-in for the e2e harness. |
.github/workflows/ci.yml |
Adds gated Anvil e2e CI coverage and includes it in the aggregate CI gate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… artifact-read error - evm_increaseTime: pass a plain u64 (JSON number) instead of U256 (hex-quantity string), which not every EVM client accepts for that RPC. - deploy_mock_usdc: it returns Result, so propagate the artifact read/parse failures via map_err(...)?/ok_or_else instead of panicking with .expect. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Review — anvil e2e harness (#752)Reviewed the incremental diff against #743. The harness is solid — I verified 1. Fixed
|
…745) Stand up a live, gated end-to-end test (behind the `anvil-e2e` cargo feature, off by default) that closes the two runtime-only verification gaps called out in PR #743: 1. on-chain acceptance of the normalized voucher signature v-byte, and 2. live ChannelOpened/ChannelSettled event decode by PaymentChannelService. The test spawns anvil, deploys a mintable mock USDC + the full protocol via `forge script DeployProtocol.s.sol`, activates the node on-chain (stake + registerNode — the iroh ed25519 key signs the Ed25519Verifier ownership proof, the eth key signs the EIP-712 binding), brings up PaymentChannelService + a persistent store + ClientHandler in-process, then runs a real iroh paid delivery and asserts: the watcher persists the opened channel (closes the #327 WrongChannel gap), the threshold withdraw lands on-chain, FeeRouter.bytesPerEpoch increments, graceful-shutdown closeChannel moves the channel to Closing, and settleChannel after the dispute window is decoded and forgets the row. Supporting changes: - contracts: add test-only MintableUSDC (6-decimal, mintable) mock. - node tests: extract the shared iroh helpers into tests/support/mod.rs (client_loopback.rs now consumes it; behavior-preserving). - node: add the `anvil-e2e` feature (no new crate deps; anvil/forge run as subprocesses). - ci: add a gated `anvil-e2e` job (Rust + Foundry) wired into ci-success. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… artifact-read error - evm_increaseTime: pass a plain u64 (JSON number) instead of U256 (hex-quantity string), which not every EVM client accepts for that RPC. - deploy_mock_usdc: it returns Result, so propagate the artifact read/parse failures via map_err(...)?/ok_or_else instead of panicking with .expect. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… fields - The redeemer/watcher warn!s (on-chain revert reasons) are emitted from tokio worker threads; `with_test_writer` routes through libtest's thread-local capture set only on the main thread, so those cross-thread logs would be dropped. Write to process stderr instead (nextest captures it and shows it on failure) — restores the intended diagnostic on a withdraw/close timeout. - Assert the persisted channel 1's `client` and `deposit` match (free, non-flaky coverage that the watcher decoded ChannelOpened's non-indexed fields, not just the channelId topic). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…se/watcher comments Rebased onto main (#743 squash-merged the #327 settlement work this branch previously carried as duplicate commits); adapted the `bootstrap` call to main's added `pending_store` param by deriving both trait handles from the one `PersistentChannelStateStore`, mirroring the runtime wiring. - free_port TOCTOU: spawn anvil through a retry helper that detects an early exit (port stolen between probe and bind) and retries on a fresh port, with a per-port 20s readiness timeout. The child is owned by AnvilGuard immediately so every early return reaps it. - shutdown-close comment: corrected to state that `close_all_unredeemed` force-closes *every* still-Open channel with unredeemed work — channel 1 also closes when its single redeem lands the 1 MiB interval voucher (verified: the run logs `closed=2`), not just channel 2. - watcher readiness comment: corrected to reflect the four sequential `.watch()` filter installs (not one) and that the ordering is bridged by the sleep plus the intervening mint/approve roundtrips; a fully deterministic fix needs a prod-side readiness signal / get_logs fallback, out of scope here. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
a6b85c7 to
5b6295c
Compare
|
Addressed in 5b6295c (also rebased onto main — #743 squash-merged the #327 work this branch had carried as duplicate commits, so the diff is now just the 6 test/CI files; adapted the 3. 2. Shutdown closes all unredeemed channels, not just channel 2 — fixed (comment). You're right, and the test run proves it: it logs 1. Fixed I kept it a time-based wait rather than a signal/ |
Gas snapshotGas changes vs baseRun: 26759839277 |
Contracts coverageLine coverage: 87.49% (1693/1935 lines) |
Coverage reportTotal: 87.79% (was 87.79%, ● 0.00%) — 24331/27715 lines No coverage data for changed Rust files. History
|
Closes #745. Stacked on top of #743 (base branch
feat/327-paymentchannel-onchain-client), so this diff is only the e2e harness.Context
PR #743 implemented and statically verified the seller-side on-chain
PaymentChannelsettlement path, but two runtime-only behaviors were never exercised against a chain:v-byte — a real client-signed voucher accepted by the contract'sECDSA.recoverwhen the node submitswithdraw/closeChannel.PaymentChannelServicewatcher'sChannelOpened/ChannelSettledsubscribe+decode path against a live RPC.What's in this PR
A single gated
#[tokio::test](crates/node/tests/anvil_settlement_e2e.rs, behind theanvil-e2ecargo feature — off by default, so the normal test run stays fast and needs no Foundry). It:anvil, deploys a mintable mock USDC, then the full protocol viaforge script DeployProtocol.s.sol(addresses read from thedeployments/<chainId>.jsonmanifest);stake+registerNode; the iroh ed25519 key signs the productionEd25519Verifierownership proof, the eth key the EIP-712 binding);PaymentChannelService+PersistentChannelStateStore+ClientHandlerin-process;openChannel→ asserts the watcher decodesChannelOpenedand persists it (closes the documented Implement on-chain CapacityBond and PaymentChannel contract integration #327WrongChannelgap), runs a real iroh paid-delivery roundtrip, asserts the thresholdwithdrawlands on-chain andFeeRouter.bytesPerEpochincrements;closeChannel→Closing; after the dispute-window time-warp,settleChannel→ assertsChannelSettledis decoded and the row isforget-ten.Supporting changes
test/mocks/MintableUSDC.sol— test-only 6-decimal mintable USDC.tests/support/mod.rs;client_loopback.rsnow consumes it (behavior-preserving — 14 tests still pass).anvil-e2efeature flag (no new crate deps).anvil-e2ejob (Rust + Foundry toolchain) wired intoci-successneeds + allowed-skips.Verification
cargo clippy --features anvil-e2e -D warningsclean (and default);cargo fmt --checkclean.forge fmt --check,FOUNDRY_PROFILE=ci forge build --sizes --deny warnings,forge test(440 passed) all green.cargo nextest rununchanged — the e2e is#![cfg(feature = "anvil-e2e")].🤖 Generated with Claude Code