fix tests
This commit is contained in:
parent
f3a3d5322c
commit
9ffcc0da87
@ -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() {
|
||||
|
@ -1,7 +1,16 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(
|
||||
Clone, Default, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize,
|
||||
Clone,
|
||||
Default,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Debug,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
RkyvArchive,
|
||||
RkyvSerialize,
|
||||
RkyvDeserialize,
|
||||
)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct NodeInfo {
|
||||
|
@ -1,6 +1,8 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[derive(
|
||||
Clone, Debug, Serialize, Deserialize, PartialEq, Eq, RkyvArchive, RkyvSerialize, RkyvDeserialize,
|
||||
)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct PeerInfo {
|
||||
node_ids: TypedKeySet,
|
||||
|
@ -1,7 +1,9 @@
|
||||
use super::*;
|
||||
|
||||
/// Signed NodeInfo that can be passed around amongst peers and verifiable
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[derive(
|
||||
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize,
|
||||
)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct SignedDirectNodeInfo {
|
||||
node_info: NodeInfo,
|
||||
|
@ -1,6 +1,8 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[derive(
|
||||
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize,
|
||||
)]
|
||||
#[archive_attr(repr(u8), derive(CheckBytes))]
|
||||
pub enum SignedNodeInfo {
|
||||
Direct(SignedDirectNodeInfo),
|
||||
|
@ -1,7 +1,9 @@
|
||||
use super::*;
|
||||
|
||||
/// Signed NodeInfo with a relay that can be passed around amongst peers and verifiable
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[derive(
|
||||
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize,
|
||||
)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct SignedRelayedNodeInfo {
|
||||
node_info: NodeInfo,
|
||||
|
@ -212,10 +212,6 @@ pub fn fix_veilidvaluechange() -> VeilidValueChange {
|
||||
key: fix_typedkey(),
|
||||
subkeys: vec![1, 2, 3, 4],
|
||||
count: 5,
|
||||
value: ValueData {
|
||||
seq: 23,
|
||||
data: b"ValueData".to_vec(),
|
||||
writer: fix_cryptokey(),
|
||||
},
|
||||
value: ValueData::new_with_seq(23, b"ValueData".to_vec(), fix_cryptokey()),
|
||||
}
|
||||
}
|
||||
|
@ -13,21 +13,18 @@ pub async fn test_alignedu64() {
|
||||
// app_messsage_call
|
||||
|
||||
pub async fn test_veilidappmessage() {
|
||||
let orig = VeilidAppMessage {
|
||||
sender: Some(fix_typedkey()),
|
||||
message: b"Hi there!".to_vec(),
|
||||
};
|
||||
let orig = VeilidAppMessage::new(Some(fix_typedkey()), b"Hi there!".to_vec());
|
||||
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||
|
||||
assert_eq!(orig, copy);
|
||||
}
|
||||
|
||||
pub async fn test_veilidappcall() {
|
||||
let orig = VeilidAppCall {
|
||||
sender: Some(fix_typedkey()),
|
||||
message: b"Well, hello!".to_vec(),
|
||||
call_id: AlignedU64::from(123),
|
||||
};
|
||||
let orig = VeilidAppCall::new(
|
||||
Some(fix_typedkey()),
|
||||
b"Well, hello!".to_vec(),
|
||||
AlignedU64::from(123),
|
||||
);
|
||||
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||
|
||||
assert_eq!(orig, copy);
|
||||
|
@ -5,12 +5,12 @@ use range_set_blaze::*;
|
||||
// dht_record_descriptors
|
||||
|
||||
pub async fn test_dhtrecorddescriptor() {
|
||||
let orig = DHTRecordDescriptor {
|
||||
key: fix_typedkey(),
|
||||
owner: fix_cryptokey(),
|
||||
owner_secret: Some(fix_cryptokey()),
|
||||
schema: DHTSchema::DFLT(DHTSchemaDFLT { o_cnt: 4321 }),
|
||||
};
|
||||
let orig = DHTRecordDescriptor::new(
|
||||
fix_typedkey(),
|
||||
fix_cryptokey(),
|
||||
Some(fix_cryptokey()),
|
||||
DHTSchema::DFLT(DHTSchemaDFLT { o_cnt: 4321 }),
|
||||
);
|
||||
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||
|
||||
assert_eq!(orig, copy);
|
||||
@ -19,11 +19,7 @@ pub async fn test_dhtrecorddescriptor() {
|
||||
// value_data
|
||||
|
||||
pub async fn test_valuedata() {
|
||||
let orig = ValueData {
|
||||
seq: 42,
|
||||
data: b"Brent Spiner".to_vec(),
|
||||
writer: fix_cryptokey(),
|
||||
};
|
||||
let orig = ValueData::new_with_seq(42, b"Brent Spiner".to_vec(), fix_cryptokey());
|
||||
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||
|
||||
assert_eq!(orig, copy);
|
||||
@ -32,9 +28,7 @@ pub async fn test_valuedata() {
|
||||
// value_subkey_range_set
|
||||
|
||||
pub async fn test_valuesubkeyrangeset() {
|
||||
let orig = ValueSubkeyRangeSet {
|
||||
data: RangeSetBlaze::from_iter([20..=30]),
|
||||
};
|
||||
let orig = ValueSubkeyRangeSet::new_with_data(RangeSetBlaze::from_iter([20..=30]));
|
||||
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||
|
||||
assert_eq!(orig, copy);
|
||||
|
@ -57,17 +57,17 @@ pub struct VeilidAppCall {
|
||||
/// Some(sender) if the request was sent directly, None if received via a private/safety route
|
||||
#[serde(with = "opt_json_as_string")]
|
||||
#[schemars(with = "Option<String>")]
|
||||
pub sender: Option<TypedKey>,
|
||||
sender: Option<TypedKey>,
|
||||
|
||||
/// The content of the request to deliver to the application
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
pub message: Vec<u8>,
|
||||
message: Vec<u8>,
|
||||
|
||||
/// The id to reply to
|
||||
#[serde(with = "json_as_string")]
|
||||
#[schemars(with = "String")]
|
||||
pub call_id: OperationId,
|
||||
call_id: OperationId,
|
||||
}
|
||||
|
||||
impl VeilidAppCall {
|
||||
|
@ -19,16 +19,16 @@ use super::*;
|
||||
pub struct DHTRecordDescriptor {
|
||||
/// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
|
||||
#[schemars(with = "String")]
|
||||
pub key: TypedKey,
|
||||
key: TypedKey,
|
||||
/// The public key of the owner
|
||||
#[schemars(with = "String")]
|
||||
pub owner: PublicKey,
|
||||
owner: PublicKey,
|
||||
/// If this key is being created: Some(the secret key of the owner)
|
||||
/// If this key is just being opened: None
|
||||
#[schemars(with = "Option<String>")]
|
||||
pub owner_secret: Option<SecretKey>,
|
||||
owner_secret: Option<SecretKey>,
|
||||
/// The schema in use associated with the key
|
||||
pub schema: DHTSchema,
|
||||
schema: DHTSchema,
|
||||
}
|
||||
|
||||
impl DHTRecordDescriptor {
|
||||
|
@ -18,16 +18,16 @@ use super::*;
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct ValueData {
|
||||
/// An increasing sequence number to time-order the DHT record changes
|
||||
pub seq: ValueSeqNum,
|
||||
seq: ValueSeqNum,
|
||||
|
||||
/// The contents of a DHT Record
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
pub data: Vec<u8>,
|
||||
data: Vec<u8>,
|
||||
|
||||
/// The public identity key of the writer of the data
|
||||
#[schemars(with = "String")]
|
||||
pub writer: PublicKey,
|
||||
writer: PublicKey,
|
||||
}
|
||||
impl ValueData {
|
||||
pub const MAX_LEN: usize = 32768;
|
||||
|
@ -23,7 +23,7 @@ pub struct ValueSubkeyRangeSet {
|
||||
#[with(RkyvRangeSetBlaze)]
|
||||
#[serde(with = "serialize_range_set_blaze")]
|
||||
#[schemars(with = "Vec<(u32,u32)>")]
|
||||
pub data: RangeSetBlaze<ValueSubkey>,
|
||||
data: RangeSetBlaze<ValueSubkey>,
|
||||
}
|
||||
|
||||
impl ValueSubkeyRangeSet {
|
||||
@ -32,6 +32,9 @@ impl ValueSubkeyRangeSet {
|
||||
data: Default::default(),
|
||||
}
|
||||
}
|
||||
pub fn new_with_data(data: RangeSetBlaze<ValueSubkey>) -> Self {
|
||||
Self { data }
|
||||
}
|
||||
pub fn single(value: ValueSubkey) -> Self {
|
||||
let mut data = RangeSetBlaze::new();
|
||||
data.insert(value);
|
||||
|
Loading…
Reference in New Issue
Block a user