diff --git a/src/main.rs b/src/main.rs index cece234..4e27fde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,9 @@ lazy_static::lazy_static! { pub static ref ROUTE_REGISTRY: Mutex>> = Mutex::new(Vec::new()); } +#[cfg(test)] +mod tests; + #[tokio::main] async fn main() { let conf = config::load(); 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..518b2d7 --- /dev/null +++ b/src/tests/mod.rs @@ -0,0 +1,2 @@ +mod utils; +mod endpoints; diff --git a/src/tests/utils.rs b/src/tests/utils.rs new file mode 100644 index 0000000..486900e --- /dev/null +++ b/src/tests/utils.rs @@ -0,0 +1,37 @@ +#[cfg(test)] +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; + assert_eq!( + to_hex(zero), + "0x0000000000000000000000000000000000000000000000000000000000000000" + ); + + let small = FieldElement::from(42u64); + assert_eq!( + to_hex(small), + "0x000000000000000000000000000000000000000000000000000000000000002a" + ); + + let large = FieldElement::from_hex_be("0x123456789abcdef0").unwrap(); + assert_eq!( + to_hex(large), + "0x000000000000000000000000000000000000000000000000123456789abcdef0" + ); + } + + #[test] + fn test_to_hex_trimmed() { + let zero = FieldElement::ZERO; + assert_eq!(to_hex_trimmed(zero), "0x0"); + + let small = FieldElement::from(42u64); + assert_eq!(to_hex_trimmed(small), "0x2a"); + + let large = FieldElement::from_hex_be("0x123456789abcdef0").unwrap(); + assert_eq!(to_hex_trimmed(large), "0x123456789abcdef0"); + } +}