From c0555ca347e9bfeec4b59950f8a04dfeb35a6d26 Mon Sep 17 00:00:00 2001 From: andrussal Date: Wed, 3 Dec 2025 05:46:32 +0100 Subject: [PATCH] Add topology_with helper and format scenario builder usage --- examples/src/bin/compose_runner.rs | 10 +++++----- examples/src/bin/k8s_runner.rs | 10 +++++----- examples/src/bin/local_runner.rs | 10 +++++----- .../core/src/scenario/definition.rs | 9 +++++++++ .../runners/compose/src/deployer.rs | 18 +++--------------- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/examples/src/bin/compose_runner.rs b/examples/src/bin/compose_runner.rs index e76786f..db3b33b 100644 --- a/examples/src/bin/compose_runner.rs +++ b/examples/src/bin/compose_runner.rs @@ -43,11 +43,11 @@ async fn run_compose_case( "building scenario plan" ); - let mut plan = ScenarioBuilder::topology() - .network_star() - .validators(validators) - .executors(executors) - .apply() + let mut plan = ScenarioBuilder::topology_with(|t| { + t.network_star() + .validators(validators) + .executors(executors) + }) .enable_node_control() .chaos() .restart() diff --git a/examples/src/bin/k8s_runner.rs b/examples/src/bin/k8s_runner.rs index 1236c9e..34522ef 100644 --- a/examples/src/bin/k8s_runner.rs +++ b/examples/src/bin/k8s_runner.rs @@ -39,11 +39,11 @@ async fn run_k8s_case( duration_secs = run_duration.as_secs(), "building scenario plan" ); - let mut plan = ScenarioBuilder::topology() - .network_star() - .validators(validators) - .executors(executors) - .apply() + let mut plan = ScenarioBuilder::topology_with(|t| { + t.network_star() + .validators(validators) + .executors(executors) + }) .wallets(TOTAL_WALLETS) .transactions() .rate(MIXED_TXS_PER_BLOCK) diff --git a/examples/src/bin/local_runner.rs b/examples/src/bin/local_runner.rs index 0e796ff..cb67c30 100644 --- a/examples/src/bin/local_runner.rs +++ b/examples/src/bin/local_runner.rs @@ -47,11 +47,11 @@ async fn run_local_case( duration_secs = run_duration.as_secs(), "building scenario plan" ); - let mut plan = ScenarioBuilder::topology() - .network_star() - .validators(validators) - .executors(executors) - .apply() + let mut plan = ScenarioBuilder::topology_with(|t| { + t.network_star() + .validators(validators) + .executors(executors) + }) .wallets(TOTAL_WALLETS) .transactions() .rate(MIXED_TXS_PER_BLOCK) diff --git a/testing-framework/core/src/scenario/definition.rs b/testing-framework/core/src/scenario/definition.rs index afc9614..57ae299 100644 --- a/testing-framework/core/src/scenario/definition.rs +++ b/testing-framework/core/src/scenario/definition.rs @@ -115,6 +115,15 @@ impl Builder { pub fn topology() -> TopologyConfigurator { TopologyConfigurator::new(Self::new(TopologyBuilder::new(TopologyConfig::empty()))) } + + /// Configure topology via a closure and return the scenario builder. + #[must_use] + pub fn topology_with( + f: impl FnOnce(TopologyConfigurator) -> TopologyConfigurator, + ) -> Builder { + let configurator = Self::topology(); + f(configurator).apply() + } } impl Builder { diff --git a/testing-framework/runners/compose/src/deployer.rs b/testing-framework/runners/compose/src/deployer.rs index 2927b19..1dad1a3 100644 --- a/testing-framework/runners/compose/src/deployer.rs +++ b/testing-framework/runners/compose/src/deployer.rs @@ -302,11 +302,7 @@ mod tests { #[test] fn cfgsync_prebuilt_configs_preserve_genesis() { - let scenario = ScenarioBuilder::topology() - .validators(1) - .executors(1) - .apply() - .build(); + let scenario = ScenarioBuilder::topology_with(|t| t.validators(1).executors(1)).build(); let topology = scenario.topology().clone(); let hosts = hosts_from_topology(&topology); let tracing_settings = tracing_settings(&topology); @@ -358,11 +354,7 @@ mod tests { #[test] fn cfgsync_genesis_proofs_verify_against_ledger() { - let scenario = ScenarioBuilder::topology() - .validators(1) - .executors(1) - .apply() - .build(); + let scenario = ScenarioBuilder::topology_with(|t| t.validators(1).executors(1)).build(); let topology = scenario.topology().clone(); let hosts = hosts_from_topology(&topology); let tracing_settings = tracing_settings(&topology); @@ -398,11 +390,7 @@ mod tests { #[test] fn cfgsync_docker_overrides_produce_valid_genesis() { - let scenario = ScenarioBuilder::topology() - .validators(1) - .executors(1) - .apply() - .build(); + let scenario = ScenarioBuilder::topology_with(|t| t.validators(1).executors(1)).build(); let topology = scenario.topology().clone(); let tracing_settings = tracing_settings(&topology); let hosts = docker_style_hosts(&topology);