Skip to content

Commit

Permalink
build: impl debug for felt (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
AvivYossef-starkware authored Jun 6, 2024
1 parent 83a3e89 commit 618afae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion crates/committer/src/felt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt;
use ethnum::U256;
use serde::{Deserialize, Serialize};
use starknet_types_core::felt::{Felt as StarknetTypesFelt, FromStrError};
Expand All @@ -7,7 +8,6 @@ use starknet_types_core::felt::{Felt as StarknetTypesFelt, FromStrError};
PartialEq,
Clone,
Copy,
Debug,
Default,
Hash,
derive_more::Add,
Expand Down Expand Up @@ -55,6 +55,12 @@ impl std::ops::Mul for Felt {
}
}

impl fmt::Debug for Felt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", U256::from(self))
}
}

impl Felt {
pub const ZERO: Felt = Felt(StarknetTypesFelt::ZERO);
#[allow(dead_code)]
Expand Down
6 changes: 6 additions & 0 deletions crates/committer/src/patricia_merkle_tree/types_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,9 @@ fn test_nodeindex_to_felt_conversion() {
let index = NodeIndex::MAX;
assert!(Felt::try_from(index).is_err());
}

#[rstest]
fn test_felt_printing() {
let felt = Felt::from(17_u8);
assert_eq!(format!("{:?}", felt), "17");
}
2 changes: 1 addition & 1 deletion crates/committer_cli/src/parse_input/read_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ fn test_input_parsing_with_mapping_key_duplicate() {
"#;
let expected_error =
"address to class hash: ContractAddress(Felt(Felt(FieldElement { value: UnsignedInteger { limbs: [72718179, 18446744073709551615, 6917529027641073992, 16140901064500135204] } })))";
"address to class hash: ContractAddress(6646139978924584093298644040422522880)";
assert!(matches!(
parse_input(input.to_string()).unwrap_err(),
DeserializationError::KeyDuplicate(key) if key == expected_error
Expand Down

0 comments on commit 618afae

Please sign in to comment.