Skip to content

Commit

Permalink
amoy fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
czarte committed Dec 8, 2024
1 parent 0861864 commit f664481
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 52 deletions.
6 changes: 5 additions & 1 deletion masq/src/commands/exit_location_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ pub mod tests {
.transact_params(&transact_params_arc)
.transact_result(Ok(UiSetExitLocationResponse {}.tmb(0)));
let stderr_arc = context.stderr_arc();
let subject = SetExitLocationCommand::new(&["exit-location".to_string(), "--show-countries".to_string()]).unwrap();
let subject = SetExitLocationCommand::new(&[
"exit-location".to_string(),
"--show-countries".to_string(),
])
.unwrap();

let result = subject.execute(&mut context);

Expand Down
2 changes: 1 addition & 1 deletion masq_lib/src/blockchains/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::blockchains::blockchain_records::{BlockchainRecord, CHAINS};
use crate::constants::{
DEFAULT_CHAIN, DEV_CHAIN_FULL_IDENTIFIER, ETH_MAINNET_FULL_IDENTIFIER,
ETH_ROPSTEN_FULL_IDENTIFIER, POLYGON_MAINNET_FULL_IDENTIFIER, POLYGON_AMOY_FULL_IDENTIFIER
ETH_ROPSTEN_FULL_IDENTIFIER, POLYGON_AMOY_FULL_IDENTIFIER, POLYGON_MAINNET_FULL_IDENTIFIER,
};
use serde_derive::{Deserialize, Serialize};

Expand Down
3 changes: 2 additions & 1 deletion masq_lib/src/shared_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::constants::{
DEFAULT_GAS_PRICE, DEFAULT_UI_PORT, DEV_CHAIN_FULL_IDENTIFIER, ETH_MAINNET_FULL_IDENTIFIER,
ETH_ROPSTEN_FULL_IDENTIFIER, HIGHEST_USABLE_PORT, LOWEST_USABLE_INSECURE_PORT,
POLYGON_MAINNET_FULL_IDENTIFIER, POLYGON_AMOY_FULL_IDENTIFIER,
POLYGON_AMOY_FULL_IDENTIFIER, POLYGON_MAINNET_FULL_IDENTIFIER,
};
use crate::crash_point::CrashPoint;
use clap::{App, Arg};
Expand Down Expand Up @@ -731,6 +731,7 @@ mod tests {
"The Ethereum client you wish to use to provide Blockchain \
exit services from your MASQ Node (e.g. http://localhost:8545, \
https://ropsten.infura.io/v3/YOUR-PROJECT-ID, https://mainnet.infura.io/v3/YOUR-PROJECT-ID), \
https://base-mainnet.g.alchemy.com/v2/d66UL0lPrltmweEqVsv3opBSVI3wkL8I, \
https://polygon-mainnet.infura.io/v3/YOUR-PROJECT-ID"
);
assert_eq!(
Expand Down
19 changes: 19 additions & 0 deletions multinode_integration_tests/src/masq_node_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,25 @@ impl MASQNodeCluster {
)),
}
}

fn create_world_network(ipv4addr: Ipv4Addr, name: &str) -> Result<(), String> {
let mut command = Command::new(
"docker",
Command::strings(vec![
"network",
"create",
format!("--subnet={}/16", ipv4addr).as_str(),
name,
]),
);
match command.wait_for_exit() {
0 => Ok(()),
_ => Err(format!(
"Could not create network integration_net: {}",
command.stderr_as_string()
)),
}
}
}

