Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTxO Info as a common interface between jcli, jormungandr and the tests #543

Merged
merged 6 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate rand;
extern crate rand_chacha;
extern crate serde_derive;
use self::serde_derive::{Deserialize, Serialize};
use jormungandr_lib::interfaces::Value;
use std::path::PathBuf;
use std::vec::Vec;

Expand Down Expand Up @@ -51,7 +52,7 @@ pub struct LinearFees {

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Fund {
pub value: i32,
pub value: Value,
pub address: String,
}

Expand Down Expand Up @@ -94,11 +95,11 @@ impl GenesisYaml {
let initial_funds = vec![
Fund {
address: String::from(initial_funds_address1),
value: 100,
value: 100.into(),
},
Fund {
address: String::from(initial_funds_address2),
value: 100,
value: 100.into(),
},
];
GenesisYaml::new_with_funds(initial_funds)
Expand Down
1 change: 0 additions & 1 deletion jormungandr-integration-tests/src/common/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod address;
pub mod keys;
pub mod utxo;
pub mod witness;
10 changes: 0 additions & 10 deletions jormungandr-integration-tests/src/common/data/utxo.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,22 @@ pub fn get_rest_utxo_get_command(host: &str) -> Command {
command
}

/// Get adress single command.
/// Get address single command.
pub fn get_address_single_command(public_key: &str, discrimination: Discrimination) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command.arg("address").arg("single").arg(&public_key);
add_discrimination(&mut command, discrimination);
command
}

/// Get adress single command.
/// Get address single command.
pub fn get_address_info_command_default(address: &str) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command.arg("address").arg("info").arg(&address);
command
}

/// Get adress single command.
/// Get address single command.
pub fn get_address_account_command(public_key: &str, discrimination: Discrimination) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command.arg("address").arg("account").arg(&public_key);
Expand All @@ -159,14 +159,14 @@ fn add_discrimination(command: &mut Command, discrimination: Discrimination) {
}
}

/// Get adress single command.
/// Get address single command.
pub fn get_genesis_init_command() -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command.arg("genesis").arg("init");
command
}

