Skip to content

Commit

Permalink
more cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Zavgorodnii committed Mar 23, 2023
1 parent 645864e commit 08f19f0
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 153 deletions.
89 changes: 24 additions & 65 deletions contracts/vesting-lp/src/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ fn claim() {

let token_code_id = store_token_code(&mut app);

let astro_token_instance =
instantiate_token(&mut app, token_code_id, "ASTRO", Some(1_000_000_000_000_000));
let astro_token_instance = instantiate_token(
&mut app,
token_code_id,
"ASTRO",
Some(1_000_000_000_000_000),
);

let vesting_instance = instantiate_vesting(&mut app, &astro_token_instance);

Expand Down Expand Up @@ -148,12 +152,7 @@ fn claim() {
);

// Check vesting balance
check_token_balance(
&mut app,
&astro_token_instance,
&vesting_instance,
300u128,
);
check_token_balance(&mut app, &astro_token_instance, &vesting_instance, 300u128);

let msg = ExecuteMsg::Claim {
recipient: None,
Expand All @@ -174,12 +173,7 @@ fn claim() {
assert_eq!(vesting_res.info.released_amount, Uint128::from(300u128));

// Check vesting balance
check_token_balance(
&mut app,
&astro_token_instance,
&vesting_instance,
0u128,
);
check_token_balance(&mut app, &astro_token_instance, &vesting_instance, 0u128);

// Check user balance
check_token_balance(&mut app, &astro_token_instance, &user1, 300u128);
Expand Down Expand Up @@ -359,10 +353,8 @@ fn claim_native() {
};

// Check user balance after claim
let user1_vesting_amount: Uint128 = app
.wrap()
.query_wasm_smart(vesting_instance, &msg)
.unwrap();
let user1_vesting_amount: Uint128 =
app.wrap().query_wasm_smart(vesting_instance, &msg).unwrap();

assert_eq!(user1_vesting_amount.clone(), Uint128::new(0u128));
}
Expand All @@ -377,8 +369,12 @@ fn register_vesting_accounts() {

let token_code_id = store_token_code(&mut app);

let astro_token_instance =
instantiate_token(&mut app, token_code_id, "ASTRO", Some(1_000_000_000_000_000));
let astro_token_instance = instantiate_token(
&mut app,
token_code_id,
"ASTRO",
Some(1_000_000_000_000_000),
);

let noname_token_instance = instantiate_token(
&mut app,
Expand Down Expand Up @@ -505,12 +501,7 @@ fn register_vesting_accounts() {
&owner.clone(),
TOKEN_INITIAL_AMOUNT - 100u128,
);
check_token_balance(
&mut app,
&astro_token_instance,
&vesting_instance,
100u128,
);
check_token_balance(&mut app, &astro_token_instance, &vesting_instance, 100u128);

// Let's check user1's final vesting amount after add schedule for a new one
let msg = Cw20ExecuteMsg::Send {
Expand Down Expand Up @@ -553,12 +544,7 @@ fn register_vesting_accounts() {
&owner.clone(),
TOKEN_INITIAL_AMOUNT - 300u128,
);
check_token_balance(
&mut app,
&astro_token_instance,
&vesting_instance,
300u128,
);
check_token_balance(&mut app, &astro_token_instance, &vesting_instance, 300u128);
// A new schedule has been added successfully and an old one hasn't changed.
// The new schedule doesn't have the same value as the old one.
assert_eq!(user2_vesting_amount, Uint128::new(200u128));
Expand Down Expand Up @@ -606,12 +592,7 @@ fn register_vesting_accounts() {
&owner.clone(),
TOKEN_INITIAL_AMOUNT - 310u128,
);
check_token_balance(
&mut app,
&astro_token_instance,
&vesting_instance,
310u128,
);
check_token_balance(&mut app, &astro_token_instance, &vesting_instance, 310u128);

let msg = ExecuteMsg::Claim {
recipient: None,
Expand All @@ -630,12 +611,7 @@ fn register_vesting_accounts() {
.query_wasm_smart(vesting_instance.clone(), &msg)
.unwrap();
assert_eq!(vesting_res.info.released_amount, Uint128::from(110u128));
check_token_balance(
&mut app,
&astro_token_instance,
&vesting_instance,
200u128,
);
check_token_balance(&mut app, &astro_token_instance, &vesting_instance, 200u128);
check_token_balance(&mut app, &astro_token_instance, &user1, 110u128);

// Owner balance mustn't change after claim
Expand Down Expand Up @@ -963,19 +939,9 @@ fn instantiate_vesting(app: &mut App, astro_token_instance: &Addr) -> Addr {
res.vesting_token.to_string()
);

mint_tokens(
app,
astro_token_instance,
&owner,
TOKEN_INITIAL_AMOUNT,
);
mint_tokens(app, astro_token_instance, &owner, TOKEN_INITIAL_AMOUNT);

check_token_balance(
app,
astro_token_instance,
&owner,
TOKEN_INITIAL_AMOUNT,
);
check_token_balance(app, astro_token_instance, &owner, TOKEN_INITIAL_AMOUNT);

vesting_instance
}
Expand All @@ -994,15 +960,8 @@ fn instantiate_vesting_remote_chain(app: &mut App) -> Addr {
vesting_token: native_asset_info(IBC_ASTRO.to_string()),
};

app.instantiate_contract(
vesting_code_id,
owner,
&init_msg,
&[],
"Vesting",
None,
)
.unwrap()
app.instantiate_contract(vesting_code_id, owner, &init_msg, &[], "Vesting", None)
.unwrap()
}

fn mint_tokens(app: &mut App, token: &Addr, recipient: &Addr, amount: u128) {
Expand Down
30 changes: 18 additions & 12 deletions contracts/vesting-managed/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::{
Addr, attr, Binary, Deps, DepsMut, entry_point, Env, MessageInfo, Response, StdError,
attr, entry_point, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError,
StdResult, SubMsg, Uint128,
};
use cw_storage_plus::{SnapshotItem, SnapshotMap, Strategy};
Expand All @@ -9,8 +9,8 @@ use astroport::asset::AssetInfo;
use astroport::asset::AssetInfoExt;
use astroport::common::{claim_ownership, drop_ownership_proposal, propose_new_owner};
use astroport::vesting::{InstantiateMsg, QueryMsg, VestingInfo, VestingState};
use vesting_base::{error::ContractError, state::BaseVesting};
use vesting_base::state::Config;
use vesting_base::{error::ContractError, state::BaseVesting};

use crate::msg::ExecuteMsg;

Expand Down Expand Up @@ -83,25 +83,31 @@ pub fn execute(
config.owner,
&vest_app.ownership_proposal,
)
.map_err(Into::into)
.map_err(Into::into)
}
ExecuteMsg::DropOwnershipProposal {} => {
let config: Config = vest_app.config.load(deps.storage)?;

drop_ownership_proposal(deps, info, config.owner, &vest_app.ownership_proposal)
.map_err(Into::into)
}
ExecuteMsg::ClaimOwnership {} => {
claim_ownership(deps, info, env, &vest_app.ownership_proposal, |deps, new_owner| {
vest_app.config.update::<_, StdError>(deps.storage, |mut v| {
v.owner = new_owner;
Ok(v)
})?;
ExecuteMsg::ClaimOwnership {} => claim_ownership(
deps,
info,
env,
&vest_app.ownership_proposal,
|deps, new_owner| {
vest_app
.config
.update::<_, StdError>(deps.storage, |mut v| {
v.owner = new_owner;
Ok(v)
})?;

Ok(())
})
.map_err(Into::into)
}
},
)
.map_err(Into::into),
ExecuteMsg::RemoveVestingAccounts {
vesting_accounts,
clawback_account,
Expand Down
Loading

0 comments on commit 08f19f0

Please sign in to comment.