Skip to content

Commit

Permalink
Run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo50 committed Nov 7, 2024
1 parent 953e62e commit 194e1e5
Show file tree
Hide file tree
Showing 44 changed files with 1,034 additions and 395 deletions.
158 changes: 127 additions & 31 deletions templates/parachain/pallets/xcnft/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

use super::*;

use enumflags2::{BitFlag, BitFlags};
use frame_benchmarking::v2::*;
use frame_support::{assert_ok, traits::Currency, BoundedVec};
use frame_system::RawOrigin;
use sp_runtime::traits::{Bounded, StaticLookup};
use pallet_nfts::{
CollectionSetting, CollectionSettings, CollectionConfig,
CollectionConfigFor, MintSettings, BenchmarkHelper, DepositBalanceOf,
BenchmarkHelper, CollectionConfig, CollectionConfigFor, CollectionSetting, CollectionSettings,
DepositBalanceOf, MintSettings,
};
use enumflags2::{BitFlag, BitFlags};
use frame_support::{traits::Currency, assert_ok, BoundedVec};
use sp_runtime::traits::{Bounded, StaticLookup};
use sp_std::vec;

fn make_collection_config<T: Config<I>, I: 'static>(
Expand All @@ -27,11 +27,10 @@ fn default_collection_config<T: Config<I>, I: 'static>() -> CollectionConfigFor<
make_collection_config::<T, I>(CollectionSetting::empty())
}


#[instance_benchmarks]
mod benchmarks {
use super::*;

// Benchmark tries the first scenario of collection_x_transfer (transfering empty collection)
#[benchmark]
fn transfer_collection_empty<T: Config<I>, I: 'static>() {
Expand All @@ -41,13 +40,24 @@ mod benchmarks {

T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());

assert_ok!(pallet_nfts::Pallet::<T, I>::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::<T, I>()));
assert_ok!(pallet_nfts::Pallet::<T, I>::create(
RawOrigin::Signed(caller.clone()).into(),
caller_lookup.clone(),
default_collection_config::<T, I>()
));

#[extrinsic_call]
collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None);
collection_x_transfer(
RawOrigin::Signed(caller.into()),
collection.clone(),
None,
1000.into(),
None,
);
}

// Benchmark tries the second scenario of collection_x_transfer (transfering collection with items same owner)
// Benchmark tries the second scenario of collection_x_transfer (transfering collection with
// items same owner)
#[benchmark]
fn transfer_collection_same_owner<T: Config<I>, I: 'static>() {
let caller: T::AccountId = whitelisted_caller();
Expand All @@ -57,15 +67,31 @@ mod benchmarks {

T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());

assert_ok!(pallet_nfts::Pallet::<T, I>::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::<T, I>()));
assert_ok!(pallet_nfts::Pallet::<T, I>::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone(), None));

assert_ok!(pallet_nfts::Pallet::<T, I>::create(
RawOrigin::Signed(caller.clone()).into(),
caller_lookup.clone(),
default_collection_config::<T, I>()
));
assert_ok!(pallet_nfts::Pallet::<T, I>::mint(
RawOrigin::Signed(caller.clone()).into(),
collection.clone(),
item.clone(),
caller_lookup.clone(),
None
));

#[extrinsic_call]
collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None);
collection_x_transfer(
RawOrigin::Signed(caller.into()),
collection.clone(),
None,
1000.into(),
None,
);
}

// Benchmark tries the third scenario of collection_x_transfer (transfering collection with items different owners)
// Benchmark tries the third scenario of collection_x_transfer (transfering collection with
// items different owners)
#[benchmark]
fn transfer_collection_other_owners<T: Config<I>, I: 'static>() {
let caller: T::AccountId = whitelisted_caller();
Expand All @@ -76,16 +102,36 @@ mod benchmarks {
let item = T::Helper::item(0);
let item2 = T::Helper::item(1);


T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());

assert_ok!(pallet_nfts::Pallet::<T, I>::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::<T, I>()));
assert_ok!(pallet_nfts::Pallet::<T, I>::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone(), None));
assert_ok!(pallet_nfts::Pallet::<T, I>::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item2.clone(), caller_lookup2.clone(), None));