/// Get adress single command.
/// Get address single command.
pub fn get_address_delegation_command(
public_key: &str,
delegation_key: &str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl TransactionCommands {
pub fn get_add_input_command(
&self,
tx_id: &str,
tx_index: &i32,
tx_index: u8,
amount: &str,
staging_file: &PathBuf,
) -> Command {
Expand All @@ -47,15 +47,15 @@ impl TransactionCommands {
pub fn get_add_account_command(
&self,
account_addr: &str,
amount: &i32,
amount: &str,
staging_file: &PathBuf,
) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command
.arg("transaction")
.arg("add-account")
.arg(account_addr.to_string())
.arg(amount.to_string())
.arg(amount)
.arg("--staging")
.arg(staging_file.as_os_str());
command
Expand All @@ -64,15 +64,15 @@ impl TransactionCommands {
pub fn get_add_output_command(
&self,
addr: &str,
amount: &i32,
amount: &str,
staging_file: &PathBuf,
) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command
.arg("transaction")
.arg("add-output")
.arg(&addr)
.arg(amount.to_string())
.arg(amount)
.arg("--staging")
.arg(staging_file.as_os_str());
command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ pub mod jcli_transaction_commands;
use self::jcli_transaction_commands::TransactionCommands;
use crate::common::configuration::genesis_model::{Fund, LinearFees};
use crate::common::data::address::AddressDataProvider;
use crate::common::data::utxo::Utxo as UtxoData;
use crate::common::data::witness::Witness;
use crate::common::file_utils;
use crate::common::jcli_wrapper;
use crate::common::process_assert;
use crate::common::process_utils;
use crate::common::process_utils::output_extensions::ProcessOutput;

use jormungandr_lib::{
crypto::hash::Hash,
interfaces::{UTxOInfo, Value},
};
use std::path::PathBuf;

#[derive(Debug)]
Expand Down Expand Up @@ -42,37 +44,41 @@ impl JCLITransactionWrapper {
}

pub fn build_transaction_from_utxo<T: AddressDataProvider, U: AddressDataProvider>(
utxo: &UtxoData,
input_amount: &i32,
reciever: &T,
output_amount: &i32,
utxo: &UTxOInfo,
input_amount: &Value,
receiver: &T,
output_amount: &Value,
sender: &U,
genesis_hash: &str,
) -> JCLITransactionWrapper {
let mut transaction_builder = JCLITransactionWrapper::new_transaction(genesis_hash);
transaction_builder
.assert_add_input(&utxo.in_txid, &utxo.in_idx, &input_amount)
.assert_add_output(&reciever.get_address(), &output_amount)
.assert_add_input(
&utxo.transaction_id(),
utxo.index_in_transaction(),
input_amount,
)
.assert_add_output(&receiver.get_address(), output_amount)
.assert_finalize()
.seal_with_witness_deafult(&sender.get_private_key(), &reciever.get_address_type());
.seal_with_witness_default(&sender.get_private_key(), &receiver.get_address_type());
transaction_builder
}

pub fn build_transaction<T: AddressDataProvider, U: AddressDataProvider>(
transaction_id: &str,
transaction_index: &i32,
input_amount: &i32,
reciever: &T,
output_amount: &i32,
transaction_id: &Hash,
transaction_index: u8,
input_amount: &Value,
receiver: &T,
output_amount: &Value,
sender: &U,
genesis_hash: &str,
) -> JCLITransactionWrapper {
let mut transaction_builder = JCLITransactionWrapper::new_transaction(genesis_hash);
transaction_builder
.assert_add_input(&transaction_id, &transaction_index, &input_amount)
.assert_add_output(&reciever.get_address(), &output_amount)
.assert_add_input(transaction_id, transaction_index, input_amount)
.assert_add_output(&receiver.get_address(), &output_amount)
.assert_finalize()
.seal_with_witness_deafult(&sender.get_private_key(), &reciever.get_address_type());
.seal_with_witness_default(&sender.get_private_key(), &receiver.get_address_type());
transaction_builder
}

Expand All @@ -94,14 +100,14 @@ impl JCLITransactionWrapper {

pub fn assert_add_input<'a>(
&'a mut self,
tx_id: &str,
tx_index: &i32,
amount: &i32,
tx_id: &Hash,
tx_index: u8,
amount: &Value,
) -> &'a mut JCLITransactionWrapper {
let output =
process_utils::run_process_and_get_output(self.commands.get_add_input_command(
&tx_id,
&tx_index,
&tx_id.to_hex(),
tx_index,
&amount.to_string(),
&self.staging_file_path,
));
Expand All @@ -111,16 +117,16 @@ impl JCLITransactionWrapper {

pub fn assert_add_input_fail<'a>(
&'a mut self,
tx_id: &str,
tx_index: &i32,
tx_id: &Hash,
tx_index: u8,
amount: &str,
expected_part: &str,
) -> () {
process_assert::assert_process_failed_and_contains_message(
self.commands.get_add_input_command(
&tx_id,
&tx_index,
&amount,
&tx_id.to_hex(),
tx_index,
amount,
&self.staging_file_path,
),
expected_part,
Expand All @@ -129,36 +135,45 @@ impl JCLITransactionWrapper {

pub fn assert_add_input_from_utxo_with_value<'a>(
&'a mut self,
utxo: &UtxoData,
amount: &i32,
utxo: &UTxOInfo,
amount: &Value,
) -> &'a mut JCLITransactionWrapper {
self.assert_add_input(&utxo.in_txid, &utxo.in_idx, &amount)
self.assert_add_input(&utxo.transaction_id(), utxo.index_in_transaction(), &amount)
}

pub fn assert_add_input_from_utxo<'a>(
&'a mut self,
utxo: &UtxoData,
utxo: &UTxOInfo,
) -> &'a mut JCLITransactionWrapper {
self.assert_add_input(&utxo.in_txid, &utxo.in_idx, &utxo.out_value)
self.assert_add_input(
&utxo.transaction_id(),
utxo.index_in_transaction(),
utxo.associated_fund(),
)
}

pub fn assert_add_account<'a>(
&'a mut self,
account_addr: &str,
amount: &i32,
amount: &Value,
) -> &'a mut JCLITransactionWrapper {
let output = process_utils::run_process_and_get_output(
self.commands
.get_add_account_command(&account_addr, &amount, &self.staging_file_path),
);
let output =
process_utils::run_process_and_get_output(self.commands.get_add_account_command(
&account_addr,
&amount.to_string(),
&self.staging_file_path,
));
process_assert::assert_process_exited_successfully(output);
self
}

pub fn assert_add_account_fail(&self, account_addr: &str, amount: &i32, expected_msg: &str) {
pub fn assert_add_account_fail(&self, account_addr: &str, amount: &Value, expected_msg: &str) {
process_assert::assert_process_failed_and_matches_message(
self.commands
.get_add_account_command(&account_addr, &amount, &self.staging_file_path),
self.commands.get_add_account_command(
&account_addr,
&amount.to_string(),
&self.staging_file_path,
),
expected_msg,
);
}
Expand All @@ -173,12 +188,14 @@ impl JCLITransactionWrapper {
pub fn assert_add_output<'a>(
&'a mut self,
addr: &str,
amount: &i32,
amount: &Value,
) -> &'a mut JCLITransactionWrapper {
let output = process_utils::run_process_and_get_output(
self.commands
.get_add_output_command(&addr, &amount, &self.staging_file_path),
);
let output =
process_utils::run_process_and_get_output(self.commands.get_add_output_command(
&addr,
&amount.to_string(),
&self.staging_file_path,
));
process_assert::assert_process_exited_successfully(output);
self
}
Expand Down Expand Up @@ -234,7 +251,7 @@ impl JCLITransactionWrapper {
self
}

pub fn seal_with_witness_deafult<'a>(
pub fn seal_with_witness_default<'a>(
&'a mut self,
private_key: &str,
transaction_type: &str,
Expand Down
11 changes: 5 additions & 6 deletions jormungandr-integration-tests/src/common/jcli_wrapper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#![allow(dead_code)]

use jormungandr_lib::interfaces::{AccountState, FragmentLog, FragmentStatus};
use jormungandr_lib::interfaces::{AccountState, FragmentLog, FragmentStatus, UTxOInfo};

pub mod certificate;
pub mod jcli_commands;
pub mod jcli_transaction_wrapper;

use super::configuration;
use super::configuration::genesis_model::GenesisYaml;
use super::data::utxo::Utxo;
use super::file_assert;
use super::file_utils;
use super::process_assert;
Expand Down Expand Up @@ -67,18 +66,18 @@ pub fn assert_rest_stats(host: &str) -> BTreeMap<String, String> {
content
}

pub fn assert_rest_utxo_get(host: &str) -> Vec<Utxo> {
pub fn assert_rest_utxo_get(host: &str) -> Vec<UTxOInfo> {
let output =
process_utils::run_process_and_get_output(jcli_commands::get_rest_utxo_get_command(&host));
let content = output.as_lossy_string();
process_assert::assert_process_exited_successfully(output);
let utxos: Vec<Utxo> = serde_yaml::from_str(&content).unwrap();
let utxos: Vec<UTxOInfo> = serde_yaml::from_str(&content).unwrap();
utxos
}

pub fn assert_get_address_info(adress: &str) -> BTreeMap<String, String> {
pub fn assert_get_address_info(address: &str) -> BTreeMap<String, String> {
let output = process_utils::run_process_and_get_output(
jcli_commands::get_address_info_command_default(&adress),
jcli_commands::get_address_info_command_default(&address),
);
let content = output.as_single_node_yaml();
process_assert::assert_process_exited_successfully(output);
Expand Down
Loading