Skip to content

Commit

Permalink
Move compile-time CCTL_CHAINSPEC and CCTL_CONFIG to runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
koxu1996 committed Jul 25, 2024
1 parent 7b5f29d commit 10a3f78
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
8 changes: 4 additions & 4 deletions kairos-cli/src/commands/run_cctl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use casper_client_types::{runtime_args, RuntimeArgs};
use kairos_test_utils::cctl::{CCTLNetwork, DeployableContract};
Expand All @@ -16,10 +16,10 @@ pub fn run() -> Result<String, CliError> {
path: contract_wasm_path,
};
println!("Deploying contract...");
let chainspec_path = Path::new(env!("CCTL_CHAINSPEC"));
let config_path = Path::new(env!("CCTL_CONFIG"));
let chainspec_path = PathBuf::from(std::env::var("CCTL_CHAINSPEC").unwrap());
let config_path = PathBuf::from(std::env::var("CCTL_CONFIG").unwrap());

let network = CCTLNetwork::run(None, Some(contract_to_deploy), Some(chainspec_path), Some(config_path))
let network = CCTLNetwork::run(None, Some(contract_to_deploy), Some(chainspec_path.as_path()), Some(config_path.as_path()))
.await
.unwrap();

Expand Down
14 changes: 10 additions & 4 deletions kairos-test-utils/src/cctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ impl CCTLNetwork {
chainspec_path: Option<&Path>,
config_path: Option<&Path>,
) -> anyhow::Result<CCTLNetwork> {
let chainspec_path = chainspec_path.unwrap_or_else(|| Path::new(env!("CCTL_CHAINSPEC")));
let config_path = config_path.unwrap_or_else(|| Path::new(env!("CCTL_CONFIG")));
let chainspec_path: String = chainspec_path
.map(|p| p.to_str().unwrap().to_owned())
.ok_or_else(|| std::env::var("CCTL_CHAINSPEC"))
.unwrap();
let config_path: String = config_path
.map(|p| p.to_str().unwrap().to_owned())
.ok_or_else(|| std::env::var("CCTL_CONFIG"))
.unwrap();

let working_dir = working_dir
.map(|dir| {
Expand All @@ -92,9 +98,9 @@ impl CCTLNetwork {
let mut setup_command = Command::new("cctl-infra-net-setup");
setup_command.env("CCTL_ASSETS", &assets_dir);

setup_command.arg(format!("chainspec={}", chainspec_path.to_str().unwrap()));
setup_command.arg(format!("chainspec={}", chainspec_path));

setup_command.arg(format!("config={}", config_path.to_str().unwrap()));
setup_command.arg(format!("config={}", config_path));

tracing::info!("Setting up network configuration");
let output = setup_command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ async fn test_cctl_deploys_a_contract_successfully() {
path: contract_wasm_path,
};

let chainspec = Path::new(env!("CCTL_CHAINSPEC"));
let config = Path::new(env!("CCTL_CONFIG"));
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),
Some(config),
Some(chainspec.as_path()),
Some(config.as_path()),
)
.await
.unwrap();
Expand Down
17 changes: 11 additions & 6 deletions kairos-test-utils/tests/test_cctl_network_starts_and_terminates.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::path::PathBuf;

use casper_client::{get_node_status, rpcs::results::ReactorState, JsonRpcId, Verbosity};
use kairos_test_utils::cctl::{CCTLNetwork, NodeState};
Expand All @@ -16,12 +16,17 @@ fn tracing_init() {
async fn test_cctl_network_starts_and_terminates() {
tracing_init();

let chainspec = Path::new(env!("CCTL_CHAINSPEC"));
let config = Path::new(env!("CCTL_CONFIG"));
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), Some(config))
.await
.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 {
Expand Down

0 comments on commit 10a3f78

Please sign in to comment.