From 480fcc933d86b8d33ac0a45c422a5706f82141d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 26 Aug 2024 11:15:17 +0200 Subject: [PATCH] kairos-test-utils: remove cctl --- Cargo.lock | 15 - kairos-test-utils/Cargo.toml | 19 - kairos-test-utils/bin/cctld.rs | 48 --- kairos-test-utils/src/cctl.rs | 391 ------------------ kairos-test-utils/src/cctl/parsers.rs | 228 ---------- kairos-test-utils/src/lib.rs | 1 - ...st_cctl_deploys_a_contract_successfully.rs | 50 --- ...test_cctl_network_starts_and_terminates.rs | 43 -- 8 files changed, 795 deletions(-) delete mode 100644 kairos-test-utils/bin/cctld.rs delete mode 100644 kairos-test-utils/src/cctl.rs delete mode 100644 kairos-test-utils/src/cctl/parsers.rs delete mode 100644 kairos-test-utils/tests/test_cctl_deploys_a_contract_successfully.rs delete mode 100644 kairos-test-utils/tests/test_cctl_network_starts_and_terminates.rs diff --git a/Cargo.lock b/Cargo.lock index c2e85b76..bce501fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2799,20 +2799,11 @@ dependencies = [ name = "kairos-test-utils" version = "0.1.0" dependencies = [ - "anyhow", "backoff", - "casper-client", "casper-types 3.0.0", - "casper-types 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "clap", - "dotenvy", - "hex", "kairos-server", - "nom", "percent-encoding", - "rand 0.8.5", "reqwest 0.12.4", - "sd-notify", "tempfile", "tokio", "tracing", @@ -4216,12 +4207,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" -[[package]] -name = "sd-notify" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4646d6f919800cd25c50edb49438a1381e2cd4833c027e75e8897981c50b8b5e" - [[package]] name = "sec1" version = "0.7.3" diff --git a/kairos-test-utils/Cargo.toml b/kairos-test-utils/Cargo.toml index 4df8218e..8c5a4516 100644 --- a/kairos-test-utils/Cargo.toml +++ b/kairos-test-utils/Cargo.toml @@ -4,40 +4,21 @@ version.workspace = true edition.workspace = true license.workspace = true -[[bin]] -name = "cctld" -path = "bin/cctld.rs" -version.workspace = true -test = false -bench = false - [features] -# FIXME enable cctl-tests once this crate is factored out in a separate repository -#all-tests = ["cctl-tests"] default = ["database"] all-tests = ["database"] -cctl-tests = [] database = ["kairos-server/database"] [lib] [dependencies] -anyhow = "1" backoff = { version = "0.4", features = ["tokio", "futures"]} -clap = { version = "4", features = ["derive"] } -casper-client.workspace = true -casper-types.workspace = true casper-client-types.workspace = true -nom = "7" -hex = "0.4" percent-encoding = "2.3" -rand = "0.8" -sd-notify = "0.4" tokio = { version = "1", features = [ "full", "tracing", "macros" ] } tempfile = "3" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["std", "env-filter"] } reqwest = { version = "0.12", features = ["json"] } kairos-server = { path = "../kairos-server" } -dotenvy = "0.15" diff --git a/kairos-test-utils/bin/cctld.rs b/kairos-test-utils/bin/cctld.rs deleted file mode 100644 index 04362149..00000000 --- a/kairos-test-utils/bin/cctld.rs +++ /dev/null @@ -1,48 +0,0 @@ -use casper_client_types::{runtime_args, RuntimeArgs}; -use clap::Parser; -use kairos_test_utils::cctl; -use sd_notify::NotifyState; -use std::path::PathBuf; -use tokio::signal; - -use crate::cctl::DeployableContract; - -#[derive(Parser)] -pub struct Cli { - #[arg(short, long)] - pub working_dir: Option, - #[arg(short, long)] - pub deploy_contract: Option, - #[arg(short, long)] - pub chainspec_path: Option, - #[arg(short, long)] - pub config_path: Option, -} - -#[tokio::main] -async fn main() -> Result<(), Box> { - let cli = Cli::parse(); - let deploy_contract = cli.deploy_contract.map(|deploy_contracts_arg| { - match deploy_contracts_arg.split_once(':') { - Some((hash_name, path)) => DeployableContract { - hash_name: hash_name.to_string(), - // FIXME at some point we want to make this parametrizable - runtime_args: runtime_args! { "initial_trie_root" => Option::<[u8; 32]>::None }, - path: PathBuf::from(&path), - }, - None => panic!("Error parsing the provided deploy contracts argument."), - } - }); - let _network = cctl::CCTLNetwork::run( - cli.working_dir, - deploy_contract, - cli.chainspec_path.as_deref(), - cli.config_path.as_deref(), - ) - .await - .expect("An error occured while starting the CCTL network"); - - let _ = sd_notify::notify(true, &[NotifyState::Ready]); - signal::ctrl_c().await?; - Ok(()) -} diff --git a/kairos-test-utils/src/cctl.rs b/kairos-test-utils/src/cctl.rs deleted file mode 100644 index 0814033f..00000000 --- a/kairos-test-utils/src/cctl.rs +++ /dev/null @@ -1,391 +0,0 @@ -pub mod parsers; -use anyhow::anyhow; -use backoff::{future::retry, ExponentialBackoff}; -use casper_client::{ - get_account, get_deploy, get_node_status, get_state_root_hash, put_deploy, query_global_state, - rpcs::results::ReactorState, - types::{DeployBuilder, ExecutableDeployItem, StoredValue, TimeDiff, Timestamp}, - Error, JsonRpcId, Verbosity, -}; -use casper_client_types::{ContractHash, ExecutionResult, Key, PublicKey, RuntimeArgs, SecretKey}; -use hex::FromHex; -use std::io::{self, Write}; -use std::path::Path; -use std::path::PathBuf; -use std::process::Command; -use std::{fs, time::Instant}; -use tempfile::tempdir; - -#[derive(Debug, PartialEq, Clone, Copy)] -pub enum NodeState { - Running, - Stopped, -} - -#[derive(Debug, PartialEq, Clone, Copy)] -pub struct CasperNodePorts { - pub consensus_port: u16, - pub rpc_port: u16, - pub rest_port: u16, - pub sse_port: u16, - pub speculative_exec_port: u16, -} - -pub struct CasperNode { - pub id: u8, - pub validator_group_id: u8, - pub state: NodeState, - pub port: CasperNodePorts, -} - -pub struct CCTLNetwork { - pub working_dir: PathBuf, - pub nodes: Vec, -} - -pub struct DeployableContract { - /// This is the named key under which the contract hash is located - pub hash_name: String, - pub runtime_args: RuntimeArgs, - pub path: PathBuf, -} - -pub fn casper_client_verbosity() -> Verbosity { - if tracing::enabled!(tracing::Level::TRACE) { - Verbosity::High - } else if tracing::enabled!(tracing::Level::DEBUG) { - Verbosity::Medium - } else { - Verbosity::Low - } -} - -// max amount allowed to be used on gas fees -pub const MAX_GAS_FEE_PAYMENT_AMOUNT: u64 = 10_000_000_000_000; - -impl CCTLNetwork { - /// Spins up a CCTL network, and deploys a contract if provided - /// - /// If a chain spec and config path are not provided, the environment variables `CCTL_CHAINSPEC` and `CCTL_CONFIG` are used. - /// - /// WARNING: do not use this function in unit tests, only sequentially executed integration tests. - /// Ensure that two instances of this function are not running at the same time even in different processes. - pub async fn run( - working_dir: Option, - contract_to_deploy: Option, - chainspec_path: Option<&Path>, - config_path: Option<&Path>, - ) -> anyhow::Result { - let chainspec_path: String = chainspec_path - .map(|p| p.to_str().unwrap().to_owned()) - .unwrap_or_else(|| std::env::var("CCTL_CHAINSPEC").unwrap()); - let config_path: String = config_path - .map(|p| p.to_str().unwrap().to_owned()) - .unwrap_or_else(|| std::env::var("CCTL_CONFIG").unwrap()); - - let working_dir = working_dir - .map(|dir| { - std::fs::create_dir_all(&dir) - .expect("Failed to create the provided working directory"); - dir - }) - .unwrap_or(tempdir()?.into_path()); - let assets_dir = working_dir.join("assets"); - tracing::info!("Working directory: {:?}", working_dir); - - let mut setup_command = Command::new("cctl-infra-net-setup"); - setup_command.env("CCTL_ASSETS", &assets_dir); - - setup_command.arg(format!("chainspec={}", chainspec_path)); - - setup_command.arg(format!("config={}", config_path)); - - tracing::info!("Setting up network configuration"); - let output = setup_command - .output() - .expect("Failed to setup network configuration"); - let output = std::str::from_utf8(output.stdout.as_slice()).unwrap(); - tracing::info!("{}", output); - - let output = Command::new("cctl-infra-net-start") - .env("CCTL_ASSETS", &assets_dir) - .output() - .expect("Failed to start network"); - let output = std::str::from_utf8(output.stdout.as_slice()).unwrap(); - tracing::info!("{}", output); - let (_, nodes) = parsers::parse_cctl_infra_net_start_lines(output).unwrap(); - - let output = Command::new("cctl-infra-node-view-ports") - .env("CCTL_ASSETS", &assets_dir) - .output() - .expect("Failed to get the networks node ports"); - let output = std::str::from_utf8(output.stdout.as_slice()).unwrap(); - tracing::info!("{}", output); - let (_, node_ports) = parsers::parse_cctl_infra_node_view_port_lines(output).unwrap(); - - // Match the started nodes with their respective ports - let nodes: Vec = nodes - .into_iter() - .map(|(validator_group_id, node_id, state)| { - if let Some(&(_, port)) = node_ports - .iter() - .find(|(node_id_ports, _)| *node_id_ports == node_id) - { - CasperNode { - validator_group_id, - state, - id: node_id, - port, - } - } else { - panic!("Can't find ports for node with id {}", node_id) - } - }) - .collect(); - - let node_port = nodes.first().unwrap().port.rpc_port; - let casper_node_rpc_url = format!("http://localhost:{}/rpc", node_port); - - let start_time = Instant::now(); - tracing::info!("Waiting for network to pass genesis"); - retry(ExponentialBackoff::default(), || async { - // This prevents retrying forever even after ctrl-c - let timed_out = start_time.elapsed().as_secs() > 90; - - get_node_status( - JsonRpcId::Number(1), - &casper_node_rpc_url, - casper_client_verbosity(), - ) - .await - .map_err(|err| { - let elapsed = start_time.elapsed().as_secs(); - tracing::info!("Running for {elapsed}s, Error: {err:?}"); - err - }) - .map_err(|err| match &err { - err if timed_out => backoff::Error::permanent(anyhow!("Timeout on error: {err:?}")), - Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { - backoff::Error::transient(anyhow!(err)) - } - _ => backoff::Error::permanent(anyhow!(err)), - }) - .map(|success| match success.result.reactor_state { - ReactorState::Validate => Ok(()), - // _ if timed_out => Ok(()), - rs if timed_out => Err(backoff::Error::permanent(anyhow!( - "Node didn't reach the VALIDATE state before timeout: {rs:?}" - ))), - _ => Err(backoff::Error::transient(anyhow!( - "Node didn't reach the VALIDATE state yet" - ))), - })? - }) - .await - .expect("Waiting for network to pass genesis failed"); - - tracing::info!("Waiting for block 1"); - let output = Command::new("cctl-chain-await-until-block-n") - .env("CCTL_ASSETS", &assets_dir) - .arg("height=1") - .output() - .expect("Waiting for network to start processing blocks failed"); - let output = std::str::from_utf8(output.stdout.as_slice()).unwrap(); - tracing::info!("{}", output); - - if let Some(contract_to_deploy) = contract_to_deploy { - let deployer_skey = - SecretKey::from_file(working_dir.join("assets/users/user-1/secret_key.pem"))?; - let deployer_pkey = - PublicKey::from_file(working_dir.join("assets/users/user-1/public_key.pem"))?; - - let (hash_name, contract_hash) = deploy_contract( - &casper_node_rpc_url, - &deployer_skey, - &deployer_pkey, - &contract_to_deploy, - ) - .await?; - let contracts_dir = working_dir.join("contracts"); - fs::create_dir_all(&contracts_dir)?; - fs::write( - contracts_dir.join(hash_name), - // For a ContractHash contract- will always be the prefix - contract_hash - .to_formatted_string() - .strip_prefix("contract-") - .unwrap(), - )? - } - Ok(CCTLNetwork { working_dir, nodes }) - } - /// Get the deployed contract hash for a hash_name that was passed to new_contract - /// https://docs.rs/casper-contract/latest/casper_contract/contract_api/storage/fn.new_contract.html - pub fn get_contract_hash_for(&self, hash_name: &str) -> ContractHash { - let contract_hash_path = self.working_dir.join("contracts").join(hash_name); - let contract_hash_string = fs::read_to_string(contract_hash_path).unwrap(); - let contract_hash_bytes = <[u8; 32]>::from_hex(contract_hash_string).unwrap(); - ContractHash::new(contract_hash_bytes) - } -} - -impl Drop for CCTLNetwork { - fn drop(&mut self) { - let output = Command::new("cctl-infra-net-stop") - .env("CCTL_ASSETS", &self.working_dir.join("assets")) - .output() - .expect("Failed to stop the network"); - io::stdout().write_all(&output.stdout).unwrap(); - io::stderr().write_all(&output.stderr).unwrap(); - } -} - -/// Deploys a contract as the given user for the contract's defined hash name located at the path. -/// The hash name should be equal to the hash name passed to https://docs.rs/casper-contract/latest/casper_contract/contract_api/storage/fn.new_locked_contract.html -async fn deploy_contract( - casper_node_rpc_url: &str, - contract_deployer_skey: &SecretKey, - contract_deployer_pkey: &PublicKey, - DeployableContract { - hash_name, - runtime_args, - path, - }: &DeployableContract, -) -> anyhow::Result<(String, casper_client_types::ContractHash)> { - tracing::info!( - "Deploying contract {}: {}", - &hash_name, - path.to_str().unwrap() - ); - - let casper_client_verbosity = casper_client_verbosity(); - - let contract_bytes = fs::read(path)?; - let contract = - ExecutableDeployItem::new_module_bytes(contract_bytes.into(), runtime_args.clone()); - let deploy = DeployBuilder::new( - // TODO ideally make the chain-name this configurable - "cspr-dev-cctl", - contract, - contract_deployer_skey, - ) - .with_standard_payment(MAX_GAS_FEE_PAYMENT_AMOUNT) // max amount allowed to be used on gas fees - .with_timestamp(Timestamp::now()) - .with_ttl(TimeDiff::from_millis(60_000)) // 1 min - .build()?; - - tracing::info!("Submitting contract deploy"); - let deploy_hash = put_deploy( - JsonRpcId::Number(1), - casper_node_rpc_url, - casper_client_verbosity, - deploy, - ) - .await - .map_err(Into::::into) - .map(|response| response.result.deploy_hash)?; - - tracing::info!("Waiting for successful contract initialization"); - let start = Instant::now(); - retry(ExponentialBackoff::default(), || async { - let timed_out = start.elapsed().as_secs() > 60; - - let response = get_deploy( - JsonRpcId::Number(1), - casper_node_rpc_url, - casper_client_verbosity, - deploy_hash, - false, - ) - .await - .map_err(|err| { - let elapsed = start.elapsed().as_secs(); - tracing::info!("Running for {elapsed}s, Error: {err:?}"); - err - }) - .map_err(|err| match &err { - e if timed_out => backoff::Error::permanent(anyhow!("Timeout on error: {e:?}")), - Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { - backoff::Error::transient(anyhow!(err)) - } - _ => backoff::Error::permanent(anyhow!(err)), - })?; - - match response.result.execution_results.first() { - Some(result) => match &result.result { - ExecutionResult::Failure { error_message, .. } => { - Err(backoff::Error::permanent(anyhow!(error_message.clone()))) - } - ExecutionResult::Success { .. } => Ok(()), - }, - None if timed_out => Err(backoff::Error::permanent(anyhow!( - "Timeout on error: No execution results" - ))), - None => Err(backoff::Error::transient(anyhow!( - "No execution results there yet" - ))), - } - }) - .await?; - tracing::info!("Contract was deployed successfully"); - - tracing::info!("Fetching deployed contract hash"); - // Query global state - let state_root_hash = get_state_root_hash( - JsonRpcId::Number(1), - casper_node_rpc_url, - casper_client_verbosity, - Option::None, - ) - .await - .map_err(Into::::into) - .and_then(|response| { - response - .result - .state_root_hash - .ok_or(anyhow!("No state root hash present in response")) - })?; - - let account = get_account( - JsonRpcId::Number(1), - casper_node_rpc_url, - casper_client_verbosity, - Option::None, - contract_deployer_pkey.clone(), - ) - .await - .map_err(Into::::into) - .map(|response| response.result.account)?; - - let account_key = Key::Account(*account.account_hash()); - let contract_hash: casper_client_types::ContractHash = query_global_state( - JsonRpcId::Number(1), - casper_node_rpc_url, - casper_client_verbosity, - casper_client::rpcs::GlobalStateIdentifier::StateRootHash(state_root_hash), // fetches recent blocks state root hash - account_key, - vec![hash_name.clone()], - ) - .await - .map_err(Into::::into) - .and_then(|response| match response.result.stored_value { - StoredValue::ContractPackage(contract_package) => Ok(*contract_package - .versions() - .next() - .expect("Expected at least one contract version") - .contract_hash()), - other => Err(anyhow!( - "Unexpected result type, type is not a CLValue: {:?}", - other - )), - })?; - tracing::info!( - "Successfully fetched the contract hash for {}: {}", - &hash_name, - &contract_hash - ); - Ok::<(String, casper_client_types::ContractHash), anyhow::Error>(( - hash_name.clone(), - contract_hash, - )) -} diff --git a/kairos-test-utils/src/cctl/parsers.rs b/kairos-test-utils/src/cctl/parsers.rs deleted file mode 100644 index b5699318..00000000 --- a/kairos-test-utils/src/cctl/parsers.rs +++ /dev/null @@ -1,228 +0,0 @@ -use super::{CasperNodePorts, NodeState}; - -use nom::{ - branch::alt, - bytes::complete::tag, - character::complete::{multispace0, not_line_ending, space1}, - combinator::map, - multi::separated_list0, - sequence::tuple, - IResult, -}; - -pub fn parse_node_state(input: &str) -> IResult<&str, NodeState> { - alt(( - map(tag("RUNNING"), |_| NodeState::Running), - map(tag("STOPPED"), |_| NodeState::Stopped), - ))(input) -} - -pub fn parse_cctl_infra_net_start_line(input: &str) -> IResult<&str, (u8, u8, NodeState)> { - let (remainder, (_, _, group_id, _, node_id, _, status, _)) = tuple(( - multispace0, - tag("validator-group-"), - nom::character::complete::u8, - tag(":cctl-node-"), - nom::character::complete::u8, - space1, - parse_node_state, - not_line_ending, - ))(input)?; - - Ok((remainder, (group_id, node_id, status))) -} - -pub fn parse_cctl_infra_net_start_lines(input: &str) -> IResult<&str, Vec<(u8, u8, NodeState)>> { - let (remainder, _) = nom::bytes::complete::take_until("validator-group")(input)?; - separated_list0(tag("\n"), parse_cctl_infra_net_start_line)(remainder) -} - -pub fn parse_cctl_infra_node_view_port_line(input: &str) -> IResult<&str, (u8, CasperNodePorts)> { - let ( - remainder, - ( - _, - _, - group_id, - _, - consensus_port, - _, - rpc_port, - _, - rest_port, - _, - sse_port, - _, - speculative_exec_port, - _, - ), - ) = tuple(( - nom::bytes::complete::take_until("node-"), - tag("node-"), - nom::character::complete::u8, - tag(" -> CONSENSUS @ "), - nom::character::complete::u16, - tag(" :: RPC @ "), - nom::character::complete::u16, - tag(" :: REST @ "), - nom::character::complete::u16, - tag(" :: SSE @ "), - nom::character::complete::u16, - tag(" :: SPECULATIVE_EXEC @ "), - nom::character::complete::u16, - not_line_ending, - ))(input)?; - - Ok(( - remainder, - ( - group_id, - CasperNodePorts { - consensus_port, - rpc_port, - rest_port, - sse_port, - speculative_exec_port, - }, - ), - )) -} - -pub fn parse_cctl_infra_node_view_port_lines( - input: &str, -) -> IResult<&str, Vec<(u8, CasperNodePorts)>> { - separated_list0(tag("\n"), parse_cctl_infra_node_view_port_line)(input) -} - -#[cfg(test)] -mod tests { - use super::*; - use anyhow::Error; - #[test] - fn test_parse_cctl_infra_net_start_line() -> Result<(), Error> { - let input = "validator-group-1:cctl-node-1 RUNNING pid 428229, uptime 0:09:06\n"; - let (_, parsed) = parse_cctl_infra_net_start_line(input)?; - Ok(assert_eq!((1, 1, NodeState::Running), parsed)) - } - #[test] - fn test_parse_cctl_infra_net_start_lines() -> Result<(), Error> { - let input = r#" - 2024-02-06T14:06:43.332420 [INFO] [431123] CCTL :: network spin up begins ... please wait - 2024-02-06T14:06:43.334599 [INFO] [431123] CCTL :: ... starting network - 2024-02-06T14:06:43.337054 [INFO] [431123] CCTL :: ... ... genesis bootstrap nodes - 2024-02-06T14:06:44.445527 [INFO] [431123] CCTL :: ... ... genesis non-bootstrap nodes - validator-group-1:cctl-node-1 RUNNING pid 428229, uptime 0:09:06 - validator-group-1:cctl-node-2 RUNNING pid 428230, uptime 0:09:06 - validator-group-1:cctl-node-3 RUNNING pid 428231, uptime 0:09:06 - validator-group-2:cctl-node-4 RUNNING pid 428296, uptime 0:09:05 - validator-group-2:cctl-node-5 RUNNING pid 428297, uptime 0:09:05 - validator-group-3:cctl-node-10 STOPPED Not started - validator-group-3:cctl-node-6 STOPPED Not started - validator-group-3:cctl-node-7 STOPPED Not started - validator-group-3:cctl-node-8 STOPPED Not started - validator-group-3:cctl-node-9 STOPPED Not started - "#; - let (_, parsed) = parse_cctl_infra_net_start_lines(input)?; - let expected = vec![ - (1, 1, NodeState::Running), - (1, 2, NodeState::Running), - (1, 3, NodeState::Running), - (2, 4, NodeState::Running), - (2, 5, NodeState::Running), - (3, 10, NodeState::Stopped), - (3, 6, NodeState::Stopped), - (3, 7, NodeState::Stopped), - (3, 8, NodeState::Stopped), - (3, 9, NodeState::Stopped), - ]; - Ok(assert_eq!(expected, parsed)) - } - #[test] - fn test_parse_cctl_infra_node_view_port_line() -> Result<(), Error> { - let input = "2024-02-06T17:28:10.731821 [INFO] [514427] CCTL :: node-1 -> CONSENSUS @ 22101 :: RPC @ 11101 :: REST @ 14101 :: SSE @ 18101 :: SPECULATIVE_EXEC @ 25101"; - let (_, parsed) = parse_cctl_infra_node_view_port_line(input)?; - Ok(assert_eq!( - ( - 1, - CasperNodePorts { - consensus_port: 22101, - rpc_port: 11101, - rest_port: 14101, - sse_port: 18101, - speculative_exec_port: 25101 - } - ), - parsed - )) - } - #[test] - fn test_parse_cctl_infra_node_view_port_lines() -> Result<(), Error> { - let input = r#" - 2024-02-06T17:28:10.728367 [INFO] [514427] CCTL :: ------------------------------------------------------------------------------------------------------ - 2024-02-06T17:28:10.731821 [INFO] [514427] CCTL :: node-1 -> CONSENSUS @ 22101 :: RPC @ 11101 :: REST @ 14101 :: SSE @ 18101 :: SPECULATIVE_EXEC @ 25101 - 2024-02-06T17:28:10.732997 [INFO] [514427] CCTL :: ------------------------------------------------------------------------------------------------------ - 2024-02-06T17:28:10.737211 [INFO] [514427] CCTL :: node-2 -> CONSENSUS @ 22102 :: RPC @ 11102 :: REST @ 14102 :: SSE @ 18102 :: SPECULATIVE_EXEC @ 25102 - 2024-02-06T17:28:10.738952 [INFO] [514427] CCTL :: ------------------------------------------------------------------------------------------------------ - 2024-02-06T17:28:10.742946 [INFO] [514427] CCTL :: node-3 -> CONSENSUS @ 22103 :: RPC @ 11103 :: REST @ 14103 :: SSE @ 18103 :: SPECULATIVE_EXEC @ 25103 - 2024-02-06T17:28:10.744218 [INFO] [514427] CCTL :: ------------------------------------------------------------------------------------------------------ - 2024-02-06T17:28:10.748632 [INFO] [514427] CCTL :: node-4 -> CONSENSUS @ 22104 :: RPC @ 11104 :: REST @ 14104 :: SSE @ 18104 :: SPECULATIVE_EXEC @ 25104 - 2024-02-06T17:28:10.749922 [INFO] [514427] CCTL :: ------------------------------------------------------------------------------------------------------ - 2024-02-06T17:28:10.754162 [INFO] [514427] CCTL :: node-5 -> CONSENSUS @ 22105 :: RPC @ 11105 :: REST @ 14105 :: SSE @ 18105 :: SPECULATIVE_EXEC @ 25105 - 2024-02-06T17:28:10.755567 [INFO] [514427] CCTL :: ------------------------------------------------------------------------------------------------------ - "#; - let (_, parsed) = parse_cctl_infra_node_view_port_lines(input)?; - let expected = vec![ - ( - 1, - CasperNodePorts { - consensus_port: 22101, - rpc_port: 11101, - rest_port: 14101, - sse_port: 18101, - speculative_exec_port: 25101, - }, - ), - ( - 2, - CasperNodePorts { - consensus_port: 22102, - rpc_port: 11102, - rest_port: 14102, - sse_port: 18102, - speculative_exec_port: 25102, - }, - ), - ( - 3, - CasperNodePorts { - consensus_port: 22103, - rpc_port: 11103, - rest_port: 14103, - sse_port: 18103, - speculative_exec_port: 25103, - }, - ), - ( - 4, - CasperNodePorts { - consensus_port: 22104, - rpc_port: 11104, - rest_port: 14104, - sse_port: 18104, - speculative_exec_port: 25104, - }, - ), - ( - 5, - CasperNodePorts { - consensus_port: 22105, - rpc_port: 11105, - rest_port: 14105, - sse_port: 18105, - speculative_exec_port: 25105, - }, - ), - ]; - Ok(assert_eq!(expected, parsed)) - } -} diff --git a/kairos-test-utils/src/lib.rs b/kairos-test-utils/src/lib.rs index 424bb913..0eefee5a 100644 --- a/kairos-test-utils/src/lib.rs +++ b/kairos-test-utils/src/lib.rs @@ -1,3 +1,2 @@ -pub mod cctl; pub mod kairos; pub mod postgres; diff --git a/kairos-test-utils/tests/test_cctl_deploys_a_contract_successfully.rs b/kairos-test-utils/tests/test_cctl_deploys_a_contract_successfully.rs deleted file mode 100644 index 648756fd..00000000 --- a/kairos-test-utils/tests/test_cctl_deploys_a_contract_successfully.rs +++ /dev/null @@ -1,50 +0,0 @@ -use casper_types::ContractHash; -use hex::FromHex; -use kairos_test_utils::cctl::CCTLNetwork; -use std::fs; -use std::path::PathBuf; - -use casper_client_types::{runtime_args, RuntimeArgs}; -use kairos_test_utils::cctl::DeployableContract; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; - -fn tracing_init() { - let _ = tracing_subscriber::registry() - .with(EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into())) - .with(tracing_subscriber::fmt::layer()) - .try_init(); -} - -#[cfg_attr(not(feature = "cctl-tests"), ignore)] -#[tokio::test] -async fn test_cctl_deploys_a_contract_successfully() { - tracing_init(); - - let contract_wasm_path = - PathBuf::from(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); - let hash_name = "kairos_contract_package_hash"; - let contract_to_deploy = DeployableContract { - hash_name: hash_name.to_string(), - runtime_args: runtime_args! { "initial_trie_root" => Option::<[u8; 32]>::None }, - path: contract_wasm_path, - }; - - let chainspec = PathBuf::from(std::env::var("CCTL_CHAINSPEC").unwrap()); - let config = PathBuf::from(std::env::var("CCTL_CONFIG").unwrap()); - - let network = CCTLNetwork::run( - None, - Some(contract_to_deploy), - Some(chainspec.as_path()), - Some(config.as_path()), - ) - .await - .unwrap(); - let expected_contract_hash_path = network.working_dir.join("contracts").join(hash_name); - assert!(expected_contract_hash_path.exists()); - - let hash_string = fs::read_to_string(expected_contract_hash_path).unwrap(); - let contract_hash_bytes = <[u8; 32]>::from_hex(hash_string).unwrap(); - let contract_hash = ContractHash::new(contract_hash_bytes); - assert!(contract_hash.to_formatted_string().starts_with("contract-")) -} diff --git a/kairos-test-utils/tests/test_cctl_network_starts_and_terminates.rs b/kairos-test-utils/tests/test_cctl_network_starts_and_terminates.rs deleted file mode 100644 index 64044748..00000000 --- a/kairos-test-utils/tests/test_cctl_network_starts_and_terminates.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::path::PathBuf; - -use casper_client::{get_node_status, rpcs::results::ReactorState, JsonRpcId, Verbosity}; -use kairos_test_utils::cctl::{CCTLNetwork, NodeState}; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; - -fn tracing_init() { - let _ = tracing_subscriber::registry() - .with(EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into())) - .with(tracing_subscriber::fmt::layer()) - .try_init(); -} - -#[cfg_attr(not(feature = "cctl-tests"), ignore)] -#[tokio::test] -async fn test_cctl_network_starts_and_terminates() { - tracing_init(); - - let chainspec = PathBuf::from(std::env::var("CCTL_CHAINSPEC").unwrap()); - let config = PathBuf::from(std::env::var("CCTL_CONFIG").unwrap()); - - let network = CCTLNetwork::run( - None, - None, - Some(chainspec.as_path()), - Some(config.as_path()), - ) - .await - .unwrap(); - - for node in &network.nodes { - if node.state == NodeState::Running { - let node_status = get_node_status( - JsonRpcId::Number(1), - &format!("http://localhost:{}", node.port.rpc_port), - Verbosity::High, - ) - .await - .unwrap(); - assert_eq!(node_status.result.reactor_state, ReactorState::Validate); - } - } -}