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-744-Review-4 #565

Open
wants to merge 10 commits into
base: GH-744-Review-4-Base
Choose a base branch
from
2 changes: 1 addition & 1 deletion masq_lib/src/test_utils/mock_blockchain_client_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl MBCSBuilder {
self.store_response_string(raw_string)
}

pub fn response<R>(self, result: R, id: u64) -> Self
pub fn ok_response<R>(self, result: R, id: u64) -> Self
where
R: Serialize,
{
Expand Down
18 changes: 9 additions & 9 deletions multinode_integration_tests/src/mock_blockchain_client_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod tests {
let _cluster = MASQNodeCluster::start();
let port = find_free_port();
let _subject = MockBlockchainClientServer::builder(port)
.response("Thank you and good night", 40)
.ok_response("Thank you and good night", 40)
.run_in_docker()
.start();
let mut client = connect(port);
Expand Down Expand Up @@ -60,8 +60,8 @@ mod tests {
let _cluster = MASQNodeCluster::start();
let port = find_free_port();
let _subject = MockBlockchainClientServer::builder(port)
.response("Welcome, and thanks for coming!", 39)
.response("Thank you and good night", 40)
.ok_response("Welcome, and thanks for coming!", 39)
.ok_response("Thank you and good night", 40)
.run_in_docker()
.start();
let mut client = connect(port);
Expand All @@ -85,7 +85,7 @@ mod tests {
let _cluster = MASQNodeCluster::start();
let port = find_free_port();
let _subject = MockBlockchainClientServer::builder(port)
.response("irrelevant".to_string(), 42)
.ok_response("irrelevant".to_string(), 42)
.run_in_docker()
.start();
let mut client = connect(port);
Expand All @@ -102,7 +102,7 @@ mod tests {
let _cluster = MASQNodeCluster::start();
let port = find_free_port();
let _subject = MockBlockchainClientServer::builder(port)
.response("irrelevant".to_string(), 42)
.ok_response("irrelevant".to_string(), 42)
.run_in_docker()
.start();
let mut client = connect(port);
Expand All @@ -119,7 +119,7 @@ mod tests {
let _cluster = MASQNodeCluster::start();
let port = find_free_port();
let _subject = MockBlockchainClientServer::builder(port)
.response("irrelevant".to_string(), 42)
.ok_response("irrelevant".to_string(), 42)
.run_in_docker()
.start();
let mut client = connect(port);
Expand All @@ -138,10 +138,10 @@ mod tests {
let subject = MockBlockchainClientServer::builder(port)
.notifier(notifier)
.begin_batch()
.response(1234u64, 40)
.ok_response(1234u64, 40)
.error(1234, "My tummy hurts", None as Option<()>)
.end_batch()
.response(
.ok_response(
Person {
name: "Billy".to_string(),
age: 15,
Expand Down Expand Up @@ -211,7 +211,7 @@ mod tests {
let _cluster = MASQNodeCluster::start();
let port = find_free_port();
let subject = MockBlockchainClientServer::builder(port)
.response(
.ok_response(
Person {
name: "Billy".to_string(),
age: 15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ fn debtors_are_credited_once_but_not_twice() {
// Create and initialize mock blockchain client: prepare a receivable at block 2000
eprintln!("Setting up mock blockchain client");
let blockchain_client_server = MBCSBuilder::new(mbcs_port)
.response("0x5DC", 1) // eth_blockNumber 1500
.response(
.ok_response("0x5DC", 1) // eth_blockNumber 1500
.ok_response(
vec![LogObject {
removed: false,
log_index: Some("0x20".to_string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ fn dns_resolution_failure_with_real_nodes() {
);
}

// >>> TODO: GH-744: - Fix this test.
#[test]
#[ignore]
fn dns_resolution_failure_for_wildcard_ip_with_real_nodes() {
let dns_server_that_fails = Ipv4Addr::new(1, 1, 1, 3).into();
let mut cluster = MASQNodeCluster::start().unwrap();
Expand All @@ -296,7 +294,7 @@ fn dns_resolution_failure_for_wildcard_ip_with_real_nodes() {

thread::sleep(Duration::from_millis(1000));
let mut client = originating_node.make_client(8080, STANDARD_CLIENT_TIMEOUT_MILLIS);
client.send_chunk(b"GET / HTTP/1.1\r\nHost: www.xvideos.com\r\n\r\n");
client.send_chunk(b"GET / HTTP/1.1\r\nHost: www.adomainthatdoesntexsit.com\r\n\r\n");
let response = client.wait_for_chunk();

assert_eq!(
Expand All @@ -306,7 +304,7 @@ fn dns_resolution_failure_for_wildcard_ip_with_real_nodes() {
String::from_utf8(response.clone()).unwrap()
);
assert_eq!(
index_of(&response, &b"<p>DNS Failure, We have tried multiple Exit Nodes and all have failed to resolve this address www.xvideos.com</p>"[..]).is_some(),
index_of(&response, &b"<p>DNS Failure, We have tried multiple Exit Nodes and all have failed to resolve this address www.adomainthatdoesntexsit.com</p>"[..]).is_some(),
true,
"Actual response:\n{}",
String::from_utf8(response).unwrap()
Expand Down
18 changes: 12 additions & 6 deletions node/src/accountant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3446,16 +3446,16 @@ mod tests {
.unwrap();
let _blockchain_client_server = MBCSBuilder::new(port)
// Blockchain Agent Gas Price
.response("0x3B9ACA00".to_string(), 0) // 1000000000
.ok_response("0x3B9ACA00".to_string(), 0) // 1000000000
// Blockchain Agent transaction fee balance
.response("0xFFF0".to_string(), 0) // 65520
.ok_response("0xFFF0".to_string(), 0) // 65520
// Blockchain Agent masq balance
.response(
.ok_response(
"0x000000000000000000000000000000000000000000000000000000000000FFFF".to_string(),
0,
)
// Submit payments to blockchain
.response("0xFFF0".to_string(), 1)
.ok_response("0xFFF0".to_string(), 1)
.begin_batch()
.raw_response(
ReceiptResponseBuilder::default()
Expand Down Expand Up @@ -3510,6 +3510,8 @@ mod tests {
ReceiptResponseBuilder::default()
.transaction_hash(pending_tx_hash_2)
.status(U64::from(1))
.block_number(U64::from(1234))
.block_hash(Default::default())
.build(),
)
.end_batch()
Expand Down Expand Up @@ -3800,6 +3802,8 @@ mod tests {
let mut transaction_receipt_1 = TransactionReceipt::default();
transaction_receipt_1.transaction_hash = transaction_hash_1;
transaction_receipt_1.status = Some(U64::from(1)); //success
transaction_receipt_1.block_number = Some(U64::from(100));
transaction_receipt_1.block_hash = Some(Default::default());
utkarshg6 marked this conversation as resolved.
Show resolved Hide resolved
let fingerprint_1 = PendingPayableFingerprint {
rowid: 5,
timestamp: from_time_t(200_000_000),
Expand All @@ -3812,6 +3816,8 @@ mod tests {
let mut transaction_receipt_2 = TransactionReceipt::default();
transaction_receipt_2.transaction_hash = transaction_hash_2;
transaction_receipt_2.status = Some(U64::from(1)); //success
transaction_receipt_2.block_number = Some(U64::from(200));
transaction_receipt_2.block_hash = Some(Default::default());
utkarshg6 marked this conversation as resolved.
Show resolved Hide resolved
let fingerprint_2 = PendingPayableFingerprint {
rowid: 10,
timestamp: from_time_t(199_780_000),
Expand All @@ -3823,11 +3829,11 @@ mod tests {
let msg = ReportTransactionReceipts {
fingerprints_with_receipts: vec![
(
TransactionReceiptResult::Found(transaction_receipt_1.into()),
TransactionReceiptResult::RpcResponse(transaction_receipt_1.into()),
fingerprint_1.clone(),
),
(
TransactionReceiptResult::Found(transaction_receipt_2.into()),
TransactionReceiptResult::RpcResponse(transaction_receipt_2.into()),
fingerprint_2.clone(),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ mod tests {
use masq_lib::logger::Logger;
use masq_lib::test_utils::logging::{init_test_logging, TestLogHandler};
use web3::types::U256;
use masq_lib::test_utils::utils::TEST_DEFAULT_CHAIN;

fn blockchain_agent_null_constructor_works<C>(constructor: C)
where
Expand Down Expand Up @@ -178,4 +179,18 @@ mod tests {
assert_eq!(result, &Wallet::null());
assert_error_log(test_name, "consuming_wallet")
}

#[test]
fn null_agent_get_chain() {
init_test_logging();
let test_name = "null_agent_get_chain";
let mut subject = BlockchainAgentNull::new();
subject.logger = Logger::new(test_name);

let result = subject.get_chain();

assert_eq!(result, TEST_DEFAULT_CHAIN);
assert_error_log(test_name, "get_chain")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ mod tests {
subject.consuming_wallet_balances(),
consuming_wallet_balances
);
assert_eq!(subject.get_chain(), TEST_DEFAULT_CHAIN);
}

#[test]
Expand Down
45 changes: 29 additions & 16 deletions node/src/accountant/scanners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use web3::types::H256;
use masq_lib::type_obfuscation::Obfuscated;
use crate::accountant::scanners::mid_scan_msg_handling::payable_scanner::{PreparedAdjustment, MultistagePayableScanner, SolvencySensitivePaymentInstructor};
use crate::accountant::scanners::mid_scan_msg_handling::payable_scanner::msgs::{BlockchainAgentWithContextMessage, QualifiedPayablesMessage};
use crate::blockchain::blockchain_interface::blockchain_interface_web3::lower_level_interface_web3::TransactionReceiptResult;
use crate::blockchain::blockchain_interface::blockchain_interface_web3::lower_level_interface_web3::{TransactionReceiptResult, TxStatus};
use crate::blockchain::blockchain_interface::data_structures::errors::PayableTransactionError;
use crate::db_config::persistent_configuration::{PersistentConfiguration, PersistentConfigurationReal};

Expand Down Expand Up @@ -675,18 +675,24 @@ impl PendingPayableScanner {
msg.fingerprints_with_receipts.into_iter().fold(
scan_report,
|scan_report_so_far, (receipt_result, fingerprint)| match receipt_result {
TransactionReceiptResult::Found(_receipt) => {
handle_status_with_success(scan_report_so_far, fingerprint, logger)
TransactionReceiptResult::RpcResponse(tx_receipt) => {
match tx_receipt.status {
TxStatus::Pending => {
handle_none_receipt(
utkarshg6 marked this conversation as resolved.
Show resolved Hide resolved
scan_report_so_far,
fingerprint,
"none was given".to_string(),
logger,
)
}
TxStatus::Failed => {
handle_status_with_failure(scan_report_so_far, fingerprint, logger)
}
TxStatus::Succeeded(_) => {
handle_status_with_success(scan_report_so_far, fingerprint, logger)
}
}
}
TransactionReceiptResult::TransactionFailed(_receipt) => {
handle_status_with_failure(scan_report_so_far, fingerprint, logger)
}
TransactionReceiptResult::NotPresent => handle_none_receipt(
scan_report_so_far,
fingerprint,
"none was given".to_string(),
logger,
),
TransactionReceiptResult::LocalError(e) => handle_none_receipt(
scan_report_so_far,
fingerprint,
Expand Down Expand Up @@ -1133,7 +1139,7 @@ mod tests {
use std::time::{Duration, SystemTime};
use web3::types::{TransactionReceipt, H256};
use web3::Error;
use crate::blockchain::blockchain_interface::blockchain_interface_web3::lower_level_interface_web3::TransactionReceiptResult;
use crate::blockchain::blockchain_interface::blockchain_interface_web3::lower_level_interface_web3::{TransactionReceiptResult, TxReceipt, TxStatus};

#[test]
fn scanners_struct_can_be_constructed_with_the_respective_scanners() {
Expand Down Expand Up @@ -2498,7 +2504,10 @@ mod tests {
};
let msg = ReportTransactionReceipts {
fingerprints_with_receipts: vec![(
TransactionReceiptResult::NotPresent,
TransactionReceiptResult::RpcResponse(TxReceipt{
transaction_hash: hash,
status: TxStatus::Pending
}),
fingerprint.clone(),
)],
response_skeleton_opt: None,
Expand Down Expand Up @@ -2821,6 +2830,8 @@ mod tests {
let mut transaction_receipt_1 = TransactionReceipt::default();
transaction_receipt_1.transaction_hash = transaction_hash_1;
transaction_receipt_1.status = Some(U64::from(1)); //success
transaction_receipt_1.block_number = Some(U64::from(1234));
transaction_receipt_1.block_hash = Some(Default::default());
let fingerprint_1 = PendingPayableFingerprint {
rowid: 5,
timestamp: from_time_t(200_000_000),
Expand All @@ -2833,6 +2844,8 @@ mod tests {
let mut transaction_receipt_2 = TransactionReceipt::default();
transaction_receipt_2.transaction_hash = transaction_hash_2;
transaction_receipt_2.status = Some(U64::from(1)); //success
transaction_receipt_2.block_number = Some(U64::from(2345));
transaction_receipt_2.block_hash = Some(Default::default());
let fingerprint_2 = PendingPayableFingerprint {
rowid: 10,
timestamp: from_time_t(199_780_000),
Expand All @@ -2844,11 +2857,11 @@ mod tests {
let msg = ReportTransactionReceipts {
fingerprints_with_receipts: vec![
(
TransactionReceiptResult::Found(transaction_receipt_1.into()),
TransactionReceiptResult::RpcResponse(transaction_receipt_1.into()),
fingerprint_1.clone(),
),
(
TransactionReceiptResult::Found(transaction_receipt_2.into()),
TransactionReceiptResult::RpcResponse(transaction_receipt_2.into()),
fingerprint_2.clone(),
),
],
Expand Down
Loading