diff --git a/Cargo.lock b/Cargo.lock index 5d85799bb..d63627496 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8422,6 +8422,7 @@ dependencies = [ "macros", "pallet-funding", "pallet-transaction-payment-rpc", + "polimec-common", "polimec-runtime", "politest-runtime", "polkadot-cli", diff --git a/integration-tests/src/constants.rs b/integration-tests/src/constants.rs index 42dfac528..f14796e94 100644 --- a/integration-tests/src/constants.rs +++ b/integration-tests/src/constants.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use frame_support::BoundedVec; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; pub use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber}; use politest_runtime::{ @@ -26,13 +27,14 @@ use politest_runtime::{ use polkadot_primitives::{AssignmentId, ValidatorId}; pub use polkadot_runtime_parachains::configuration::HostConfiguration; use sc_consensus_grandpa::AuthorityId as GrandpaId; -use sp_arithmetic::Percent; +use sp_arithmetic::{FixedU128, Percent}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId; use sp_core::{sr25519, storage::Storage, Pair, Public}; use sp_runtime::{bounded_vec, BuildStorage, Perbill}; +use pallet_funding::AcceptedFundingAsset; pub use xcm; use xcm_emulator::{helpers::get_account_id_from_seed, Chain, Parachain}; @@ -318,10 +320,10 @@ pub mod asset_hub { // Polimec pub mod politest { use super::*; - use crate::{Polimec, PolitestRuntime, PolkadotNet}; - use pallet_funding::AcceptedFundingAsset; + use crate::{Polimec, PolitestNet, PolitestOrigin, PolitestRuntime, PolkadotNet}; use sp_runtime::traits::AccountIdConversion; use xcm::v3::Parent; + use xcm_emulator::TestExt; pub const PARA_ID: u32 = 3344; pub const ED: Balance = politest_runtime::EXISTENTIAL_DEPOSIT; @@ -331,6 +333,45 @@ pub mod politest { const GENESIS_PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(0); const GENESIS_NUM_SELECTED_CANDIDATES: u32 = 5; + pub fn set_prices() { + PolitestNet::execute_with(|| { + let dot = (AcceptedFundingAsset::DOT.to_assethub_id(), FixedU128::from_rational(69, 1)); + let usdc = (AcceptedFundingAsset::USDC.to_assethub_id(), FixedU128::from_rational(1, 1)); + let usdt = (AcceptedFundingAsset::USDT.to_assethub_id(), FixedU128::from_rational(1, 1)); + let plmc = (pallet_funding::PLMC_FOREIGN_ID, FixedU128::from_rational(840, 100)); + + let values: BoundedVec<(u32, FixedU128), ::MaxFeedValues> = + vec![dot, usdc, usdt, plmc].try_into().expect("benchmarks can panic"); + let alice: [u8; 32] = [ + 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, + 227, 154, 86, 132, 231, 165, 109, 162, 125, + ]; + let bob: [u8; 32] = [ + 142, 175, 4, 21, 22, 135, 115, 99, 38, 201, 254, 161, 126, 37, 252, 82, 135, 97, 54, 147, 201, 18, 144, + 156, 178, 38, 170, 71, 148, 242, 106, 72, + ]; + let charlie: [u8; 32] = [ + 144, 181, 171, 32, 92, 105, 116, 201, 234, 132, 27, 230, 136, 134, 70, 51, 220, 156, 168, 163, 87, 132, + 62, 234, 207, 35, 20, 100, 153, 101, 254, 34, + ]; + + frame_support::assert_ok!(orml_oracle::Pallet::::feed_values( + PolitestOrigin::signed(alice.clone().into()), + values.clone() + )); + + frame_support::assert_ok!(orml_oracle::Pallet::::feed_values( + PolitestOrigin::signed(bob.clone().into()), + values.clone() + )); + + frame_support::assert_ok!(orml_oracle::Pallet::::feed_values( + PolitestOrigin::signed(charlie.clone().into()), + values.clone() + )); + }); + } + pub fn genesis() -> Storage { let dot_asset_id = AcceptedFundingAsset::DOT.to_assethub_id(); let usdt_asset_id = AcceptedFundingAsset::USDT.to_assethub_id(); @@ -437,7 +478,6 @@ pub mod politest { ], accounts: vec![], }, - funding: Default::default(), vesting: Default::default(), transaction_payment: Default::default(), contribution_tokens: Default::default(), @@ -506,10 +546,11 @@ pub mod penpal { // Polimec Runtime pub mod polimec { use super::*; - use crate::PolimecNet; + use crate::{PolimecNet, PolimecOrigin, PolimecRuntime}; use pallet_funding::AcceptedFundingAsset; use polimec_runtime::PayMaster; use xcm::v3::Parent; + use xcm_emulator::TestExt; pub const PARA_ID: u32 = 3344; pub const ED: Balance = polimec_runtime::EXISTENTIAL_DEPOSIT; @@ -519,6 +560,46 @@ pub mod polimec { const GENESIS_PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(0); const GENESIS_NUM_SELECTED_CANDIDATES: u32 = 5; + #[allow(unused)] + pub fn set_prices() { + PolimecNet::execute_with(|| { + let dot = (AcceptedFundingAsset::DOT.to_assethub_id(), FixedU128::from_rational(69, 1)); + let usdc = (AcceptedFundingAsset::USDC.to_assethub_id(), FixedU128::from_rational(1, 1)); + let usdt = (AcceptedFundingAsset::USDT.to_assethub_id(), FixedU128::from_rational(1, 1)); + let plmc = (pallet_funding::PLMC_FOREIGN_ID, FixedU128::from_rational(840, 100)); + + let values: BoundedVec<(u32, FixedU128), ::MaxFeedValues> = + vec![dot, usdc, usdt, plmc].try_into().expect("benchmarks can panic"); + let alice: [u8; 32] = [ + 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, + 227, 154, 86, 132, 231, 165, 109, 162, 125, + ]; + let bob: [u8; 32] = [ + 142, 175, 4, 21, 22, 135, 115, 99, 38, 201, 254, 161, 126, 37, 252, 82, 135, 97, 54, 147, 201, 18, 144, + 156, 178, 38, 170, 71, 148, 242, 106, 72, + ]; + let charlie: [u8; 32] = [ + 144, 181, 171, 32, 92, 105, 116, 201, 234, 132, 27, 230, 136, 134, 70, 51, 220, 156, 168, 163, 87, 132, + 62, 234, 207, 35, 20, 100, 153, 101, 254, 34, + ]; + + frame_support::assert_ok!(orml_oracle::Pallet::::feed_values( + PolimecOrigin::signed(alice.clone().into()), + values.clone() + )); + + frame_support::assert_ok!(orml_oracle::Pallet::::feed_values( + PolimecOrigin::signed(bob.clone().into()), + values.clone() + )); + + frame_support::assert_ok!(orml_oracle::Pallet::::feed_values( + PolimecOrigin::signed(charlie.clone().into()), + values.clone() + )); + }); + } + pub fn genesis() -> Storage { let dot_asset_id = AcceptedFundingAsset::DOT.to_assethub_id(); let usdt_asset_id = AcceptedFundingAsset::USDT.to_assethub_id(); @@ -548,7 +629,6 @@ pub mod polimec { system: Default::default(), balances: polimec_runtime::BalancesConfig { balances: funded_accounts }, contribution_tokens: Default::default(), - funding: Default::default(), foreign_assets: polimec_runtime::ForeignAssetsConfig { assets: vec![ (dot_asset_id, alice_account.clone(), true, 0_0_010_000_000u128), diff --git a/integration-tests/src/tests/basic_comms.rs b/integration-tests/src/tests/basic_comms.rs deleted file mode 100644 index 0d40d82a0..000000000 --- a/integration-tests/src/tests/basic_comms.rs +++ /dev/null @@ -1,145 +0,0 @@ -// Polimec Blockchain – https://www.polimec.org/ -// Copyright (C) Polimec 2022. All rights reserved. - -// The Polimec Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Polimec Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#[allow(unused_imports)] -use crate::*; - -const MAX_REF_TIME: u64 = 300_000_000; -const MAX_PROOF_SIZE: u64 = 10_000; - -// Ignored for now as we are not allowing "Transact" execution on our parachain -#[ignore] -#[test] -fn dmp() { - let remark = PolimecCall::System(frame_system::Call::::remark_with_event { - remark: "Hello from Polkadot!".as_bytes().to_vec(), - }); - let sudo_origin = PolkadotOrigin::root(); - let para_id = PolimecNet::para_id(); - let xcm = VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(MAX_REF_TIME, MAX_PROOF_SIZE), - call: remark.encode().into(), - }, - ])); - - PolkaNet::execute_with(|| { - assert_ok!(PolkadotXcmPallet::send(sudo_origin, bx!(Parachain(para_id.into()).into()), bx!(xcm),)); - - assert_expected_events!( - PolkaNet, - vec![ - PolkadotEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - PolimecNet::execute_with(|| { - assert_expected_events!( - PolimecNet, - vec![ - PolimecEvent::System(frame_system::Event::Remarked { sender: _, hash: _ }) => {}, - ] - ); - }); -} -#[ignore] -#[test] -fn ump() { - use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId}; - let burn_transfer = PolkadotCall::Balances(pallet_balances::Call::::transfer_allow_death { - dest: PolkadotAccountId::from([0u8; 32]).into(), - value: 1_000, - }); - - let here_asset: MultiAsset = (MultiLocation::here(), 1_0_000_000_000u128).into(); - - PolimecNet::execute_with(|| { - assert_ok!(PolimecXcmPallet::force_default_xcm_version(PolimecOrigin::root(), Some(3))); - - assert_ok!(PolimecXcmPallet::send_xcm( - Here, - Parent, - Xcm(vec![ - WithdrawAsset(vec![here_asset.clone()].into()), - BuyExecution { fees: here_asset.clone(), weight_limit: Unlimited }, - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(MAX_REF_TIME, MAX_PROOF_SIZE), - call: burn_transfer.encode().into(), - } - ]), - )); - }); - - PolkaNet::execute_with(|| { - assert_expected_events!( - PolkaNet, - vec![ - PolkadotEvent::MessageQueue(pallet_message_queue::Event::Processed { - id: _, - origin: AggregateMessageOrigin::Ump( - UmpQueueId::Para(_para_id) - ), - weight_used: _, - success: false - }) => {}, - ] - ); - }); -} - -// Ignored for now as we are not allowing "Transact" execution on our parachain -#[ignore] -#[test] -fn xcmp() { - let burn_transfer = PolimecCall::Balances(pallet_balances::Call::::transfer_allow_death { - dest: PolimecAccountId::from([0u8; 32]).into(), - value: 1_000, - }); - - let here_asset: MultiAsset = (MultiLocation::here(), 1_0_000_000_000u128).into(); - - PenNet::execute_with(|| { - assert_ok!(PenpalXcmPallet::send_xcm( - Here, - MultiLocation::new(1, X1(Parachain(PolimecNet::para_id().into()))), - Xcm(vec![ - WithdrawAsset(vec![here_asset.clone()].into()), - BuyExecution { fees: here_asset.clone(), weight_limit: Unlimited }, - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(MAX_REF_TIME, MAX_PROOF_SIZE), - call: burn_transfer.encode().into(), - } - ]), - )); - }); - - let penpal_account = PolimecNet::sovereign_account_id_of((Parent, Parachain(PenNet::para_id().into())).into()); - let penpal_balance = PolimecNet::account_data_of(penpal_account.clone()).free; - - PolimecNet::execute_with(|| { - assert_expected_events!( - PolimecNet, - vec![ - PolimecEvent::MessageQueue(pallet_message_queue::Event::Processed {success: true, ..}) => {}, - ] - ); - }); -} diff --git a/integration-tests/src/tests/build_spec.rs b/integration-tests/src/tests/build_spec.rs deleted file mode 100644 index 52fed43ed..000000000 --- a/integration-tests/src/tests/build_spec.rs +++ /dev/null @@ -1,46 +0,0 @@ -// Polimec Blockchain – https://www.polimec.org/ -// Copyright (C) Polimec 2022. All rights reserved. - -// The Polimec Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Polimec Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -#[ignore] -#[test] -fn build_spec_testing_node() { - // run the polimec-node compiled with "std" with the build-spec command and --raw flag - // This makes sure our async parallel instantiation of projects is working as intended. - // We need this to test the protocol with the UI. - - match std::env::current_dir() { - Ok(path) => { - println!("The current directory is {}", path.display()); - }, - Err(e) => { - println!("Error getting the current directory: {}", e); - }, - } - - let output = std::process::Command::new("../target/release/polimec-node") - .arg("build-spec") - .arg("--chain=politest-populated") - .arg("--disable-default-bootnode") - .arg("--raw") - .output() - .expect("failed to execute process"); - - dbg!(output.clone()); - assert_eq!( - output.status.success(), - true, - "Make sure you compile the polimec-node with \"--release\" and \"--features std,fast-mode\" before running this test." - ); -} diff --git a/integration-tests/src/tests/ct_migration.rs b/integration-tests/src/tests/ct_migration.rs index 307c762e8..8dce49cb4 100644 --- a/integration-tests/src/tests/ct_migration.rs +++ b/integration-tests/src/tests/ct_migration.rs @@ -179,6 +179,7 @@ fn create_settled_project() -> (ProjectId, Vec) { #[test] fn full_migration_test() { + politest::set_prices(); let (project_id, participants) = create_settled_project(); mock_hrmp_establishment(project_id); diff --git a/integration-tests/src/tests/e2e.rs b/integration-tests/src/tests/e2e.rs index f8e263498..aa75e9691 100644 --- a/integration-tests/src/tests/e2e.rs +++ b/integration-tests/src/tests/e2e.rs @@ -26,7 +26,6 @@ use itertools::Itertools; use macros::generate_accounts; use pallet_funding::{traits::ProvideAssetPrice, *}; use polimec_common::{USD_DECIMALS, USD_UNIT}; -use polimec_runtime::PLMC; use sp_arithmetic::{traits::Zero, Percent, Perquintill}; use sp_runtime::{FixedPointNumber, FixedU128}; use xcm_emulator::log; @@ -272,6 +271,8 @@ fn excel_ct_amounts() -> UserToCTBalance { #[test] fn evaluation_round_completed() { + politest::set_prices(); + let mut inst = IntegrationInstantiator::new(None); let issuer = ISSUER.into(); @@ -285,6 +286,8 @@ fn evaluation_round_completed() { #[test] fn auction_round_completed() { + politest::set_prices(); + let mut inst = IntegrationInstantiator::new(None); let issuer = ISSUER.into(); @@ -323,6 +326,8 @@ fn auction_round_completed() { #[test] fn community_round_completed() { + politest::set_prices(); + let mut inst = IntegrationInstantiator::new(None); PolitestNet::execute_with(|| { @@ -338,19 +343,21 @@ fn community_round_completed() { let contributions = Contributions::::iter_prefix_values((0,)) .sorted_by_key(|bid| bid.contributor.clone()) .collect_vec(); - let total_contribution = + let _total_contribution = contributions.clone().into_iter().fold(0, |acc, bid| acc + bid.funding_asset_amount); - let total_contribution_as_fixed = FixedU128::from_rational(total_contribution, PLMC); + // TODO: add test for exact amount contributed }) }); } #[test] fn remainder_round_completed() { + politest::set_prices(); + let mut inst = IntegrationInstantiator::new(None); PolitestNet::execute_with(|| { - let project_id = inst.create_finished_project( + inst.create_finished_project( excel_project(), ISSUER.into(), excel_evaluators(), @@ -359,16 +366,6 @@ fn remainder_round_completed() { excel_remainders(), ); - let price = inst.get_project_details(project_id).weighted_average_price.unwrap(); - let funding_necessary_1 = inst.calculate_contributed_funding_asset_spent(excel_contributions(), price); - let funding_necessary_2 = inst.calculate_contributed_funding_asset_spent(excel_remainders(), price); - let mut total = 0u128; - for item in funding_necessary_1 { - total += item.asset_amount; - } - for item in funding_necessary_2 { - total += item.asset_amount; - } let contributions = Contributions::::iter_prefix_values((0,)) .sorted_by_key(|contribution| contribution.contributor.clone()) .collect_vec(); @@ -388,6 +385,8 @@ fn remainder_round_completed() { #[test] fn funds_raised() { + politest::set_prices(); + let mut inst = IntegrationInstantiator::new(None); PolitestNet::execute_with(|| { @@ -417,6 +416,8 @@ fn funds_raised() { #[test] fn ct_minted() { + politest::set_prices(); + let mut inst = IntegrationInstantiator::new(None); PolitestNet::execute_with(|| { @@ -443,6 +444,8 @@ fn ct_minted() { #[test] fn ct_migrated() { + politest::set_prices(); + let mut inst = IntegrationInstantiator::new(None); let project_id = PolitestNet::execute_with(|| { diff --git a/integration-tests/src/tests/mod.rs b/integration-tests/src/tests/mod.rs index fafd86d16..0888699c3 100644 --- a/integration-tests/src/tests/mod.rs +++ b/integration-tests/src/tests/mod.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -mod basic_comms; -mod build_spec; mod credentials; mod ct_migration; mod defaults; diff --git a/nodes/parachain/Cargo.toml b/nodes/parachain/Cargo.toml index 522a5c9c8..48c19b65b 100644 --- a/nodes/parachain/Cargo.toml +++ b/nodes/parachain/Cargo.toml @@ -25,6 +25,7 @@ politest-runtime.workspace = true polimec-runtime.workspace = true pallet-funding.workspace = true macros = { workspace = true } +polimec-common.workspace = true # Substrate frame-benchmarking.workspace = true @@ -110,7 +111,6 @@ std = [ "frame-benchmarking/std", "frame-support/std", "log/std", - "pallet-funding/std", "polkadot-primitives/std", "serde/std", "sp-api/std", diff --git a/nodes/parachain/src/chain_spec/politest.rs b/nodes/parachain/src/chain_spec/politest.rs index c4e33ab87..d1528e236 100644 --- a/nodes/parachain/src/chain_spec/politest.rs +++ b/nodes/parachain/src/chain_spec/politest.rs @@ -45,6 +45,7 @@ const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(30); const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(0); const BLOCKS_PER_ROUND: u32 = 2 * 10; const NUM_SELECTED_CANDIDATES: u32 = 5; + pub fn polimec_inflation_config() -> InflationInfo { fn to_round_inflation(annual: Range) -> Range { perbill_annual_to_perbill_round( @@ -70,49 +71,6 @@ pub fn get_politest_session_keys(keys: AuthorityId) -> politest_runtime::Session politest_runtime::SessionKeys { aura: keys } } -#[cfg(feature = "std")] -pub fn get_populated_chain_spec() -> Result { - let properties = get_properties("PLMC", 10, 41); - let wasm = politest_runtime::WASM_BINARY.ok_or("No WASM")?; - - #[allow(deprecated)] - Ok(ChainSpec::from_genesis( - "Polimec Develop", - "polimec", - ChainType::Local, - move || { - testing_genesis( - vec![ - (get_account_id_from_seed::("Alice"), None, 2 * MinCandidateStk::get()), - (get_account_id_from_seed::("Bob"), None, 2 * MinCandidateStk::get()), - ], - polimec_inflation_config(), - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - ], - vec![ - (get_account_id_from_seed::("Alice"), 5 * MinCandidateStk::get()), - (get_account_id_from_seed::("Bob"), 5 * MinCandidateStk::get()), - (get_account_id_from_seed::("Charlie"), 5 * MinCandidateStk::get()), - (get_account_id_from_seed::("Dave"), 5 * MinCandidateStk::get()), - (get_account_id_from_seed::("Eve"), 5 * MinCandidateStk::get()), - (get_account_id_from_seed::("Ferdie"), 5 * MinCandidateStk::get()), - ], - get_account_id_from_seed::("Alice"), - DEFAULT_PARA_ID, - ) - }, - vec![], - None, - None, - None, - Some(properties), - Extensions { relay_chain: "rococo-local".into(), para_id: DEFAULT_PARA_ID.into() }, - wasm, - )) -} - pub fn get_local_chain_spec() -> GenericChainSpec { let properties = get_properties("RLMC", 10, 41); @@ -289,272 +247,3 @@ fn testnet_genesis( }, }) } - -#[cfg(feature = "std")] -mod testing_helpers { - use super::*; - pub use macros::generate_accounts; - pub use pallet_funding::{instantiator::UserToUSDBalance, ProjectStatus, *}; - pub use sp_runtime::{ - traits::{ConstU32, Get, PhantomData}, - BoundedVec, FixedPointNumber, - }; - - pub const IPFS_CID: &str = "QmeuJ24ffwLAZppQcgcggJs3n689bewednYkuc8Bx5Gngz"; - pub const ASSET_DECIMALS: u8 = 10; - pub const ASSET_UNIT: u128 = 10_u128.pow(10 as u32); - - generate_accounts!( - ALICE, BOB, CHARLIE, ISSUER, ISSUER_1, ISSUER_2, ISSUER_3, ISSUER_4, ISSUER_5, ISSUER_6, EVAL_1, EVAL_2, - EVAL_3, EVAL_4, BIDDER_1, BIDDER_2, BIDDER_3, BIDDER_4, BIDDER_5, BIDDER_6, BUYER_1, BUYER_2, BUYER_3, BUYER_4, - BUYER_5, BUYER_6, - ); - - pub fn bounded_name() -> BoundedVec> { - BoundedVec::try_from("Contribution Token TEST".as_bytes().to_vec()).unwrap() - } - pub fn bounded_symbol() -> BoundedVec> { - BoundedVec::try_from("CTEST".as_bytes().to_vec()).unwrap() - } - pub fn ipfs_hash() -> BoundedVec> { - BoundedVec::try_from(IPFS_CID.as_bytes().to_vec()).unwrap() - } - pub fn default_weights() -> Vec { - vec![20u8, 15u8, 10u8, 25u8, 30u8] - } - - pub fn project_metadata(issuer: AccountId) -> ProjectMetadataOf { - ProjectMetadata { - token_information: CurrencyMetadata { - name: bounded_name(), - symbol: bounded_symbol(), - decimals: ASSET_DECIMALS, - }, - mainnet_token_max_supply: 8_000_000 * ASSET_UNIT, - total_allocation_size: 1_000_000 * ASSET_UNIT, - auction_round_allocation_percentage: Percent::from_percent(50u8), - minimum_price: PriceOf::::from_float(10.0), - bidding_ticket_sizes: BiddingTicketSizes { - professional: TicketSize::new(Some(5000 * USD_UNIT), None), - institutional: TicketSize::new(Some(5000 * USD_UNIT), None), - phantom: Default::default(), - }, - contributing_ticket_sizes: ContributingTicketSizes { - retail: TicketSize::new(None, None), - professional: TicketSize::new(None, None), - institutional: TicketSize::new(None, None), - phantom: Default::default(), - }, - participation_currencies: vec![AcceptedFundingAsset::USDT].try_into().unwrap(), - funding_destination_account: issuer, - policy_ipfs_cid: Some(ipfs_hash()), - } - } - pub fn default_evaluations() -> Vec> { - vec![ - UserToUSDBalance::new(EVAL_1.into(), 500_000 * PLMC), - UserToUSDBalance::new(EVAL_2.into(), 250_000 * PLMC), - UserToUSDBalance::new(EVAL_3.into(), 320_000 * PLMC), - ] - } - pub fn default_bidders() -> Vec { - vec![BIDDER_1.into(), BIDDER_2.into(), BIDDER_3.into(), BIDDER_4.into(), BIDDER_5.into()] - } - pub fn default_bidder_multipliers() -> Vec { - vec![10u8, 3u8, 8u8, 7u8, 9u8] - } - pub fn default_community_contributor_multipliers() -> Vec { - vec![1u8, 1u8, 1u8, 1u8, 1u8] - } - pub fn default_remainder_contributor_multipliers() -> Vec { - vec![1u8, 1u8, 1u8, 1u8, 1u8] - } - - pub fn default_community_contributors() -> Vec { - vec![BUYER_1.into(), BUYER_2.into(), BUYER_3.into(), BUYER_4.into(), BUYER_5.into()] - } - - pub fn default_remainder_contributors() -> Vec { - vec![EVAL_1.into(), BIDDER_3.into(), BUYER_4.into(), BUYER_6.into(), BIDDER_6.into()] - } - - use politest_runtime::Runtime as T; - pub type GenesisInstantiator = pallet_funding::instantiator::Instantiator< - T, - ::AllPalletsWithoutSystem, - ::RuntimeEvent, - >; -} - -#[cfg(feature = "std")] -#[allow(clippy::too_many_arguments)] -fn testing_genesis( - stakers: Vec<(AccountId, Option, Balance)>, - inflation_config: InflationInfo, - initial_authorities: Vec, - mut endowed_accounts: Vec<(AccountId, Balance)>, - sudo_account: AccountId, - id: ParaId, -) -> RuntimeGenesisConfig { - use pallet_funding::instantiator::TestProjectParams; - use politest_runtime::{ - BalancesConfig, CouncilConfig, ForeignAssetsConfig, ParachainInfoConfig, ParachainStakingConfig, - PolkadotXcmConfig, SessionConfig, SudoConfig, TechnicalCommitteeConfig, EXISTENTIAL_DEPOSIT, - }; - use sp_runtime::bounded_vec; - use testing_helpers::*; - - // only used to generate some values, and not for chain interactions - let default_project_metadata = project_metadata(ISSUER.into()); - let min_price = default_project_metadata.minimum_price; - let usdt_funding_amount = - default_project_metadata.minimum_price.checked_mul_int(default_project_metadata.total_allocation_size).unwrap(); - let evaluations = default_evaluations(); - let bids = GenesisInstantiator::generate_bids_from_total_usd( - Percent::from_percent(40u8) * usdt_funding_amount, - min_price, - default_weights(), - default_bidders(), - default_bidder_multipliers(), - ); - let community_contributions = GenesisInstantiator::generate_contributions_from_total_usd( - Percent::from_percent(50u8) * usdt_funding_amount, - min_price, - default_weights(), - default_community_contributors(), - default_community_contributor_multipliers(), - ); - let remainder_contributions = GenesisInstantiator::generate_contributions_from_total_usd( - Percent::from_percent(5u8) * usdt_funding_amount, - min_price, - default_weights(), - default_remainder_contributors(), - default_remainder_contributor_multipliers(), - ); - - let accounts = endowed_accounts.iter().map(|(account, _)| account.clone()).collect::>(); - endowed_accounts - .push((::PalletId::get().into_account_truncating(), EXISTENTIAL_DEPOSIT)); - endowed_accounts.push((::ContributionTreasury::get(), EXISTENTIAL_DEPOSIT)); - RuntimeGenesisConfig { - system: Default::default(), - oracle_providers_membership: OracleProvidersMembershipConfig { - members: bounded_vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - ], - phantom: Default::default(), - }, - funding: politest_runtime::FundingConfig { - starting_projects: vec![ - TestProjectParams:: { - expected_state: ProjectStatus::FundingSuccessful, - metadata: project_metadata(ISSUER_1.into()), - issuer: ISSUER_1.into(), - evaluations: evaluations.clone(), - bids: bids.clone(), - community_contributions: community_contributions.clone(), - remainder_contributions: remainder_contributions.clone(), - }, - TestProjectParams:: { - expected_state: ProjectStatus::RemainderRound, - metadata: project_metadata(ISSUER_2.into()), - issuer: ISSUER_2.into(), - evaluations: evaluations.clone(), - bids: bids.clone(), - community_contributions: community_contributions.clone(), - remainder_contributions: vec![], - }, - TestProjectParams:: { - expected_state: ProjectStatus::CommunityRound, - metadata: project_metadata(ISSUER_3.into()), - issuer: ISSUER_3.into(), - evaluations: evaluations.clone(), - bids: bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams:: { - expected_state: ProjectStatus::AuctionOpening, - metadata: project_metadata(ISSUER_4.into()), - issuer: ISSUER_4.into(), - evaluations: evaluations.clone(), - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams:: { - expected_state: ProjectStatus::EvaluationRound, - metadata: project_metadata(ISSUER_5.into()), - issuer: ISSUER_5.into(), - evaluations: vec![], - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams:: { - expected_state: ProjectStatus::Application, - metadata: project_metadata(ISSUER_6.into()), - issuer: ISSUER_6.into(), - evaluations: vec![], - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - ], - phantom: PhantomData, - }, - balances: BalancesConfig { balances: endowed_accounts.clone() }, - foreign_assets: ForeignAssetsConfig { - assets: vec![( - pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id(), - ::PalletId::get().into_account_truncating(), - false, - 10, - )], - metadata: vec![], - accounts: vec![], - }, - parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() }, - parachain_staking: ParachainStakingConfig { - candidates: stakers.iter().map(|(accunt, _, balance)| (accunt.clone(), *balance)).collect::>(), - inflation_config, - delegations: vec![], - collator_commission: COLLATOR_COMMISSION, - parachain_bond_reserve_percent: PARACHAIN_BOND_RESERVE_PERCENT, - blocks_per_round: BLOCKS_PER_ROUND, - num_selected_candidates: NUM_SELECTED_CANDIDATES, - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - session: SessionConfig { - keys: initial_authorities - .iter() - .map(|acc| { - ( - acc.clone(), - acc.clone(), - get_politest_session_keys(Into::<[u8; 32]>::into(acc.clone()).unchecked_into()), - ) - }) - .collect::>(), - }, - polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, - treasury: Default::default(), - sudo: SudoConfig { key: Some(sudo_account) }, - council: CouncilConfig { members: accounts.clone(), phantom: Default::default() }, - technical_committee: TechnicalCommitteeConfig { - members: accounts.clone().into_iter().take(5).collect(), - phantom: Default::default(), - }, - democracy: Default::default(), - elections: Default::default(), - vesting: Default::default(), - contribution_tokens: Default::default(), - transaction_payment: Default::default(), - } -} diff --git a/nodes/parachain/src/command.rs b/nodes/parachain/src/command.rs index df98f3c4d..0b0742675 100644 --- a/nodes/parachain/src/command.rs +++ b/nodes/parachain/src/command.rs @@ -97,8 +97,6 @@ fn load_spec(id: &str) -> std::result::Result, String> { "polimec-local" => Box::new(chain_spec::polimec::get_local_chain_spec()), "rolimec-local" => Box::new(chain_spec::polimec::get_rococo_chain_spec()), "politest-local" => Box::new(chain_spec::politest::get_local_chain_spec()), - #[cfg(feature = "std")] - "politest-populated" => Box::new(chain_spec::politest::get_populated_chain_spec()?), // -- Fallback (generic chainspec) "" => { log::warn!("No ChainSpec.id specified, so using default one, based on polimec-rococo-local"); diff --git a/pallets/funding/src/benchmarking.rs b/pallets/funding/src/benchmarking.rs index eb4e17ef9..d7f2177fc 100644 --- a/pallets/funding/src/benchmarking.rs +++ b/pallets/funding/src/benchmarking.rs @@ -32,7 +32,6 @@ use frame_support::{ use pallet::Pallet as PalletFunding; use parity_scale_codec::{Decode, Encode}; use polimec_common::{credentials::InvestorType, USD_DECIMALS, USD_UNIT}; -use scale_info::prelude::format; use sp_arithmetic::Percent; use sp_core::H256; use sp_io::hashing::blake2_256; @@ -282,53 +281,6 @@ pub fn string_account( .expect("infinite length input; no invalid inputs for type; qed") } -#[cfg(feature = "std")] -pub fn populate_with_projects(amount: u32, inst: BenchInstantiator) -> BenchInstantiator -where - T: Config - + frame_system::Config::RuntimeEvent> - + pallet_balances::Config>, - ::RuntimeEvent: TryInto> + Parameter + Member, - ::Price: From, - ::Balance: From, - T::Hash: From, - ::AccountId: - Into<<::RuntimeOrigin as OriginTrait>::AccountId> + sp_std::fmt::Debug, - ::Balance: Into>, -{ - let states = vec![ - ProjectStatus::Application, - ProjectStatus::EvaluationRound, - ProjectStatus::AuctionOpening, - ProjectStatus::CommunityRound, - ProjectStatus::RemainderRound, - ProjectStatus::FundingSuccessful, - ] - .into_iter() - .cycle() - .take(amount as usize); - - let instantiation_details = states - .map(|state| { - let nonce = inst.get_new_nonce(); - let issuer_name: String = format!("issuer_{}", nonce); - - let issuer = string_account::>(issuer_name, 0, 0); - TestProjectParams:: { - expected_state: state, - metadata: default_project_metadata::(issuer.clone()), - issuer: issuer.clone(), - evaluations: default_evaluations::(), - bids: default_bids::(), - community_contributions: default_community_contributions::(), - remainder_contributions: default_remainder_contributions::(), - } - }) - .collect::>>(); - - async_features::create_multiple_projects_at(inst, instantiation_details).1 -} - // IMPORTANT: make sure your project starts at (block 1 + `total_vecs_in_storage` - `fully_filled_vecs_from_insertion`) to always have room to insert new vecs pub fn fill_projects_to_update( fully_filled_vecs_from_insertion: u32, @@ -363,6 +315,7 @@ pub fn run_blocks_to_execute_next_transition( )] mod benchmarks { use super::*; + use crate::traits::SetPrices; use itertools::Itertools; use polimec_common_test_utils::{generate_did_from_account, get_mock_jwt_with_cid}; @@ -375,6 +328,7 @@ mod benchmarks { fn create_project() { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -425,6 +379,7 @@ mod benchmarks { fn remove_project() { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -456,6 +411,7 @@ mod benchmarks { fn edit_project() { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -559,6 +515,7 @@ mod benchmarks { ) { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -611,6 +568,7 @@ mod benchmarks { ) { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // We need to leave enough block numbers to fill `ProjectsToUpdate` before our project insertion let time_advance: u32 = x + 2; @@ -671,6 +629,7 @@ mod benchmarks { ) { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -782,6 +741,7 @@ mod benchmarks { { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1110,6 +1070,7 @@ mod benchmarks { { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // We need to leave enough block numbers to fill `ProjectsToUpdate` before our project insertion let mut time_advance: u32 = 1; @@ -1403,6 +1364,7 @@ mod benchmarks { ) { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // We need to leave enough block numbers to fill `ProjectsToUpdate` before our project insertion @@ -1474,6 +1436,7 @@ mod benchmarks { fn settle_successful_evaluation() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1537,6 +1500,7 @@ mod benchmarks { fn settle_failed_evaluation() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1619,6 +1583,7 @@ mod benchmarks { fn settle_successful_bid() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1665,6 +1630,7 @@ mod benchmarks { fn settle_failed_bid() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1724,6 +1690,7 @@ mod benchmarks { fn settle_successful_contribution() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1781,6 +1748,7 @@ mod benchmarks { fn settle_failed_contribution() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1857,6 +1825,7 @@ mod benchmarks { ) { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1901,6 +1870,7 @@ mod benchmarks { fn end_evaluation_failure() { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -1962,6 +1932,7 @@ mod benchmarks { ) { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -2008,6 +1979,7 @@ mod benchmarks { ) { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -2139,6 +2111,7 @@ mod benchmarks { ) { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -2263,6 +2236,7 @@ mod benchmarks { ) { // * setup * let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); // real benchmark starts at block 0, and we can't call `events()` at block 0 inst.advance_time(1u32.into()).unwrap(); @@ -2314,6 +2288,7 @@ mod benchmarks { ) { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); let issuer = account::>("issuer", 0, 0); @@ -2371,6 +2346,7 @@ mod benchmarks { ) { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); let issuer = account::>("issuer", 0, 0); @@ -2429,6 +2405,7 @@ mod benchmarks { ) { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); let issuer = account::>("issuer", 0, 0); @@ -2489,6 +2466,7 @@ mod benchmarks { ) { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); let issuer = account::>("issuer", 0, 0); @@ -2563,6 +2541,7 @@ mod benchmarks { fn project_decision() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); let issuer = account::>("issuer", 0, 0); @@ -2612,6 +2591,7 @@ mod benchmarks { fn start_settlement_funding_success() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); let issuer = account::>("issuer", 0, 0); @@ -2642,6 +2622,7 @@ mod benchmarks { fn start_settlement_funding_failure() { // setup let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); let issuer = account::>("issuer", 0, 0); diff --git a/pallets/funding/src/instantiator/async_features.rs b/pallets/funding/src/instantiator/async_features.rs deleted file mode 100644 index 7e1947479..000000000 --- a/pallets/funding/src/instantiator/async_features.rs +++ /dev/null @@ -1,907 +0,0 @@ -use super::*; -use assert_matches2::assert_matches; -use futures::FutureExt; -use std::{ - collections::HashMap, - sync::{ - atomic::{AtomicBool, AtomicU32, Ordering}, - Arc, - }, - time::Duration, -}; -use tokio::{ - sync::{Mutex, Notify}, - time::sleep, -}; - -pub struct BlockOrchestrator { - pub current_block: Arc, - // used for resuming execution of a project that is waiting for a certain block to be reached - pub awaiting_projects: Mutex, Vec>>>, - pub should_continue: Arc, - pub instantiator_phantom: PhantomData<(T, AllPalletsWithoutSystem, RuntimeEvent)>, -} -pub async fn block_controller< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - block_orchestrator: Arc>, - instantiator: Arc>>, -) { - loop { - if !block_orchestrator.continue_running() { - break; - } - - let maybe_target_reached = block_orchestrator.advance_to_next_target(instantiator.clone()).await; - - if let Some(target_reached) = maybe_target_reached { - block_orchestrator.execute_callbacks(target_reached).await; - } - // leaves some time for the projects to submit their targets to the orchestrator - sleep(Duration::from_millis(100)).await; - } -} - -impl< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, - > Default for BlockOrchestrator -{ - fn default() -> Self { - Self::new() - } -} - -impl< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, - > BlockOrchestrator -{ - pub fn new() -> Self { - BlockOrchestrator:: { - current_block: Arc::new(AtomicU32::new(0)), - awaiting_projects: Mutex::new(HashMap::new()), - should_continue: Arc::new(AtomicBool::new(true)), - instantiator_phantom: PhantomData, - } - } - - pub async fn add_awaiting_project(&self, block_number: BlockNumberFor, notify: Arc) { - let mut awaiting_projects = self.awaiting_projects.lock().await; - awaiting_projects.entry(block_number).or_default().push(notify); - drop(awaiting_projects); - } - - pub async fn advance_to_next_target( - &self, - instantiator: Arc>>, - ) -> Option> { - let mut inst = instantiator.lock().await; - let now: u32 = inst.current_block().try_into().unwrap_or_else(|_| panic!("Block number should fit into u32")); - self.current_block.store(now, Ordering::SeqCst); - - let awaiting_projects = self.awaiting_projects.lock().await; - - if let Some(&next_block) = awaiting_projects.keys().min() { - drop(awaiting_projects); - - while self.get_current_block() < next_block { - inst.advance_time(One::one()).unwrap(); - let current_block: u32 = - self.get_current_block().try_into().unwrap_or_else(|_| panic!("Block number should fit into u32")); - self.current_block.store(current_block + 1u32, Ordering::SeqCst); - } - Some(next_block) - } else { - None - } - } - - pub async fn execute_callbacks(&self, block_number: BlockNumberFor) { - let mut awaiting_projects = self.awaiting_projects.lock().await; - if let Some(notifies) = awaiting_projects.remove(&block_number) { - for notify in notifies { - notify.notify_one(); - } - } - } - - pub async fn is_empty(&self) -> bool { - self.awaiting_projects.lock().await.is_empty() - } - - // Method to check if the loop should continue - pub fn continue_running(&self) -> bool { - self.should_continue.load(Ordering::SeqCst) - } - - // Method to get the current block number - pub fn get_current_block(&self) -> BlockNumberFor { - self.current_block.load(Ordering::SeqCst).into() - } -} - -// async instantiations for parallel testing -pub async fn async_create_new_project< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - project_metadata: ProjectMetadataOf, - issuer: AccountIdOf, -) -> ProjectId { - let mut inst = instantiator.lock().await; - - let now = inst.current_block(); - let ed = inst.get_ed(); - // One ED for the issuer, one for the escrow account - inst.mint_plmc_to(vec![UserToPLMCBalance::new(issuer.clone(), ed * 2u64.into())]); - inst.execute(|| { - crate::Pallet::::do_create_project( - &issuer.clone(), - project_metadata.clone(), - generate_did_from_account(issuer.clone()), - ) - .unwrap(); - let last_project_metadata = ProjectsMetadata::::iter().last().unwrap(); - log::trace!("Last project metadata: {:?}", last_project_metadata); - }); - - let created_project_id = inst.execute(|| NextProjectId::::get().saturating_sub(One::one())); - inst.creation_assertions(created_project_id, project_metadata, now); - created_project_id -} - -pub async fn async_create_evaluating_project< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - project_metadata: ProjectMetadataOf, - issuer: AccountIdOf, -) -> ProjectId { - let project_id = async_create_new_project(instantiator.clone(), project_metadata, issuer.clone()).await; - - let mut inst = instantiator.lock().await; - - inst.start_evaluation(project_id, issuer).unwrap(); - project_id -} - -pub async fn async_start_auction< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - project_id: ProjectId, - caller: AccountIdOf, -) -> Result<(), DispatchError> { - let mut inst = instantiator.lock().await; - - let project_details = inst.get_project_details(project_id); - - if project_details.status == ProjectStatus::EvaluationRound { - let update_block = inst.get_update_block(project_id, &UpdateType::EvaluationEnd).unwrap(); - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(update_block, notify.clone()).await; - - // Wait for the notification that our desired block was reached to continue - drop(inst); - - notify.notified().await; - - inst = instantiator.lock().await; - }; - - assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::AuctionInitializePeriod); - - inst.execute(|| crate::Pallet::::do_start_auction_opening(caller.clone(), project_id).unwrap()); - - assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::AuctionOpening); - - Ok(()) -} - -pub async fn async_create_auctioning_project< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - project_metadata: ProjectMetadataOf, - issuer: AccountIdOf, - evaluations: Vec>, - bids: Vec>, -) -> ProjectId { - let project_id = - async_create_evaluating_project(instantiator.clone(), project_metadata.clone(), issuer.clone()).await; - - let mut inst = instantiator.lock().await; - - let evaluators = evaluations.accounts(); - let prev_supply = inst.get_plmc_total_supply(); - let prev_plmc_balances = inst.get_free_plmc_balances_for(evaluators.clone()); - - let plmc_eval_deposits: Vec> = inst.calculate_evaluation_plmc_spent(evaluations.clone()); - let plmc_existential_deposits: Vec> = evaluators.existential_deposits(); - - let expected_remaining_plmc: Vec> = - inst.generic_map_operation(vec![prev_plmc_balances, plmc_existential_deposits.clone()], MergeOperation::Add); - - inst.mint_plmc_to(plmc_eval_deposits.clone()); - inst.mint_plmc_to(plmc_existential_deposits.clone()); - - inst.evaluate_for_users(project_id, evaluations).unwrap(); - - let expected_evaluator_balances = - inst.sum_balance_mappings(vec![plmc_eval_deposits.clone(), plmc_existential_deposits.clone()]); - - let expected_total_supply = prev_supply + expected_evaluator_balances; - - inst.evaluation_assertions(project_id, expected_remaining_plmc, plmc_eval_deposits, expected_total_supply); - - drop(inst); - - async_start_auction(instantiator.clone(), block_orchestrator, project_id, issuer).await.unwrap(); - - inst = instantiator.lock().await; - let plmc_for_bids = - inst.calculate_auction_plmc_charged_from_all_bids_made_or_with_bucket(&bids, project_metadata.clone(), None); - let plmc_existential_deposits: Vec> = bids.accounts().existential_deposits(); - let usdt_for_bids = - inst.calculate_auction_funding_asset_charged_from_all_bids_made_or_with_bucket(&bids, project_metadata, None); - - inst.mint_plmc_to(plmc_for_bids.clone()); - inst.mint_plmc_to(plmc_existential_deposits.clone()); - inst.mint_foreign_asset_to(usdt_for_bids.clone()); - - inst.bid_for_users(project_id, bids).unwrap(); - drop(inst); - - project_id -} - -pub async fn async_start_community_funding< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - project_id: ProjectId, -) -> Result<(), DispatchError> { - let mut inst = instantiator.lock().await; - if let Some(update_block) = inst.get_update_block(project_id, &UpdateType::AuctionClosingStart) { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(update_block, notify.clone()).await; - drop(inst); - notify.notified().await; - } - let mut inst = instantiator.lock().await; - if let Some(update_block) = inst.get_update_block(project_id, &UpdateType::AuctionClosingEnd) { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(update_block, notify.clone()).await; - drop(inst); - notify.notified().await; - } - let mut inst = instantiator.lock().await; - if let Some(update_block) = inst.get_update_block(project_id, &UpdateType::CommunityFundingStart) { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(update_block, notify.clone()).await; - drop(inst); - notify.notified().await; - } - let mut inst = instantiator.lock().await; - - ensure!( - inst.get_project_details(project_id).status == ProjectStatus::CommunityRound, - DispatchError::from("Auction failed") - ); - - Ok(()) -} - -pub async fn async_create_community_contributing_project< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - project_metadata: ProjectMetadataOf, - issuer: AccountIdOf, - evaluations: Vec>, - bids: Vec>, -) -> (ProjectId, Vec>) { - if bids.is_empty() { - panic!("Cannot start community funding without bids") - } - - let project_id = async_create_auctioning_project( - instantiator.clone(), - block_orchestrator.clone(), - project_metadata.clone(), - issuer, - evaluations.clone(), - vec![], - ) - .await; - - let mut inst = instantiator.lock().await; - - let bidders = bids.accounts(); - let asset_id = bids[0].asset.to_assethub_id(); - let prev_plmc_balances = inst.get_free_plmc_balances_for(bidders.clone()); - let prev_funding_asset_balances = inst.get_free_foreign_asset_balances_for(asset_id, bidders.clone()); - let plmc_evaluation_deposits: Vec> = inst.calculate_evaluation_plmc_spent(evaluations); - let plmc_bid_deposits: Vec> = - inst.calculate_auction_plmc_charged_from_all_bids_made_or_with_bucket(&bids, project_metadata.clone(), None); - let participation_usable_evaluation_deposits = plmc_evaluation_deposits - .into_iter() - .map(|mut x| { - x.plmc_amount = x.plmc_amount.saturating_sub(::EvaluatorSlash::get() * x.plmc_amount); - x - }) - .collect::>>(); - let necessary_plmc_mint = inst.generic_map_operation( - vec![plmc_bid_deposits.clone(), participation_usable_evaluation_deposits], - MergeOperation::Subtract, - ); - let total_plmc_participation_locked = plmc_bid_deposits; - let plmc_existential_deposits: Vec> = bidders.existential_deposits(); - let funding_asset_deposits = inst.calculate_auction_funding_asset_charged_from_all_bids_made_or_with_bucket( - &bids, - project_metadata.clone(), - None, - ); - - let bidder_balances = - inst.sum_balance_mappings(vec![necessary_plmc_mint.clone(), plmc_existential_deposits.clone()]); - - let expected_free_plmc_balances = - inst.generic_map_operation(vec![prev_plmc_balances, plmc_existential_deposits.clone()], MergeOperation::Add); - - let prev_supply = inst.get_plmc_total_supply(); - let post_supply = prev_supply + bidder_balances; - - inst.mint_plmc_to(necessary_plmc_mint.clone()); - inst.mint_plmc_to(plmc_existential_deposits.clone()); - inst.mint_foreign_asset_to(funding_asset_deposits.clone()); - - inst.bid_for_users(project_id, bids.clone()).unwrap(); - - inst.do_reserved_plmc_assertions( - total_plmc_participation_locked.merge_accounts(MergeOperation::Add), - HoldReason::Participation(project_id).into(), - ); - inst.do_bid_transferred_foreign_asset_assertions( - funding_asset_deposits.merge_accounts(MergeOperation::Add), - project_id, - ); - inst.do_free_plmc_assertions(expected_free_plmc_balances.merge_accounts(MergeOperation::Add)); - inst.do_free_foreign_asset_assertions(prev_funding_asset_balances.merge_accounts(MergeOperation::Add)); - assert_eq!(inst.get_plmc_total_supply(), post_supply); - - drop(inst); - async_start_community_funding(instantiator.clone(), block_orchestrator, project_id).await.unwrap(); - let mut inst = instantiator.lock().await; - - let _weighted_price = inst.get_project_details(project_id).weighted_average_price.unwrap(); - let accepted_bids = inst.filter_bids_after_auction( - bids, - project_metadata.auction_round_allocation_percentage * project_metadata.total_allocation_size, - ); - let bid_expectations = accepted_bids - .iter() - .map(|bid| BidInfoFilter:: { - bidder: Some(bid.bidder.clone()), - final_ct_amount: Some(bid.amount), - ..Default::default() - }) - .collect_vec(); - - let total_ct_sold = accepted_bids.iter().map(|bid| bid.amount).fold(Zero::zero(), |acc, item| item + acc); - - inst.finalized_bids_assertions(project_id, bid_expectations, total_ct_sold); - - (project_id, accepted_bids) -} - -pub async fn async_start_remainder_or_end_funding< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - project_id: ProjectId, -) -> Result<(), DispatchError> { - let mut inst = instantiator.lock().await; - - assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::CommunityRound); - - let update_block = inst.get_update_block(project_id, &UpdateType::RemainderFundingStart).unwrap(); - let remainder_start = update_block; - - let notify = Arc::new(Notify::new()); - - block_orchestrator.add_awaiting_project(remainder_start, notify.clone()).await; - - // Wait for the notification that our desired block was reached to continue - - drop(inst); - - notify.notified().await; - - let mut inst = instantiator.lock().await; - - assert_matches!( - inst.get_project_details(project_id).status, - (ProjectStatus::RemainderRound | ProjectStatus::FundingSuccessful) - ); - Ok(()) -} - -pub async fn async_create_remainder_contributing_project< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - project_metadata: ProjectMetadataOf, - issuer: AccountIdOf, - evaluations: Vec>, - bids: Vec>, - contributions: Vec>, -) -> (ProjectId, Vec>) { - let (project_id, accepted_bids) = async_create_community_contributing_project( - instantiator.clone(), - block_orchestrator.clone(), - project_metadata, - issuer, - evaluations.clone(), - bids, - ) - .await; - - if contributions.is_empty() { - async_start_remainder_or_end_funding(instantiator.clone(), block_orchestrator.clone(), project_id) - .await - .unwrap(); - return (project_id, accepted_bids); - } - - let mut inst = instantiator.lock().await; - - let ct_price = inst.get_project_details(project_id).weighted_average_price.unwrap(); - let contributors = contributions.accounts(); - let asset_id = contributions[0].asset.to_assethub_id(); - let prev_plmc_balances = inst.get_free_plmc_balances_for(contributors.clone()); - let prev_funding_asset_balances = inst.get_free_foreign_asset_balances_for(asset_id, contributors.clone()); - - let plmc_evaluation_deposits = inst.calculate_evaluation_plmc_spent(evaluations); - let plmc_bid_deposits = inst.calculate_auction_plmc_charged_with_given_price(&accepted_bids, ct_price); - - let plmc_contribution_deposits = inst.calculate_contributed_plmc_spent(contributions.clone(), ct_price); - - let necessary_plmc_mint = inst.generic_map_operation( - vec![plmc_contribution_deposits.clone(), plmc_evaluation_deposits], - MergeOperation::Subtract, - ); - let total_plmc_participation_locked = - inst.generic_map_operation(vec![plmc_bid_deposits, plmc_contribution_deposits], MergeOperation::Add); - let plmc_existential_deposits = contributors.existential_deposits(); - - let funding_asset_deposits = inst.calculate_contributed_funding_asset_spent(contributions.clone(), ct_price); - let contributor_balances = - inst.sum_balance_mappings(vec![necessary_plmc_mint.clone(), plmc_existential_deposits.clone()]); - - let expected_free_plmc_balances = - inst.generic_map_operation(vec![prev_plmc_balances, plmc_existential_deposits.clone()], MergeOperation::Add); - - let prev_supply = inst.get_plmc_total_supply(); - let post_supply = prev_supply + contributor_balances; - - inst.mint_plmc_to(necessary_plmc_mint.clone()); - inst.mint_plmc_to(plmc_existential_deposits.clone()); - inst.mint_foreign_asset_to(funding_asset_deposits.clone()); - - inst.contribute_for_users(project_id, contributions).expect("Contributing should work"); - - inst.do_reserved_plmc_assertions( - total_plmc_participation_locked.merge_accounts(MergeOperation::Add), - HoldReason::Participation(project_id).into(), - ); - inst.do_contribution_transferred_foreign_asset_assertions( - funding_asset_deposits.merge_accounts(MergeOperation::Add), - project_id, - ); - inst.do_free_plmc_assertions(expected_free_plmc_balances.merge_accounts(MergeOperation::Add)); - inst.do_free_foreign_asset_assertions(prev_funding_asset_balances.merge_accounts(MergeOperation::Add)); - assert_eq!(inst.get_plmc_total_supply(), post_supply); - drop(inst); - async_start_remainder_or_end_funding(instantiator.clone(), block_orchestrator.clone(), project_id).await.unwrap(); - (project_id, accepted_bids) -} - -pub async fn async_finish_funding< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - project_id: ProjectId, -) -> Result<(), DispatchError> { - let mut inst = instantiator.lock().await; - let update_block = inst.get_update_block(project_id, &UpdateType::FundingEnd).unwrap(); - - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(update_block, notify.clone()).await; - drop(inst); - notify.notified().await; - Ok(()) -} - -pub async fn async_create_finished_project< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - project_metadata: ProjectMetadataOf, - issuer: AccountIdOf, - evaluations: Vec>, - bids: Vec>, - community_contributions: Vec>, - remainder_contributions: Vec>, -) -> ProjectId { - let (project_id, accepted_bids) = async_create_remainder_contributing_project( - instantiator.clone(), - block_orchestrator.clone(), - project_metadata.clone(), - issuer, - evaluations.clone(), - bids.clone(), - community_contributions.clone(), - ) - .await; - - let mut inst = instantiator.lock().await; - - let total_ct_sold_in_bids = bids.iter().map(|bid| bid.amount).fold(Zero::zero(), |acc, item| item + acc); - let total_ct_sold_in_community_contributions = - community_contributions.iter().map(|cont| cont.amount).fold(Zero::zero(), |acc, item| item + acc); - let total_ct_sold_in_remainder_contributions = - remainder_contributions.iter().map(|cont| cont.amount).fold(Zero::zero(), |acc, item| item + acc); - - let total_ct_sold = - total_ct_sold_in_bids + total_ct_sold_in_community_contributions + total_ct_sold_in_remainder_contributions; - let total_ct_available = project_metadata.total_allocation_size; - assert!( - total_ct_sold <= total_ct_available, - "Some CT buys are getting less than expected due to running out of CTs. This is ok in the runtime, but likely unexpected from the parameters of this instantiation" - ); - - match inst.get_project_details(project_id).status { - ProjectStatus::FundingSuccessful => return project_id, - ProjectStatus::RemainderRound if remainder_contributions.is_empty() => { - drop(inst); - async_finish_funding(instantiator.clone(), block_orchestrator.clone(), project_id).await.unwrap(); - return project_id; - }, - _ => {}, - }; - - let ct_price = inst.get_project_details(project_id).weighted_average_price.unwrap(); - let contributors = remainder_contributions.accounts(); - let asset_id = remainder_contributions[0].asset.to_assethub_id(); - let prev_plmc_balances = inst.get_free_plmc_balances_for(contributors.clone()); - let prev_funding_asset_balances = inst.get_free_foreign_asset_balances_for(asset_id, contributors.clone()); - - let plmc_evaluation_deposits = inst.calculate_evaluation_plmc_spent(evaluations); - let plmc_bid_deposits = inst.calculate_auction_plmc_charged_from_all_bids_made_or_with_bucket( - &accepted_bids, - project_metadata.clone(), - None, - ); - let plmc_community_contribution_deposits = - inst.calculate_contributed_plmc_spent(community_contributions.clone(), ct_price); - let plmc_remainder_contribution_deposits = - inst.calculate_contributed_plmc_spent(remainder_contributions.clone(), ct_price); - - let necessary_plmc_mint = inst.generic_map_operation( - vec![plmc_remainder_contribution_deposits.clone(), plmc_evaluation_deposits], - MergeOperation::Subtract, - ); - let total_plmc_participation_locked = inst.generic_map_operation( - vec![plmc_bid_deposits, plmc_community_contribution_deposits, plmc_remainder_contribution_deposits], - MergeOperation::Add, - ); - let plmc_existential_deposits = contributors.existential_deposits(); - let funding_asset_deposits = - inst.calculate_contributed_funding_asset_spent(remainder_contributions.clone(), ct_price); - - let contributor_balances = - inst.sum_balance_mappings(vec![necessary_plmc_mint.clone(), plmc_existential_deposits.clone()]); - - let expected_free_plmc_balances = - inst.generic_map_operation(vec![prev_plmc_balances, plmc_existential_deposits.clone()], MergeOperation::Add); - - let prev_supply = inst.get_plmc_total_supply(); - let post_supply = prev_supply + contributor_balances; - - inst.mint_plmc_to(necessary_plmc_mint.clone()); - inst.mint_plmc_to(plmc_existential_deposits.clone()); - inst.mint_foreign_asset_to(funding_asset_deposits.clone()); - - inst.contribute_for_users(project_id, remainder_contributions.clone()).expect("Remainder Contributing should work"); - - let merged = total_plmc_participation_locked.merge_accounts(MergeOperation::Add); - - inst.do_reserved_plmc_assertions(merged, HoldReason::Participation(project_id).into()); - - inst.do_contribution_transferred_foreign_asset_assertions( - funding_asset_deposits.merge_accounts(MergeOperation::Add), - project_id, - ); - inst.do_free_plmc_assertions(expected_free_plmc_balances.merge_accounts(MergeOperation::Add)); - inst.do_free_foreign_asset_assertions(prev_funding_asset_balances.merge_accounts(MergeOperation::Add)); - assert_eq!(inst.get_plmc_total_supply(), post_supply); - - drop(inst); - async_finish_funding(instantiator.clone(), block_orchestrator.clone(), project_id).await.unwrap(); - let mut inst = instantiator.lock().await; - - if inst.get_project_details(project_id).status == ProjectStatus::FundingSuccessful { - // Check that remaining CTs are updated - let project_details = inst.get_project_details(project_id); - let auction_bought_tokens = - accepted_bids.iter().map(|bid| bid.amount).fold(Zero::zero(), |acc, item| item + acc); - let community_bought_tokens = - community_contributions.iter().map(|cont| cont.amount).fold(Zero::zero(), |acc, item| item + acc); - let remainder_bought_tokens = - remainder_contributions.iter().map(|cont| cont.amount).fold(Zero::zero(), |acc, item| item + acc); - - assert_eq!( - project_details.remaining_contribution_tokens, - project_metadata.total_allocation_size - - auction_bought_tokens - - community_bought_tokens - - remainder_bought_tokens, - "Remaining CTs are incorrect" - ); - } - - project_id -} - -pub async fn create_project_at< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Arc>>, - block_orchestrator: Arc>, - test_project_params: TestProjectParams, -) -> ProjectId { - match test_project_params.expected_state { - ProjectStatus::FundingSuccessful => - async_create_finished_project( - instantiator, - block_orchestrator, - test_project_params.metadata, - test_project_params.issuer, - test_project_params.evaluations, - test_project_params.bids, - test_project_params.community_contributions, - test_project_params.remainder_contributions, - ) - .await, - ProjectStatus::RemainderRound => - async_create_remainder_contributing_project( - instantiator, - block_orchestrator, - test_project_params.metadata, - test_project_params.issuer, - test_project_params.evaluations, - test_project_params.bids, - test_project_params.community_contributions, - ) - .map(|(project_id, _)| project_id) - .await, - ProjectStatus::CommunityRound => - async_create_community_contributing_project( - instantiator, - block_orchestrator, - test_project_params.metadata, - test_project_params.issuer, - test_project_params.evaluations, - test_project_params.bids, - ) - .map(|(project_id, _)| project_id) - .await, - ProjectStatus::AuctionOpening => - async_create_auctioning_project( - instantiator, - block_orchestrator, - test_project_params.metadata, - test_project_params.issuer, - test_project_params.evaluations, - test_project_params.bids, - ) - .await, - ProjectStatus::EvaluationRound => - async_create_evaluating_project(instantiator, test_project_params.metadata, test_project_params.issuer) - .await, - ProjectStatus::Application => - async_create_new_project(instantiator, test_project_params.metadata, test_project_params.issuer).await, - _ => panic!("unsupported project creation in that status"), - } -} - -pub async fn async_create_project_at< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize>, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - mutex_inst: Arc>>, - block_orchestrator: Arc>, - test_project_params: TestProjectParams, -) -> ProjectId { - let time_to_new_project: BlockNumberFor = Zero::zero(); - let time_to_evaluation: BlockNumberFor = time_to_new_project + Zero::zero(); - // we immediately start the auction, so we don't wait for T::AuctionInitializePeriodDuration. - let time_to_auction: BlockNumberFor = time_to_evaluation + ::EvaluationDuration::get(); - let wap_calculation_duration: BlockNumberFor = 2u32.into(); - let time_to_community: BlockNumberFor = time_to_auction + - ::AuctionOpeningDuration::get() + - ::AuctionClosingDuration::get() + - wap_calculation_duration; - let time_to_remainder: BlockNumberFor = time_to_community + ::CommunityFundingDuration::get(); - let time_to_finish: BlockNumberFor = time_to_remainder + ::RemainderFundingDuration::get(); - - let mut inst = mutex_inst.lock().await; - let now = inst.current_block(); - drop(inst); - - match test_project_params.expected_state { - ProjectStatus::Application => { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(now + time_to_finish - time_to_new_project, notify.clone()).await; - // Wait for the notification that our desired block was reached to continue - notify.notified().await; - async_create_new_project(mutex_inst.clone(), test_project_params.metadata, test_project_params.issuer).await - }, - ProjectStatus::EvaluationRound => { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(now + time_to_finish - time_to_evaluation, notify.clone()).await; - // Wait for the notification that our desired block was reached to continue - notify.notified().await; - async_create_evaluating_project( - mutex_inst.clone(), - test_project_params.metadata, - test_project_params.issuer, - ) - .await - }, - ProjectStatus::AuctionOpening | ProjectStatus::AuctionClosing => { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(now + time_to_finish - time_to_auction, notify.clone()).await; - // Wait for the notification that our desired block was reached to continue - notify.notified().await; - async_create_auctioning_project( - mutex_inst.clone(), - block_orchestrator.clone(), - test_project_params.metadata, - test_project_params.issuer, - test_project_params.evaluations, - test_project_params.bids, - ) - .await - }, - ProjectStatus::CommunityRound => { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(now + time_to_finish - time_to_community, notify.clone()).await; - // Wait for the notification that our desired block was reached to continue - notify.notified().await; - async_create_community_contributing_project( - mutex_inst.clone(), - block_orchestrator.clone(), - test_project_params.metadata, - test_project_params.issuer, - test_project_params.evaluations, - test_project_params.bids, - ) - .map(|(project_id, _)| project_id) - .await - }, - ProjectStatus::RemainderRound => { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(now + time_to_finish - time_to_remainder, notify.clone()).await; - // Wait for the notification that our desired block was reached to continue - notify.notified().await; - async_create_remainder_contributing_project( - mutex_inst.clone(), - block_orchestrator.clone(), - test_project_params.metadata, - test_project_params.issuer, - test_project_params.evaluations, - test_project_params.bids, - test_project_params.community_contributions, - ) - .map(|(project_id, _)| project_id) - .await - }, - ProjectStatus::FundingSuccessful => { - let notify = Arc::new(Notify::new()); - block_orchestrator.add_awaiting_project(now + time_to_finish - time_to_finish, notify.clone()).await; - // Wait for the notification that our desired block was reached to continue - notify.notified().await; - async_create_finished_project( - mutex_inst.clone(), - block_orchestrator.clone(), - test_project_params.metadata, - test_project_params.issuer, - test_project_params.evaluations, - test_project_params.bids, - test_project_params.community_contributions, - test_project_params.remainder_contributions, - ) - .await - }, - _ => unimplemented!("Unsupported project creation in that status"), - } -} - -pub fn create_multiple_projects_at< - T: Config + pallet_balances::Config>, - AllPalletsWithoutSystem: OnFinalize> + OnIdle> + OnInitialize> + 'static + 'static, - RuntimeEvent: From> + TryInto> + Parameter + Member + IsType<::RuntimeEvent>, ->( - instantiator: Instantiator, - projects: Vec>, -) -> (Vec, Instantiator) { - use tokio::runtime::Builder; - let tokio_runtime = Builder::new_current_thread().enable_all().build().unwrap(); - let local = tokio::task::LocalSet::new(); - let execution = local.run_until(async move { - let block_orchestrator = Arc::new(BlockOrchestrator::new()); - let mutex_inst = Arc::new(Mutex::new(instantiator)); - - let project_futures = projects.into_iter().map(|project| { - let block_orchestrator = block_orchestrator.clone(); - let mutex_inst = mutex_inst.clone(); - tokio::task::spawn_local(async { async_create_project_at(mutex_inst, block_orchestrator, project).await }) - }); - - // Wait for all project creation tasks to complete - let joined_project_futures = futures::future::join_all(project_futures); - let controller_handle = - tokio::task::spawn_local(block_controller(block_orchestrator.clone(), mutex_inst.clone())); - let projects = joined_project_futures.await; - - // Now that all projects have been set up, signal the block_controller to stop - block_orchestrator.should_continue.store(false, Ordering::SeqCst); - - // Wait for the block controller to finish - controller_handle.await.unwrap(); - - let inst = Arc::try_unwrap(mutex_inst).unwrap_or_else(|_| panic!("mutex in use")).into_inner(); - let project_ids = projects.into_iter().map(|project| project.unwrap()).collect_vec(); - - (project_ids, inst) - }); - tokio_runtime.block_on(execution) -} diff --git a/pallets/funding/src/instantiator/mod.rs b/pallets/funding/src/instantiator/mod.rs index 62fc6402c..111062f2a 100644 --- a/pallets/funding/src/instantiator/mod.rs +++ b/pallets/funding/src/instantiator/mod.rs @@ -52,12 +52,13 @@ use sp_std::{ marker::PhantomData, }; +#[cfg(any(feature = "std", feature = "runtime-benchmarks"))] pub mod macros; pub mod types; pub use types::*; pub mod traits; pub use traits::*; -#[cfg(feature = "std")] -pub mod async_features; +#[cfg(any(feature = "std", feature = "runtime-benchmarks"))] pub mod calculations; +#[cfg(any(feature = "std", feature = "runtime-benchmarks"))] pub mod chain_interactions; diff --git a/pallets/funding/src/instantiator/types.rs b/pallets/funding/src/instantiator/types.rs index 25fe56688..94def5617 100644 --- a/pallets/funding/src/instantiator/types.rs +++ b/pallets/funding/src/instantiator/types.rs @@ -1,4 +1,5 @@ use super::*; +use frame_support::{Deserialize, Serialize}; pub type RuntimeOriginOf = ::RuntimeOrigin; pub struct BoxToFunction(pub Box); @@ -8,12 +9,8 @@ impl Default for BoxToFunction { } } -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr( - feature = "std", - serde(rename_all = "camelCase", deny_unknown_fields, bound(serialize = ""), bound(deserialize = "")) -)] -#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)] +#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, Serialize, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields, bound(serialize = ""), bound(deserialize = ""))] pub struct TestProjectParams { pub expected_state: ProjectStatus, pub metadata: ProjectMetadataOf, @@ -108,12 +105,8 @@ impl AccountMerge for Vec> { } } -#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr( - feature = "std", - serde(rename_all = "camelCase", deny_unknown_fields, bound(serialize = ""), bound(deserialize = "")) -)] +#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields, bound(serialize = ""), bound(deserialize = ""))] pub struct UserToUSDBalance { pub account: AccountIdOf, pub usd_amount: BalanceOf, @@ -239,12 +232,8 @@ impl AccountMerge for Vec> { } } -#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr( - feature = "std", - serde(rename_all = "camelCase", deny_unknown_fields, bound(serialize = ""), bound(deserialize = "")) -)] +#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields, bound(serialize = ""), bound(deserialize = ""))] pub struct BidParams { pub bidder: AccountIdOf, pub amount: BalanceOf, @@ -308,12 +297,8 @@ impl Accounts for Vec> { } } -#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr( - feature = "std", - serde(rename_all = "camelCase", deny_unknown_fields, bound(serialize = ""), bound(deserialize = "")) -)] +#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields, bound(serialize = ""), bound(deserialize = ""))] pub struct ContributionParams { pub contributor: AccountIdOf, pub amount: BalanceOf, diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index 589719db3..225a056ec 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -117,6 +117,8 @@ // This recursion limit is needed because we have too many benchmarks and benchmarking will fail if // we add more without this limit. #![cfg_attr(feature = "runtime-benchmarks", recursion_limit = "512")] +extern crate alloc; + pub use crate::weights::WeightInfo; use frame_support::{ traits::{ @@ -151,7 +153,6 @@ pub mod tests; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; mod functions; -#[cfg(any(feature = "runtime-benchmarks", feature = "std"))] pub mod instantiator; pub mod traits; @@ -202,9 +203,6 @@ pub mod pallet { DispatchErrorWithPostInfo, }; - #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] - use crate::traits::SetPrices; - #[pallet::composite_enum] pub enum HoldReason { Evaluation(ProjectId), @@ -411,8 +409,8 @@ pub mod pallet { + Into::RuntimeOrigin>>; /// test and benchmarking helper to set the prices of assets - #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] - type SetPrices: SetPrices; + #[cfg(any(feature = "runtime-benchmarks"))] + type SetPrices: traits::SetPrices; /// The maximum length of data stored on-chain. #[pallet::constant] @@ -1355,54 +1353,6 @@ pub mod pallet { used_weight } } - - #[pallet::genesis_config] - #[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)] - pub struct GenesisConfig - where - T: Config + pallet_balances::Config>, - ::Balance: Into>, - { - #[cfg(feature = "std")] - pub starting_projects: Vec>, - pub phantom: PhantomData, - } - - impl Default for GenesisConfig - where - T: Config + pallet_balances::Config>, - ::Balance: Into>, - { - fn default() -> Self { - Self { - #[cfg(feature = "std")] - starting_projects: vec![], - phantom: PhantomData, - } - } - } - - #[pallet::genesis_build] - impl BuildGenesisConfig for GenesisConfig - where - T: Config + pallet_balances::Config>, - ::Balance: Into>, - { - fn build(&self) { - #[cfg(any(feature = "std", feature = "runtime-benchmarks"))] - { - ::SetPrices::set_prices(); - } - #[cfg(feature = "std")] - { - type GenesisInstantiator = - instantiator::Instantiator::AllPalletsWithoutSystem, ::RuntimeEvent>; - let inst = GenesisInstantiator::::new(None); - instantiator::async_features::create_multiple_projects_at(inst, self.starting_projects.clone()); - frame_system::Pallet::::set_block_number(0u32.into()); - } - } - } } pub mod xcm_executor_impl { diff --git a/pallets/funding/src/mock.rs b/pallets/funding/src/mock.rs index e6ae3964d..c29ae3194 100644 --- a/pallets/funding/src/mock.rs +++ b/pallets/funding/src/mock.rs @@ -437,7 +437,7 @@ impl Config for TestRuntime { type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeOrigin = RuntimeOrigin; - #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] + #[cfg(any(feature = "runtime-benchmarks"))] type SetPrices = (); type StringLimit = ConstU32<64>; type SuccessToSettlementTime = SuccessToSettlementTime; @@ -458,7 +458,7 @@ construct_runtime!( ContributionTokens: pallet_assets::::{Pallet, Call, Storage, Event}, ForeignAssets: pallet_assets::::{Pallet, Call, Storage, Event, Config}, PolkadotXcm: pallet_xcm, - PolimecFunding: pallet_funding::{Pallet, Call, Storage, Event, Config, HoldReason} = 52, + PolimecFunding: pallet_funding::{Pallet, Call, Storage, Event, HoldReason} = 52, } ); diff --git a/pallets/funding/src/tests/3_auction.rs b/pallets/funding/src/tests/3_auction.rs index 8e3ecceec..4b724e32f 100644 --- a/pallets/funding/src/tests/3_auction.rs +++ b/pallets/funding/src/tests/3_auction.rs @@ -929,7 +929,8 @@ mod bid_extrinsic { #[test] fn bid_with_multiple_currencies() { - let inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let mut project_metadata_all = default_project_metadata(ISSUER_1); project_metadata_all.participation_currencies = vec![AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC, AcceptedFundingAsset::DOT] @@ -947,51 +948,6 @@ mod bid_extrinsic { let evaluations = default_evaluations(); - let projects = vec![ - TestProjectParams { - expected_state: ProjectStatus::AuctionOpening, - metadata: project_metadata_all.clone(), - issuer: ISSUER_1, - evaluations: evaluations.clone(), - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::AuctionOpening, - metadata: project_metadata_usdt, - issuer: ISSUER_2, - evaluations: evaluations.clone(), - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::AuctionOpening, - metadata: project_metadata_usdc, - issuer: ISSUER_3, - evaluations: evaluations.clone(), - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::AuctionOpening, - metadata: project_metadata_dot, - issuer: ISSUER_4, - evaluations: evaluations.clone(), - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - ]; - let (project_ids, mut inst) = create_multiple_projects_at(inst, projects); - - let project_id_all = project_ids[0]; - let project_id_usdt = project_ids[1]; - let project_id_usdc = project_ids[2]; - let project_id_dot = project_ids[3]; - let usdt_bid = BidParams::new(BIDDER_1, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDT); let usdc_bid = BidParams::new(BIDDER_1, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDC); let dot_bid = BidParams::new(BIDDER_1, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::DOT); @@ -1016,8 +972,10 @@ mod bid_extrinsic { inst.mint_foreign_asset_to(usdt_fundings.clone()); inst.mint_foreign_asset_to(usdt_fundings.clone()); + let project_id_all = inst.create_auctioning_project(project_metadata_all, ISSUER_1, evaluations.clone()); assert_ok!(inst.bid_for_users(project_id_all, vec![usdt_bid.clone(), usdc_bid.clone(), dot_bid.clone()])); + let project_id_usdt = inst.create_auctioning_project(project_metadata_usdt, ISSUER_2, evaluations.clone()); assert_ok!(inst.bid_for_users(project_id_usdt, vec![usdt_bid.clone()])); assert_err!( inst.bid_for_users(project_id_usdt, vec![usdc_bid.clone()]), @@ -1028,6 +986,7 @@ mod bid_extrinsic { Error::::FundingAssetNotAccepted ); + let project_id_usdc = inst.create_auctioning_project(project_metadata_usdc, ISSUER_3, evaluations.clone()); assert_err!( inst.bid_for_users(project_id_usdc, vec![usdt_bid.clone()]), Error::::FundingAssetNotAccepted @@ -1038,6 +997,7 @@ mod bid_extrinsic { Error::::FundingAssetNotAccepted ); + let project_id_dot = inst.create_auctioning_project(project_metadata_dot, ISSUER_4, evaluations.clone()); assert_err!( inst.bid_for_users(project_id_dot, vec![usdt_bid.clone()]), Error::::FundingAssetNotAccepted diff --git a/pallets/funding/src/tests/4_community.rs b/pallets/funding/src/tests/4_community.rs index c3741171c..b38e812df 100644 --- a/pallets/funding/src/tests/4_community.rs +++ b/pallets/funding/src/tests/4_community.rs @@ -1090,6 +1090,7 @@ mod community_contribute_extrinsic { fungibles::Mutate as MutateFungibles, tokens::{Fortitude, Precision}, }; + use sp_runtime::bounded_vec; #[test] fn contribution_errors_if_user_limit_is_reached() { @@ -1654,13 +1655,13 @@ mod community_contribute_extrinsic { #[test] fn contribute_with_unaccepted_currencies() { - let inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); let mut project_metadata_usdt = default_project_metadata(ISSUER_2); - project_metadata_usdt.participation_currencies = vec![AcceptedFundingAsset::USDT].try_into().unwrap(); + project_metadata_usdt.participation_currencies = bounded_vec![AcceptedFundingAsset::USDT]; let mut project_metadata_usdc = default_project_metadata(ISSUER_3); - project_metadata_usdc.participation_currencies = vec![AcceptedFundingAsset::USDC].try_into().unwrap(); + project_metadata_usdc.participation_currencies = bounded_vec![AcceptedFundingAsset::USDC]; let evaluations = default_evaluations(); @@ -1680,39 +1681,27 @@ mod community_contribute_extrinsic { }) .collect::>(); - let projects = vec![ - TestProjectParams { - expected_state: ProjectStatus::CommunityRound, - metadata: project_metadata_usdt, - issuer: ISSUER_2, - evaluations: evaluations.clone(), - bids: usdt_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::CommunityRound, - metadata: project_metadata_usdc, - issuer: ISSUER_3, - evaluations: evaluations.clone(), - bids: usdc_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - ]; - let (project_ids, mut inst) = create_multiple_projects_at(inst, projects); - - let project_id_usdt = project_ids[0]; - let project_id_usdc = project_ids[1]; - let usdt_contribution = ContributionParams::new(BUYER_1, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDT); let usdc_contribution = ContributionParams::new(BUYER_2, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDC); let dot_contribution = ContributionParams::new(BUYER_3, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::DOT); + let project_id_usdc = inst.create_community_contributing_project( + project_metadata_usdc, + ISSUER_2, + evaluations.clone(), + usdc_bids.clone(), + ); assert_err!( inst.contribute_for_users(project_id_usdc, vec![usdt_contribution.clone()]), Error::::FundingAssetNotAccepted ); + + let project_id_usdt = inst.create_community_contributing_project( + project_metadata_usdt, + ISSUER_3, + evaluations.clone(), + usdt_bids.clone(), + ); assert_err!( inst.contribute_for_users(project_id_usdt, vec![usdc_contribution.clone()]), Error::::FundingAssetNotAccepted diff --git a/pallets/funding/src/tests/5_remainder.rs b/pallets/funding/src/tests/5_remainder.rs index e6f953269..6ffa0af51 100644 --- a/pallets/funding/src/tests/5_remainder.rs +++ b/pallets/funding/src/tests/5_remainder.rs @@ -1,5 +1,5 @@ use super::*; -use crate::instantiator::async_features::create_multiple_projects_at; +// use crate::instantiator::async_features::create_multiple_projects_at; use frame_support::{dispatch::DispatchResultWithPostInfo, traits::fungibles::metadata::Inspect}; use sp_runtime::bounded_vec; use std::collections::HashSet; @@ -25,47 +25,6 @@ mod round_flow { ); } - #[test] - fn multiple_remainder_projects_completed_in_parallel() { - let inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); - - let project_params = vec![ - TestProjectParams { - expected_state: ProjectStatus::FundingSuccessful, - metadata: default_project_metadata(ISSUER_1), - issuer: ISSUER_1, - evaluations: default_evaluations(), - bids: default_bids(), - community_contributions: default_community_buys(), - remainder_contributions: default_remainder_buys(), - }, - TestProjectParams { - expected_state: ProjectStatus::FundingSuccessful, - metadata: default_project_metadata(ISSUER_2), - issuer: ISSUER_2, - evaluations: default_evaluations(), - bids: default_bids(), - community_contributions: default_community_buys(), - remainder_contributions: default_remainder_buys(), - }, - TestProjectParams { - expected_state: ProjectStatus::FundingSuccessful, - metadata: default_project_metadata(ISSUER_3), - issuer: ISSUER_3, - evaluations: default_evaluations(), - bids: default_bids(), - community_contributions: default_community_buys(), - remainder_contributions: default_remainder_buys(), - }, - ]; - - let (_project_ids, mut inst) = create_multiple_projects_at(inst, project_params); - - assert_eq!(inst.get_project_details(0).status, ProjectStatus::FundingSuccessful); - assert_eq!(inst.get_project_details(1).status, ProjectStatus::FundingSuccessful); - assert_eq!(inst.get_project_details(2).status, ProjectStatus::FundingSuccessful); - } - #[test] fn remainder_round_ends_on_all_ct_sold_exact() { let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); @@ -515,13 +474,14 @@ mod remaining_contribute_extrinsic { #[test] fn contribute_with_multiple_currencies() { + let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let mut project_metadata_all = default_project_metadata(ISSUER_1); project_metadata_all.participation_currencies = vec![AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC, AcceptedFundingAsset::DOT] .try_into() .unwrap(); - let inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); let mut project_metadata_usdt = default_project_metadata(ISSUER_2); project_metadata_usdt.participation_currencies = vec![AcceptedFundingAsset::USDT].try_into().unwrap(); @@ -557,55 +517,17 @@ mod remaining_contribute_extrinsic { }) .collect::>(); - let projects = vec![ - TestProjectParams { - expected_state: ProjectStatus::RemainderRound, - metadata: project_metadata_all.clone(), - issuer: ISSUER_1, - evaluations: evaluations.clone(), - bids: usdt_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::RemainderRound, - metadata: project_metadata_usdt, - issuer: ISSUER_2, - evaluations: evaluations.clone(), - bids: usdt_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::RemainderRound, - metadata: project_metadata_usdc, - issuer: ISSUER_3, - evaluations: evaluations.clone(), - bids: usdc_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::RemainderRound, - metadata: project_metadata_dot, - issuer: ISSUER_4, - evaluations: evaluations.clone(), - bids: dot_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - ]; - let (project_ids, mut inst) = create_multiple_projects_at(inst, projects); - - let project_id_all = project_ids[0]; - let project_id_usdt = project_ids[1]; - let project_id_usdc = project_ids[2]; - let project_id_dot = project_ids[3]; - let usdt_contribution = ContributionParams::new(BUYER_1, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDT); let usdc_contribution = ContributionParams::new(BUYER_2, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDC); let dot_contribution = ContributionParams::new(BUYER_3, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::DOT); + let project_id_all = inst.create_remainder_contributing_project( + project_metadata_all.clone(), + ISSUER_1, + evaluations.clone(), + default_bids(), + vec![], + ); let wap = inst.get_project_details(project_id_all).weighted_average_price.unwrap(); let plmc_fundings = inst.calculate_contributed_plmc_spent( @@ -613,7 +535,6 @@ mod remaining_contribute_extrinsic { wap, ); let plmc_existential_deposits = plmc_fundings.accounts().existential_deposits(); - let plmc_all_mints = inst.generic_map_operation(vec![plmc_fundings, plmc_existential_deposits], MergeOperation::Add); inst.mint_plmc_to(plmc_all_mints.clone()); @@ -633,6 +554,14 @@ mod remaining_contribute_extrinsic { vec![usdt_contribution.clone(), usdc_contribution.clone(), dot_contribution.clone()] )); + let project_id_usdt = inst.create_remainder_contributing_project( + project_metadata_usdt.clone(), + ISSUER_2, + evaluations.clone(), + usdt_bids, + vec![], + ); + assert_ok!(inst.contribute_for_users(project_id_usdt, vec![usdt_contribution.clone()])); assert_err!( inst.contribute_for_users(project_id_usdt, vec![usdc_contribution.clone()]), @@ -643,6 +572,14 @@ mod remaining_contribute_extrinsic { Error::::FundingAssetNotAccepted ); + let project_id_usdc = inst.create_remainder_contributing_project( + project_metadata_usdc.clone(), + ISSUER_3, + evaluations.clone(), + usdc_bids, + vec![], + ); + assert_err!( inst.contribute_for_users(project_id_usdc, vec![usdt_contribution.clone()]), Error::::FundingAssetNotAccepted @@ -653,6 +590,14 @@ mod remaining_contribute_extrinsic { Error::::FundingAssetNotAccepted ); + let project_id_dot = inst.create_remainder_contributing_project( + project_metadata_dot.clone(), + ISSUER_4, + evaluations.clone(), + dot_bids, + vec![], + ); + assert_err!( inst.contribute_for_users(project_id_dot, vec![usdt_contribution.clone()]), Error::::FundingAssetNotAccepted @@ -1738,7 +1683,7 @@ mod remaining_contribute_extrinsic { #[test] fn contribute_with_unaccepted_currencies() { - let inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); let mut project_metadata_usdt = default_project_metadata(ISSUER_2); project_metadata_usdt.participation_currencies = vec![AcceptedFundingAsset::USDT].try_into().unwrap(); @@ -1764,39 +1709,29 @@ mod remaining_contribute_extrinsic { }) .collect::>(); - let projects = vec![ - TestProjectParams { - expected_state: ProjectStatus::RemainderRound, - metadata: project_metadata_usdt, - issuer: ISSUER_2, - evaluations: evaluations.clone(), - bids: usdt_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::RemainderRound, - metadata: project_metadata_usdc, - issuer: ISSUER_3, - evaluations: evaluations.clone(), - bids: usdc_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - ]; - let (project_ids, mut inst) = create_multiple_projects_at(inst, projects); - - let project_id_usdt = project_ids[0]; - let project_id_usdc = project_ids[1]; - let usdt_contribution = ContributionParams::new(BUYER_1, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDT); let usdc_contribution = ContributionParams::new(BUYER_2, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::USDC); let dot_contribution = ContributionParams::new(BUYER_3, 10_000 * CT_UNIT, 1u8, AcceptedFundingAsset::DOT); + let project_id_usdc = inst.create_remainder_contributing_project( + project_metadata_usdc, + ISSUER_3, + evaluations.clone(), + usdc_bids, + vec![], + ); assert_err!( inst.contribute_for_users(project_id_usdc, vec![usdt_contribution.clone()]), Error::::FundingAssetNotAccepted ); + + let project_id_usdt = inst.create_remainder_contributing_project( + project_metadata_usdt, + ISSUER_2, + evaluations.clone(), + usdt_bids, + vec![], + ); assert_err!( inst.contribute_for_users(project_id_usdt, vec![usdc_contribution.clone()]), Error::::FundingAssetNotAccepted diff --git a/pallets/funding/src/tests/misc.rs b/pallets/funding/src/tests/misc.rs index e53643773..ed05b8ead 100644 --- a/pallets/funding/src/tests/misc.rs +++ b/pallets/funding/src/tests/misc.rs @@ -345,278 +345,3 @@ mod inner_functions { assert_eq!(multiplier_25_duration, FixedU128::from_rational(52008, 1000).saturating_mul_int((DAYS * 7) as u64)); } } - -// test the parallel instantiation of projects -mod async_tests { - use super::*; - - #[test] - fn prototype_2() { - let inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); - - let project_params = vec![ - TestProjectParams { - expected_state: ProjectStatus::Application, - metadata: default_project_metadata(ISSUER_1), - issuer: ISSUER_1, - evaluations: vec![], - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::EvaluationRound, - metadata: default_project_metadata(ISSUER_2), - issuer: ISSUER_2, - evaluations: vec![], - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::AuctionOpening, - metadata: default_project_metadata(ISSUER_3), - issuer: ISSUER_3, - evaluations: default_evaluations(), - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::CommunityRound, - metadata: default_project_metadata(ISSUER_4), - issuer: ISSUER_4, - evaluations: default_evaluations(), - bids: default_bids(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::RemainderRound, - metadata: default_project_metadata(ISSUER_5), - issuer: ISSUER_5, - evaluations: default_evaluations(), - bids: default_bids(), - community_contributions: default_community_buys(), - remainder_contributions: vec![], - }, - TestProjectParams { - expected_state: ProjectStatus::FundingSuccessful, - metadata: default_project_metadata(ISSUER_6), - issuer: ISSUER_6, - evaluations: default_evaluations(), - bids: default_bids(), - community_contributions: default_community_buys(), - remainder_contributions: default_remainder_buys(), - }, - ]; - - let (project_ids, mut inst) = create_multiple_projects_at(inst, project_params); - - assert_eq!(inst.get_project_details(project_ids[0]).status, ProjectStatus::Application); - assert_eq!(inst.get_project_details(project_ids[1]).status, ProjectStatus::EvaluationRound); - assert_eq!(inst.get_project_details(project_ids[2]).status, ProjectStatus::AuctionOpening); - assert_eq!(inst.get_project_details(project_ids[3]).status, ProjectStatus::CommunityRound); - assert_eq!(inst.get_project_details(project_ids[4]).status, ProjectStatus::RemainderRound); - assert_eq!(inst.get_project_details(project_ids[5]).status, ProjectStatus::FundingSuccessful); - } - - #[test] - fn genesis_parallel_instantiaton() { - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - // only used to generate some values, and not for chain interactions - let inst = MockInstantiator::new(None); - - // only used to generate some values, and not for chain interactions - let funding_percent = 93u64; - let project_metadata = default_project_metadata(ISSUER_1.into()); - let min_price = project_metadata.minimum_price; - let twenty_percent_funding_usd = Perquintill::from_percent(funding_percent) * - (project_metadata.minimum_price.checked_mul_int(project_metadata.total_allocation_size).unwrap()); - let evaluations = default_evaluations(); - let bids = inst.generate_bids_from_total_usd( - Percent::from_percent(50u8) * twenty_percent_funding_usd, - min_price, - default_weights(), - default_bidders(), - default_bidder_multipliers(), - ); - let community_contributions = inst.generate_contributions_from_total_usd( - Percent::from_percent(30u8) * twenty_percent_funding_usd, - min_price, - default_weights(), - default_community_contributors(), - default_community_contributor_multipliers(), - ); - let remainder_contributions = inst.generate_contributions_from_total_usd( - Percent::from_percent(20u8) * twenty_percent_funding_usd, - min_price, - default_weights(), - default_remainder_contributors(), - default_remainder_contributor_multipliers(), - ); - let ed = ::ExistentialDeposit::get(); - mock::RuntimeGenesisConfig { - balances: BalancesConfig { - balances: vec![ - (::PalletId::get().into_account_truncating(), ed), - (::ContributionTreasury::get(), ed), - ], - }, - foreign_assets: ForeignAssetsConfig { - assets: vec![( - AcceptedFundingAsset::USDT.to_assethub_id(), - ::PalletId::get().into_account_truncating(), - false, - 10, - )], - metadata: vec![], - accounts: vec![], - }, - polimec_funding: PolimecFundingConfig { - starting_projects: vec![ - TestProjectParams:: { - expected_state: ProjectStatus::FundingSuccessful, - metadata: default_project_metadata(ISSUER_1.into()), - issuer: ISSUER_1.into(), - evaluations: evaluations.clone(), - bids: bids.clone(), - community_contributions: community_contributions.clone(), - remainder_contributions: remainder_contributions.clone(), - }, - TestProjectParams:: { - expected_state: ProjectStatus::RemainderRound, - metadata: default_project_metadata(ISSUER_2.into()), - issuer: (ISSUER_2).into(), - evaluations: evaluations.clone(), - bids: bids.clone(), - community_contributions: community_contributions.clone(), - remainder_contributions: vec![], - }, - TestProjectParams:: { - expected_state: ProjectStatus::CommunityRound, - metadata: default_project_metadata(ISSUER_3.into()), - issuer: (ISSUER_3).into(), - evaluations: evaluations.clone(), - bids: bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams:: { - expected_state: ProjectStatus::AuctionOpening, - metadata: default_project_metadata(ISSUER_4.into()), - issuer: ISSUER_4.into(), - evaluations: evaluations.clone(), - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams:: { - expected_state: ProjectStatus::EvaluationRound, - metadata: default_project_metadata(ISSUER_5.into()), - issuer: ISSUER_5.into(), - evaluations: vec![], - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - TestProjectParams:: { - expected_state: ProjectStatus::Application, - metadata: default_project_metadata(ISSUER_6.into()), - issuer: ISSUER_6.into(), - evaluations: vec![], - bids: vec![], - community_contributions: vec![], - remainder_contributions: vec![], - }, - ], - phantom: PhantomData, - }, - - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); - - let ext = sp_io::TestExternalities::new(t); - let mut inst = MockInstantiator::new(Some(RefCell::new(ext))); - - assert_eq!(inst.get_project_details(0).status, ProjectStatus::FundingSuccessful); - assert_eq!(inst.get_project_details(1).status, ProjectStatus::RemainderRound); - assert_eq!(inst.get_project_details(2).status, ProjectStatus::CommunityRound); - assert_eq!(inst.get_project_details(3).status, ProjectStatus::AuctionOpening); - assert_eq!(inst.get_project_details(4).status, ProjectStatus::EvaluationRound); - assert_eq!(inst.get_project_details(5).status, ProjectStatus::Application); - } - - #[test] - fn starting_auction_round_with_bids() { - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - - // only used to generate some values, and not for chain interactions - let mut project_metadata = default_project_metadata(ISSUER_1.into()); - let evaluations = default_evaluations(); - let max_bids_per_project: u32 = ::MaxBidsPerProject::get(); - let min_bid = project_metadata.bidding_ticket_sizes.institutional.usd_minimum_per_participation; - let auction_allocation_percentage = project_metadata.auction_round_allocation_percentage; - let auction_ct_required = min_bid.saturating_mul(max_bids_per_project as u128); - let total_allocation_required = auction_allocation_percentage.saturating_reciprocal_mul(auction_ct_required); - project_metadata.total_allocation_size = total_allocation_required; - - let min_bid_usd = project_metadata.bidding_ticket_sizes.institutional.usd_minimum_per_participation; - let min_bid_ct = project_metadata.minimum_price.reciprocal().unwrap().checked_mul_int(min_bid_usd).unwrap(); - let max_bids = (0u32..max_bids_per_project) - .map(|i| { - instantiator::BidParams::::new( - (i + 69).into(), - min_bid_ct, - 1u8, - AcceptedFundingAsset::USDT, - ) - }) - .collect_vec(); - let ed = ::ExistentialDeposit::get(); - mock::RuntimeGenesisConfig { - balances: BalancesConfig { - balances: vec![ - (::PalletId::get().into_account_truncating(), ed), - (::ContributionTreasury::get(), ed), - ], - }, - foreign_assets: ForeignAssetsConfig { - assets: vec![( - AcceptedFundingAsset::USDT.to_assethub_id(), - ::PalletId::get().into_account_truncating(), - false, - 10, - )], - metadata: vec![], - accounts: vec![], - }, - polimec_funding: PolimecFundingConfig { - starting_projects: vec![TestProjectParams:: { - expected_state: ProjectStatus::AuctionOpening, - metadata: default_project_metadata(ISSUER_1.into()), - issuer: ISSUER_1.into(), - evaluations: evaluations.clone(), - bids: max_bids.clone(), - community_contributions: vec![], - remainder_contributions: vec![], - }], - phantom: PhantomData, - }, - - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); - - let ext = sp_io::TestExternalities::new(t); - let mut inst = MockInstantiator::new(Some(RefCell::new(ext))); - - assert_eq!(inst.get_project_details(0).status, ProjectStatus::AuctionOpening); - let max_bids_per_project: u32 = ::MaxBidsPerProject::get(); - let total_bids_count = inst.execute(|| Bids::::iter_values().collect_vec().len()); - assert_eq!(total_bids_count, max_bids_per_project as usize); - } -} diff --git a/pallets/funding/src/tests/mod.rs b/pallets/funding/src/tests/mod.rs index 159829eeb..c77c84eb6 100644 --- a/pallets/funding/src/tests/mod.rs +++ b/pallets/funding/src/tests/mod.rs @@ -1,6 +1,6 @@ use super::*; use crate::{ - instantiator::{async_features::create_multiple_projects_at, *}, + instantiator::*, mock::*, traits::{ProvideAssetPrice, VestingDurationCalculation}, CurrencyMetadata, Error, ProjectMetadata, TicketSize, @@ -18,8 +18,8 @@ use parachains_common::DAYS; use polimec_common::{ReleaseSchedule, USD_DECIMALS, USD_UNIT}; use polimec_common_test_utils::{generate_did_from_account, get_mock_jwt_with_cid}; use sp_arithmetic::{traits::Zero, Percent, Perquintill}; -use sp_runtime::{BuildStorage, TokenError}; -use sp_std::{cell::RefCell, marker::PhantomData}; +use sp_runtime::{TokenError}; +use sp_std::cell::RefCell; use std::iter::zip; type MockInstantiator = Instantiator::AllPalletsWithoutSystem, RuntimeEvent>; diff --git a/pallets/funding/src/types.rs b/pallets/funding/src/types.rs index 4ca6fc8ae..ed033fbdb 100644 --- a/pallets/funding/src/types.rs +++ b/pallets/funding/src/types.rs @@ -166,8 +166,7 @@ pub mod config_types { pub mod storage_types { use super::*; - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] pub struct ProjectMetadata { /// Token Metadata pub token_information: CurrencyMetadata, @@ -501,8 +500,9 @@ pub mod inner_types { BadTokenomics, } - #[derive(Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive( + Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize, + )] pub struct CurrencyMetadata { /// The user-friendly name of this asset. Limited in length by `StringLimit`. pub name: BoundedString, @@ -512,8 +512,9 @@ pub mod inner_types { pub decimals: u8, } - #[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive( + Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize, + )] pub struct TicketSize { pub usd_minimum_per_participation: Balance, pub usd_maximum_per_did: Option, @@ -555,8 +556,9 @@ pub mod inner_types { } } - #[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive( + Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize, + )] pub struct BiddingTicketSizes { pub professional: TicketSize, pub institutional: TicketSize, @@ -581,8 +583,9 @@ pub mod inner_types { } } - #[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive( + Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize, + )] pub struct ContributingTicketSizes { pub retail: TicketSize, pub professional: TicketSize, @@ -612,9 +615,21 @@ pub mod inner_types { } #[derive( - VariantCount, Clone, Copy, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, RuntimeDebug, TypeInfo, MaxEncodedLen, + VariantCount, + Clone, + Copy, + Encode, + Decode, + Eq, + PartialEq, + PartialOrd, + Ord, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, + Serialize, + Deserialize, )] - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub enum AcceptedFundingAsset { #[codec(index = 0)] USDT, @@ -633,8 +648,9 @@ pub mod inner_types { } } - #[derive(Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive( + Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize, + )] pub enum ProjectStatus { #[default] Application, diff --git a/runtimes/polimec/src/benchmarks/mod.rs b/runtimes/polimec/src/benchmarks/mod.rs index b05a14f2c..08bfb5015 100644 --- a/runtimes/polimec/src/benchmarks/mod.rs +++ b/runtimes/polimec/src/benchmarks/mod.rs @@ -1,4 +1,4 @@ -#[cfg(any(feature = "runtime-benchmarks", feature = "std"))] +#[cfg(any(feature = "runtime-benchmarks", test))] pub mod helpers; #[test] diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index 0ff64608d..209ab0ace 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -1070,7 +1070,7 @@ impl pallet_funding::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeOrigin = RuntimeOrigin; - #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] + #[cfg(any(feature = "runtime-benchmarks", test))] type SetPrices = crate::benchmarks::helpers::SetOraclePrices; type StringLimit = ConstU32<64>; type SuccessToSettlementTime = SuccessToSettlementTime; diff --git a/runtimes/politest/src/lib.rs b/runtimes/politest/src/lib.rs index 44b9cdf1d..33061408a 100644 --- a/runtimes/politest/src/lib.rs +++ b/runtimes/politest/src/lib.rs @@ -1064,7 +1064,7 @@ impl pallet_funding::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeOrigin = RuntimeOrigin; - #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] + #[cfg(feature = "runtime-benchmarks")] type SetPrices = crate::benchmarks::helpers::SetOraclePrices; type StringLimit = ConstU32<64>; type SuccessToSettlementTime = SuccessToSettlementTime; diff --git a/scripts/zombienet/native/hrmpless-rococo-statemint-polimec-penpal.toml b/scripts/zombienet/native/hrmpless-rococo-statemint-polimec-penpal.toml index de5cf515f..4c2def377 100644 --- a/scripts/zombienet/native/hrmpless-rococo-statemint-polimec-penpal.toml +++ b/scripts/zombienet/native/hrmpless-rococo-statemint-polimec-penpal.toml @@ -3,7 +3,7 @@ timeout = 1000 provider = "native" [relaychain] -default_command = "../polkadot/target/release/polkadot" +default_command = "/usr/local/bin/polkadot" chain = "rococo-local" @@ -25,32 +25,32 @@ chain = "rococo-local" [[relaychain.nodes]] name = "ferdie" - -[[parachains]] -id = 1000 -chain = "statemint-local" - - [[parachains.collators]] - name = "statemint-dev" - command = "../cumulus/target/release/polkadot-parachain" - args = ["-lerror", "-lxcm::process_instruction=trace", "-lxcm::execute_xcm_in_credit=trace", "-lxcm::barriers=trace", "-lpallet_funding::hrmp=trace", "-lpallet_funding::test=trace", "--execution=native", ] - ws_port = 7777 +# +#[[parachains]] +#id = 1000 +#chain = "asset-hub-rococo-dev" +# +# [[parachains.collators]] +# name = "statemint-dev" +# command = "../polkadot-sdk/target/release/polkadot-parachain" +# args = ["-lerror", "-lxcm::process_instruction=trace", "-lxcm::execute_xcm_in_credit=trace", "-lxcm::barriers=trace", "-lpallet_funding::hrmp=trace", "-lpallet_funding::test=trace", "--execution=native", ] +# ws_port = 7777 [[parachains]] id = 3344 -chain = "polimec-testing" +chain = "politest-populated" [[parachains.collators]] name = "polimec-testing" command = "./target/release/polimec-node" args = ["-lerror", "-lxcm::process_instruction=trace", "-lxcm::execute_xcm_in_credit=trace", "-lxcm::barriers=trace", "-lpallet_funding::hrmp=trace", "-lpallet_funding::test=trace", "--execution=native", ] ws_port = 8888 -[[parachains]] -id = 3000 -chain = "penpal-polkadot-3000" - [[parachains.collators]] - name = "penpal-collator" - command = "../cumulus/target/release/polkadot-parachain" - args = ["-lerror", "-lxcm::process_instruction=trace", "-lxcm::execute_xcm_in_credit=trace", "-lxcm::barriers=trace", "-lpallet_funding::hrmp=trace", "-lpallet_funding::test=trace", "--execution=native", ] - ws_port = 9999 \ No newline at end of file +#[[parachains]] +#id = 3000 +#chain = "penpal-rococo-3000" +# [[parachains.collators]] +# name = "penpal-collator" +# command = "../polkadot-sdk/target/release/polkadot-parachain" +# args = ["-lerror", "-lxcm::process_instruction=trace", "-lxcm::execute_xcm_in_credit=trace", "-lxcm::barriers=trace", "-lpallet_funding::hrmp=trace", "-lpallet_funding::test=trace", "--execution=native", ] +# ws_port = 9999 \ No newline at end of file diff --git a/scripts/zombienet/native/local-testnet.toml b/scripts/zombienet/native/local-testnet.toml index 93df56249..68be3d3c8 100644 --- a/scripts/zombienet/native/local-testnet.toml +++ b/scripts/zombienet/native/local-testnet.toml @@ -4,7 +4,7 @@ provider = "native" # Using Rococo 1.7.0 as relay. [relaychain] -default_command = "./bin/polkadot" +default_command = "/usr/local/bin/polkadot" chain = "rococo-local" [[relaychain.nodes]]