• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ergoplatform / sigma-rust / 19715256552

26 Nov 2025 07:29PM UTC coverage: 86.888% (+8.4%) from 78.463%
19715256552

Pull #838

github

web-flow
Merge ff3964431 into 2f840d387
Pull Request #838: CI fixes

7 of 8 new or added lines in 7 files covered. (87.5%)

1628 existing lines in 221 files now uncovered.

27460 of 31604 relevant lines covered (86.89%)

253315.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.11
/ergo-rest/src/peer_info.rs
1
use ergo_chain_types::ConnectionDirection;
2
use ergo_chain_types::PeerAddr;
3
use serde::{de::Error, Deserialize, Deserializer, Serialize};
4

5
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
6
#[repr(C)]
7
/// Peer info returned by node REST API
8
pub struct PeerInfo {
9
    /// Peer address
10
    #[serde(
11
        rename = "address",
12
        deserialize_with = "parse_peer_addr_with_leading_slash"
13
    )]
14
    pub addr: PeerAddr,
15
    /// Last message
16
    #[serde(rename = "lastMessage")]
17
    pub last_message: u64,
18
    /// Timestamp of the last handshake
19
    #[serde(rename = "lastHandshake")]
20
    pub last_handshake: u64, // TODO: any more precise type?
21
    /// Node name
22
    pub name: String,
23
    /// Type of connection (Incoming/Outgoing) established to this peer if any
24
    #[serde(rename = "connectionType")]
25
    pub conn_type: Option<ConnectionDirection>,
26
}
27

28
/// The `PeerAddr` reported by ergo nodes at the `peers/all` endpoint begin with a leading '/'.
29
/// This custom deserialization function simply removes the leading character then uses the
30
/// serde-generated function to parse.
31
fn parse_peer_addr_with_leading_slash<'de, D>(deserializer: D) -> Result<PeerAddr, D::Error>
17,085✔
32
where
17,085✔
33
    D: Deserializer<'de>,
17,085✔
34
{
35
    let s: &str = Deserialize::deserialize(deserializer)?;
17,085✔
36

37
    let s = if s.starts_with('/') {
17,085✔
38
        let mut chars = s.chars();
17,085✔
39
        chars.next();
17,085✔
40
        chars.as_str()
17,085✔
41
    } else {
42
        s
×
43
    };
44
    match s.parse().map_err(D::Error::custom) {
17,085✔
45
        Ok(peer_addr) => Ok(peer_addr),
17,004✔
46
        Err(_) => {
47
            // try to fix an invalid IP v6 address encoding on node
48
            // the format should be `[ipv6]:port`, but pre-JDK14 node returns `ipv6:port`
49
            // see https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8225499
50
            //dbg!(&s);
51
            let parts: Vec<&str> = s.rsplit(':').collect();
81✔
52
            if parts.len() == 2 {
81✔
53
                // not an IP v6 address
54
                return Err(D::Error::custom(format!(
×
55
                    "expected invalid IP v6(without brackets) address, got: {}",
×
56
                    s
×
UNCOV
57
                )));
×
58
            }
81✔
59
            #[allow(clippy::unwrap_used)]
60
            let port = parts.first().cloned().unwrap();
81✔
61
            let host: String = parts
81✔
62
                .into_iter()
81✔
63
                .skip(1)
81✔
64
                .rev()
81✔
65
                .collect::<Vec<&str>>()
81✔
66
                .join(":");
81✔
67
            // put host inside brackets to make it a valid IP v6 address
68
            let str = format!("[{}]:{}", host, port);
81✔
69
            str.parse().map_err(D::Error::custom)
81✔
70
        }
71
    }
72
}
17,085✔
73

74
#[cfg(test)]
75
#[cfg(feature = "json")]
76
#[allow(clippy::unwrap_used)]
77
mod tests {
78
    use super::*;
79
    #[test]
80
    fn test_parse_peer_info() {
1✔
81
        let json = "{\n    \"address\" : \"/62.106.112.158:9030\",\n    \"lastMessage\" : 0,\n    \"lastHandshake\" : 0,\n    \"name\" : \"ergo-mainnet-4.0.12\",\n    \"connectionType\" : null\n  }";
1✔
82
        let _: PeerInfo = serde_json::from_str(json).unwrap();
1✔
83
    }
1✔
84

85
    #[test]
86
    fn test_parse_peer_info_ipv6_pre_jkd14() {
1✔
87
        let json = "{\n    \"address\" : \"/2a0d:6fc0:7cb:be00:50be:7d74:7a00:aa3e:9030\",\n    \"lastMessage\" : 0,\n    \"lastHandshake\" : 0,\n    \"name\" : \"ergo-mainnet-4.0.12\",\n    \"connectionType\" : null\n  }";
1✔
88
        let _: PeerInfo = serde_json::from_str(json).unwrap();
1✔
89
    }
1✔
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc