Skip to content

Commit

Permalink
Implement Felt from boolean (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
pefontana authored Dec 20, 2023
1 parent 33c8fbd commit 6f29700
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/starknet-types-core/src/felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,15 @@ impl From<i128> for Felt {
}
}

impl From<bool> for Felt {
fn from(value: bool) -> Felt {
match value {
true => Felt::ONE,
false => Felt::ZERO,
}
}
}

impl From<&BigInt> for Felt {
fn from(bigint: &BigInt) -> Felt {
let (sign, bytes) = bigint.mod_floor(&CAIRO_PRIME_BIGINT).to_bytes_le();
Expand Down Expand Up @@ -1715,4 +1724,12 @@ mod test {
);
}
}

#[test]
fn bool_into_felt() {
let zero: Felt = false.into();
let one: Felt = true.into();
assert_eq!(one, Felt::ONE);
assert_eq!(zero, Felt::ZERO);
}
}

0 comments on commit 6f29700

Please sign in to comment.