multiversx_sc_meta_lib/
version_history.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
use crate::{framework_version, framework_versions, version::FrameworkVersion};

/// The last version to be used for upgrades and templates.
///
/// Should be edited every time a new version of the framework is released.
pub const LAST_VERSION: FrameworkVersion = framework_version!(0.55.0);

/// Indicates where to stop with the upgrades.
pub const LAST_UPGRADE_VERSION: FrameworkVersion = LAST_VERSION;

pub const LAST_TEMPLATE_VERSION: FrameworkVersion = LAST_VERSION;

#[rustfmt::skip]
/// Known versions for the upgrader.
pub const VERSIONS: &[FrameworkVersion] = framework_versions![
    0.28.0, 
    0.29.0, 
    0.29.2, 
    0.29.3, 
    0.30.0, 
    0.31.0, 
    0.31.1, 
    0.32.0, 
    0.33.0, 
    0.33.1, 
    0.34.0, 
    0.34.1,
    0.35.0, 
    0.36.0, 
    0.36.1, 
    0.37.0, 
    0.38.0, 
    0.39.0, 
    0.39.1, 
    0.39.2, 
    0.39.3, 
    0.39.4, 
    0.39.5, 
    0.39.6,
    0.39.7, 
    0.39.8, 
    0.40.0, 
    0.40.1, 
    0.41.0, 
    0.41.1, 
    0.41.2, 
    0.41.3, 
    0.42.0, 
    0.43.0, 
    0.43.1, 
    0.43.2,
    0.43.3, 
    0.43.4, 
    0.43.5, 
    0.44.0, 
    0.45.0, 
    0.45.2,
    0.46.0,
    0.46.1,
    0.47.0,
    0.47.1,
    0.47.2,
    0.47.3,
    0.47.4,
    0.47.5,
    0.47.6,
    0.47.7,
    0.47.8,
    0.48.0,
    0.48.1,
    0.49.0,
    0.50.0,
    0.50.1,
    0.50.2,
    0.50.3,
    0.50.4,
    0.50.5,
    0.50.6,
    0.51.0,
    0.51.1,
    0.52.0,
    0.52.1,
    0.52.2,
    0.52.3,
    0.53.0,
    0.53.1,
    0.53.2,
    0.54.0,
    0.54.1,
    0.54.2,
    0.54.3,
    0.54.4,
    0.54.5,
    0.54.6,
    0.55.0,
];

#[rustfmt::skip]
pub const CHECK_AFTER_UPGRADE_TO: &[FrameworkVersion] = framework_versions![
    0.28.0,
    0.29.0,
    0.30.0,
    0.31.0,
    0.32.0,
    0.33.0,
    0.34.0,
    0.35.0,
    0.36.0,
    0.37.0,
    0.40.0,
    0.41.0,
    0.42.0,
    0.43.0,
    0.44.0,
    0.45.2,
    0.46.0,
    0.47.0,
    0.49.0,
    0.50.6,
    0.51.1,
    0.52.3,
    0.53.2,
    0.54.6,
    0.55.0,
];

pub const LOWER_VERSION_WITH_TEMPLATE_TAG: FrameworkVersion = framework_version!(0.43.0);
pub const LOWER_VERSION_WITH_AUTOGENERATED_JSON: FrameworkVersion = framework_version!(0.44.0);
pub const LOWER_VERSION_WITH_AUTOGENERATED_WASM: FrameworkVersion = framework_version!(0.45.0);

pub fn parse_known_version(tag_str: &str) -> FrameworkVersion {
    let tag: FrameworkVersion = FrameworkVersion::from_string_template(tag_str);
    if VERSIONS.contains(&tag) {
        tag
    } else {
        panic!("Version unknown")
    }
}

/// We started supporting contract templates with version 0.43.0.
pub fn validate_template_tag(tag_str: &str) -> bool {
    let tag: FrameworkVersion = parse_known_version(tag_str);

    tag >= LOWER_VERSION_WITH_TEMPLATE_TAG
}

pub fn is_template_with_autogenerated_wasm(tag: FrameworkVersion) -> bool {
    tag >= LOWER_VERSION_WITH_AUTOGENERATED_WASM
}

pub fn is_template_with_autogenerated_json(tag: FrameworkVersion) -> bool {
    tag >= LOWER_VERSION_WITH_AUTOGENERATED_JSON
}

pub fn find_version_by_str(tag: &str) -> Option<&FrameworkVersion> {
    VERSIONS.iter().find(|&v| v.to_string() == tag)
}

pub struct VersionIterator {
    next_version: usize,
    last_version: FrameworkVersion,
}

impl VersionIterator {
    fn is_last_version(&self, version: &FrameworkVersion) -> bool {
        self.last_version == *version
    }
}

impl Iterator for VersionIterator {
    type Item = (&'static FrameworkVersion, &'static FrameworkVersion);

    fn next(&mut self) -> Option<Self::Item> {
        if self.next_version > 0 && self.next_version < VERSIONS.len() {
            let from_version = &VERSIONS[self.next_version - 1];

            if self.is_last_version(from_version) {
                None
            } else {
                let to_version = &VERSIONS[self.next_version];
                let result = (from_version, to_version);
                self.next_version += 1;
                Some(result)
            }
        } else {
            None
        }
    }
}

pub fn versions_iter(last_version: FrameworkVersion) -> VersionIterator {
    VersionIterator {
        next_version: 1,
        last_version,
    }
}

#[cfg(test)]
pub mod tests {

    use crate::version::is_sorted;

    use super::*;

    #[test]
    fn compare_versions_test() {
        let f1: FrameworkVersion = framework_version!(0.44.0);
        let f2: FrameworkVersion = framework_version!(0.41.2);

        assert!(f1 > f2);
    }

    #[test]
    fn framework_version_display_test() {
        assert_eq!(format!("Framework: {}", VERSIONS[0]), "Framework: 0.28.0");
    }

    #[test]
    fn template_versions_test() {
        assert!(validate_template_tag("0.43.0"));
        assert!(!validate_template_tag("0.42.0"));
    }

    #[test]
    fn template_versions_with_autogenerated_wasm_test() {
        assert!(is_template_with_autogenerated_wasm(framework_version!(
            0.45.0
        )));
        assert!(!is_template_with_autogenerated_wasm(framework_version!(
            0.44.0
        )));
    }

    #[test]
    fn template_versions_with_autogenerated_json_test() {
        assert!(is_template_with_autogenerated_json(framework_version!(
            0.44.0
        )));
        assert!(!is_template_with_autogenerated_json(framework_version!(
            0.43.0
        )));
    }

    #[test]
    fn find_version_by_str_test() {
        let version = find_version_by_str("0.28.0");
        match version {
            Some(v) => assert_eq!(VERSIONS[0], *v),
            None => unreachable!(),
        }
    }

    #[test]
    fn framework_version_test() {
        assert!(is_sorted(VERSIONS));
    }
}