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

GH-672: review 3 #314

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
GH-672-with-agent: approaching the fixture...this might work well; la…
…st vexing situations unhandled meaning there are like 8 failing tests at the moment
  • Loading branch information
Bert authored and Bert committed Jun 29, 2023
commit b587d87d04d30c144408cf73874f210d10ef0031
27 changes: 13 additions & 14 deletions node/src/accountant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ mod tests {
use crate::test_utils::recorder::peer_actors_builder;
use crate::test_utils::recorder::Recorder;
use crate::test_utils::recorder_stop_conditions::{StopCondition, StopConditions};
use crate::test_utils::unshared_test_utils::arbitrary_id_stamp::ArbitraryIdStamp;
use crate::test_utils::unshared_test_utils::notify_handlers::NotifyLaterHandleMock;
use crate::test_utils::unshared_test_utils::system_killer_actor::SystemKillerActor;
use crate::test_utils::unshared_test_utils::{
Expand Down Expand Up @@ -1433,13 +1434,12 @@ mod tests {
transaction_fee_currency_in_minor_units: U256::from(u32::MAX),
masq_tokens_in_minor_units: U256::from(u32::MAX),
};
let agent = PayablePaymentsAgentMock::default()
.estimated_fees_result(112_000)
.consuming_wallet_balances_result(Some(consuming_wallet_balances))
.requested_unit_price_result(132);
let arbitrary_id_stamp = ArbitraryIdStamp::new();
let agent = PayablePaymentsAgentMock::default().set_arbitrary_id_stamp(arbitrary_id_stamp);
let agent_boxed = Box::new(agent) as Box<dyn PayablePaymentsAgent>;
let expected_payable_payments_setup_msg = PayablePaymentsSetupMsg {
qualified_payables: vec![account_1.clone(), account_2.clone()],
agent: Box::new(agent),
agent: agent_boxed.clone(),
response_skeleton_opt: Some(ResponseSkeleton {
client_id: 1234,
context_id: 4321,
Expand All @@ -1464,7 +1464,7 @@ mod tests {
blockchain_bridge_recording.get_record::<OutboundPaymentsInstructions>(0),
&OutboundPaymentsInstructions {
checked_accounts: vec![account_1, account_2],
agent: todo!("write an assertion on the arbitrary id"),
agent: agent_boxed,
response_skeleton_opt: Some(ResponseSkeleton {
client_id: 1234,
context_id: 4321,
Expand Down Expand Up @@ -1514,7 +1514,8 @@ mod tests {
context_id: 55,
};
let mut agent = PayablePaymentsAgentWeb3::new(78910);
agent.ask_for_price_per_computed_unit(Some(30));
let persistent_config = PersistentConfigurationMock::default().gas_price_result(Ok(123));
let _ = agent.consult_desired_fee_per_computed_unit(&persistent_config);
let boxed_agent = Box::new(agent);
let adjusted_payments_instructions = OutboundPaymentsInstructions {
checked_accounts: vec![adjusted_account_1.clone(), adjusted_account_2.clone()],
Expand All @@ -1537,13 +1538,11 @@ mod tests {
transaction_fee_currency_in_minor_units: U256::from(u32::MAX),
masq_tokens_in_minor_units: U256::from(150_000_000_000_u64),
};
let agent = PayablePaymentsAgentMock::default()
.consuming_wallet_balances_result(Some(consuming_wallet_balances))
.estimated_fees_result(110_000)
.requested_unit_price_result(30);
let arbitrary_id_stamp = ArbitraryIdStamp::new();
let agent = PayablePaymentsAgentMock::default().set_arbitrary_id_stamp(arbitrary_id_stamp);
let payable_payments_setup_msg = PayablePaymentsSetupMsg {
qualified_payables: vec![unadjusted_account_1.clone(), unadjusted_account_2.clone()],
agent: Box::new(agent),
agent: boxed_agent.clone(),
response_skeleton_opt: Some(response_skeleton),
};

Expand Down Expand Up @@ -2419,12 +2418,12 @@ mod tests {
let recording = blockchain_bridge_recording.lock().unwrap();
let messages_received = recording.len();
assert_eq!(messages_received, 2);
let first_message: &PayablePaymentsSetupMsg = recording.get_record(0);
let first_message: &InitialPayablePaymentsSetupMsg = recording.get_record(0);
assert_eq!(
first_message.response_skeleton_opt,
message_before.response_skeleton_opt
);
let second_message: &PayablePaymentsSetupMsg = recording.get_record(1);
let second_message: &InitialPayablePaymentsSetupMsg = recording.get_record(1);
assert_eq!(
second_message.response_skeleton_opt,
message_after.response_skeleton_opt
Expand Down
4 changes: 2 additions & 2 deletions node/src/accountant/payment_adjuster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {
};
let mut agent_for_enough = PayablePaymentsAgentMock::default()
.consuming_wallet_balances_result(Some(consuming_wallet_balances))
.estimated_fees_result(1_000_000_000_000_000);
.estimated_transaction_fee_result(1_000_000_000_000_000);
let non_required = PayablePaymentsSetupMsg {
qualified_payables: vec![payable_1.clone(), payable_2.clone()],
agent: Box::new(agent_for_enough),
Expand All @@ -112,7 +112,7 @@ mod tests {
};
let mut agent_for_insufficient = PayablePaymentsAgentMock::default()
.consuming_wallet_balances_result(Some(consuming_wallet_balances))
.estimated_fees_result(1_000_000_000_000_000);
.estimated_transaction_fee_result(1_000_000_000_000_000);
let should_require = PayablePaymentsSetupMsg {
qualified_payables: vec![payable_1, payable_2],
agent: Box::new(agent_for_insufficient),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//Cardano No *wr

use crate::arbitrary_id_stamp_in_trait;
use crate::blockchain::blockchain_interface::{BlockchainError, BlockchainInterface};
use crate::db_config::persistent_configuration::{PersistentConfigError, PersistentConfiguration};
use crate::sub_lib::blockchain_bridge::ConsumingWalletBalances;
use crate::test_utils::unshared_test_utils::arbitrary_id_stamp::ArbitraryIdStamp;
Expand All @@ -22,18 +21,15 @@ use web3::types::U256;

pub trait PayablePaymentsAgent: Send {
//e.g. Cardano does not require user's own choice of price
fn ask_for_price_per_computed_unit(
fn consult_desired_fee_per_computed_unit(
&mut self,
persistent_config: &dyn PersistentConfiguration,
) -> Result<(), PersistentConfigError>;
fn ask_for_pending_transaction_id(
&mut self,
blockchain_interface: &dyn BlockchainInterface,
) -> Result<(), BlockchainError>;
fn set_up_pending_transaction_id(&mut self, id: U256);
fn set_up_consuming_wallet_balances(&mut self, balances: ConsumingWalletBalances);
fn estimated_fees(&self, number_of_transactions: usize) -> u128;
fn consuming_wallet_balances(&self) -> Option<&ConsumingWalletBalances>;
fn price_per_computed_unit(&self) -> Option<u64>;
fn estimated_transaction_fee(&self, number_of_transactions: usize) -> u128;
fn consuming_wallet_balances(&self) -> Option<ConsumingWalletBalances>;
fn desired_fee_per_computed_unit(&self) -> Option<u64>;
fn pending_transaction_id(&self) -> Option<U256>;
fn debug(&self) -> String;
fn duplicate(&self) -> Box<dyn PayablePaymentsAgent>;
Expand All @@ -54,20 +50,24 @@ impl Debug for Box<dyn PayablePaymentsAgent> {

impl Clone for Box<dyn PayablePaymentsAgent> {
fn clone(&self) -> Self {
todo!()
self.duplicate()
}
}

#[cfg(test)]
mod tests {
use crate::accountant::scanners::payable_payments_agent_abstract_layer::PayablePaymentsAgent;
use crate::accountant::scanners::payable_payments_agent_web3::PayablePaymentsAgentWeb3;
use crate::accountant::test_utils::PayablePaymentsAgentMock;
use crate::accountant::test_utils::{
assert_on_cloneable_agent_objects, PayablePaymentsAgentMock,
};
use crate::sub_lib::blockchain_bridge::ConsumingWalletBalances;
use crate::test_utils::persistent_configuration_mock::PersistentConfigurationMock;
use crate::test_utils::unshared_test_utils::arbitrary_id_stamp::ArbitraryIdStamp;
use web3::types::U256;

#[test]
fn even_abstract_payable_payments_agent_implements_partial_eq() {
fn trait_object_like_payable_payments_agent_implements_partial_eq() {
let mut agent_a =
Box::new(PayablePaymentsAgentWeb3::new(45678)) as Box<dyn PayablePaymentsAgent>;
let agent_b =
Expand All @@ -92,21 +92,34 @@ mod tests {
assert_eq!(&agent_d, &agent_e);
assert_ne!(&agent_d, &agent_f);

agent_a.ask_for_pending_transaction_id(U256::from(1234));
agent_c.ask_for_pending_transaction_id(U256::from(1234));
agent_a.set_up_pending_transaction_id(U256::from(1234));
agent_c.set_up_pending_transaction_id(U256::from(1234));
assert_eq!(&agent_a, &agent_c);
agent_c.ask_for_pending_transaction_id(U256::from(5678));
agent_c.set_up_pending_transaction_id(U256::from(5678));
assert_ne!(&agent_a, &agent_c);
}

#[test]
fn payable_payments_agent_implements_debug() {
fn trait_object_like_payable_payments_agent_implements_debug() {
let subject = Box::new(PayablePaymentsAgentWeb3::new(456)) as Box<dyn PayablePaymentsAgent>;

let result = format!("{:?}", subject);

let expected = "Trait object of: PayablePaymentsAgentWeb3 \
{ gas_limit_const_part: 456, upmost_added_gas_margin: 3328, pending_transaction_id_opt: None }";
let expected = "Trait object of: PayablePaymentsAgentWeb3 { \
gas_limit_const_part: 456, \
upmost_added_gas_margin: 3328, \
consuming_wallet_balance_opt: None, \
pending_transaction_id_opt: None, \
desired_fee_per_computed_unit_gwei_opt: None \
}";
assert_eq!(result, expected)
}

#[test]
fn trait_object_like_payable_payments_agent_implements_clone() {
assert_on_cloneable_agent_objects(|original_agent: PayablePaymentsAgentWeb3| {
let boxed_agent = Box::new(original_agent) as Box<dyn PayablePaymentsAgent>;
boxed_agent.clone()
})
}
}
Loading