-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat: usage for mocking blockchain scenarios in Rust tests #6974
Comments
something like this you mean? foundry/crates/anvil/tests/it/anvil.rs Lines 53 to 60 in 1e8fb25
|
Since this is just for internal testing, you should just require the |
Note that the I know that alloy is supposed to replace it and ethers is being deprecated, but until there is a better solution, maybe this is an acceptable workaround? We do something very similar to what you describe here with anvil from ethers: https://github.com/xmtp/didethresolver/blob/a30b4da8b436cdbef6f93a17538612bc4d512e81/lib/tests/integration_util/mod.rs#L52 It seems |
Thanks guys for the ideas! Ideally I'd like to do what @mattsse mentioned; i.e. call into the Anvil directly and spawn it. However, I had gotten compiler errors when trying to do this.
That's fine, I don't mind if the API is unstable and changes frequently. Would be nice if I could get it to compile though! Seems like |
In the future we possibly have a better way of using Anvil as a library but for now using |
Component
Forge
Describe the feature you would like
I'm implementing EIP-1271 using alloy in a Rust project and I'd like to write an automated test for my implementation. My idea is to write a tokio test which starts up an anvil blockchain, and deploys a mock EIP-1271 contract (perhaps the one from the spec) to the chain, and then executes the code under test using a mocked blockchain. Several test cases would check more scenarios, such as invalid signatures or invalid address.
However, I ran into some problems with this approach, namely:
anvil = { git = "https://github.com/foundry-rs/foundry.git" }
and providing the same[patch.crates-io]
I get compile errors (and different ones from yesterday).bin
folder: https://github.com/foundry-rs/foundry/blob/master/crates/forge/bin/cmd/create.rsAlternatively I could install the anvil and forge binaries and execute them from Rust, but this significantly more effort to pass configuration around (e.g. private keys and deployment addresses) and requires the developer to install dependencies.
Additional context
No response
The text was updated successfully, but these errors were encountered: