mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-12-24 23:09:25 -05:00
Added JSON dht and dht/schema tests.
This commit is contained in:
parent
cb49477490
commit
e3a20a352e
@ -2,3 +2,5 @@ mod fixtures;
|
|||||||
pub mod test_serialize_json;
|
pub mod test_serialize_json;
|
||||||
pub mod test_serialize_rkyv;
|
pub mod test_serialize_rkyv;
|
||||||
mod test_types;
|
mod test_types;
|
||||||
|
mod test_types_dht;
|
||||||
|
mod test_types_dht_schema;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
use super::test_types::*;
|
use super::test_types::*;
|
||||||
|
use super::test_types_dht::*;
|
||||||
|
use super::test_types_dht_schema::*;
|
||||||
|
|
||||||
pub async fn test_all() {
|
pub async fn test_all() {
|
||||||
|
// test_types
|
||||||
test_alignedu64().await;
|
test_alignedu64().await;
|
||||||
test_veilidappmessage().await;
|
test_veilidappmessage().await;
|
||||||
test_veilidappcall().await;
|
test_veilidappcall().await;
|
||||||
@ -30,4 +33,13 @@ pub async fn test_all() {
|
|||||||
test_veilidvaluechange().await;
|
test_veilidvaluechange().await;
|
||||||
test_veilidupdate().await;
|
test_veilidupdate().await;
|
||||||
test_veilidstate().await;
|
test_veilidstate().await;
|
||||||
|
// test_types_dht
|
||||||
|
test_dhtrecorddescriptor().await;
|
||||||
|
test_valuedata().await;
|
||||||
|
test_valuesubkeyrangeset().await;
|
||||||
|
// test_types_dht_schema
|
||||||
|
test_dhtschemadflt().await;
|
||||||
|
test_dhtschema().await;
|
||||||
|
test_dhtschemasmplmember().await;
|
||||||
|
test_dhtschemasmpl().await;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::fixtures::*;
|
use super::fixtures::*;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
// veilid_api/types/aligned_u64.rs
|
// aligned_u64
|
||||||
|
|
||||||
pub async fn test_alignedu64() {
|
pub async fn test_alignedu64() {
|
||||||
let orig = AlignedU64::new(0x0123456789abcdef);
|
let orig = AlignedU64::new(0x0123456789abcdef);
|
||||||
@ -10,7 +10,7 @@ pub async fn test_alignedu64() {
|
|||||||
assert_eq!(orig, copy);
|
assert_eq!(orig, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// veilid_api/types/app_messsage_call.rs
|
// app_messsage_call
|
||||||
|
|
||||||
pub async fn test_veilidappmessage() {
|
pub async fn test_veilidappmessage() {
|
||||||
let orig = VeilidAppMessage {
|
let orig = VeilidAppMessage {
|
||||||
@ -33,7 +33,7 @@ pub async fn test_veilidappcall() {
|
|||||||
assert_eq!(orig, copy);
|
assert_eq!(orig, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// veilid_api/types/fourcc.rs
|
// fourcc
|
||||||
|
|
||||||
pub async fn test_fourcc() {
|
pub async fn test_fourcc() {
|
||||||
let orig = FourCC::from_str("D34D").unwrap();
|
let orig = FourCC::from_str("D34D").unwrap();
|
||||||
@ -42,7 +42,7 @@ pub async fn test_fourcc() {
|
|||||||
assert_eq!(orig, copy);
|
assert_eq!(orig, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// veilid_api/types/safety.rs
|
// safety
|
||||||
|
|
||||||
pub async fn test_sequencing() {
|
pub async fn test_sequencing() {
|
||||||
let orig = Sequencing::PreferOrdered;
|
let orig = Sequencing::PreferOrdered;
|
||||||
@ -77,7 +77,7 @@ pub async fn test_safetyspec() {
|
|||||||
assert_eq!(orig, copy);
|
assert_eq!(orig, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// veilid_api/types/stats.rs
|
// stats
|
||||||
|
|
||||||
pub async fn test_latencystats() {
|
pub async fn test_latencystats() {
|
||||||
let orig = fix_latencystats();
|
let orig = fix_latencystats();
|
||||||
@ -114,7 +114,7 @@ pub async fn test_peerstats() {
|
|||||||
assert_eq!(orig, copy);
|
assert_eq!(orig, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// veilid_api/types/tunnel.rs
|
// tunnel
|
||||||
|
|
||||||
pub async fn test_tunnelmode() {
|
pub async fn test_tunnelmode() {
|
||||||
let orig = TunnelMode::Raw;
|
let orig = TunnelMode::Raw;
|
||||||
@ -171,7 +171,7 @@ pub async fn test_partialtunnel() {
|
|||||||
assert_eq!(orig, copy);
|
assert_eq!(orig, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// veilid_api/types/veilid_log.rs
|
// veilid_log
|
||||||
|
|
||||||
pub async fn test_veilidloglevel() {
|
pub async fn test_veilidloglevel() {
|
||||||
let orig = VeilidLogLevel::Info;
|
let orig = VeilidLogLevel::Info;
|
||||||
@ -191,7 +191,7 @@ pub async fn test_veilidlog() {
|
|||||||
assert_eq!(orig, copy);
|
assert_eq!(orig, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// veilid_api/types/veilid_state.rs
|
// veilid_state
|
||||||
|
|
||||||
pub async fn test_attachmentstate() {
|
pub async fn test_attachmentstate() {
|
||||||
let orig = AttachmentState::FullyAttached;
|
let orig = AttachmentState::FullyAttached;
|
||||||
|
41
veilid-core/src/veilid_api/tests/test_types_dht.rs
Normal file
41
veilid-core/src/veilid_api/tests/test_types_dht.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
use super::fixtures::*;
|
||||||
|
use crate::*;
|
||||||
|
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 copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(orig, copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// value_data
|
||||||
|
|
||||||
|
pub async fn test_valuedata() {
|
||||||
|
let orig = ValueData {
|
||||||
|
seq: 42,
|
||||||
|
data: b"Brent Spiner".to_vec(),
|
||||||
|
writer: fix_cryptokey(),
|
||||||
|
};
|
||||||
|
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(orig, copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// value_subkey_range_set
|
||||||
|
|
||||||
|
pub async fn test_valuesubkeyrangeset() {
|
||||||
|
let orig = ValueSubkeyRangeSet {
|
||||||
|
data: RangeSetBlaze::from_iter([20..=30]),
|
||||||
|
};
|
||||||
|
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(orig, copy);
|
||||||
|
}
|
64
veilid-core/src/veilid_api/tests/test_types_dht_schema.rs
Normal file
64
veilid-core/src/veilid_api/tests/test_types_dht_schema.rs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
use super::fixtures::*;
|
||||||
|
use crate::*;
|
||||||
|
use range_set_blaze::*;
|
||||||
|
|
||||||
|
// dlft
|
||||||
|
|
||||||
|
pub async fn test_dhtschemadflt() {
|
||||||
|
let orig = DHTSchemaDFLT { o_cnt: 9 };
|
||||||
|
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(orig, copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mod
|
||||||
|
|
||||||
|
pub async fn test_dhtschema() {
|
||||||
|
let orig = DHTSchema::SMPL(DHTSchemaSMPL {
|
||||||
|
o_cnt: 91,
|
||||||
|
members: vec![
|
||||||
|
DHTSchemaSMPLMember {
|
||||||
|
m_key: fix_cryptokey(),
|
||||||
|
m_cnt: 5,
|
||||||
|
},
|
||||||
|
DHTSchemaSMPLMember {
|
||||||
|
m_key: fix_cryptokey(),
|
||||||
|
m_cnt: 6,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(orig, copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// smpl
|
||||||
|
|
||||||
|
pub async fn test_dhtschemasmplmember() {
|
||||||
|
let orig = DHTSchemaSMPLMember {
|
||||||
|
m_key: fix_cryptokey(),
|
||||||
|
m_cnt: 7,
|
||||||
|
};
|
||||||
|
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(orig, copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn test_dhtschemasmpl() {
|
||||||
|
let orig = DHTSchemaSMPL {
|
||||||
|
o_cnt: 91,
|
||||||
|
members: vec![
|
||||||
|
DHTSchemaSMPLMember {
|
||||||
|
m_key: fix_cryptokey(),
|
||||||
|
m_cnt: 8,
|
||||||
|
},
|
||||||
|
DHTSchemaSMPLMember {
|
||||||
|
m_key: fix_cryptokey(),
|
||||||
|
m_cnt: 9,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(orig, copy);
|
||||||
|
}
|
@ -17,14 +17,14 @@ use super::*;
|
|||||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||||
pub struct DHTRecordDescriptor {
|
pub struct DHTRecordDescriptor {
|
||||||
/// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
|
/// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
|
||||||
key: TypedKey,
|
pub key: TypedKey,
|
||||||
/// The public key of the owner
|
/// The public key of the owner
|
||||||
owner: PublicKey,
|
pub 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
|
||||||
owner_secret: Option<SecretKey>,
|
pub owner_secret: Option<SecretKey>,
|
||||||
/// The schema in use associated with the key
|
/// The schema in use associated with the key
|
||||||
schema: DHTSchema,
|
pub schema: DHTSchema,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DHTRecordDescriptor {
|
impl DHTRecordDescriptor {
|
||||||
|
@ -20,7 +20,7 @@ use range_set_blaze::*;
|
|||||||
pub struct ValueSubkeyRangeSet {
|
pub struct ValueSubkeyRangeSet {
|
||||||
#[with(RkyvRangeSetBlaze)]
|
#[with(RkyvRangeSetBlaze)]
|
||||||
#[serde(with = "serialize_range_set_blaze")]
|
#[serde(with = "serialize_range_set_blaze")]
|
||||||
data: RangeSetBlaze<ValueSubkey>,
|
pub data: RangeSetBlaze<ValueSubkey>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ValueSubkeyRangeSet {
|
impl ValueSubkeyRangeSet {
|
||||||
|
Loading…
Reference in New Issue
Block a user