Skip to content

Commit

Permalink
Removed LinearFee duplicated struct (#1588)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania committed Jan 20, 2020
1 parent dab0388 commit 205541b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

extern crate chain_addr;
extern crate chain_crypto;
extern crate chain_impl_mockchain;
extern crate rand;
extern crate rand_chacha;
extern crate serde_derive;
use self::chain_addr::{Address as ChainAddress, Discrimination, Kind};
use self::chain_crypto::bech32::Bech32;
use self::chain_crypto::{Ed25519, Ed25519Extended, KeyPair, PublicKey, SecretKey};
use self::chain_impl_mockchain::fee::LinearFee;
use self::rand::SeedableRng;
use self::rand_chacha::ChaChaRng;
use self::serde_derive::{Deserialize, Serialize};
use super::file_utils;
use jormungandr_lib::interfaces::{
Address, Initial, InitialUTxO, LegacyUTxO, Ratio, RewardParams, TaxType, Value,
Address, Initial, InitialUTxO, LegacyUTxO, LinearFeeDef, Ratio, RewardParams, TaxType, Value,
};
use std::num::NonZeroU32;
use std::path::PathBuf;
Expand All @@ -37,7 +39,8 @@ pub struct BlockchainConfig {
pub consensus_leader_ids: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub consensus_genesis_praos_active_slot_coeff: Option<String>,
pub linear_fees: LinearFees,
#[serde(with = "LinearFeeDef")]
pub linear_fees: LinearFee,
pub kes_update_speed: u32,
#[serde(default)]
pub treasury: Option<Value>,
Expand All @@ -49,23 +52,6 @@ pub struct BlockchainConfig {
pub reward_parameters: Option<RewardParams>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct LinearFees {
pub constant: u64,
pub coefficient: u64,
pub certificate: u64,
}

impl From<chain_impl_mockchain::fee::LinearFee> for LinearFees {
fn from(fees: chain_impl_mockchain::fee::LinearFee) -> LinearFees {
LinearFees {
constant: fees.constant,
coefficient: fees.coefficient,
certificate: fees.certificate,
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GenesisYaml {
pub blockchain_configuration: BlockchainConfig,
Expand Down Expand Up @@ -143,11 +129,7 @@ impl GenesisYaml {
String::from(leader_2_pk),
]),
consensus_genesis_praos_active_slot_coeff: Some("0.444".to_owned()),
linear_fees: LinearFees {
constant: 0,
coefficient: 0,
certificate: 0,
},
linear_fees: LinearFee::new(0, 0, 0),
kes_update_speed: 12 * 3600,
treasury: Some(1_000_000.into()),
treasury_parameters: Some(TaxType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::path::PathBuf;
use std::process::Command;

use crate::common::configuration;
use crate::common::configuration::genesis_model::LinearFees;

use chain_impl_mockchain::fee::LinearFee;

#[derive(Debug)]
pub struct TransactionCommands {}
Expand Down Expand Up @@ -106,7 +107,7 @@ impl TransactionCommands {
pub fn get_finalize_with_fee_command<P: AsRef<Path>>(
&self,
address: &str,
linear_fees: &LinearFees,
linear_fees: &LinearFee,
staging_file: &P,
) -> Command {
let mut command = Command::new(configuration::get_jcli_app().as_os_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pub mod jcli_transaction_commands;

use self::jcli_transaction_commands::TransactionCommands;
use crate::common::configuration::genesis_model::LinearFees;
use crate::common::data::address::AddressDataProvider;
use crate::common::data::witness::Witness;
use crate::common::file_utils;
Expand All @@ -12,7 +11,7 @@ use crate::common::process_assert;
use crate::common::process_utils;
use crate::common::process_utils::output_extensions::ProcessOutput;
use chain_core::property::Deserialize;
use chain_impl_mockchain::fragment::Fragment;
use chain_impl_mockchain::{fee::LinearFee, fragment::Fragment};
use jormungandr_lib::{
crypto::hash::Hash,
interfaces::{LegacyUTxO, UTxOInfo, Value},
Expand Down Expand Up @@ -202,11 +201,7 @@ impl JCLITransactionWrapper {
self
}

pub fn assert_finalize_with_fee(
&mut self,
address: &str,
linear_fee: &LinearFees,
) -> &mut Self {
pub fn assert_finalize_with_fee(&mut self, address: &str, linear_fee: &LinearFee) -> &mut Self {
let output =
process_utils::run_process_and_get_output(self.commands.get_finalize_with_fee_command(
&address,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::{
configuration::{
genesis_model::{GenesisYaml, LinearFees},
genesis_model::GenesisYaml,
jormungandr_config::JormungandrConfig,
node_config_model::{Log, LogEntry, NodeConfig, TrustedPeer},
secret_model::SecretModel,
Expand All @@ -9,6 +9,8 @@ use crate::common::{
startup::build_genesis_block,
};

use chain_impl_mockchain::fee::LinearFee;

use jormungandr_lib::interfaces::{Initial, InitialUTxO, Mempool, SignedCertificate};

pub struct ConfigurationBuilder {
Expand All @@ -25,7 +27,7 @@ pub struct ConfigurationBuilder {
slot_duration: Option<u32>,
epoch_stability_depth: Option<u32>,
kes_update_speed: u32,
linear_fees: LinearFees,
linear_fees: LinearFee,
consensus_leader_ids: Vec<String>,
mempool: Option<Mempool>,
enable_explorer: bool,
Expand All @@ -49,11 +51,7 @@ impl ConfigurationBuilder {
level: Some("info".to_string()),
format: Some("json".to_string()),
}])),
linear_fees: LinearFees {
constant: 0,
coefficient: 0,
certificate: 0,
},
linear_fees: LinearFee::new(0, 0, 0),
consensus_genesis_praos_active_slot_coeff: Some("0.1".to_owned()),
kes_update_speed: 12 * 3600,
mempool: None,
Expand Down Expand Up @@ -81,7 +79,7 @@ impl ConfigurationBuilder {
self
}

pub fn with_linear_fees(&mut self, linear_fees: LinearFees) -> &mut Self {
pub fn with_linear_fees(&mut self, linear_fees: LinearFee) -> &mut Self {
self.linear_fees = linear_fees;
self
}
Expand Down
19 changes: 5 additions & 14 deletions jormungandr-integration-tests/src/jcli/transaction/e2e.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::common::{
configuration::genesis_model::LinearFees,
jcli_wrapper::{self, jcli_transaction_wrapper::JCLITransactionWrapper},
jormungandr::{ConfigurationBuilder, Starter},
startup,
Expand All @@ -9,6 +8,8 @@ use jormungandr_lib::{
interfaces::{InitialUTxO, UTxOInfo},
};

use chain_impl_mockchain::fee::LinearFee;

lazy_static! {
static ref FAKE_INPUT_TRANSACTION_ID: Hash = {
"19c9852ca0a68f15d0f7de5d1a26acd67a3a3251640c6066bdb91d22e2000193"
Expand Down Expand Up @@ -495,16 +496,13 @@ pub fn test_input_with_no_spending_utxo_is_rejected_by_node() {
pub fn test_transaction_with_non_zero_linear_fees() {
let sender = startup::create_new_utxo_address();
let receiver = startup::create_new_utxo_address();
let fee = LinearFee::new(10, 1, 0);
let config = ConfigurationBuilder::new()
.with_funds(vec![InitialUTxO {
address: sender.address.parse().unwrap(),
value: 100.into(),
}])
.with_linear_fees(LinearFees {
constant: 10,
coefficient: 1,
certificate: 0,
})
.with_linear_fees(fee.clone())
.build();

let jormungandr = Starter::new().config(config.clone()).start().unwrap();
Expand All @@ -513,14 +511,7 @@ pub fn test_transaction_with_non_zero_linear_fees() {
let transaction_message = tx
.assert_add_input_from_utxo(&utxo)
.assert_add_output(&receiver.address, &50.into())
.assert_finalize_with_fee(
&sender.address,
&LinearFees {
constant: 10,
coefficient: 1,
certificate: 0,
},
)
.assert_finalize_with_fee(&sender.address, &fee)
.seal_with_witness_for_address(&sender)
.assert_to_message();
let tx_id = tx.get_fragment_id();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::common::{
configuration::genesis_model::LinearFees,
data::address::Account,
file_utils,
jcli_wrapper::{
Expand All @@ -13,6 +12,7 @@ use crate::common::{

use chain_addr::Discrimination;
use chain_crypto::{Curve25519_2HashDH, SumEd25519_12};
use chain_impl_mockchain::fee::LinearFee;
use jormungandr_lib::{
crypto::hash::Hash,
interfaces::{InitialUTxO, Ratio, TaxType, Value},
Expand All @@ -31,11 +31,7 @@ pub fn create_delegate_retire_stake_pool() {
let mut actor_account = startup::create_new_account_address();

let config = ConfigurationBuilder::new()
.with_linear_fees(LinearFees {
constant: 100,
coefficient: 100,
certificate: 200,
})
.with_linear_fees(LinearFee::new(100, 100, 200))
.with_funds(vec![InitialUTxO {
value: 1000000.into(),
address: actor_account.address.parse().unwrap(),
Expand Down Expand Up @@ -79,7 +75,7 @@ pub fn create_new_stake_pool(
file_utils::create_file_in_temp("stake_key.private_key", &account.private_key);

let settings = jcli_wrapper::assert_get_rest_settings(&jormungandr_rest_address);
let fees: LinearFees = settings.fees.into();
let fees: LinearFee = settings.fees.into();
let fee_value: Value = (fees.certificate + fees.coefficient + fees.constant).into();

let certificate_wrapper = JCLICertificateWrapper::new();
Expand Down Expand Up @@ -139,7 +135,7 @@ pub fn delegate_stake(
certificate_wrapper.assert_new_stake_delegation(&stake_pool_id, &account.public_key);

let settings = jcli_wrapper::assert_get_rest_settings(&jormungandr_rest_address);
let fees: LinearFees = settings.fees.into();
let fees: LinearFee = settings.fees.into();
let fee_value: Value = (fees.certificate + fees.coefficient + fees.constant).into();

let transaction = JCLITransactionWrapper::new_transaction(genesis_block_hash)
Expand Down Expand Up @@ -186,7 +182,7 @@ pub fn retire_stake_pool(
let retirement_cert = certificate_wrapper.assert_new_stake_pool_retirement(&stake_pool_id);

let settings = jcli_wrapper::assert_get_rest_settings(&jormungandr_rest_address);
let fees: LinearFees = settings.fees.into();
let fees: LinearFee = settings.fees.into();
let fee_value: Value = (fees.certificate + fees.coefficient + fees.constant).into();

let transaction = JCLITransactionWrapper::new_transaction(genesis_block_hash)
Expand Down

0 comments on commit 205541b

Please sign in to comment.