Skip to content
Snippets Groups Projects
Unverified Commit 8454948f authored by Javier Viola's avatar Javier Viola Committed by GitHub
Browse files

Merge pull request #85 from paritytech/feat/parachain-defaults

Feat/parachain defaults
parents cdf7a395 2623380d
Branches
No related merge requests found
......@@ -5,7 +5,7 @@ use crate::{
hrmp_channel::{self, HrmpChannelConfig, HrmpChannelConfigBuilder},
parachain::{self, ParachainConfig, ParachainConfigBuilder},
relaychain::{self, RelaychainConfig, RelaychainConfigBuilder},
shared::{errors::ConfigError, helpers::merge_errors_vecs, macros::states},
shared::{helpers::merge_errors_vecs, macros::states},
};
/// A network configuration, composed of a relaychain, parachains and HRMP channels.
......@@ -138,16 +138,7 @@ impl NetworkConfigBuilder<WithRelaychain> {
},
self.errors,
),
Err((para_id, errors)) => Self::transition(
self.config,
merge_errors_vecs(
self.errors,
errors
.into_iter()
.map(|error| ConfigError::Parachain(para_id, error).into())
.collect::<Vec<_>>(),
),
),
Err(errors) => Self::transition(self.config, merge_errors_vecs(self.errors, errors)),
}
}
......@@ -194,27 +185,29 @@ mod tests {
.validator(true)
})
})
.with_parachain(|parachain1| {
parachain1
.with_parachain(|parachain| {
parachain
.with_id(1)
.with_chain("myparachain1")
.with_initial_balance(100_000)
.with_collator(|collator| {
collator
.with_name("collator1")
.with_command("command1")
.validator(true)
})
.with_initial_balance(100_000)
})
.with_parachain(|parachain2| {
parachain2
.with_parachain(|parachain| {
parachain
.with_id(2)
.with_chain("myparachain2")
.with_initial_balance(0)
.with_collator(|collator| {
collator
.with_name("collator2")
.with_command("command2")
.validator(true)
})
.with_initial_balance(0)
})
.with_hrmp_channel(|hrmp_channel1| {
hrmp_channel1
......@@ -312,16 +305,17 @@ mod tests {
.validator(true)
})
})
.with_parachain(|parachain1| {
parachain1
.with_parachain(|parachain| {
parachain
.with_id(1)
.with_chain("myparachain")
.with_initial_balance(100_000)
.with_collator(|collator| {
collator
.with_name("collator1")
.with_command("command1")
.validator(true)
})
.with_initial_balance(100_000)
})
.build()
.unwrap_err();
......@@ -350,9 +344,11 @@ mod tests {
.validator(true)
})
})
.with_parachain(|parachain1| {
parachain1
.with_parachain(|parachain| {
parachain
.with_id(1000)
.with_chain("myparachain")
.with_initial_balance(100_000)
.with_collator(|collator| {
collator
.with_name("collator1")
......@@ -360,7 +356,6 @@ mod tests {
.with_image("invalid.image")
.validator(true)
})
.with_initial_balance(100_000)
})
.build()
.unwrap_err();
......@@ -393,17 +388,20 @@ mod tests {
.with_parachain(|parachain1| {
parachain1
.with_id(1000)
.with_chain("myparachain1")
.with_initial_balance(100_000)
.with_collator(|collator| {
collator
.with_name("collator")
.with_command("invalid command")
.validator(true)
})
.with_initial_balance(100_000)
})
.with_parachain(|parachain2| {
parachain2
.with_id(2000)
.with_chain("myparachain2")
.with_initial_balance(100_000)
.with_collator(|collator| {
collator
.with_name("collator")
......@@ -415,7 +413,6 @@ mod tests {
.with_request_cpu("invalid")
})
})
.with_initial_balance(100_000)
})
.build()
.unwrap_err();
......@@ -445,16 +442,17 @@ mod tests {
.validator(true)
})
})
.with_parachain(|parachain1| {
parachain1
.with_parachain(|parachain| {
parachain
.with_id(1000)
.with_chain("myparachain")
.with_initial_balance(100_000)
.with_collator(|collator| {
collator
.with_name("collator")
.with_command("command")
.validator(true)
})
.with_initial_balance(100_000)
})
.with_global_settings(|global_settings| {
global_settings
......@@ -489,9 +487,11 @@ mod tests {
.validator(true)
})
})
.with_parachain(|parachain1| {
parachain1
.with_parachain(|parachain| {
parachain
.with_id(1000)
.with_chain("myparachain")
.with_initial_balance(100_000)
.with_collator(|collator| {
collator
.with_name("collator")
......@@ -499,7 +499,6 @@ mod tests {
.with_image("invalid.image")
.validator(true)
})
.with_initial_balance(100_000)
})
.with_global_settings(|global_settings| global_settings.with_local_ip("127.0.0000.1"))
.build()
......
This diff is collapsed.
......@@ -64,14 +64,14 @@ impl RelaychainConfig {
self.default_db_snapshot.as_ref()
}
pub fn chain_spec_path(&self) -> Option<&AssetLocation> {
self.chain_spec_path.as_ref()
}
pub fn default_args(&self) -> Vec<&Arg> {
self.default_args.iter().collect::<Vec<&Arg>>()
}
pub fn chain_spec_path(&self) -> Option<&AssetLocation> {
self.chain_spec_path.as_ref()
}
pub fn random_minators_count(&self) -> Option<u32> {
self.random_nominators_count
}
......@@ -102,15 +102,15 @@ impl Default for RelaychainConfigBuilder<Initial> {
fn default() -> Self {
Self {
config: RelaychainConfig {
chain: ""
chain: "default"
.try_into()
.expect("empty string should be valid. this is a bug, please report it: https://github.com/paritytech/zombienet-sdk/issues"),
.expect("'default' overriding should be ensured by typestate. this is a bug, please report it: https://github.com/paritytech/zombienet-sdk/issues"),
default_command: None,
default_image: None,
default_resources: None,
default_db_snapshot: None,
chain_spec_path: None,
default_args: vec![],
chain_spec_path: None,
random_nominators_count: None,
max_nominations: None,
nodes: vec![],
......@@ -369,10 +369,9 @@ mod tests {
.with_default_args(vec![("--arg1", "value1").into(), "--option2".into()])
.with_random_nominators_count(42)
.with_max_nominations(5)
.with_node(|node1| node1.with_name("node1").bootnode(true))
.with_node(|node2| {
node2
.with_name("node2")
.with_node(|node| node.with_name("node1").bootnode(true))
.with_node(|node| {
node.with_name("node2")
.with_command("command2")
.validator(true)
})
......@@ -521,75 +520,6 @@ mod tests {
);
}
#[test]
fn relaychain_config_builder_with_default_command_should_fails_and_returns_an_error_if_default_image_is_invalid(
) {
let errors = RelaychainConfigBuilder::new()
.with_chain("chain")
.with_default_command("command")
.with_default_image("invalid image")
.with_node(|node| {
node.with_name("node")
.with_command("command")
.validator(true)
})
.build()
.unwrap_err();
assert_eq!(errors.len(), 1);
assert_eq!(
errors.get(0).unwrap().to_string(),
r"relaychain.default_image: 'invalid image' doesn't match regex '^([ip]|[hostname]/)?[tag_name]:[tag_version]?$'"
);
}
#[test]
fn relaychain_config_builder_with_default_command_should_fails_and_returns_an_error_if_default_resources_are_invalid(
) {
let errors = RelaychainConfigBuilder::new()
.with_chain("chain")
.with_default_command("command")
.with_default_resources(|default_resources| {
default_resources
.with_limit_memory("100m")
.with_request_cpu("invalid")
})
.with_node(|node| {
node.with_name("node")
.with_command("command")
.validator(true)
})
.build()
.unwrap_err();
assert_eq!(errors.len(), 1);
assert_eq!(
errors.get(0).unwrap().to_string(),
r"relaychain.default_resources.request_cpu: 'invalid' doesn't match regex '^\d+(.\d+)?(m|K|M|G|T|P|E|Ki|Mi|Gi|Ti|Pi|Ei)?$'"
);
}
#[test]
fn relaychain_config_builder_with_default_command_should_fails_and_returns_an_error_if_first_node_is_invalid(
) {
let errors = RelaychainConfigBuilder::new()
.with_chain("chain")
.with_default_command("command")
.with_node(|node| {
node.with_name("node")
.with_command("invalid command")
.validator(true)
})
.build()
.unwrap_err();
assert_eq!(errors.len(), 1);
assert_eq!(
errors.get(0).unwrap().to_string(),
"relaychain.nodes['node'].command: 'invalid command' shouldn't contains whitespace"
);
}
#[test]
fn relaychain_config_builder_with_at_least_one_node_should_fails_and_returns_an_error_if_second_node_is_invalid(
) {
......
......@@ -73,4 +73,7 @@ pub enum ConversionError {
#[error("'{}' doesn't match regex '{}'", .value, .regex)]
DoesntMatchRegex { value: String, regex: String },
#[error("can't be empty")]
CantBeEmpty,
}
......@@ -23,6 +23,10 @@ impl TryFrom<&str> for Chain {
return Err(ConversionError::ContainsWhitespaces(value.to_string()));
}
if value.is_empty() {
return Err(ConversionError::CantBeEmpty);
}
Ok(Self(value.to_string()))
}
}
......@@ -272,6 +276,17 @@ mod tests {
);
}
#[test]
fn converting_an_empty_str_into_a_chain_should_fails() {
let got: Result<Chain, ConversionError> = "".try_into();
assert!(matches!(
got.clone().unwrap_err(),
ConversionError::CantBeEmpty
));
assert_eq!(got.unwrap_err().to_string(), "can't be empty");
}
#[test]
fn converting_a_str_containing_only_ip_into_an_image_should_fails() {
let got: Result<Image, ConversionError> = "127.0.0.1".try_into();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment