diff --git a/pallets/funding/src/tests.rs b/pallets/funding/src/tests.rs index 5a2ae4448..f43474f8b 100644 --- a/pallets/funding/src/tests.rs +++ b/pallets/funding/src/tests.rs @@ -3545,284 +3545,6 @@ mod community_contribution { } } } - - #[test] - fn non_retail_multiplier_limits() { - let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); - let project_metadata = ProjectMetadata { - token_information: default_token_information(), - mainnet_token_max_supply: 80_000_000 * ASSET_UNIT, - total_allocation_size: 10_000_000 * ASSET_UNIT, - auction_round_allocation_percentage: Percent::from_percent(50u8), - minimum_price: PriceOf::::from_float(10.0), - bidding_ticket_sizes: BiddingTicketSizes { - professional: TicketSize::new(Some(5000 * US_DOLLAR), None), - institutional: TicketSize::new(Some(5000 * US_DOLLAR), None), - phantom: Default::default(), - }, - contributing_ticket_sizes: ContributingTicketSizes { - retail: TicketSize::new(None, None), - professional: TicketSize::new(None, None), - institutional: TicketSize::new(None, None), - phantom: Default::default(), - }, - participation_currencies: vec![AcceptedFundingAsset::USDT].try_into().unwrap(), - funding_destination_account: ISSUER_1, - offchain_information_hash: Some(hashed(METADATA)), - }; - let evaluations = MockInstantiator::generate_successful_evaluations( - project_metadata.clone(), - default_evaluators(), - default_weights(), - ); - let bids = MockInstantiator::generate_bids_from_total_ct_percent( - project_metadata.clone(), - 50, - default_weights(), - default_bidders(), - default_multipliers(), - ); - let project_id = - inst.create_community_contributing_project(project_metadata.clone(), ISSUER_1, evaluations, bids); - let wap = inst.get_project_details(project_id).weighted_average_price.unwrap(); - - // Professional bids: 0x multiplier should fail - let jwt = get_mock_jwt(BUYER_1, InvestorType::Professional, generate_did_from_account(BUYER_1)); - inst.execute(|| { - assert_noop!( - Pallet::::community_contribute( - RuntimeOrigin::signed(BUYER_1), - jwt, - project_id, - 1000 * ASSET_UNIT, - Multiplier::force_new(0), - AcceptedFundingAsset::USDT - ), - Error::::ForbiddenMultiplier - ); - }); - // Professional bids: 1 - 10x multiplier should work - for multiplier in 1..=10u8 { - let jwt = get_mock_jwt(BUYER_1, InvestorType::Professional, generate_did_from_account(BUYER_1)); - let bidder_plmc = MockInstantiator::calculate_contributed_plmc_spent( - vec![(BUYER_1, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let bidder_usdt = MockInstantiator::calculate_contributed_funding_asset_spent( - vec![(BUYER_1, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let ed = MockInstantiator::get_ed(); - inst.mint_plmc_to(vec![(BUYER_1, ed).into()]); - inst.mint_plmc_to(bidder_plmc); - inst.mint_foreign_asset_to(bidder_usdt); - assert_ok!(inst.execute(|| Pallet::::community_contribute( - RuntimeOrigin::signed(BUYER_1), - jwt, - project_id, - 1000 * ASSET_UNIT, - Multiplier::force_new(multiplier), - AcceptedFundingAsset::USDT - ))); - } - // Professional bids: >=11x multiplier should fail - for multiplier in 11..=50u8 { - let jwt = get_mock_jwt(BUYER_1, InvestorType::Professional, generate_did_from_account(BUYER_1)); - let bidder_plmc = MockInstantiator::calculate_contributed_plmc_spent( - vec![(BUYER_1, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let bidder_usdt = MockInstantiator::calculate_contributed_funding_asset_spent( - vec![(BUYER_1, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let ed = MockInstantiator::get_ed(); - inst.mint_plmc_to(vec![(BUYER_1, ed).into()]); - inst.mint_plmc_to(bidder_plmc); - inst.mint_foreign_asset_to(bidder_usdt); - inst.execute(|| { - assert_noop!( - Pallet::::community_contribute( - RuntimeOrigin::signed(BUYER_1), - jwt, - project_id, - 1000 * ASSET_UNIT, - Multiplier::force_new(multiplier), - AcceptedFundingAsset::USDT - ), - Error::::ForbiddenMultiplier - ); - }); - } - - - // Institutional bids: 0x multiplier should fail - let jwt = get_mock_jwt(BUYER_2, InvestorType::Institutional, generate_did_from_account(BUYER_2)); - inst.execute(|| { - assert_noop!( - Pallet::::community_contribute( - RuntimeOrigin::signed(BUYER_2), - jwt, - project_id, - 1000 * ASSET_UNIT, - Multiplier::force_new(0), - AcceptedFundingAsset::USDT - ), - Error::::ForbiddenMultiplier - ); - }); - // Institutional bids: 1 - 25x multiplier should work - for multiplier in 1..=25u8 { - let jwt = get_mock_jwt(BUYER_2, InvestorType::Institutional, generate_did_from_account(BUYER_2)); - let bidder_plmc = MockInstantiator::calculate_contributed_plmc_spent( - vec![(BUYER_2, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let bidder_usdt = MockInstantiator::calculate_contributed_funding_asset_spent( - vec![(BUYER_2, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let ed = MockInstantiator::get_ed(); - inst.mint_plmc_to(vec![(BUYER_2, ed).into()]); - inst.mint_plmc_to(bidder_plmc); - inst.mint_foreign_asset_to(bidder_usdt); - assert_ok!(inst.execute(|| Pallet::::community_contribute( - RuntimeOrigin::signed(BUYER_2), - jwt, - project_id, - 1000 * ASSET_UNIT, - multiplier.try_into().unwrap(), - AcceptedFundingAsset::USDT - ))); - } - // Institutional bids: >=26x multiplier should fail - for multiplier in 26..=50u8 { - let jwt = get_mock_jwt(BUYER_2, InvestorType::Institutional, generate_did_from_account(BUYER_2)); - let bidder_plmc = MockInstantiator::calculate_contributed_plmc_spent( - vec![(BUYER_2, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let bidder_usdt = MockInstantiator::calculate_contributed_funding_asset_spent( - vec![(BUYER_2, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let ed = MockInstantiator::get_ed(); - inst.mint_plmc_to(vec![(BUYER_2, ed).into()]); - inst.mint_plmc_to(bidder_plmc); - inst.mint_foreign_asset_to(bidder_usdt); - inst.execute(|| { - assert_noop!( - Pallet::::community_contribute( - RuntimeOrigin::signed(BUYER_2), - jwt, - project_id, - 1000 * ASSET_UNIT, - Multiplier::force_new(multiplier), - AcceptedFundingAsset::USDT - ), - Error::::ForbiddenMultiplier - ); - }); - } - } - - #[test] - fn retail_multiplier_limits() { - let _ = env_logger::try_init(); - let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); - let mut issuer: AccountId = 6969420; - log::debug!("starting..."); - - let mut create_project = |inst: &mut MockInstantiator| { - issuer += 1; - inst.create_community_contributing_project( - default_project_metadata(issuer as u64, issuer), - issuer, - default_evaluations(), - default_bids(), - ) - }; - let mut contribute = |inst: &mut MockInstantiator, project_id, multiplier| { - let jwt = get_mock_jwt(BUYER_1, InvestorType::Retail, generate_did_from_account(BUYER_1)); - let wap = inst.get_project_details(project_id).weighted_average_price.unwrap(); - let contributor_plmc = MockInstantiator::calculate_contributed_plmc_spent( - vec![(BUYER_1, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let bidder_usdt = MockInstantiator::calculate_contributed_funding_asset_spent( - vec![(BUYER_1, 1_000 * ASSET_UNIT, Multiplier::force_new(multiplier)).into()], - wap, - ); - let ed = MockInstantiator::get_ed(); - inst.mint_plmc_to(vec![(BUYER_1, ed).into()]); - inst.mint_plmc_to(contributor_plmc); - inst.mint_foreign_asset_to(bidder_usdt); - inst.execute(|| Pallet::::community_contribute( - RuntimeOrigin::signed(BUYER_1), - jwt, - project_id, - 1000 * ASSET_UNIT, - Multiplier::force_new(multiplier), - AcceptedFundingAsset::USDT - )) - }; - - let max_allowed_multipliers_map = vec![ - (2, 1), - (4, 2), - (9, 4), - (24, 7), - (25, 10), - ]; - - let mut previous_projects_created = 0; - for (projects_participated_amount, max_allowed_multiplier) in max_allowed_multipliers_map { - log::debug!("{projects_participated_amount:?}"); - - log::debug!("{max_allowed_multiplier:?}"); - - log::debug!("creating {} new projects", projects_participated_amount-previous_projects_created); - - (previous_projects_created..projects_participated_amount-1).for_each(|_|{ - let project_id = create_project(&mut inst); - log::debug!("created"); - assert_ok!(contribute(&mut inst, project_id, 1)); - }); - - let project_id = create_project(&mut inst); - log::debug!("created"); - previous_projects_created = projects_participated_amount; - - // 0x multiplier should fail - // Professional bids: 0x multiplier should fail - inst.execute(|| { - assert_noop!( - Pallet::::community_contribute( - RuntimeOrigin::signed(BUYER_1), - get_mock_jwt(BUYER_1, InvestorType::Retail, generate_did_from_account(BUYER_1)), - project_id, - 1000 * ASSET_UNIT, - Multiplier::force_new(0), - AcceptedFundingAsset::USDT - ), - Error::::ForbiddenMultiplier - ); - }); - - // Multipliers that should work - for multiplier in 1..=max_allowed_multiplier { - log::debug!("success? - multiplier: {}", multiplier); - assert_ok!(contribute(&mut inst, project_id, multiplier)); - } - // dbg! - - // Multipliers that should NOT work - for multiplier in max_allowed_multiplier+1..=50 { - log::debug!("error? - multiplier: {}", multiplier); - assert_err!(contribute(&mut inst, project_id, multiplier), Error::::ForbiddenMultiplier); - } - } - } } // only functionalities that happen in the REMAINDER FUNDING period of a project