Skip to content

Commit

Permalink
Merge #369: Adding default port value if not provided.
Browse files Browse the repository at this point in the history
a5178a3 Adding default port value if not provided. (Zshan0)

Pull request description:

  Currently, the `Installer` gives a warning:
  ```
  Invalid format for a socket address
  ```
  If the entered host address at "Coordinator information" does not contain the port. Since there exists a default port that must be used if not provided, the GUI must try using it.

  The issue was raised in #250 and this PR closes it.

ACKs for top commit:
  edouardparis:
    ACK a5178a3

Tree-SHA512: 5eadc2c308618816cfadc2e78d3a6079d77661582fa29559190822e684ad4e50bb0abea5a462fca1fab18a1b24723d6327c762f9485eaa8cbb2ffcf9333d7cb0
  • Loading branch information
edouardparis committed Jul 4, 2022
2 parents 0859e52 + a5178a3 commit 7ac8b12
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion src/installer/step/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ impl Step for DefineCoordinator {

self.host.valid = SocketAddr::from_str(&self.host.value).is_ok();

if !self.host.valid {
// trim spaces at the end if any.
let clean_value = self.host.value.trim_end();
let value = format!("{}:8383", clean_value).to_string();

self.host.valid = SocketAddr::from_str(&value).is_ok();

if self.host.valid {
self.host.value = value;
}
}

if !self.host.valid || !self.noise_key.valid {
return false;
}
Expand Down Expand Up @@ -555,9 +567,10 @@ impl From<Final> for Box<dyn Step> {

#[cfg(test)]
mod tests {
use super::DefineCoordinator as DefineCoordinatorStep;
use super::{DefineCpfpDescriptor as DefineCpfpDescriptorStep, *};
use crate::installer::config::Config;
use crate::installer::message::{DefineCpfpDescriptor, ParticipantXpub, *};
use crate::installer::message::{DefineCoordinator, DefineCpfpDescriptor, ParticipantXpub, *};

const STAKEHOLDERS_XPUBS: [&str; 4] = [
"xpub6DEzq5DNPx2rPiZJ7wvFhxRKUKDoV1GwjFmFdaxFfbsw9HsHyxc9usoRUMxqJaMrwoXh4apahsGEnjAS4cVCBDgqsx5Groww22AdHbgxVDg",
Expand Down Expand Up @@ -618,6 +631,60 @@ mod tests {
}
}

const HOST_NO_PORT: [&str; 3] = ["193.168.1.13", "193.168.1.13 ", "193.168.1.13 "];
const HOST_PORT: [&str; 1] = ["193.168.1.13:8383"];
const INCORRECT_HOST: [&str; 1] = ["193.168.1."];
const NOISE_KEYS: [&str; 1] =
// 64 character long string
["1234678901234567890123456789012345678901234567890123456789012345"];

#[test]
fn define_coordinator_host() {
let mut ctx = Context::new(bitcoin::Network::Bitcoin);
let mut manager_config = Config::new();

// Valid host with port already existing.
for host in HOST_PORT.iter() {
let mut coordinator_step = DefineCoordinatorStep::new();
coordinator_step.update(message::Message::DefineCoordinator(
DefineCoordinator::NoiseKeyEdited(NOISE_KEYS[0].to_string()),
));

coordinator_step.update(message::Message::DefineCoordinator(
DefineCoordinator::HostEdited(host.to_string()),
));
let is_valid = coordinator_step.apply(&mut ctx, &mut manager_config);
assert!(is_valid);
}

// No port.
for host in HOST_NO_PORT.iter() {
let mut coordinator_step = DefineCoordinatorStep::new();
coordinator_step.update(message::Message::DefineCoordinator(
DefineCoordinator::NoiseKeyEdited(NOISE_KEYS[0].to_string()),
));

coordinator_step.update(Message::DefineCoordinator(DefineCoordinator::HostEdited(
host.to_string(),
)));
let is_valid = coordinator_step.apply(&mut ctx, &mut manager_config);
assert!(is_valid);
}
// Incorrect host addresses for avoiding false positive.
for host in INCORRECT_HOST.iter() {
let mut coordinator_step = DefineCoordinatorStep::new();
coordinator_step.update(message::Message::DefineCoordinator(
DefineCoordinator::NoiseKeyEdited(NOISE_KEYS[0].to_string()),
));

coordinator_step.update(Message::DefineCoordinator(DefineCoordinator::HostEdited(
host.to_string(),
)));
let is_valid = coordinator_step.apply(&mut ctx, &mut manager_config);
assert!(!is_valid);
}
}

#[test]
fn define_deposit_descriptor() {
let mut ctx = Context::new(bitcoin::Network::Bitcoin);
Expand Down

0 comments on commit 7ac8b12

Please sign in to comment.