pub struct DockerHostSocketAddr {
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 @@ -331,7 +331,7 @@ pub fn all_chains() -> [Chain; 4] {
[
Chain::EthMainnet,
Chain::PolyMainnet,
Chain::PolyMumbai,
Chain::PolyAmoy,
Chain::Dev,
]
}
6 changes: 1 addition & 5 deletions node/src/daemon/setup_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2278,11 +2278,7 @@ mod tests {
.join(BlockChain::PolyAmoy.rec().literal_identifier); //not a default
let existing_setup = setup_cluster_from(vec![
("blockchain-service-url", "", Required),
(
"chain",
BlockChain::PolyAmoy.rec().literal_identifier,
Set,
),
("chain", BlockChain::PolyAmoy.rec().literal_identifier, Set),
("clandestine-port", "7788", Default),
("config-file", "config.toml", Default),
("consuming-private-key", "", Blank),
Expand Down
91 changes: 48 additions & 43 deletions node/src/neighborhood/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ impl UserExitPreferences {
&& country_code != ZZ_COUNTRY_CODE_STRING
{
node_record.metadata.country_undesirability =
Self::calculate_country_undesirability((exit_location.priority - 1) as u32);
Self::calculate_country_undesirability(
(exit_location.priority - 1) as u32,
);
}
if (self.location_preference == ExitPreference::ExitCountryWithFallback
&& !self.exit_countries.contains(&country_code))
Expand Down Expand Up @@ -1705,7 +1707,12 @@ impl Neighborhood {
"Neighborhood is empty, no exit Nodes are available.",
),
}
let message = self.create_exit_location_response(client_id, context_id, missing_locations, message.show_countries);
let message = self.create_exit_location_response(
client_id,
context_id,
missing_locations,
message.show_countries,
);
self.node_to_ui_recipient_opt
.as_ref()
.expect("UI Gateway is unbound")
Expand All @@ -1720,53 +1727,45 @@ impl Neighborhood {
missing_locations: Vec<String>,
show_countries: bool,
) -> NodeToUiMessage {
let errmessage =
match show_countries {
let errmessage = match show_countries {
true => match &missing_locations.is_empty() {
true => {
match &missing_locations.is_empty() {
true => {
format!("Exit Countries: {:?}", self.user_exit_preferences.db_countries)
},
false => {
format!(
format!(
"Exit Countries: {:?}",
self.user_exit_preferences.db_countries
)
}
false => {
format!(
"Exit Countries: {:?}\nExit Location: following desired countries are missing in Neighborhood {:?}",
self.user_exit_preferences.db_countries,
self.user_exit_preferences.db_countries,
missing_locations
)
},
}
},
}
},
false => match &missing_locations.is_empty() {
true => "".to_string(),
false => {
match &missing_locations.is_empty() {
true => {
"".to_string()
},
false => {
format!(
format!(
"Exit Location: following desired countries are missing in Neighborhood {:?}",
missing_locations
)
},
}
}
};
},
};
match &errmessage.is_empty() {
false => {
NodeToUiMessage {
target: MessageTarget::ClientId(client_id),
body: MessageBody {
opcode: "exit_location".to_string(),
path: Conversation(context_id),
payload: Err((EXIT_COUNTRY_ERROR, errmessage)),
},
}
false => NodeToUiMessage {
target: MessageTarget::ClientId(client_id),
body: MessageBody {
opcode: "exit_location".to_string(),
path: Conversation(context_id),
payload: Err((EXIT_COUNTRY_ERROR, errmessage)),
},
},
true => NodeToUiMessage {
target: MessageTarget::ClientId(client_id),
body: UiSetExitLocationResponse {}.tmb(context_id),
},
true => {
NodeToUiMessage {
target: MessageTarget::ClientId(client_id),
body: UiSetExitLocationResponse {}.tmb(context_id),
}
}
}
}

Expand Down Expand Up @@ -2240,12 +2239,19 @@ mod tests {
let root_node = subject.neighborhood_database.root().clone();
let mut first_neighbor = make_node_record(1111, true);
first_neighbor.inner.country_code_opt = Some("CZ".to_string());
subject.neighborhood_database.add_node(first_neighbor.clone()).unwrap();
subject.neighborhood_database.add_arbitrary_full_neighbor(root_node.public_key(), first_neighbor.public_key());
subject
.neighborhood_database
.add_node(first_neighbor.clone())
.unwrap();
subject
.neighborhood_database
.add_arbitrary_full_neighbor(root_node.public_key(), first_neighbor.public_key());

let filled_db_countries = subject.init_db_countries();

subject.neighborhood_database.remove_arbitrary_half_neighbor(root_node.public_key(), first_neighbor.public_key());
subject
.neighborhood_database
.remove_arbitrary_half_neighbor(root_node.public_key(), first_neighbor.public_key());
let emptied_db_countries = subject.init_db_countries();

assert_eq!(filled_db_countries, &["CZ".to_string()]);
Expand Down Expand Up @@ -4660,8 +4666,7 @@ mod tests {
let mut subject = make_standard_subject();
let (recipient, _) = make_node_to_ui_recipient();
subject.node_to_ui_recipient_opt = Some(recipient);
subject.user_exit_preferences.location_preference =
ExitPreference::ExitCountryWithFallback;
subject.user_exit_preferences.location_preference = ExitPreference::ExitCountryWithFallback;
let message = UiSetExitLocationRequest {
fallback_routing: false,
exit_locations: vec![CountryCodes {
Expand Down

0 comments on commit f664481

Please sign in to comment.