Skip to content

Commit

Permalink
add clirunner trait methods to run cardano cli
Browse files Browse the repository at this point in the history
adds methods to the `clirunner` trait to allow interaction with the cardano cli from the mithril project. the methods are `launch_utxo`, `launch_stake_distribution`, `launch_stake_snapshot`, `launch_stake_snapshot_all_pools`, `launch_epoch` and `launch_kes_period`.
  • Loading branch information
falcucci committed Nov 21, 2023
1 parent 18357fb commit 214f457
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mithril-common/src/chain_observer/cli_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ use crate::crypto_helper::{KESPeriod, OpCert, SerDeShelleyFileFormat};
use crate::entities::{Epoch, StakeDistribution};
use crate::{CardanoNetwork, StdResult};

/// `CliRunner` trait defines the asynchronous methods
/// for interaction with the Cardano CLI.
#[async_trait]
pub trait CliRunner {
/// launches a UTxO.
async fn launch_utxo(&self, address: &str) -> StdResult<String>;
/// launches the stake distribution.
async fn launch_stake_distribution(&self) -> StdResult<String>;
/// launches the stake snapshot.
async fn launch_stake_snapshot(&self, stake_pool_id: &str) -> StdResult<String>;
/// launches the stake snapshot for all pools.
async fn launch_stake_snapshot_all_pools(&self) -> StdResult<String>;
/// launches the epoch info.
async fn launch_epoch(&self) -> StdResult<String>;
/// launches the kes period.
async fn launch_kes_period(&self, opcert_file: &str) -> StdResult<String>;
}

Expand Down
6 changes: 6 additions & 0 deletions mithril-common/src/test_utils/test_cli_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Default for TestCliRunner {

#[async_trait]
impl CliRunner for TestCliRunner {
/// launches a UTxO.
async fn launch_utxo(&self, _address: &str) -> StdResult<String> {
let output = r#"
{
Expand Down Expand Up @@ -60,6 +61,7 @@ impl CliRunner for TestCliRunner {
Ok(output.to_string())
}

/// launches the stake distribution.
async fn launch_stake_distribution(&self) -> StdResult<String> {
let output = r#"
PoolId Stake frac
Expand All @@ -77,6 +79,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
Ok(output.to_string())
}

/// launches the stake snapshot.
async fn launch_stake_snapshot(&self, stake_pool_id: &str) -> StdResult<String> {
let mut output = r#"
{
Expand Down Expand Up @@ -104,6 +107,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
Ok(output.to_string())
}

/// launches the stake snapshot for all pools.
async fn launch_stake_snapshot_all_pools(&self) -> StdResult<String> {
let output = r#"
{
Expand Down Expand Up @@ -145,6 +149,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
}
}

/// launches the epoch info.
async fn launch_epoch(&self) -> StdResult<String> {
let output = r#"
{
Expand All @@ -159,6 +164,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
Ok(output.to_string())
}

/// launches the kes period.
async fn launch_kes_period(&self, _opcert_file: &str) -> StdResult<String> {
let output = r#"
✓ The operational certificate counter agrees with the node protocol state counter
Expand Down

0 comments on commit 214f457

Please sign in to comment.