Skip to content

Commit 8b60fc2

Browse files
committed
Rename state_version to migrate_version
1 parent b96aa96 commit 8b60fc2

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

packages/derive/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Parse for Options {
106106
/// #
107107
/// # type MigrateMsg = ();
108108
/// #[entry_point]
109-
/// #[state_version(2)]
109+
/// #[migrate_version(2)]
110110
/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult<Response> {
111111
/// todo!();
112112
/// }
@@ -123,7 +123,7 @@ fn expand_attributes(func: &mut ItemFn) -> syn::Result<TokenStream> {
123123
let attributes = std::mem::take(&mut func.attrs);
124124
let mut stream = TokenStream::new();
125125
for attribute in attributes {
126-
if !attribute.path().is_ident("state_version") {
126+
if !attribute.path().is_ident("migrate_version") {
127127
func.attrs.push(attribute);
128128
continue;
129129
}
@@ -152,10 +152,10 @@ fn expand_attributes(func: &mut ItemFn) -> syn::Result<TokenStream> {
152152
#[allow(unused)]
153153
#[doc(hidden)]
154154
#[cfg(target_arch = "wasm32")]
155-
#[link_section = "cw_state_version"]
155+
#[link_section = "cw_migrate_version"]
156156
/// This is an internal constant exported as a custom section denoting the contract state version.
157157
/// The format and even the existence of this value is an implementation detail, DO NOT RELY ON THIS!
158-
static __CW_STATE_VERSION: &str = #version;
158+
static __CW_MIGRATE_VERSION: &str = #version;
159159
};
160160
}
161161

@@ -202,7 +202,7 @@ mod test {
202202
#[test]
203203
fn contract_state_zero_not_allowed() {
204204
let code = quote! {
205-
#[state_version(0)]
205+
#[migrate_version(0)]
206206
fn migrate() -> Response {
207207
// Logic here
208208
}
@@ -217,9 +217,9 @@ mod test {
217217
}
218218

219219
#[test]
220-
fn contract_state_version_on_non_migrate() {
220+
fn contract_migrate_version_on_non_migrate() {
221221
let code = quote! {
222-
#[state_version(42)]
222+
#[migrate_version(42)]
223223
fn anything_else() -> Response {
224224
// Logic here
225225
}
@@ -234,9 +234,9 @@ mod test {
234234
}
235235

236236
#[test]
237-
fn contract_state_version_in_u64() {
237+
fn contract_migrate_version_in_u64() {
238238
let code = quote! {
239-
#[state_version(0xDEAD_BEEF_FFFF_DEAD_2BAD)]
239+
#[migrate_version(0xDEAD_BEEF_FFFF_DEAD_2BAD)]
240240
fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Response {
241241
// Logic here
242242
}
@@ -251,9 +251,9 @@ mod test {
251251
}
252252

253253
#[test]
254-
fn contract_state_version_expansion() {
254+
fn contract_migrate_version_expansion() {
255255
let code = quote! {
256-
#[state_version(2)]
256+
#[migrate_version(2)]
257257
fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Response {
258258
// Logic here
259259
}
@@ -264,10 +264,10 @@ mod test {
264264
#[allow(unused)]
265265
#[doc(hidden)]
266266
#[cfg(target_arch = "wasm32")]
267-
#[link_section = "cw_state_version"]
267+
#[link_section = "cw_migrate_version"]
268268
/// This is an internal constant exported as a custom section denoting the contract state version.
269269
/// The format and even the existence of this value is an implementation detail, DO NOT RELY ON THIS!
270-
static __CW_STATE_VERSION: &str = "2";
270+
static __CW_MIGRATE_VERSION: &str = "2";
271271

272272
fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Response {
273273
// Logic here

packages/vm/src/cache.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub struct AnalysisReport {
134134
/// The set of capabilities the contract requires.
135135
pub required_capabilities: BTreeSet<String>,
136136
/// The contract state version exported set by the contract developer
137-
pub contract_state_version: Option<u64>,
137+
pub contract_migrate_version: Option<u64>,
138138
}
139139

140140
impl<A, S, Q> Cache<A, S, Q>
@@ -323,7 +323,7 @@ where
323323
required_capabilities: required_capabilities_from_module(&module)
324324
.into_iter()
325325
.collect(),
326-
contract_state_version: module.contract_state_version,
326+
contract_migrate_version: module.contract_migrate_version,
327327
})
328328
}
329329

@@ -1416,7 +1416,7 @@ mod tests {
14161416
E::Query
14171417
]),
14181418
required_capabilities: BTreeSet::new(),
1419-
contract_state_version: None,
1419+
contract_migrate_version: None,
14201420
}
14211421
);
14221422

@@ -1434,7 +1434,7 @@ mod tests {
14341434
"iterator".to_string(),
14351435
"stargate".to_string()
14361436
]),
1437-
contract_state_version: None,
1437+
contract_migrate_version: None,
14381438
}
14391439
);
14401440

@@ -1446,13 +1446,13 @@ mod tests {
14461446
has_ibc_entry_points: false,
14471447
entrypoints: BTreeSet::new(),
14481448
required_capabilities: BTreeSet::from(["iterator".to_string()]),
1449-
contract_state_version: None,
1449+
contract_migrate_version: None,
14501450
}
14511451
);
14521452

14531453
let mut wasm_with_version = EMPTY_CONTRACT.to_vec();
14541454
let custom_section = wasm_encoder::CustomSection {
1455-
name: Cow::Borrowed("cw_state_version"),
1455+
name: Cow::Borrowed("cw_migrate_version"),
14561456
data: Cow::Borrowed(b"21"),
14571457
};
14581458
custom_section.append_to_component(&mut wasm_with_version);
@@ -1465,7 +1465,7 @@ mod tests {
14651465
has_ibc_entry_points: false,
14661466
entrypoints: BTreeSet::new(),
14671467
required_capabilities: BTreeSet::from(["iterator".to_string()]),
1468-
contract_state_version: Some(21),
1468+
contract_migrate_version: Some(21),
14691469
}
14701470
);
14711471
}

packages/vm/src/parsed_wasm.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct ParsedWasm<'a> {
6767
/// Collections of functions that are potentially pending validation
6868
pub func_validator: FunctionValidator<'a>,
6969
/// Contract state version as defined in a custom section
70-
pub contract_state_version: Option<u64>,
70+
pub contract_migrate_version: Option<u64>,
7171
}
7272

7373
impl<'a> ParsedWasm<'a> {
@@ -110,7 +110,7 @@ impl<'a> ParsedWasm<'a> {
110110
max_func_results: 0,
111111
total_func_params: 0,
112112
func_validator: FunctionValidator::Pending(OpaqueDebug::default()),
113-
contract_state_version: None,
113+
contract_migrate_version: None,
114114
};
115115

116116
for p in Parser::new(0).parse_all(wasm) {
@@ -182,12 +182,12 @@ impl<'a> ParsedWasm<'a> {
182182
Payload::ExportSection(e) => {
183183
this.exports = e.into_iter().collect::<Result<Vec<_>, _>>()?;
184184
}
185-
Payload::CustomSection(reader) if reader.name() == "cw_state_version" => {
185+
Payload::CustomSection(reader) if reader.name() == "cw_migrate_version" => {
186186
// This is supposed to be valid UTF-8
187187
let raw_version = str::from_utf8(reader.data())
188188
.map_err(|err| VmError::static_validation_err(err.to_string()))?;
189189

190-
this.contract_state_version = Some(
190+
this.contract_migrate_version = Some(
191191
raw_version
192192
.parse::<u64>()
193193
.map_err(|err| VmError::static_validation_err(err.to_string()))?,
@@ -234,18 +234,19 @@ mod test {
234234
use super::ParsedWasm;
235235

236236
#[test]
237-
fn read_state_version() {
237+
fn read_migrate_version() {
238238
let wasm_data =
239-
wat::parse_str(r#"( module ( @custom "cw_state_version" "42" ) )"#).unwrap();
239+
wat::parse_str(r#"( module ( @custom "cw_migrate_version" "42" ) )"#).unwrap();
240240
let parsed = ParsedWasm::parse(&wasm_data).unwrap();
241241

242-
assert_eq!(parsed.contract_state_version, Some(42));
242+
assert_eq!(parsed.contract_migrate_version, Some(42));
243243
}
244244

245245
#[test]
246-
fn read_state_version_fails() {
246+
fn read_migrate_version_fails() {
247247
let wasm_data =
248-
wat::parse_str(r#"( module ( @custom "cw_state_version" "not a number" ) )"#).unwrap();
248+
wat::parse_str(r#"( module ( @custom "cw_migrate_version" "not a number" ) )"#)
249+
.unwrap();
249250
assert!(ParsedWasm::parse(&wasm_data).is_err());
250251
}
251252
}

0 commit comments

Comments
 (0)