Skip to content

Commit

Permalink
disallow 0CT participation
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios authored and lrazovic committed Aug 30, 2024
1 parent 604543d commit 3ca9df8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pallets/funding/src/functions/4_contribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ impl<T: Config> Pallet<T> {
ensure!(now < round_end, Error::<T>::TooLateForRound);

let buyable_tokens = token_amount.min(project_details.remaining_contribution_tokens);
if buyable_tokens.is_zero() {
return Err(Error::<T>::ProjectSoldOut.into());
}
project_details.remaining_contribution_tokens.saturating_reduce(buyable_tokens);

let perform_params = DoPerformContributionParams {
Expand Down
2 changes: 2 additions & 0 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ pub mod pallet {
ParticipantNotEnoughFunds,
/// The JWT included the wrong policy for participating in this project.
PolicyMismatch,
/// Contribution tokens have all been sold
ProjectSoldOut,

// * An error related to the migration process. *
/// Tried to start a migration check but the bidirectional channel is not yet open
Expand Down
46 changes: 46 additions & 0 deletions pallets/funding/src/tests/4_contribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,5 +1741,51 @@ mod contribute_extrinsic {
);
});
}

#[test]
fn ct_sold_out() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_metadata = default_project_metadata(ISSUER_1);
let project_id = inst.create_community_contributing_project(
project_metadata.clone(),
ISSUER_1,
None,
default_evaluations(),
default_bids(),
);
let project_details = inst.get_project_details(project_id);
let remaining_cts = project_details.remaining_contribution_tokens;
let glutton_contribution = ContributionParams::new(BUYER_1, remaining_cts, 4u8, AcceptedFundingAsset::USDT);
let wap = project_details.weighted_average_price.unwrap();
let plmc_mint = inst.calculate_contributed_plmc_spent(vec![glutton_contribution.clone()], wap, true);
let funding_asset_mint = inst.calculate_contributed_funding_asset_spent(vec![glutton_contribution.clone()], wap);
inst.mint_plmc_to(plmc_mint);
inst.mint_funding_asset_to(funding_asset_mint);
inst.contribute_for_users(project_id, vec![glutton_contribution.clone()]).unwrap();

let failing_contribution = ContributionParams::<TestRuntime>::new(BUYER_2, 1000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDT);
let plmc_mint = inst.calculate_contributed_plmc_spent(vec![glutton_contribution.clone()], wap, true);
let funding_asset_mint = inst.calculate_contributed_funding_asset_spent(vec![glutton_contribution.clone()], wap);
inst.mint_plmc_to(plmc_mint);
inst.mint_funding_asset_to(funding_asset_mint);
inst.execute(|| {
assert_noop!(
PolimecFunding::contribute(
RuntimeOrigin::signed(failing_contribution.contributor),
get_mock_jwt_with_cid(
failing_contribution.contributor,
InvestorType::Retail,
generate_did_from_account(failing_contribution.contributor),
project_metadata.clone().policy_ipfs_cid.unwrap()
),
project_id,
failing_contribution.amount,
failing_contribution.multiplier,
failing_contribution.asset
),
Error::<TestRuntime>::ProjectSoldOut
);
});
}
}
}

0 comments on commit 3ca9df8

Please sign in to comment.