Skip to content

Commit aacbed3

Browse files
chore: [MR-591] Trim canonical state framework (#2539)
This removes exceptions for unsupported certification versions and trims down the testing framework accordingly. --------- Co-authored-by: Alin Sinpalean <58422065+alin-at-dfinity@users.noreply.github.com>
1 parent 03f3deb commit aacbed3

File tree

15 files changed

+267
-1152
lines changed

15 files changed

+267
-1152
lines changed

rs/canonical_state/certification_version/src/lib.rs

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,6 @@ use strum_macros::{EnumCount, EnumIter};
22

33
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, EnumCount, EnumIter)]
44
pub enum CertificationVersion {
5-
/// Initial version.
6-
V0 = 0,
7-
/// Added canister module hash and controller.
8-
V1 = 1,
9-
/// Added support for multiple canister controllers.
10-
V2 = 2,
11-
/// Added subnet to canister ID ranges routing tables.
12-
V3 = 3,
13-
/// Added optional `Request::cycles_payment` and `Response::cycles_refund`
14-
/// fields that are not yet populated.
15-
V4 = 4,
16-
/// Added support for canister metadata custom sections.
17-
V5 = 5,
18-
/// Encoding of canister metadata custom sections.
19-
V6 = 6,
20-
/// Support for decoding of `StreamHeader::reject_signals`.
21-
/// Support for `done` ingress history status.
22-
V7 = 7,
23-
/// Encoding of `StreamHeader::reject_signals`.
24-
/// Producing `done` ingress history statuses.
25-
V8 = 8,
26-
/// Producing non-empty `StreamHeader::reject_signals`.
27-
V9 = 9,
28-
/// Dropped `SystemMetadata::id_counter`.
29-
V10 = 10,
30-
/// Producing `error_code` field in `request_status` subtree.
31-
V11 = 11,
32-
/// Added `/subnet/<own_subnet_id>/node` subtree, with node public keys.
33-
V12 = 12,
34-
/// Dropped `/canister/<canister_id>/controller`.
35-
V13 = 13,
36-
/// Define optional `Request::metadata` field.
37-
V14 = 14,
38-
/// Added subnet metrics in `subnet` subtree.
39-
V15 = 15,
40-
/// Added `/api_boundary_nodes` subtree with domain, ipv4_address and ipv6_address for each API boundary node.
41-
V16 = 16,
425
/// Added `flags` to `StreamHeader`. Defined `StreamHeaderFlagBits::ResponsesOnly` flag.
436
V17 = 17,
447
/// Added `deadline` fields to `Request` and `Response`.
@@ -69,9 +32,8 @@ impl std::convert::TryFrom<u32> for CertificationVersion {
6932
type Error = UnsupportedCertificationVersion;
7033

7134
fn try_from(n: u32) -> Result<Self, Self::Error> {
72-
use strum::IntoEnumIterator;
73-
CertificationVersion::iter()
74-
.nth(n as usize)
35+
all_supported_versions()
36+
.find(|v| *v as u32 == n)
7537
.ok_or(UnsupportedCertificationVersion(n))
7638
}
7739
}
@@ -92,7 +54,8 @@ pub const MIN_SUPPORTED_CERTIFICATION_VERSION: CertificationVersion = Certificat
9254
/// this.
9355
pub const MAX_SUPPORTED_CERTIFICATION_VERSION: CertificationVersion = CertificationVersion::V19;
9456

95-
/// Returns a list of all certification versions up to [MAX_SUPPORTED_CERTIFICATION_VERSION].
57+
/// Returns a list of all certification versions from `MIN_SUPPORTED_CERTIFICATION_VERSION`
58+
/// up to `MAX_SUPPORTED_CERTIFICATION_VERSION`.
9659
pub fn all_supported_versions() -> impl std::iter::Iterator<Item = CertificationVersion> {
9760
use strum::IntoEnumIterator;
9861
CertificationVersion::iter().filter(|v| {
@@ -105,3 +68,21 @@ fn version_constants_consistent() {
10568
assert!(MIN_SUPPORTED_CERTIFICATION_VERSION <= CURRENT_CERTIFICATION_VERSION);
10669
assert!(CURRENT_CERTIFICATION_VERSION <= MAX_SUPPORTED_CERTIFICATION_VERSION);
10770
}
71+
72+
#[test]
73+
fn convert_from_u32_succeeds_for_all_supported_certification_versions() {
74+
use strum::IntoEnumIterator;
75+
assert!(all_supported_versions().all(|v| (v as u32).try_into() == Ok(v)));
76+
// Old unsupported version should fail.
77+
let v = CertificationVersion::iter().next().unwrap() as u32 - 1;
78+
assert_eq!(
79+
CertificationVersion::try_from(v),
80+
Err(UnsupportedCertificationVersion(v))
81+
);
82+
// Non-existent version should fail.
83+
let v = CertificationVersion::iter().last().unwrap() as u32 + 1;
84+
assert_eq!(
85+
CertificationVersion::try_from(v),
86+
Err(UnsupportedCertificationVersion(v))
87+
);
88+
}

0 commit comments

Comments
 (0)