e5afd54ce0
* Basic storage stub * New models for new node status api * Route handling * Mounting new routes * Missing selective commit * Moved network monitor related files to separate package * Starting to see some sqlx action * Schema updates * Log statement upon finished migration * Removed old diesel related imports * Converted mixnode cache initialisation into a fairing * Moved cache related functionalities to separate package Also defined staging there * Created run method for validator cache + removed unwrap * Removed old node-status-api types and left bunch of todo placeholders in their place * Fixed managing validatorcache * Status reports are starting to get constructed * Submitting some dummy results to the database * Removing duplicate code for generating reports * Removed statuses older than 48h * Initial attempt at trying to obtain reports for all active nodes * Removed duplicates from the full report * Grabbing uptime history * Updating historical uptimes of active nodes * Updated sqlx-data.json * Removed all placeholder foomp owner values * Changed Layer serde behaviour for easier usage * Extended validator api config * Initial (seems working !) integration with network monitor * Added database path configuration to config * Using ValidatorCache in NetworkMonitor * Flag indicating whether validator cache has been initialised * Introduced a locla-only route for reward script to perform daily chores * Flag to save config to a file * Moved spawning of receiving future to run method rather than new * Removed arguments that dont make sense to be configured via CLI * Removed dead code from config file * More dead code removal * Added validator API to CI * Corrected manifest-path arguments * Constructing network monitor by passing config * Combined validator API CI with the main CI file * Using query_as for NodeStatus * Checking if historical uptimes were already calculated on particular day * Making id field NOT NULL * More query_as! action * Updated sqlx-data.json * Removed unused chrono feature * Renamed the migration file * Changed default validator endpoint to point to local validator * Removing unnecessary clone * More appropriate naming * Removed dead code * Lock file updates * Updated network monitor address in contract code * Don't stage node status api if network monitor is disabled * cargo fmt * Updated all license notices to SPDX
78 lines
2.4 KiB
Rust
78 lines
2.4 KiB
Rust
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use semver::SemVerError;
|
|
pub use semver::Version;
|
|
|
|
/// Checks whether given `version` is compatible with a given semantic version requirement `req`
|
|
/// according to major-minor semver rules. The semantic version requirement can be passed as a full,
|
|
/// concrete version number, because that's what we'll have in our Cargo.toml files (e.g. 0.3.2).
|
|
/// The patch number in the requirement gets dropped and replaced with a wildcard (0.3.*) as all
|
|
/// minor versions should be compatible with each other.
|
|
pub fn is_minor_version_compatible(version: &str, req: &str) -> bool {
|
|
let expected_version = match Version::parse(version) {
|
|
Ok(v) => v,
|
|
Err(_) => return false,
|
|
};
|
|
let req_version = match Version::parse(req) {
|
|
Ok(v) => v,
|
|
Err(_) => return false,
|
|
};
|
|
|
|
expected_version.major == req_version.major && expected_version.minor == req_version.minor
|
|
}
|
|
|
|
pub fn parse_version(raw_version: &str) -> Result<Version, SemVerError> {
|
|
Version::parse(raw_version)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn version_0_3_0_is_compatible_with_requirement_0_3_x() {
|
|
assert!(is_minor_version_compatible("0.3.0", "0.3.2"));
|
|
}
|
|
|
|
#[test]
|
|
fn version_0_3_1_is_compatible_with_minimum_requirement_0_3_x() {
|
|
assert!(is_minor_version_compatible("0.3.1", "0.3.2"));
|
|
}
|
|
|
|
#[test]
|
|
fn version_0_3_2_is_compatible_with_minimum_requirement_0_3_x() {
|
|
assert!(is_minor_version_compatible("0.3.2", "0.3.0"));
|
|
}
|
|
|
|
#[test]
|
|
fn version_0_2_0_is_not_compatible_with_requirement_0_3_x() {
|
|
assert!(!is_minor_version_compatible("0.2.0", "0.3.2"));
|
|
}
|
|
|
|
#[test]
|
|
fn version_0_4_0_is_not_compatible_with_requirement_0_3_x() {
|
|
assert!(!is_minor_version_compatible("0.4.0", "0.3.2"));
|
|
}
|
|
|
|
#[test]
|
|
fn version_1_3_2_is_not_compatible_with_requirement_0_3_x() {
|
|
assert!(!is_minor_version_compatible("1.3.2", "0.3.2"));
|
|
}
|
|
|
|
#[test]
|
|
fn version_0_4_0_rc_1_is_compatible_with_version_0_4_0_rc_1() {
|
|
assert!(is_minor_version_compatible("0.4.0-rc.1", "0.4.0-rc.1"));
|
|
}
|
|
|
|
#[test]
|
|
fn returns_false_on_foo_version() {
|
|
assert!(!is_minor_version_compatible("foo", "0.3.2"));
|
|
}
|
|
|
|
#[test]
|
|
fn returns_false_on_bar_version() {
|
|
assert!(!is_minor_version_compatible("0.3.2", "bar"));
|
|
}
|
|
}
|