Skip to content

Commit

Permalink
fee-splitter: changes the contract initialization and adds test for w…
Browse files Browse the repository at this point in the history
…hen the weights are below the limit
  • Loading branch information
gangov committed Feb 5, 2024
1 parent b0117a1 commit a34da59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/fee_splitter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn instantiate(
.iter()
.map(|&(_, weight)| weight)
.fold(Decimal::zero(), |acc, x| acc + x)
.le(&Decimal::percent(100u64));
.eq(&Decimal::percent(100u64));

if !is_weights_valid {
return Err(ContractError::InvalidWeights {});
Expand Down
19 changes: 18 additions & 1 deletion contracts/fee_splitter/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn init_works() {
}

#[test]
fn fails_to_init_because_weights_not_correct() {
fn fails_to_init_because_weights_above_limit() {
let mut deps = mock_coreum_deps(&[]);
let env = mock_env();
let info = mock_info(SENDER, &[]);
Expand All @@ -63,6 +63,23 @@ fn fails_to_init_because_weights_not_correct() {
assert_eq!(res, ContractError::InvalidWeights {});
}

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

let first_addr_percent = (FIRST_RECIPIENT.to_string(), Decimal::percent(20u64));
let second_addr_percent = (SECOND_RECIPIENT.to_string(), Decimal::percent(20u64));
let msg = InstantiateMsg {
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();
assert_eq!(res, ContractError::InvalidWeights {});
}

#[test]
fn should_send_tokens_in_correct_amount() {
let mut deps = mock_coreum_deps(&[]);
Expand Down

0 comments on commit a34da59

Please sign in to comment.