Skip to content

test(surfpool): native cargo runner via build.rs + per-IDL macro#285

Draft
shahan-khatchadourian-anchorage wants to merge 2 commits intoshahankhatch/surfpool_testingfrom
shahankhatch/surfpool-rust-runner
Draft

test(surfpool): native cargo runner via build.rs + per-IDL macro#285
shahan-khatchadourian-anchorage wants to merge 2 commits intoshahankhatch/surfpool_testingfrom
shahankhatch/surfpool-rust-runner

Conversation

@shahan-khatchadourian-anchorage
Copy link
Copy Markdown
Contributor

Summary

Stacked on #202. Replaces the bash runner (scripts/surfpool_fuzz_all_idls.sh) with a native Rust setup so cargo test itself enumerates the per-IDL roundtrip tests.

  • chain_parsers/visualsign-solana/build.rs runs cargo metadata at build time, locates solana_parser's IDL directory (the one matching the rev in Cargo.lock), and emits it as cargo:rustc-env=SOLANA_IDL_DIR. Tests pick it up via env!() — no runtime cargo invocation.
  • A macro_rules! macro in tests/surfpool_fuzz.rs generates one #[tokio::test] per IDL (surfpool_idl_<name>). Cargo's harness handles enumeration, parallelism, pass/fail counts, and per-test failure diagnostics — the things the bash script was reimplementing.
  • The surfpool test path now distinguishes the three failure modes (decode rejected, no instructions, missing discriminator) with messages that name the IDL file. Previously a malformed IDL produced a misleading "no discriminator" panic.
  • collision.json and cyclic.json are excluded: they're solana_parser's negative test fixtures (duplicate type names / cyclic type refs) intentionally rejected by decode_idl_data.

CI change

The workflow drops the bash invocation and runs:

cargo test -p visualsign-solana --test surfpool_fuzz -- --ignored --test-threads=1

--test-threads=1 serialises surfpool spawns so each test owns its mainnet fork.

Documentation

Adds a Testing Patterns bullet in CLAUDE.md covering the macro-based pattern and how to add a new IDL.

Test plan

Why this PR

Addresses the third-party reviewer comment from #202 ("you might be able to do all this in Rust itself"). The narrow interpretation was already done there via the idl-meta Rust tool; this PR closes the loop by removing the bash orchestrator entirely.

🤖 Generated with Claude Code

Replaces the bash runner (`scripts/surfpool_fuzz_all_idls.sh`) with a
fully native Rust setup:

- `build.rs` runs `cargo metadata` once, locates `solana_parser`'s IDL
  directory (matching the rev in `Cargo.lock`), and emits it as
  `cargo:rustc-env=SOLANA_IDL_DIR`. Tests pick it up via `env!()` with
  no runtime cargo invocation.

- A `macro_rules!` macro generates one `#[tokio::test]` per IDL
  (`surfpool_idl_<name>`). Cargo's harness handles enumeration,
  parallelism, pass/fail counts, and per-test failure output -- the
  things the bash script was reimplementing by hand.

- `collision.json` and `cyclic.json` are excluded: they're solana_parser's
  own negative test fixtures (duplicate type names / cyclic type refs)
  and are intentionally rejected by `decode_idl_data`.

- The surfpool test now distinguishes the three failure modes (decode
  rejected, no instructions, missing discriminator) with messages that
  name the IDL file -- previously a malformed IDL produced a misleading
  "no discriminator" panic.

CI now invokes `cargo test ... --test surfpool_fuzz -- --ignored
--test-threads=1` directly. The 14 tests run serially in ~9s end-to-end
on the local Helius pin.

Documents the pattern in `CLAUDE.md`'s Testing Patterns section.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e IDL lookup

`solana_parser` already exposes each IDL as a `pub const &str` via
`solana::embedded_idls::*` (compiled in via `include_str!`). Use those
consts directly in the per-IDL macro instead of resolving a filesystem
path at build time.

Net deletions:
- `build.rs::emit_solana_idl_dir()` (the `cargo metadata` invocation)
- `[build-dependencies] serde_json` from `visualsign-solana/Cargo.toml`
- `env!("SOLANA_IDL_DIR")` and the `std::fs::read_to_string` per test

Resolves the duplicated locate-IDL-dir logic the code review flagged
between `tools/idl-meta::locate_idl_dir` and `build.rs::emit_solana_idl_dir`.

14 tests pass locally in ~9s (`HELIUS_API_KEY=<key> cargo test ... --
--ignored --test-threads=1`).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant