Skip to content

Commit

Permalink
chore: update weight and test
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Dec 12, 2024
1 parent ca27938 commit fafb988
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 42 deletions.
4 changes: 2 additions & 2 deletions pallets/nfts/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ benchmarks_instance_pallet! {
}

clear_collection_approvals {
let n in 1 .. T::ApprovalsLimit::get();
let n in 1 .. 1_000;
let (collection, caller, _) = create_collection::<T, I>();
mint_item::<T, I>(0);
for i in 0 .. n {
Expand All @@ -675,7 +675,7 @@ benchmarks_instance_pallet! {
}

force_clear_collection_approvals {
let n in 1 .. T::ApprovalsLimit::get();
let n in 1 .. 1_000;
let (collection, caller, _) = create_collection::<T, I>();
let caller_lookup = T::Lookup::unlookup(caller.clone());
mint_item::<T, I>(0);
Expand Down
6 changes: 4 additions & 2 deletions pallets/nfts/src/features/approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
}

T::Currency::unreserve(&owner, deposits);
Self::deposit_event(Event::ApprovalsCancelled { collection, item: None, owner });
if removed_approvals > 0 {
T::Currency::unreserve(&owner, deposits);
Self::deposit_event(Event::ApprovalsCancelled { collection, item: None, owner });
}
Ok(removed_approvals)
}

Expand Down
49 changes: 36 additions & 13 deletions pallets/nfts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ fn approval_lifecycle_works() {
}

#[test]
fn check_approval_works_without_deadline_works() {
fn check_approval_without_deadline_works() {
new_test_ext().execute_with(|| {
let collection_id = 0;
let collection_owner = account(1);
Expand Down Expand Up @@ -2622,6 +2622,18 @@ fn approve_collection_transfer_works() {
Error::<Test>::NoItemOwned
);

// Force-approve unknown collection, throws error `Error::NoItemOwned`.
assert_noop!(
Nfts::force_approve_collection_transfer(
RuntimeOrigin::root(),
item_owner.clone(),
collection_id,
delegate.clone(),
None
),
Error::<Test>::NoItemOwned
);

assert_ok!(Nfts::force_create(
RuntimeOrigin::root(),
collection_owner.clone(),
Expand All @@ -2644,6 +2656,18 @@ fn approve_collection_transfer_works() {
Error::<Test>::NoItemOwned
);

// Force-approve collection without items, throws error `Error::NoItemOwned`.
assert_noop!(
Nfts::force_approve_collection_transfer(
RuntimeOrigin::root(),
item_owner.clone(),
collection_id,
delegate.clone(),
None
),
Error::<Test>::NoItemOwned
);

assert_ok!(Nfts::force_mint(
RuntimeOrigin::signed(collection_owner.clone()),
collection_id,
Expand Down Expand Up @@ -2682,18 +2706,6 @@ fn approve_collection_transfer_works() {
Error::<Test>::ItemsNonTransferable
);

// Approve unknown collection, throws error `Error::NoItemOwned`.
assert_noop!(
approve_collection_transfer(
origin.clone(),
maybe_item_owner.clone(),
2,
delegate.clone(),
None
),
Error::<Test>::NoItemOwned
);

assert_ok!(approve_collection_transfer(
origin.clone(),
maybe_item_owner.clone(),
Expand Down Expand Up @@ -3183,6 +3195,17 @@ fn clear_collection_approvals_works() {
.count()
.is_zero());

// Emitting no event if zero approvals removed.
assert_eq!(
clear_collection_approvals(origin.clone(), maybe_owner.clone(), collection_id, 10),
Ok(Some(WeightOf::<Test>::clear_collection_approvals(0)).into())
);
assert!(!events().contains(&Event::<Test>::ApprovalsCancelled {
collection: collection_id,
item: None,
owner: owner.clone(),
}));

assert_noop!(
Nfts::transfer(
RuntimeOrigin::signed(delegate_1.clone()),
Expand Down
50 changes: 25 additions & 25 deletions pallets/nfts/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Autogenerated weights for `pallet_nfts`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 40.0.0
//! DATE: 2024-12-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-12-12, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `R0GUE`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
Expand Down Expand Up @@ -633,33 +633,33 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `Nfts::CollectionApprovals` (r:21 w:20)
/// Storage: `Nfts::CollectionApprovals` (r:1000 w:999)
/// Proof: `Nfts::CollectionApprovals` (`max_values`: None, `max_size`: Some(137), added: 2612, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 20]`.
/// The range of component `n` is `[1, 1000]`.
fn clear_collection_approvals(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `348 + n * (75 ±0)`
// Measured: `327 + n * (75 ±0)`
// Estimated: `3602 + n * (2612 ±0)`
// Minimum execution time: 18_000_000 picoseconds.
Weight::from_parts(16_365_393, 3602)
// Standard Error: 5_564
.saturating_add(Weight::from_parts(3_008_044, 0).saturating_mul(n.into()))
Weight::from_parts(18_000_000, 3602)
// Standard Error: 7_954
.saturating_add(Weight::from_parts(3_625_558, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
.saturating_add(Weight::from_parts(0, 2612).saturating_mul(n.into()))
}
/// Storage: `Nfts::CollectionApprovals` (r:21 w:20)
/// Storage: `Nfts::CollectionApprovals` (r:1000 w:999)
/// Proof: `Nfts::CollectionApprovals` (`max_values`: None, `max_size`: Some(137), added: 2612, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 20]`.
/// The range of component `n` is `[1, 1000]`.
fn force_clear_collection_approvals(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `348 + n * (75 ±0)`
// Measured: `327 + n * (75 ±0)`
// Estimated: `3602 + n * (2612 ±0)`
// Minimum execution time: 18_000_000 picoseconds.
Weight::from_parts(16_193_192, 3602)
// Standard Error: 5_637
.saturating_add(Weight::from_parts(3_029_821, 0).saturating_mul(n.into()))
Weight::from_parts(18_000_000, 3602)
// Standard Error: 5_861
.saturating_add(Weight::from_parts(3_576_220, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
Expand Down Expand Up @@ -1424,33 +1424,33 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `Nfts::CollectionApprovals` (r:21 w:20)
/// Storage: `Nfts::CollectionApprovals` (r:1000 w:999)
/// Proof: `Nfts::CollectionApprovals` (`max_values`: None, `max_size`: Some(137), added: 2612, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 20]`.
/// The range of component `n` is `[1, 1000]`.
fn clear_collection_approvals(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `348 + n * (75 ±0)`
// Measured: `327 + n * (75 ±0)`
// Estimated: `3602 + n * (2612 ±0)`
// Minimum execution time: 18_000_000 picoseconds.
Weight::from_parts(16_365_393, 3602)
// Standard Error: 5_564
.saturating_add(Weight::from_parts(3_008_044, 0).saturating_mul(n.into()))
Weight::from_parts(18_000_000, 3602)
// Standard Error: 7_954
.saturating_add(Weight::from_parts(3_625_558, 0).saturating_mul(n.into()))
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into())))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into())))
.saturating_add(Weight::from_parts(0, 2612).saturating_mul(n.into()))
}
/// Storage: `Nfts::CollectionApprovals` (r:21 w:20)
/// Storage: `Nfts::CollectionApprovals` (r:1000 w:999)
/// Proof: `Nfts::CollectionApprovals` (`max_values`: None, `max_size`: Some(137), added: 2612, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 20]`.
/// The range of component `n` is `[1, 1000]`.
fn force_clear_collection_approvals(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `348 + n * (75 ±0)`
// Measured: `327 + n * (75 ±0)`
// Estimated: `3602 + n * (2612 ±0)`
// Minimum execution time: 18_000_000 picoseconds.
Weight::from_parts(16_193_192, 3602)
// Standard Error: 5_637
.saturating_add(Weight::from_parts(3_029_821, 0).saturating_mul(n.into()))
Weight::from_parts(18_000_000, 3602)
// Standard Error: 5_861
.saturating_add(Weight::from_parts(3_576_220, 0).saturating_mul(n.into()))
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into())))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into())))
Expand Down

0 comments on commit fafb988

Please sign in to comment.