@@ -2,43 +2,6 @@ use strum_macros::{EnumCount, EnumIter};
2
2
3
3
#[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Debug , EnumCount , EnumIter ) ]
4
4
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 ,
42
5
/// Added `flags` to `StreamHeader`. Defined `StreamHeaderFlagBits::ResponsesOnly` flag.
43
6
V17 = 17 ,
44
7
/// Added `deadline` fields to `Request` and `Response`.
@@ -69,9 +32,8 @@ impl std::convert::TryFrom<u32> for CertificationVersion {
69
32
type Error = UnsupportedCertificationVersion ;
70
33
71
34
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)
75
37
. ok_or ( UnsupportedCertificationVersion ( n) )
76
38
}
77
39
}
@@ -92,7 +54,8 @@ pub const MIN_SUPPORTED_CERTIFICATION_VERSION: CertificationVersion = Certificat
92
54
/// this.
93
55
pub const MAX_SUPPORTED_CERTIFICATION_VERSION : CertificationVersion = CertificationVersion :: V19 ;
94
56
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`.
96
59
pub fn all_supported_versions ( ) -> impl std:: iter:: Iterator < Item = CertificationVersion > {
97
60
use strum:: IntoEnumIterator ;
98
61
CertificationVersion :: iter ( ) . filter ( |v| {
@@ -105,3 +68,21 @@ fn version_constants_consistent() {
105
68
assert ! ( MIN_SUPPORTED_CERTIFICATION_VERSION <= CURRENT_CERTIFICATION_VERSION ) ;
106
69
assert ! ( CURRENT_CERTIFICATION_VERSION <= MAX_SUPPORTED_CERTIFICATION_VERSION ) ;
107
70
}
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