diff --git a/contracts/non-fungible-tokens/andromeda-crowdfund/src/mock.rs b/contracts/non-fungible-tokens/andromeda-crowdfund/src/mock.rs index 45a514d00..532d77f79 100644 --- a/contracts/non-fungible-tokens/andromeda-crowdfund/src/mock.rs +++ b/contracts/non-fungible-tokens/andromeda-crowdfund/src/mock.rs @@ -5,7 +5,7 @@ use andromeda_non_fungible_tokens::crowdfund::{ CampaignConfig, CampaignSummaryResponse, Cw20HookMsg, ExecuteMsg, InstantiateMsg, PresaleTierOrder, QueryMsg, SimpleTierOrder, Tier, TierMetaData, TiersResponse, }; -use andromeda_std::common::expiration::Expiry; +use andromeda_std::common::{expiration::Expiry, OrderBy}; use andromeda_testing::{ mock::MockApp, mock_ado, @@ -99,12 +99,14 @@ impl MockCrowdfund { self.query(app, msg) } - pub fn query_tiers(&self, app: &mut MockApp) -> TiersResponse { - let msg = QueryMsg::Tiers { - start_after: None, - limit: None, - order_by: None, - }; + pub fn query_tiers( + &self, + app: &mut MockApp, + start_after: Option, + limit: Option, + order_by: Option, + ) -> TiersResponse { + let msg = mock_query_tiers_msg(start_after, limit, order_by); self.query(app, msg) } } @@ -177,3 +179,15 @@ pub fn mock_claim_msg() -> ExecuteMsg { pub fn mock_purchase_cw20_msg(orders: Vec) -> Cw20HookMsg { Cw20HookMsg::PurchaseTiers { orders } } + +pub fn mock_query_tiers_msg( + start_after: Option, + limit: Option, + order_by: Option, +) -> QueryMsg { + QueryMsg::Tiers { + start_after, + limit, + order_by, + } +} diff --git a/contracts/non-fungible-tokens/andromeda-crowdfund/src/state.rs b/contracts/non-fungible-tokens/andromeda-crowdfund/src/state.rs index 8b92d9e98..ca880ee78 100644 --- a/contracts/non-fungible-tokens/andromeda-crowdfund/src/state.rs +++ b/contracts/non-fungible-tokens/andromeda-crowdfund/src/state.rs @@ -175,7 +175,7 @@ pub(crate) fn get_tiers( .take(limit) .map(|v| { let (level, tier) = v?; - let sold_amount = TIER_SALES.load(storage, level).unwrap_or_default(); + let sold_amount = TIER_SALES.may_load(storage, level)?.unwrap_or_default(); Ok(TierResponseItem { tier, sold_amount }) }) .collect() diff --git a/tests-integration/tests/crowdfund_app.rs b/tests-integration/tests/crowdfund_app.rs index 69c924194..8edc3854c 100644 --- a/tests-integration/tests/crowdfund_app.rs +++ b/tests-integration/tests/crowdfund_app.rs @@ -272,7 +272,7 @@ fn test_successful_crowdfund_app_native(setup: TestCase) { assert_eq!(summary.current_capital, 0); assert_eq!(summary.current_stage, CampaignStage::ONGOING.to_string()); - let tiers = crowdfund.query_tiers(&mut router).tiers; + let tiers = crowdfund.query_tiers(&mut router, None, None, None).tiers; assert_eq!(tiers.len(), 2); // Purchase tiers @@ -493,12 +493,38 @@ fn test_crowdfund_app_native_with_ado_recipient( .query_balance(buyer_one.clone(), "uandr") .unwrap() .amount; + + let tiers_pre_sale = crowdfund.query_tiers(&mut router, None, None, None); let _ = crowdfund.execute_purchase( buyer_one.clone(), &mut router, - orders, + orders.clone(), vec![coin(5000, "uandr")], ); + let tiers_post_sale = crowdfund.query_tiers(&mut router, None, None, None); + + // Verify each tier's amount_sold increased by the correct amount + for order in orders { + let pre_tier = tiers_pre_sale + .tiers + .iter() + .find(|t| t.tier.level == order.level) + .unwrap(); + let post_tier = tiers_post_sale + .tiers + .iter() + .find(|t| t.tier.level == order.level) + .unwrap(); + + assert_eq!( + post_tier.sold_amount, + pre_tier.sold_amount + order.amount, + "Tier {} amount_sold should increase by {}", + order.level, + order.amount + ); + } + let buyer_one_balance = router .wrap() .query_balance(buyer_one.clone(), "uandr") @@ -653,7 +679,7 @@ fn test_successful_crowdfund_app_cw20(#[with(false)] setup: TestCase) { assert_eq!(summary.current_capital, 0); assert_eq!(summary.current_stage, CampaignStage::ONGOING.to_string()); - let tiers = crowdfund.query_tiers(&mut router).tiers; + let tiers = crowdfund.query_tiers(&mut router, None, None, None).tiers; assert_eq!(tiers.len(), 2); // Purchase tiers