Skip to content

Commit

Permalink
Migrate simple example from Polkadot-sdk repo (#116)
Browse files Browse the repository at this point in the history
In order to ensure that backward compatibility with existing node
Zombienet, this PR migrates (as a start) a [simple example of a test
from
Polkadot-SDK](https://github.com/paritytech/polkadot-sdk/blob/0a6dfdf973b8e7b669eda6e2ed202fb3549a20b9/polkadot/zombienet_tests/smoke/0001-parachains-smoke-test.toml),
and fixes some bugs in order to make the test work;
  • Loading branch information
wirednkod authored Oct 6, 2023
1 parent 1b37b9e commit 2a221b4
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 12 deletions.
33 changes: 33 additions & 0 deletions crates/configuration/src/global_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct GlobalSettings {
// TODO: parse both case in zombienet node version to avoid renamed ?
#[serde(rename = "timeout")]
network_spawn_timeout: Duration,
#[serde(default)]
node_spawn_timeout: Duration,
local_ip: Option<IpAddr>,
}
Expand Down Expand Up @@ -189,6 +190,38 @@ mod tests {
);
}

#[test]
fn global_settings_config_builder_should_succeeds_when_node_spawn_timeout_is_missing() {
let global_settings_config = GlobalSettingsBuilder::new()
.with_bootnodes_addresses(vec![
"/ip4/10.41.122.55/tcp/45421",
"/ip4/51.144.222.10/tcp/2333",
])
.with_network_spawn_timeout(600)
.with_local_ip("10.0.0.1")
.build()
.unwrap();

let bootnodes_addresses: Vec<Multiaddr> = vec![
"/ip4/10.41.122.55/tcp/45421".try_into().unwrap(),
"/ip4/51.144.222.10/tcp/2333".try_into().unwrap(),
];
assert_eq!(
global_settings_config.bootnodes_addresses(),
bootnodes_addresses.iter().collect::<Vec<_>>()
);
assert_eq!(global_settings_config.network_spawn_timeout(), 600);
assert_eq!(global_settings_config.node_spawn_timeout(), 300);
assert_eq!(
global_settings_config
.local_ip()
.unwrap()
.to_string()
.as_str(),
"10.0.0.1"
);
}

#[test]
fn global_settings_builder_should_fails_and_returns_an_error_if_one_bootnode_address_is_invalid(
) {
Expand Down
13 changes: 4 additions & 9 deletions crates/configuration/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ impl NetworkConfig {
}

// retrieve the defaults relaychain for assigning to nodes if needed
let relaychain_default_command: Option<Command> =
let mut relaychain_default_command: Option<Command> =
network_config.relaychain().default_command().cloned();

if relaychain_default_command.is_none() {
relaychain_default_command = network_config.relaychain().command().cloned();
}
let relaychain_default_image: Option<Image> =
network_config.relaychain().default_image().cloned();

Expand Down Expand Up @@ -144,14 +147,6 @@ impl NetworkConfig {

// Validation checks for parachains
network_config.parachains().iter().for_each(|parachain| {
let _ = TryInto::<Chain>::try_into(
parachain
.chain()
.ok_or("chain name must exist")
.unwrap()
.as_str(),
);

if parachain.default_image().is_some() {
let _ = TryInto::<Image>::try_into(parachain.default_image().unwrap().as_str());
}
Expand Down
4 changes: 2 additions & 2 deletions crates/configuration/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct ParachainConfig {
default = "default_as_true"
)]
onboard_as_parachain: bool,
#[serde(rename = "balance")]
#[serde(rename = "balance", default)]
initial_balance: U128,
default_command: Option<Command>,
default_image: Option<Image>,
Expand All @@ -118,7 +118,7 @@ pub struct ParachainConfig {
genesis_state_path: Option<AssetLocation>,
genesis_state_generator: Option<Command>,
chain_spec_path: Option<AssetLocation>,
#[serde(rename = "cumulus_based")]
#[serde(rename = "cumulus_based", default = "default_as_true")]
is_cumulus_based: bool,
#[serde(skip_serializing_if = "std::vec::Vec::is_empty", default)]
bootnodes_addresses: Vec<Multiaddr>,
Expand Down
7 changes: 7 additions & 0 deletions crates/configuration/src/relaychain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct RelaychainConfig {
#[serde(skip_serializing_if = "std::vec::Vec::is_empty", default)]
nodes: Vec<NodeConfig>,
genesis_overrides: Option<serde_json::Value>,
command: Option<Command>,
}

impl RelaychainConfig {
Expand Down Expand Up @@ -66,6 +67,11 @@ impl RelaychainConfig {
self.chain_spec_path.as_ref()
}

/// The non-default command used for nodes.
pub fn command(&self) -> Option<&Command> {
self.command.as_ref()
}

/// The number of `random nominators` to create for chains using staking, this is used in tandem with `max_nominations` to simulate the amount of nominators and nominations.
pub fn random_nominators_count(&self) -> Option<u32> {
self.random_nominators_count
Expand Down Expand Up @@ -118,6 +124,7 @@ impl Default for RelaychainConfigBuilder<Initial> {
default_db_snapshot: None,
default_args: vec![],
chain_spec_path: None,
command: None,
random_nominators_count: None,
max_nominations: None,
genesis_overrides: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/configuration/src/shared/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct NodeConfig {
pub(crate) is_validator: bool,
#[serde(alias = "invulnerable", default = "default_as_true")]
pub(crate) is_invulnerable: bool,
#[serde(alias = "bootnode")]
#[serde(alias = "bootnode", default)]
pub(crate) is_bootnode: bool,
#[serde(alias = "balance")]
#[serde(default)]
Expand Down
30 changes: 30 additions & 0 deletions crates/examples/examples/0001-simple.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[settings]
timeout = 1000

[relaychain]
default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}"
chain = "rococo-local"
command = "polkadot"

[[relaychain.nodes]]
name = "alice"
args = [ "--alice", "-lruntime=debug,parachain=trace" ]

[[relaychain.nodes]]
name = "bob"
args = [ "--bob", "-lruntime=debug,parachain=trace" ]

[[parachains]]
id = 100
addToGenesis = false

[parachains.collator]
name = "collator01"
image = "{{COL_IMAGE}}"
command = "adder-collator"
args = [ "-lruntime=debug,parachain=trace" ]

[types.Header]
number = "u64"
parent_hash = "Hash"
post_state = "Hash"
23 changes: 23 additions & 0 deletions crates/examples/examples/simple_network_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// use std::time::Duration;

use configuration::NetworkConfig;
use orchestrator::Orchestrator;
use provider::NativeProvider;
use support::fs::local::LocalFileSystem;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = NetworkConfig::load_from_toml("./crates/examples/examples/0001-simple.toml")
.expect("errored?");

let fs = LocalFileSystem;
let provider = NativeProvider::new(fs.clone());
let orchestrator = Orchestrator::new(fs, provider);
orchestrator.spawn(config).await?;
println!("πŸš€πŸš€πŸš€πŸš€ network deployed");
// For now let just loop....
#[allow(clippy::empty_loop)]
loop {}

// Ok(())
}

0 comments on commit 2a221b4

Please sign in to comment.