novax_data/types/
native_number.rs1use multiversx_sc_scenario::api::StaticApi;
2use num_bigint::{BigInt, BigUint};
3use crate::types::managed::{managed_convertible_impl_self, ManagedConvertible};
4
5type SCBigInt = multiversx_sc::types::BigInt<StaticApi>;
6type SCBigUint = multiversx_sc::types::BigUint<StaticApi>;
7
8impl ManagedConvertible<SCBigInt> for BigInt {
9 fn to_managed(&self) -> SCBigInt {
10 SCBigInt::from(self)
11 }
12}
13
14impl ManagedConvertible<SCBigUint> for BigUint {
15 fn to_managed(&self) -> SCBigUint {
16 SCBigUint::from(self)
17 }
18}
19
20managed_convertible_impl_self! {
21 BigInt BigUint
22}
23
24#[cfg(test)]
25mod tests {
26 use multiversx_sc::types::{BigInt, BigUint};
27 use multiversx_sc_scenario::api::StaticApi;
28 use crate::types::native::NativeConvertible;
29
30 #[test]
31 fn test_biguint_to_native() {
32 let biguint: BigUint<StaticApi> = BigUint::from(10u64).pow(18);
33 let native = biguint.to_native();
34
35 let expected = num_bigint::BigUint::from(10u64).pow(18);
36
37 assert_eq!(
38 native,
39 expected
40 )
41 }
42
43 #[test]
44 fn test_bigint_to_native() {
45 let bigint: BigInt<StaticApi> = BigInt::from(10i64).pow(18);
46 let native = bigint.to_native();
47
48 let expected = num_bigint::BigInt::from(10i64).pow(18);
49
50 assert_eq!(
51 native,
52 expected
53 )
54 }
55
56 #[test]
57 fn test_negative_bigint_to_native() {
58 let bigint: BigInt<StaticApi> = BigInt::from(-10i64).pow(18);
59 let native = bigint.to_native();
60
61 let expected = num_bigint::BigInt::from(-10i64).pow(18);
62
63 assert_eq!(
64 native,
65 expected
66 )
67 }
68}