Skip to content

Commit

Permalink
fee-splitter: adds consts instead of writing the same vars in each test
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Feb 2, 2024
1 parent 3b18ad1 commit b0117a1
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions contracts/fee_splitter/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@ use crate::{
state::Config,
};

const SENDER: &str = "addr0000";
const FIRST_RECIPIENT: &str = "address0000";
const SECOND_RECIPIENT: &str = "address0001";
const ATOM: &str = "ATOM";
const TIA: &str = "TIA";
const USDT: &str = "USDT";
const CW20_ASSET_ONE: &str = "asset0000";
const CW20_ASSET_TWO: &str = "asset0001";

#[test]
fn init_works() {
let mut deps = mock_coreum_deps(&[]);
let env = mock_env();
let sender = "addr0000";
let info = mock_info(sender, &[]);
let info = mock_info(SENDER, &[]);

let first_addr_pecnt = ("address0000".to_string(), Decimal::percent(50u64));
let second_addr_pecnt = ("address0001".to_string(), Decimal::percent(50u64));
let first_addr_percent = (FIRST_RECIPIENT.to_string(), Decimal::percent(50u64));
let second_addr_percent = (SECOND_RECIPIENT.to_string(), Decimal::percent(50u64));
let msg = InstantiateMsg {
addresses: vec![first_addr_pecnt.clone(), second_addr_pecnt.clone()],
cw20_contracts: vec!["USDT".to_string()],
addresses: vec![first_addr_percent.clone(), second_addr_percent.clone()],
cw20_contracts: vec![USDT.to_string()],
};

let res = instantiate(deps.as_mut(), env, info, msg).unwrap();
Expand All @@ -42,14 +50,13 @@ fn init_works() {
fn fails_to_init_because_weights_not_correct() {
let mut deps = mock_coreum_deps(&[]);
let env = mock_env();
let sender = "addr0000";
let info = mock_info(sender, &[]);
let info = mock_info(SENDER, &[]);

let first_tupple = ("ATOM".to_string(), Decimal::percent(50u64));
let second_tuple = ("TIA".to_string(), Decimal::percent(60u64));
let first_addr_percent = (FIRST_RECIPIENT.to_string(), Decimal::percent(50u64));
let second_addr_percent = (SECOND_RECIPIENT.to_string(), Decimal::percent(60u64));
let msg = InstantiateMsg {
addresses: vec![first_tupple.clone(), second_tuple.clone()],
cw20_contracts: vec!["USDT".to_string()],
addresses: vec![first_addr_percent.clone(), second_addr_percent.clone()],
cw20_contracts: vec![USDT.to_string()],
};

let res = instantiate(deps.as_mut(), env, info, msg).unwrap_err();
Expand All @@ -61,35 +68,33 @@ fn should_send_tokens_in_correct_amount() {
let mut deps = mock_coreum_deps(&[]);

deps.querier.with_token_balances(&[(
&String::from("asset0000"),
&String::from(CW20_ASSET_ONE),
&[(&String::from(MOCK_CONTRACT_ADDR), &Uint128::new(100_000))],
)]);

deps.querier.with_balance(&[(
&String::from(MOCK_CONTRACT_ADDR),
&[
Coin {
denom: "ATOM".to_string(),
denom: ATOM.to_string(),
amount: Uint128::new(100_000),
},
Coin {
denom: "TIA".to_string(),
denom: TIA.to_string(),
amount: Uint128::new(100_000),
},
],
)]);

let env = mock_env();

let sender = "addr0000";

let info = mock_info(sender, &[]);
let info = mock_info(SENDER, &[]);
let msg = InstantiateMsg {
addresses: vec![
("address0000".to_string(), Decimal::percent(60u64)),
("address0001".to_string(), Decimal::percent(40u64)),
(FIRST_RECIPIENT.to_string(), Decimal::percent(60u64)),
(SECOND_RECIPIENT.to_string(), Decimal::percent(40u64)),
],
cw20_contracts: vec!["asset0000".to_string(), "asset0001".to_string()],
cw20_contracts: vec![CW20_ASSET_ONE.to_string(), CW20_ASSET_TWO.to_string()],
};

let fee_splitter_instance = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap();
Expand All @@ -103,8 +108,8 @@ fn should_send_tokens_in_correct_amount() {
);

let msg = ExecuteMsg::SendTokens {
native_denoms: vec!["ATOM".to_string(), "TIA".to_string()],
cw20_addresses: vec!["asset0000".to_string()],
native_denoms: vec![ATOM.to_string(), TIA.to_string()],
cw20_addresses: vec![CW20_ASSET_ONE.to_string()],
};

let res = execute(deps.as_mut(), env.clone(), info, msg).unwrap();
Expand All @@ -115,14 +120,14 @@ fn should_send_tokens_in_correct_amount() {
SubMsg {
id: 0,
msg: CosmosMsg::Bank(BankMsg::Send {
to_address: "address0000".to_string(),
to_address: FIRST_RECIPIENT.to_string(),
amount: vec![
Coin {
denom: "ATOM".to_string(),
denom: ATOM.to_string(),
amount: Uint128::new(60_000),
},
Coin {
denom: "TIA".to_string(),
denom: TIA.to_string(),
amount: Uint128::new(60_000),
}
]
Expand All @@ -133,9 +138,9 @@ fn should_send_tokens_in_correct_amount() {
SubMsg {
id: 0,
msg: CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: "asset0000".to_string(),
contract_addr: CW20_ASSET_ONE.to_string(),
msg: to_json_binary(&Cw20ExecuteMsg::Transfer {
recipient: "address0000".to_string(),
recipient: FIRST_RECIPIENT.to_string(),
amount: Uint128::new(60_000),
})
.unwrap(),
Expand All @@ -147,14 +152,14 @@ fn should_send_tokens_in_correct_amount() {
SubMsg {
id: 0,
msg: CosmosMsg::Bank(BankMsg::Send {
to_address: "address0001".to_string(),
to_address: SECOND_RECIPIENT.to_string(),
amount: vec![
Coin {
denom: "ATOM".to_string(),
denom: ATOM.to_string(),
amount: Uint128::new(40_000),
},
Coin {
denom: "TIA".to_string(),
denom: TIA.to_string(),
amount: Uint128::new(40_000),
}
]
Expand All @@ -165,9 +170,9 @@ fn should_send_tokens_in_correct_amount() {
SubMsg {
id: 0,
msg: CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: "asset0000".to_string(),
contract_addr: CW20_ASSET_ONE.to_string(),
msg: to_json_binary(&Cw20ExecuteMsg::Transfer {
recipient: "address0001".to_string(),
recipient: SECOND_RECIPIENT.to_string(),
amount: Uint128::new(40_000),
})
.unwrap(),
Expand All @@ -188,8 +193,8 @@ fn should_send_tokens_in_correct_amount() {
config_res,
Config {
addresses: vec![
("address0000".to_string(), Decimal::percent(60)),
("address0001".to_string(), Decimal::percent(40))
(FIRST_RECIPIENT.to_string(), Decimal::percent(60)),
(SECOND_RECIPIENT.to_string(), Decimal::percent(40))
],
}
);
Expand Down

0 comments on commit b0117a1

Please sign in to comment.