Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(rpc): add remaining anvil rpc methods to provider #831

Merged

Conversation

zerosnacks
Copy link
Member

@zerosnacks zerosnacks commented Jun 5, 2024

Motivation

Closes #271

Solution

Implements Anvil API mirroring implementation in Foundry: https://github.com/foundry-rs/foundry/blob/00854b602ef0e67379a2027ccc5d0aad553e5333/crates/anvil/src/eth/api.rs#L1492-L2025

Found a couple of issues in Anvil, very likely unrelated to this API implementation that will requires follow-ups in Foundry:

  • evm_mine, evm_mine_detailed only mines a single block regardless of the configuration defined by MineOptions. Works OK with None.
  • anvil_setBlock logic is implemented in Anvil but not available on the API (dead code).
  • anvil_enable_traces is disabled in Anvil.
  • anvil_reset does not update the chain_id correctly.

Goal of the tests are mainly as a smoke test to make sure the API is correct.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple nits

Cargo.toml Outdated Show resolved Hide resolved
@@ -77,5 +78,11 @@ ipc = ["pubsub", "alloy-rpc-client/ipc", "alloy-transport-ipc"]
reqwest-default-tls = ["alloy-transport-http?/reqwest-default-tls"]
reqwest-rustls-tls = ["alloy-transport-http?/reqwest-rustls-tls"]
reqwest-native-tls = ["alloy-transport-http?/reqwest-native-tls"]
anvil = ["reqwest", "dep:alloy-node-bindings", "dep:alloy-signer-wallet"]
anvil-api = ["dep:alloy-rpc-types-anvil"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure if newlines are from your formatter, or if other formatters would also produce them.

Copy link
Member Author

@zerosnacks zerosnacks Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its my formatter (Even Better TOML extension) with the default configuration

@zerosnacks zerosnacks changed the title feature: add remaining anvil rpc methods to provider feature(rpc): add remaining anvil rpc methods to provider Jun 6, 2024
@zerosnacks zerosnacks marked this pull request as ready for review June 6, 2024 13:31
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits

crates/rpc-types-anvil/src/lib.rs Outdated Show resolved Hide resolved
crates/rpc-types/src/eth/admin.rs Outdated Show resolved Hide resolved
}

async fn anvil_set_next_block_timestamp(&self, seconds: u64) -> TransportResult<()> {
self.client().request("evm_setNextBlockTimestamp", (seconds,)).await
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of these are declared as fn anvil but are evm_ ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, these were originally introduced by ganache which is deprecated now, imo we can keep the anvil prefix because these are also aliased in anvil:

https://github.com/foundry-rs/foundry/blob/e764c316c96c8062e9bc52f78f7ee45ea359bc60/crates/anvil/core/src/eth/mod.rs#L559-L559

but these also exist on hardhat iirc

Copy link
Member Author

@zerosnacks zerosnacks Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I've used the anvil prefix if it is available in Foundry as such. This is the case for most methods but unfortunately not all.

crates/rpc-types/src/eth/mod.rs Outdated Show resolved Hide resolved
crates/rpc-types-anvil/src/lib.rs Outdated Show resolved Hide resolved
@zerosnacks zerosnacks requested a review from prestwich June 6, 2024 15:59
@prestwich prestwich merged commit ebd72f1 into main Jun 6, 2024
24 checks passed
@prestwich prestwich deleted the zerosnacks/add-remaining-anvil-rpc-methods-to-provider branch June 6, 2024 20:34
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Capture Anvil RPC methods in AnvilProvider
4 participants