Skip to content

Commit

Permalink
GH-606: Apply PR feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
masqrauder committed Mar 31, 2024
1 parent 26fe492 commit b0f9e02
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 86 deletions.
7 changes: 4 additions & 3 deletions masq/src/commands/set_configuration_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl SetConfigurationCommand {
}

fn validate_start_block(start_block: String) -> Result<(), String> {
if "none".eq_ignore_ascii_case(&start_block) {
if "latest".eq_ignore_ascii_case(&start_block) || "none".eq_ignore_ascii_case(&start_block) {
Ok(())
} else {
match start_block.parse::<u64>() {
Expand Down Expand Up @@ -63,7 +63,7 @@ impl Command for SetConfigurationCommand {
const SET_CONFIGURATION_ABOUT: &str =
"Sets Node configuration parameters being enabled for this operation when the Node is running.";
const START_BLOCK_HELP: &str =
"Ordinal number of the Ethereum block where scanning for transactions will start. Use 'none' for Latest block.";
"Ordinal number of the Ethereum block where scanning for transactions will start. Use 'latest' or 'none' for Latest block.";

pub fn set_configurationify<'a>(shared_schema_arg: Arg<'a, 'a>) -> Arg<'a, 'a> {
shared_schema_arg.takes_value(true).min_values(1)
Expand Down Expand Up @@ -107,7 +107,7 @@ mod tests {
);
assert_eq!(
START_BLOCK_HELP,
"Ordinal number of the Ethereum block where scanning for transactions will start. Use 'none' for Latest block."
"Ordinal number of the Ethereum block where scanning for transactions will start. Use 'latest' or 'none' for Latest block."
);
}

Expand All @@ -130,6 +130,7 @@ mod tests {
fn validate_start_block_works() {
assert!(validate_start_block("abc".to_string()).is_err());
assert!(validate_start_block("1566".to_string()).is_ok());
assert!(validate_start_block("latest".to_string()).is_ok());
assert!(validate_start_block("none".to_string()).is_ok());
}

Expand Down
2 changes: 1 addition & 1 deletion masq_lib/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::data_version::DataVersion;
use const_format::concatcp;

pub const DEFAULT_CHAIN: Chain = Chain::PolyMainnet;
pub const CURRENT_SCHEMA_VERSION: usize = 10;
pub const CURRENT_SCHEMA_VERSION: usize = 9;

pub const HIGHEST_RANDOM_CLANDESTINE_PORT: u16 = 9999;
pub const HTTP_PORT: u16 = 80;
Expand Down
6 changes: 3 additions & 3 deletions node/src/accountant/scanners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ impl Scanner<RetrieveTransactions, ReceivedPayments> for ReceivableScanner {

match self
.persistent_configuration
.set_start_block(msg.new_start_block)
.set_start_block(Some(msg.new_start_block))
{
Ok(()) => debug!(logger, "Start block updated to {}", msg.new_start_block),
Err(e) => panic!(
Expand Down Expand Up @@ -1245,7 +1245,7 @@ mod tests {
assert_eq!(receivable_scanner.common.initiated_at_opt.is_some(), false);
receivable_scanner
.persistent_configuration
.set_start_block(136890)
.set_start_block(Some(136890))
.unwrap();
let set_params = set_params_arc.lock().unwrap();
assert_eq!(
Expand Down Expand Up @@ -3061,7 +3061,7 @@ mod tests {

assert_eq!(message_opt, None);
let set_start_block_params = set_start_block_params_arc.lock().unwrap();
assert_eq!(*set_start_block_params, vec![4321]);
assert_eq!(*set_start_block_params, vec![Some(4321)]);
TestLogHandler::new().exists_log_containing(&format!(
"INFO: {test_name}: No newly received payments were detected during the scanning process."
));
Expand Down
5 changes: 4 additions & 1 deletion node/src/blockchain/blockchain_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ mod tests {
.retrieve_transactions_params(&retrieve_transactions_params_arc)
.retrieve_transactions_result(Ok(expected_transactions.clone()))
.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(None))
.start_block_result(Ok(Some(6)))
Expand Down Expand Up @@ -1499,6 +1500,7 @@ mod tests {
#[test]
fn handle_retrieve_transactions_sends_received_payments_back_to_accountant() {
let retrieve_transactions_params_arc = Arc::new(Mutex::new(vec![]));
let set_start_block_params_arc = Arc::new(Mutex::new(vec![]));
let system =
System::new("handle_retrieve_transactions_sends_received_payments_back_to_accountant");
let (accountant, _, accountant_recording_arc) = make_recorder();
Expand Down Expand Up @@ -1557,7 +1559,7 @@ mod tests {
system.run();
let after = SystemTime::now();
let set_start_block_params = set_start_block_params_arc.lock().unwrap();
assert_eq!(*set_start_block_params, vec![Some(1234u64)]);
assert_eq!(*set_start_block_params, vec![Some(9876u64)]);
let retrieve_transactions_params = retrieve_transactions_params_arc.lock().unwrap();
assert_eq!(
*retrieve_transactions_params,
Expand Down Expand Up @@ -1596,6 +1598,7 @@ mod tests {
transactions: vec![],
}))
.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)))
.start_block_result(Ok(Some(6)))
Expand Down
2 changes: 1 addition & 1 deletion node/src/database/db_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ mod tests {
#[test]
fn constants_have_correct_values() {
assert_eq!(DATABASE_FILE, "node-data.db");
assert_eq!(CURRENT_SCHEMA_VERSION, 10);
assert_eq!(CURRENT_SCHEMA_VERSION, 9);
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions node/src/database/db_migrations/db_migrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::database::db_migrations::migrations::migration_5_to_6::Migrate_5_to_6
use crate::database::db_migrations::migrations::migration_6_to_7::Migrate_6_to_7;
use crate::database::db_migrations::migrations::migration_7_to_8::Migrate_7_to_8;
use crate::database::db_migrations::migrations::migration_8_to_9::Migrate_8_to_9;
use crate::database::db_migrations::migrations::migration_9_to_10::Migrate_9_to_10;
use crate::database::db_migrations::migrator_utils::{
DBMigDeclarator, DBMigrationUtilities, DBMigrationUtilitiesReal, DBMigratorInnerConfiguration,
};
Expand Down Expand Up @@ -79,7 +78,6 @@ impl DbMigratorReal {
&Migrate_6_to_7,
&Migrate_7_to_8,
&Migrate_8_to_9,
&Migrate_9_to_10,
]
}

Expand Down
71 changes: 0 additions & 71 deletions node/src/database/db_migrations/migrations/migration_9_to_10.rs

This file was deleted.

1 change: 0 additions & 1 deletion node/src/database/db_migrations/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ pub mod migration_5_to_6;
pub mod migration_6_to_7;
pub mod migration_7_to_8;
pub mod migration_8_to_9;
pub mod migration_9_to_10;
23 changes: 22 additions & 1 deletion node/src/test_utils/database_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ pub fn bring_db_0_back_to_life_and_return_connection(db_path: &Path) -> Connecti
conn
}

pub fn bring_db_9_back_to_life_and_return_connection(db_path: &Path) -> Connection {
match remove_file(db_path) {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => (),
Err(e) => panic!("Unexpected but serious error: {}", e),
_ => (),
}
let file_path = current_dir()
.unwrap()
.join("src")
.join("test_utils")
.join("database_version_9_sql.txt");
let mut file = File::open(file_path).unwrap();
let mut buffer = String::new();
file.read_to_string(&mut buffer).unwrap();
let conn = Connection::open(&db_path).unwrap();
buffer.lines().for_each(|stm| {
conn.execute(stm, []).unwrap();
});
conn
}

#[derive(Default)]
pub struct DbMigratorMock {
logger: Option<Logger>,
Expand Down Expand Up @@ -196,7 +217,7 @@ fn contains_particular_list_of_key_words(
found += 1
}
});
assert_eq!(found,1, "We found {} occurrences of the searched line in the tested sql although only a one is considered correct", found)
assert_eq!(found, 1, "We found {} occurrences of the searched line in the tested sql although only a one is considered correct", found)
}

fn prepare_expected_vectors_of_words_including_sorting(
Expand Down
4 changes: 2 additions & 2 deletions node/src/test_utils/database_version_0_sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ insert into config (name, value, encrypted) values ('consuming_wallet_public_key
insert into config (name, value, encrypted) values ('earning_wallet_address', null, 0)
insert into config (name, value, encrypted) values ('schema_version', '0', 0)
insert into config (name, value, encrypted) values ('seed', null, 0)
insert into config (name, value, encrypted) values ('start_block', null, 0)
insert into config (name, value, encrypted) values ('start_block', 8688171, 0)
insert into config (name, value, encrypted) values ('gas_price', '1', 0)
insert into config (name, value, encrypted) values ('past_neighbors', null, 1)
create table payable (wallet_address text primary key, balance integer not null, last_paid_timestamp integer not null, pending_payment_transaction text null)
create unique index idx_payable_wallet_address on payable (wallet_address)
create table receivable (wallet_address text primary key, balance integer not null, last_received_timestamp integer not null)
create unique index idx_receivable_wallet_address on receivable (wallet_address)
create table banned ( wallet_address text primary key )
create unique index idx_banned_wallet_address on banned (wallet_address)
create unique index idx_banned_wallet_address on banned (wallet_address)
18 changes: 18 additions & 0 deletions node/src/test_utils/database_version_9_sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
create table config (name text not null, value text, encrypted integer not null)
create unique index idx_config_name on config (name)
insert into config (name, value, encrypted) values ('example_encrypted', null, 1)
insert into config (name, value, encrypted) values ('clandestine_port', '2897', 0)
insert into config (name, value, encrypted) values ('consuming_wallet_derivation_path', null, 0)
insert into config (name, value, encrypted) values ('consuming_wallet_public_key', null, 0)
insert into config (name, value, encrypted) values ('earning_wallet_address', null, 0)
insert into config (name, value, encrypted) values ('schema_version', '10', 0)
insert into config (name, value, encrypted) values ('seed', null, 0)
insert into config (name, value, encrypted) values ('start_block', null, 0)
insert into config (name, value, encrypted) values ('gas_price', '1', 0)
insert into config (name, value, encrypted) values ('past_neighbors', null, 1)
create table payable (wallet_address text primary key, balance integer not null, last_paid_timestamp integer not null, pending_payment_transaction text null)
create unique index idx_payable_wallet_address on payable (wallet_address)
create table receivable (wallet_address text primary key, balance integer not null, last_received_timestamp integer not null)
create unique index idx_receivable_wallet_address on receivable (wallet_address)
create table banned ( wallet_address text primary key )
create unique index idx_banned_wallet_address on banned (wallet_address)

0 comments on commit b0f9e02

Please sign in to comment.