Skip to content

Commit

Permalink
disable vesting token mutation once set
Browse files Browse the repository at this point in the history
  • Loading branch information
sotnikov-s committed Oct 2, 2023
1 parent c5d4667 commit e7eec41
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/vesting-base/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub enum ContractError {

#[error("Vesting token is not set!")]
VestingTokenIsNotSet {},

#[error("Vesting token is already set!")]
VestingTokenAlreadySet {},
}

impl From<OverflowError> for ContractError {
Expand Down
14 changes: 11 additions & 3 deletions packages/vesting-base/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,19 @@ pub(crate) fn set_vesting_token(
if info.sender != config.owner && info.sender != config.token_info_manager {
return Err(ContractError::Unauthorized {});
}
token.check(deps.api)?;
config.vesting_token = Some(token);
if config.vesting_token.is_some() {
return Err(ContractError::VestingTokenAlreadySet {});
}

token.check(deps.api)?;
config.vesting_token = Some(token.clone());
CONFIG.save(deps.storage, &config)?;
Ok(Response::new())

let response = Response::new();
Ok(response.add_attributes(vec![
attr("action", "set_vesting_token"),
attr("vesting_token", token.to_string()),
]))
}

pub(crate) fn get_vesting_token(config: &Config) -> Result<AssetInfo, ContractError> {
Expand Down
31 changes: 30 additions & 1 deletion packages/vesting-base/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,42 @@ fn set_vesting_token() {
execute(
deps.as_mut(),
env.clone(),
info,
info.clone(),
ExecuteMsg::SetVestingToken {
vesting_token: token_asset_info(Addr::unchecked("ntrn_token")),
},
)
.unwrap();

assert_eq!(
from_binary::<Config>(&query(deps.as_ref(), env.clone(), QueryMsg::Config {}).unwrap())
.unwrap(),
Config {
owner: Addr::unchecked("owner"),
token_info_manager: Addr::unchecked(token_info_manager),
vesting_token: Some(token_asset_info(Addr::unchecked("ntrn_token"))),
extensions: Extensions {
historical: false,
managed: false,
with_managers: false
}
}
);

// set vesting token second time by the owner -> VestingTokenAlreadySet
assert_eq!(
execute(
deps.as_mut(),
env.clone(),
info,
ExecuteMsg::SetVestingToken {
vesting_token: token_asset_info(Addr::unchecked("not_a_ntrn_token")),
},
)
.unwrap_err(),
ContractError::VestingTokenAlreadySet {},
);

assert_eq!(
from_binary::<Config>(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(),
Config {
Expand Down

0 comments on commit e7eec41

Please sign in to comment.