From e3a20a352e35df230430c18dd705fb9910c41f36 Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 1 Jun 2023 15:40:47 -0700 Subject: [PATCH] Added JSON dht and dht/schema tests. --- veilid-core/src/veilid_api/tests/mod.rs | 2 + .../veilid_api/tests/test_serialize_json.rs | 12 ++++ .../src/veilid_api/tests/test_types.rs | 16 ++--- .../src/veilid_api/tests/test_types_dht.rs | 41 ++++++++++++ .../veilid_api/tests/test_types_dht_schema.rs | 64 +++++++++++++++++++ .../types/dht/dht_record_descriptor.rs | 8 +-- .../types/dht/value_subkey_range_set.rs | 2 +- 7 files changed, 132 insertions(+), 13 deletions(-) create mode 100644 veilid-core/src/veilid_api/tests/test_types_dht.rs create mode 100644 veilid-core/src/veilid_api/tests/test_types_dht_schema.rs diff --git a/veilid-core/src/veilid_api/tests/mod.rs b/veilid-core/src/veilid_api/tests/mod.rs index ea2ec200..a5fe97b7 100644 --- a/veilid-core/src/veilid_api/tests/mod.rs +++ b/veilid-core/src/veilid_api/tests/mod.rs @@ -2,3 +2,5 @@ mod fixtures; pub mod test_serialize_json; pub mod test_serialize_rkyv; mod test_types; +mod test_types_dht; +mod test_types_dht_schema; diff --git a/veilid-core/src/veilid_api/tests/test_serialize_json.rs b/veilid-core/src/veilid_api/tests/test_serialize_json.rs index a3521c83..78df9607 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -1,6 +1,9 @@ use super::test_types::*; +use super::test_types_dht::*; +use super::test_types_dht_schema::*; pub async fn test_all() { + // test_types test_alignedu64().await; test_veilidappmessage().await; test_veilidappcall().await; @@ -30,4 +33,13 @@ pub async fn test_all() { test_veilidvaluechange().await; test_veilidupdate().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; } diff --git a/veilid-core/src/veilid_api/tests/test_types.rs b/veilid-core/src/veilid_api/tests/test_types.rs index 739dbd0d..b56cc024 100644 --- a/veilid-core/src/veilid_api/tests/test_types.rs +++ b/veilid-core/src/veilid_api/tests/test_types.rs @@ -1,7 +1,7 @@ use super::fixtures::*; use crate::*; -// veilid_api/types/aligned_u64.rs +// aligned_u64 pub async fn test_alignedu64() { let orig = AlignedU64::new(0x0123456789abcdef); @@ -10,7 +10,7 @@ pub async fn test_alignedu64() { assert_eq!(orig, copy); } -// veilid_api/types/app_messsage_call.rs +// app_messsage_call pub async fn test_veilidappmessage() { let orig = VeilidAppMessage { @@ -33,7 +33,7 @@ pub async fn test_veilidappcall() { assert_eq!(orig, copy); } -// veilid_api/types/fourcc.rs +// fourcc pub async fn test_fourcc() { let orig = FourCC::from_str("D34D").unwrap(); @@ -42,7 +42,7 @@ pub async fn test_fourcc() { assert_eq!(orig, copy); } -// veilid_api/types/safety.rs +// safety pub async fn test_sequencing() { let orig = Sequencing::PreferOrdered; @@ -77,7 +77,7 @@ pub async fn test_safetyspec() { assert_eq!(orig, copy); } -// veilid_api/types/stats.rs +// stats pub async fn test_latencystats() { let orig = fix_latencystats(); @@ -114,7 +114,7 @@ pub async fn test_peerstats() { assert_eq!(orig, copy); } -// veilid_api/types/tunnel.rs +// tunnel pub async fn test_tunnelmode() { let orig = TunnelMode::Raw; @@ -171,7 +171,7 @@ pub async fn test_partialtunnel() { assert_eq!(orig, copy); } -// veilid_api/types/veilid_log.rs +// veilid_log pub async fn test_veilidloglevel() { let orig = VeilidLogLevel::Info; @@ -191,7 +191,7 @@ pub async fn test_veilidlog() { assert_eq!(orig, copy); } -// veilid_api/types/veilid_state.rs +// veilid_state pub async fn test_attachmentstate() { let orig = AttachmentState::FullyAttached; diff --git a/veilid-core/src/veilid_api/tests/test_types_dht.rs b/veilid-core/src/veilid_api/tests/test_types_dht.rs new file mode 100644 index 00000000..f098e06b --- /dev/null +++ b/veilid-core/src/veilid_api/tests/test_types_dht.rs @@ -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); +} diff --git a/veilid-core/src/veilid_api/tests/test_types_dht_schema.rs b/veilid-core/src/veilid_api/tests/test_types_dht_schema.rs new file mode 100644 index 00000000..a7a8379c --- /dev/null +++ b/veilid-core/src/veilid_api/tests/test_types_dht_schema.rs @@ -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); +} diff --git a/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs b/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs index 1c4d114e..1b04050b 100644 --- a/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs +++ b/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs @@ -17,14 +17,14 @@ use super::*; #[archive_attr(repr(C), derive(CheckBytes))] pub struct DHTRecordDescriptor { /// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ] - key: TypedKey, + pub key: TypedKey, /// 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 just being opened: None - owner_secret: Option, + pub owner_secret: Option, /// The schema in use associated with the key - schema: DHTSchema, + pub schema: DHTSchema, } impl DHTRecordDescriptor { diff --git a/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs b/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs index 3dd40f67..376530b5 100644 --- a/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs +++ b/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs @@ -20,7 +20,7 @@ use range_set_blaze::*; pub struct ValueSubkeyRangeSet { #[with(RkyvRangeSetBlaze)] #[serde(with = "serialize_range_set_blaze")] - data: RangeSetBlaze, + pub data: RangeSetBlaze, } impl ValueSubkeyRangeSet {