Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test version node #233

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion chain-signatures/node/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use contract::primitives::ParticipantInfo;
pub use contract::ProtocolState;
pub use cryptography::CryptographicError;
pub use message::{Message, MessageChannel};
use semver::Version;
pub use signature::{IndexedSignRequest, SignQueue};
pub use state::NodeState;
pub use sysinfo::{Components, CpuRefreshKind, Disks, RefreshKind, System};
Expand Down Expand Up @@ -275,7 +276,17 @@ impl MpcSignProtocol {

/// our release versions take the form of "1.0.0-rc.2"
fn node_version() -> i64 {
let version = semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
parse_node_version(env!("CARGO_PKG_VERSION"))
}

fn parse_node_version(version: &str) -> i64 {
let version = match Version::parse(version) {
Ok(v) => v,
Err(_) => {
tracing::error!("Failed to parse version: {}", version);
Version::new(999, 999, 999)
}
};
let rc_num = if let Some(rc_str) = version.pre.split('.').nth(1) {
rc_str.parse::<u64>().unwrap_or(0)
} else {
Expand Down Expand Up @@ -342,3 +353,30 @@ pub enum Chain {
NEAR,
Ethereum,
}

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

#[test]
fn test_parse_node_version() {
assert_eq!(parse_node_version("1.0.0-beta"), 1000000000);
assert_eq!(parse_node_version("1.0.0-rc.1"), 1000000001);
assert_eq!(parse_node_version("1.0.0-rc.2"), 1000000002);
assert_eq!(parse_node_version("1.2.3-rc.4"), 1002003004);
assert_eq!(parse_node_version("1.0.0"), 1000000000);
assert_eq!(parse_node_version("1.1.0"), 1001000000);
assert_eq!(parse_node_version("1.2.3"), 1002003000);
assert_eq!(parse_node_version("2.0.0"), 2000000000);
assert_eq!(parse_node_version("2.1.0"), 2001000000);
assert_eq!(parse_node_version("2.1.1-rc.5"), 2001001005);
assert_eq!(parse_node_version("2.1.1"), 2001001000);
assert_eq!(parse_node_version("10.20.30-rc.40"), 10020030040);
}

#[test]
fn test_parse_node_version_invalid() {
assert_eq!(parse_node_version("bad_version"), 999999999000);
assert_eq!(parse_node_version(""), 999999999000);
}
}
Loading