Skip to content

Commit 5f8bfa1

Browse files
authored
switch polkadot zombienet-sdk tests to use cumulus test helpers (paritytech#7993)
paritytech#7988. The coretime-revenue test is the one remaining which uses static data types from the metadata for rococo and coretime-rococo. That test does some quite intricate event decoding which actually benefits from having static data types. Rewriting it using only dynamic types would actually be counterproductive and would complicate it
1 parent 98c6ffc commit 5f8bfa1

File tree

16 files changed

+92
-276
lines changed

16 files changed

+92
-276
lines changed

.github/workflows/build-publish-images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ jobs:
313313
uses: actions/checkout@v4
314314
- name: build
315315
run: |
316-
forklift cargo nextest --manifest-path polkadot/zombienet-sdk-tests/Cargo.toml archive --locked --features zombie-metadata --archive-file polkadot-zombienet-tests.tar.zst
316+
forklift cargo nextest --manifest-path polkadot/zombienet-sdk-tests/Cargo.toml archive --locked --features zombie-metadata,zombie-ci --archive-file polkadot-zombienet-tests.tar.zst
317317
- name: pack artifacts
318318
run: |
319319
mkdir -p artifacts

.gitlab/pipeline/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ build-polkadot-zombienet-tests:
131131
artifacts: true
132132

133133
script:
134-
- cargo nextest --manifest-path polkadot/zombienet-sdk-tests/Cargo.toml archive --features zombie-metadata --archive-file polkadot-zombienet-tests.tar.zst
134+
- cargo nextest --manifest-path polkadot/zombienet-sdk-tests/Cargo.toml archive --features zombie-metadata,zombie-ci --archive-file polkadot-zombienet-tests.tar.zst
135135
- mkdir -p artifacts
136136
- cp polkadot-zombienet-tests.tar.zst ./artifacts
137137

cumulus/zombienet/zombienet-sdk-helpers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ serde = { workspace = true }
1616
serde_json = { workspace = true }
1717
subxt = { workspace = true, features = ["native"] }
1818
subxt-signer = { workspace = true }
19-
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
19+
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "time"] }
2020

cumulus/zombienet/zombienet-sdk-helpers/src/lib.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use subxt::{
1212
blocks::Block, events::Events, ext::scale_value::value, tx::DynamicPayload, utils::H256,
1313
OnlineClient, PolkadotConfig,
1414
};
15-
use tokio::join;
15+
use tokio::{
16+
join,
17+
time::{sleep, Duration},
18+
};
1619

