Skip to content

Commit

Permalink
test: additional conditional_splitter integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
joemonem committed Jan 13, 2025
1 parent 75d6f93 commit b3e26d7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ fn execute_send(ctx: ExecuteContext) -> Result<Response, ContractError> {
amount: remainder_funds,
})));
}
let kernel_address = ADOContract::default().get_kernel_address(deps.as_ref().storage)?;
if !pkt.messages.is_empty() {
let kernel_address = ADOContract::default().get_kernel_address(deps.as_ref().storage)?;
let distro_msg = pkt.to_sub_msg(kernel_address, Some(amp_funds), 1)?;
msgs.push(distro_msg);
}
Expand Down
97 changes: 97 additions & 0 deletions tests-integration/tests/conditional_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,100 @@ fn test_conditional_splitter() {
assert_eq!(uusd_balance_1.amount, Uint128::from(20u128));
assert_eq!(uusd_balance_2.amount, Uint128::from(80u128));
}

#[test]
fn test_conditional_splitter_with_multiple_thresholds() {
let mut router = mock_app(None);
let andr = MockAndromedaBuilder::new(&mut router, "admin")
.with_wallets(vec![("owner", vec![coin(100_000, "uandr")])])
.with_contracts(vec![
("app-contract", mock_andromeda_app()),
(
"conditional-splitter",
mock_andromeda_conditional_splitter(),
),
])
.build(&mut router);
let owner = andr.get_wallet("owner");

let recipient_a = "andr12lm0kfn2g3gn39ulzvqnadwksss5ez8rc7rwq7";
let recipient_b = "andr10dx5rcshf3fwpyw8jjrh5m25kv038xkqvngnls";

let threshold_recipients_5 = vec![
AddressPercent {
recipient: Recipient::from_string(recipient_b.to_string()),
percent: Decimal::from_str("0.3").unwrap(),
},
AddressPercent {
recipient: Recipient::from_string(recipient_a.to_string()),
percent: Decimal::from_str("0.7").unwrap(),
},
];

let threshold_recipients_10 = vec![
AddressPercent {
recipient: Recipient::from_string(recipient_a.to_string()),
percent: Decimal::from_str("0.5").unwrap(),
},
AddressPercent {
recipient: Recipient::from_string(recipient_b.to_string()),
percent: Decimal::from_str("0.5").unwrap(),
},
];

let thresholds = vec![
Threshold::new(Uint128::new(5), threshold_recipients_5),
Threshold::new(Uint128::new(10), threshold_recipients_10),
];

let app_code_id = andr.get_code_id(&mut router, "app-contract");
let splitter_init_msg = mock_conditional_splitter_instantiate_msg(
thresholds,
andr.kernel.addr().clone(),
None,
None,
);
let splitter_app_component = AppComponent {
name: "conditional-splitter".to_string(),
component_type: ComponentType::new(splitter_init_msg),
ado_type: "conditional-splitter".to_string(),
};

let app_components = vec![splitter_app_component.clone()];
let app = MockAppContract::instantiate(
app_code_id,
owner,
&mut router,
"Conditional Splitter App",
app_components,
andr.kernel.addr(),
None,
);

let splitter: MockConditionalSplitter =
app.query_ado_by_component_name(&router, splitter_app_component.name);

// Test amount between 5 and 10 (should use 30/70 split)
let token_1 = coin(6, "uandr");
splitter
.execute_send(&mut router, owner.clone(), &[token_1])
.unwrap();

let balance_a = router.wrap().query_balance(recipient_a, "uandr").unwrap();
let balance_b = router.wrap().query_balance(recipient_b, "uandr").unwrap();

assert_eq!(balance_a.amount, Uint128::from(4u128)); // 70% of 6
assert_eq!(balance_b.amount, Uint128::from(1u128)); // 30% of 6

// Test amount above 10 (should use 50/50 split)
let token_2 = coin(15, "uandr");
splitter
.execute_send(&mut router, owner.clone(), &[token_2])
.unwrap();

let balance_a = router.wrap().query_balance(recipient_a, "uandr").unwrap();
let balance_b = router.wrap().query_balance(recipient_b, "uandr").unwrap();

assert_eq!(balance_a.amount, Uint128::from(11u128)); // 4 from previous + 50% of 15
assert_eq!(balance_b.amount, Uint128::from(8u128)); // 1 from previous + 50% of 15
}

0 comments on commit b3e26d7

Please sign in to comment.