Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ™…πŸ»β€β™‚οΈ Disallow 0CT participation #385

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 16 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/penpal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ sp-session = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }
sp-std = { workspace = true }
sp-storage = { version = "19.0.0", default-features = false }
sp-storage = { version = "21.0.0", default-features = false }
pallet-collator-selection = { version = "16.0.0", default-features = false }
# Polkadot
polkadot-primitives = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ impl_runtime_apis! {
];

let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
let params = (&config, whitelist.as_slice());
add_benchmarks!(params, batches);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Expand Down
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
);
});
}
}
}