fix tests

This commit is contained in:
John Smith
2023-06-16 14:18:34 -04:00
parent f3a3d5322c
commit 9ffcc0da87
13 changed files with 73 additions and 51 deletions

View File

@@ -1,6 +1,5 @@
use crate::*;
const SERIALIZED_PEERINFO: &str = r###"{"node_ids":["FAKE:eFOfgm_FNZBsTRi7KAESNwYFAUGgX2uDrTRWAL8ucjM"],"signed_node_info":{"Direct":{"node_info":{"network_class":"InboundCapable","outbound_protocols":1,"address_types":3,"envelope_support":[0],"crypto_support":[[86,76,68,48]],"dial_info_detail_list":[{"class":"Direct","dial_info":{"kind":"UDP","socket_address":{"address":{"IPV4":"1.2.3.4"},"port":5150}}},{"class":"Direct","dial_info":{"kind":"UDP","socket_address":{"address":{"IPV6":"bad:cafe::1"},"port":5150}}},{"class":"Direct","dial_info":{"kind":"TCP","socket_address":{"address":{"IPV4":"5.6.7.8"},"port":5150}}},{"class":"Direct","dial_info":{"kind":"TCP","socket_address":{"address":{"IPV6":"bad:cafe::1"},"port":5150}}},{"class":"Direct","dial_info":{"kind":"WS","socket_address":{"address":{"IPV4":"9.10.11.12"},"port":5150},"request":"bootstrap-1.dev.veilid.net:5150/ws"}},{"class":"Direct","dial_info":{"kind":"WS","socket_address":{"address":{"IPV6":"bad:cafe::1"},"port":5150},"request":"bootstrap-1.dev.veilid.net:5150/ws"}}]},"timestamp":1685058646770389,"signatures":[]}}}"###;
use routing_table::*;
fn fake_routing_table() -> routing_table::RoutingTable {
let veilid_config = VeilidConfig::new();
@@ -25,7 +24,7 @@ fn fake_routing_table() -> routing_table::RoutingTable {
block_store.clone(),
crypto.clone(),
);
routing_table::RoutingTable::new(network_manager)
RoutingTable::new(network_manager)
}
pub async fn test_routingtable_buckets_round_trip() {
@@ -84,11 +83,27 @@ pub async fn test_routingtable_buckets_round_trip() {
}
pub async fn test_round_trip_peerinfo() {
let pi: routing_table::PeerInfo = deserialize_json(SERIALIZED_PEERINFO).unwrap();
let pi: PeerInfo = PeerInfo::new(
TypedKeySet::new(),
SignedNodeInfo::Direct(SignedDirectNodeInfo::new(
NodeInfo::new(
NetworkClass::OutboundOnly,
ProtocolTypeSet::new(),
AddressTypeSet::new(),
vec![0],
vec![CRYPTO_KIND_VLD0],
vec![],
),
Timestamp::new(0),
Vec::new(),
)),
);
let s = serialize_json(&pi);
let pi2 = deserialize_json(&s).expect("Should deserialize");
let s2 = serialize_json(&pi2);
let back = serialize_json(pi);
assert_eq!(SERIALIZED_PEERINFO, back);
assert_eq!(pi, pi2);
assert_eq!(s, s2);
}
pub async fn test_all() {