diff --git a/corelib/src/integer.cairo b/corelib/src/integer.cairo index 68d5c1c748b..ebf0ce9690f 100644 --- a/corelib/src/integer.cairo +++ b/corelib/src/integer.cairo @@ -1373,7 +1373,7 @@ extern fn u512_safe_divmod_by_u256( U128MulGuarantee ) implicits(RangeCheck) nopanic; -pub(crate) impl U512TryIntoU256 of TryInto { +impl U512TryIntoU256 of TryInto { fn try_into(self: u512) -> Option { if self.limb2 != 0 || self.limb3 != 0 { Option::None diff --git a/corelib/src/test/integer_test.cairo b/corelib/src/test/integer_test.cairo index a3366f9bc72..b136d23d91b 100644 --- a/corelib/src/test/integer_test.cairo +++ b/corelib/src/test/integer_test.cairo @@ -797,18 +797,10 @@ fn test_u512_safe_div_rem_by_u256() { #[test] fn test_u512_try_into_u256() { - let num = u512 { limb0: 0xdeadbeef, limb1: 0, limb2: 0, limb3: 0 }; - let num_u256: u256 = num.try_into().unwrap(); - assert_eq(@num_u256, @0xdeadbeef_u256, 'u512 -> u256'); - - let num = u512 { - limb0: 0x33233223222222122112111111011001, - limb1: 0x54455445544554454444443443343333, - limb2: 0x21222222322332333333433443444444, - limb3: 0x1001101111112112, - }; - let option: Option = num.try_into(); - assert(option.is_none(), 'u512 -/-> u256'); + assert!(u512 { limb0: 1, limb1: 2, limb2: 0, limb3: 0 }.try_into() == Option::Some(0x200000000000000000000000000000001_u256)); + assert!(u512 { limb0: 1, limb1: 2, limb2: 3, limb3: 0 }.try_into() == Option::::None); + assert!(u512 { limb0: 1, limb1: 2, limb2: 0, limb3: 4 }.try_into() == Option::::None); + assert!(u512 { limb0: 1, limb1: 2, limb2: 3, limb3: 4 }.try_into() == Option::::None); } #[test]