Skip to content

Commit

Permalink
fix(token-vesting): assert deposit amount (#86)
Browse files Browse the repository at this point in the history
* fix(token-vesting): assert deposit amount

* test: deposit amount different than vesting amount

* build: re-compile contracts

---------

Co-authored-by: Unique-Divine <realuniquedivine@gmail.com>
  • Loading branch information
k-yang and Unique-Divine authored Nov 1, 2023
1 parent ac45814 commit 2fc3a13
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ec6cc298bf32cad7f5f426002fdcee602b133f24f6f7d65905c5aad0e3b777c9 incentives.was
d2dfc9ed4a689a8b23b020421c7e3fc0a90fd985c1291a44659073cc9021bb38 nibi_stargate.wasm
bbb9c32c863ff78366ac5bae241967b206a6ad463e0154e7081309ab36904dce pricefeed.wasm
8014645275544b90c2ae33002e30c6cce6859dcd1193a48c599bedf4fb1015e3 shifter.wasm
0e4db7a116f27db4973e46db4a9cdd60abde1fb3e0dfeb7b1d5d9197c788229b token_vesting.wasm
27b401ca6e918bec98ec1e8e98dcb9f4de25191e1a53c34c4ceae6d4847b3b31 token_vesting.wasm
2 changes: 1 addition & 1 deletion artifacts/checksums_intermediate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ f95b4a566d319f6cf39de88d168c19134bdff3864916c48c71a9a7f2d4474ee2 target/wasm32-
516fc6e8ca410041834e807cfed96478b51805d5c112bdd520bfd32e0f55eb4b target/wasm32-unknown-unknown/release/controller.wasm
ae4e6405de49a97cde63c7d8abb88a77b8dcb8211759dc22ecab61b8e98f8519 target/wasm32-unknown-unknown/release/nibi_stargate.wasm
4a9bc648eaa78b691e286108dcf57111b1325c8df4c59366532b19cf80bac782 target/wasm32-unknown-unknown/release/shifter.wasm
b457a863837b7f4e93a322e9cc90887bd6b6d51f88efd0be50d9d52ee5a8c2d0 target/wasm32-unknown-unknown/release/token_vesting.wasm
f781a92390f4b89086310d79f20d9c81ce0aaa8865fb5811150244db483785f5 target/wasm32-unknown-unknown/release/token_vesting.wasm
Binary file modified artifacts/token_vesting.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions contracts/token-vesting/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ impl VestingSchedule {
});
}

if vesting_amount != deposit_amount {
return Err(
VestingError::MismatchedVestingAndDepositAmount {
vesting_amount: vesting_amount.u128(),
deposit_amount: deposit_amount.u128(),
},
);
}

let cliff = Cliff {
amount: *cliff_amount,
time: *cliff_time,
Expand Down
28 changes: 27 additions & 1 deletion contracts/token-vesting/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::msg::{
};

use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage};
use cosmwasm_std::MessageInfo;
use cosmwasm_std::{
from_binary,
testing::{mock_dependencies, mock_env, mock_info},
Expand Down Expand Up @@ -64,6 +65,7 @@ fn register_cliff_vesting_account_with_native_token() -> TestResult {
require_error(
&mut deps,
&env,
mock_info("addr0000", &[Coin::new(0u128, "uusd")]),
msg,
ContractError::Vesting(VestingError::ZeroVestingAmount),
);
Expand All @@ -73,6 +75,7 @@ fn register_cliff_vesting_account_with_native_token() -> TestResult {
require_error(
&mut deps,
&env,
mock_info("addr0000", &[Coin::new(1000u128, "uusd")]),
msg,
ContractError::Vesting(VestingError::Cliff(CliffError::ZeroAmount)),
);
Expand All @@ -82,6 +85,7 @@ fn register_cliff_vesting_account_with_native_token() -> TestResult {
require_error(
&mut deps,
&env,
mock_info("addr0000", &[Coin::new(1000u128, "uusd")]),
msg,
ContractError::Vesting(VestingError::Cliff(CliffError::InvalidTime {
cliff_time: 99,
Expand All @@ -94,6 +98,7 @@ fn register_cliff_vesting_account_with_native_token() -> TestResult {
require_error(
&mut deps,
&env,
mock_info("addr0000", &[Coin::new(1000u128, "uusd")]),
msg,
ContractError::Vesting(VestingError::InvalidTimeRange {
start_time: 110,
Expand All @@ -106,6 +111,7 @@ fn register_cliff_vesting_account_with_native_token() -> TestResult {
require_error(
&mut deps,
&env,
mock_info("addr0000", &[Coin::new(1000u128, "uusd")]),
msg,
ContractError::Vesting(VestingError::StartBeforeBlockTime {
start_time: 99,
Expand All @@ -119,6 +125,7 @@ fn register_cliff_vesting_account_with_native_token() -> TestResult {
require_error(
&mut deps,
&env,
mock_info("addr0000", &[Coin::new(1000u128, "uusd")]),
msg,
ContractError::Vesting(
CliffError::ExcessiveAmount {
Expand All @@ -128,16 +135,34 @@ fn register_cliff_vesting_account_with_native_token() -> TestResult {
.into(),
),
);

// deposit amount different than vesting amount
let (vesting_amount, cliff_amount, cliff_time) = (1000, 250, 105);
let msg = create_msg(100, 110, vesting_amount, cliff_amount, cliff_time);
require_error(
&mut deps,
&env,
mock_info("addr0000", &[Coin::new(999u128, "uusd")]),
msg,
ContractError::Vesting(
VestingError::MismatchedVestingAndDepositAmount {
vesting_amount: 1000u128,
deposit_amount: 999u128,
}
.into(),
),
);

Ok(())
}

fn require_error(
deps: &mut OwnedDeps<MockStorage, MockApi, MockQuerier>,
env: &Env,
info: MessageInfo,
msg: ExecuteMsg,
expected_error: ContractError,
) {
let info = mock_info("addr0000", &[Coin::new(0u128, "uusd")]);
let res = execute(deps.as_mut(), env.clone(), info, msg);
match res {
Err(err) => {
Expand Down Expand Up @@ -173,6 +198,7 @@ fn register_vesting_account_with_native_token() -> TestResult {
require_error(
&mut deps,
&env,
mock_info("addr0000", &[Coin::new(0u128, "uusd")]),
msg,
ContractError::Vesting(VestingError::ZeroVestingAmount),
);
Expand Down

0 comments on commit 2fc3a13

Please sign in to comment.