@@ -89,18 +89,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
89
89
#[ allow( clippy:: pedantic) ]
90
90
pub fn migrate ( deps : DepsMut , _env : Env , _msg : MigrateMsg ) -> Result < Response , ContractError > {
91
91
migrate:: validate_semver ( deps. as_ref ( ) ) ?;
92
-
93
- // Reject the migration if the channel encoding is not protobuf
94
- if let Some ( ica_info) = state:: STATE . load ( deps. storage ) ?. ica_info {
95
- if !matches ! (
96
- ica_info. encoding,
97
- crate :: ibc:: types:: metadata:: TxEncoding :: Protobuf
98
- ) {
99
- return Err ( ContractError :: UnsupportedPacketEncoding (
100
- ica_info. encoding . to_string ( ) ,
101
- ) ) ;
102
- }
103
- }
92
+ migrate:: validate_channel_encoding ( deps. as_ref ( ) ) ?;
104
93
105
94
cw2:: set_contract_version ( deps. storage , keys:: CONTRACT_NAME , keys:: CONTRACT_VERSION ) ?;
106
95
// If state structure changed in any contract version in the way migration is needed, it
@@ -255,8 +244,10 @@ mod query {
255
244
}
256
245
257
246
mod migrate {
258
- use super :: { keys, ContractError , Deps } ;
247
+ use super :: { keys, state , ContractError , Deps } ;
259
248
249
+ /// Validate that the contract version is semver compliant
250
+ /// and greater than the previous version.
260
251
pub fn validate_semver ( deps : Deps ) -> Result < ( ) , ContractError > {
261
252
let prev_cw2_version = cw2:: get_contract_version ( deps. storage ) ?;
262
253
if prev_cw2_version. contract != keys:: CONTRACT_NAME {
@@ -276,6 +267,23 @@ mod migrate {
276
267
}
277
268
Ok ( ( ) )
278
269
}
270
+
271
+ /// Validate that the channel encoding is protobuf if set.
272
+ pub fn validate_channel_encoding ( deps : Deps ) -> Result < ( ) , ContractError > {
273
+ // Reject the migration if the channel encoding is not protobuf
274
+ if let Some ( ica_info) = state:: STATE . load ( deps. storage ) ?. ica_info {
275
+ if !matches ! (
276
+ ica_info. encoding,
277
+ crate :: ibc:: types:: metadata:: TxEncoding :: Protobuf
278
+ ) {
279
+ return Err ( ContractError :: UnsupportedPacketEncoding (
280
+ ica_info. encoding . to_string ( ) ,
281
+ ) ) ;
282
+ }
283
+ }
284
+
285
+ Ok ( ( ) )
286
+ }
279
287
}
280
288
281
289
#[ cfg( test) ]
@@ -495,7 +503,14 @@ mod tests {
495
503
. unwrap ( ) ;
496
504
497
505
// Migration should fail because the encoding is not protobuf
498
- let _err = migrate ( deps. as_mut ( ) , mock_env ( ) , MigrateMsg { } ) . unwrap_err ( ) ;
506
+ let err = migrate ( deps. as_mut ( ) , mock_env ( ) , MigrateMsg { } ) . unwrap_err ( ) ;
507
+ assert_eq ! (
508
+ err. to_string( ) ,
509
+ ContractError :: UnsupportedPacketEncoding (
510
+ crate :: ibc:: types:: metadata:: TxEncoding :: Proto3Json . to_string( )
511
+ )
512
+ . to_string( )
513
+ ) ;
499
514
500
515
// Set the encoding to protobuf
501
516
state:: STATE
0 commit comments