Skip to content

Commit

Permalink
migrate pallet-nft-fractionalization to benchmarking v2 syntax (#6301)
Browse files Browse the repository at this point in the history
Migrates pallet-nft-fractionalization to benchmarking v2 syntax.

Part of:
* #6202

---------

Co-authored-by: Giuseppe Re <giuseppe.re@parity.io>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
4 people authored Nov 11, 2024
1 parent 1b0cbe9 commit aff3a07
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
11 changes: 11 additions & 0 deletions prdoc/pr_6301.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: migrate pallet-nft-fractionalization to benchmarking v2 syntax
doc:
- audience: Runtime Dev
description: |-
Migrates pallet-nft-fractionalization to benchmarking v2 syntax.

Part of:
* #6202
crates:
- name: pallet-nft-fractionalization
bump: patch
70 changes: 46 additions & 24 deletions substrate/frame/nft-fractionalization/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]

use super::*;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_benchmarking::v2::*;
use frame_support::{
assert_ok,
traits::{
Expand Down Expand Up @@ -77,55 +77,77 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
assert_eq!(event, &system_event);
}

benchmarks! {
where_clause {
where
T::Nfts: Create<T::AccountId, CollectionConfig<BalanceOf<T>, frame_system::pallet_prelude::BlockNumberFor::<T>, T::NftCollectionId>>
+ Mutate<T::AccountId, ItemConfig>,
}

fractionalize {
#[benchmarks(
where
T::Nfts:
Create<
T::AccountId,
CollectionConfig<BalanceOf<T>,
frame_system::pallet_prelude::BlockNumberFor::<T>,
T::NftCollectionId>
>
+ Mutate<T::AccountId, ItemConfig>,
)]
mod benchmarks {
use super::*;

#[benchmark]
fn fractionalize() {
let asset = T::BenchmarkHelper::asset(0);
let collection = T::BenchmarkHelper::collection(0);
let nft = T::BenchmarkHelper::nft(0);
let (caller, caller_lookup) = mint_nft::<T>(nft);
}: _(SystemOrigin::Signed(caller.clone()), collection, nft, asset.clone(), caller_lookup, 1000u32.into())
verify {

#[extrinsic_call]
_(
SystemOrigin::Signed(caller.clone()),
collection,
nft,
asset.clone(),
caller_lookup,
1000u32.into(),
);

assert_last_event::<T>(
Event::NftFractionalized {
nft_collection: collection,
nft,
fractions: 1000u32.into(),
asset,
beneficiary: caller,
}.into()
}
.into(),
);
}

unify {
#[benchmark]
fn unify() {
let asset = T::BenchmarkHelper::asset(0);
let collection = T::BenchmarkHelper::collection(0);
let nft = T::BenchmarkHelper::nft(0);
let (caller, caller_lookup) = mint_nft::<T>(nft);
NftFractionalization::<T>::fractionalize(

assert_ok!(NftFractionalization::<T>::fractionalize(
SystemOrigin::Signed(caller.clone()).into(),
collection,
nft,
asset.clone(),
caller_lookup.clone(),
1000u32.into(),
)?;
}: _(SystemOrigin::Signed(caller.clone()), collection, nft, asset.clone(), caller_lookup)
verify {
));

#[extrinsic_call]
_(SystemOrigin::Signed(caller.clone()), collection, nft, asset.clone(), caller_lookup);

assert_last_event::<T>(
Event::NftUnified {
nft_collection: collection,
nft,
asset,
beneficiary: caller,
}.into()
Event::NftUnified { nft_collection: collection, nft, asset, beneficiary: caller }
.into(),
);
}

impl_benchmark_test_suite!(NftFractionalization, crate::mock::new_test_ext(), crate::mock::Test);
impl_benchmark_test_suite!(
NftFractionalization,
crate::mock::new_test_ext(),
crate::mock::Test
);
}

0 comments on commit aff3a07

Please sign in to comment.