Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gateway): update migration handler #714

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 2 additions & 0 deletions contracts/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ gateway-api = { workspace = true }
itertools = { workspace = true }
report = { workspace = true }
router-api = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
voting-verifier = { workspace = true, features = ["library"] }

[dev-dependencies]
assert_ok = { workspace = true }
cw-multi-test = "0.15.1"
rand = { workspace = true }

Expand Down
51 changes: 47 additions & 4 deletions contracts/gateway/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
use axelar_wasm_std::{address, FnExt};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response};
use error_stack::ResultExt;
use cosmwasm_std::{ensure, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response};
use cw2::VersionError;
use error_stack::{report, ResultExt};
use router_api::client::Router;
use semver::Version;

use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state;
Expand All @@ -17,7 +19,6 @@

const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
const BASE_VERSION: &str = "1.0.0";

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -45,7 +46,15 @@
_env: Env,
_msg: Empty,
) -> Result<Response, axelar_wasm_std::error::ContractError> {
cw2::assert_contract_version(deps.storage, CONTRACT_NAME, BASE_VERSION)?;
let old_version = Version::parse(&cw2::get_contract_version(deps.storage)?.version)?;
ensure!(
old_version.major == 1 && old_version.minor == 1,
report!(VersionError::WrongVersion {
expected: "1.1.x".into(),
found: old_version.to_string()
})

Check warning on line 55 in contracts/gateway/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/gateway/src/contract.rs#L52-L55

Added lines #L52 - L55 were not covered by tests
);

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

Ok(Response::default())
Expand Down Expand Up @@ -110,3 +119,37 @@
}?
.then(Ok)
}

#[cfg(test)]
mod test {
use assert_ok::assert_ok;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{Addr, Empty};

use crate::contract::{instantiate, migrate, CONTRACT_NAME, CONTRACT_VERSION};
use crate::msg::InstantiateMsg;

#[test]
fn migrate_sets_contract_version() {
let mut deps = mock_dependencies();
let env = mock_env();
let info = mock_info("sender", &[]);
let instantiate_msg = InstantiateMsg {
verifier_address: Addr::unchecked("verifier").to_string(),
router_address: Addr::unchecked("router").to_string(),
};

assert_ok!(instantiate(
deps.as_mut(),
env.clone(),
info.clone(),
instantiate_msg
));

migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();

let contract_version = cw2::get_contract_version(deps.as_mut().storage).unwrap();
assert_eq!(contract_version.contract, CONTRACT_NAME);
assert_eq!(contract_version.version, CONTRACT_VERSION);
}
}
Loading