Skip to content

Commit

Permalink
Merge pull request #1903 from input-output-hk/jcli_retirement
Browse files Browse the repository at this point in the history
[Tests] jcli retirement test case
  • Loading branch information
NicolasDP authored Mar 11, 2020
2 parents b3b87c9 + cff8cf7 commit 6bed447
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ impl CertificateCommands {
command
}

pub fn get_retire_command(&self, stake_pool_id: &str, retirement_time: u64) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command
.arg("certificate")
.arg("new")
.arg("stake-pool-retirement")
.arg("--pool-id")
.arg(&stake_pool_id)
.arg("--retirement-time")
.arg(&retirement_time.to_string());
command
}

pub fn get_stake_pool_registration_command(
&self,
kes_key: &str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ use crate::common::{
file_assert, file_utils, process_assert,
process_utils::{self, output_extensions::ProcessOutput},
};
use chain_impl_mockchain::{
certificate::PoolId, testing::builders::cert_builder::build_stake_pool_retirement_cert,
};
use std::{path::PathBuf, str::FromStr};

use jormungandr_lib::interfaces::{Certificate, TaxType};
use jormungandr_lib::interfaces::TaxType;
use std::path::PathBuf;

#[derive(Debug)]
pub struct JCLICertificateWrapper {
Expand Down Expand Up @@ -142,9 +138,12 @@ impl JCLICertificateWrapper {
}

pub fn assert_new_stake_pool_retirement(&self, stake_pool_id: &str) -> String {
let pool_id = PoolId::from_str(&stake_pool_id).unwrap();
let start_validity = 0u64;
let certificate = build_stake_pool_retirement_cert(pool_id, start_validity);
format!("{}", Certificate::from(certificate).to_bech32().unwrap())
println!("Running create retirement certification...");
let output = process_utils::run_process_and_get_output(
self.commands.get_retire_command(&stake_pool_id, 0u64),
);
let certification = output.as_single_line();
process_assert::assert_process_exited_successfully(output);
certification
}
}
1 change: 1 addition & 0 deletions jormungandr-integration-tests/src/jcli/certificate/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod e2e;
pub mod retirement;
43 changes: 43 additions & 0 deletions jormungandr-integration-tests/src/jcli/certificate/retirement.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::common::{
file_assert, file_utils, jcli_wrapper::certificate::wrapper::JCLICertificateWrapper,
startup::create_new_key_pair,
};
use chain_crypto::{Curve25519_2HashDH, Ed25519, SumEd25519_12};
use chain_impl_mockchain::{
certificate::PoolId, testing::builders::cert_builder::build_stake_pool_retirement_cert,
};
use std::str::FromStr;

use jormungandr_lib::interfaces::Certificate;

#[test]
pub fn jcli_creates_correct_retirement_certificate() {
let owner = create_new_key_pair::<Ed25519>();
let kes = create_new_key_pair::<SumEd25519_12>();
let vrf = create_new_key_pair::<Curve25519_2HashDH>();

let certificate_wrapper = JCLICertificateWrapper::new();
let certificate = certificate_wrapper.assert_new_stake_pool_registration(
&kes.identifier().to_bech32_str(),
&vrf.identifier().to_bech32_str(),
0,
1,
&owner.identifier().to_bech32_str(),
None,
);

let input_file = file_utils::create_file_in_temp("certificate", &certificate);
let stake_pool_id = certificate_wrapper.assert_get_stake_pool_id(&input_file);

let expected_certificate = certificate_wrapper.assert_new_stake_pool_retirement(&stake_pool_id);
let actual_certificate = assert_new_stake_pool_retirement(&stake_pool_id);

assert_eq!(expected_certificate, actual_certificate);
}

pub fn assert_new_stake_pool_retirement(stake_pool_id: &str) -> String {
let pool_id = PoolId::from_str(&stake_pool_id).unwrap();
let start_validity = 0u64;
let certificate = build_stake_pool_retirement_cert(pool_id, start_validity);
format!("{}", Certificate::from(certificate).to_bech32().unwrap())
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::common::{
jcli_wrapper::{self, JCLITransactionWrapper},
jormungandr::ConfigurationBuilder,
process_utils::Wait,
startup,
jcli_wrapper, jormungandr::ConfigurationBuilder, process_utils::Wait, startup,
transaction_utils::TransactionHash,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::mock::{

use crate::common::{
jcli_wrapper,
jcli_wrapper::JCLITransactionWrapper,
jormungandr::{ConfigurationBuilder, Starter},
startup,
transaction_utils::TransactionHash,
Expand Down

0 comments on commit 6bed447

Please sign in to comment.