Skip to content

Commit

Permalink
kairos-test-utils/kairos: start kairos with a contract hash
Browse files Browse the repository at this point in the history
  • Loading branch information
marijanp committed Jun 22, 2024
1 parent 6ed37a2 commit 226b0fa
Show file tree
Hide file tree
Showing 4 changed files with 12 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 kairos-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ assert_cmd = "2"
predicates = "3"
kairos-test-utils = { path = "../kairos-test-utils" }
casper-client-hashing.workspace = true
casper-types.workspace = true
8 changes: 3 additions & 5 deletions kairos-cli/tests/cli_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use assert_cmd::Command;
use reqwest::Url;
use std::fs;
use std::path::PathBuf;

use casper_client::types::DeployHash;
Expand Down Expand Up @@ -40,10 +39,9 @@ async fn deposit_successful_with_ed25519() {
))
.unwrap();

let contract_hash_path = network.working_dir.join("contracts").join(hash_name);
let contract_hash_string = fs::read_to_string(contract_hash_path).unwrap();
let contract_hash = network.get_contract_hash_for(hash_name);

let kairos = kairos::Kairos::run(casper_rpc_url, casper_sse_url)
let kairos = kairos::Kairos::run(casper_rpc_url, casper_sse_url, Some(contract_hash))
.await
.unwrap();

Expand All @@ -57,7 +55,7 @@ async fn deposit_successful_with_ed25519() {
.arg(kairos.url.as_str())
.arg("deposit")
.arg("--contract-hash")
.arg(contract_hash_string)
.arg(contract_hash.to_string())
.arg("--amount")
.arg("123")
.arg("--private-key")
Expand Down
10 changes: 7 additions & 3 deletions kairos-test-utils/src/kairos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ pub struct Kairos {
}

impl Kairos {
pub async fn run(casper_rpc: Url, casper_sse: Url) -> Result<Kairos, io::Error> {
pub async fn run(
casper_rpc: Url,
casper_sse: Url,
kairos_demo_contract_hash: Option<ContractHash>,
) -> Result<Kairos, io::Error> {
let socket_addr = TcpListener::bind("0.0.0.0:0")?.local_addr()?;
let port = socket_addr.port().to_string();
let url = Url::parse(&format!("http://0.0.0.0:{}", port)).unwrap();
let config = kairos_server::config::ServerConfig {
socket_addr,
casper_rpc,
casper_sse,
kairos_demo_contract_hash: ContractHash::default(),
kairos_demo_contract_hash: kairos_demo_contract_hash.unwrap_or_default(),
};

let process_handle = tokio::spawn(async move {
Expand Down Expand Up @@ -57,6 +61,6 @@ mod tests {
async fn test_kairos_starts_and_terminates() {
let dummy_rpc = Url::parse("http://127.0.0.1:11101/rpc").unwrap();
let dummy_sse = Url::parse("http://127.0.0.1:11101/events/main").unwrap();
let _kairos = Kairos::run(dummy_rpc, dummy_sse).await.unwrap();
let _kairos = Kairos::run(dummy_rpc, dummy_sse, None).await.unwrap();
}
}

0 comments on commit 226b0fa

Please sign in to comment.