Skip to content

Commit

Permalink
πŸ™…πŸ»β€β™‚οΈ Disallow 0CT participation (#385)
Browse files Browse the repository at this point in the history
## What?
- Participants could contribute with 0CTs, now we disallow it

## Why?
- Useless storage consumption

## How?
- an ensure on the final ct bought

## Testing?
- New test
  • Loading branch information
JuaniRios authored Sep 3, 2024
1 parent 7ffcbab commit 56918d4
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 56918d4

Please sign in to comment.