From 410e18cf51977879bb1e4b1d823537d39507b95c Mon Sep 17 00:00:00 2001 From: dkijania Date: Fri, 23 Oct 2020 19:08:53 +0200 Subject: [PATCH] draft --- .../src/common/jcli/api/address.rs | 139 +++++++++++++++ .../src/common/jcli/api/genesis.rs | 83 +++++++++ .../src/common/jcli/api/key.rs | 161 ++++++++++++++++++ .../src/common/jcli/api/mod.rs | 7 + .../common/jcli/command/address/account.rs | 30 ++++ .../src/common/jcli/command/address/info.rs | 20 +++ .../src/common/jcli/command/address/mod.rs | 35 ++++ .../src/common/jcli/command/address/single.rs | 35 ++++ .../src/common/jcli/command/genesis/decode.rs | 25 +++ .../src/common/jcli/command/genesis/encode.rs | 25 +++ .../src/common/jcli/command/genesis/hash.rs | 20 +++ .../src/common/jcli/command/genesis/mod.rs | 39 +++++ .../src/common/jcli/command/key/from_bytes.rs | 25 +++ .../src/common/jcli/command/key/generate.rs | 25 +++ .../src/common/jcli/command/key/mod.rs | 43 +++++ .../src/common/jcli/command/key/to_bytes.rs | 25 +++ .../src/common/jcli/command/key/to_public.rs | 25 +++ .../src/common/jcli/command/mod.rs | 34 ++++ .../src/common/jcli/mod.rs | 37 ++++ .../src/common/jcli_wrapper/jcli_commands.rs | 8 +- .../jcli_transaction_wrapper/mod.rs | 5 +- .../src/common/jcli_wrapper/mod.rs | 11 +- .../jormungandr/configuration_builder.rs | 9 +- .../src/common/mod.rs | 1 + .../src/common/startup/mod.rs | 5 +- .../src/jcli/address/account.rs | 24 +-- .../src/jcli/address/info.rs | 45 +++-- .../src/jcli/address/single.rs | 92 ++++++---- .../src/jcli/genesis/encode.rs | 34 ++-- .../src/jcli/genesis/hash.rs | 13 +- .../src/jcli/genesis/init.rs | 8 +- .../src/jcli/key/from_bytes.rs | 21 ++- .../src/jcli/key/generate.rs | 56 +++--- .../src/jcli/key/to_bytes.rs | 24 +-- .../src/jcli/key/to_public.rs | 16 +- .../src/jcli/transaction/e2e.rs | 20 ++- 36 files changed, 1071 insertions(+), 154 deletions(-) create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/api/address.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/api/genesis.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/api/key.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/api/mod.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/address/account.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/address/info.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/address/mod.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/address/single.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/genesis/decode.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/genesis/encode.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/genesis/hash.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/genesis/mod.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/key/from_bytes.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/key/generate.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/key/mod.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/key/to_bytes.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/key/to_public.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/command/mod.rs create mode 100644 testing/jormungandr-integration-tests/src/common/jcli/mod.rs diff --git a/testing/jormungandr-integration-tests/src/common/jcli/api/address.rs b/testing/jormungandr-integration-tests/src/common/jcli/api/address.rs new file mode 100644 index 0000000000..c3c2d3435d --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/api/address.rs @@ -0,0 +1,139 @@ +use crate::common::jcli::command::{AddressCommand, GenesisCommand}; +use assert_cmd::assert::OutputAssertExt; +use assert_fs::assert::PathAssert; +use assert_fs::fixture::ChildPath; +use chain_addr::Discrimination; +use jormungandr_lib::crypto::hash::Hash; +use jortestkit::prelude::ProcessOutput; +use std::str::FromStr; +use std::{collections::BTreeMap, path::Path}; +pub struct JCliAddress { + address_command: AddressCommand, +} + +impl JCliAddress { + pub fn new(address_command: AddressCommand) -> Self { + Self { address_command } + } + + pub fn info>(self, public_key: S) -> BTreeMap { + self.address_command + .info() + .address(public_key.into()) + .build() + .assert() + .success() + .get_output() + .as_single_node_yaml() + } + + pub fn account>( + self, + prefix: Option, + public_key: S, + discrimination: Discrimination, + ) -> String { + let mut address_command = self.address_command.account(); + + if let Some(prefix) = prefix { + address_command = address_command.prefix(prefix.into()); + } + + if discrimination == Discrimination::Test { + address_command = address_command.test_discrimination(); + } + + address_command + .public_key(public_key) + .build() + .assert() + .success() + .get_output() + .as_single_line() + } + + pub fn account_expect_fail>( + self, + prefix: Option, + public_key: S, + expected_msg: &str, + ) { + let mut address_command = self.address_command.account(); + + if let Some(prefix) = prefix { + address_command = address_command.prefix(prefix.into()); + } + + if discrimination == Discrimination::Test { + address_command = address_command.test_discrimination(); + } + + address_command + .public_key(public_key) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg)); + } + + pub fn info_expect_fail>(self, public_key: S, expected_msg: &str) { + self.address_command + .info() + .address(public_key.into()) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg)); + } + + pub fn single>( + self, + prefix: Option, + public_key: S, + discrimination: Discrimination, + ) -> String { + let mut address_command = self.address_command.single(); + + if let Some(prefix) = prefix { + address_command = address_command.prefix(prefix.into()); + } + + if discrimination == Discrimination::Test { + address_command = address_command.test_discrimination(); + } + + address_command + .public_key(public_key) + .build() + .assert() + .success() + .get_output() + .as_single_line() + } + + pub fn delegation, P: Into>( + mut self, + public_key: S, + delegation_key: P, + discrimination: Discrimination, + ) -> String { + let mut address_command = self.address_command.single(); + + if let Some(prefix) = prefix { + address_command = address_command.prefix(prefix.into()); + } + + if discrimination == Discrimination::Test { + address_command = address_command.test_discrimination(); + } + + address_command + .public_key(public_key) + .delegation_key(delegation_key) + .build() + .assert() + .success() + .get_output() + .as_single_line() + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/api/genesis.rs b/testing/jormungandr-integration-tests/src/common/jcli/api/genesis.rs new file mode 100644 index 0000000000..4f975e67d7 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/api/genesis.rs @@ -0,0 +1,83 @@ +use crate::common::jcli::command::GenesisCommand; +use assert_cmd::assert::OutputAssertExt; +use assert_fs::assert::PathAssert; +use assert_fs::fixture::ChildPath; +use jormungandr_lib::crypto::hash::Hash; +use jortestkit::prelude::ProcessOutput; +use std::path::Path; +use std::str::FromStr; +pub struct JCliGenesis { + genesis_command: GenesisCommand, +} + +impl JCliGenesis { + pub fn new(genesis_command: GenesisCommand) -> Self { + Self { genesis_command } + } + + pub fn decode>(self, input: P, output: &ChildPath) { + self.genesis_command + .decode() + .input(input) + .output(output.path()) + .build() + .assert() + .success(); + output.assert(crate::predicate::file_exists_and_not_empty()); + } + + pub fn encode>(self, input: P, output: &ChildPath) { + self.genesis_command + .encode() + .input(input) + .output(output.path()) + .build() + .assert() + .success(); + + output.assert(crate::predicate::file_exists_and_not_empty()); + } + + pub fn encode_expect_fail>(self, input: P, expected_msg: &str) { + self.genesis_command + .encode() + .input(input) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg)); + } + + pub fn hash>(self, input: P) -> Hash { + let hash = self + .genesis_command + .hash() + .input(input) + .build() + .assert() + .success() + .get_output() + .as_single_line(); + + Hash::from_str(&hash).unwrap() + } + + pub fn hash_expect_fail>(self, input: P, expected_msg: &str) { + self.genesis_command + .hash() + .input(input) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg)); + } + + pub fn init(self) -> String { + self.genesis_command + .init() + .assert() + .success() + .get_output() + .as_lossy_string() + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/api/key.rs b/testing/jormungandr-integration-tests/src/common/jcli/api/key.rs new file mode 100644 index 0000000000..7b5e0cd54e --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/api/key.rs @@ -0,0 +1,161 @@ +use crate::common::jcli::command::KeyCommand; +use assert_cmd::assert::OutputAssertExt; +use assert_fs::fixture::ChildPath; +use assert_fs::fixture::FileWriteStr; +use assert_fs::{assert::PathAssert, NamedTempFile}; +use jormungandr_lib::crypto::hash::Hash; +use jortestkit::prelude::ProcessOutput; +use std::path::Path; +use std::str::FromStr; +const DEFAULT_KEY_TYPE: &str = "Ed25519Extended"; + +pub struct JCliKey { + key_command: KeyCommand, +} + +impl JCliKey { + pub fn new(key_command: KeyCommand) -> Self { + Self { key_command } + } + + pub fn generate_default(self) -> String { + self.generate(DEFAULT_KEY_TYPE) + } + + pub fn generate>(self, key_type: S) -> String { + self.key_command + .generate() + .key_type(key_type.into()) + .build() + .assert() + .success() + .get_output() + .as_single_line() + } + + pub fn generate_expect_fail>(self, key_type: S, expected_msg_path: &str) { + self.key_command + .generate() + .key_type(key_type.into()) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg_path)); + } + + pub fn generate_with_seed>(self, key_type: S, seed: S) -> String { + self.key_command + .generate() + .key_type(key_type.into()) + .seed(seed.into()) + .build() + .assert() + .success() + .get_output() + .as_single_line() + } + + pub fn generate_with_seed_expect_fail>( + self, + key_type: S, + seed: S, + expected_msg_path: &str, + ) { + self.key_command + .generate() + .key_type(key_type.into()) + .seed(seed.into()) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg_path)); + } + + pub fn to_public>(self, private_key: S) -> String { + let input_file = NamedTempFile::new("key_to_public.input").unwrap(); + input_file.write_str(&private_key.into()).unwrap(); + + self.key_command + .to_public() + .input(input_file.path()) + .build() + .assert() + .success() + .get_output() + .as_single_line() + } + + pub fn to_public_expect_fail>(self, private_key: S, expected_msg_path: &str) { + let input_file = NamedTempFile::new("key_to_public.input").unwrap(); + input_file.write_str(&private_key.into()).unwrap(); + + self.key_command + .to_public() + .input(input_file.path()) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg_path)); + } + + pub fn to_bytes, P: AsRef>(self, private_key: S, output: P) { + let input = NamedTempFile::new("key_to_bytes.input").unwrap(); + input.write_str(&private_key.into()).unwrap(); + + self.to_bytes_from_file(input.path(), output.as_ref()) + } + + pub fn to_bytes_from_file, Q: AsRef>(self, input: P, output: Q) { + self.key_command + .to_bytes() + .output(output) + .input(input) + .build() + .assert() + .success(); + } + + pub fn to_bytes_expect_fail, Q: AsRef>( + self, + input: P, + output: Q, + expected_msg_path: &str, + ) { + self.key_command + .to_bytes() + .output(output) + .input(input) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg_path)); + } + + pub fn from_bytes, S: Into>(self, key_type: S, input: P) -> String { + self.key_command + .from_bytes() + .key_type(key_type) + .input(input) + .build() + .assert() + .success() + .get_output() + .as_single_line() + } + + pub fn from_bytes_expect_fail, S: Into>( + self, + key_type: S, + input: P, + expected_msg_path: &str, + ) { + self.key_command + .from_bytes() + .key_type(key_type) + .input(input) + .build() + .assert() + .failure() + .stderr(predicates::str::contains(expected_msg_path)); + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/api/mod.rs b/testing/jormungandr-integration-tests/src/common/jcli/api/mod.rs new file mode 100644 index 0000000000..7724e660e4 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/api/mod.rs @@ -0,0 +1,7 @@ +mod address; +mod genesis; +mod key; + +pub use address::JCliAddress; +pub use genesis::JCliGenesis; +pub use key::JCliKey; diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/address/account.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/address/account.rs new file mode 100644 index 0000000000..1355252679 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/address/account.rs @@ -0,0 +1,30 @@ +use std::path::Path; +use std::process::Command; +pub struct AccountCommand { + command: Command, +} + +impl AccountCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn public_key>(mut self, public_key: S) -> Self { + self.command.arg(public_key.into()); + self + } + + pub fn test_discrimination(mut self) -> Self { + self.command.arg("--testing"); + self + } + + pub fn prefix>(mut self, prefix: S) -> Self { + self.command.arg("--prefix").arg(prefix.into()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/address/info.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/address/info.rs new file mode 100644 index 0000000000..67656ff61f --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/address/info.rs @@ -0,0 +1,20 @@ +use std::path::Path; +use std::process::Command; +pub struct InfoCommand { + command: Command, +} + +impl InfoCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn address>(mut self, address: S) -> Self { + self.command.arg(address.into()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/address/mod.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/address/mod.rs new file mode 100644 index 0000000000..b861e058fa --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/address/mod.rs @@ -0,0 +1,35 @@ +mod account; +mod info; +mod single; + +pub use account::AccountCommand; +pub use info::InfoCommand; +pub use single::SingleCommand; + +use assert_cmd::assert::OutputAssertExt; +use jortestkit::prelude::ProcessOutput; +use std::process::Command; +pub struct AddressCommand { + command: Command, +} + +impl AddressCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn account(mut self) -> AccountCommand { + self.command.arg("account"); + AccountCommand::new(self.command) + } + + pub fn info(mut self) -> InfoCommand { + self.command.arg("info"); + InfoCommand::new(self.command) + } + + pub fn single(mut self) -> SingleCommand { + self.command.arg("single"); + SingleCommand::new(self.command) + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/address/single.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/address/single.rs new file mode 100644 index 0000000000..e517278b54 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/address/single.rs @@ -0,0 +1,35 @@ +use std::path::Path; +use std::process::Command; +pub struct SingleCommand { + command: Command, +} + +impl SingleCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn public_key>(mut self, public_key: S) -> Self { + self.command.arg(public_key.into()); + self + } + + pub fn test_discrimination(mut self) -> Self { + self.command.arg("--testing"); + self + } + + pub fn delegation_key>(mut self, delegation_key: S) -> Self { + self.command.arg(delegation_key.into()); + self + } + + pub fn prefix>(mut self, prefix: S) -> Self { + self.command.arg("--prefix").arg(prefix.into()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/decode.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/decode.rs new file mode 100644 index 0000000000..dcd8346cb4 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/decode.rs @@ -0,0 +1,25 @@ +use std::path::Path; +use std::process::Command; +pub struct GenesisDecodeCommand { + command: Command, +} + +impl GenesisDecodeCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn input>(mut self, input: P) -> Self { + self.command.arg("--input").arg(input.as_ref()); + self + } + + pub fn output>(mut self, output: P) -> Self { + self.command.arg("--output").arg(output.as_ref()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/encode.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/encode.rs new file mode 100644 index 0000000000..550d0d79a4 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/encode.rs @@ -0,0 +1,25 @@ +use std::path::Path; +use std::process::Command; +pub struct GenesisEncodeCommand { + command: Command, +} + +impl GenesisEncodeCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn input>(mut self, input: P) -> Self { + self.command.arg("--input").arg(input.as_ref()); + self + } + + pub fn output>(mut self, output: P) -> Self { + self.command.arg("--output").arg(output.as_ref()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/hash.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/hash.rs new file mode 100644 index 0000000000..fd72002872 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/hash.rs @@ -0,0 +1,20 @@ +use std::path::Path; +use std::process::Command; +pub struct GenesisHashCommand { + command: Command, +} + +impl GenesisHashCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn input>(mut self, input: P) -> Self { + self.command.arg("--input").arg(input.as_ref()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/mod.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/mod.rs new file mode 100644 index 0000000000..1472a0bdff --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/genesis/mod.rs @@ -0,0 +1,39 @@ +mod decode; +mod encode; +mod hash; + +use assert_cmd::assert::OutputAssertExt; +pub use decode::GenesisDecodeCommand; +pub use encode::GenesisEncodeCommand; +pub use hash::GenesisHashCommand; +use jortestkit::prelude::ProcessOutput; +use std::process::Command; +pub struct GenesisCommand { + command: Command, +} + +impl GenesisCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn encode(mut self) -> GenesisEncodeCommand { + self.command.arg("encode"); + GenesisEncodeCommand::new(self.command) + } + + pub fn decode(mut self) -> GenesisDecodeCommand { + self.command.arg("decode"); + GenesisDecodeCommand::new(self.command) + } + + pub fn hash(mut self) -> GenesisHashCommand { + self.command.arg("hash"); + GenesisHashCommand::new(self.command) + } + + pub fn init(mut self) -> Command { + self.command.arg("init"); + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/key/from_bytes.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/key/from_bytes.rs new file mode 100644 index 0000000000..65d44b8112 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/key/from_bytes.rs @@ -0,0 +1,25 @@ +use std::path::Path; +use std::process::Command; +pub struct KeyFromBytesCommand { + command: Command, +} + +impl KeyFromBytesCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn input>(mut self, input: P) -> Self { + self.command.arg(input.as_ref()); + self + } + + pub fn key_type>(mut self, key_type: S) -> Self { + self.command.arg("--type").arg(key_type.into()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/key/generate.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/key/generate.rs new file mode 100644 index 0000000000..2fec2cd821 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/key/generate.rs @@ -0,0 +1,25 @@ +use std::path::Path; +use std::process::Command; +pub struct KeyGenerateCommand { + command: Command, +} + +impl KeyGenerateCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn key_type>(mut self, key_type: S) -> Self { + self.command.arg("--type").arg(key_type.into()); + self + } + + pub fn seed>(mut self, seed: S) -> Self { + self.command.arg("--seed").arg(seed.into()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/key/mod.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/key/mod.rs new file mode 100644 index 0000000000..359c31681f --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/key/mod.rs @@ -0,0 +1,43 @@ +mod from_bytes; +mod generate; +mod to_bytes; +mod to_public; + +pub use from_bytes::KeyFromBytesCommand; +pub use generate::KeyGenerateCommand; +pub use to_bytes::KeyToBytesCommand; +pub use to_public::KeyToPublicCommand; + +use assert_cmd::assert::OutputAssertExt; +use jortestkit::prelude::ProcessOutput; +use std::process::Command; + +pub struct KeyCommand { + command: Command, +} + +impl KeyCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn generate(mut self) -> KeyGenerateCommand { + self.command.arg("generate"); + KeyGenerateCommand::new(self.command) + } + + pub fn to_bytes(mut self) -> KeyToBytesCommand { + self.command.arg("to-bytes"); + KeyToBytesCommand::new(self.command) + } + + pub fn from_bytes(mut self) -> KeyFromBytesCommand { + self.command.arg("from-bytes"); + KeyFromBytesCommand::new(self.command) + } + + pub fn to_public(mut self) -> KeyToPublicCommand { + self.command.arg("to-public"); + KeyToPublicCommand::new(self.command) + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/key/to_bytes.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/key/to_bytes.rs new file mode 100644 index 0000000000..2691d18129 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/key/to_bytes.rs @@ -0,0 +1,25 @@ +use std::path::Path; +use std::process::Command; +pub struct KeyToBytesCommand { + command: Command, +} + +impl KeyToBytesCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn input>(mut self, input: P) -> Self { + self.command.arg(input.as_ref()); + self + } + + pub fn output>(mut self, output: P) -> Self { + self.command.arg(output.as_ref()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/key/to_public.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/key/to_public.rs new file mode 100644 index 0000000000..5edb5ee383 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/key/to_public.rs @@ -0,0 +1,25 @@ +use std::path::Path; +use std::process::Command; +pub struct KeyToPublicCommand { + command: Command, +} + +impl KeyToPublicCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn input>(mut self, input: P) -> Self { + self.command.arg("--input").arg(input.as_ref()); + self + } + + pub fn output>(mut self, output: P) -> Self { + self.command.arg(output.as_ref()); + self + } + + pub fn build(self) -> Command { + self.command + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/command/mod.rs b/testing/jormungandr-integration-tests/src/common/jcli/command/mod.rs new file mode 100644 index 0000000000..b19e7e3511 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/command/mod.rs @@ -0,0 +1,34 @@ +use std::process::Command; + +mod address; +mod genesis; +mod key; + +pub use address::AddressCommand; +pub use genesis::GenesisCommand; +pub use key::KeyCommand; + +pub struct JCliCommand { + command: Command, +} + +impl JCliCommand { + pub fn new(command: Command) -> Self { + Self { command } + } + + pub fn genesis(mut self) -> GenesisCommand { + self.command.arg("genesis"); + GenesisCommand::new(self.command) + } + + pub fn key(mut self) -> KeyCommand { + self.command.arg("key"); + KeyCommand::new(self.command) + } + + pub fn address(mut self) -> AddressCommand { + self.command.arg("address"); + AddressCommand::new(self.command) + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli/mod.rs b/testing/jormungandr-integration-tests/src/common/jcli/mod.rs new file mode 100644 index 0000000000..09645b07d1 --- /dev/null +++ b/testing/jormungandr-integration-tests/src/common/jcli/mod.rs @@ -0,0 +1,37 @@ +mod api; +mod command; + +use command::JCliCommand; + +use crate::common::configuration; +use api::{JCliGenesis, JCliKey}; +use std::{path::PathBuf, process::Command}; + +#[derive(Clone, Debug)] +pub struct JCli { + exe: PathBuf, +} + +impl Default for JCli { + fn default() -> Self { + Self::new(configuration::get_jcli_app()) + } +} + +impl JCli { + pub fn new(exe: PathBuf) -> Self { + Self { exe } + } + + pub fn genesis(&self) -> JCliGenesis { + let command = Command::new(self.exe.clone()); + let jcli_command = JCliCommand::new(command); + JCliGenesis::new(jcli_command.genesis()) + } + + pub fn key(&self) -> JCliKey { + let command = Command::new(self.exe.clone()); + let jcli_command = JCliCommand::new(command); + JCliKey::new(jcli_command.key()) + } +} diff --git a/testing/jormungandr-integration-tests/src/common/jcli_wrapper/jcli_commands.rs b/testing/jormungandr-integration-tests/src/common/jcli_wrapper/jcli_commands.rs index 833e5b1f38..387e04c336 100644 --- a/testing/jormungandr-integration-tests/src/common/jcli_wrapper/jcli_commands.rs +++ b/testing/jormungandr-integration-tests/src/common/jcli_wrapper/jcli_commands.rs @@ -5,7 +5,7 @@ use super::Discrimination; use std::path::Path; use std::process::Command; - +/* /// Get genesis encode command. /// /// # Arguments @@ -58,7 +58,7 @@ pub fn get_genesis_hash_command(path_to_output_block: &Path) -> Command { .arg(path_to_output_block); command } - +*/ /// Get rest stat command. pub fn get_rest_stats_command(host: &str) -> Command { let mut command = get_jcli_command(); @@ -202,11 +202,11 @@ fn add_discrimination(command: &mut Command, discrimination: Discrimination) { } /// Get address single command. -pub fn get_genesis_init_command() -> Command { +/*pub fn get_genesis_init_command() -> Command { let mut command = get_jcli_command(); command.arg("genesis").arg("init"); command -} +}*/ /// Get address single command. pub fn get_address_delegation_command( diff --git a/testing/jormungandr-integration-tests/src/common/jcli_wrapper/jcli_transaction_wrapper/mod.rs b/testing/jormungandr-integration-tests/src/common/jcli_wrapper/jcli_transaction_wrapper/mod.rs index 8cc2a33d87..1b629ae915 100644 --- a/testing/jormungandr-integration-tests/src/common/jcli_wrapper/jcli_transaction_wrapper/mod.rs +++ b/testing/jormungandr-integration-tests/src/common/jcli_wrapper/jcli_transaction_wrapper/mod.rs @@ -2,7 +2,7 @@ pub mod jcli_transaction_commands; use self::jcli_transaction_commands::TransactionCommands; -use crate::common::{data::witness::Witness, jcli_wrapper}; +use crate::common::{data::witness::Witness, jcli::JCli, jcli_wrapper}; use assert_cmd::assert::OutputAssertExt; use assert_fs::fixture::ChildPath; use assert_fs::prelude::*; @@ -321,7 +321,8 @@ impl JCLITransactionWrapper { } pub fn create_witness_default(&self, addr_type: &str, spending_key: Option) -> Witness { - let private_key = jcli_wrapper::assert_key_generate_default(); + let jcli: JCli = Default::default(); + let private_key = jcli.key().generate_default(); self.create_witness_from_key(&private_key, &addr_type, spending_key) } diff --git a/testing/jormungandr-integration-tests/src/common/jcli_wrapper/mod.rs b/testing/jormungandr-integration-tests/src/common/jcli_wrapper/mod.rs index f76e5a8930..5779a8687a 100644 --- a/testing/jormungandr-integration-tests/src/common/jcli_wrapper/mod.rs +++ b/testing/jormungandr-integration-tests/src/common/jcli_wrapper/mod.rs @@ -42,6 +42,7 @@ pub enum Error { }, } +/* pub fn assert_genesis_encode(genesis_yaml_file_path: &Path, output_file: &ChildPath) { jcli_commands::get_genesis_encode_command(genesis_yaml_file_path, output_file.path()) .assert() @@ -80,7 +81,7 @@ pub fn assert_genesis_hash_fails(path_to_output_block: &Path, expected_msg: &str .assert() .failure() .stderr(predicates::str::contains(expected_msg)); -} +}*/ pub fn assert_rest_stats(host: &str) -> BTreeMap { jcli_commands::get_rest_stats_command(&host) @@ -132,7 +133,7 @@ pub fn assert_rest_utxo_get_not_found(host: &str, fragment_id_bech32: &str, outp .failure() .stderr(predicates::str::contains("404 Not Found")); } - +/* pub fn assert_get_address_info(address: &str) -> BTreeMap { jcli_commands::get_address_info_command_default(&address) .assert() @@ -183,7 +184,7 @@ pub fn assert_address_account(public_key: &str, discrimination: Discrimination) .get_output() .as_single_line() } - +*/ pub fn assert_post_transaction(transactions_message: &str, host: &str) -> Hash { let transaction_file = NamedTempFile::new("transaction.hash").unwrap(); transaction_file.write_str(transactions_message).unwrap(); @@ -240,7 +241,7 @@ pub fn assert_get_active_vote_plans(host: &str) -> Vec { .as_lossy_string(); serde_yaml::from_str(&content).expect("JCLI returned malformed VotePlan") } - +/* pub fn assert_key_generate_default() -> String { jcli_commands::get_key_generate_command_default() .assert() @@ -319,7 +320,7 @@ pub fn assert_key_to_bytes_fails( .failure() .stderr(predicates::str::contains(expected_msg)); } - +*/ pub fn assert_rest_get_leadership_log(host: &str) -> Vec { let content = jcli_commands::get_rest_leaders_logs_command(&host) .assert() diff --git a/testing/jormungandr-integration-tests/src/common/jormungandr/configuration_builder.rs b/testing/jormungandr-integration-tests/src/common/jormungandr/configuration_builder.rs index 32a0a85df1..c0906fb80d 100644 --- a/testing/jormungandr-integration-tests/src/common/jormungandr/configuration_builder.rs +++ b/testing/jormungandr-integration-tests/src/common/jormungandr/configuration_builder.rs @@ -1,5 +1,7 @@ use crate::common::{ - configuration, jcli_wrapper, + configuration, + jcli::JCli, + jcli_wrapper, jormungandr::JormungandrProcess, startup::{build_genesis_block, create_new_key_pair}, }; @@ -281,7 +283,10 @@ impl ConfigurationBuilder { let path_to_output_block = build_genesis_block(&block0_config, temp_dir); let genesis_block_hash = match self.block0_hash { Some(ref value) => value.clone(), - None => jcli_wrapper::assert_genesis_hash(&path_to_output_block), + None => { + let jcli: JCli = Default::default(); + jcli.genesis().hash(&path_to_output_block).to_string() + } }; fn write_secret(secret: &NodeSecret, output_file: ChildPath) -> PathBuf { diff --git a/testing/jormungandr-integration-tests/src/common/mod.rs b/testing/jormungandr-integration-tests/src/common/mod.rs index 0634a41a8a..6ab8b6f356 100644 --- a/testing/jormungandr-integration-tests/src/common/mod.rs +++ b/testing/jormungandr-integration-tests/src/common/mod.rs @@ -4,6 +4,7 @@ extern crate serde_derive; pub mod configuration; pub mod data; +pub mod jcli; pub mod jcli_wrapper; pub mod jormungandr; pub mod load; diff --git a/testing/jormungandr-integration-tests/src/common/startup/mod.rs b/testing/jormungandr-integration-tests/src/common/startup/mod.rs index f3a4d4cb72..958b9c2487 100644 --- a/testing/jormungandr-integration-tests/src/common/startup/mod.rs +++ b/testing/jormungandr-integration-tests/src/common/startup/mod.rs @@ -18,6 +18,7 @@ use jormungandr_testing_utils::{ }; use jortestkit::process as process_utils; +use super::jcli::JCli; use assert_fs::fixture::{ChildPath, PathChild, TempDir}; use assert_fs::prelude::*; use std::path::PathBuf; @@ -29,7 +30,9 @@ pub fn build_genesis_block( let config_file = temp_dir.child("genesis.yaml"); write_block0_config(&block0_config, &config_file); let output_block_file = temp_dir.child("block-0.bin"); - jcli_wrapper::assert_genesis_encode(config_file.path(), &output_block_file); + let jcli: JCli = Default::default(); + jcli.genesis() + .encode(config_file.path(), &output_block_file); output_block_file.path().into() } diff --git a/testing/jormungandr-integration-tests/src/jcli/address/account.rs b/testing/jormungandr-integration-tests/src/jcli/address/account.rs index b0a8e612b6..698d99bc8d 100644 --- a/testing/jormungandr-integration-tests/src/jcli/address/account.rs +++ b/testing/jormungandr-integration-tests/src/jcli/address/account.rs @@ -1,34 +1,34 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; use assert_cmd::assert::OutputAssertExt; use chain_addr::Discrimination; #[test] pub fn test_account_address_made_of_incorrect_ed25519_extended_key() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); println!("private key: {}", &private_key); - let mut public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let mut public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); public_key.remove(20); // Assertion changed due to issue #306. After fix please change it to correct one - jcli_wrapper::jcli_commands::get_address_account_command(&public_key, Discrimination::Test) - .assert() - .failure() - .stderr(predicates::str::contains( - "Failed to parse bech32, invalid data format", - )); + jcli.address() + .account_expect_fail(&public_key, "Failed to parse bech32, invalid data format"); } #[test] pub fn test_account_address_made_of_ed25519_extended_key() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); println!("private key: {}", &private_key); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); - let account_address = jcli_wrapper::assert_address_account(&public_key, Discrimination::Test); + let account_address = jcli.address().account(&public_key); assert_ne!(account_address, "", "generated account address is empty"); } diff --git a/testing/jormungandr-integration-tests/src/jcli/address/info.rs b/testing/jormungandr-integration-tests/src/jcli/address/info.rs index a56a6cd73f..65a72d544f 100644 --- a/testing/jormungandr-integration-tests/src/jcli/address/info.rs +++ b/testing/jormungandr-integration-tests/src/jcli/address/info.rs @@ -1,18 +1,23 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; use chain_addr::Discrimination; #[test] pub fn test_info_unknown_address_public_key() { + let jcli: JCli = Default::default(); + let account_address = "48mDfYyQn21iyEPzCfkATEHTwZBcZJqXhRJezmswfvc6Ne89u1axXsiazmgd7SwT8VbafbVnCvyXhBSMhSkPiCezMkqHC4dmxRahRC86SknFu6JF6hwSg8"; - jcli_wrapper::assert_get_address_info_fails(&account_address, "invalid internal encoding"); + jcli.address() + .info_expect_fail(&account_address, "invalid internal encoding"); } #[test] pub fn test_info_account_address() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); - let account_address = jcli_wrapper::assert_address_account(&public_key, Discrimination::Test); - let info = jcli_wrapper::assert_get_address_info(&account_address); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); + let public_key = jcli.key().to_public(&private_key); + let account_address = jcli.address().account(&public_key); + let info = jcli.address().info(&account_address); assert_eq!( info.get("discrimination").unwrap(), "testing", @@ -23,11 +28,14 @@ pub fn test_info_account_address() { #[test] pub fn test_info_account_address_for_prod() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); - let account_address = - jcli_wrapper::assert_address_account(&public_key, Discrimination::Production); - let info = jcli_wrapper::assert_get_address_info(&account_address); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); + let public_key = jcli.key().to_public(&private_key); + let account_address = jcli + .address() + .account(&public_key, Discrimination::Production); + let info = jcli.address().info(&account_address); assert_eq!( info.get("discrimination").unwrap(), "production", @@ -38,14 +46,17 @@ pub fn test_info_account_address_for_prod() { #[test] pub fn test_info_delegation_address() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); + let public_key = jcli.key().to_public(&private_key); - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); - let delegation_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let private_key = jcli.key().generate("ed25519Extended"); + let delegation_key = jcli.key().to_public(&private_key); let account_address = - jcli_wrapper::assert_address_delegation(&public_key, &delegation_key, Discrimination::Test); - let info = jcli_wrapper::assert_get_address_info(&account_address); + jcli.address() + .delegation(&public_key, &delegation_key, Discrimination::Test); + let info = jcli.address().info(&account_address); assert_eq!( info.get("discrimination").unwrap(), "testing", diff --git a/testing/jormungandr-integration-tests/src/jcli/address/single.rs b/testing/jormungandr-integration-tests/src/jcli/address/single.rs index 273d5d499b..7698d03f77 100644 --- a/testing/jormungandr-integration-tests/src/jcli/address/single.rs +++ b/testing/jormungandr-integration-tests/src/jcli/address/single.rs @@ -1,36 +1,45 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; use assert_cmd::assert::OutputAssertExt; use chain_addr::Discrimination; #[test] pub fn test_utxo_address_made_of_ed25519_extended_key() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); println!("private key: {}", &private_key); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); - let utxo_address = jcli_wrapper::assert_address_single(&public_key, Discrimination::Test); + let utxo_address = jcli.address().single(&public_key, Discrimination::Test); assert_ne!(utxo_address, "", "generated utxo address is empty"); } #[test] pub fn test_delegation_address_made_of_ed25519_extended_seed_key() { + let jcli: JCli = Default::default(); + let correct_seed = "73855612722627931e20c850f8ad53eb04c615c7601a95747be073dcada3e135"; - let private_key = jcli_wrapper::assert_key_with_seed_generate("ed25519Extended", &correct_seed); + let private_key = jcli + .key() + .generate_with_seed("ed25519Extended", &correct_seed); println!("private key: {}", &private_key); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); - let private_key = jcli_wrapper::assert_key_with_seed_generate("ed25519Extended", &correct_seed); + let private_key = jcli + .key() + .generate_with_seed("ed25519Extended", &correct_seed); println!("private delegation key: {}", &private_key); - let delegation_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let delegation_key = jcli.key().to_public(&private_key); println!("delegation key: {}", &delegation_key); let delegation_address = - jcli_wrapper::assert_address_delegation(&public_key, &delegation_key, Discrimination::Test); + jcli.address() + .delegation(&public_key, &delegation_key, Discrimination::Test); assert_ne!( delegation_address, "", "generated delegation adress is empty" @@ -39,16 +48,19 @@ pub fn test_delegation_address_made_of_ed25519_extended_seed_key() { #[test] pub fn test_delegation_address_is_the_same_as_public() { + let jcli: JCli = Default::default(); + let correct_seed = "73855612722627931e20c850f8ad53eb04c615c7601a95747be073dcada3e135"; - let private_key = jcli_wrapper::assert_key_with_seed_generate("ed25519Extended", &correct_seed); + let private_key = jcli + .key() + .generate_with_seed("ed25519Extended", &correct_seed); println!("private key: {}", &private_key); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); - let delegation_address = - jcli_wrapper::assert_address_delegation(&public_key, &public_key, Discrimination::Test); + let delegation_address = jcli.address().delegation(&public_key, &public_key); assert_ne!( delegation_address, "", "generated delegation address is empty" @@ -57,19 +69,21 @@ pub fn test_delegation_address_is_the_same_as_public() { #[test] pub fn test_delegation_address_for_prod_discrimination() { + let jcli: JCli = Default::default(); + let correct_seed = "73855612722627931e20c850f8ad53eb04c615c7601a95747be073dcada3e135"; - let private_key = jcli_wrapper::assert_key_with_seed_generate("ed25519Extended", &correct_seed); + let private_key = jcli + .key() + .generate_with_seed("ed25519Extended", &correct_seed); println!("private key: {}", &private_key); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); - let delegation_address = jcli_wrapper::assert_address_delegation( - &public_key, - &public_key, - Discrimination::Production, - ); + let delegation_address = + jcli.address() + .delegation(&public_key, &public_key, Discrimination::Production); assert_ne!( delegation_address, "", "generated delegation address is empty" @@ -78,12 +92,16 @@ pub fn test_delegation_address_for_prod_discrimination() { #[test] pub fn test_single_address_for_prod_discrimination() { + let jcli: JCli = Default::default(); + let correct_seed = "73855612722627931e20c850f8ad53eb04c615c7601a95747be073dcada3e135"; - let private_key = jcli_wrapper::assert_key_with_seed_generate("ed25519Extended", &correct_seed); + let private_key = jcli + .key() + .generate_with_seed("ed25519Extended", &correct_seed); println!("private key: {}", &private_key); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); let delegation_address = jcli_wrapper::assert_address_delegation( @@ -96,12 +114,16 @@ pub fn test_single_address_for_prod_discrimination() { #[test] pub fn test_account_address_for_prod_discrimination() { + let jcli: JCli = Default::default(); + let correct_seed = "73855612722627931e20c850f8ad53eb04c615c7601a95747be073dcada3e135"; - let private_key = jcli_wrapper::assert_key_with_seed_generate("ed25519Extended", &correct_seed); + let private_key = jcli + .key() + .generate_with_seed("ed25519Extended", &correct_seed); println!("private key: {}", &private_key); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); let delegation_address = jcli_wrapper::assert_address_delegation( @@ -113,10 +135,12 @@ pub fn test_account_address_for_prod_discrimination() { } #[test] pub fn test_utxo_address_made_of_incorrect_ed25519_extended_key() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); println!("private key: {}", &private_key); - let mut public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let mut public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); public_key.push('A'); @@ -132,10 +156,12 @@ pub fn test_utxo_address_made_of_incorrect_ed25519_extended_key() { #[test] pub fn test_delegation_address_made_of_random_string() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); println!("private key: {}", &private_key); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); let delegation_key = "adfasdfasdfdasfasdfadfasdf"; @@ -155,15 +181,17 @@ pub fn test_delegation_address_made_of_random_string() { #[test] pub fn test_delegation_address_made_of_incorrect_public_ed25519_extended_key() { - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate("ed25519Extended"); println!("private key: {}", &private_key); - let mut public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let mut public_key = jcli.key().to_public(&private_key); println!("public key: {}", &public_key); - let private_key = jcli_wrapper::assert_key_generate("ed25519Extended"); + let private_key = jcli.key().generate("ed25519Extended"); println!("private delegation key: {}", &private_key); - let delegation_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let delegation_key = jcli.key().to_public(&private_key); println!("delegation key: {}", &delegation_key); public_key.push('A'); diff --git a/testing/jormungandr-integration-tests/src/jcli/genesis/encode.rs b/testing/jormungandr-integration-tests/src/jcli/genesis/encode.rs index cf6b949114..51117dcd32 100644 --- a/testing/jormungandr-integration-tests/src/jcli/genesis/encode.rs +++ b/testing/jormungandr-integration-tests/src/jcli/genesis/encode.rs @@ -1,5 +1,6 @@ use crate::common::{ configuration::{Block0ConfigurationBuilder, JormungandrParams}, + jcli::JCli, jcli_wrapper, jormungandr::ConfigurationBuilder, startup, @@ -57,16 +58,18 @@ impl Fixture { fn assert_encode(&self) { let yaml_file = self.write_config("genesis.yaml"); - jcli_wrapper::assert_genesis_encode(yaml_file.path(), &self.temp_dir.child("block-0.bin")); + let jcli: JCli = Default::default(); + jcli.genesis() + .encode(yaml_file.path(), &self.temp_dir.child("block-0.bin")); } fn assert_encode_fails(&self, expected_msg: &str) { + let jcli: JCli = Default::default(); + let yaml_file = self.write_config("genesis.yaml"); - jcli_wrapper::assert_genesis_encode_fails( - yaml_file.path(), - &self.temp_dir.child("block0-failure.bin"), - expected_msg, - ); + + jcli.genesis() + .encode_expect_fail(yaml_file.path(), expected_msg); } } @@ -98,8 +101,10 @@ pub fn test_genesis_for_production_is_successfully_built() { #[test] pub fn test_genesis_for_prod_with_initial_funds_for_testing_address_fail_to_build() { - let private_key = jcli_wrapper::assert_key_generate_default(); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate_default(); + let public_key = jcli.key().to_public(&private_key); let test_address = jcli_wrapper::assert_address_single(&public_key, Discrimination::Test); let mut fixture = Fixture::new(); @@ -181,22 +186,27 @@ pub fn test_genesis_decode_bijection() { let expected_yaml_file = fixture.write_config("expected-genesis.yaml"); let actual_yaml_file = fixture.temp_dir().child("actual-genesis.yaml"); + let jcli: JCli = Default::default(); - jcli_wrapper::assert_genesis_decode(params.genesis_block_path(), &actual_yaml_file); + jcli.clone() + .genesis() + .decode(params.genesis_block_path(), &actual_yaml_file); actual_yaml_file.assert(crate::predicate::file_text_content_is_same_as( expected_yaml_file.path(), )); let block0_after = fixture.temp_dir().child("block-0-after.bin"); - jcli_wrapper::assert_genesis_encode(actual_yaml_file.path(), &block0_after); + jcli.clone() + .genesis() + .encode(actual_yaml_file.path(), &block0_after); block0_after.assert(crate::predicate::file_binary_content_is_same_as( params.genesis_block_path(), )); - let right_hash = jcli_wrapper::assert_genesis_hash(block0_after.path()); + let right_hash = jcli.genesis().hash(block0_after.path()); - assert_eq!(params.genesis_block_hash(), right_hash); + assert_eq!(params.genesis_block_hash(), right_hash.to_string()); } #[test] diff --git a/testing/jormungandr-integration-tests/src/jcli/genesis/hash.rs b/testing/jormungandr-integration-tests/src/jcli/genesis/hash.rs index f243d369ec..73e21fe788 100644 --- a/testing/jormungandr-integration-tests/src/jcli/genesis/hash.rs +++ b/testing/jormungandr-integration-tests/src/jcli/genesis/hash.rs @@ -1,22 +1,25 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; use assert_fs::prelude::*; use assert_fs::TempDir; #[test] pub fn test_correct_hash_is_returned_for_correct_block() { - let content = jcli_wrapper::assert_genesis_init(); + let jcli: JCli = Default::default(); + let content = jcli.clone().genesis().init(); let temp_dir = TempDir::new().unwrap(); let yaml_file = temp_dir.child("init_file.yaml"); yaml_file.write_str(&content).unwrap(); let block_file = temp_dir.child("block-0.bin"); - jcli_wrapper::assert_genesis_encode(yaml_file.path(), &block_file); - jcli_wrapper::assert_genesis_hash(block_file.path()); + + jcli.clone().genesis().encode(yaml_file.path(), &block_file); + jcli.genesis().hash(block_file.path()); } #[test] pub fn test_correct_error_is_returned_for_non_existent_genesis_block() { let temp_dir = TempDir::new().unwrap(); let block_file = temp_dir.child("block-0.bin"); - jcli_wrapper::assert_genesis_hash_fails(block_file.path(), "file"); + let jcli: JCli = Default::default(); + jcli.genesis().hash_expect_fail(block_file.path(), "file"); } diff --git a/testing/jormungandr-integration-tests/src/jcli/genesis/init.rs b/testing/jormungandr-integration-tests/src/jcli/genesis/init.rs index 5d679cceca..e2621c6906 100644 --- a/testing/jormungandr-integration-tests/src/jcli/genesis/init.rs +++ b/testing/jormungandr-integration-tests/src/jcli/genesis/init.rs @@ -1,14 +1,16 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; use assert_fs::prelude::*; use assert_fs::TempDir; #[test] pub fn test_genesis_block_is_built_from_init_yaml() { - let content = jcli_wrapper::assert_genesis_init(); + let jcli: JCli = Default::default(); + + let content = jcli.clone().genesis().init(); let temp_dir = TempDir::new().unwrap(); let yaml_file = temp_dir.child("init_file.yaml"); yaml_file.write_str(&content).unwrap(); let block_file = temp_dir.child("block-0.bin"); - jcli_wrapper::assert_genesis_encode(yaml_file.path(), &block_file); + jcli.genesis().encode(yaml_file.path(), &block_file); } diff --git a/testing/jormungandr-integration-tests/src/jcli/key/from_bytes.rs b/testing/jormungandr-integration-tests/src/jcli/key/from_bytes.rs index 634b8467d4..d559dee148 100644 --- a/testing/jormungandr-integration-tests/src/jcli/key/from_bytes.rs +++ b/testing/jormungandr-integration-tests/src/jcli/key/from_bytes.rs @@ -1,4 +1,4 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; use assert_fs::prelude::*; use assert_fs::NamedTempFile; @@ -24,11 +24,12 @@ pub fn test_key_from_bytes_ed25510bip32() { } fn transform_key_to_bytes_and_back(key_type: &str) { - let private_key = jcli_wrapper::assert_key_generate(&key_type); + let jcli: JCli = Default::default(); + + let private_key = jcli.key().generate(key_type); let byte_key_file = NamedTempFile::new("byte_file").unwrap(); - jcli_wrapper::assert_key_to_bytes(&private_key, byte_key_file.path()); - let key_after_transformation = - jcli_wrapper::assert_key_from_bytes(byte_key_file.path(), &key_type); + jcli.key().to_bytes(&private_key, byte_key_file.path()); + let key_after_transformation = jcli.key().from_bytes(key_type, byte_key_file.path()); assert_eq!( &private_key, &key_after_transformation, @@ -39,24 +40,26 @@ fn transform_key_to_bytes_and_back(key_type: &str) { #[test] pub fn test_from_bytes_for_invalid_key() { + let jcli: JCli = Default::default(); let byte_key_file = NamedTempFile::new("byte_file").unwrap(); byte_key_file.write_str( "ed25519e_sk1kp80gevhccz8cnst6x97rmlc9n5fls2nmcqcjfn65vdktt0wy9f3zcf76hp7detq9sz8cmhlcyzw5h3ralf98rdwl4wcwcgaaqna3pgz9qgk0").unwrap(); - jcli_wrapper::assert_key_from_bytes_fails( - byte_key_file.path(), + jcli.key().from_bytes_expect_fail( "ed25519Extended", + byte_key_file.path(), "Odd number of digits", ); } #[test] pub fn test_from_bytes_for_unknown_key() { + let jcli: JCli = Default::default(); let byte_key_file = NamedTempFile::new("byte_file").unwrap(); byte_key_file.write_str( "ed25519e_sk1kp80gevhccz8cnst6x97rmlc9n5fls2nmcqcjfn65vdktt0wy9f3zcf76hp7detq9sz8cmhlcyzw5h3ralf98rdwl4wcwcgaaqna3pgz9qgk0").unwrap(); - jcli_wrapper::assert_key_from_bytes_fails( - byte_key_file.path(), + jcli.key().from_bytes_expect_fail( "ed25519Exten", + byte_key_file.path(), "Invalid value for '--type ':", ); } diff --git a/testing/jormungandr-integration-tests/src/jcli/key/generate.rs b/testing/jormungandr-integration-tests/src/jcli/key/generate.rs index 7b936bf0e0..7b5a7a6f45 100644 --- a/testing/jormungandr-integration-tests/src/jcli/key/generate.rs +++ b/testing/jormungandr-integration-tests/src/jcli/key/generate.rs @@ -1,57 +1,62 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; use assert_cmd::assert::OutputAssertExt; #[test] pub fn test_ed25519_key_generation() { - let generated_key = jcli_wrapper::assert_key_generate("ed25519"); + let jcli: JCli = Default::default(); + let generated_key = jcli.key().generate("ed25519"); assert_ne!(generated_key, "", "generated key is empty"); } #[test] pub fn test_ed25519_uppercase_key_generation() { - let generated_key = jcli_wrapper::assert_key_generate("ED25519EXTENDED"); + let jcli: JCli = Default::default(); + let generated_key = jcli.key().generate("ED25519EXTENDED"); assert_ne!(generated_key, "", "generated key is empty"); } #[test] pub fn test_ed25510bip32_key_generation() { - let generated_key = jcli_wrapper::assert_key_generate("Ed25519Bip32"); + let jcli: JCli = Default::default(); + let generated_key = jcli.key().generate("Ed25519Bip32"); assert_ne!(generated_key, "", "generated key is empty"); } #[test] pub fn test_ed25519extended_key_generation() { - let generated_key = jcli_wrapper::assert_key_generate("Ed25519Extended"); + let jcli: JCli = Default::default(); + let generated_key = jcli.key().generate("Ed25519Extended"); assert_ne!(generated_key, "", "generated key is empty"); } #[test] pub fn test_curve25519_2hashdh_key_generation() { - let generated_key = jcli_wrapper::assert_key_generate("Curve25519_2HashDH"); + let jcli: JCli = Default::default(); + let generated_key = jcli.key().generate("Curve25519_2HashDH"); assert_ne!(generated_key, "", "generated key is empty"); } #[test] pub fn test_sumed25519_12_key_generation() { - let generated_key = jcli_wrapper::assert_key_generate("SumEd25519_12"); + let jcli: JCli = Default::default(); + let generated_key = jcli.key().generate("SumEd25519_12"); assert_ne!(generated_key, "", "generated key is empty"); } #[test] pub fn test_unknown_key_type_generation() { - jcli_wrapper::jcli_commands::get_key_generate_command("unknown") - .assert() - .failure() - .stderr(predicates::str::contains( - "Invalid value for '--type ':", - )); + let jcli: JCli = Default::default(); + jcli.key() + .generate_expect_fail("unknown", "Invalid value for '--type ':"); } #[test] pub fn test_key_with_seed_generation() { + let jcli: JCli = Default::default(); let correct_seed = "73855612722627931e20c850f8ad53eb04c615c7601a95747be073dcada3e135"; - let generated_key = - jcli_wrapper::assert_key_with_seed_generate("Ed25519Extended", &correct_seed); + let generated_key = jcli + .key() + .generate_with_seed("Ed25519Extended", &correct_seed); assert_ne!(generated_key, "", "generated key is empty"); } @@ -68,22 +73,21 @@ pub fn test_key_with_too_long_seed_generation() { } fn test_key_invalid_seed_length(seed: &str) { - jcli_wrapper::jcli_commands::get_key_generate_with_seed_command("Ed25519Extended", &seed) - .assert() - .failure() - .stderr(predicates::str::contains( - "invalid seed length, expected 32 bytes but received", - )); + let jcli: JCli = Default::default(); + jcli.key().generate_with_seed_expect_fail( + "Ed25519Extended", + &seed, + "invalid seed length, expected 32 bytes but received", + ); } #[test] pub fn test_key_with_seed_with_unknown_symbol_generation() { + let jcli: JCli = Default::default(); let incorrect_seed = "73855612722627931e20c850f8ad53eb04c615c7601a95747be073dcay"; - jcli_wrapper::jcli_commands::get_key_generate_with_seed_command( + jcli.key().generate_with_seed_expect_fail( "Ed25519Extended", &incorrect_seed, - ) - .assert() - .failure() - .stderr(predicates::str::contains("invalid Hexadecimal")); + "invalid Hexadecimal", + ); } diff --git a/testing/jormungandr-integration-tests/src/jcli/key/to_bytes.rs b/testing/jormungandr-integration-tests/src/jcli/key/to_bytes.rs index b74ecaec50..6c63eea38a 100644 --- a/testing/jormungandr-integration-tests/src/jcli/key/to_bytes.rs +++ b/testing/jormungandr-integration-tests/src/jcli/key/to_bytes.rs @@ -1,15 +1,17 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; use assert_fs::prelude::*; use assert_fs::{NamedTempFile, TempDir}; #[test] pub fn test_key_from_and_to_bytes() { - let private_key = jcli_wrapper::assert_key_generate("Ed25519Extended"); + let jcli: JCli = Default::default(); + let private_key = jcli.key().generate("Ed25519Extended"); let byte_key_file = NamedTempFile::new("byte_file").unwrap(); - jcli_wrapper::assert_key_to_bytes(&private_key, byte_key_file.path()); - let key_after_transformation = - jcli_wrapper::assert_key_from_bytes(byte_key_file.path(), "Ed25519Extended"); + jcli.key().to_bytes(&private_key, byte_key_file.path()); + let key_after_transformation = jcli + .key() + .from_bytes("Ed25519Extended", byte_key_file.path()); assert_eq!( &private_key, &key_after_transformation, @@ -20,19 +22,19 @@ pub fn test_key_from_and_to_bytes() { #[test] pub fn test_to_bytes_for_non_existent_input_file() { + let jcli: JCli = Default::default(); let byte_key_file = NamedTempFile::new("byte_file").unwrap(); - jcli_wrapper::assert_key_from_bytes_fails(byte_key_file.path(), "ed25519Extended", "file"); + jcli.key() + .from_bytes_expect_fail("ed25519Extended", byte_key_file.path(), "file"); } #[test] pub fn test_to_bytes_for_invalid_key() { let temp_dir = TempDir::new().unwrap(); + let jcli: JCli = Default::default(); let byte_key_file = temp_dir.child("byte_file"); byte_key_file.write_str("ed25519e_sk1kp80gevhccz8cnst6x97rmlc9n5fls2nmcqcjfn65vdktt0wy9f3zcf76hp7detq9sz8cmhlcyzw5h3ralf98rdwl4wcwcgaaqna3pgz9qgk0").unwrap(); let output_file = temp_dir.child("output_byte_file"); - jcli_wrapper::assert_key_to_bytes_fails( - byte_key_file.path(), - output_file.path(), - "invalid Bech32", - ); + jcli.key() + .to_bytes_expect_fail(byte_key_file.path(), output_file.path(), "invalid Bech32"); } diff --git a/testing/jormungandr-integration-tests/src/jcli/key/to_public.rs b/testing/jormungandr-integration-tests/src/jcli/key/to_public.rs index 764ba995a6..c8b59b652c 100644 --- a/testing/jormungandr-integration-tests/src/jcli/key/to_public.rs +++ b/testing/jormungandr-integration-tests/src/jcli/key/to_public.rs @@ -1,15 +1,17 @@ -use crate::common::jcli_wrapper; +use crate::common::{jcli::JCli, jcli_wrapper}; #[test] pub fn test_key_to_public() { + let jcli: JCli = Default::default(); let private_key = "ed25519_sk1357nu8uaxvdekg6uhqmdd0zcd3tjv3qq0p2029uk6pvfxuks5rzstp5ceq"; - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let public_key = jcli.key().to_public(private_key.to_owned()); assert_ne!(public_key, "", "generated key is empty"); } #[test] pub fn test_key_to_public_invalid_key() { - jcli_wrapper::assert_key_to_public_fails( + let jcli: JCli = Default::default(); + jcli.key().to_public_expect_fail( "ed2551ssss9_sk1357nu8uaxvdekg6uhqmdd0zcd3tjv3qq0p2029uk6pvfxuks5rzstp5ceq", "invalid checksum", ); @@ -17,7 +19,8 @@ pub fn test_key_to_public_invalid_key() { #[test] pub fn test_key_to_public_invalid_chars_key() { - jcli_wrapper::assert_key_to_public_fails( + let jcli: JCli = Default::default(); + jcli.key().to_public_expect_fail( "node:: ed2551ssss9_sk1357nu8uaxvdekg6uhqmdd0zcd3tjv3qq0p2029uk6pvfxuks5rzstp5ceq", "invalid character", ); @@ -25,7 +28,8 @@ pub fn test_key_to_public_invalid_chars_key() { #[test] pub fn test_private_key_to_public_key() { - let private_key = jcli_wrapper::assert_key_generate("Ed25519Extended"); - let public_key = jcli_wrapper::assert_key_to_public_default(&private_key); + let jcli: JCli = Default::default(); + let private_key = jcli.key().generate("Ed25519Extended"); + let public_key = jcli.key().to_public(&private_key); assert_ne!(public_key, "", "generated key is empty"); } diff --git a/testing/jormungandr-integration-tests/src/jcli/transaction/e2e.rs b/testing/jormungandr-integration-tests/src/jcli/transaction/e2e.rs index dad1368209..f91c7b2a5a 100644 --- a/testing/jormungandr-integration-tests/src/jcli/transaction/e2e.rs +++ b/testing/jormungandr-integration-tests/src/jcli/transaction/e2e.rs @@ -1,4 +1,5 @@ use crate::common::{ + jcli::JCli, jcli_wrapper::{self, jcli_transaction_wrapper::JCLITransactionWrapper}, jormungandr::{ConfigurationBuilder, Starter}, startup, @@ -58,6 +59,7 @@ pub fn test_utxo_transaction_with_more_than_one_witness_per_input_is_rejected() #[test] pub fn test_two_correct_utxo_to_utxo_transactions_are_accepted_by_node() { + let jcli: JCli = Default::default(); let temp_dir = TempDir::new().unwrap(); let sender = startup::create_new_utxo_address(); @@ -74,14 +76,14 @@ pub fn test_two_correct_utxo_to_utxo_transactions_are_accepted_by_node() { let jormungandr = Starter::new().config(config.clone()).start().unwrap(); let utxo = config.block0_utxo_for_address(&sender); - let block0_hash = jcli_wrapper::assert_genesis_hash(config.genesis_block_path()); + let block0_hash = jcli.genesis().hash(config.genesis_block_path()); let first_transaction = JCLITransactionWrapper::build_transaction_from_utxo( &utxo, *utxo.associated_fund(), &middle_man, *utxo.associated_fund(), &sender, - &block0_hash, + &block0_hash.to_string(), ); let first_transaction_id = @@ -94,7 +96,7 @@ pub fn test_two_correct_utxo_to_utxo_transactions_are_accepted_by_node() { &receiver, 100.into(), &middle_man, - &block0_hash, + &block0_hash.to_string(), ); jcli_wrapper::assert_transaction_in_block(&second_transaction, &jormungandr); } @@ -410,6 +412,7 @@ pub fn test_transaction_from_utxo_to_delegation_is_accepted_by_node() { #[test] pub fn test_input_with_smaller_value_than_initial_utxo_is_rejected_by_node() { let temp_dir = TempDir::new().unwrap(); + let jcli: JCli = Default::default(); let sender = startup::create_new_utxo_address(); let receiver = startup::create_new_utxo_address(); @@ -421,7 +424,7 @@ pub fn test_input_with_smaller_value_than_initial_utxo_is_rejected_by_node() { .build(&temp_dir); let jormungandr = Starter::new().config(config.clone()).start().unwrap(); - let block0_hash = jcli_wrapper::assert_genesis_hash(&config.genesis_block_path()); + let block0_hash = jcli.genesis().hash(&config.genesis_block_path()); let utxo = config.block0_utxo_for_address(&sender); let transaction_message = JCLITransactionWrapper::build_transaction_from_utxo( &utxo, @@ -429,7 +432,7 @@ pub fn test_input_with_smaller_value_than_initial_utxo_is_rejected_by_node() { &receiver, 99.into(), &sender, - &block0_hash, + &block0_hash.to_string(), ); jcli_wrapper::assert_transaction_rejected( &transaction_message, @@ -441,7 +444,7 @@ pub fn test_input_with_smaller_value_than_initial_utxo_is_rejected_by_node() { #[test] pub fn test_transaction_with_non_existing_id_should_be_rejected_by_node() { let temp_dir = TempDir::new().unwrap(); - + let jcli: JCli = Default::default(); let sender = startup::create_new_utxo_address(); let receiver = startup::create_new_utxo_address(); let config = ConfigurationBuilder::new() @@ -451,7 +454,10 @@ pub fn test_transaction_with_non_existing_id_should_be_rejected_by_node() { }]) .build(&temp_dir); let jormungandr = Starter::new().config(config.clone()).start().unwrap(); - let block0_hash = jcli_wrapper::assert_genesis_hash(&config.genesis_block_path()); + let block0_hash = jcli + .genesis() + .hash(&config.genesis_block_path()) + .to_string(); let transaction_message = JCLITransactionWrapper::build_transaction( &FAKE_INPUT_TRANSACTION_ID, 0,