From a74b0cf3b6cd13995ea177ce41dcde067014b888 Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 25 May 2023 15:01:50 -0700 Subject: [PATCH 01/18] Refactor veilid_core::tests::native with macros --- veilid-core/src/tests/native/mod.rs | 138 +++++++++------------------- 1 file changed, 41 insertions(+), 97 deletions(-) diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index f2c5ab07..336fb343 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -33,7 +33,7 @@ pub async fn run_all_tests() { test_crypto::test_all().await; info!("TEST: test_envelope_receipt"); test_envelope_receipt::test_all().await; - info!("TEST: veilid_api::test_serialize"); + info!("TEST: veilid_api::tests::test_serialize_rkyv"); veilid_api::tests::test_serialize_rkyv::test_all().await; info!("TEST: routing_table::test_serialize"); routing_table::tests::test_serialize::test_all().await; @@ -59,6 +59,34 @@ cfg_if! { if #[cfg(test)] { use serial_test::serial; use std::sync::Once; + use paste::paste; + + macro_rules! run_test { + ($mod:ident, $func:ident) => { + paste! { + #[test] + #[serial] + fn []() { + setup(); + block_on(async { + $mod::tests::$func::test_all().await; + }) + } + } + }; + ($func:ident) => { + paste! { + #[test] + #[serial] + fn []() { + setup(); + block_on(async { + $func::test_all().await; + }) + } + } + }; + } static SETUP_ONCE: Once = Once::new(); @@ -81,112 +109,28 @@ cfg_if! { }); } - #[test] - #[serial] - fn run_test_host_interface() { - setup(); - block_on(async { - test_host_interface::test_all().await; - }); - } + run_test!(test_host_interface); - #[test] - #[serial] - fn run_test_dht_key() { - setup(); - block_on(async { - test_types::test_all().await; - }); - } + run_test!(test_types); - #[test] - #[serial] - fn run_test_veilid_core() { - setup(); - block_on(async { - test_veilid_core::test_all().await; - }); - } + run_test!(test_veilid_core); - #[test] - #[serial] - fn run_test_veilid_config() { - setup(); - block_on(async { - test_veilid_config::test_all().await; - }) - } + run_test!(test_veilid_config); - #[test] - #[serial] - fn run_test_connection_table() { - setup(); - block_on(async { - test_connection_table::test_all().await; - }) - } + run_test!(test_connection_table); - #[test] - #[serial] - fn run_test_signed_node_info() { - setup(); - block_on(async { - test_signed_node_info::test_all().await; - }) - } + run_test!(test_signed_node_info); - #[test] - #[serial] - fn run_test_table_store() { - setup(); - block_on(async { - test_table_store::test_all().await; - }) - } + run_test!(test_table_store); - #[test] - #[serial] - fn run_test_protected_store() { - setup(); - block_on(async { - test_protected_store::test_all().await; - }) - } + run_test!(test_protected_store); - #[test] - #[serial] - fn run_test_crypto() { - setup(); - block_on(async { - test_crypto::test_all().await; - }) - } + run_test!(test_crypto); - #[test] - #[serial] - fn run_test_envelope_receipt() { - setup(); - block_on(async { - test_envelope_receipt::test_all().await; - }) - } + run_test!(test_envelope_receipt); - #[test] - #[serial] - fn run_test_serialize_rkyv() { - setup(); - block_on(async { - veilid_api::tests::test_serialize_rkyv::test_all().await; - }) - } + run_test!(veilid_api, test_serialize_rkyv); - #[test] - #[serial] - fn run_test_routing_table_serialize() { - setup(); - block_on(async { - routing_table::tests::test_serialize::test_all().await; - }) - } + run_test!(routing_table, test_serialize); } } From d0ac838708593480d114c78578bd0165ba09b498 Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 25 May 2023 15:20:03 -0700 Subject: [PATCH 02/18] test_serialize => test_serialize_routing_table --- veilid-core/Cargo.toml | 1 + veilid-core/src/routing_table/tests/mod.rs | 2 +- .../{test_serialize.rs => test_serialize_routing_table.rs} | 0 veilid-core/src/tests/native/mod.rs | 6 +++--- veilid-core/tests/web.rs | 2 ++ 5 files changed, 7 insertions(+), 4 deletions(-) rename veilid-core/src/routing_table/tests/{test_serialize.rs => test_serialize_routing_table.rs} (100%) diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index 6eb99b12..d646c587 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -72,6 +72,7 @@ data-encoding = { version = "^2" } weak-table = "0.3.2" range-set-blaze = "0.1.5" argon2 = "0.5.0" +paste = "1.0.12" # Dependencies for native builds only # Linux, Windows, Mac, iOS, Android diff --git a/veilid-core/src/routing_table/tests/mod.rs b/veilid-core/src/routing_table/tests/mod.rs index 209cc9d3..44ed3a79 100644 --- a/veilid-core/src/routing_table/tests/mod.rs +++ b/veilid-core/src/routing_table/tests/mod.rs @@ -1 +1 @@ -pub mod test_serialize; +pub mod test_serialize_routing_table; diff --git a/veilid-core/src/routing_table/tests/test_serialize.rs b/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs similarity index 100% rename from veilid-core/src/routing_table/tests/test_serialize.rs rename to veilid-core/src/routing_table/tests/test_serialize_routing_table.rs diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index 336fb343..613ac9e7 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -35,8 +35,8 @@ pub async fn run_all_tests() { test_envelope_receipt::test_all().await; info!("TEST: veilid_api::tests::test_serialize_rkyv"); veilid_api::tests::test_serialize_rkyv::test_all().await; - info!("TEST: routing_table::test_serialize"); - routing_table::tests::test_serialize::test_all().await; + info!("TEST: routing_table::test_serialize_routing_table"); + routing_table::tests::test_serialize_routing_table::test_all().await; info!("Finished unit tests"); } @@ -131,6 +131,6 @@ cfg_if! { run_test!(veilid_api, test_serialize_rkyv); - run_test!(routing_table, test_serialize); + run_test!(routing_table, test_serialize_routing_table); } } diff --git a/veilid-core/tests/web.rs b/veilid-core/tests/web.rs index f8a2b6fd..ec4e1b31 100644 --- a/veilid-core/tests/web.rs +++ b/veilid-core/tests/web.rs @@ -100,4 +100,6 @@ async fn wasm_test_serialize_rkyv() { async fn wasm_test_routing_table_serialize() { setup(); test_routing_table_serialize::test_all().await; + setup(); + test_serialize::test_all().await; } From cd8e90cafafc7042a1d390f1595f5be555d81843 Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 25 May 2023 15:22:01 -0700 Subject: [PATCH 03/18] Added the bones of test_serialize_json --- veilid-core/src/tests/native/mod.rs | 4 ++++ veilid-core/src/veilid_api/tests/mod.rs | 1 + veilid-core/src/veilid_api/tests/test_serialize_json.rs | 3 +++ veilid-core/tests/web.rs | 6 ++++++ 4 files changed, 14 insertions(+) create mode 100644 veilid-core/src/veilid_api/tests/test_serialize_json.rs diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index 613ac9e7..c687b1e0 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -33,6 +33,8 @@ pub async fn run_all_tests() { test_crypto::test_all().await; info!("TEST: test_envelope_receipt"); test_envelope_receipt::test_all().await; + info!("TEST: veilid_api::tests::test_serialize_json"); + veilid_api::tests::test_serialize_json::test_all().await; info!("TEST: veilid_api::tests::test_serialize_rkyv"); veilid_api::tests::test_serialize_rkyv::test_all().await; info!("TEST: routing_table::test_serialize_routing_table"); @@ -129,6 +131,8 @@ cfg_if! { run_test!(test_envelope_receipt); + run_test!(veilid_api, test_serialize_json); + run_test!(veilid_api, test_serialize_rkyv); run_test!(routing_table, test_serialize_routing_table); diff --git a/veilid-core/src/veilid_api/tests/mod.rs b/veilid-core/src/veilid_api/tests/mod.rs index 3c3d2f33..2d85d773 100644 --- a/veilid-core/src/veilid_api/tests/mod.rs +++ b/veilid-core/src/veilid_api/tests/mod.rs @@ -1 +1,2 @@ +pub mod test_serialize_json; pub mod test_serialize_rkyv; diff --git a/veilid-core/src/veilid_api/tests/test_serialize_json.rs b/veilid-core/src/veilid_api/tests/test_serialize_json.rs new file mode 100644 index 00000000..bd5a3c36 --- /dev/null +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -0,0 +1,3 @@ +pub async fn test_all() { + // test_simple_string().await; +} diff --git a/veilid-core/tests/web.rs b/veilid-core/tests/web.rs index ec4e1b31..2f88f780 100644 --- a/veilid-core/tests/web.rs +++ b/veilid-core/tests/web.rs @@ -90,6 +90,12 @@ async fn wasm_test_envelope_receipt() { test_envelope_receipt::test_all().await; } +#[wasm_bindgen_test] +async fn wasm_test_serialize_json() { + setup(); + test_serialize_json::test_all().await; +} + #[wasm_bindgen_test] async fn wasm_test_serialize_rkyv() { setup(); From c01566cc697cec14470a978077d685827cb1bda8 Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 25 May 2023 17:15:14 -0700 Subject: [PATCH 04/18] Round-trip de/ser for PeerInfo --- .../src/veilid_api/tests/test_serialize_json.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 bd5a3c36..1bc0368d 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -1,3 +1,15 @@ -pub async fn test_all() { - // test_simple_string().await; +use crate::*; + +const SERIALIZED_PEERINFO: &str = r###"{"node_ids":["VLD0:grOBXsrkgw4aBbmz6cFSUFkDan2_OFOwk6j-SayrQtA"],"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":[]}}}"###; + +pub async fn test_round_trip_peerinfo() { + let pi: routing_table::PeerInfo = deserialize_json(SERIALIZED_PEERINFO).unwrap(); + + let back = serialize_json(pi); + + assert_eq!(SERIALIZED_PEERINFO, back); +} + +pub async fn test_all() { + test_round_trip_peerinfo().await; } From 367e1600750da1b5cf6a6e574f9c9a24cdf10e86 Mon Sep 17 00:00:00 2001 From: Teknique Date: Fri, 26 May 2023 11:51:20 -0700 Subject: [PATCH 05/18] Better run_test! macro param naming --- veilid-core/src/tests/native/mod.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index c687b1e0..e8b450a3 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -64,26 +64,31 @@ cfg_if! { use paste::paste; macro_rules! run_test { - ($mod:ident, $func:ident) => { + // Nearly all test runner code is cookie cutter, and copy-pasting makes it too easy to make a typo. + + // Pass in a module and test module, and we'll run its `test_all`. + ($parent_module:ident, $test_module:ident) => { paste! { #[test] #[serial] - fn []() { + fn []() { setup(); block_on(async { - $mod::tests::$func::test_all().await; + $parent_module::tests::$test_module::test_all().await; }) } } }; - ($func:ident) => { + + // Pass in a test module name, and we'll run its `test_all`. + ($test_module:ident) => { paste! { #[test] #[serial] - fn []() { + fn []() { setup(); block_on(async { - $func::test_all().await; + $test_module::test_all().await; }) } } From 9daf47d11757fdf63cd4d1181fb031e5f88b80aa Mon Sep 17 00:00:00 2001 From: Teknique Date: Fri, 26 May 2023 14:44:32 -0700 Subject: [PATCH 06/18] Tested AlignedU64 --- veilid-core/src/veilid_api/tests/test_serialize_json.rs | 9 +++++++++ 1 file changed, 9 insertions(+) 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 1bc0368d..4cf44cba 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -10,6 +10,15 @@ pub async fn test_round_trip_peerinfo() { assert_eq!(SERIALIZED_PEERINFO, back); } +pub async fn test_alignedu64() { + let a = AlignedU64::new(0x0123456789abcdef); + + let b = serialize_json(a); + let c = deserialize_json(&b).unwrap(); + + assert_ne!(a, c); +} + pub async fn test_all() { test_round_trip_peerinfo().await; } From f1e12a8ac315c91bb62964bc6a87de33b636edf8 Mon Sep 17 00:00:00 2001 From: Teknique Date: Fri, 26 May 2023 18:29:06 -0700 Subject: [PATCH 07/18] More type testing. --- .../veilid_api/tests/test_serialize_json.rs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) 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 4cf44cba..1f9f28fe 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -11,14 +11,34 @@ pub async fn test_round_trip_peerinfo() { } pub async fn test_alignedu64() { - let a = AlignedU64::new(0x0123456789abcdef); + let orig = AlignedU64::new(0x0123456789abcdef); + let copy = deserialize_json(&serialize_json(orig)).unwrap(); - let b = serialize_json(a); - let c = deserialize_json(&b).unwrap(); + assert_eq!(orig, copy); +} - assert_ne!(a, c); +pub async fn test_fourcc() { + let orig = FourCC::from_str("D34D").unwrap(); + let copy = deserialize_json(&serialize_json(orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_safetyspec() { + let orig = SafetySpec { + preferred_route: Some(CryptoKey::new(*b"thisISaKEYthat's32charsLONGitIS!")), + hop_count: 23, + stability: Stability::default(), + sequencing: Sequencing::default(), + }; + let copy = deserialize_json(&serialize_json(orig)).unwrap(); + + assert_eq!(orig, copy); } pub async fn test_all() { test_round_trip_peerinfo().await; + test_alignedu64().await; + test_fourcc().await; + test_safetyspec().await; } From cdff17dca136750f760110bb8c77229bcab28979 Mon Sep 17 00:00:00 2001 From: Teknique Date: Tue, 30 May 2023 10:23:48 -0700 Subject: [PATCH 08/18] Snapshot --- veilid-core/tests/web.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/veilid-core/tests/web.rs b/veilid-core/tests/web.rs index 2f88f780..65b3e291 100644 --- a/veilid-core/tests/web.rs +++ b/veilid-core/tests/web.rs @@ -103,9 +103,7 @@ async fn wasm_test_serialize_rkyv() { } #[wasm_bindgen_test] -async fn wasm_test_routing_table_serialize() { +async fn wasm_test_serialize_routing_table() { setup(); - test_routing_table_serialize::test_all().await; - setup(); - test_serialize::test_all().await; + test_serialize_routing_table::test_all().await; } From e2b8c4488eeb0800aaeeb4f8194ca97e5a18d6b5 Mon Sep 17 00:00:00 2001 From: Teknique Date: Wed, 31 May 2023 13:34:53 -0700 Subject: [PATCH 09/18] Fix routing_table test imports --- veilid-core/src/tests/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/veilid-core/src/tests/mod.rs b/veilid-core/src/tests/mod.rs index 3ef5396d..e82fa3cc 100644 --- a/veilid-core/src/tests/mod.rs +++ b/veilid-core/src/tests/mod.rs @@ -12,6 +12,6 @@ use super::*; pub use common::*; pub use crypto::tests::*; pub use network_manager::tests::*; -pub use routing_table::tests::test_serialize as test_routing_table_serialize; +pub use routing_table::tests::*; pub use table_store::tests::*; pub use veilid_api::tests::*; From 4b14bbb4f4b6480575f1e258abf9e5ae98ab43a0 Mon Sep 17 00:00:00 2001 From: Teknique Date: Wed, 31 May 2023 15:49:21 -0700 Subject: [PATCH 10/18] Add stats JSON serde tests --- .../veilid_api/tests/test_serialize_json.rs | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) 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 1f9f28fe..8e3a9109 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -36,9 +36,111 @@ pub async fn test_safetyspec() { assert_eq!(orig, copy); } +pub async fn test_latencystats() { + let orig = LatencyStats { + fastest: AlignedU64::from(1234), + average: AlignedU64::from(2345), + slowest: AlignedU64::from(3456), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_transferstats() { + let orig = TransferStats { + total: AlignedU64::from(1_000_000), + maximum: AlignedU64::from(3456), + average: AlignedU64::from(2345), + minimum: AlignedU64::from(1234), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_transferstatsdownup() { + let orig = TransferStatsDownUp { + down: TransferStats { + total: AlignedU64::from(1_000_000), + maximum: AlignedU64::from(3456), + average: AlignedU64::from(2345), + minimum: AlignedU64::from(1234), + }, + up: TransferStats { + total: AlignedU64::from(1_000_000 * 2), + maximum: AlignedU64::from(3456 * 2), + average: AlignedU64::from(2345 * 2), + minimum: AlignedU64::from(1234 * 2), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_rpcstats() { + let orig = RPCStats { + messages_sent: 1_000_000, + messages_rcvd: 2_000_000, + questions_in_flight: 42, + last_question_ts: Some(AlignedU64::from(1685569084280)), + last_seen_ts: Some(AlignedU64::from(1685569101256)), + first_consecutive_seen_ts: Some(AlignedU64::from(1685569111851)), + recent_lost_answers: 5, + failed_to_send: 3, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_peerstats() { + let orig = PeerStats { + time_added: AlignedU64::from(1685569176894), + rpc_stats: RPCStats { + messages_sent: 1_000_000, + messages_rcvd: 2_000_000, + questions_in_flight: 42, + last_question_ts: Some(AlignedU64::from(1685569084280)), + last_seen_ts: Some(AlignedU64::from(1685569101256)), + first_consecutive_seen_ts: Some(AlignedU64::from(1685569111851)), + recent_lost_answers: 5, + failed_to_send: 3, + }, + latency: Some(LatencyStats { + fastest: AlignedU64::from(1234), + average: AlignedU64::from(2345), + slowest: AlignedU64::from(3456), + }), + transfer: TransferStatsDownUp { + down: TransferStats { + total: AlignedU64::from(1_000_000), + maximum: AlignedU64::from(3456), + average: AlignedU64::from(2345), + minimum: AlignedU64::from(1234), + }, + up: TransferStats { + total: AlignedU64::from(1_000_000 * 2), + maximum: AlignedU64::from(3456 * 2), + average: AlignedU64::from(2345 * 2), + minimum: AlignedU64::from(1234 * 2), + }, + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + pub async fn test_all() { test_round_trip_peerinfo().await; test_alignedu64().await; test_fourcc().await; test_safetyspec().await; + test_latencystats().await; + test_transferstats().await; + test_transferstatsdownup().await; + test_rpcstats().await; + test_peerstats().await; } From 04c52a4ddb26ac2b27352446376d793c01c15f94 Mon Sep 17 00:00:00 2001 From: Teknique Date: Wed, 31 May 2023 16:16:57 -0700 Subject: [PATCH 11/18] Added tunnel.rs tests. --- .../veilid_api/tests/test_serialize_json.rs | 61 +++++++++++++++++++ veilid-core/src/veilid_api/types/tunnel.rs | 26 +++++++- 2 files changed, 84 insertions(+), 3 deletions(-) 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 8e3a9109..d2829df6 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -133,6 +133,61 @@ pub async fn test_peerstats() { assert_eq!(orig, copy); } +pub async fn test_tunnelmode() { + let orig = TunnelMode::Raw; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} +pub async fn test_tunnelerror() { + let orig = TunnelError::NoCapacity; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_tunnelendpoint() { + let orig = TunnelEndpoint { + mode: TunnelMode::Raw, + description: "Here there be tygers.".to_string(), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_fulltunnel() { + let orig = FullTunnel { + id: AlignedU64::from(42), + timeout: AlignedU64::from(3_000_000), + local: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "Left end.".to_string(), + }, + remote: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "Right end.".to_string(), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_partialtunnel() { + let orig = PartialTunnel { + id: AlignedU64::from(42), + timeout: AlignedU64::from(3_000_000), + local: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "I'm so lonely.".to_string(), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + pub async fn test_all() { test_round_trip_peerinfo().await; test_alignedu64().await; @@ -143,4 +198,10 @@ pub async fn test_all() { test_transferstatsdownup().await; test_rpcstats().await; test_peerstats().await; + test_tunnelmode().await; + test_tunnelmode().await; + test_tunnelerror().await; + test_tunnelendpoint().await; + test_fulltunnel().await; + test_partialtunnel().await; } diff --git a/veilid-core/src/veilid_api/types/tunnel.rs b/veilid-core/src/veilid_api/types/tunnel.rs index 968c7695..bdea8a1c 100644 --- a/veilid-core/src/veilid_api/types/tunnel.rs +++ b/veilid-core/src/veilid_api/types/tunnel.rs @@ -45,7 +45,9 @@ pub enum TunnelError { NoCapacity, // Endpoint is full } -#[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 TunnelEndpoint { pub mode: TunnelMode, @@ -62,7 +64,16 @@ impl Default for TunnelEndpoint { } #[derive( - Clone, Debug, Default, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, + Clone, + Debug, + Default, + PartialEq, + Eq, + Serialize, + Deserialize, + RkyvArchive, + RkyvSerialize, + RkyvDeserialize, )] #[archive_attr(repr(C), derive(CheckBytes))] pub struct FullTunnel { @@ -73,7 +84,16 @@ pub struct FullTunnel { } #[derive( - Clone, Debug, Default, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, + Clone, + Debug, + Default, + PartialEq, + Eq, + Serialize, + Deserialize, + RkyvArchive, + RkyvSerialize, + RkyvDeserialize, )] #[archive_attr(repr(C), derive(CheckBytes))] pub struct PartialTunnel { From febd5fe2dd02f294514262dc5c019736ad90b3d4 Mon Sep 17 00:00:00 2001 From: Teknique Date: Wed, 31 May 2023 16:26:28 -0700 Subject: [PATCH 12/18] Added veilid_log tests. --- .../src/veilid_api/tests/test_serialize_json.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 d2829df6..edd34f5b 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -187,7 +187,22 @@ pub async fn test_partialtunnel() { assert_eq!(orig, copy); } +pub async fn test_veilidloglevel() { + let orig = VeilidLogLevel::Info; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + assert_eq!(orig, copy); +} +pub async fn test_veilidlog() { + let orig = VeilidLog { + log_level: VeilidLogLevel::Debug, + message: "A log! A log!".to_string(), + backtrace: Some("Func1 -> Func2 -> Func3".to_string()), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} pub async fn test_all() { test_round_trip_peerinfo().await; test_alignedu64().await; @@ -204,4 +219,6 @@ pub async fn test_all() { test_tunnelendpoint().await; test_fulltunnel().await; test_partialtunnel().await; + test_veilidloglevel().await; + test_veilidlog().await; } From 075da7fe4981f6c2cb86b2adb1679f806b058aa2 Mon Sep 17 00:00:00 2001 From: Teknique Date: Wed, 31 May 2023 18:12:57 -0700 Subject: [PATCH 13/18] Refactoring snapshot --- .../veilid_api/tests/test_serialize_json.rs | 159 +++++++++++------- 1 file changed, 102 insertions(+), 57 deletions(-) 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 edd34f5b..0352270c 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,8 @@ use crate::*; -const SERIALIZED_PEERINFO: &str = r###"{"node_ids":["VLD0:grOBXsrkgw4aBbmz6cFSUFkDan2_OFOwk6j-SayrQtA"],"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":[]}}}"###; +// Fixtures + +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":[]}}}"###; pub async fn test_round_trip_peerinfo() { let pi: routing_table::PeerInfo = deserialize_json(SERIALIZED_PEERINFO).unwrap(); @@ -26,7 +28,7 @@ pub async fn test_fourcc() { pub async fn test_safetyspec() { let orig = SafetySpec { - preferred_route: Some(CryptoKey::new(*b"thisISaKEYthat's32charsLONGitIS!")), + preferred_route: Some(fix_typedkey().value), hop_count: 23, stability: Stability::default(), sequencing: Sequencing::default(), @@ -36,51 +38,53 @@ pub async fn test_safetyspec() { assert_eq!(orig, copy); } -pub async fn test_latencystats() { - let orig = LatencyStats { +fn fix_latencystats() -> LatencyStats { + LatencyStats { fastest: AlignedU64::from(1234), average: AlignedU64::from(2345), slowest: AlignedU64::from(3456), - }; + } +} + +pub async fn test_latencystats() { + let orig = fix_latencystats(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); } -pub async fn test_transferstats() { - let orig = TransferStats { +fn fix_transferstats() -> TransferStats { + TransferStats { total: AlignedU64::from(1_000_000), maximum: AlignedU64::from(3456), average: AlignedU64::from(2345), minimum: AlignedU64::from(1234), - }; + } +} + +pub async fn test_transferstats() { + let orig = fix_transferstats(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); } +fn fix_transferstatsdownup() -> TransferStatsDownUp { + TransferStatsDownUp { + down: fix_transferstats(), + up: fix_transferstats(), + } +} + pub async fn test_transferstatsdownup() { - let orig = TransferStatsDownUp { - down: TransferStats { - total: AlignedU64::from(1_000_000), - maximum: AlignedU64::from(3456), - average: AlignedU64::from(2345), - minimum: AlignedU64::from(1234), - }, - up: TransferStats { - total: AlignedU64::from(1_000_000 * 2), - maximum: AlignedU64::from(3456 * 2), - average: AlignedU64::from(2345 * 2), - minimum: AlignedU64::from(1234 * 2), - }, - }; + let orig = fix_transferstatsdownup(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); } -pub async fn test_rpcstats() { - let orig = RPCStats { +fn fix_rpcstats() -> RPCStats { + RPCStats { messages_sent: 1_000_000, messages_rcvd: 2_000_000, questions_in_flight: 42, @@ -89,45 +93,27 @@ pub async fn test_rpcstats() { first_consecutive_seen_ts: Some(AlignedU64::from(1685569111851)), recent_lost_answers: 5, failed_to_send: 3, - }; + } +} + +pub async fn test_rpcstats() { + let orig = fix_rpcstats(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); } -pub async fn test_peerstats() { - let orig = PeerStats { +fn fix_peerstats() -> PeerStats { + PeerStats { time_added: AlignedU64::from(1685569176894), - rpc_stats: RPCStats { - messages_sent: 1_000_000, - messages_rcvd: 2_000_000, - questions_in_flight: 42, - last_question_ts: Some(AlignedU64::from(1685569084280)), - last_seen_ts: Some(AlignedU64::from(1685569101256)), - first_consecutive_seen_ts: Some(AlignedU64::from(1685569111851)), - recent_lost_answers: 5, - failed_to_send: 3, - }, - latency: Some(LatencyStats { - fastest: AlignedU64::from(1234), - average: AlignedU64::from(2345), - slowest: AlignedU64::from(3456), - }), - transfer: TransferStatsDownUp { - down: TransferStats { - total: AlignedU64::from(1_000_000), - maximum: AlignedU64::from(3456), - average: AlignedU64::from(2345), - minimum: AlignedU64::from(1234), - }, - up: TransferStats { - total: AlignedU64::from(1_000_000 * 2), - maximum: AlignedU64::from(3456 * 2), - average: AlignedU64::from(2345 * 2), - minimum: AlignedU64::from(1234 * 2), - }, - }, - }; + rpc_stats: fix_rpcstats(), + latency: Some(fix_latencystats()), + transfer: fix_transferstatsdownup(), + } +} + +pub async fn test_peerstats() { + let orig = fix_peerstats(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); @@ -203,6 +189,62 @@ pub async fn test_veilidlog() { assert_eq!(orig, copy); } +pub async fn test_attachmentstate() { + let orig = AttachmentState::FullyAttached; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidstateattachment() { + let orig = VeilidStateAttachment { + state: AttachmentState::OverAttached, + public_internet_ready: true, + local_network_ready: false, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +fn fix_typedkey() -> TypedKey { + let mut fake_key = [0u8; CRYPTO_KEY_LENGTH]; + random_bytes(&mut fake_key); + let b = TypedKey { + kind: FourCC::from_str("FAKE").unwrap(), + value: CryptoKey::new(fake_key), + }; + b + //panic!("{}", b); +} + +fn fix_peertabledata() -> PeerTableData { + PeerTableData { + node_ids: vec![fix_typedkey()], + peer_address: "123 Main St.".to_string(), + peer_stats: fix_peerstats(), + } +} + +pub async fn test_peertabledata() { + let orig = fix_peertabledata(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidstatenetwork() { + let orig = VeilidStateNetwork { + started: true, + bps_down: AlignedU64::from(14_400), + bps_up: AlignedU64::from(1200), + peers: vec![fix_peertabledata()], + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + pub async fn test_all() { test_round_trip_peerinfo().await; test_alignedu64().await; @@ -221,4 +263,7 @@ pub async fn test_all() { test_partialtunnel().await; test_veilidloglevel().await; test_veilidlog().await; + test_attachmentstate().await; + test_veilidstateattachment().await; + test_peertabledata().await; } From c25029b10fdec031f53c86ce00d2892844df0b7b Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 1 Jun 2023 13:04:51 -0700 Subject: [PATCH 14/18] Added veilid_state tests. --- .../veilid_api/tests/test_serialize_json.rs | 226 +++++++++++++++++- .../src/veilid_api/types/dht/value_data.rs | 6 +- .../src/veilid_api/types/veilid_state.rs | 16 +- 3 files changed, 233 insertions(+), 15 deletions(-) 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 0352270c..ee7f5383 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -28,7 +28,7 @@ pub async fn test_fourcc() { pub async fn test_safetyspec() { let orig = SafetySpec { - preferred_route: Some(fix_typedkey().value), + preferred_route: Some(fix_cryptokey()), hop_count: 23, stability: Stability::default(), sequencing: Sequencing::default(), @@ -207,15 +207,19 @@ pub async fn test_veilidstateattachment() { assert_eq!(orig, copy); } +fn fix_cryptokey() -> CryptoKey { + let mut fake_key = [0u8; CRYPTO_KEY_LENGTH]; + random_bytes(&mut fake_key); + CryptoKey::new(fake_key) +} + fn fix_typedkey() -> TypedKey { let mut fake_key = [0u8; CRYPTO_KEY_LENGTH]; random_bytes(&mut fake_key); - let b = TypedKey { + TypedKey { kind: FourCC::from_str("FAKE").unwrap(), - value: CryptoKey::new(fake_key), - }; - b - //panic!("{}", b); + value: fix_cryptokey(), + } } fn fix_peertabledata() -> PeerTableData { @@ -245,6 +249,210 @@ pub async fn test_veilidstatenetwork() { assert_eq!(orig, copy); } +pub async fn test_veilidroutechange() { + let orig = VeilidRouteChange { + dead_routes: vec![fix_cryptokey()], + dead_remote_routes: vec![fix_cryptokey()], + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +fn fix_veilidconfiginner() -> VeilidConfigInner { + VeilidConfigInner { + program_name: "Bob".to_string(), + namespace: "Internets".to_string(), + capabilities: VeilidConfigCapabilities { + protocol_udp: false, + protocol_connect_tcp: true, + protocol_accept_tcp: false, + protocol_connect_ws: true, + protocol_accept_ws: false, + protocol_connect_wss: true, + protocol_accept_wss: false, + }, + protected_store: VeilidConfigProtectedStore { + allow_insecure_fallback: true, + always_use_insecure_storage: false, + directory: "/root".to_string(), + delete: true, + device_encryption_key_password: "1234".to_string(), + new_device_encryption_key_password: Some("5678".to_string()), + }, + table_store: VeilidConfigTableStore { + directory: "Yellow Pages".to_string(), + delete: false, + }, + block_store: VeilidConfigBlockStore { + directory: "C:\\Program Files".to_string(), + delete: true, + }, + network: VeilidConfigNetwork { + connection_initial_timeout_ms: 1000, + connection_inactivity_timeout_ms: 2000, + max_connections_per_ip4: 3000, + max_connections_per_ip6_prefix: 4000, + max_connections_per_ip6_prefix_size: 5000, + max_connection_frequency_per_min: 6000, + client_whitelist_timeout_ms: 7000, + reverse_connection_receipt_time_ms: 8000, + hole_punch_receipt_time_ms: 9000, + routing_table: VeilidConfigRoutingTable { + node_id: TypedKeySet::new(), + node_id_secret: TypedSecretSet::new(), + bootstrap: vec!["boots".to_string()], + limit_over_attached: 1, + limit_fully_attached: 2, + limit_attached_strong: 3, + limit_attached_good: 4, + limit_attached_weak: 5, + }, + rpc: VeilidConfigRPC { + concurrency: 5, + queue_size: 6, + max_timestamp_behind_ms: Some(1000), + max_timestamp_ahead_ms: Some(2000), + timeout_ms: 3000, + max_route_hop_count: 7, + default_route_hop_count: 8, + }, + dht: VeilidConfigDHT { + max_find_node_count: 1, + resolve_node_timeout_ms: 2, + resolve_node_count: 3, + resolve_node_fanout: 4, + get_value_timeout_ms: 5, + get_value_count: 6, + get_value_fanout: 7, + set_value_timeout_ms: 8, + set_value_count: 9, + set_value_fanout: 10, + min_peer_count: 11, + min_peer_refresh_time_ms: 12, + validate_dial_info_receipt_time_ms: 13, + local_subkey_cache_size: 14, + local_max_subkey_cache_memory_mb: 15, + remote_subkey_cache_size: 16, + remote_max_records: 17, + remote_max_subkey_cache_memory_mb: 18, + remote_max_storage_space_mb: 19, + }, + upnp: true, + detect_address_changes: false, + restricted_nat_retries: 10000, + tls: VeilidConfigTLS { + certificate_path: "/etc/ssl/certs/cert.pem".to_string(), + private_key_path: "/etc/ssl/keys/key.pem".to_string(), + connection_initial_timeout_ms: 1000, + }, + application: VeilidConfigApplication { + https: VeilidConfigHTTPS { + enabled: true, + listen_address: "10.0.0.3".to_string(), + path: "/https_path/".to_string(), + url: Some("https://veilid.com/".to_string()), + }, + http: VeilidConfigHTTP { + enabled: true, + listen_address: "10.0.0.4".to_string(), + path: "/http_path/".to_string(), + url: Some("http://veilid.com/".to_string()), + }, + }, + protocol: VeilidConfigProtocol { + udp: VeilidConfigUDP { + enabled: false, + socket_pool_size: 30, + listen_address: "10.0.0.2".to_string(), + public_address: Some("2.3.4.5".to_string()), + }, + tcp: VeilidConfigTCP { + connect: true, + listen: false, + max_connections: 8, + listen_address: "10.0.0.1".to_string(), + public_address: Some("1.2.3.4".to_string()), + }, + ws: VeilidConfigWS { + connect: false, + listen: true, + max_connections: 9, + listen_address: "127.0.0.1".to_string(), + path: "Straight".to_string(), + url: Some("https://veilid.com/ws".to_string()), + }, + wss: VeilidConfigWSS { + connect: true, + listen: false, + max_connections: 10, + listen_address: "::1".to_string(), + path: "Curved".to_string(), + url: Some("https://veilid.com/wss".to_string()), + }, + }, + }, + } +} + +pub async fn test_veilidstateconfig() { + let orig = VeilidStateConfig { + config: fix_veilidconfiginner(), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +fn fix_veilidvaluechange() -> 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(), + }, + } +} + +pub async fn test_veilidvaluechange() { + let orig = fix_veilidvaluechange(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidupdate() { + let orig = VeilidUpdate::ValueChange(fix_veilidvaluechange()); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidstate() { + let orig = VeilidState { + attachment: VeilidStateAttachment { + state: AttachmentState::OverAttached, + public_internet_ready: true, + local_network_ready: false, + }, + network: VeilidStateNetwork { + started: true, + bps_down: AlignedU64::from(14_400), + bps_up: AlignedU64::from(1200), + peers: vec![fix_peertabledata()], + }, + config: VeilidStateConfig { + config: fix_veilidconfiginner(), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + pub async fn test_all() { test_round_trip_peerinfo().await; test_alignedu64().await; @@ -266,4 +474,10 @@ pub async fn test_all() { test_attachmentstate().await; test_veilidstateattachment().await; test_peertabledata().await; + test_veilidstatenetwork().await; + test_veilidroutechange().await; + test_veilidstateconfig().await; + test_veilidvaluechange().await; + test_veilidupdate().await; + test_veilidstate().await; } diff --git a/veilid-core/src/veilid_api/types/dht/value_data.rs b/veilid-core/src/veilid_api/types/dht/value_data.rs index 734e735d..5ac50649 100644 --- a/veilid-core/src/veilid_api/types/dht/value_data.rs +++ b/veilid-core/src/veilid_api/types/dht/value_data.rs @@ -16,9 +16,9 @@ use super::*; )] #[archive_attr(repr(C), derive(CheckBytes))] pub struct ValueData { - seq: ValueSeqNum, - data: Vec, - writer: PublicKey, + pub seq: ValueSeqNum, + pub data: Vec, + pub writer: PublicKey, } impl ValueData { pub const MAX_LEN: usize = 32768; diff --git a/veilid-core/src/veilid_api/types/veilid_state.rs b/veilid-core/src/veilid_api/types/veilid_state.rs index 09f21a24..ca583953 100644 --- a/veilid-core/src/veilid_api/types/veilid_state.rs +++ b/veilid-core/src/veilid_api/types/veilid_state.rs @@ -114,13 +114,15 @@ pub struct VeilidStateConfig { )] #[archive_attr(repr(C), derive(CheckBytes))] pub struct VeilidValueChange { - key: TypedKey, - subkeys: Vec, - count: u32, - value: ValueData, + pub key: TypedKey, + pub subkeys: Vec, + pub count: u32, + pub value: ValueData, } -#[derive(Debug, Clone, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)] +#[derive( + Debug, Clone, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, +)] #[archive_attr(repr(u8), derive(CheckBytes))] #[serde(tag = "kind")] pub enum VeilidUpdate { @@ -135,7 +137,9 @@ pub enum VeilidUpdate { Shutdown, } -#[derive(Debug, Clone, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)] +#[derive( + Debug, Clone, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, +)] #[archive_attr(repr(C), derive(CheckBytes))] pub struct VeilidState { pub attachment: VeilidStateAttachment, From ded3f22870d9e40fd093991fe7b79b29309026b3 Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 1 Jun 2023 13:38:35 -0700 Subject: [PATCH 15/18] Factor out fixtures; add path to things tested --- veilid-core/src/veilid_api/tests/fixtures.rs | 223 ++++++++++++++++ veilid-core/src/veilid_api/tests/mod.rs | 1 + .../veilid_api/tests/test_serialize_json.rs | 238 ++---------------- 3 files changed, 242 insertions(+), 220 deletions(-) create mode 100644 veilid-core/src/veilid_api/tests/fixtures.rs diff --git a/veilid-core/src/veilid_api/tests/fixtures.rs b/veilid-core/src/veilid_api/tests/fixtures.rs new file mode 100644 index 00000000..17124fd5 --- /dev/null +++ b/veilid-core/src/veilid_api/tests/fixtures.rs @@ -0,0 +1,223 @@ +use crate::*; + +// Fixtures used by various tests + +pub 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":[]}}}"###; + +pub fn fix_latencystats() -> LatencyStats { + LatencyStats { + fastest: AlignedU64::from(1234), + average: AlignedU64::from(2345), + slowest: AlignedU64::from(3456), + } +} + +pub fn fix_transferstats() -> TransferStats { + TransferStats { + total: AlignedU64::from(1_000_000), + maximum: AlignedU64::from(3456), + average: AlignedU64::from(2345), + minimum: AlignedU64::from(1234), + } +} + +pub fn fix_transferstatsdownup() -> TransferStatsDownUp { + TransferStatsDownUp { + down: fix_transferstats(), + up: fix_transferstats(), + } +} + +pub fn fix_rpcstats() -> RPCStats { + RPCStats { + messages_sent: 1_000_000, + messages_rcvd: 2_000_000, + questions_in_flight: 42, + last_question_ts: Some(AlignedU64::from(1685569084280)), + last_seen_ts: Some(AlignedU64::from(1685569101256)), + first_consecutive_seen_ts: Some(AlignedU64::from(1685569111851)), + recent_lost_answers: 5, + failed_to_send: 3, + } +} + +pub fn fix_peerstats() -> PeerStats { + PeerStats { + time_added: AlignedU64::from(1685569176894), + rpc_stats: fix_rpcstats(), + latency: Some(fix_latencystats()), + transfer: fix_transferstatsdownup(), + } +} + +pub fn fix_cryptokey() -> CryptoKey { + let mut fake_key = [0u8; CRYPTO_KEY_LENGTH]; + random_bytes(&mut fake_key); + CryptoKey::new(fake_key) +} + +pub fn fix_typedkey() -> TypedKey { + let mut fake_key = [0u8; CRYPTO_KEY_LENGTH]; + random_bytes(&mut fake_key); + TypedKey { + kind: FourCC::from_str("FAKE").unwrap(), + value: fix_cryptokey(), + } +} + +pub fn fix_peertabledata() -> PeerTableData { + PeerTableData { + node_ids: vec![fix_typedkey()], + peer_address: "123 Main St.".to_string(), + peer_stats: fix_peerstats(), + } +} + +pub fn fix_veilidconfiginner() -> VeilidConfigInner { + VeilidConfigInner { + program_name: "Bob".to_string(), + namespace: "Internets".to_string(), + capabilities: VeilidConfigCapabilities { + protocol_udp: false, + protocol_connect_tcp: true, + protocol_accept_tcp: false, + protocol_connect_ws: true, + protocol_accept_ws: false, + protocol_connect_wss: true, + protocol_accept_wss: false, + }, + protected_store: VeilidConfigProtectedStore { + allow_insecure_fallback: true, + always_use_insecure_storage: false, + directory: "/root".to_string(), + delete: true, + device_encryption_key_password: "1234".to_string(), + new_device_encryption_key_password: Some("5678".to_string()), + }, + table_store: VeilidConfigTableStore { + directory: "Yellow Pages".to_string(), + delete: false, + }, + block_store: VeilidConfigBlockStore { + directory: "C:\\Program Files".to_string(), + delete: true, + }, + network: VeilidConfigNetwork { + connection_initial_timeout_ms: 1000, + connection_inactivity_timeout_ms: 2000, + max_connections_per_ip4: 3000, + max_connections_per_ip6_prefix: 4000, + max_connections_per_ip6_prefix_size: 5000, + max_connection_frequency_per_min: 6000, + client_whitelist_timeout_ms: 7000, + reverse_connection_receipt_time_ms: 8000, + hole_punch_receipt_time_ms: 9000, + routing_table: VeilidConfigRoutingTable { + node_id: TypedKeySet::new(), + node_id_secret: TypedSecretSet::new(), + bootstrap: vec!["boots".to_string()], + limit_over_attached: 1, + limit_fully_attached: 2, + limit_attached_strong: 3, + limit_attached_good: 4, + limit_attached_weak: 5, + }, + rpc: VeilidConfigRPC { + concurrency: 5, + queue_size: 6, + max_timestamp_behind_ms: Some(1000), + max_timestamp_ahead_ms: Some(2000), + timeout_ms: 3000, + max_route_hop_count: 7, + default_route_hop_count: 8, + }, + dht: VeilidConfigDHT { + max_find_node_count: 1, + resolve_node_timeout_ms: 2, + resolve_node_count: 3, + resolve_node_fanout: 4, + get_value_timeout_ms: 5, + get_value_count: 6, + get_value_fanout: 7, + set_value_timeout_ms: 8, + set_value_count: 9, + set_value_fanout: 10, + min_peer_count: 11, + min_peer_refresh_time_ms: 12, + validate_dial_info_receipt_time_ms: 13, + local_subkey_cache_size: 14, + local_max_subkey_cache_memory_mb: 15, + remote_subkey_cache_size: 16, + remote_max_records: 17, + remote_max_subkey_cache_memory_mb: 18, + remote_max_storage_space_mb: 19, + }, + upnp: true, + detect_address_changes: false, + restricted_nat_retries: 10000, + tls: VeilidConfigTLS { + certificate_path: "/etc/ssl/certs/cert.pem".to_string(), + private_key_path: "/etc/ssl/keys/key.pem".to_string(), + connection_initial_timeout_ms: 1000, + }, + application: VeilidConfigApplication { + https: VeilidConfigHTTPS { + enabled: true, + listen_address: "10.0.0.3".to_string(), + path: "/https_path/".to_string(), + url: Some("https://veilid.com/".to_string()), + }, + http: VeilidConfigHTTP { + enabled: true, + listen_address: "10.0.0.4".to_string(), + path: "/http_path/".to_string(), + url: Some("http://veilid.com/".to_string()), + }, + }, + protocol: VeilidConfigProtocol { + udp: VeilidConfigUDP { + enabled: false, + socket_pool_size: 30, + listen_address: "10.0.0.2".to_string(), + public_address: Some("2.3.4.5".to_string()), + }, + tcp: VeilidConfigTCP { + connect: true, + listen: false, + max_connections: 8, + listen_address: "10.0.0.1".to_string(), + public_address: Some("1.2.3.4".to_string()), + }, + ws: VeilidConfigWS { + connect: false, + listen: true, + max_connections: 9, + listen_address: "127.0.0.1".to_string(), + path: "Straight".to_string(), + url: Some("https://veilid.com/ws".to_string()), + }, + wss: VeilidConfigWSS { + connect: true, + listen: false, + max_connections: 10, + listen_address: "::1".to_string(), + path: "Curved".to_string(), + url: Some("https://veilid.com/wss".to_string()), + }, + }, + }, + } +} + +pub fn fix_veilidvaluechange() -> 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(), + }, + } +} diff --git a/veilid-core/src/veilid_api/tests/mod.rs b/veilid-core/src/veilid_api/tests/mod.rs index 2d85d773..87a9c6bb 100644 --- a/veilid-core/src/veilid_api/tests/mod.rs +++ b/veilid-core/src/veilid_api/tests/mod.rs @@ -1,2 +1,3 @@ +mod fixtures; pub mod test_serialize_json; pub mod test_serialize_rkyv; 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 ee7f5383..4afa633a 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -1,8 +1,7 @@ +use super::fixtures::*; use crate::*; -// Fixtures - -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":[]}}}"###; +// routing_table/types/peer_info.rs pub async fn test_round_trip_peerinfo() { let pi: routing_table::PeerInfo = deserialize_json(SERIALIZED_PEERINFO).unwrap(); @@ -12,6 +11,8 @@ pub async fn test_round_trip_peerinfo() { assert_eq!(SERIALIZED_PEERINFO, back); } +// veilid_api/types/aligned_u64.rs + pub async fn test_alignedu64() { let orig = AlignedU64::new(0x0123456789abcdef); let copy = deserialize_json(&serialize_json(orig)).unwrap(); @@ -19,6 +20,8 @@ pub async fn test_alignedu64() { assert_eq!(orig, copy); } +// veilid_api/types/fourcc.rs + pub async fn test_fourcc() { let orig = FourCC::from_str("D34D").unwrap(); let copy = deserialize_json(&serialize_json(orig)).unwrap(); @@ -26,6 +29,8 @@ pub async fn test_fourcc() { assert_eq!(orig, copy); } +// veilid_api/types/safety.rs + pub async fn test_safetyspec() { let orig = SafetySpec { preferred_route: Some(fix_cryptokey()), @@ -38,13 +43,7 @@ pub async fn test_safetyspec() { assert_eq!(orig, copy); } -fn fix_latencystats() -> LatencyStats { - LatencyStats { - fastest: AlignedU64::from(1234), - average: AlignedU64::from(2345), - slowest: AlignedU64::from(3456), - } -} +// veilid_api/types/stats.rs pub async fn test_latencystats() { let orig = fix_latencystats(); @@ -53,15 +52,6 @@ pub async fn test_latencystats() { assert_eq!(orig, copy); } -fn fix_transferstats() -> TransferStats { - TransferStats { - total: AlignedU64::from(1_000_000), - maximum: AlignedU64::from(3456), - average: AlignedU64::from(2345), - minimum: AlignedU64::from(1234), - } -} - pub async fn test_transferstats() { let orig = fix_transferstats(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -69,13 +59,6 @@ pub async fn test_transferstats() { assert_eq!(orig, copy); } -fn fix_transferstatsdownup() -> TransferStatsDownUp { - TransferStatsDownUp { - down: fix_transferstats(), - up: fix_transferstats(), - } -} - pub async fn test_transferstatsdownup() { let orig = fix_transferstatsdownup(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -83,19 +66,6 @@ pub async fn test_transferstatsdownup() { assert_eq!(orig, copy); } -fn fix_rpcstats() -> RPCStats { - RPCStats { - messages_sent: 1_000_000, - messages_rcvd: 2_000_000, - questions_in_flight: 42, - last_question_ts: Some(AlignedU64::from(1685569084280)), - last_seen_ts: Some(AlignedU64::from(1685569101256)), - first_consecutive_seen_ts: Some(AlignedU64::from(1685569111851)), - recent_lost_answers: 5, - failed_to_send: 3, - } -} - pub async fn test_rpcstats() { let orig = fix_rpcstats(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -103,15 +73,6 @@ pub async fn test_rpcstats() { assert_eq!(orig, copy); } -fn fix_peerstats() -> PeerStats { - PeerStats { - time_added: AlignedU64::from(1685569176894), - rpc_stats: fix_rpcstats(), - latency: Some(fix_latencystats()), - transfer: fix_transferstatsdownup(), - } -} - pub async fn test_peerstats() { let orig = fix_peerstats(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -119,6 +80,8 @@ pub async fn test_peerstats() { assert_eq!(orig, copy); } +// veilid_api/types/tunnel.rs + pub async fn test_tunnelmode() { let orig = TunnelMode::Raw; let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -173,12 +136,16 @@ pub async fn test_partialtunnel() { assert_eq!(orig, copy); } + +// veilid_api/types/veilid_lo.rs + pub async fn test_veilidloglevel() { let orig = VeilidLogLevel::Info; let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); } + pub async fn test_veilidlog() { let orig = VeilidLog { log_level: VeilidLogLevel::Debug, @@ -189,6 +156,9 @@ pub async fn test_veilidlog() { assert_eq!(orig, copy); } + +// veilid_api/types/veilid_state.rs + pub async fn test_attachmentstate() { let orig = AttachmentState::FullyAttached; let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -207,29 +177,6 @@ pub async fn test_veilidstateattachment() { assert_eq!(orig, copy); } -fn fix_cryptokey() -> CryptoKey { - let mut fake_key = [0u8; CRYPTO_KEY_LENGTH]; - random_bytes(&mut fake_key); - CryptoKey::new(fake_key) -} - -fn fix_typedkey() -> TypedKey { - let mut fake_key = [0u8; CRYPTO_KEY_LENGTH]; - random_bytes(&mut fake_key); - TypedKey { - kind: FourCC::from_str("FAKE").unwrap(), - value: fix_cryptokey(), - } -} - -fn fix_peertabledata() -> PeerTableData { - PeerTableData { - node_ids: vec![fix_typedkey()], - peer_address: "123 Main St.".to_string(), - peer_stats: fix_peerstats(), - } -} - pub async fn test_peertabledata() { let orig = fix_peertabledata(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -259,142 +206,6 @@ pub async fn test_veilidroutechange() { assert_eq!(orig, copy); } -fn fix_veilidconfiginner() -> VeilidConfigInner { - VeilidConfigInner { - program_name: "Bob".to_string(), - namespace: "Internets".to_string(), - capabilities: VeilidConfigCapabilities { - protocol_udp: false, - protocol_connect_tcp: true, - protocol_accept_tcp: false, - protocol_connect_ws: true, - protocol_accept_ws: false, - protocol_connect_wss: true, - protocol_accept_wss: false, - }, - protected_store: VeilidConfigProtectedStore { - allow_insecure_fallback: true, - always_use_insecure_storage: false, - directory: "/root".to_string(), - delete: true, - device_encryption_key_password: "1234".to_string(), - new_device_encryption_key_password: Some("5678".to_string()), - }, - table_store: VeilidConfigTableStore { - directory: "Yellow Pages".to_string(), - delete: false, - }, - block_store: VeilidConfigBlockStore { - directory: "C:\\Program Files".to_string(), - delete: true, - }, - network: VeilidConfigNetwork { - connection_initial_timeout_ms: 1000, - connection_inactivity_timeout_ms: 2000, - max_connections_per_ip4: 3000, - max_connections_per_ip6_prefix: 4000, - max_connections_per_ip6_prefix_size: 5000, - max_connection_frequency_per_min: 6000, - client_whitelist_timeout_ms: 7000, - reverse_connection_receipt_time_ms: 8000, - hole_punch_receipt_time_ms: 9000, - routing_table: VeilidConfigRoutingTable { - node_id: TypedKeySet::new(), - node_id_secret: TypedSecretSet::new(), - bootstrap: vec!["boots".to_string()], - limit_over_attached: 1, - limit_fully_attached: 2, - limit_attached_strong: 3, - limit_attached_good: 4, - limit_attached_weak: 5, - }, - rpc: VeilidConfigRPC { - concurrency: 5, - queue_size: 6, - max_timestamp_behind_ms: Some(1000), - max_timestamp_ahead_ms: Some(2000), - timeout_ms: 3000, - max_route_hop_count: 7, - default_route_hop_count: 8, - }, - dht: VeilidConfigDHT { - max_find_node_count: 1, - resolve_node_timeout_ms: 2, - resolve_node_count: 3, - resolve_node_fanout: 4, - get_value_timeout_ms: 5, - get_value_count: 6, - get_value_fanout: 7, - set_value_timeout_ms: 8, - set_value_count: 9, - set_value_fanout: 10, - min_peer_count: 11, - min_peer_refresh_time_ms: 12, - validate_dial_info_receipt_time_ms: 13, - local_subkey_cache_size: 14, - local_max_subkey_cache_memory_mb: 15, - remote_subkey_cache_size: 16, - remote_max_records: 17, - remote_max_subkey_cache_memory_mb: 18, - remote_max_storage_space_mb: 19, - }, - upnp: true, - detect_address_changes: false, - restricted_nat_retries: 10000, - tls: VeilidConfigTLS { - certificate_path: "/etc/ssl/certs/cert.pem".to_string(), - private_key_path: "/etc/ssl/keys/key.pem".to_string(), - connection_initial_timeout_ms: 1000, - }, - application: VeilidConfigApplication { - https: VeilidConfigHTTPS { - enabled: true, - listen_address: "10.0.0.3".to_string(), - path: "/https_path/".to_string(), - url: Some("https://veilid.com/".to_string()), - }, - http: VeilidConfigHTTP { - enabled: true, - listen_address: "10.0.0.4".to_string(), - path: "/http_path/".to_string(), - url: Some("http://veilid.com/".to_string()), - }, - }, - protocol: VeilidConfigProtocol { - udp: VeilidConfigUDP { - enabled: false, - socket_pool_size: 30, - listen_address: "10.0.0.2".to_string(), - public_address: Some("2.3.4.5".to_string()), - }, - tcp: VeilidConfigTCP { - connect: true, - listen: false, - max_connections: 8, - listen_address: "10.0.0.1".to_string(), - public_address: Some("1.2.3.4".to_string()), - }, - ws: VeilidConfigWS { - connect: false, - listen: true, - max_connections: 9, - listen_address: "127.0.0.1".to_string(), - path: "Straight".to_string(), - url: Some("https://veilid.com/ws".to_string()), - }, - wss: VeilidConfigWSS { - connect: true, - listen: false, - max_connections: 10, - listen_address: "::1".to_string(), - path: "Curved".to_string(), - url: Some("https://veilid.com/wss".to_string()), - }, - }, - }, - } -} - pub async fn test_veilidstateconfig() { let orig = VeilidStateConfig { config: fix_veilidconfiginner(), @@ -404,19 +215,6 @@ pub async fn test_veilidstateconfig() { assert_eq!(orig, copy); } -fn fix_veilidvaluechange() -> 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(), - }, - } -} - pub async fn test_veilidvaluechange() { let orig = fix_veilidvaluechange(); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); From b397b5c66b27a070a4871e67ebb948a0853187fb Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 1 Jun 2023 13:57:18 -0700 Subject: [PATCH 16/18] Finish coverage of veilid_api::types --- .../veilid_api/tests/test_serialize_json.rs | 52 ++++++++++++++++++- .../src/veilid_api/types/app_message_call.rs | 10 ++-- 2 files changed, 55 insertions(+), 7 deletions(-) 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 4afa633a..109fc6a6 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -20,6 +20,29 @@ pub async fn test_alignedu64() { assert_eq!(orig, copy); } +// veilid_api/types/app_messsage_call.rs + +pub async fn test_veilidappmessage() { + let orig = VeilidAppMessage { + sender: Some(fix_typedkey()), + message: 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(), + id: AlignedU64::from(123), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + // veilid_api/types/fourcc.rs pub async fn test_fourcc() { @@ -31,6 +54,27 @@ pub async fn test_fourcc() { // veilid_api/types/safety.rs +pub async fn test_sequencing() { + let orig = Sequencing::PreferOrdered; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_stability() { + let orig = Stability::Reliable; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_safetyselection() { + let orig = SafetySelection::Unsafe(Sequencing::EnsureOrdered); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + pub async fn test_safetyspec() { let orig = SafetySpec { preferred_route: Some(fix_cryptokey()), @@ -137,7 +181,7 @@ pub async fn test_partialtunnel() { assert_eq!(orig, copy); } -// veilid_api/types/veilid_lo.rs +// veilid_api/types/veilid_log.rs pub async fn test_veilidloglevel() { let orig = VeilidLogLevel::Info; @@ -254,7 +298,12 @@ pub async fn test_veilidstate() { pub async fn test_all() { test_round_trip_peerinfo().await; test_alignedu64().await; + test_veilidappmessage().await; + test_veilidappcall().await; test_fourcc().await; + test_sequencing().await; + test_stability().await; + test_safetyselection().await; test_safetyspec().await; test_latencystats().await; test_transferstats().await; @@ -262,7 +311,6 @@ pub async fn test_all() { test_rpcstats().await; test_peerstats().await; test_tunnelmode().await; - test_tunnelmode().await; test_tunnelerror().await; test_tunnelendpoint().await; test_fulltunnel().await; diff --git a/veilid-core/src/veilid_api/types/app_message_call.rs b/veilid-core/src/veilid_api/types/app_message_call.rs index 6f0805fe..f2485d46 100644 --- a/veilid-core/src/veilid_api/types/app_message_call.rs +++ b/veilid-core/src/veilid_api/types/app_message_call.rs @@ -8,10 +8,10 @@ use super::*; pub struct VeilidAppMessage { /// Some(sender) if the message was sent directly, None if received via a private/safety route #[serde(with = "opt_json_as_string")] - sender: Option, + pub sender: Option, /// The content of the message to deliver to the application #[serde(with = "json_as_base64")] - message: Vec, + pub message: Vec, } impl VeilidAppMessage { @@ -35,13 +35,13 @@ impl VeilidAppMessage { 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")] - sender: Option, + pub sender: Option, /// The content of the request to deliver to the application #[serde(with = "json_as_base64")] - message: Vec, + pub message: Vec, /// The id to reply to #[serde(with = "json_as_string")] - id: OperationId, + pub id: OperationId, } impl VeilidAppCall { From cb494774904fdd1abf786efdc6bbae6b9d9ac55a Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 1 Jun 2023 14:14:24 -0700 Subject: [PATCH 17/18] Rearrangement for easier scaling of test count --- .../tests/test_serialize_routing_table.rs | 11 + veilid-core/src/veilid_api/tests/fixtures.rs | 2 - veilid-core/src/veilid_api/tests/mod.rs | 1 + .../veilid_api/tests/test_serialize_json.rs | 298 +----------------- .../src/veilid_api/tests/test_types.rs | 286 +++++++++++++++++ 5 files changed, 299 insertions(+), 299 deletions(-) create mode 100644 veilid-core/src/veilid_api/tests/test_types.rs diff --git a/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs b/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs index 14e07930..c8202de2 100644 --- a/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs +++ b/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs @@ -1,5 +1,7 @@ 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":[]}}}"###; + fn fake_routing_table() -> routing_table::RoutingTable { let veilid_config = VeilidConfig::new(); let block_store = BlockStore::new(veilid_config.clone()); @@ -79,6 +81,15 @@ pub async fn test_routingtable_buckets_round_trip() { copy.terminate().await; } +pub async fn test_round_trip_peerinfo() { + let pi: routing_table::PeerInfo = deserialize_json(SERIALIZED_PEERINFO).unwrap(); + + let back = serialize_json(pi); + + assert_eq!(SERIALIZED_PEERINFO, back); +} + pub async fn test_all() { test_routingtable_buckets_round_trip().await; + test_round_trip_peerinfo().await; } diff --git a/veilid-core/src/veilid_api/tests/fixtures.rs b/veilid-core/src/veilid_api/tests/fixtures.rs index 17124fd5..7f86ac22 100644 --- a/veilid-core/src/veilid_api/tests/fixtures.rs +++ b/veilid-core/src/veilid_api/tests/fixtures.rs @@ -2,8 +2,6 @@ use crate::*; // Fixtures used by various tests -pub 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":[]}}}"###; - pub fn fix_latencystats() -> LatencyStats { LatencyStats { fastest: AlignedU64::from(1234), diff --git a/veilid-core/src/veilid_api/tests/mod.rs b/veilid-core/src/veilid_api/tests/mod.rs index 87a9c6bb..ea2ec200 100644 --- a/veilid-core/src/veilid_api/tests/mod.rs +++ b/veilid-core/src/veilid_api/tests/mod.rs @@ -1,3 +1,4 @@ mod fixtures; pub mod test_serialize_json; pub mod test_serialize_rkyv; +mod test_types; 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 109fc6a6..a3521c83 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -1,302 +1,6 @@ -use super::fixtures::*; -use crate::*; - -// routing_table/types/peer_info.rs - -pub async fn test_round_trip_peerinfo() { - let pi: routing_table::PeerInfo = deserialize_json(SERIALIZED_PEERINFO).unwrap(); - - let back = serialize_json(pi); - - assert_eq!(SERIALIZED_PEERINFO, back); -} - -// veilid_api/types/aligned_u64.rs - -pub async fn test_alignedu64() { - let orig = AlignedU64::new(0x0123456789abcdef); - let copy = deserialize_json(&serialize_json(orig)).unwrap(); - - assert_eq!(orig, copy); -} - -// veilid_api/types/app_messsage_call.rs - -pub async fn test_veilidappmessage() { - let orig = VeilidAppMessage { - sender: Some(fix_typedkey()), - message: 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(), - id: AlignedU64::from(123), - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -// veilid_api/types/fourcc.rs - -pub async fn test_fourcc() { - let orig = FourCC::from_str("D34D").unwrap(); - let copy = deserialize_json(&serialize_json(orig)).unwrap(); - - assert_eq!(orig, copy); -} - -// veilid_api/types/safety.rs - -pub async fn test_sequencing() { - let orig = Sequencing::PreferOrdered; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_stability() { - let orig = Stability::Reliable; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_safetyselection() { - let orig = SafetySelection::Unsafe(Sequencing::EnsureOrdered); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_safetyspec() { - let orig = SafetySpec { - preferred_route: Some(fix_cryptokey()), - hop_count: 23, - stability: Stability::default(), - sequencing: Sequencing::default(), - }; - let copy = deserialize_json(&serialize_json(orig)).unwrap(); - - assert_eq!(orig, copy); -} - -// veilid_api/types/stats.rs - -pub async fn test_latencystats() { - let orig = fix_latencystats(); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_transferstats() { - let orig = fix_transferstats(); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_transferstatsdownup() { - let orig = fix_transferstatsdownup(); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_rpcstats() { - let orig = fix_rpcstats(); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_peerstats() { - let orig = fix_peerstats(); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -// veilid_api/types/tunnel.rs - -pub async fn test_tunnelmode() { - let orig = TunnelMode::Raw; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} -pub async fn test_tunnelerror() { - let orig = TunnelError::NoCapacity; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_tunnelendpoint() { - let orig = TunnelEndpoint { - mode: TunnelMode::Raw, - description: "Here there be tygers.".to_string(), - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_fulltunnel() { - let orig = FullTunnel { - id: AlignedU64::from(42), - timeout: AlignedU64::from(3_000_000), - local: TunnelEndpoint { - mode: TunnelMode::Turn, - description: "Left end.".to_string(), - }, - remote: TunnelEndpoint { - mode: TunnelMode::Turn, - description: "Right end.".to_string(), - }, - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_partialtunnel() { - let orig = PartialTunnel { - id: AlignedU64::from(42), - timeout: AlignedU64::from(3_000_000), - local: TunnelEndpoint { - mode: TunnelMode::Turn, - description: "I'm so lonely.".to_string(), - }, - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -// veilid_api/types/veilid_log.rs - -pub async fn test_veilidloglevel() { - let orig = VeilidLogLevel::Info; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_veilidlog() { - let orig = VeilidLog { - log_level: VeilidLogLevel::Debug, - message: "A log! A log!".to_string(), - backtrace: Some("Func1 -> Func2 -> Func3".to_string()), - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -// veilid_api/types/veilid_state.rs - -pub async fn test_attachmentstate() { - let orig = AttachmentState::FullyAttached; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_veilidstateattachment() { - let orig = VeilidStateAttachment { - state: AttachmentState::OverAttached, - public_internet_ready: true, - local_network_ready: false, - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_peertabledata() { - let orig = fix_peertabledata(); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_veilidstatenetwork() { - let orig = VeilidStateNetwork { - started: true, - bps_down: AlignedU64::from(14_400), - bps_up: AlignedU64::from(1200), - peers: vec![fix_peertabledata()], - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_veilidroutechange() { - let orig = VeilidRouteChange { - dead_routes: vec![fix_cryptokey()], - dead_remote_routes: vec![fix_cryptokey()], - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_veilidstateconfig() { - let orig = VeilidStateConfig { - config: fix_veilidconfiginner(), - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_veilidvaluechange() { - let orig = fix_veilidvaluechange(); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_veilidupdate() { - let orig = VeilidUpdate::ValueChange(fix_veilidvaluechange()); - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} - -pub async fn test_veilidstate() { - let orig = VeilidState { - attachment: VeilidStateAttachment { - state: AttachmentState::OverAttached, - public_internet_ready: true, - local_network_ready: false, - }, - network: VeilidStateNetwork { - started: true, - bps_down: AlignedU64::from(14_400), - bps_up: AlignedU64::from(1200), - peers: vec![fix_peertabledata()], - }, - config: VeilidStateConfig { - config: fix_veilidconfiginner(), - }, - }; - let copy = deserialize_json(&serialize_json(&orig)).unwrap(); - - assert_eq!(orig, copy); -} +use super::test_types::*; pub async fn test_all() { - test_round_trip_peerinfo().await; test_alignedu64().await; test_veilidappmessage().await; test_veilidappcall().await; diff --git a/veilid-core/src/veilid_api/tests/test_types.rs b/veilid-core/src/veilid_api/tests/test_types.rs new file mode 100644 index 00000000..739dbd0d --- /dev/null +++ b/veilid-core/src/veilid_api/tests/test_types.rs @@ -0,0 +1,286 @@ +use super::fixtures::*; +use crate::*; + +// veilid_api/types/aligned_u64.rs + +pub async fn test_alignedu64() { + let orig = AlignedU64::new(0x0123456789abcdef); + let copy = deserialize_json(&serialize_json(orig)).unwrap(); + + assert_eq!(orig, copy); +} + +// veilid_api/types/app_messsage_call.rs + +pub async fn test_veilidappmessage() { + let orig = VeilidAppMessage { + sender: Some(fix_typedkey()), + message: 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(), + id: AlignedU64::from(123), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +// veilid_api/types/fourcc.rs + +pub async fn test_fourcc() { + let orig = FourCC::from_str("D34D").unwrap(); + let copy = deserialize_json(&serialize_json(orig)).unwrap(); + + assert_eq!(orig, copy); +} + +// veilid_api/types/safety.rs + +pub async fn test_sequencing() { + let orig = Sequencing::PreferOrdered; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_stability() { + let orig = Stability::Reliable; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_safetyselection() { + let orig = SafetySelection::Unsafe(Sequencing::EnsureOrdered); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_safetyspec() { + let orig = SafetySpec { + preferred_route: Some(fix_cryptokey()), + hop_count: 23, + stability: Stability::default(), + sequencing: Sequencing::default(), + }; + let copy = deserialize_json(&serialize_json(orig)).unwrap(); + + assert_eq!(orig, copy); +} + +// veilid_api/types/stats.rs + +pub async fn test_latencystats() { + let orig = fix_latencystats(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_transferstats() { + let orig = fix_transferstats(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_transferstatsdownup() { + let orig = fix_transferstatsdownup(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_rpcstats() { + let orig = fix_rpcstats(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_peerstats() { + let orig = fix_peerstats(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +// veilid_api/types/tunnel.rs + +pub async fn test_tunnelmode() { + let orig = TunnelMode::Raw; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} +pub async fn test_tunnelerror() { + let orig = TunnelError::NoCapacity; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_tunnelendpoint() { + let orig = TunnelEndpoint { + mode: TunnelMode::Raw, + description: "Here there be tygers.".to_string(), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_fulltunnel() { + let orig = FullTunnel { + id: AlignedU64::from(42), + timeout: AlignedU64::from(3_000_000), + local: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "Left end.".to_string(), + }, + remote: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "Right end.".to_string(), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_partialtunnel() { + let orig = PartialTunnel { + id: AlignedU64::from(42), + timeout: AlignedU64::from(3_000_000), + local: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "I'm so lonely.".to_string(), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +// veilid_api/types/veilid_log.rs + +pub async fn test_veilidloglevel() { + let orig = VeilidLogLevel::Info; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidlog() { + let orig = VeilidLog { + log_level: VeilidLogLevel::Debug, + message: "A log! A log!".to_string(), + backtrace: Some("Func1 -> Func2 -> Func3".to_string()), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +// veilid_api/types/veilid_state.rs + +pub async fn test_attachmentstate() { + let orig = AttachmentState::FullyAttached; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidstateattachment() { + let orig = VeilidStateAttachment { + state: AttachmentState::OverAttached, + public_internet_ready: true, + local_network_ready: false, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_peertabledata() { + let orig = fix_peertabledata(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidstatenetwork() { + let orig = VeilidStateNetwork { + started: true, + bps_down: AlignedU64::from(14_400), + bps_up: AlignedU64::from(1200), + peers: vec![fix_peertabledata()], + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidroutechange() { + let orig = VeilidRouteChange { + dead_routes: vec![fix_cryptokey()], + dead_remote_routes: vec![fix_cryptokey()], + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidstateconfig() { + let orig = VeilidStateConfig { + config: fix_veilidconfiginner(), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidvaluechange() { + let orig = fix_veilidvaluechange(); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidupdate() { + let orig = VeilidUpdate::ValueChange(fix_veilidvaluechange()); + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_veilidstate() { + let orig = VeilidState { + attachment: VeilidStateAttachment { + state: AttachmentState::OverAttached, + public_internet_ready: true, + local_network_ready: false, + }, + network: VeilidStateNetwork { + started: true, + bps_down: AlignedU64::from(14_400), + bps_up: AlignedU64::from(1200), + peers: vec![fix_peertabledata()], + }, + config: VeilidStateConfig { + config: fix_veilidconfiginner(), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} From e3a20a352e35df230430c18dd705fb9910c41f36 Mon Sep 17 00:00:00 2001 From: Teknique Date: Thu, 1 Jun 2023 15:40:47 -0700 Subject: [PATCH 18/18] 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 {