Skip to content

Commit

Permalink
fix: make claim have the same interface than legacy contract (#131)
Browse files Browse the repository at this point in the history
* fix: make new contract with the same query output format as the previous one

* feat: fix claim interface

* fix: remove schema

* fix: merge

* fix(airdrop-token-vesting): return empty array when no vesting accounts are found

* test: claim empty vesting account response

---------

Co-authored-by: Kevin Yang <[email protected]>
  • Loading branch information
matthiasmatt and k-yang authored Mar 7, 2024
1 parent 939f68c commit 753f118
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ contracts/*/.editorconfig
packages/*/.editorconfig
lcov.info

.DS_Store
.DS_Store
artifacts/*.json
Binary file modified artifacts/airdrop_token_vesting.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
84148d7b8c372a9f103c51c8626464fe93bc560e43b711a1cd7ffd188969f891 airdrop_token_vesting.wasm
f684c6daf9e77d2f7cb14e70f87e6f10cd97cd02d163f71ab4e2f6f823abfc8a airdrop_token_vesting.wasm
382c05baf544f2886de849933ecf59e8bc3bcdcdd552d5a63537bd6d63f2ecf1 controller.wasm
b56a880d4c67d9f353f549b502256f73159f89b50aa6dae683948e117efa4792 cw3_flex_multisig.wasm
1ecff403bbf3b5fcedccb5de76a0ef5f1fdbcc5f60890e3388f5425584899f0b incentives.wasm
Expand Down
17 changes: 11 additions & 6 deletions contracts/airdrop-token-vesting/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_json_binary, Attribute, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut,
Env, MessageInfo, Response, StdError, StdResult, Storage, Timestamp,
Uint128,
Env, MessageInfo, Response, StdError, StdResult, Storage, Uint128,
};
use std::cmp::min;

Expand Down Expand Up @@ -86,7 +85,10 @@ pub fn execute(
vested_token_recipient,
left_vesting_token_recipient,
),
ExecuteMsg::Claim { recipient } => claim(deps, env, info, recipient),
ExecuteMsg::Claim {
denoms: _denoms,
recipient,
} => claim(deps, env, info, recipient),
ExecuteMsg::Withdraw { amount, recipient } => {
withdraw(deps, env, info, amount, recipient)
}
Expand Down Expand Up @@ -136,7 +138,7 @@ pub fn withdraw(

fn reward_users(
deps: DepsMut,
env: Env,
_env: Env,
info: MessageInfo,
rewards: Vec<RewardUserRequest>,
vesting_schedule: VestingSchedule,
Expand Down Expand Up @@ -418,7 +420,10 @@ fn vesting_account(
let denom = DENOM.load(deps.storage)?;

match account {
None => Err(StdError::not_found("Vesting account not found")),
None => Ok(VestingAccountResponse {
address,
vestings: vec![],
}),
Some(account) => {
let vested_amount =
account.vested_amount(env.block.time.seconds())?;
Expand Down Expand Up @@ -456,7 +461,7 @@ pub mod tests {
use cosmwasm_std::{
coin,
testing::{self, MockApi, MockQuerier, MockStorage},
Empty, OwnedDeps, Uint64,
Empty, OwnedDeps, Timestamp, Uint64,
};

pub type TestResult = Result<(), anyhow::Error>;
Expand Down
1 change: 1 addition & 0 deletions contracts/airdrop-token-vesting/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum ExecuteMsg {

/// Claim is an operation that allows one to claim vested tokens.
Claim {
denoms: Vec<Denom>,
recipient: Option<String>,
},

Expand Down
30 changes: 17 additions & 13 deletions contracts/airdrop-token-vesting/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,10 @@ fn claim_native() -> TestResult {

// valid claim
let info = mock_info("addr0001", &[]);
let msg = ExecuteMsg::Claim { recipient: None };
let msg = ExecuteMsg::Claim {
recipient: None,
denoms: vec![],
};

let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone())?;
assert_eq!(
Expand Down Expand Up @@ -841,20 +844,21 @@ fn claim_native() -> TestResult {
);

// query vesting account
let res = &query(
deps.as_ref(),
env,
QueryMsg::VestingAccount {
assert_eq!(
from_json::<VestingAccountResponse>(&query(
deps.as_ref(),
env,
QueryMsg::VestingAccount {
address: "addr0001".to_string(),
start_after: None,
limit: None,
},
)?)?,
VestingAccountResponse {
address: "addr0001".to_string(),
start_after: None,
limit: None,
},
vestings: vec![],
}
);
//expect res to be an errro
match res {
Err(StdError::NotFound { .. }) => {}
_ => panic!("should not enter. got result: {res:?}"),
}

Ok(())
}

0 comments on commit 753f118

Please sign in to comment.