1720
// Maximum number of blocks to wait for a session change.
1821
// If it does not arrive for whatever reason, we should not wait forever.
@@ -234,7 +237,7 @@ pub async fn assert_para_throughput(
234237
/// Wait for the first block with a session change.
235238
///
236239
/// The session change is detected by inspecting the events in the block.
237-
async fn wait_for_first_session_change(
240+
pub async fn wait_for_first_session_change(
238241
blocks_sub: &mut subxt::backend::StreamOfResults<
239242
Block<PolkadotConfig, OnlineClient<PolkadotConfig>>,
240243
>,
@@ -277,3 +280,25 @@ pub async fn assert_finality_lag(
277280
assert!(finality_lag <= maximum_lag, "Expected finality to lag by a maximum of {maximum_lag} blocks, but was lagging by {finality_lag} blocks.");
278281
Ok(())
279282
}
283+
284+
/// Assert that finality has not stalled.
285+
pub async fn assert_blocks_are_being_finalized(
286+
client: &OnlineClient<PolkadotConfig>,
287+
) -> Result<(), anyhow::Error> {
288+
let mut finalized_blocks = client.blocks().subscribe_finalized().await?;
289+
let first_measurement = finalized_blocks
290+
.next()
291+
.await
292+
.ok_or(anyhow::anyhow!("Can't get finalized block from stream"))??
293+
.number();
294+
sleep(Duration::from_secs(12)).await;
295+
let second_measurement = finalized_blocks
296+
.next()
297+
.await
298+
.ok_or(anyhow::anyhow!("Can't get finalized block from stream"))??
299+
.number();
300+
301+
assert!(second_measurement > first_measurement);
302+
303+
Ok(())
304+
}

polkadot/zombienet-sdk-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ zombienet-sdk = { workspace = true }
2424

2525
[features]
2626
zombie-metadata = []
27+
zombie-ci = []
2728

2829
[build-dependencies]
2930
substrate-build-script-utils = { workspace = true, default-features = true }

polkadot/zombienet-sdk-tests/build.rs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ fn make_env_key(k: &str) -> String {
2727

2828
fn wasm_sub_path(chain: &str) -> String {
2929
let (package, runtime_name) =
30-
if let Some(cumulus_test_runtime) = chain.strip_prefix("cumulus-test-runtime-") {
31-
(
32-
"cumulus-test-runtime".to_string(),
33-
format!("wasm_binary_{}.rs", replace_dashes(cumulus_test_runtime)),
34-
)
35-
} else {
36-
(format!("{chain}-runtime"), replace_dashes(&format!("{chain}-runtime")))
37-
};
30+
(format!("{chain}-runtime"), replace_dashes(&format!("{chain}-runtime")));
3831

3932
format!("{}/{}.wasm", package, runtime_name)
4033
}
@@ -61,11 +54,7 @@ fn find_wasm(chain: &str) -> Option<PathBuf> {
6154

6255
// based on https://gist.github.com/s0me0ne-unkn0wn/bbd83fe32ce10327086adbf13e750eec
6356
fn build_wasm(chain: &str) -> PathBuf {
64-
let package = if chain.starts_with("cumulus-test-runtime-") {
65-
String::from("cumulus-test-runtime")
66-
} else {
67-
format!("{chain}-runtime")
68-
};
57+
let package = format!("{chain}-runtime");
6958

7059
let cargo = env::var("CARGO").unwrap();
7160
let target = env::var("TARGET").unwrap();
@@ -132,10 +121,6 @@ fn main() {
132121
const METADATA_DIR: &str = "metadata-files";
133122
const CHAINS: [&str; 2] = ["rococo", "coretime-rococo"];
134123

135-
// Add some cumulus test runtimes if needed. Formatted like
136-
// "cumulus-test-runtime-elastic-scaling".
137-
const CUMULUS_TEST_RUNTIMES: [&str; 0] = [];
138-
139124
let metadata_path = format!("{manifest_path}/{METADATA_DIR}");
140125

141126
for chain in CHAINS {
@@ -153,21 +138,6 @@ fn main() {
153138
};
154139
}
155140

156-
for chain in CUMULUS_TEST_RUNTIMES {
157-
let full_path = format!("{metadata_path}/{chain}-local.scale");
158-
let output_path = path::PathBuf::from(&full_path);
159-
160-
match output_path.try_exists() {
161-
Ok(true) => {
162-
debug_output!("got: {}", full_path);
163-
},
164-
_ => {
165-
debug_output!("needs: {}", full_path);
166-
fetch_metadata_file(chain, &output_path);
167-
},
168-
};
169-
}
170-
171141
substrate_build_script_utils::generate_cargo_keys();
172142
substrate_build_script_utils::rerun_if_git_head_changed();
173143
println!("cargo:rerun-if-changed={}", metadata_path);

polkadot/zombienet-sdk-tests/tests/disabling/slashing.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
//! making some of the honest nodes go offline.
77
88
use anyhow::anyhow;
9-
10-
use crate::helpers::{assert_blocks_are_being_finalized, assert_para_throughput};
9+
use cumulus_zombienet_sdk_helpers::{
10+
assert_blocks_are_being_finalized, assert_finalized_para_throughput,
11+
wait_for_first_session_change,
12+
};
1113
use polkadot_primitives::{BlockNumber, CandidateHash, DisputeState, Id as ParaId, SessionIndex};
1214
use serde_json::json;
1315
use subxt::{OnlineClient, PolkadotConfig};
@@ -87,8 +89,12 @@ async fn dispute_past_session_slashing() -> Result<(), anyhow::Error> {
8789
let relay_client: OnlineClient<PolkadotConfig> = honest.wait_client().await?;
8890

8991
// Wait for some para blocks being produced
90-
assert_para_throughput(&relay_client, 20, [(ParaId::from(1337), 10..20)].into_iter().collect())
91-
.await?;
92+
assert_finalized_para_throughput(
93+
&relay_client,
94+
20,
95+
[(ParaId::from(1337), 10..20)].into_iter().collect(),
96+
)
97+
.await?;
9298

9399
// Let's initiate a dispute
94100
malus.resume().await?;
@@ -119,16 +125,7 @@ async fn dispute_past_session_slashing() -> Result<(), anyhow::Error> {
119125
assert_ne!(dispute_session, u32::MAX, "dispute should be initiated");
120126
log::info!("Dispute initiated, now waiting for a new session");
121127

122-
while let Some(block) = best_blocks.next().await {
123-
let current_session = relay_client
124-
.runtime_api()
125-
.at(block?.hash())
126-
.call_raw::<SessionIndex>("ParachainHost_session_index_for_child", None)
127-
.await?;
128-
if current_session > dispute_session {
129-
break
130-
}
131-
}
128+
wait_for_first_session_change(&mut best_blocks).await?;
132129

133130
// We don't need malus anymore
134131
malus.pause().await?;

polkadot/zombienet-sdk-tests/tests/elastic_scaling/basic_3cores.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55
// can achieve full throughput of 3 candidates per block.
66

77
use anyhow::anyhow;
8-
9-
use crate::helpers::{
10-
assert_para_throughput, rococo,
11-
rococo::runtime_types::{
12-
pallet_broker::coretime_interface::CoreAssignment,
13-
polkadot_runtime_parachains::assigner_coretime::PartsOf57600,
14-
},
15-
};
8+
use cumulus_zombienet_sdk_helpers::{assert_finalized_para_throughput, create_assign_core_call};
169
use polkadot_primitives::Id as ParaId;
1710
use serde_json::json;
1811
use subxt::{OnlineClient, PolkadotConfig};
@@ -84,30 +77,7 @@ async fn basic_3cores_test() -> Result<(), anyhow::Error> {
8477
relay_client
8578
.tx()
8679
.sign_and_submit_then_watch_default(
87-
&rococo::tx()
88-
.sudo()
89-
.sudo(rococo::runtime_types::rococo_runtime::RuntimeCall::Utility(
90-
rococo::runtime_types::pallet_utility::pallet::Call::batch {
91-
calls: vec![
92-
rococo::runtime_types::rococo_runtime::RuntimeCall::Coretime(
93-
rococo::runtime_types::polkadot_runtime_parachains::coretime::pallet::Call::assign_core {
94-
core: 0,
95-
begin: 0,
96-
assignment: vec![(CoreAssignment::Task(2000), PartsOf57600(57600))],
97-
end_hint: None
98-
}
99-
),
100-
rococo::runtime_types::rococo_runtime::RuntimeCall::Coretime(
101-
rococo::runtime_types::polkadot_runtime_parachains::coretime::pallet::Call::assign_core {
102-
core: 1,
103-
begin: 0,
104-
assignment: vec![(CoreAssignment::Task(2000), PartsOf57600(57600))],
105-
end_hint: None
106-
}
107-
),
108-
],
109-
},
110-
)),
80+
&create_assign_core_call(&[(0, 2000), (1, 2000)]),
11181
&alice,
11282
)
11383
.await?
@@ -116,7 +86,7 @@ async fn basic_3cores_test() -> Result<(), anyhow::Error> {
11686

11787
log::info!("2 more cores assigned to adder-2000");
11888

119-
assert_para_throughput(
89+
assert_finalized_para_throughput(
12090
&relay_client,
12191
15,
12292
[(ParaId::from(2000), 40..46), (ParaId::from(2001), 12..16)]

polkadot/zombienet-sdk-tests/tests/elastic_scaling/doesnt_break_parachains.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
// itself if ElasticScalingMVP feature is enabled in genesis.
66

77
use anyhow::anyhow;
8-
9-
use crate::helpers::{
10-
assert_finalized_block_height, assert_para_throughput, rococo,
11-
rococo::runtime_types::{
12-
pallet_broker::coretime_interface::CoreAssignment,
13-
polkadot_runtime_parachains::assigner_coretime::PartsOf57600,
14-
},
8+
use cumulus_zombienet_sdk_helpers::{
9+
assert_finality_lag, assert_finalized_para_throughput, create_assign_core_call,
1510
};
1611
use polkadot_primitives::{CoreIndex, Id as ParaId};
1712
use serde_json::json;
@@ -77,19 +72,7 @@ async fn doesnt_break_parachains_test() -> Result<(), anyhow::Error> {
7772

7873
relay_client
7974
.tx()
80-
.sign_and_submit_then_watch_default(
81-
&rococo::tx()
82-
.sudo()
83-
.sudo(rococo::runtime_types::rococo_runtime::RuntimeCall::Coretime(
84-
rococo::runtime_types::polkadot_runtime_parachains::coretime::pallet::Call::assign_core {
85-
core: 0,
86-
begin: 0,
87-
assignment: vec![(CoreAssignment::Task(2000), PartsOf57600(57600))],
88-
end_hint: None
89-
}
90-
)),
91-
&alice,
92-
)
75+
.sign_and_submit_then_watch_default(&create_assign_core_call(&[(0, 2000)]), &alice)
9376
.await?
9477
.wait_for_finalized_success()
9578
.await?;
@@ -98,12 +81,13 @@ async fn doesnt_break_parachains_test() -> Result<(), anyhow::Error> {
9881

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

10387
let para_client = para_node.wait_client().await?;
10488
// Assert the parachain finalized block height is also on par with the number of backed
10589
// candidates.
106-
assert_finalized_block_height(&para_client, 12..16).await?;
90+
assert_finality_lag(&para_client, 5).await?;
10791

10892
// Sanity check that indeed the parachain has two assigned cores.
10993
let cq = relay_client

polkadot/zombienet-sdk-tests/tests/functional/async_backing_6_seconds_rate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use anyhow::anyhow;
77

8-
use crate::helpers::{assert_finalized_block_height, assert_para_throughput};
8+
use cumulus_zombienet_sdk_helpers::{assert_finality_lag, assert_finalized_para_throughput};
99
use polkadot_primitives::Id as ParaId;
1010
use serde_json::json;
1111
use subxt::{OnlineClient, PolkadotConfig};
@@ -73,7 +73,7 @@ async fn async_backing_6_seconds_rate_test() -> Result<(), anyhow::Error> {
7373

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

76-
assert_para_throughput(
76+
assert_finalized_para_throughput(
7777
&relay_client,
7878
15,
7979
[(ParaId::from(2000), 11..16), (ParaId::from(2001), 11..16)]
@@ -84,7 +84,7 @@ async fn async_backing_6_seconds_rate_test() -> Result<(), anyhow::Error> {
8484

8585
// Assert the parachain finalized block height is also on par with the number of backed
8686
// candidates. We can only do this for the collator based on cumulus.
87-
assert_finalized_block_height(&para_node_2001.wait_client().await?, 10..16).await?;
87+
assert_finality_lag(&para_node_2001.wait_client().await?, 5).await?;
8888

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

0 commit comments

Comments
 (0)