You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(anvil): comprehensive documentation and API improvements (#429)
# Improve the anvil module
Enhance the anvil module with better documentation, API consistency, and
improved test coverage to match repository best practices.
## Changes
- Add public ANVIL_PORT constant for API consistency with other modules
- Add with_tag() convenience method for ergonomic tag selection
- Create comprehensive inline documentation with usage examples
- Add detailed builder method documentation clarifying path handling
- Create examples/anvil.rs demonstrating practical usage
- Add blocking/sync test variant
- Add test for latest() method
- Update lib.rs module description to be more descriptive
- Update outdated testcontainers version references
## Impact
- Test coverage: 2 → 4 tests (100% increase)
- Documentation: Now includes comprehensive examples and usage patterns
- API: Consistent with 27+ other modules that export port constants
- User experience: Significantly improved with clearer docs and examples
---
Signed off by Joseph Livesey <[email protected]>
/// # Community Testcontainers Implementation for [Foundry Anvil](https://book.getfoundry.sh/anvil/)
13
18
///
14
19
/// This is a community implementation of the [Testcontainers](https://testcontainers.org/) interface for [Foundry Anvil](https://book.getfoundry.sh/anvil/).
15
20
///
16
-
/// It is not officially supported by Foundry, but it is a community effort to provide a more user-friendly interface for running Anvil inside a Docker container.
21
+
/// Anvil is Foundry's fast local Ethereum node for development and testing. It's an ideal tool for rapid
22
+
/// iteration on smart contract development and provides a clean, lightweight alternative to running a full node.
/// let node = AnvilNode::default().start().await?;
35
+
///
36
+
/// // Get the RPC endpoint URL
37
+
/// let host_port = node.get_host_port_ipv4(ANVIL_PORT).await?;
38
+
/// let rpc_url = format!("http://localhost:{host_port}");
39
+
///
40
+
/// // Use with your favorite Ethereum library (alloy, ethers, web3, etc.)
41
+
/// // let provider = Provider::try_from(rpc_url)?;
42
+
/// # Ok(())
43
+
/// # }
44
+
/// ```
45
+
///
46
+
/// # Advanced Configuration
47
+
///
48
+
/// ```rust,ignore
49
+
/// use testcontainers_modules::anvil::AnvilNode;
50
+
///
51
+
/// // Configure chain ID and forking
52
+
/// let node = AnvilNode::default()
53
+
/// .with_chain_id(1337)
54
+
/// .with_fork_url("https://eth.llamarpc.com")
55
+
/// .with_fork_block_number(18_000_000)
56
+
/// .start().await?;
57
+
/// ```
58
+
///
59
+
/// # Usage
17
60
///
18
-
/// The endpoint of the container is intended to be injected into your provider configuration, so that you can easily run tests against a local Anvil instance.
19
-
/// See the `test_anvil_node_container` test for an example of how to use this.
61
+
/// The endpoint of the container is intended to be injected into your provider configuration, so that you can
62
+
/// easily run tests against a local Anvil instance.
20
63
///
21
64
/// To use the latest Foundry image, you can use the `latest()` method:
22
65
///
23
66
/// ```rust,ignore
24
67
/// let node = AnvilNode::latest().start().await?;
25
68
/// ```
26
69
///
27
-
/// Users can use a specific Foundry image in their code with [`ImageExt::with_tag`](https://docs.rs/testcontainers/0.23.1/testcontainers/core/trait.ImageExt.html#tymethod.with_tag).
70
+
/// Users can use a specific Foundry image in their code with [`ImageExt::with_tag`](https://docs.rs/testcontainers/latest/testcontainers/core/trait.ImageExt.html#tymethod.with_tag).
28
71
///
29
72
/// ```rust,ignore
30
-
/// let node = AnvilNode::with_tag("master").start().await?;
73
+
/// use testcontainers::core::ImageExt;
74
+
/// let node = AnvilNode::default().with_tag("nightly").start().await?;
0 commit comments