Closed chris13524 closed 1 month ago
Since this is just for internal testing, you should just require the anvil
binary and call it through alloy-node-bindings
. We don't provide any stability guarantees to any crate at the moment.
Note that the ethers
crate provides an interface to anvil
: https://docs.rs/ethers/latest/ethers/core/utils/struct.Anvil.html
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 alloy-node-bindings
is this same/similar interface, so that would do the trick
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.
We don't provide any stability guarantees to any crate at the moment.
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 alloy-node-bindings
is the best way forward for now. However I'd still request that this feature be added in the future: ability to spawn a node and deploy a contract from Rust w/o binary installation.
In the future we possibly have a better way of using Anvil as a library but for now using alloy-node-bindings
is the recommended way. Marking as resolved
.
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