-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: log/error on mismatch of client version and supported version (#…
…1166) Co-authored-by: hal3e <[email protected]> Co-authored-by: Ahmed Mujkic <[email protected]>
- Loading branch information
1 parent
7534c12
commit f12ff73
Showing
5 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
use semver::Version; | ||
|
||
fn get_supported_fuel_core_version() -> Version { | ||
"0.20.6".parse().unwrap() | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub(crate) struct VersionCompatibility { | ||
pub(crate) supported_version: Version, | ||
pub(crate) is_major_supported: bool, | ||
pub(crate) is_minor_supported: bool, | ||
pub(crate) is_patch_supported: bool, | ||
} | ||
|
||
pub(crate) fn check_fuel_core_version_compatibility( | ||
network_version: Version, | ||
) -> VersionCompatibility { | ||
let supported_version = get_supported_fuel_core_version(); | ||
check_version_compatibility(network_version, supported_version) | ||
} | ||
|
||
fn check_version_compatibility( | ||
actual_version: Version, | ||
expected_version: Version, | ||
) -> VersionCompatibility { | ||
let is_major_supported = expected_version.major == actual_version.major; | ||
let is_minor_supported = expected_version.minor == actual_version.minor; | ||
let is_patch_supported = expected_version.patch == actual_version.patch; | ||
|
||
VersionCompatibility { | ||
supported_version: expected_version, | ||
is_major_supported, | ||
is_minor_supported, | ||
is_patch_supported, | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn should_validate_all_possible_version_mismatches() { | ||
let expected_version = "0.1.2".parse::<Version>().unwrap(); | ||
|
||
assert_eq!( | ||
check_version_compatibility("1.1.2".parse().unwrap(), expected_version.clone()), | ||
VersionCompatibility { | ||
is_major_supported: false, | ||
is_minor_supported: true, | ||
is_patch_supported: true, | ||
supported_version: expected_version.clone() | ||
} | ||
); | ||
|
||
assert_eq!( | ||
check_version_compatibility("1.2.2".parse().unwrap(), expected_version.clone()), | ||
VersionCompatibility { | ||
is_major_supported: false, | ||
is_minor_supported: false, | ||
is_patch_supported: true, | ||
supported_version: expected_version.clone() | ||
} | ||
); | ||
|
||
assert_eq!( | ||
check_version_compatibility("1.1.3".parse().unwrap(), expected_version.clone()), | ||
VersionCompatibility { | ||
is_major_supported: false, | ||
is_minor_supported: true, | ||
is_patch_supported: false, | ||
supported_version: expected_version.clone() | ||
} | ||
); | ||
|
||
assert_eq!( | ||
check_version_compatibility("0.2.2".parse().unwrap(), expected_version.clone()), | ||
VersionCompatibility { | ||
is_major_supported: true, | ||
is_minor_supported: false, | ||
is_patch_supported: true, | ||
supported_version: expected_version.clone() | ||
} | ||
); | ||
|
||
assert_eq!( | ||
check_version_compatibility("0.2.3".parse().unwrap(), expected_version.clone()), | ||
VersionCompatibility { | ||
is_major_supported: true, | ||
is_minor_supported: false, | ||
is_patch_supported: false, | ||
supported_version: expected_version.clone() | ||
} | ||
); | ||
|
||
assert_eq!( | ||
check_version_compatibility("0.1.3".parse().unwrap(), expected_version.clone()), | ||
VersionCompatibility { | ||
is_major_supported: true, | ||
is_minor_supported: true, | ||
is_patch_supported: false, | ||
supported_version: expected_version.clone() | ||
} | ||
); | ||
|
||
assert_eq!( | ||
check_version_compatibility("0.1.2".parse().unwrap(), expected_version.clone()), | ||
VersionCompatibility { | ||
is_major_supported: true, | ||
is_minor_supported: true, | ||
is_patch_supported: true, | ||
supported_version: expected_version.clone() | ||
} | ||
); | ||
} | ||
} |