Add test for eth_client config
@@ -4,7 +4,7 @@ use serde::Deserialize;
use crate::envy_load;
/// Configuration for the Ethereum gateways.
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct ETHClientConfig {
/// Numeric identifier of the L1 network (e.g. `9` for localhost).
pub chain_id: u64,
@@ -21,3 +21,30 @@ impl ETHClientConfig {
envy_load!("eth_client", "ETH_CLIENT_")
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::configs::test_utils::set_env;
+
+ fn expected_config() -> ETHClientConfig {
+ ETHClientConfig {
+ chain_id: 9,
+ gas_price_factor: 1.0f64,
+ web3_url: "http://127.0.0.1:8545".into(),
+ }
+ }
+
+ #[test]
+ fn from_env() {
+ let config = r#"
+ETH_CLIENT_CHAIN_ID="9"
+ETH_CLIENT_GAS_PRICE_FACTOR="1"
+ETH_CLIENT_WEB3_URL="http://127.0.0.1:8545"
+ "#;
+ set_env(config);
+
+ let actual = ETHClientConfig::from_env();
+ assert_eq!(actual, expected_config());
+ }
+}
