diff --git a/crates/starknet-types-core/src/felt.rs b/crates/starknet-types-core/src/felt.rs index dc5820b..f8a4a38 100644 --- a/crates/starknet-types-core/src/felt.rs +++ b/crates/starknet-types-core/src/felt.rs @@ -464,6 +464,15 @@ impl From for Felt { } } +impl From 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(); @@ -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); + } }