assert_ok!(pallet_nfts::Pallet::<T, I>::create(
RawOrigin::Signed(caller.clone()).into(),
caller_lookup.clone(),
default_collection_config::<T, I>()
));
assert_ok!(pallet_nfts::Pallet::<T, I>::mint(
RawOrigin::Signed(caller.clone()).into(),
collection.clone(),
item.clone(),
caller_lookup.clone(),
None
));
assert_ok!(pallet_nfts::Pallet::<T, I>::mint(
RawOrigin::Signed(caller.clone()).into(),
collection.clone(),
item2.clone(),
caller_lookup2.clone(),
None
));

#[extrinsic_call]
collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None);
collection_x_transfer(
RawOrigin::Signed(caller.into()),
collection.clone(),
None,
1000.into(),
None,
);
}

//Benchmark tries nft transfer
Expand All @@ -98,13 +144,30 @@ mod benchmarks {

T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());

assert_ok!(pallet_nfts::Pallet::<T, I>::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::<T, I>()));
assert_ok!(pallet_nfts::Pallet::<T, I>::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone(), None));
assert_ok!(pallet_nfts::Pallet::<T, I>::create(
RawOrigin::Signed(caller.clone()).into(),
caller_lookup.clone(),
default_collection_config::<T, I>()
));
assert_ok!(pallet_nfts::Pallet::<T, I>::mint(
RawOrigin::Signed(caller.clone()).into(),
collection.clone(),
item.clone(),
caller_lookup.clone(),
None
));

#[extrinsic_call]
nft_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , item.clone(), 1000.into(), collection.clone() , item.clone());
nft_x_transfer(
RawOrigin::Signed(caller.into()),
collection.clone(),
item.clone(),
1000.into(),
collection.clone(),
item.clone(),
);
}

//Benchmark tries collection empty parse
#[benchmark]
fn parse_empty_col<T: Config<I>, I: 'static>() {
Expand All @@ -114,7 +177,13 @@ mod benchmarks {
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());

#[extrinsic_call]
parse_collection_empty(RawOrigin::Signed(caller.into()),collection.clone() , None, BoundedVec::new(), None);
parse_collection_empty(
RawOrigin::Signed(caller.into()),
collection.clone(),
None,
BoundedVec::new(),
None,
);
}

//Benchmark tries collection parse with items
Expand All @@ -127,9 +196,16 @@ mod benchmarks {

T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());


#[extrinsic_call]
parse_collection_same_owner(RawOrigin::Signed(caller.into()),None, BoundedVec::new(), nfts.clone() ,1000.into(), collection.clone(), None);
parse_collection_same_owner(
RawOrigin::Signed(caller.into()),
None,
BoundedVec::new(),
nfts.clone(),
1000.into(),
collection.clone(),
None,
);
}

//Benchmark tries collection parse with items and different owners
Expand All @@ -145,7 +221,15 @@ mod benchmarks {
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());

#[extrinsic_call]
parse_collection_diff_owners(RawOrigin::Signed(caller.into()),None, BoundedVec::new(), nfts.clone() ,1000.into(), collection.clone(), None);
parse_collection_diff_owners(
RawOrigin::Signed(caller.into()),
None,
BoundedVec::new(),
nfts.clone(),
1000.into(),
collection.clone(),
None,
);
}

//Benchmark tries collection parse item
Expand All @@ -158,10 +242,22 @@ mod benchmarks {

T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());

assert_ok!(pallet_nfts::Pallet::<T, I>::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::<T, I>()));
assert_ok!(pallet_nfts::Pallet::<T, I>::create(
RawOrigin::Signed(caller.clone()).into(),
caller_lookup.clone(),
default_collection_config::<T, I>()
));

#[extrinsic_call]
parse_nft_transfer(RawOrigin::Signed(caller.into()),collection.clone(), item.clone(), BoundedVec::new(), collection.clone(), item.clone() ,1000.into());
parse_nft_transfer(
RawOrigin::Signed(caller.into()),
collection.clone(),
item.clone(),
BoundedVec::new(),
collection.clone(),
item.clone(),
1000.into(),
);
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
Loading

0 comments on commit 194e1e5

Please sign in to comment.