Skip to content

Commit

Permalink
GH-719: Replace BlockchainInterfaceClandestine with BlockchainInterfa…
Browse files Browse the repository at this point in the history
…ceNull (#307)

* GH-719: Blockchain interfaces slightly modified, mainly naming. The clandestine was replaced with BlockchainInterfaceNull

* GH-719: review issues fixed

* GH-719: review two answered

* GH-719: review 3 answered

* GH-719: additional changes for review 3

* GH-719: web3 ABI reformated

---------

Co-authored-by: Bert <[email protected]>
  • Loading branch information
bertllll and Bert authored Jun 30, 2023
1 parent 1dc60bf commit 7bf8c05
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 327 deletions.
8 changes: 4 additions & 4 deletions multinode_integration_tests/tests/verify_bill_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use node_lib::accountant::database_access_objects::receivable_dao::{
};
use node_lib::blockchain::bip32::Bip32ECKeyProvider;
use node_lib::blockchain::blockchain_interface::{
BlockchainInterface, BlockchainInterfaceNonClandestine, REQUESTS_IN_PARALLEL,
BlockchainInterface, BlockchainInterfaceWeb3, REQUESTS_IN_PARALLEL,
};
use node_lib::database::db_initializer::{
DbInitializationConfig, DbInitializer, DbInitializerReal, ExternalData,
Expand Down Expand Up @@ -61,7 +61,7 @@ fn verify_bill_payment() {
contract_addr
);
let blockchain_interface =
BlockchainInterfaceNonClandestine::new(http, _event_loop_handle, cluster.chain);
BlockchainInterfaceWeb3::new(http, _event_loop_handle, cluster.chain);
assert_balances(
&contract_owner_wallet,
&blockchain_interface,
Expand Down Expand Up @@ -321,12 +321,12 @@ fn make_init_config(chain: Chain) -> DbInitializationConfig {

fn assert_balances(
wallet: &Wallet,
blockchain_interface: &BlockchainInterfaceNonClandestine<Http>,
blockchain_interface: &BlockchainInterfaceWeb3<Http>,
expected_eth_balance: &str,
expected_token_balance: &str,
) {
let eth_balance = blockchain_interface
.get_gas_balance(&wallet)
.get_transaction_fee_balance(&wallet)
.unwrap_or_else(|_| panic!("Failed to retrieve gas balance for {}", wallet));
assert_eq!(
format!("{}", eth_balance),
Expand Down
28 changes: 11 additions & 17 deletions node/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ toml = "0.5.8"
trust-dns = "0.17.0"
trust-dns-resolver = "0.12.0"
unindent = "0.1.7"
variant_count = "1.1.0"
web3 = {version = "0.11.0", default-features = false, features = ["http", "tls"]}
websocket = {version = "0.26.2", default-features = false, features = ["async", "sync"]}
secp256k1secrets = {package = "secp256k1", version = "0.17.2"}
Expand All @@ -69,7 +70,6 @@ system-configuration = "0.4.0"
core-foundation = "0.7.0"

[target.'cfg(not(target_os = "windows"))'.dependencies]
daemonize = "0.4.1"
nix = "0.23.0"
openssl = {version = "0.10.38", features = ["vendored"]}

Expand Down
66 changes: 44 additions & 22 deletions node/src/accountant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2999,7 +2999,7 @@ mod tests {
let mut transaction_receipt_tx_2_fourth_round = TransactionReceipt::default();
transaction_receipt_tx_2_fourth_round.status = Some(U64::from(1)); // confirmed
let blockchain_interface = BlockchainInterfaceMock::default()
.get_gas_balance_result(Ok(U256::from(u128::MAX)))
.get_transaction_fee_balance_result(Ok(U256::from(u128::MAX)))
.get_token_balance_result(Ok(U256::from(u128::MAX)))
.get_transaction_count_result(Ok(web3::types::U256::from(1)))
.get_transaction_count_result(Ok(web3::types::U256::from(2)))
Expand Down Expand Up @@ -3381,59 +3381,81 @@ mod tests {
confirmation for all these transactions: 0x00000000000000000000000000000000000000000000000000000000000001c8");
}

const EXAMPLE_RESPONSE_SKELETON: ResponseSkeleton = ResponseSkeleton {
client_id: 1234,
context_id: 4321,
};

const EXAMPLE_ERROR_MSG: &str = "My tummy hurts";

#[test]
fn handles_scan_error() {
let response_skeleton = ResponseSkeleton {
client_id: 1234,
context_id: 4321,
};
let msg = "My tummy hurts";
fn handling_scan_error_for_externally_triggered_payables() {
assert_scan_error_is_handled_properly(
"payables_externally_triggered",
"handling_scan_error_for_externally_triggered_payables",
ScanError {
scan_type: ScanType::Payables,
response_skeleton_opt: Some(response_skeleton),
msg: msg.to_string(),
response_skeleton_opt: Some(EXAMPLE_RESPONSE_SKELETON),
msg: EXAMPLE_ERROR_MSG.to_string(),
},
);
}

#[test]
fn handling_scan_error_for_externally_triggered_pending_payables() {
assert_scan_error_is_handled_properly(
"pending_payables_externally_triggered",
"handling_scan_error_for_externally_triggered_pending_payables",
ScanError {
scan_type: ScanType::PendingPayables,
response_skeleton_opt: Some(response_skeleton),
msg: msg.to_string(),
response_skeleton_opt: Some(EXAMPLE_RESPONSE_SKELETON),
msg: EXAMPLE_ERROR_MSG.to_string(),
},
);
}

#[test]
fn handling_scan_error_for_externally_triggered_receivables() {
assert_scan_error_is_handled_properly(
"receivables_externally_triggered",
"handling_scan_error_for_externally_triggered_receivables",
ScanError {
scan_type: ScanType::Receivables,
response_skeleton_opt: Some(response_skeleton),
msg: msg.to_string(),
response_skeleton_opt: Some(EXAMPLE_RESPONSE_SKELETON),
msg: EXAMPLE_ERROR_MSG.to_string(),
},
);
}

#[test]
fn handling_scan_error_for_internally_triggered_payables() {
assert_scan_error_is_handled_properly(
"payables_internally_triggered",
"handling_scan_error_for_internally_triggered_payables",
ScanError {
scan_type: ScanType::Payables,
response_skeleton_opt: None,
msg: msg.to_string(),
msg: EXAMPLE_ERROR_MSG.to_string(),
},
);
}

#[test]
fn handling_scan_error_for_internally_triggered_pending_payables() {
assert_scan_error_is_handled_properly(
"pending_payables_internally_triggered",
"handling_scan_error_for_internally_triggered_pending_payables",
ScanError {
scan_type: ScanType::PendingPayables,
response_skeleton_opt: None,
msg: msg.to_string(),
msg: EXAMPLE_ERROR_MSG.to_string(),
},
);
}

#[test]
fn handling_scan_error_for_internally_triggered_receivables() {
assert_scan_error_is_handled_properly(
"receivables_internally_triggered",
"handling_scan_error_for_internally_triggered_receivables",
ScanError {
scan_type: ScanType::Receivables,
response_skeleton_opt: None,
msg: msg.to_string(),
msg: EXAMPLE_ERROR_MSG.to_string(),
},
);
}
Expand Down
57 changes: 33 additions & 24 deletions node/src/blockchain/blockchain_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::accountant::{
};
use crate::accountant::{ReportTransactionReceipts, RequestTransactionReceipts};
use crate::blockchain::blockchain_interface::{
BlockchainError, BlockchainInterface, BlockchainInterfaceClandestine,
BlockchainInterfaceNonClandestine, PayableTransactionError, ProcessedPayableFallible,
BlockchainError, BlockchainInterface, BlockchainInterfaceNull, BlockchainInterfaceWeb3,
PayableTransactionError, ProcessedPayableFallible,
};
use crate::database::db_initializer::{DbInitializationConfig, DbInitializer, DbInitializerReal};
use crate::db_config::config_dao::ConfigDaoReal;
Expand Down Expand Up @@ -221,17 +221,18 @@ impl BlockchainBridge {
Box<dyn BlockchainInterface>,
Box<dyn PersistentConfiguration>,
) {
let blockchain_interface: Box<dyn BlockchainInterface> = {
match blockchain_service_url {
Some(url) => match Http::new(&url) {
Ok((event_loop_handle, transport)) => Box::new(
BlockchainInterfaceNonClandestine::new(transport, event_loop_handle, chain),
),
Err(e) => panic!("Invalid blockchain node URL: {:?}", e),
},
None => Box::new(BlockchainInterfaceClandestine::new(chain)),
}
};
let blockchain_interface: Box<dyn BlockchainInterface> =
{
match blockchain_service_url {
Some(url) => match Http::new(&url) {
Ok((event_loop_handle, transport)) => Box::new(
BlockchainInterfaceWeb3::new(transport, event_loop_handle, chain),
),
Err(e) => panic!("Invalid blockchain node URL: {:?}", e),
},
None => Box::new(BlockchainInterfaceNull::default()),
}
};
let config_dao = Box::new(ConfigDaoReal::new(
DbInitializerReal::default()
.initialize(
Expand Down Expand Up @@ -272,7 +273,10 @@ impl BlockchainBridge {
}
};
//TODO rewrite this into a batch call as soon as GH-629 gets into master
let gas_balance = match self.blockchain_interface.get_gas_balance(consuming_wallet) {
let gas_balance = match self
.blockchain_interface
.get_transaction_fee_balance(consuming_wallet)
{
Ok(gas_balance) => gas_balance,
Err(e) => {
return Err(format!(
Expand Down Expand Up @@ -652,7 +656,7 @@ mod tests {
let system = System::new(
"handle_request_balances_to_pay_payables_reports_balances_and_payables_back_to_accountant",
);
let get_gas_balance_params_arc = Arc::new(Mutex::new(vec![]));
let get_transaction_fee_balance_params_arc = Arc::new(Mutex::new(vec![]));
let get_token_balance_params_arc = Arc::new(Mutex::new(vec![]));
let (accountant, _, accountant_recording_arc) = make_recorder();
let gas_balance = U256::from(4455);
Expand All @@ -662,8 +666,8 @@ mod tests {
masq_tokens: token_balance,
};
let blockchain_interface = BlockchainInterfaceMock::default()
.get_gas_balance_params(&get_gas_balance_params_arc)
.get_gas_balance_result(Ok(gas_balance))
.get_transaction_fee_balance_params(&get_transaction_fee_balance_params_arc)
.get_transaction_fee_balance_result(Ok(gas_balance))
.get_token_balance_params(&get_token_balance_params_arc)
.get_token_balance_result(Ok(token_balance));
let consuming_wallet = make_paying_wallet(b"somewallet");
Expand Down Expand Up @@ -698,8 +702,12 @@ mod tests {

System::current().stop();
system.run();
let get_gas_balance_params = get_gas_balance_params_arc.lock().unwrap();
assert_eq!(*get_gas_balance_params, vec![consuming_wallet.clone()]);
let get_transaction_fee_balance_params =
get_transaction_fee_balance_params_arc.lock().unwrap();
assert_eq!(
*get_transaction_fee_balance_params,
vec![consuming_wallet.clone()]
);
let get_token_balance_params = get_token_balance_params_arc.lock().unwrap();
assert_eq!(*get_token_balance_params, vec![consuming_wallet]);
let accountant_received_payment = accountant_recording_arc.lock().unwrap();
Expand Down Expand Up @@ -781,9 +789,10 @@ mod tests {
fn handle_request_balances_to_pay_payables_fails_on_inspection_of_gas_balance() {
let test_name =
"handle_request_balances_to_pay_payables_fails_on_inspection_of_gas_balance";
let blockchain_interface = BlockchainInterfaceMock::default().get_gas_balance_result(Err(
BlockchainError::QueryFailed("Lazy and yet you're asking for balances?".to_string()),
));
let blockchain_interface = BlockchainInterfaceMock::default()
.get_transaction_fee_balance_result(Err(BlockchainError::QueryFailed(
"Lazy and yet you're asking for balances?".to_string(),
)));
let error_msg = "Did not find out gas balance of the consuming wallet: \
QueryFailed(\"Lazy and yet you're asking for balances?\")";

Expand All @@ -795,7 +804,7 @@ mod tests {
let test_name =
"handle_request_balances_to_pay_payables_fails_on_inspection_of_token_balance";
let blockchain_interface = BlockchainInterfaceMock::default()
.get_gas_balance_result(Ok(U256::from(45678)))
.get_transaction_fee_balance_result(Ok(U256::from(45678)))
.get_token_balance_result(Err(BlockchainError::QueryFailed(
"Go get you a job. This balance must be deserved".to_string(),
)));
Expand Down Expand Up @@ -1397,7 +1406,7 @@ mod tests {
let (accountant, _, accountant_recording) = make_recorder();
let recipient = accountant.start().recipient();
let mut subject = BlockchainBridge::new(
Box::new(BlockchainInterfaceClandestine::new(Chain::Dev)),
Box::new(BlockchainInterfaceNull::default()),
Box::new(PersistentConfigurationMock::default()),
false,
Some(Wallet::new("mine")),
Expand Down
Loading

0 comments on commit 7bf8c05

Please sign in to comment.