From 835d4f46f649d767abdffdc58826b78bc06e2d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 11 Jan 2022 16:31:39 +0000 Subject: [PATCH] Introduced denom check when trying to withdraw vested coins (#1018) * Introduced denom check when trying to withdraw vested coins * Using correct denom in the relevant unit test --- contracts/vesting/src/contract.rs | 4 ++++ contracts/vesting/src/errors.rs | 6 +++--- contracts/vesting/src/vesting/mod.rs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/contracts/vesting/src/contract.rs b/contracts/vesting/src/contract.rs index 44a68ae853..999f2eb95b 100644 --- a/contracts/vesting/src/contract.rs +++ b/contracts/vesting/src/contract.rs @@ -96,6 +96,10 @@ pub fn try_withdraw_vested_coins( info: MessageInfo, deps: DepsMut, ) -> Result { + if amount.denom != DENOM { + return Err(ContractError::WrongDenom(amount.denom, DENOM.to_string())); + } + let address = info.sender.clone(); let account = account_from_address(info.sender.as_str(), deps.storage, deps.api)?; if address != account.owner_address() { diff --git a/contracts/vesting/src/errors.rs b/contracts/vesting/src/errors.rs index 3651ac48b5..c9faef420a 100644 --- a/contracts/vesting/src/errors.rs +++ b/contracts/vesting/src/errors.rs @@ -24,11 +24,11 @@ pub enum ContractError { ImprobableVestingAmount(u128), #[error("Address {0} has already bonded a node")] AlreadyBonded(String), - #[error("Recieved empty funds vector")] + #[error("Received empty funds vector")] EmptyFunds, - #[error("Recieved wrong denom: {0}, expected {1}")] + #[error("Received wrong denom: {0}, expected {1}")] WrongDenom(String, String), - #[error("Recieved multiple denoms, expected 1")] + #[error("Received multiple denoms, expected 1")] MultipleDenoms, #[error("No delegations found for account {0}, mix_identity {1}")] NoSuchDelegation(Addr, IdentityKey), diff --git a/contracts/vesting/src/vesting/mod.rs b/contracts/vesting/src/vesting/mod.rs index ef4551c11f..1c4b0a6ca5 100644 --- a/contracts/vesting/src/vesting/mod.rs +++ b/contracts/vesting/src/vesting/mod.rs @@ -124,7 +124,7 @@ mod tests { let msg = ExecuteMsg::WithdrawVestedCoins { amount: Coin { amount: Uint128::new(1), - denom: "nym".to_string(), + denom: DENOM.to_string(), }, }; let info = mock_info("new_owner", &[]);