Skip to content

Commit

Permalink
add withdraw test
Browse files Browse the repository at this point in the history
  • Loading branch information
vuonghuuhung committed Oct 1, 2024
1 parent 37e8ed5 commit 1e7e13a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
18 changes: 18 additions & 0 deletions contracts/zapper/src/tests/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ impl MockApp {
)
}

pub fn withdraw(
&mut self,
sender: &str,
zapper: &str,
assets: Vec<Asset>,
recipient: Option<&str>,
) -> MockResult<ExecuteResponse> {
self.execute(
Addr::unchecked(sender),
Addr::unchecked(zapper),
&msg::ExecuteMsg::Withdraw {
assets,
recipient: recipient.map(Addr::unchecked),
},
&[],
)
}

pub fn get_zapper_config(&mut self, zapper: &str) -> StdResult<Config> {
self.query(Addr::unchecked(zapper), &msg::QueryMsg::Config {})
}
Expand Down
1 change: 1 addition & 0 deletions contracts/zapper/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mod config;
mod helper;
mod zapin;
mod zapout;
mod withdraw;
44 changes: 44 additions & 0 deletions contracts/zapper/src/tests/withdraw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use cosmwasm_std::{coins, Uint128};
use decimal::*;
use oraiswap::mixed_router::SwapOperation;
use oraiswap_v3_common::asset::{Asset, AssetInfo};
use oraiswap_v3_common::math::percentage::Percentage;

use oraiswap_v3_common::storage::{FeeTier, PoolKey};

use crate::msg::Route;
use crate::tests::common::init_basic_v3_pool;
use crate::tests::helper::MockApp;
use crate::tests::helper::{macros::*, FEE_DENOM};

#[test]
fn test_withdraw() {
let (mut app, accounts) = MockApp::new(&[
("alice", &coins(100_000_000_000, FEE_DENOM)),
("bob", &coins(100_000_000_000, FEE_DENOM)),
]);
let alice = &accounts[0];
let bob = &accounts[1];
let initial_amount = 10u128.pow(20);
let (token_x, _, _) =
create_3_tokens!(app, initial_amount, initial_amount, initial_amount, alice);

let zapper = create_zapper!(app, alice);

app.mint_token(alice, zapper.as_str(), token_x.as_str(), 1)
.unwrap();
let assets: Vec<Asset> = vec![Asset {
info: AssetInfo::Token {
contract_addr: token_x.clone(),
},
amount: Uint128::new(1),
}];
let err = app.withdraw(bob, zapper.as_str(), assets.clone(), Some(bob))
.unwrap_err();
assert!(err.root_cause().to_string().contains("Unauthorized"));

app.withdraw(alice, zapper.as_str(), assets, Some(bob))
.unwrap();
let balance = balance_of!(app, token_x, bob);
assert_eq!(balance, 1);
}

0 comments on commit 1e7e13a

Please sign in to comment.