test: unit tests via httptest, concurrent stress, fork scenarios, benchmarks - #51
Merged
Conversation
…chmarks Fills the test-depth gaps flagged in Phase 3. Four new files plus subtests in the existing integration file. anvil_unit_test.go — pure-Go tests, no live anvil required. Covers builder validation, WithStartupTimeout semantics, resolveAnvilPath with temp-dir fixtures (missing / not executable / directory / executable / XDG vs HOME precedence), the retry helper's backoff and exhaustion paths, errors.Is propagation for every sentinel, and RPC method shape via an httptest JSON-RPC server that records method + params and verifies ctx cancellation mid-call. Contributors without Foundry can run the unit subset via go test -run '^Test(AnvilBuilder|ResolveAnvilPath|Retry|SentinelErrors|RPC)' ./... anvil_test.go — three new subtests on the existing shared-anvil harness: startup-timeout-exceeded expects ErrStartupTimeout, RPC with cancelled ctx returns context.Canceled, and a 50-goroutine concurrent stress test (~500ms burst of MineBlock / SetBalance / Metrics reads) that exercises atomics under contention and validates no races under -race. fork_test.go — new file behind //go:build fork. Reads ETH_RPC_URL and skips when unset. Covers WithFork at chain head and WithForkBlockNumber at a specific block. CI default is tag-off so these are skipped; run locally with ETH_RPC_URL=https://... go test -tags=fork -run Fork ./... anvil_bench_test.go — BenchmarkMineBlock, BenchmarkSetBalance, BenchmarkSnapshotRevertCycle, BenchmarkResetState. Sensible numbers locally (~200–400 µs/op on Apple M4); backs the make bench target. .golangci.yml — added gosec to the _test\.go exclusion list. The test fixtures legitimately create executable files (mode 0o755) which gosec G306 flags in production code but not in tests. CONTRIBUTING.md — documents the unit-only and fork-mode test invocations. CHANGELOG.md — Tests section under [Unreleased]. Verified locally: go build / vet / lint clean, go test -race ./... green in ~24s, benchmarks run clean. Closes #47 Closes #48 Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Phase 3 PR F — fills the test-depth gaps.
Summary
Four new files plus subtests in the existing integration harness, adding +705 lines of test code.
`anvil_unit_test.go` — pure-Go, no live anvil (#47)
Runs without Foundry installed. Covers:
Contributors without Foundry can run the unit subset:
```
go test -run '^Test(AnvilBuilder|ResolveAnvilPath|Retry|SentinelErrors|RPC)' ./...
```
`anvil_test.go` — new integration subtests (#48)
`fork_test.go` — `//go:build fork` tag (#48)
Reads `ETH_RPC_URL` from env; skips cleanly if unset. CI default runs without the tag. Run locally:
```
ETH_RPC_URL=https://... go test -tags=fork -run Fork ./...
```
Covers `WithFork` at chain head and `WithForkBlockNumber` at a specific block.
`anvil_bench_test.go` — benchmarks (#48)
Four benchmarks backing the existing `make bench` target:
```
BenchmarkMineBlock-16 ~283 µs/op
BenchmarkSetBalance-16 ~195 µs/op
BenchmarkSnapshotRevertCycle-16 ~253 µs/op
BenchmarkResetState-16 ~380 µs/op
```
(Apple M4, localhost anvil 1.5.0.)
`.golangci.yml` — added `gosec` to `_test\.go` exclusions
Test fixtures legitimately create executable files (mode 0o755) which gosec G306 flags in production code. Not a concern in test-only code.
Test plan
Scope notes
Closes #47
Closes #48
What's left
🤖 Generated with Claude Code