From 604543d0f5c6b31fa410b41c84134a4e645f1eb6 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Fri, 30 Aug 2024 16:22:47 +0200 Subject: [PATCH 1/2] fix penpal --- Cargo.lock | 46 ++++++++++------------------- integration-tests/penpal/Cargo.toml | 2 +- integration-tests/penpal/src/lib.rs | 2 +- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4d5d4a83..d4d553822 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -490,7 +490,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "sp-transaction-pool", "sp-version", "sp-weights", @@ -2138,7 +2138,7 @@ dependencies = [ "sp-runtime", "sp-state-machine", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "sp-trie", "tracing", ] @@ -2534,7 +2534,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-state-machine", - "sp-storage 21.0.0", + "sp-storage", "sp-version", "thiserror", "tokio", @@ -3475,7 +3475,7 @@ dependencies = [ "sp-runtime", "sp-runtime-interface", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "static_assertions", ] @@ -3523,7 +3523,7 @@ dependencies = [ "sp-keystore", "sp-runtime", "sp-state-machine", - "sp-storage 21.0.0", + "sp-storage", "sp-trie", "sp-wasm-interface", "thiserror", @@ -7983,7 +7983,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "sp-timestamp", ] @@ -8501,7 +8501,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-std", - "sp-storage 19.0.0", + "sp-storage", "sp-transaction-pool", "sp-version", "staging-parachain-info", @@ -9770,7 +9770,7 @@ dependencies = [ "sp-session", "sp-staking", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "sp-transaction-pool", "sp-version", "staging-xcm", @@ -10016,7 +10016,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-state-machine", - "sp-storage 21.0.0", + "sp-storage", "sp-timestamp", "sp-transaction-pool", "sp-version", @@ -11140,7 +11140,7 @@ dependencies = [ "sp-session", "sp-staking", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "sp-transaction-pool", "sp-version", "staging-xcm", @@ -11654,7 +11654,7 @@ dependencies = [ "sp-runtime", "sp-state-machine", "sp-statement-store", - "sp-storage 21.0.0", + "sp-storage", "sp-trie", "substrate-prometheus-endpoint", ] @@ -12491,7 +12491,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-state-machine", - "sp-storage 21.0.0", + "sp-storage", "sp-transaction-pool", "sp-transaction-storage-proof", "sp-trie", @@ -13785,7 +13785,7 @@ dependencies = [ "sp-externalities", "sp-runtime-interface", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "ss58-registry", "substrate-bip39", "thiserror", @@ -13848,7 +13848,7 @@ checksum = "a904407d61cb94228c71b55a9d3708e9d6558991f9e83bd42bd91df37a159d30" dependencies = [ "environmental", "parity-scale-codec", - "sp-storage 21.0.0", + "sp-storage", ] [[package]] @@ -14066,7 +14066,7 @@ dependencies = [ "sp-externalities", "sp-runtime-interface-proc-macro", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "sp-tracing", "sp-wasm-interface", "static_assertions", @@ -14167,20 +14167,6 @@ version = "14.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12f8ee986414b0a9ad741776762f4083cd3a5128449b982a3919c4df36874834" -[[package]] -name = "sp-storage" -version = "19.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb92d7b24033a8a856d6e20dd980b653cbd7af7ec471cc988b1b7c1d2e3a32b" -dependencies = [ - "impl-serde", - "parity-scale-codec", - "ref-cast", - "serde", - "sp-debug-derive", - "sp-std", -] - [[package]] name = "sp-storage" version = "21.0.0" @@ -16269,7 +16255,7 @@ dependencies = [ "sp-session", "sp-staking", "sp-std", - "sp-storage 21.0.0", + "sp-storage", "sp-transaction-pool", "sp-version", "staging-xcm", diff --git a/integration-tests/penpal/Cargo.toml b/integration-tests/penpal/Cargo.toml index 0f1af6ba9..bbd8a8543 100644 --- a/integration-tests/penpal/Cargo.toml +++ b/integration-tests/penpal/Cargo.toml @@ -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 } diff --git a/integration-tests/penpal/src/lib.rs b/integration-tests/penpal/src/lib.rs index 46f4c80d1..e9a30bdf2 100644 --- a/integration-tests/penpal/src/lib.rs +++ b/integration-tests/penpal/src/lib.rs @@ -1042,7 +1042,7 @@ impl_runtime_apis! { ]; let mut batches = Vec::::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()) } From 0905da241a1fedaa1260630168e20d79f9fdfdb5 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Fri, 30 Aug 2024 13:08:22 +0200 Subject: [PATCH 2/2] disallow 0CT participation --- .../funding/src/functions/4_contribution.rs | 3 ++ pallets/funding/src/lib.rs | 2 + pallets/funding/src/tests/4_contribution.rs | 46 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/pallets/funding/src/functions/4_contribution.rs b/pallets/funding/src/functions/4_contribution.rs index 381b232bc..99a1c9912 100644 --- a/pallets/funding/src/functions/4_contribution.rs +++ b/pallets/funding/src/functions/4_contribution.rs @@ -38,6 +38,9 @@ impl Pallet { ensure!(now < round_end, Error::::TooLateForRound); let buyable_tokens = token_amount.min(project_details.remaining_contribution_tokens); + if buyable_tokens.is_zero() { + return Err(Error::::ProjectSoldOut.into()); + } project_details.remaining_contribution_tokens.saturating_reduce(buyable_tokens); let perform_params = DoPerformContributionParams { diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index 706e46114..bf9fe2137 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -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 diff --git a/pallets/funding/src/tests/4_contribution.rs b/pallets/funding/src/tests/4_contribution.rs index 70248e246..275a526ef 100644 --- a/pallets/funding/src/tests/4_contribution.rs +++ b/pallets/funding/src/tests/4_contribution.rs @@ -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::::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::::ProjectSoldOut + ); + }); + } } }