Skip to content

Commit

Permalink
fix(multisig-prover): update migration version check
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcobb23 committed Nov 26, 2024
1 parent 7d715f8 commit a5fb9f2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ rewards = { version = "^1.2.0", path = "contracts/rewards" }
router = { version = "^1.1.0", path = "contracts/router" }
router-api = { version = "^1.0.0", path = "packages/router-api" }
schemars = "0.8.10"
semver = "1.0"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
serde_json = "1.0.89"
service-registry = { version = "^1.1.0", path = "contracts/service-registry" }
Expand Down
1 change: 1 addition & 0 deletions contracts/multisig-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ msgs-derive = { workspace = true }
multisig = { workspace = true, features = ["library"] }
report = { workspace = true }
router-api = { workspace = true }
semver = { workspace = true }
serde_json = "1.0.89"
service-registry = { workspace = true }
service-registry-api = { workspace = true }
Expand Down
11 changes: 4 additions & 7 deletions contracts/multisig-prover/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cosmwasm_std::{
to_json_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response,
};
use error_stack::ResultExt;
use semver::{Version, VersionReq};

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
Expand Down Expand Up @@ -116,19 +117,15 @@ pub fn query(
.map_err(axelar_wasm_std::error::ContractError::from)
}

// It is valid to migrate from any of the below versions
const BASE_VERSION: &str = "1.1.0";
const OLD_BASE_VERSION: &str = "1.0.0";
const PATCH_VERSION: &str = "1.0.1";
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(
deps: DepsMut,
_env: Env,
_msg: Empty,
) -> Result<Response, axelar_wasm_std::error::ContractError> {
cw2::assert_contract_version(deps.storage, CONTRACT_NAME, BASE_VERSION)
.or_else(|_| cw2::assert_contract_version(deps.storage, CONTRACT_NAME, PATCH_VERSION))
.or_else(|_| cw2::assert_contract_version(deps.storage, CONTRACT_NAME, OLD_BASE_VERSION))?;
let old_version = Version::parse(&cw2::get_contract_version(deps.storage)?.version)?;
let version_requirement = VersionReq::parse(">= 1.1.0, < 1.2.0")?;
assert!(version_requirement.matches(&old_version));

cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Expand Down
1 change: 1 addition & 0 deletions packages/axelar-wasm-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ num-traits = { workspace = true }
regex = { version = "1.10.0", default-features = false, features = ["perf", "std"] }
report = { workspace = true }
schemars = "0.8.10"
semver = { workspace = true }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
serde_json = "1.0.89"
serde_with = { version = "3.11.0", features = ["macros"] }
Expand Down
8 changes: 8 additions & 0 deletions packages/axelar-wasm-std/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ impl From<cw2::VersionError> for ContractError {
}
}

impl From<semver::Error> for ContractError {
fn from(err: semver::Error) -> Self {
ContractError {
report: report!(err).change_context(Error::Report),
}
}

Check warning on line 47 in packages/axelar-wasm-std/src/error.rs

View check run for this annotation

Codecov / codecov/patch

packages/axelar-wasm-std/src/error.rs#L43-L47

Added lines #L43 - L47 were not covered by tests
}

impl From<permission_control::Error> for ContractError {
fn from(err: permission_control::Error) -> Self {
ContractError {
Expand Down

0 comments on commit a5fb9f2

Please sign in to comment.