Skip to content

Commit

Permalink
Use zero ports in tests (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcph4 authored Sep 29, 2023
1 parent 299638d commit faa5801
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/service/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use parking_lot::RwLock;
use std::{collections::HashMap, sync::Arc, time::Duration};
use tokio::sync::{mpsc, oneshot};

/// Default UDP port number to use for tests requiring UDP exposure
pub const DEFAULT_UDP_PORT: u16 = 0;

fn _connected_state() -> NodeStatus {
NodeStatus {
state: ConnectionState::Connected,
Expand Down Expand Up @@ -105,14 +108,14 @@ async fn test_updating_connection_on_ping() {
let ip = "127.0.0.1".parse().unwrap();
let enr = EnrBuilder::new("v4")
.ip4(ip)
.udp4(10001)
.udp4(DEFAULT_UDP_PORT)
.build(&enr_key1)
.unwrap();
let ip2 = "127.0.0.1".parse().unwrap();
let enr_key2 = CombinedKey::generate_secp256k1();
let enr2 = EnrBuilder::new("v4")
.ip4(ip2)
.udp4(10002)
.udp4(DEFAULT_UDP_PORT)
.build(&enr_key2)
.unwrap();

Expand Down Expand Up @@ -141,7 +144,7 @@ async fn test_updating_connection_on_ping() {
body: ResponseBody::Pong {
enr_seq: 2,
ip: ip2.into(),
port: 10002,
port: DEFAULT_UDP_PORT,
},
};

Expand Down Expand Up @@ -173,15 +176,15 @@ async fn test_connection_direction_on_inject_session_established() {
let ip = std::net::Ipv4Addr::LOCALHOST;
let enr = EnrBuilder::new("v4")
.ip4(ip)
.udp4(10001)
.udp4(DEFAULT_UDP_PORT)
.build(&enr_key1)
.unwrap();

let enr_key2 = CombinedKey::generate_secp256k1();
let ip2 = std::net::Ipv4Addr::LOCALHOST;
let enr2 = EnrBuilder::new("v4")
.ip4(ip2)
.udp4(10002)
.udp4(DEFAULT_UDP_PORT)
.build(&enr_key2)
.unwrap();

Expand Down

0 comments on commit faa5801

Please sign in to comment.