use std::collections::HashMap;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use grin_p2p as p2p;
use crate::p2p::types::PeerAddr;
#[test]
fn test_peer_addr_hashing() {
let mut peers: HashMap<PeerAddr, String> = HashMap::new();
let socket_addr1 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), 8080);
let peer_addr1 = PeerAddr(socket_addr1);
peers.insert(peer_addr1, "peer1".into());
assert!(peers.contains_key(&peer_addr1));
assert_eq!(peers.len(), 1);
let socket_addr2 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), 8081);
let peer_addr2 = PeerAddr(socket_addr2);
assert!(peers.contains_key(&peer_addr1));
assert!(peers.contains_key(&peer_addr2));
peers.insert(peer_addr2, "peer2".into());
assert!(peers.contains_key(&peer_addr1));
assert!(peers.contains_key(&peer_addr2));
assert_eq!(peers.len(), 1);
assert_eq!(peer_addr1, peer_addr2);
assert_eq!(peer_addr1.0, socket_addr1);
assert_eq!(peer_addr2.0, socket_addr2);
assert_eq!(peer_addr1.0.port(), 8080);
assert_eq!(peer_addr2.0.port(), 8081);
}