From 2a3ff1364731f2e8c76cb88d46b6a290d21e3153 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Mon, 1 Jul 2024 16:55:34 +0200 Subject: [PATCH] benchmarks --- pallets/funding/src/benchmarking.rs | 148 +++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 3 deletions(-) diff --git a/pallets/funding/src/benchmarking.rs b/pallets/funding/src/benchmarking.rs index 2169d5989..8a4f6c1e6 100644 --- a/pallets/funding/src/benchmarking.rs +++ b/pallets/funding/src/benchmarking.rs @@ -2623,9 +2623,6 @@ mod benchmarks { vec![], ); - // let issuer_mint = UserToPLMCBalance::::new(issuer.clone(), (100 * ASSET_UNIT).into()); - // inst.mint_plmc_to(vec![issuer_mint]); - #[block] { Pallet::::do_start_settlement(project_id).unwrap(); @@ -2685,6 +2682,137 @@ mod benchmarks { assert_eq!(project_details.status, ProjectStatus::SettlementStarted(FundingOutcome::FundingFailed)); } + #[benchmark] + fn start_pallet_migration() { + // setup + let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); + + let issuer = account::>("issuer", 0, 0); + + let project_metadata = default_project_metadata::(issuer.clone()); + let project_id = inst.create_finished_project( + project_metadata.clone(), + issuer.clone(), + default_evaluations::(), + default_bids::(), + default_community_contributions::(), + vec![], + ); + + let settlement_block = inst.get_update_block(project_id, &UpdateType::StartSettlement).unwrap(); + inst.jump_to_block(settlement_block); + + inst.settle_project(project_id).unwrap(); + + let jwt = get_mock_jwt_with_cid( + issuer.clone(), + InvestorType::Institutional, + generate_did_from_account(issuer.clone()), + project_metadata.clone().policy_ipfs_cid.unwrap(), + ); + + #[extrinsic_call] + start_pallet_migration(RawOrigin::Signed(issuer), jwt, project_id, ParaId::from(6969)); + + // * validity checks * + let project_details = inst.get_project_details(project_id); + assert_eq!(project_details.status, ProjectStatus::CTMigrationStarted); + assert_eq!(project_details.migration_type, Some(MigrationType::Pallet(PalletMigrationInfo { + parachain_id: ParaId::from(6969), + hrmp_channel_status: HRMPChannelStatus { project_to_polimec: ChannelStatus::Closed, polimec_to_project: ChannelStatus::Closed }, + migration_readiness_check: None, + remaining_participants: 13, + }))) + } + + #[benchmark] + fn start_offchain_migration() { + // setup + let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); + + let issuer = account::>("issuer", 0, 0); + + let project_metadata = default_project_metadata::(issuer.clone()); + let project_id = inst.create_finished_project( + project_metadata.clone(), + issuer.clone(), + default_evaluations::(), + default_bids::(), + default_community_contributions::(), + vec![], + ); + + let settlement_block = inst.get_update_block(project_id, &UpdateType::StartSettlement).unwrap(); + inst.jump_to_block(settlement_block); + + inst.settle_project(project_id).unwrap(); + + let jwt = get_mock_jwt_with_cid( + issuer.clone(), + InvestorType::Institutional, + generate_did_from_account(issuer.clone()), + project_metadata.clone().policy_ipfs_cid.unwrap(), + ); + + #[extrinsic_call] + start_offchain_migration(RawOrigin::Signed(issuer), jwt, project_id); + + // * validity checks * + let project_details = inst.get_project_details(project_id); + assert_eq!(project_details.status, ProjectStatus::CTMigrationStarted); + assert_eq!(project_details.migration_type, Some(MigrationType::Offchain(OffchainMigrationInfo{ remaining_participants: 13 }))); + } + + #[benchmark] + fn confirm_offchain_migration() { + // setup + let mut inst = BenchInstantiator::::new(None); + ::SetPrices::set_prices(); + + let issuer = account::>("issuer", 0, 0); + let participant = account::>("test_participant", 0, 0); + + let max_participations = 0..::MaxContributionsPerUser::get(); + + let project_metadata = default_project_metadata::(issuer.clone()); + let project_id = inst.create_finished_project( + project_metadata.clone(), + issuer.clone(), + default_evaluations::(), + default_bids::(), + default_community_contributions::(), + vec![], + ); + + let settlement_block = inst.get_update_block(project_id, &UpdateType::StartSettlement).unwrap(); + inst.jump_to_block(settlement_block); + + inst.settle_project(project_id).unwrap(); + + let jwt = get_mock_jwt_with_cid( + issuer.clone(), + InvestorType::Institutional, + generate_did_from_account(issuer.clone()), + project_metadata.clone().policy_ipfs_cid.unwrap(), + ); + + + crate::Pallet::::start_offchain_migration(RawOrigin::Signed(issuer.clone()).into(), jwt.clone(), project_id).unwrap(); + + #[extrinsic_call] + confirm_offchain_migration(RawOrigin::Signed(issuer), project_id, account::>("contributor_1", 0, 0)); + + // * validity checks * + let project_details = inst.get_project_details(project_id); + assert_eq!(project_details.status, ProjectStatus::CTMigrationStarted); + assert_eq!(project_details.migration_type, Some(MigrationType::Offchain(OffchainMigrationInfo{ remaining_participants: 13 }))); + } + + + + #[cfg(test)] mod tests { use super::*; @@ -2886,5 +3014,19 @@ mod benchmarks { assert_ok!(PalletFunding::::test_end_funding_awaiting_decision_evaluators_slashed()); }); } + + #[test] + fn bench_start_pallet_migration() { + new_test_ext().execute_with(|| { + assert_ok!(PalletFunding::::test_start_pallet_migration()); + }); + } + + #[test] + fn bench_start_offchain_migration() { + new_test_ext().execute_with(|| { + assert_ok!(PalletFunding::::test_start_offchain_migration()); + }); + } } }