feat!: migrate RPC methods to context-first signatures - #44
Merged
Conversation
Every mutating RPC wrapper now takes context.Context as its first parameter and forwards to a.rpcClient.CallContext(ctx, ...). A hung RPC no longer blocks the caller indefinitely — callers can enforce deadlines and cancellation per operation. Affected methods (breaking): MineBlock, SetNextBlockTimestamp, IncreaseTime, SetBalance, Impersonate, StopImpersonating, Snapshot, Revert, SetCode, SetStorageAt, SetNonce, Mine, DropTransaction, SetAutomine, SetIntervalMining, AutoImpersonate, ResetFork, ResetState. EthereumTestEnvironment interface updated to match. MemPoolEmpty helper promoted to (*Anvil).WaitForMemPoolEmpty(ctx, timeout) so it uses the instance's own client and honors both ctx deadlines and an explicit timeout. The free function MemPoolEmpty is kept as a Deprecated shim for one release. Tests migrated to pass t.Context() everywhere; the former anvil.context escape hatch used in test bodies is no longer needed. Two new subtests cover WaitForMemPoolEmpty success and ctx-cancel paths. Docs updated: CHANGELOG entries under Changed / Added / Deprecated with a migration snippet; CLAUDE.md's "pending migration" section replaced with the current-API shape and an example; README quick start and usage examples updated to use ctx. Locally verified: go build / go vet clean, golangci-lint 0 issues, go test -race ./... green in ~30s. Closes #36 Closes #39 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 23, 2026
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 2 PR C — the largest breaking change in the roadmap. Every mutating RPC wrapper now takes `context.Context` as its first parameter, so callers can enforce per-call deadlines and cancellation.
Summary
Breaking (pre-1.0; will bump the next minor tag):
Additive:
Deprecated:
Docs updated:
Migration
```go
// before
anvil.MineBlock()
anvil.SetBalance(addr, bal)
snapshotID, _ := anvil.Snapshot()
// after
ctx := context.Background() // or t.Context() in tests, or ctx with a timeout
anvil.MineBlock(ctx)
anvil.SetBalance(ctx, addr, bal)
snapshotID, _ := anvil.Snapshot(ctx)
```
Test plan
Scope notes
Closes #36
Closes #39
Follow-ups in this phase
🤖 Generated with Claude Code