Skip to content
Permalink
Browse files

Test case for non-zero linear fee

Signed-off-by: dkijania <dariusz.kijania@iohk.io>
  • Loading branch information...
dkijania committed Jun 13, 2019
1 parent e63f603 commit 9525c15ba37d9b366947c5e9ab4859bfeef04bce
@@ -86,6 +86,30 @@ impl TransactionCommands {
command
}

pub fn get_finalize_with_fee_command(
&self,
address: &str,
fee_constant: &i32,
fee_coefficient: &i32,
fee_certificate: &i32,
staging_file: &PathBuf,
) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command
.arg("transaction")
.arg("finalize")
.arg(address)
.arg("--fee-certificate")
.arg(fee_certificate.to_string())
.arg("--fee-coefficient")
.arg(fee_coefficient.to_string())
.arg("--fee-constant")
.arg(fee_constant.to_string())
.arg("--staging")
.arg(staging_file.as_os_str());
command
}

pub fn get_make_witness_command(
&self,
block0_hash: &str,
@@ -157,4 +181,14 @@ impl TransactionCommands {
.arg(staging_file.as_os_str());
command
}

pub fn get_transaction_info_command(&self, staging_file: &PathBuf) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
command
.arg("transaction")
.arg("info")
.arg("--staging")
.arg(staging_file.as_os_str());
command
}
}
@@ -3,7 +3,7 @@
pub mod jcli_transaction_commands;

use self::jcli_transaction_commands::TransactionCommands;
use crate::common::configuration::genesis_model::Fund;
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;
@@ -12,6 +12,7 @@ use crate::common::jcli_wrapper;
use crate::common::process_assert;
use crate::common::process_utils;
use crate::common::process_utils::output_extensions::ProcessOutput;

use std::path::PathBuf;

#[derive(Debug)]
@@ -190,6 +191,23 @@ impl JCLITransactionWrapper {
self
}

pub fn assert_finalize_with_fee<'a>(
&'a mut self,
address: &str,
linear_fee: &LinearFees,
) -> &'a mut JCLITransactionWrapper {
let output =
process_utils::run_process_and_get_output(self.commands.get_finalize_with_fee_command(
&address,
&linear_fee.constant,
&linear_fee.coefficient,
&linear_fee.certificate,
&self.staging_file_path,
));
process_assert::assert_process_exited_successfully(output);
self
}

pub fn assert_finalize_fail(&self, expected_part: &str) -> () {
let output = process_utils::run_process_and_get_output(
self.commands.get_finalize_command(&self.staging_file_path),
@@ -341,4 +359,14 @@ impl JCLITransactionWrapper {
let mut split = content.split_whitespace();
split.next().unwrap().to_string()
}

pub fn get_transaction_info(&self) -> String {
let output = process_utils::run_process_and_get_output(
self.commands
.get_transaction_info_command(&self.staging_file_path),
);
let content = output.as_single_line();
let mut split = content.split_whitespace();
split.next().unwrap().to_string()
}
}
@@ -1,5 +1,5 @@
use crate::common::configuration::{
genesis_model::{Fund, GenesisYaml},
genesis_model::{Fund, GenesisYaml, LinearFees},
jormungandr_config::JormungandrConfig,
node_config_model::{Logger, NodeConfig, Peer},
secret_model::SecretModel,
@@ -15,6 +15,7 @@ pub struct ConfigurationBuilder {
bft_slots_ratio: Option<String>,
consensus_genesis_praos_active_slot_coeff: Option<String>,
kes_update_speed: u32,
linear_fees: LinearFees,
certs: Vec<String>,
consensus_leader_ids: Vec<String>,
}
@@ -29,6 +30,11 @@ impl ConfigurationBuilder {
block0_hash: None,
block0_consensus: Some("bft".to_string()),
logger: None,
linear_fees: LinearFees {
constant: 0,
coefficient: 0,
certificate: 0,
},
bft_slots_ratio: Some("0.222".to_owned()),
consensus_genesis_praos_active_slot_coeff: Some("0.1".to_owned()),
kes_update_speed: 12 * 3600,
@@ -40,6 +46,11 @@ impl ConfigurationBuilder {
self
}

pub fn with_linear_fees<'a>(&'a mut self, linear_fees: LinearFees) -> &'a mut Self {
self.linear_fees = linear_fees;
self
}

pub fn with_consensus_leaders_ids<'a>(
&'a mut self,
consensus_leader_ids: Vec<String>,
@@ -112,6 +123,7 @@ impl ConfigurationBuilder {
.blockchain_configuration
.consensus_genesis_praos_active_slot_coeff =
self.consensus_genesis_praos_active_slot_coeff.clone();
genesis_model.blockchain_configuration.linear_fees = self.linear_fees.clone();
genesis_model.initial_certs = self.certs.clone();
let path_to_output_block = super::build_genesis_block(&genesis_model);

@@ -515,4 +515,52 @@ pub fn test_input_with_no_spending_utxo_is_rejected_by_node() {
"Inputs, outputs and fees are not balanced, transaction with 100 input and 50 output",
);
}

#[test]
#[ignore] //#449
pub fn test_transaction_with_non_zero_linear_fees() {
let sender = startup::create_new_utxo_address();
let reciever = startup::create_new_utxo_address();
let mut config = startup::ConfigurationBuilder::new()
.with_funds(vec![Fund {
address: sender.address.clone(),
value: 100,
}])
.with_linear_fees(LinearFees {
constant: 10,
coefficient: 1,
certificate: 0,
})
.build();

let jormungandr_rest_address = config.get_node_address();
let _jormungandr = startup::start_jormungandr_node_as_leader(&mut config);
let utxo = startup::get_utxo_for_address(&sender, &jormungandr_rest_address);
let mut transaction_builder =
JCLITransactionWrapper::new_transaction(&config.genesis_block_hash);
transaction_builder
.assert_add_input_from_utxo(&utxo)
.assert_add_output(&reciever.address, &50)
.assert_finalize_with_fee(
&sender.address,
&LinearFees {
constant: 10,
coefficient: 1,
certificate: 0,
},
)
.seal_with_witness_deafult(&sender.private_key, "utxo");
let transaction_message = transaction_builder.assert_transaction_to_message();

transaction_builder.get_transaction_info();

jcli_wrapper::assert_transaction_in_block(&transaction_message, &jormungandr_rest_address);

let utxo = startup::get_utxo_for_address(&reciever, &jormungandr_rest_address);
assert_eq!(utxo.out_value, 50, "Wrong funds amount on receiver account");
let utxo = startup::get_utxo_for_address(&sender, &jormungandr_rest_address);
assert_eq!(
utxo.out_value, 37,
"Wrong remaining funds amount on sender account"
);
}

0 comments on commit 9525c15

Please sign in to comment.
You can’t perform that action at this time.