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
use wasm_bindgen::prelude::*;

#[wasm_bindgen(module = "@ethersproject/bignumber")]
extern "C" {
    pub type BigNumber;

    #[wasm_bindgen(static_method_of = BigNumber, js_name = from)]
    pub fn new(number: String) -> BigNumber;

    #[wasm_bindgen(static_method_of = BigNumber, js_name = from)]
    pub fn new_from_array(number: &[u8]) -> BigNumber;

    #[wasm_bindgen(method, getter, js_name = _hex)]
    pub fn hex(this: &BigNumber) -> String;
}

#[cfg(test)]
mod tests {
    use wasm_bindgen_test::*;

    use super::BigNumber;

    #[wasm_bindgen_test]
    fn new_then_hex() {
        assert_eq!(
            BigNumber::new("0x1e00".to_string()).hex(),
            "0x1e00".to_string()
        );
    }

    #[wasm_bindgen_test]
    fn new_from_array_then_hex() {
        assert_eq!(
            BigNumber::new_from_array(&[30, 0]).hex(),
            "0x1e00".to_string()
        );
    }
}