git.delta.rocks / unique-network / refs/commits / 5f417e832e48

difftreelog

feat(rmrk) benchmark send

Daniel Shiposha2022-06-09parent: #7f00cfc.patch.diff
in: master

2 files changed

modifiedpallets/proxy-rmrk-core/src/benchmarking.rsdiffbeforeafterboth
18 vec![0; S::get() as usize].try_into().expect("size == S")18 vec![0; S::get() as usize].try_into().expect("size == S")
19}19}
2020
21fn create_max_collection<T: Config>(owner: &T::AccountId) -> Result<RmrkCollectionId, DispatchError> {21fn create_max_collection<T: Config>(owner: &T::AccountId) -> DispatchResult {
22 <T as pallet_common::Config>::Currency::deposit_creating(owner, T::CollectionCreationPrice::get());22 <T as pallet_common::Config>::Currency::deposit_creating(owner, T::CollectionCreationPrice::get());
2323
24 let metadata = create_data();24 let metadata = create_data();
25 let max = None;25 let max = None;
26 let symbol = create_data();26 let symbol = create_data();
2727
28 <Pallet<T>>::create_collection(RawOrigin::Signed(owner.clone()).into(), metadata, max, symbol)?;28 <Pallet<T>>::create_collection(RawOrigin::Signed(owner.clone()).into(), metadata, max, symbol)
29
30 Ok(<CollectionIndex<T>>::get() - 1)
31}29}
30
31fn create_max_nft<T: Config>(owner: &T::AccountId, collection_id: RmrkCollectionId) -> DispatchResult {
32 let royalty_recipient = Some(owner.clone());
33 let royalty_amount = Some(Permill::from_percent(25));
34 let metadata = create_data();
35 let transferable = true;
36
37 <Pallet<T>>::mint_nft(
38 RawOrigin::Signed(owner.clone()).into(),
39 owner.clone(),
40 collection_id,
41 royalty_recipient,
42 royalty_amount,
43 metadata,
44 transferable
45 )
46}
47
48struct NftTowerBuilder {
49 collection_id: RmrkCollectionId,
50 current_nft_id: RmrkNftId
51}
52
53impl NftTowerBuilder {
54 fn new(collection_id: RmrkCollectionId) -> Self {
55 Self {
56 collection_id,
57 current_nft_id: 0
58 }
59 }
60
61 fn build<T: Config>(&mut self, owner: &T::AccountId, height: u32) -> Result<RmrkNftId, DispatchError> {
62 create_max_nft::<T>(owner, self.collection_id)?;
63 self.current_nft_id += 1;
64
65 let mut prev_nft_id = self.current_nft_id;
66
67 for _ in 0..height {
68 create_max_nft::<T>(owner, self.collection_id)?;
69 self.current_nft_id += 1;
70
71 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(
72 self.collection_id,
73 prev_nft_id
74 );
75
76 <Pallet<T>>::send(
77 RawOrigin::Signed(owner.clone()).into(),
78 self.collection_id,
79 self.current_nft_id,
80 new_owner,
81 )?;
82
83 prev_nft_id = self.current_nft_id;
84 }
85
86 let deepest_nft_id = self.current_nft_id;
87
88 Ok(deepest_nft_id)
89 }
90}
3291
33benchmarks! {92benchmarks! {
34 create_collection {93 create_collection {
42 destroy_collection {101 destroy_collection {
43 let caller = account("caller", 0, SEED);102 let caller = account("caller", 0, SEED);
103
44 let collection_id = create_max_collection::<T>(&caller)?;104 create_max_collection::<T>(&caller)?;
105 let collection_id = 0;
45 }: _(RawOrigin::Signed(caller), collection_id)106 }: _(RawOrigin::Signed(caller), collection_id)
46107
47 change_collection_issuer {108 change_collection_issuer {
48 let caller: T::AccountId = account("caller", 0, SEED);109 let caller: T::AccountId = account("caller", 0, SEED);
110
49 let collection_id = create_max_collection::<T>(&caller)?;111 create_max_collection::<T>(&caller)?;
112 let collection_id = 0;
113
50 let new_owner: T::AccountId = account("new_owner", 0, SEED);114 let new_owner: T::AccountId = account("new_owner", 0, SEED);
51115
55 lock_collection {119 lock_collection {
56 let caller: T::AccountId = account("caller", 0, SEED);120 let caller: T::AccountId = account("caller", 0, SEED);
121
57 let collection_id = create_max_collection::<T>(&caller)?;122 create_max_collection::<T>(&caller)?;
123 let collection_id = 0;
58 }: _(RawOrigin::Signed(caller), collection_id)124 }: _(RawOrigin::Signed(caller), collection_id)
59125
60 mint_nft {126 mint_nft {
61 let caller: T::AccountId = account("caller", 0, SEED);127 let caller: T::AccountId = account("caller", 0, SEED);
128
62 let collection_id = create_max_collection::<T>(&caller)?;129 create_max_collection::<T>(&caller)?;
130 let collection_id = 0;
63 let owner = caller.clone();131 let owner = caller.clone();
64 132
65 let royalty_recipient = Some(caller.clone());133 let royalty_recipient = Some(caller.clone());
76 transferable144 transferable
77 )145 )
146
147 send {
148 let caller: T::AccountId = account("caller", 0, SEED);
149 create_max_collection::<T>(&caller)?;
150 let collection_id = 0;
151
152 let mut nft_tower_builder = NftTowerBuilder::new(collection_id);
153 let src_nft_id = nft_tower_builder.build::<T>(&caller, 0)?;
154 let target_nft_id = nft_tower_builder.build::<T>(&caller, NESTING_BUDGET - 2)?;
155 }: _(
156 RawOrigin::Signed(caller),
157 collection_id,
158 src_nft_id,
159 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(collection_id, target_nft_id)
160 )
78}161}
79162
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
4545
46use RmrkProperty::*;46use RmrkProperty::*;
4747
48const NESTING_BUDGET: u32 = 5;48pub const NESTING_BUDGET: u32 = 5;
4949
50#[frame_support::pallet]50#[frame_support::pallet]
51pub mod pallet {51pub mod pallet {