From 35e4ca977718f3a4567dfec7d3f0cf13a7df5a84 Mon Sep 17 00:00:00 2001 From: guha-rahul <69rahul16@gmail.com> Date: Mon, 25 Nov 2024 02:06:14 +0530 Subject: [PATCH 1/5] added tests totest_to_hex and test_to_hex_trimmed --- src/endpoints/defi/rewards.rs | 2 -- tests/utils.rs | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/utils.rs diff --git a/src/endpoints/defi/rewards.rs b/src/endpoints/defi/rewards.rs index d147f96..95e80a7 100644 --- a/src/endpoints/defi/rewards.rs +++ b/src/endpoints/defi/rewards.rs @@ -16,7 +16,6 @@ use futures::stream::{FuturesOrdered, StreamExt}; use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, USER_AGENT}; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, Error}; use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware}; -use reqwest_tracing::TracingMiddleware; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::{core::types::FieldElement, macros::selector}; @@ -37,7 +36,6 @@ pub async fn get_defi_rewards( // Retry up to 3 times with increasing intervals between attempts. let retry_policy = ExponentialBackoff::builder().build_with_max_retries(3); let client = ClientBuilder::new(reqwest::Client::new()) - .with(TracingMiddleware::default()) .with(RetryTransientMiddleware::new_with_policy(retry_policy)) .build(); diff --git a/tests/utils.rs b/tests/utils.rs new file mode 100644 index 0000000..f25a2dd --- /dev/null +++ b/tests/utils.rs @@ -0,0 +1,38 @@ +#[cfg(test)] +mod tests { + use crate::utils::{to_hex, to_hex_trimmed}; + use starknet::core::types::FieldElement; + + #[test] + fn test_to_hex() { + let zero = FieldElement::ZERO; + assert_eq!( + to_hex(zero), + "0x0000000000000000000000000000000000000000000000000000000000000000" + ); + + let small = FieldElement::from(42); + assert_eq!( + to_hex(small), + "0x000000000000000000000000000000000000000000000000000000000000002a" + ); + + let large = FieldElement::from_hex_be("0x123456789abcdef0").unwrap(); + assert_eq!( + to_hex(large), + "0x0000000000000000000000000000000000000000000000000123456789abcdef0" + ); + } + + #[test] + fn test_to_hex_trimmed() { + let zero = FieldElement::ZERO; + assert_eq!(to_hex_trimmed(zero), "0x0"); + + let small = FieldElement::from(42); + assert_eq!(to_hex_trimmed(small), "0x2a"); + + let large = FieldElement::from_hex_be("0x123456789abcdef0").unwrap(); + assert_eq!(to_hex_trimmed(large), "0x123456789abcdef0"); + } +} From 8fff0fd4a5e21f21d9a12cd35b8198a63c8bf287 Mon Sep 17 00:00:00 2001 From: guha-rahul <69rahul16@gmail.com> Date: Wed, 27 Nov 2024 19:23:16 +0530 Subject: [PATCH 2/5] refactor tests --- mod.rs | 2 ++ src/main.rs | 3 ++- {tests => src/tests}/endpoints.rs | 0 src/tests/mod.rs | 1 + {tests => src/tests}/utils.rs | 9 ++++----- 5 files changed, 9 insertions(+), 6 deletions(-) rename {tests => src/tests}/endpoints.rs (100%) create mode 100644 src/tests/mod.rs rename {tests => src/tests}/utils.rs (83%) diff --git a/mod.rs b/mod.rs index 504a74c..f9b38b0 100644 --- a/mod.rs +++ b/mod.rs @@ -2,4 +2,6 @@ pub mod create_quest; pub(crate) mod get_quest; pub mod get_quests; pub mod get_tasks; +#[cfg(test)] +mod tests; pub mod update_quest; diff --git a/src/main.rs b/src/main.rs index b543ae8..396aa4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,8 @@ use utils::WithState; lazy_static::lazy_static! { pub static ref ROUTE_REGISTRY: Mutex>> = Mutex::new(Vec::new()); } - +#[cfg(test)] +mod tests; #[derive(Serialize)] struct LogData<'a> { token: &'a str, diff --git a/tests/endpoints.rs b/src/tests/endpoints.rs similarity index 100% rename from tests/endpoints.rs rename to src/tests/endpoints.rs diff --git a/src/tests/mod.rs b/src/tests/mod.rs new file mode 100644 index 0000000..95adf51 --- /dev/null +++ b/src/tests/mod.rs @@ -0,0 +1 @@ +mod utils; diff --git a/tests/utils.rs b/src/tests/utils.rs similarity index 83% rename from tests/utils.rs rename to src/tests/utils.rs index f25a2dd..486900e 100644 --- a/tests/utils.rs +++ b/src/tests/utils.rs @@ -1,8 +1,7 @@ #[cfg(test)] -mod tests { +pub mod tests { use crate::utils::{to_hex, to_hex_trimmed}; use starknet::core::types::FieldElement; - #[test] fn test_to_hex() { let zero = FieldElement::ZERO; @@ -11,7 +10,7 @@ mod tests { "0x0000000000000000000000000000000000000000000000000000000000000000" ); - let small = FieldElement::from(42); + let small = FieldElement::from(42u64); assert_eq!( to_hex(small), "0x000000000000000000000000000000000000000000000000000000000000002a" @@ -20,7 +19,7 @@ mod tests { let large = FieldElement::from_hex_be("0x123456789abcdef0").unwrap(); assert_eq!( to_hex(large), - "0x0000000000000000000000000000000000000000000000000123456789abcdef0" + "0x000000000000000000000000000000000000000000000000123456789abcdef0" ); } @@ -29,7 +28,7 @@ mod tests { let zero = FieldElement::ZERO; assert_eq!(to_hex_trimmed(zero), "0x0"); - let small = FieldElement::from(42); + let small = FieldElement::from(42u64); assert_eq!(to_hex_trimmed(small), "0x2a"); let large = FieldElement::from_hex_be("0x123456789abcdef0").unwrap(); From 6ec09d479af1a938a4f6c1f25175700ec88bb1f7 Mon Sep 17 00:00:00 2001 From: guha-rahul <52607971+guha-rahul@users.noreply.github.com> Date: Thu, 28 Nov 2024 03:47:45 +0530 Subject: [PATCH 3/5] Update mod.rs --- src/tests/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 95adf51..518b2d7 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1 +1,2 @@ mod utils; +mod endpoints; From f6c69e7046025a8f05db76e605d6a941f4060bca Mon Sep 17 00:00:00 2001 From: guha-rahul <52607971+guha-rahul@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:03:29 +0530 Subject: [PATCH 4/5] Update main.rs --- src/main.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 23963f8..4e27fde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,20 +26,6 @@ lazy_static::lazy_static! { #[cfg(test)] mod tests; -#[derive(Serialize)] -struct LogData<'a> { - token: &'a str, - log: LogPayload<'a>, -} - -#[derive(Serialize)] -struct LogPayload<'a> { - app_id: &'a str, - r#type: &'a str, - message: Cow<'a, str>, - timestamp: i64, -} - #[tokio::main] async fn main() { From e1757a38cbea6234f513edfbba5edbcc12b6e313 Mon Sep 17 00:00:00 2001 From: Nico <60229704+Marchand-Nicolas@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:11:11 +0100 Subject: [PATCH 5/5] removing not needed code --- mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/mod.rs b/mod.rs index f9b38b0..504a74c 100644 --- a/mod.rs +++ b/mod.rs @@ -2,6 +2,4 @@ pub mod create_quest; pub(crate) mod get_quest; pub mod get_quests; pub mod get_tasks; -#[cfg(test)] -mod tests; pub mod update_quest;