Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed May 1, 2024
1 parent beb1f1f commit 101379d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/cairo-serde/src/types/non_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ mod tests {
_ => panic!("Expected ZeroedNonZero error"),
}
}

#[test]
fn test_non_zero_const_size() {
assert_eq!(NonZero::<u32>::SERIALIZED_SIZE, Some(1));
Expand Down
13 changes: 13 additions & 0 deletions crates/cairo-serde/src/types/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl U256 {
mod tests {
use super::*;
use starknet::core::types::FieldElement;

#[test]
fn test_serialize_u256() {
let low = 9_u128;
Expand All @@ -100,6 +101,7 @@ mod tests {
assert_eq!(felts[0], FieldElement::from(9_u128));
assert_eq!(felts[1], FieldElement::from(8_u128));
}

#[test]
fn test_serialize_u256_max() {
let low = u128::MAX;
Expand All @@ -109,6 +111,7 @@ mod tests {
assert_eq!(felts[0], FieldElement::from(u128::MAX));
assert_eq!(felts[1], FieldElement::from(u128::MAX));
}

#[test]
fn test_serialize_u256_min() {
let low = u128::MIN;
Expand All @@ -118,13 +121,15 @@ mod tests {
assert_eq!(felts[0], FieldElement::from(u128::MIN));
assert_eq!(felts[1], FieldElement::from(u128::MIN));
}

#[test]
fn test_deserialize_u256() {
let felts = vec![FieldElement::from(9_u128), FieldElement::from(8_u128)];
let num_u256 = U256::cairo_deserialize(&felts, 0).unwrap();
assert_eq!(num_u256.low, 9_u128);
assert_eq!(num_u256.high, 8_u128);
}

#[test]
fn test_serialized_size_u256() {
let u256 = U256 {
Expand All @@ -133,6 +138,7 @@ mod tests {
};
assert_eq!(U256::cairo_serialized_size(&u256), 2);
}

#[test]
fn test_to_bytes_be() {
let u256 = U256 {
Expand All @@ -146,6 +152,7 @@ mod tests {
];
assert_eq!(bytes, expected_bytes);
}

#[test]
fn test_to_bytes_le() {
let u256 = U256 {
Expand All @@ -159,6 +166,7 @@ mod tests {
];
assert_eq!(bytes, expected_bytes);
}

#[test]
fn test_from_bytes_be() {
let bytes: [u8; 32] = [
Expand All @@ -169,6 +177,7 @@ mod tests {
assert_eq!(u256.low, 9_u128);
assert_eq!(u256.high, 8_u128);
}

#[test]
fn test_from_bytes_le() {
let bytes: [u8; 32] = [
Expand All @@ -179,13 +188,15 @@ mod tests {
assert_eq!(u256.low, 9_u128);
assert_eq!(u256.high, 8_u128);
}

#[test]
fn test_from_field_element() {
let felts = (FieldElement::from(9_u128), FieldElement::from(8_u128));
let u256 = U256::try_from(felts).unwrap();
assert_eq!(u256.low, 9_u128);
assert_eq!(u256.high, 8_u128);
}

#[test]
fn test_ordering_1() {
let u256_1 = U256 {
Expand All @@ -198,6 +209,7 @@ mod tests {
};
assert!(u256_1 < u256_2);
}

#[test]
fn test_ordering_2() {
let u256_1 = U256 {
Expand All @@ -210,6 +222,7 @@ mod tests {
};
assert!(u256_1 == u256_2);
}

#[test]
fn test_ordering_3() {
let u256_1 = U256 {
Expand Down
1 change: 1 addition & 0 deletions examples/simple_get_set.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cainome::cairo_serde::U256;
use cainome::rs::abigen;
use starknet::{
accounts::{Account, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount},
Expand Down

0 comments on commit 101379d

Please sign in to comment.