Skip to content

Commit

Permalink
Check contract and version during migration and set version to 0.3.1 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll authored Sep 3, 2024
1 parent 3593087 commit 8f5d2cb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion smart-contracts/osmosis/contracts/cl-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["LaurensKubat <[email protected]>"]
edition = "2021"
name = "cl-vault"
version = "0.3.0"
version = "0.3.1"

exclude = [
"cl_vault.wasm",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "cl-vault",
"contract_version": "0.3.0",
"contract_version": "0.3.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
19 changes: 15 additions & 4 deletions smart-contracts/osmosis/contracts/cl-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
cw2::assert_contract_version(deps.storage, CONTRACT_NAME, "0.3.0")?;
let previous_version =
cw2::ensure_from_older_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
let dex_router_item: Item<Addr> = Item::new("dex_router");
dex_router_item.remove(deps.storage);
// VaultConfig
Expand Down Expand Up @@ -246,7 +249,10 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, Co
pub const USER_REWARDS: Map<Addr, CoinList> = Map::new("user_rewards");
USER_REWARDS.clear(deps.storage);

let response = Response::new().add_attribute("migrate", "successful");
let response = Response::new()
.add_attribute("migrate", "successful")
.add_attribute("previous version", previous_version.to_string())
.add_attribute("new version", CONTRACT_VERSION);
Ok(response)
}

Expand All @@ -260,6 +266,7 @@ mod tests {
fn test_migrate() {
let env = mock_env();
let mut deps = mock_dependencies();
assert!(set_contract_version(deps.as_mut().storage, CONTRACT_NAME, "0.3.0").is_ok());

// VaultConfig mocking
#[cw_serde]
Expand All @@ -272,7 +279,7 @@ mod tests {
const OLD_VAULT_CONFIG: Item<OldVaultConfig> = Item::new("vault_config_v2");
OLD_VAULT_CONFIG
.save(
&mut deps.storage,
deps.as_mut().storage,
&OldVaultConfig {
performance_fee: Decimal::percent(1),
treasury: Addr::unchecked("treasury"),
Expand All @@ -290,13 +297,17 @@ mod tests {
}
pub const MIGRATION_STATUS: Item<MigrationStatus> = Item::new("migration_status");
MIGRATION_STATUS
.save(&mut deps.storage, &MigrationStatus::Closed)
.save(deps.as_mut().storage, &MigrationStatus::Closed)
.unwrap();

// UserRewards mocking
pub const USER_REWARDS: Map<Addr, CoinList> = Map::new("user_rewards");
USER_REWARDS
.save(&mut deps.storage, Addr::unchecked("user"), &CoinList::new())
.save(
deps.as_mut().storage,
Addr::unchecked("user"),
&CoinList::new(),
)
.unwrap();

// Migrate and assert new states
Expand Down
4 changes: 4 additions & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cosmwasm_std::{
CoinFromStrError, ConversionOverflowError, Decimal, Decimal256, Decimal256RangeExceeded,
DecimalRangeExceeded, DivideByZeroError, OverflowError, StdError, Storage, Uint128,
};
use cw2::VersionError;
use cw_utils::PaymentError;
use prost::DecodeError;
use quasar_types::pool_pair::PoolPairError;
Expand Down Expand Up @@ -162,6 +163,9 @@ pub enum ContractError {

#[error("{0}")]
PoolPair(#[from] PoolPairError),

#[error("{0}")]
Version(#[from] VersionError),
}

pub fn assert_deposits(funds: &[Coin], config: &PoolConfig) -> Result<(), ContractError> {
Expand Down

0 comments on commit 8f5d2cb

Please sign in to comment.