From cff8cf7047edd5f78fb0c6b3101831e64a539241 Mon Sep 17 00:00:00 2001 From: dkijania Date: Wed, 11 Mar 2020 11:34:20 +0100 Subject: [PATCH] jcli retirement test case --- .../jcli_wrapper/certificate/commands.rs | 13 ++++++ .../jcli_wrapper/certificate/wrapper.rs | 19 ++++---- .../src/jcli/certificate/mod.rs | 1 + .../src/jcli/certificate/retirement.rs | 43 +++++++++++++++++++ .../src/jormungandr/explorer/mod.rs | 5 +-- .../src/mock/testing/client_tests.rs | 1 - 6 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 jormungandr-integration-tests/src/jcli/certificate/retirement.rs diff --git a/jormungandr-integration-tests/src/common/jcli_wrapper/certificate/commands.rs b/jormungandr-integration-tests/src/common/jcli_wrapper/certificate/commands.rs index a8d7cfe04c..aebebaa103 100644 --- a/jormungandr-integration-tests/src/common/jcli_wrapper/certificate/commands.rs +++ b/jormungandr-integration-tests/src/common/jcli_wrapper/certificate/commands.rs @@ -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, diff --git a/jormungandr-integration-tests/src/common/jcli_wrapper/certificate/wrapper.rs b/jormungandr-integration-tests/src/common/jcli_wrapper/certificate/wrapper.rs index 2fdca6c845..fb08bdb1da 100644 --- a/jormungandr-integration-tests/src/common/jcli_wrapper/certificate/wrapper.rs +++ b/jormungandr-integration-tests/src/common/jcli_wrapper/certificate/wrapper.rs @@ -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 { @@ -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 } } diff --git a/jormungandr-integration-tests/src/jcli/certificate/mod.rs b/jormungandr-integration-tests/src/jcli/certificate/mod.rs index 087349751c..541447a3bc 100644 --- a/jormungandr-integration-tests/src/jcli/certificate/mod.rs +++ b/jormungandr-integration-tests/src/jcli/certificate/mod.rs @@ -1 +1,2 @@ pub mod e2e; +pub mod retirement; diff --git a/jormungandr-integration-tests/src/jcli/certificate/retirement.rs b/jormungandr-integration-tests/src/jcli/certificate/retirement.rs new file mode 100644 index 0000000000..f3408d8149 --- /dev/null +++ b/jormungandr-integration-tests/src/jcli/certificate/retirement.rs @@ -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::(); + let kes = create_new_key_pair::(); + let vrf = create_new_key_pair::(); + + 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()) +} diff --git a/jormungandr-integration-tests/src/jormungandr/explorer/mod.rs b/jormungandr-integration-tests/src/jormungandr/explorer/mod.rs index 20519ffd60..bc8d299bcf 100644 --- a/jormungandr-integration-tests/src/jormungandr/explorer/mod.rs +++ b/jormungandr-integration-tests/src/jormungandr/explorer/mod.rs @@ -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, }; diff --git a/jormungandr-integration-tests/src/mock/testing/client_tests.rs b/jormungandr-integration-tests/src/mock/testing/client_tests.rs index 23da0952ce..9daccaab25 100644 --- a/jormungandr-integration-tests/src/mock/testing/client_tests.rs +++ b/jormungandr-integration-tests/src/mock/testing/client_tests.rs @@ -5,7 +5,6 @@ use crate::mock::{ use crate::common::{ jcli_wrapper, - jcli_wrapper::JCLITransactionWrapper, jormungandr::{ConfigurationBuilder, Starter}, startup, transaction_utils::TransactionHash,