|
11 | 11 | #![allow(clippy::type_complexity)] |
12 | 12 |
|
13 | 13 | use std::collections::HashMap; |
| 14 | +use std::fmt::Display; |
14 | 15 | use std::path::PathBuf; |
15 | 16 | use std::process::Command; |
16 | 17 | use std::str::FromStr; |
@@ -62,7 +63,7 @@ use crate::strings::{ |
62 | 63 | }; |
63 | 64 | use crate::{run, run_as}; |
64 | 65 |
|
65 | | -const ENV_VAR_NAMADA_ADD_PEER: &str = "NAMADA_ADD_PEER"; |
| 66 | +const ENV_VAR_NAMADA_SEED_NODES: &str = "NAMADA_SEED_NODES"; |
66 | 67 |
|
67 | 68 | fn start_namada_ledger_node( |
68 | 69 | test: &Test, |
@@ -4020,8 +4021,8 @@ fn proposal_change_shielded_reward() -> Result<()> { |
4020 | 4021 | /// Test sync with a chain. |
4021 | 4022 | /// |
4022 | 4023 | /// The chain ID must be set via `NAMADA_CHAIN_ID` env var. |
4023 | | -/// Additionally, `NAMADA_ADD_PEER` maybe be specified with a string that must |
4024 | | -/// be parsable into `TendermintAddress`. |
| 4024 | +/// Additionally, `NAMADA_SEED_NODES` maybe be specified with a comma-separated |
| 4025 | +/// list of addresses that must be parsable into `TendermintAddress`. |
4025 | 4026 | /// |
4026 | 4027 | /// To run this test use `--ignored`. |
4027 | 4028 | #[test] |
@@ -4059,21 +4060,32 @@ fn test_sync_chain() -> Result<()> { |
4059 | 4060 | join_network.exp_string("Successfully configured for chain")?; |
4060 | 4061 | join_network.assert_success(); |
4061 | 4062 |
|
4062 | | - // Add peer if any given |
4063 | | - if let Ok(add_peer) = std::env::var(ENV_VAR_NAMADA_ADD_PEER) { |
| 4063 | + if cfg!(debug_assertions) { |
| 4064 | + let res: Result<Vec<TendermintAddress>, _> = |
| 4065 | + deserialize_comma_separated_list( |
| 4066 | + |
| 4067 | + 168:26656,tcp://0edfd7e6a1a172864ddb76a10ea77a8bb242759a@65.\ |
| 4068 | + 21.194.46:36656", |
| 4069 | + ); |
| 4070 | + debug_assert!(res.is_ok(), "Expected Ok, got {res:#?}"); |
| 4071 | + } |
| 4072 | + // Add seed nodes if any given |
| 4073 | + if let Ok(seed_nodes) = std::env::var(ENV_VAR_NAMADA_SEED_NODES) { |
4064 | 4074 | let mut config = namada_apps::config::Config::load( |
4065 | 4075 | base_dir, |
4066 | 4076 | &test.net.chain_id, |
4067 | 4077 | None, |
4068 | 4078 | ); |
4069 | | - config.ledger.cometbft.p2p.persistent_peers.push( |
4070 | | - TendermintAddress::from_str(&add_peer).unwrap_or_else(|_| { |
4071 | | - panic!( |
4072 | | - "Invalid `{ENV_VAR_NAMADA_ADD_PEER}` value. Must be a \ |
4073 | | - valid `TendermintAddress`." |
4074 | | - ) |
4075 | | - }), |
4076 | | - ); |
| 4079 | + let seed_nodes: Vec<TendermintAddress> = |
| 4080 | + deserialize_comma_separated_list(&seed_nodes).unwrap_or_else( |
| 4081 | + |_| { |
| 4082 | + panic!( |
| 4083 | + "Invalid `{ENV_VAR_NAMADA_SEED_NODES}` value. Must be \ |
| 4084 | + a valid `TendermintAddress`." |
| 4085 | + ) |
| 4086 | + }, |
| 4087 | + ); |
| 4088 | + config.ledger.cometbft.p2p.seeds.extend(seed_nodes); |
4077 | 4089 | config.write(base_dir, &test.net.chain_id, true).unwrap(); |
4078 | 4090 | } |
4079 | 4091 |
|
@@ -4102,3 +4114,32 @@ fn test_sync_chain() -> Result<()> { |
4102 | 4114 |
|
4103 | 4115 | Ok(()) |
4104 | 4116 | } |
| 4117 | + |
| 4118 | +/// Deserialize a comma separated list of types that impl `FromStr` as a `Vec` |
| 4119 | +/// from a string. Same as `tendermint-config/src/config.rs` list |
| 4120 | +/// deserialization. |
| 4121 | +fn deserialize_comma_separated_list<T, E>( |
| 4122 | + list: &str, |
| 4123 | +) -> serde_json::Result<Vec<T>> |
| 4124 | +where |
| 4125 | + T: FromStr<Err = E>, |
| 4126 | + E: Display, |
| 4127 | +{ |
| 4128 | + use serde::de::Error; |
| 4129 | + |
| 4130 | + let mut result = vec![]; |
| 4131 | + |
| 4132 | + if list.is_empty() { |
| 4133 | + return Ok(result); |
| 4134 | + } |
| 4135 | + |
| 4136 | + for item in list.split(',') { |
| 4137 | + result.push( |
| 4138 | + item.parse() |
| 4139 | + .map_err(|e| serde_json::Error::custom(format!("{e}"))) |
| 4140 | + .unwrap(), |
| 4141 | + ); |
| 4142 | + } |
| 4143 | + |
| 4144 | + Ok(result) |
| 4145 | +} |
0 commit comments