1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use multiversx_sc_scenario::api::StaticApi;
use num_bigint::{BigInt, BigUint};
use crate::types::managed::{managed_convertible_impl_self, ManagedConvertible};

type SCBigInt = multiversx_sc::types::BigInt<StaticApi>;
type SCBigUint = multiversx_sc::types::BigUint<StaticApi>;

impl ManagedConvertible<SCBigInt> for BigInt {
    fn to_managed(&self) -> SCBigInt {
        SCBigInt::from(self)
    }
}

impl ManagedConvertible<SCBigUint> for BigUint {
    fn to_managed(&self) -> SCBigUint {
        SCBigUint::from(self)
    }
}

managed_convertible_impl_self! {
    BigInt BigUint
}

#[cfg(test)]
mod tests {
    use multiversx_sc::types::{BigInt, BigUint};
    use multiversx_sc_scenario::api::StaticApi;
    use crate::types::native::NativeConvertible;

    #[test]
    fn test_biguint_to_native() {
        let biguint: BigUint<StaticApi> = BigUint::from(10u64).pow(18);
        let native = biguint.to_native();

        let expected = num_bigint::BigUint::from(10u64).pow(18);

        assert_eq!(
            native,
            expected
        )
    }

    #[test]
    fn test_bigint_to_native() {
        let bigint: BigInt<StaticApi> = BigInt::from(10i64).pow(18);
        let native = bigint.to_native();

        let expected = num_bigint::BigInt::from(10i64).pow(18);

        assert_eq!(
            native,
            expected
        )
    }

    #[test]
    fn test_negative_bigint_to_native() {
        let bigint: BigInt<StaticApi> = BigInt::from(-10i64).pow(18);
        let native = bigint.to_native();

        let expected = num_bigint::BigInt::from(-10i64).pow(18);

        assert_eq!(
            native,
            expected
        )
    }
}