Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alindima committed Dec 19, 2024
1 parent e103ea2 commit 48b8105
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions polkadot/zombienet-sdk-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ zombienet-sdk = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
codec = { workspace = true, features = ["derive"] }
polkadot-primitives = { workspace = true, default-features = true }

[features]
zombie-metadata = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::helpers::{
polkadot_runtime_parachains::assigner_coretime::PartsOf57600,
},
};
use polkadot_primitives::Id as ParaId;
use serde_json::json;
use subxt::{OnlineClient, PolkadotConfig};
use subxt_signer::sr25519::dev;
Expand Down Expand Up @@ -122,7 +123,9 @@ async fn basic_3cores_test() -> Result<(), anyhow::Error> {
assert_para_throughput(
&relay_client,
15,
[(2000, 40..46), (2001, 12..16)].into_iter().collect(),
[(ParaId::from(2000), 40..46), (ParaId::from(2001), 12..16)]
.into_iter()
.collect(),
)
.await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::helpers::{
polkadot_runtime_parachains::assigner_coretime::PartsOf57600,
},
};
use polkadot_primitives::{CoreIndex, Id as ParaId};
use serde_json::json;
use std::collections::{BTreeMap, VecDeque};
use subxt::{OnlineClient, PolkadotConfig};
use subxt_signer::sr25519::dev;
use zombienet_sdk::NetworkConfigBuilder;
Expand Down Expand Up @@ -98,14 +100,33 @@ async fn doesnt_break_parachains_test() -> Result<(), anyhow::Error> {

log::info!("1 more core assigned to the parachain");

let para_id = ParaId::from(2000);
// Expect the parachain to be making normal progress, 1 candidate backed per relay chain block.
assert_para_throughput(&relay_client, 15, [(2000, 13..16)].into_iter().collect()).await?;
assert_para_throughput(&relay_client, 15, [(para_id, 13..16)].into_iter().collect()).await?;

let para_client = para_node.wait_client().await?;
// Assert the parachain finalized block height is also on par with the number of backed
// candidates.
assert_finalized_block_height(&para_client, 12..16).await?;

// Sanity check that indeed the parachain has two assigned cores.
let cq = relay_client
.runtime_api()
.at_latest()
.await?
.call_raw::<BTreeMap<CoreIndex, VecDeque<ParaId>>>("ParachainHost_claim_queue", None)
.await?;

assert_eq!(
cq,
[
(CoreIndex(0), [para_id, para_id].into_iter().collect()),
(CoreIndex(1), [para_id, para_id].into_iter().collect()),
]
.into_iter()
.collect()
);

log::info!("Test finished successfully");

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::helpers::{
polkadot_runtime_parachains::assigner_coretime::PartsOf57600,
},
};
use polkadot_primitives::Id as ParaId;
use serde_json::json;
use subxt::{OnlineClient, PolkadotConfig};
use subxt_signer::sr25519::dev;
Expand Down Expand Up @@ -156,7 +157,9 @@ async fn slot_based_3cores_test() -> Result<(), anyhow::Error> {
assert_para_throughput(
&relay_client,
15,
[(2100, 39..46), (2200, 39..46)].into_iter().collect(),
[(ParaId::from(2100), 39..46), (ParaId::from(2200), 39..46)]
.into_iter()
.collect(),
)
.await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use anyhow::anyhow;

use crate::helpers::{assert_finalized_block_height, assert_para_throughput};
use polkadot_primitives::Id as ParaId;
use serde_json::json;
use subxt::{OnlineClient, PolkadotConfig};
use zombienet_sdk::NetworkConfigBuilder;
Expand Down Expand Up @@ -78,7 +79,9 @@ async fn async_backing_6_seconds_rate_test() -> Result<(), anyhow::Error> {
assert_para_throughput(
&relay_client,
15,
[(2000, 11..16), (2001, 11..16)].into_iter().collect(),
[(ParaId::from(2000), 11..16), (ParaId::from(2001), 11..16)]
.into_iter()
.collect(),
)
.await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use anyhow::anyhow;

use crate::helpers::{assert_finalized_block_height, assert_para_throughput};
use polkadot_primitives::Id as ParaId;
use serde_json::json;
use subxt::{OnlineClient, PolkadotConfig};
use zombienet_sdk::NetworkConfigBuilder;
Expand Down Expand Up @@ -60,7 +61,8 @@ async fn sync_backing_test() -> Result<(), anyhow::Error> {

let relay_client: OnlineClient<PolkadotConfig> = relay_node.wait_client().await?;

assert_para_throughput(&relay_client, 15, [(2000, 6..9)].into_iter().collect()).await?;
assert_para_throughput(&relay_client, 15, [(ParaId::from(2000), 6..9)].into_iter().collect())
.await?;

// Assert the parachain finalized block height is also on par with the number of backed
// candidates.
Expand Down
7 changes: 4 additions & 3 deletions polkadot/zombienet-sdk-tests/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

use polkadot_primitives::Id as ParaId;
use std::{collections::HashMap, ops::Range};
use subxt::{OnlineClient, PolkadotConfig};

Expand All @@ -12,10 +13,10 @@ pub mod rococo {}
pub async fn assert_para_throughput(
relay_client: &OnlineClient<PolkadotConfig>,
stop_at: u32,
expected_candidate_ranges: HashMap<u32, Range<u32>>,
expected_candidate_ranges: HashMap<ParaId, Range<u32>>,
) -> Result<(), anyhow::Error> {
let mut blocks_sub = relay_client.blocks().subscribe_finalized().await?;
let mut candidate_count: HashMap<u32, u32> = HashMap::new();
let mut candidate_count: HashMap<ParaId, u32> = HashMap::new();
let mut current_block_count = 0;
let mut had_first_session_change = false;

Expand All @@ -33,7 +34,7 @@ pub async fn assert_para_throughput(
current_block_count += 1;

for event in events.find::<rococo::para_inclusion::events::CandidateBacked>() {
*(candidate_count.entry(event?.0.descriptor.para_id.0).or_default()) += 1;
*(candidate_count.entry(event?.0.descriptor.para_id.0.into()).or_default()) += 1;
}
}

Expand Down

0 comments on commit 48b8105

Please sign in to comment.