From edc35e04390ba955fc7d992970ad2bd58bb66d6a Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Tue, 23 Apr 2024 17:36:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test=20evaluation=20bond=20cannot?= =?UTF-8?q?=20be=20used=20on=20another=20project=20participation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pallets/funding/src/tests/3_auction.rs | 60 +++++++++++++++++++++++ pallets/funding/src/tests/4_community.rs | 61 ++++++++++++++++++++++++ pallets/funding/src/tests/5_remainder.rs | 61 ++++++++++++++++++++++++ 3 files changed, 182 insertions(+) diff --git a/pallets/funding/src/tests/3_auction.rs b/pallets/funding/src/tests/3_auction.rs index 8e3ec7058..25bbc56d0 100644 --- a/pallets/funding/src/tests/3_auction.rs +++ b/pallets/funding/src/tests/3_auction.rs @@ -1054,6 +1054,66 @@ mod bid_extrinsic { ); } + #[test] + fn cannot_use_evaluation_bond_on_another_project_bid() { + let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let project_metadata_1 = default_project_metadata(ISSUER_1); + let project_metadata_2 = default_project_metadata(ISSUER_2); + + + let mut evaluations_1 = default_evaluations(); + let evaluations_2 = default_evaluations(); + + let evaluator_bidder = 69; + let evaluation_amount = 420 * US_DOLLAR; + let evaluator_bid = BidParams::new(evaluator_bidder, 600 * ASSET_UNIT, 1u8, AcceptedFundingAsset::USDT); + evaluations_1.push((evaluator_bidder, evaluation_amount).into()); + + let project_id_1 = inst.create_auctioning_project(project_metadata_1.clone(), ISSUER_1, evaluations_1); + let project_id_2 = inst.create_auctioning_project(project_metadata_2.clone(), ISSUER_2, evaluations_2); + + + // Necessary Mints + let already_bonded_plmc = + MockInstantiator::calculate_evaluation_plmc_spent(vec![(evaluator_bidder, evaluation_amount).into()]) + [0] + .plmc_amount; + let usable_evaluation_plmc = + already_bonded_plmc - ::EvaluatorSlash::get() * already_bonded_plmc; + let necessary_plmc_for_bid = MockInstantiator::calculate_auction_plmc_charged_with_given_price( + &vec![evaluator_bid.clone()], + project_metadata_2.minimum_price, + )[0] + .plmc_amount; + let necessary_usdt_for_bid = MockInstantiator::calculate_auction_funding_asset_charged_with_given_price( + &vec![evaluator_bid.clone()], + project_metadata_2.minimum_price, + ); + inst.mint_plmc_to(vec![UserToPLMCBalance::new( + evaluator_bidder, + necessary_plmc_for_bid - usable_evaluation_plmc, + )]); + inst.mint_foreign_asset_to(necessary_usdt_for_bid); + + inst.execute(|| { + assert_noop!( + PolimecFunding::bid( + RuntimeOrigin::signed(evaluator_bidder), + get_mock_jwt( + evaluator_bidder, + InvestorType::Professional, + generate_did_from_account(evaluator_bidder) + ), + project_id_2, + evaluator_bid.amount, + evaluator_bid.multiplier, + evaluator_bid.asset + ), + Error::::ParticipationFailed(ParticipationError::NotEnoughFunds) + ); + }); + } + #[test] fn cannot_bid_before_auction_round() { let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); diff --git a/pallets/funding/src/tests/4_community.rs b/pallets/funding/src/tests/4_community.rs index d581cf62b..20d333d25 100644 --- a/pallets/funding/src/tests/4_community.rs +++ b/pallets/funding/src/tests/4_community.rs @@ -1250,5 +1250,66 @@ mod community_contribute_extrinsic { Error::::ParticipationFailed(ParticipationError::FundingAssetNotAccepted) ); } + + #[test] + fn cannot_use_evaluation_bond_on_another_project_contribution() { + let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let project_metadata_1 = default_project_metadata(ISSUER_1); + let project_metadata_2 = default_project_metadata(ISSUER_2); + + + let mut evaluations_1 = default_evaluations(); + let evaluations_2 = default_evaluations(); + + let evaluator_contributor = 69; + let evaluation_amount = 420 * US_DOLLAR; + let evaluator_contribution = ContributionParams::new(evaluator_contributor, 600 * ASSET_UNIT, 1u8, AcceptedFundingAsset::USDT); + evaluations_1.push((evaluator_contributor, evaluation_amount).into()); + + let project_id_1 = inst.create_community_contributing_project(project_metadata_1.clone(), ISSUER_1, evaluations_1, default_bids()); + let project_id_2 = inst.create_community_contributing_project(project_metadata_2.clone(), ISSUER_2, evaluations_2, default_bids()); + + let wap = inst.get_project_details(project_id_2).weighted_average_price.unwrap(); + + // Necessary Mints + let already_bonded_plmc = + MockInstantiator::calculate_evaluation_plmc_spent(vec![(evaluator_contributor, evaluation_amount).into()]) + [0] + .plmc_amount; + let usable_evaluation_plmc = + already_bonded_plmc - ::EvaluatorSlash::get() * already_bonded_plmc; + let necessary_plmc_for_contribution = MockInstantiator::calculate_contributed_plmc_spent( + vec![evaluator_contribution.clone()], + wap, + )[0] + .plmc_amount; + let necessary_usdt_for_contribution = MockInstantiator::calculate_contributed_funding_asset_spent( + vec![evaluator_contribution.clone()], + wap, + ); + inst.mint_plmc_to(vec![UserToPLMCBalance::new( + evaluator_contributor, + necessary_plmc_for_contribution - usable_evaluation_plmc, + )]); + inst.mint_foreign_asset_to(necessary_usdt_for_contribution); + + inst.execute(|| { + assert_noop!( + PolimecFunding::community_contribute( + RuntimeOrigin::signed(evaluator_contributor), + get_mock_jwt( + evaluator_contributor, + InvestorType::Retail, + generate_did_from_account(evaluator_contributor) + ), + project_id_2, + evaluator_contribution.amount, + evaluator_contribution.multiplier, + evaluator_contribution.asset + ), + Error::::ParticipationFailed(ParticipationError::NotEnoughFunds) + ); + }); + } } } diff --git a/pallets/funding/src/tests/5_remainder.rs b/pallets/funding/src/tests/5_remainder.rs index 9d17c3ffe..86b23fa85 100644 --- a/pallets/funding/src/tests/5_remainder.rs +++ b/pallets/funding/src/tests/5_remainder.rs @@ -910,5 +910,66 @@ mod remaining_contribute_extrinsic { )); }); } + + #[test] + fn cannot_use_evaluation_bond_on_another_project_contribution() { + let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let project_metadata_1 = default_project_metadata(ISSUER_1); + let project_metadata_2 = default_project_metadata(ISSUER_2); + + + let mut evaluations_1 = default_evaluations(); + let evaluations_2 = default_evaluations(); + + let evaluator_contributor = 69; + let evaluation_amount = 420 * US_DOLLAR; + let evaluator_contribution = ContributionParams::new(evaluator_contributor, 600 * ASSET_UNIT, 1u8, AcceptedFundingAsset::USDT); + evaluations_1.push((evaluator_contributor, evaluation_amount).into()); + + let project_id_1 = inst.create_remainder_contributing_project(project_metadata_1.clone(), ISSUER_1, evaluations_1, default_bids(), vec![]); + let project_id_2 = inst.create_remainder_contributing_project(project_metadata_2.clone(), ISSUER_2, evaluations_2, default_bids(), vec![]); + + let wap = inst.get_project_details(project_id_2).weighted_average_price.unwrap(); + + // Necessary Mints + let already_bonded_plmc = + MockInstantiator::calculate_evaluation_plmc_spent(vec![(evaluator_contributor, evaluation_amount).into()]) + [0] + .plmc_amount; + let usable_evaluation_plmc = + already_bonded_plmc - ::EvaluatorSlash::get() * already_bonded_plmc; + let necessary_plmc_for_contribution = MockInstantiator::calculate_contributed_plmc_spent( + vec![evaluator_contribution.clone()], + wap, + )[0] + .plmc_amount; + let necessary_usdt_for_contribution = MockInstantiator::calculate_contributed_funding_asset_spent( + vec![evaluator_contribution.clone()], + wap, + ); + inst.mint_plmc_to(vec![UserToPLMCBalance::new( + evaluator_contributor, + necessary_plmc_for_contribution - usable_evaluation_plmc, + )]); + inst.mint_foreign_asset_to(necessary_usdt_for_contribution); + + inst.execute(|| { + assert_noop!( + PolimecFunding::remaining_contribute( + RuntimeOrigin::signed(evaluator_contributor), + get_mock_jwt( + evaluator_contributor, + InvestorType::Retail, + generate_did_from_account(evaluator_contributor) + ), + project_id_2, + evaluator_contribution.amount, + evaluator_contribution.multiplier, + evaluator_contribution.asset + ), + Error::::ParticipationFailed(ParticipationError::NotEnoughFunds) + ); + }); + } } }