pub struct TestConfig {
pub network: Network,
pub rpc_port: u16,
pub rpc_username: String,
pub rpc_password: String,
pub bitcoind_path: Option<PathBuf>,
pub extra_args: Vec<String>,
}Expand description
TestConfig represents the configuration needed to run a Bitcoin node in a test environment. This struct encapsulates test‑node settings: network, RPC port, username, password, and extra args. Defaults are:
network = Network::Regtestrpc_port = 0(auto‑select a free port)rpc_username = "rpcuser"rpc_password = "rpcpassword"bitcoind_path = None(use executable from PATH)extra_args = ["-prune=0", "-txindex"](for full blockchain history and transaction lookup)
To override any of these, simply modify fields on TestConfig::default()
(or assign directly in code). If you prefer not to recompile for every change,
consider using TestConfig::from_env() to read overrides from environment variables.
§Examples
let mut cfg = TestConfig::default();
cfg.network = Network::Testnet;
cfg.rpc_port = 18545;
cfg.rpc_username = "alice".into();§Environment Overrides
Reads RPC_NETWORK, RPC_PORT, RPC_USER, and RPC_PASS, and BITCOIND_PATH (path to bitcoind executable) to override defaults.
Fields§
§network: NetworkWhich Bitcoin network to run against.
rpc_port: u16The port number for RPC communication with the Bitcoin node. A value of 0 indicates that an available port should be automatically selected.
rpc_username: StringThe username for RPC authentication.
Can be customized to match your bitcoin.conf rpcuser setting.
rpc_password: StringThe password for RPC authentication.
Can be customized to match your bitcoin.conf rpcpassword setting.
bitcoind_path: Option<PathBuf>Path to the bitcoind executable. If None, the default executable name is used (e.g. from PATH).
extra_args: Vec<String>Extra command-line arguments to pass to bitcoind
Implementations§
Source§impl TestConfig
impl TestConfig
Sourcepub fn as_chain_str(&self) -> Result<&'static str, UnsupportedNetwork>
pub fn as_chain_str(&self) -> Result<&'static str, UnsupportedNetwork>
Return the value used with -chain=<value> for the configured network.
Returns Err(UnsupportedNetwork) if the network variant is not supported for node startup.
Sourcepub fn network_from_str(s: &str) -> Option<Network>
pub fn network_from_str(s: &str) -> Option<Network>
Parse network from common strings (case-insensitive). Accepts: regtest, testnet|test, signet, mainnet|main|bitcoin, testnet4.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a TestConfig, overriding defaults with environment variables:
RPC_NETWORK: overridesnetwork; one ofregtest,testnet|test,signet,mainnet|main|bitcoin,testnet4RPC_PORT: overridesrpc_portRPC_USER: overridesrpc_usernameRPC_PASS: overridesrpc_passwordBITCOIND_PATH: overridesbitcoind_path(path to the bitcoind executable)
Sourcepub fn into_config(self) -> Config
pub fn into_config(self) -> Config
Convert this test configuration into a full Config instance
Sourcepub fn from_config(config: &Config) -> Self
pub fn from_config(config: &Config) -> Self
Create a TestConfig from a full Config instance
Trait Implementations§
Source§impl Clone for TestConfig
impl Clone for TestConfig
Source§fn clone(&self) -> TestConfig
fn clone(&self) -> TestConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more