Skip to content

Commit d765bbf

Browse files
committed
Merge branch 'tomas/test-fullnode-sync-seeds' (#2707)
* tomas/test-fullnode-sync-seeds: test/e2e/test_sync_chain: add seed_nodes param
2 parents 412accd + 197b0d2 commit d765bbf

File tree

2 files changed

+57
-16
lines changed

2 files changed

+57
-16
lines changed

.github/workflows/triggerable_sync.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ on:
1515
description: 'Chain ID'
1616
required: true
1717
type: string
18-
add_peer:
19-
description: "Optional address to add to Comet's P2P config (must be a valid `TendermintAddress`, e.g. `tcp://[email protected]:26656`)."
18+
seed_nodes:
19+
description: "An optional list of seed node addresses (comma separated with no whitespace) to add to Comet's P2P config (must be a valid `TendermintAddress`es, e.g. `tcp://[email protected]:26656`)."
2020
required: false
2121
default: ''
2222
type: string
@@ -109,7 +109,7 @@ jobs:
109109
NAMADA_E2E_USE_PREBUILT_BINARIES: "true"
110110
NAMADA_E2E_KEEP_TEMP: "true"
111111
NAMADA_LOG_COLOR: "false"
112-
NAMADA_ADD_PEER: "${{ inputs.add_peer }}"
112+
NAMADA_SEED_NODES: "${{ inputs.seed_nodes }}"
113113
NAMADA_CHAIN_ID: "${{ inputs.chain_id }}"
114114
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=/usr/local/bin/mold"
115115
- name: Upload logs

crates/tests/src/e2e/ledger_tests.rs

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![allow(clippy::type_complexity)]
1212

1313
use std::collections::HashMap;
14+
use std::fmt::Display;
1415
use std::path::PathBuf;
1516
use std::process::Command;
1617
use std::str::FromStr;
@@ -62,7 +63,7 @@ use crate::strings::{
6263
};
6364
use crate::{run, run_as};
6465

65-
const ENV_VAR_NAMADA_ADD_PEER: &str = "NAMADA_ADD_PEER";
66+
const ENV_VAR_NAMADA_SEED_NODES: &str = "NAMADA_SEED_NODES";
6667

6768
fn start_namada_ledger_node(
6869
test: &Test,
@@ -4020,8 +4021,8 @@ fn proposal_change_shielded_reward() -> Result<()> {
40204021
/// Test sync with a chain.
40214022
///
40224023
/// 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`.
40254026
///
40264027
/// To run this test use `--ignored`.
40274028
#[test]
@@ -4059,21 +4060,32 @@ fn test_sync_chain() -> Result<()> {
40594060
join_network.exp_string("Successfully configured for chain")?;
40604061
join_network.assert_success();
40614062

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) {
40644074
let mut config = namada_apps::config::Config::load(
40654075
base_dir,
40664076
&test.net.chain_id,
40674077
None,
40684078
);
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);
40774089
config.write(base_dir, &test.net.chain_id, true).unwrap();
40784090
}
40794091

@@ -4102,3 +4114,32 @@ fn test_sync_chain() -> Result<()> {
41024114

41034115
Ok(())
41044116
}
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

Comments
 (0)