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

tgrade-valset migrate contract update #186

Merged
merged 4 commits into from
Sep 19, 2022
Merged
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
13 changes: 5 additions & 8 deletions contracts/tgrade-valset/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use tg_bindings::{
use tg_utils::{Duration, JailingDuration, SlashMsg, ADMIN};

use crate::error::ContractError;
use crate::migration::{migrate_jailing_period, migrate_verify_validators};
use crate::msg::{
EpochResponse, ExecuteMsg, InstantiateMsg, InstantiateResponse, JailingEnd, JailingPeriod,
ListActiveValidatorsResponse, ListValidatorResponse, ListValidatorSlashingResponse, MigrateMsg,
Expand Down Expand Up @@ -983,12 +982,11 @@ fn calculate_diff(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(
mut deps: DepsMut<TgradeQuery>,
deps: DepsMut<TgradeQuery>,
_env: Env,
msg: MigrateMsg,
) -> Result<Response, ContractError> {
let original_version =
ensure_from_older_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
ensure_from_older_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

CONFIG.update::<_, StdError>(deps.storage, |mut cfg| {
if let Some(min_points) = msg.min_points {
Expand All @@ -997,16 +995,15 @@ pub fn migrate(
if let Some(max_validators) = msg.max_validators {
cfg.max_validators = max_validators;
}
if let Some(distribution_contracts) = msg.distribution_contracts {
cfg.distribution_contracts = distribution_contracts;
}
if let Some(verify_validators) = msg.verify_validators {
cfg.verify_validators = verify_validators;
}
Ok(cfg)
})?;

migrate_jailing_period(deps.branch(), &original_version)?;

migrate_verify_validators(deps.branch(), &original_version)?;

Ok(Response::new())
}

Expand Down
1 change: 0 additions & 1 deletion contracts/tgrade-valset/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod contract;
pub mod error;
mod migration;
pub mod msg;
#[cfg(test)]
mod multitest;
Expand Down
139 changes: 0 additions & 139 deletions contracts/tgrade-valset/src/migration.rs

This file was deleted.

1 change: 1 addition & 0 deletions contracts/tgrade-valset/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ pub struct InstantiateResponse {
pub struct MigrateMsg {
pub min_points: Option<u64>,
pub max_validators: Option<u32>,
pub distribution_contracts: Option<Vec<DistributionContract>>,
pub verify_validators: Option<bool>,
}

Expand Down
14 changes: 14 additions & 0 deletions contracts/tgrade-valset/src/multitest/migration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::suite::SuiteBuilder;
use crate::msg::MigrateMsg;
use crate::state::DistributionContract;
use cosmwasm_std::{Addr, Decimal};

#[test]
fn migration_can_alter_cfg() {
Expand All @@ -19,6 +21,10 @@ fn migration_can_alter_cfg() {
&MigrateMsg {
min_points: Some(5),
max_validators: Some(10),
distribution_contracts: Some(vec![DistributionContract {
contract: Addr::unchecked("engagement1".to_string()),
ratio: Decimal::percent(50),
}]),
verify_validators: Some(true),
},
)
Expand All @@ -27,4 +33,12 @@ fn migration_can_alter_cfg() {
let cfg = suite.config().unwrap();
assert_eq!(cfg.max_validators, 10);
assert_eq!(cfg.min_points, 5);
assert!(cfg.verify_validators);
assert_eq!(
cfg.distribution_contracts,
vec![DistributionContract {
contract: Addr::unchecked("engagement1".to_string()),
ratio: Decimal::percent(50),
}]
);
}