pub struct TestConfig {
pub rpc_port: u16,
pub rpc_username: String,
pub rpc_password: String,
pub network: Network,
pub extra_args: Vec<String>,
}Expand description
TestConfig represents the configuration needed to run a Bitcoin node in a test environment. This struct is the single source of truth for test‑node settings: RPC port, username, and password. Defaults are:
rpc_port = 0(auto‑select a free port)rpc_username = "rpcuser"rpc_password = "rpcpassword"network = Network::Regtest(for isolation and testability)
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.rpc_port = 18545;
cfg.rpc_username = "alice".into();
cfg.network = Network::Testnet;§Environment Overrides
Reads RPC_PORT, RPC_USER, RPC_PASS, and RPC_NETWORK environment variables to override defaults.
Fields§
§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.
network: NetworkWhich Bitcoin network to run against.
extra_args: Vec<String>Extra command-line arguments to pass to bitcoind
Implementations§
Source§impl TestConfig
impl TestConfig
Sourcepub fn as_chain_str(&self) -> &'static str
pub fn as_chain_str(&self) -> &'static str
Return the value used with -chain=<value> for the configured network
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_PORT: overridesrpc_portRPC_USER: overridesrpc_usernameRPC_PASS: overridesrpc_passwordRPC_NETWORK: one ofregtest,testnet|test,signet,mainnet|main|bitcoin,testnet4
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