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
use std::string::String;

use num_bigint::BigInt;
use serde::{Deserialize, Serialize};

use avalanche_utils::big_int;

/// ref. https://docs.avax.network/build/avalanchego-apis/c-chain#eth_getassetbalance
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
pub struct GetBalanceResponse {
    pub jsonrpc: String,
    pub id: u32,
    #[serde(with = "big_int::serde_hex_format")]
    pub result: BigInt,
}

/// RUST_LOG=debug cargo test --package avalanche-types --lib -- api::eth::test_get_balance_response --exact --show-output
#[test]
fn test_get_balance_response() {
    // ref. https://docs.avax.network/build/avalanchego-apis/c-chain#eth_getassetbalance
    let resp: GetBalanceResponse = serde_json::from_str(
        "

{
    \"jsonrpc\": \"2.0\",
    \"result\": \"0x1388\",
    \"id\": 1
}

",
    )
    .unwrap();
    let expected = GetBalanceResponse {
        jsonrpc: "2.0".to_string(),
        id: 1,
        result: big_int::from_hex("0x1388").unwrap(),
    };
    assert_eq!(resp, expected);
}