Skip to content

Commit

Permalink
Merge pull request #118 from blessingbytes/fix-106
Browse files Browse the repository at this point in the history
Test: Add tests for to_u256 function
  • Loading branch information
Marchand-Nicolas authored Nov 29, 2024
2 parents c91af5a + c58a9cc commit c8c9b53
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::extract_prefix_and_root;
use crate::utils::{extract_prefix_and_root, to_u256};
use ark_ff::{biginteger::BigInteger256, BigInteger};

#[cfg(test)]
mod extract_prefix_and_root {
Expand Down Expand Up @@ -67,3 +68,53 @@ mod extract_prefix_and_root {
assert_eq!(root, "例子.com");
}
}

#[cfg(test)]
mod to_u256 {
use super::*;

#[test]
fn test_to_u256_valid_inputs() {
let low = "0x00000000000000000000000000000001";
let high = "0x00000000000000000000000000000000";

let result = to_u256(low, high);

// Check if the result is within the valid range
let min_value = BigInteger256::from_bits_be(&[false; 256][..]);
let max_value = BigInteger256::from_bits_be(&[true; 256][..]);

assert!(result >= min_value);
assert!(result <= max_value);
}

#[test]
fn test_to_u256_invalid_inputs() {
let low = "invalid hex";
let high = "0x00000000000000000000000000000000";

let result = std::panic::catch_unwind(||to_u256(low, high));

assert!(result.is_err());
}

#[test]
fn test_to_u256_edge_cases() {
let low = "0x0000000000000000";
let high = "0x0000000000000001";

let result = to_u256(low, high);

assert_eq!(result, BigInteger256::from_bits_be(&[false; 32][..]));
}

#[test]
fn test_to_u256_zero_value() {
let low = "0x0000000000000000";
let high = "0x0000000000000000";

let result = to_u256(low, high);

assert_eq!(result, BigInteger256::from_bits_be(&[false; 32][..]));
}
}

0 comments on commit c8c9b53

Please sign in to comment.