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