Skip to content

test(node): anvil e2e harness for on-chain PaymentChannel settlement #745

Closed

Description

@thiras

Context

Split out from #327 (PR #743). The seller-side on-chain PaymentChannel settlement path is implemented and statically verified (build, clippy -D warnings, 1264 unit/integration tests, cargo deny, and bindings cross-checked against the compiled ABI). What's not covered is a live end-to-end run against a chain — there is no existing anvil/forge integration harness for the Rust node (no alloy node-bindings dev-dep, no anvil test infra).

Two runtime-only behaviors remain unverified by the static checks:

  1. On-chain acceptance of the normalized voucher signature v-byte (normalize_voucher_signature maps 0/1 → 27/28 for ECDSA.recover).
  2. Live event decode at runtime (ChannelOpened / ChannelSettled / ChannelCloseInitiated) — the ABI cross-check substitutes for the layout but doesn't exercise the actual subscription/decode path.

Scope

Stand up an anvil-backed e2e (gated/ignored or behind a feature so default CI stays fast):

  • Deploy CapacityBond + PaymentChannel + FeeRouter to a local anvil via the Foundry deploy scripts (script/DeployProtocol.s.sol / BaseProtocolDeploy.s.sol), wiring the USDC + roles.
  • Bring up a decdn-node pointed at the anvil RPC with a real keystore/identity and the resolved blockchain config.
  • From a test client: openChannel against the node → assert the node persists the channel and now accepts a voucher (closes the prior WrongChannel path).
  • Push vouchers past redeem_threshold_micro_usdc → assert an on-chain withdraw lands and getChannel().withdrawnAmount advances.
  • Trigger graceful shutdown with an un-redeemed claim → assert closeChannel fires; settleChannel after the dispute window → assert ChannelSettled is observed and store.forget drops the row.
  • Confirm FeeRouter.bytesPerEpoch increments (settlement routed correctly).

Notes

Activity

  1. self-assigned this
    on May 31, 2026
  2. added
    prio:high
    rust
    kind:test
    on May 31, 2026
  3. github-actions commented on May 31, 2026

    @github-actions

    🎯 Triage report

    This issue tracks standing up an anvil-backed end-to-end test harness for the PaymentChannel Rust settlement path, split out from #327 (PR #743). The static verification is complete (1264 tests, ABI cross-check); what remains are two runtime-only gaps: v-byte normalization acceptance by the on-chain ECDSA.recover and live event subscription/decode. The scope is well-defined with a concrete step-by-step checklist and explicit gating strategy for CI.

    📊 Assessment

    Dimension Value Reasoning
    Type Task This is a testing/infrastructure task — no new feature or bug; purely verification work
    Labels testing, rust, technical, high Rust incentive crate, test infrastructure, high priority as it closes a known verification gap in the payment path
    Coding agent Suitable Requirements are precise and enumerated; anvil + Foundry toolchain and deploy scripts exist; success criteria are explicit assertions; self-contained within the incentive / node crates

    🔗 Similar issues

    💡 Notes and suggestions

    Key verification gaps to close:

    1. v-byte normalization (normalize_voucher_signature 0/1 → 27/28): write a forge test first to confirm the Solidity ECDSA.recover accepts both raw and normalized forms, then mirror in the Rust e2e with alloy's LocalSigner.

    2. Live event subscription/decode: the ChannelOpened / ChannelSettled / ChannelCloseInitiated subscriptions should be tested against a real anvil log stream — static ABI layout checks don't cover the alloy eth_subscribe / getLogs decode path.

    Suggested implementation approach:

    crates/incentive/tests/e2e_payment_channel.rs  (or node/tests/)
    
    • Use tokio::process::Command to spawn anvil --silent in-process (or anvil_instance crate).
    • Use alloy::providers::ext::AnvilApi to snapshot/revert state between test cases.
    • Deploy via forge script script/DeployProtocol.s.sol --broadcast --rpc-url $ANVIL_RPC OR port the deploy logic to Rust using alloy's ContractFactory (the latter avoids a subprocess dependency in CI).
    • Gate the test with #[ignore = "requires-anvil"] and add a separate CI job: cargo nextest run --ignored -p decdn-incentive with foundry-rs/foundry-toolchain action.

    Test sequence checklist:

    • Spawn anvil, deploy CapacityBond + PaymentChannel + FeeRouter + mock USDC
    • Register and bond operator; fund client wallet with USDC
    • openChannel → assert node ChannelStore row created, vouchers now accepted
    • Submit vouchers past redeem_threshold_micro_usdc → assert withdraw tx lands, withdrawnAmount advances
    • Graceful node shutdown with un-redeemed claim → assert closeChannel fired
    • Advance anvil time past dispute window, call settleChannel → assert ChannelSettled event decoded, store.forget drops row
    • Assert FeeRouter.bytesPerEpoch incremented

    CI consideration: the job should be continue-on-error: false but only run on non-draft PRs touching crates/incentive/** or contracts/** to keep default CI fast.

    Generated by Agentic Triage for issue #745 · sonnet46 428.1K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:testprio:highrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions