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

Add dev-rpc middleware #640

Merged
merged 5 commits into from
Dec 3, 2021
Merged

Add dev-rpc middleware #640

merged 5 commits into from
Dec 3, 2021

Conversation

wolflo
Copy link
Contributor

@wolflo wolflo commented Dec 2, 2021

Adds a dev-rpc feature flag to ethers-providers. This gives you a DevRpcMiddleware that exposes evm_snapshot and evm_revert for managing snapshot state.

There are more methods that may be useful, but there is a bit of a mess to untangle with conflicts between documentation, hardhat, and ganache.

A lighter-weight alternative may be to just expose provider.request() for raw requests under a dev-rpc flag.

  • Added Tests
  • Added Documentation TODO
  • Updated the changelog TODO

@wolflo
Copy link
Contributor Author

wolflo commented Dec 2, 2021

Not sure what the test failure is, will take a look today. Seems to pass when run with --features dev-rpc but fail when run with --all-features.

@wolflo
Copy link
Contributor Author

wolflo commented Dec 2, 2021

Seems this is the issue:

// Celo blocks can not get parsed when used with Ganache
#[cfg(not(feature = "celo"))]

Also, this is jammed into provider.rs because it needs access to the request. If making that pub(crate) were okay I could break this out.

Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

Nice work! Will merge once linted, if you want to do it @wolflo, otherwise i'll try later

Comment on lines 1090 to 1093
match ok {
true => Ok(()),
false => Err(DevRpcMiddlewareError::NoSnapshotError),
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

an if {} else {}would be more idiomatic here

ProviderError(ProviderError),

#[error("Could not revert to snapshot")]
NoSnapshot,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I misunderstood this lint, but it seems to not jive with the rest of the Error naming convention for ethers.

@gakonst gakonst merged commit bccc7b9 into gakonst:master Dec 3, 2021
@wolflo wolflo deleted the dev-rpc branch December 3, 2021 17:12
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.

3 participants