diff --git a/contracts/finance/andromeda-conditional-splitter/src/contract.rs b/contracts/finance/andromeda-conditional-splitter/src/contract.rs index 46f6b2554..f47a74866 100644 --- a/contracts/finance/andromeda-conditional-splitter/src/contract.rs +++ b/contracts/finance/andromeda-conditional-splitter/src/contract.rs @@ -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); } diff --git a/tests-integration/tests/conditional_splitter.rs b/tests-integration/tests/conditional_splitter.rs index a4e0557ef..f733ace16 100644 --- a/tests-integration/tests/conditional_splitter.rs +++ b/tests-integration/tests/conditional_splitter.rs @@ -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 +}