From 04fbe25a7b27cbb8553a3b3a02f515a976c48780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Fri, 8 Mar 2024 22:52:13 -0500 Subject: [PATCH] feat(kreivo-runtime): configure benchmark helper for pallet-communities --- runtime/kreivo/src/communities/mod.rs | 60 +++++++++++++++++++-------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/runtime/kreivo/src/communities/mod.rs b/runtime/kreivo/src/communities/mod.rs index 011396bf..0381d292 100644 --- a/runtime/kreivo/src/communities/mod.rs +++ b/runtime/kreivo/src/communities/mod.rs @@ -78,32 +78,38 @@ impl BenchmarkHelper for CommunityBenchmarkHelper { origin.into() } + fn membership_id(community_id: CommunityIdOf, index: u32) -> MembershipIdOf { + MembershipId(community_id, index) + } + fn initialize_memberships_collection() -> Result<(), BenchmarkError> { let collection = MembershipsCollectionId::get(); Nfts::::do_create_collection( collection, - RootAccount::get(), - RootAccount::get(), + TreasuryAccount::get(), + TreasuryAccount::get(), Default::default(), 0, pallet_nfts::Event::ForceCreated { collection, - owner: RootAccount::get(), + owner: TreasuryAccount::get(), }, )?; Ok(()) } - fn new_membership_id(community_id: CommunityIdOf, index: u32) -> MembershipIdOf { - MembershipId(community_id, index) + fn issue_membership( + community_id: CommunityIdOf, + membership_id: MembershipIdOf, + ) -> Result<(), BenchmarkError> { + let community_account = pallet_communities::Pallet::::community_account(&community_id); + MembershipCollection::mint_into(&membership_id, &community_account, &Default::default(), true)?; + + Ok(()) } - fn prepare_track_and_submit_referendum( - origin: OriginFor, - proposal_origin: PalletsOriginOf, - proposal_call: RuntimeCallFor, - ) -> Result, BenchmarkError> { + fn prepare_track(pallet_origin: PalletsOriginOf) -> Result<(), BenchmarkError> { let id = Self::community_id(); let info = TrackInfo { name: sp_runtime::str_array("Community"), @@ -125,8 +131,16 @@ impl BenchmarkHelper for CommunityBenchmarkHelper { }, }; - Tracks::::insert(RuntimeOrigin::root(), id, info, proposal_origin.clone())?; + Tracks::::insert(RuntimeOrigin::root(), id, info, pallet_origin)?; + Ok(()) + } + + fn prepare_poll( + origin: OriginFor, + proposal_origin: PalletsOriginOf, + proposal_call: RuntimeCallFor, + ) -> Result, BenchmarkError> { let bounded_call = BoundedVec::truncate_from(proposal_call.encode()); let proposal_origin = Box::new(proposal_origin); let proposal = BoundedCallOf::::Inline(bounded_call); @@ -141,15 +155,25 @@ impl BenchmarkHelper for CommunityBenchmarkHelper { )?; Referenda::::place_decision_deposit(origin, index)?; - Ok(index) + System::set_block_number(2); + Referenda::::nudge_referendum(RuntimeOrigin::root(), 0)?; + + Ok(0) } - fn extend_membership( - community_id: CommunityIdOf, - membership_id: MembershipIdOf, - ) -> Result<(), BenchmarkError> { - let community_account = pallet_communities::Pallet::::community_account(&community_id); - MembershipCollection::mint_into(&membership_id, &community_account, &Default::default(), true)?; + fn finish_poll(index: PollIndexOf) -> Result<(), BenchmarkError> { + System::set_block_number(8); + Referenda::::nudge_referendum(RuntimeOrigin::root(), index)?; + + frame_support::assert_ok!(Referenda::::ensure_ongoing(index)); + + System::set_block_number(9); + Referenda::::nudge_referendum(RuntimeOrigin::root(), index)?; + + frame_support::assert_err!( + Referenda::::ensure_ongoing(index), + pallet_referenda::Error::::NotOngoing + ); Ok(()) }