Skip to content

Commit

Permalink
GH-672: lower interface renames
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert authored and Bert committed Oct 13, 2023
1 parent c71662b commit 89434e8
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 96 deletions.
18 changes: 11 additions & 7 deletions node/src/blockchain/blockchain_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ mod tests {
BlockchainTransaction, RetrievedBlockchainTransactions,
};
use crate::blockchain::blockchain_interface::lower_level_interface::LatestBlockNumber;
use crate::blockchain::blockchain_interface::test_utils::LowerBCIMock;
use crate::blockchain::blockchain_interface::test_utils::LowBlockchainIntMock;
use crate::blockchain::test_utils::{make_tx_hash, BlockchainInterfaceMock};
use crate::db_config::persistent_configuration::PersistentConfigError;
use crate::match_every_type_id;
Expand Down Expand Up @@ -1123,7 +1123,7 @@ mod tests {
.system_stop_conditions(match_every_type_id!(ScanError))
.start()
.recipient();
let lower_interface = LowerBCIMock::default()
let lower_interface = LowBlockchainIntMock::default()
.get_block_number_result(LatestBlockNumber::Ok(U64::from(1234u64)));
let blockchain_interface = BlockchainInterfaceMock::default()
.retrieve_transactions_result(Err(BlockchainError::QueryFailed(
Expand Down Expand Up @@ -1419,7 +1419,7 @@ mod tests {
],
};
let lower_interface =
LowerBCIMock::default().get_block_number_result(LatestBlockNumber::Err(
LowBlockchainIntMock::default().get_block_number_result(LatestBlockNumber::Err(
BlockchainError::QueryFailed("Failed to read the latest block number".to_string()),
));
let blockchain_interface_mock = BlockchainInterfaceMock::default()
Expand Down Expand Up @@ -1512,7 +1512,8 @@ mod tests {
],
};
let latest_block_number = LatestBlockNumber::Ok(1024u64.into());
let lower_interface = LowerBCIMock::default().get_block_number_result(latest_block_number);
let lower_interface =
LowBlockchainIntMock::default().get_block_number_result(latest_block_number);
let blockchain_interface_mock = BlockchainInterfaceMock::default()
.retrieve_transactions_params(&retrieve_transactions_params_arc)
.retrieve_transactions_result(Ok(expected_transactions.clone()))
Expand Down Expand Up @@ -1578,7 +1579,8 @@ mod tests {
#[test]
fn processing_of_received_payments_continues_even_if_no_payments_are_detected() {
init_test_logging();
let lower_interface = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let lower_interface =
LowBlockchainIntMock::default().get_block_number_result(Ok(0u64.into()));
let blockchain_interface_mock = BlockchainInterfaceMock::default()
.retrieve_transactions_result(Ok(RetrievedBlockchainTransactions {
new_start_block: 7,
Expand Down Expand Up @@ -1644,7 +1646,8 @@ mod tests {
expected = "Cannot retrieve start block from database; payments to you may not be processed: TransactionError"
)]
fn handle_retrieve_transactions_panics_if_start_block_cannot_be_read() {
let lower_interface = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let lower_interface =
LowBlockchainIntMock::default().get_block_number_result(Ok(0u64.into()));
let blockchain_interface =
BlockchainInterfaceMock::default().lower_interface_results(Box::new(lower_interface));
let persistent_config = PersistentConfigurationMock::new()
Expand Down Expand Up @@ -1672,7 +1675,8 @@ mod tests {
.start_block_result(Ok(1234))
.max_block_count_result(Ok(Some(10000u64)))
.set_start_block_result(Err(PersistentConfigError::TransactionError));
let lower_interface = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let lower_interface =
LowBlockchainIntMock::default().get_block_number_result(Ok(0u64.into()));
let blockchain_interface = BlockchainInterfaceMock::default()
.retrieve_transactions_result(Ok(RetrievedBlockchainTransactions {
new_start_block: 1234,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

use crate::blockchain::blockchain_interface::data_structures::errors::BlockchainError;
use crate::blockchain::blockchain_interface::lower_level_interface::{
LatestBlockNumber, LowerBCI, ResultForBalance, ResultForNonce,
LatestBlockNumber, LowBlockchainInt, ResultForBalance, ResultForNonce,
};
use crate::sub_lib::wallet::Wallet;
use masq_lib::logger::Logger;

pub struct LowerBCINull {
pub struct LowBlockChainIntNull {
logger: Logger,
}

impl LowerBCI for LowerBCINull {
impl LowBlockchainInt for LowBlockChainIntNull {
fn get_transaction_fee_balance(&self, _wallet: &Wallet) -> ResultForBalance {
Err(self.handle_null_call("transaction fee balance"))
}
Expand All @@ -29,7 +29,7 @@ impl LowerBCI for LowerBCINull {
}
}

impl LowerBCINull {
impl LowBlockChainIntNull {
pub fn new(logger: &Logger) -> Self {
Self {
logger: logger.clone(),
Expand All @@ -45,55 +45,59 @@ impl LowerBCINull {
#[cfg(test)]
mod tests {
use crate::blockchain::blockchain_interface::BlockchainError;
use crate::blockchain::blockchain_interface::blockchain_interface_null::lower_level_interface_null::LowerBCINull;
use crate::blockchain::blockchain_interface::lower_level_interface::LowerBCI;
use crate::blockchain::blockchain_interface::blockchain_interface_null::lower_level_interface_null::LowBlockChainIntNull;
use crate::blockchain::blockchain_interface::lower_level_interface::LowBlockchainInt;
use crate::sub_lib::wallet::Wallet;
use crate::test_utils::make_wallet;
use masq_lib::logger::Logger;
use masq_lib::test_utils::logging::{init_test_logging, TestLogHandler};
use std::fmt::Debug;

#[test]
fn lower_bci_null_gets_no_transaction_fee_balance() {
let test_name = "lower_bci_null_gets_no_transaction_fee_balance";
let act =
|subject: &LowerBCINull, wallet: &Wallet| subject.get_transaction_fee_balance(wallet);
fn low_bci_null_gets_no_transaction_fee_balance() {
let test_name = "low_bci_null_gets_no_transaction_fee_balance";
let act = |subject: &LowBlockChainIntNull, wallet: &Wallet| {
subject.get_transaction_fee_balance(wallet)
};

test_null_method(test_name, act, "transaction fee balance");
}

#[test]
fn lower_bci_null_gets_no_masq_balance() {
let test_name = "lower_bci_null_gets_no_masq_balance";
let act = |subject: &LowerBCINull, wallet: &Wallet| subject.get_service_fee_balance(wallet);
fn low_bci_null_gets_no_masq_balance() {
let test_name = "low_bci_null_gets_no_masq_balance";
let act = |subject: &LowBlockChainIntNull, wallet: &Wallet| {
subject.get_service_fee_balance(wallet)
};

test_null_method(test_name, act, "masq balance");
}

#[test]
fn lower_bci_null_gets_no_block_number() {
let test_name = "lower_bci_null_gets_no_block_number";
let act = |subject: &LowerBCINull, _wallet: &Wallet| subject.get_block_number();
fn low_bci_null_gets_no_block_number() {
let test_name = "low_bci_null_gets_no_block_number";
let act = |subject: &LowBlockChainIntNull, _wallet: &Wallet| subject.get_block_number();

test_null_method(test_name, act, "block number");
}

#[test]
fn lower_bci_null_gets_no_transaction_id() {
let test_name = "lower_bci_null_gets_no_transaction_id";
let act = |subject: &LowerBCINull, wallet: &Wallet| subject.get_transaction_id(wallet);
fn low_bci_null_gets_no_transaction_id() {
let test_name = "low_bci_null_gets_no_transaction_id";
let act =
|subject: &LowBlockChainIntNull, wallet: &Wallet| subject.get_transaction_id(wallet);

test_null_method(test_name, act, "transaction id");
}

fn test_null_method<T: Debug + PartialEq>(
test_name: &str,
act: fn(&LowerBCINull, &Wallet) -> Result<T, BlockchainError>,
act: fn(&LowBlockChainIntNull, &Wallet) -> Result<T, BlockchainError>,
expected_method_name: &str,
) {
init_test_logging();
let wallet = make_wallet("blah");
let subject = LowerBCINull::new(&Logger::new(test_name));
let subject = LowBlockChainIntNull::new(&Logger::new(test_name));

let result = act(&subject, &wallet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pub mod lower_level_interface_null;
use crate::accountant::db_access_objects::payable_dao::PayableAccount;
use crate::accountant::scanners::mid_scan_msg_handling::payable_scanner::blockchain_agent::BlockchainAgent;
use crate::blockchain::blockchain_bridge::PendingPayableFingerprintSeeds;
use crate::blockchain::blockchain_interface::blockchain_interface_null::lower_level_interface_null::LowerBCINull;
use crate::blockchain::blockchain_interface::lower_level_interface::LowerBCI;
use crate::blockchain::blockchain_interface::blockchain_interface_null::lower_level_interface_null::LowBlockChainIntNull;
use crate::blockchain::blockchain_interface::lower_level_interface::LowBlockchainInt;
use crate::db_config::persistent_configuration::PersistentConfiguration;
use crate::sub_lib::wallet::Wallet;
use actix::Recipient;
Expand All @@ -18,7 +18,7 @@ use crate::blockchain::blockchain_interface::data_structures::{ProcessedPayableF

pub struct BlockchainInterfaceNull {
logger: Logger,
helper: Box<dyn LowerBCI>,
lower_level_interface: Box<dyn LowBlockchainInt>,
}

impl BlockchainInterface for BlockchainInterfaceNull {
Expand Down Expand Up @@ -57,9 +57,12 @@ impl BlockchainInterface for BlockchainInterfaceNull {
self.handle_uninitialized_interface("get transaction receipt")
}

fn lower_interface(&self) -> &dyn LowerBCI {
error!(self.logger, "Provides null RPC helpers only");
&*self.helper
fn lower_interface(&self) -> &dyn LowBlockchainInt {
error!(
self.logger,
"Provides the null version of lower blockchain interface only"
);
&*self.lower_level_interface
}

as_any_in_trait_impl!();
Expand Down Expand Up @@ -96,8 +99,11 @@ impl_bci_uninitialized!(
impl BlockchainInterfaceNull {
pub fn new() -> Self {
let logger = Logger::new("BlockchainInterface");
let helper = Box::new(LowerBCINull::new(&logger));
BlockchainInterfaceNull { logger, helper }
let lower_level_interface = Box::new(LowBlockChainIntNull::new(&logger));
BlockchainInterfaceNull {
logger,
lower_level_interface,
}
}

fn handle_uninitialized_interface<Irrelevant, E>(
Expand Down Expand Up @@ -126,7 +132,7 @@ impl BlockchainInterfaceNull {
mod tests {
use crate::accountant::scanners::mid_scan_msg_handling::payable_scanner::agent_null::BlockchainAgentNull;
use crate::accountant::test_utils::make_payable_account;
use crate::blockchain::blockchain_interface::blockchain_interface_null::lower_level_interface_null::LowerBCINull;
use crate::blockchain::blockchain_interface::blockchain_interface_null::lower_level_interface_null::LowBlockChainIntNull;
use crate::blockchain::blockchain_interface::blockchain_interface_null::{
BlockchainInterfaceNull, BlockchainInterfaceUninitializedError,
};
Expand All @@ -144,8 +150,11 @@ mod tests {

fn make_subject(test_name: &str) -> BlockchainInterfaceNull {
let logger = Logger::new(test_name);
let helper = Box::new(LowerBCINull::new(&logger));
BlockchainInterfaceNull { logger, helper }
let lower_level_interface = Box::new(LowBlockChainIntNull::new(&logger));
BlockchainInterfaceNull {
logger,
lower_level_interface,
}
}

#[test]
Expand Down Expand Up @@ -244,21 +253,22 @@ mod tests {
}

#[test]
fn blockchain_interface_null_gives_null_helper() {
fn blockchain_interface_null_gives_null_lower_interface() {
init_test_logging();
let test_name = "blockchain_interface_null_gives_null_helper";
let test_name = "blockchain_interface_null_gives_null_lower_interface";
let wallet = make_wallet("abc");

let _ = make_subject(test_name)
.lower_interface()
.get_transaction_id(&wallet);

let expected_log_msg_from_helpers_call =
format!("ERROR: {test_name}: Provides null RPC helpers only");
let expected_log_msg_from_low_level_interface_call = format!(
"ERROR: {test_name}: Provides the null version of lower blockchain interface only"
);
let expected_log_msg_from_rcp_call =
format!("ERROR: {test_name}: Null version can't fetch transaction id");
TestLogHandler::new().assert_logs_contain_in_order(vec![
expected_log_msg_from_helpers_call.as_str(),
expected_log_msg_from_low_level_interface_call.as_str(),
expected_log_msg_from_rcp_call.as_str(),
]);
}
Expand Down
Loading

0 comments on commit 89434e8

Please sign in to comment.