Files
pezkuwi-sdk/pezkuwi/tests/benchmark_block.rs
T
pezkuwichain abc4c3989b style: Migrate to stable-only rustfmt configuration
- Remove nightly-only features from .rustfmt.toml and vendor/ss58-registry/rustfmt.toml
- Removed features: imports_granularity, wrap_comments, comment_width,
  reorder_impl_items, spaces_around_ranges, binop_separator,
  match_arm_blocks, trailing_semicolon, trailing_comma
- Format all 898 affected files with stable rustfmt
- Ensures long-term reliability without nightly toolchain dependency
2025-12-23 09:37:11 +03:00

104 lines
3.0 KiB
Rust

// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
#![allow(deprecated)]
// Unix only since it uses signals.
#![cfg(unix)]
#[allow(deprecated)]
use assert_cmd::cargo::cargo_bin;
use common::run_with_timeout;
use nix::{
sys::signal::{kill, Signal::SIGINT},
unistd::Pid,
};
use std::{
path::Path,
process::{self, Command},
result::Result,
time::Duration,
};
use tempfile::tempdir;
pub mod common;
static RUNTIMES: &[&str] = &["zagros", "pezkuwichain"];
/// `benchmark block` works for all dev runtimes using the wasm executor.
#[tokio::test]
async fn benchmark_block_works() {
for runtime in RUNTIMES {
run_with_timeout(Duration::from_secs(10 * 60), async move {
let tmp_dir = tempdir().expect("could not create a temp dir");
let base_path = tmp_dir.path();
let runtime = format!("{}-dev", runtime);
// Build a chain with a single block.
build_chain(&runtime, base_path).await;
// Benchmark the one block.
benchmark_block(&runtime, base_path, 1).unwrap();
})
.await
}
}
/// Builds a chain with one block for the given runtime and base path.
async fn build_chain(runtime: &str, base_path: &Path) {
let mut cmd = Command::new(cargo_bin("pezkuwi"))
.stdout(process::Stdio::piped())
.stderr(process::Stdio::piped())
.args([
"--chain",
runtime,
"--force-authoring",
"--alice",
"--unsafe-force-node-key-generation",
])
.arg("-d")
.arg(base_path)
.arg("--no-hardware-benchmarks")
.spawn()
.unwrap();
let (ws_url, _) = common::find_ws_url_from_output(cmd.stderr.take().unwrap());
// Wait for the chain to produce one block.
common::wait_n_finalized_blocks(1, &ws_url).await;
// Send SIGINT to node.
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
assert!(cmd.wait().unwrap().success());
}
/// Benchmarks the given block with the wasm executor.
fn benchmark_block(runtime: &str, base_path: &Path, block: u32) -> Result<(), String> {
// Invoke `benchmark block` with all options to make sure that they are valid.
let status = Command::new(cargo_bin("pezkuwi"))
.args(["benchmark", "block", "--chain", runtime])
.arg("-d")
.arg(base_path)
.args(["--from", &block.to_string(), "--to", &block.to_string()])
.args(["--repeat", "1"])
.args(["--wasm-execution", "compiled"])
.status()
.map_err(|e| format!("command failed: {:?}", e))?;
if !status.success() {
return Err("Command failed".into());
}
Ok(())
}