Skip to content

Commit

Permalink
GH-672: merged master in
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert authored and Bert committed Oct 10, 2023
2 parents d7f91bb + 44193ef commit 0d4d6a3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 40 deletions.
27 changes: 14 additions & 13 deletions node/src/blockchain/blockchain_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ mod tests {
.retrieve_transactions_result(Err(BlockchainError::QueryFailed(
"we have no luck".to_string(),
)))
.helpers_results(Box::new(lower_interface));
.lower_interface_results(Box::new(lower_interface));
let persistent_config = PersistentConfigurationMock::new()
.max_block_count_result(Ok(Some(100_000)))
.start_block_result(Ok(5)); // no set_start_block_result: set_start_block() must not be called
Expand Down Expand Up @@ -1418,13 +1418,14 @@ mod tests {
},
],
};
let rpc_helpers = LowerBCIMock::default().get_block_number_result(LatestBlockNumber::Err(
BlockchainError::QueryFailed("Failed to read the latest block number".to_string()),
));
let lower_interface =
LowerBCIMock::default().get_block_number_result(LatestBlockNumber::Err(
BlockchainError::QueryFailed("Failed to read the latest block number".to_string()),
));
let blockchain_interface_mock = BlockchainInterfaceMock::default()
.retrieve_transactions_params(&retrieve_transactions_params_arc)
.retrieve_transactions_result(Ok(expected_transactions.clone()))
.helpers_results(Box::new(rpc_helpers));
.lower_interface_results(Box::new(lower_interface));
let set_start_block_params_arc = Arc::new(Mutex::new(vec![]));
let persistent_config = PersistentConfigurationMock::new()
.max_block_count_result(Ok(Some(10000u64)))
Expand Down Expand Up @@ -1511,11 +1512,11 @@ mod tests {
],
};
let latest_block_number = LatestBlockNumber::Ok(1024u64.into());
let rpc_helpers = LowerBCIMock::default().get_block_number_result(latest_block_number);
let lower_interface = LowerBCIMock::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()))
.helpers_results(Box::new(rpc_helpers));
.lower_interface_results(Box::new(lower_interface));
let set_start_block_params_arc = Arc::new(Mutex::new(vec![]));
let persistent_config = PersistentConfigurationMock::new()
.max_block_count_result(Ok(Some(10000u64)))
Expand Down Expand Up @@ -1577,13 +1578,13 @@ mod tests {
#[test]
fn processing_of_received_payments_continues_even_if_no_payments_are_detected() {
init_test_logging();
let rpc_helpers = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let lower_interface = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let blockchain_interface_mock = BlockchainInterfaceMock::default()
.retrieve_transactions_result(Ok(RetrievedBlockchainTransactions {
new_start_block: 7,
transactions: vec![],
}))
.helpers_results(Box::new(rpc_helpers));
.lower_interface_results(Box::new(lower_interface));
let set_start_block_params_arc = Arc::new(Mutex::new(vec![]));
let persistent_config = PersistentConfigurationMock::new()
.max_block_count_result(Ok(Some(10000u64)))
Expand Down Expand Up @@ -1643,9 +1644,9 @@ 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 rpc_helpers = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let lower_interface = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let blockchain_interface =
BlockchainInterfaceMock::default().helpers_results(Box::new(rpc_helpers));
BlockchainInterfaceMock::default().lower_interface_results(Box::new(lower_interface));
let persistent_config = PersistentConfigurationMock::new()
.start_block_result(Err(PersistentConfigError::TransactionError));
let mut subject = BlockchainBridge::new(
Expand All @@ -1671,7 +1672,7 @@ mod tests {
.start_block_result(Ok(1234))
.set_start_block_result(Err(PersistentConfigError::TransactionError))
.max_block_count_result(Ok(Some(10000u64)));
let rpc_helpers = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let lower_interface = LowerBCIMock::default().get_block_number_result(Ok(0u64.into()));
let blockchain_interface = BlockchainInterfaceMock::default()
.retrieve_transactions_result(Ok(RetrievedBlockchainTransactions {
new_start_block: 1234,
Expand All @@ -1681,7 +1682,7 @@ mod tests {
wei_amount: 2345,
}],
}))
.helpers_results(Box::new(rpc_helpers));
.lower_interface_results(Box::new(lower_interface));
let mut subject = BlockchainBridge::new(
Box::new(blockchain_interface),
Box::new(persistent_config),
Expand Down
2 changes: 1 addition & 1 deletion node/src/blockchain/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl BlockchainInterfaceMock {
self
}

pub fn helpers_results(mut self, aggregated_results: Box<LowerBCIMock>) -> Self {
pub fn lower_interface_results(mut self, aggregated_results: Box<LowerBCIMock>) -> Self {
self.helpers_result = Some(aggregated_results);
self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl DatabaseMigration for Migrate_8_to_9 {
declaration_utils: Box<dyn DBMigDeclarator + 'a>,
) -> rusqlite::Result<()> {
declaration_utils.execute_upon_transaction(&[
&"INSERT INTO config (name, value, encrypted) VALUES ('max_block_count', '', 0)",
&"INSERT INTO config (name, value, encrypted) VALUES ('max_block_count', null, 0)",
])
}

Expand Down Expand Up @@ -51,7 +51,7 @@ mod tests {
let connection = result.unwrap();
let (mp_value, mp_encrypted) = retrieve_config_row(connection.as_ref(), "max_block_count");
let (cs_value, cs_encrypted) = retrieve_config_row(connection.as_ref(), "schema_version");
assert_eq!(mp_value, Some("".to_string()));
assert_eq!(mp_value, None);
assert_eq!(mp_encrypted, false);
assert_eq!(cs_value, Some("9".to_string()));
assert_eq!(cs_encrypted, false);
Expand Down
22 changes: 3 additions & 19 deletions node/src/db_config/persistent_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,24 +410,11 @@ impl PersistentConfiguration for PersistentConfigurationReal {
}

fn max_block_count(&self) -> Result<Option<u64>, PersistentConfigError> {
match self.get("max_block_count") {
Ok(max_block_count) => match decode_u64(max_block_count) {
Ok(mbc_opt) => Ok(mbc_opt),
Err(TypedConfigLayerError::BadNumberFormat(value)) if value.is_empty() => Ok(None),
Err(e) => Err(PersistentConfigError::from(e)),
},
Err(e) => Err(PersistentConfigError::from(e)),
}
Ok(decode_u64(self.get("max_block_count")?)?)
}

fn set_max_block_count(&mut self, value: Option<u64>) -> Result<(), PersistentConfigError> {
self.simple_set_method(
"max_block_count",
match encode_u64(value) {
Ok(Some(mbc)) => mbc,
_ => "".to_string(),
},
)
Ok(self.dao.set("max_block_count", encode_u64(value)?)?)
}

fn set_wallet_info(
Expand Down Expand Up @@ -1982,10 +1969,7 @@ mod tests {

assert!(result.is_ok());
let set_params = set_params_arc.lock().unwrap();
assert_eq!(
*set_params,
vec![("max_block_count".to_string(), Some("".to_string()))]
);
assert_eq!(*set_params, vec![("max_block_count".to_string(), None)]);
}

#[test]
Expand Down
9 changes: 4 additions & 5 deletions node/src/node_configurator/configurator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,7 @@ mod tests {
.consuming_wallet_private_key_params(&consuming_wallet_private_key_params_arc)
.consuming_wallet_private_key_result(Ok(Some(consuming_wallet_private_key.clone())))
.mapping_protocol_result(Ok(Some(AutomapProtocol::Igdp)))
.max_block_count_result(Ok(Some(100000)))
.max_block_count_result(Ok(None))
.neighborhood_mode_result(Ok(NeighborhoodModeLight::ConsumeOnly))
.past_neighbors_params(&past_neighbors_params_arc)
.past_neighbors_result(Ok(Some(vec![node_descriptor.clone()])))
Expand Down Expand Up @@ -2579,7 +2579,7 @@ mod tests {
clandestine_port: 1234,
chain_name: "ropsten".to_string(),
gas_price: 2345,
max_block_count_opt: Some(100000),
max_block_count_opt: None,
neighborhood_mode: String::from("consume-only"),
consuming_wallet_private_key_opt: Some(consuming_wallet_private_key),
consuming_wallet_address_opt: Some(consuming_wallet_address),
Expand Down Expand Up @@ -2619,9 +2619,8 @@ mod tests {
}

#[test]
fn configuration_handles_retrieving_max_block_count_none() {
fn configuration_handles_retrieving_all_possible_none_values() {
let persistent_config = PersistentConfigurationMock::new()
.check_password_result(Ok(true))
.blockchain_service_url_result(Ok(None))
.current_schema_version_result("3")
.clandestine_port_result(Ok(1234))
Expand Down Expand Up @@ -2658,7 +2657,7 @@ mod tests {
let (configuration, context_id) =
UiConfigurationResponse::fmb(subject.handle_configuration(
UiConfigurationRequest {
db_password_opt: Some("password".to_string()),
db_password_opt: None,
},
4321,
))
Expand Down

0 comments on commit 0d4d6a3

Please sign in to comment.