From c14015ab68abcac833bacefc970181b7544e2890 Mon Sep 17 00:00:00 2001
From: bgallois <benjamin@gallois.cc>
Date: Fri, 19 Jan 2024 16:03:00 +0100
Subject: [PATCH] fix all pallets benchmarks

---
 pallets/certification/src/benchmarking.rs     |  8 ++---
 pallets/distance/src/benchmarking.rs          |  5 ++--
 pallets/duniter-account/src/benchmarking.rs   |  6 ++--
 pallets/identity/src/benchmarking.rs          | 30 +++++++++----------
 pallets/membership/src/benchmarking.rs        |  4 +--
 pallets/oneshot-account/src/benchmarking.rs   |  4 +--
 .../provide-randomness/src/benchmarking.rs    |  5 ++--
 pallets/quota/src/benchmarking.rs             |  8 ++---
 8 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/pallets/certification/src/benchmarking.rs b/pallets/certification/src/benchmarking.rs
index add49d644..6c521de2c 100644
--- a/pallets/certification/src/benchmarking.rs
+++ b/pallets/certification/src/benchmarking.rs
@@ -19,9 +19,9 @@
 use super::*;
 
 use frame_benchmarking::benchmarks;
-use frame_benchmarking::Zero;
 use frame_system::RawOrigin;
 use sp_runtime::traits::Convert;
+use sp_runtime::traits::Zero;
 
 #[cfg(test)]
 use maplit::btreemap;
@@ -80,10 +80,10 @@ benchmarks! {
         assert!(CertsByReceiver::<T>::get(receiver).is_empty() );
     }
     on_initialize {
-        assert!(CertsRemovableOn::<T>::try_get(T::BlockNumber::zero()).is_err());
-    }: {Pallet::<T>::on_initialize(T::BlockNumber::zero());}
+        assert!(CertsRemovableOn::<T>::try_get(BlockNumberFor::<T>::zero()).is_err());
+    }: {Pallet::<T>::on_initialize(BlockNumberFor::<T>::zero());}
     do_remove_cert_noop {
-    }: {Pallet::<T>::do_remove_cert(100.into(), 101.into(), Some(T::BlockNumber::zero()));}
+    }: {Pallet::<T>::do_remove_cert(100.into(), 101.into(), Some(BlockNumberFor::<T>::zero()));}
     do_remove_cert {
         let issuer: T::IdtyIndex = 1.into();
         let receiver: T::IdtyIndex = 0.into();
diff --git a/pallets/distance/src/benchmarking.rs b/pallets/distance/src/benchmarking.rs
index c762bde19..4b5fb9557 100644
--- a/pallets/distance/src/benchmarking.rs
+++ b/pallets/distance/src/benchmarking.rs
@@ -19,8 +19,9 @@
 use super::*;
 
 use codec::Encode;
-use frame_benchmarking::{benchmarks, vec};
+use frame_benchmarking::benchmarks;
 use frame_support::traits::{Currency, OnFinalize};
+use frame_system::pallet_prelude::BlockNumberFor;
 use frame_system::RawOrigin;
 use pallet_balances::Pallet as Balances;
 use sp_runtime::traits::{Bounded, One};
@@ -48,7 +49,7 @@ benchmarks! {
     where_clause {
         where
         T: pallet_balances::Config, T::Balance: From<u64>,
-        T::BlockNumber: From<u32>,
+        BlockNumberFor<T>: From<u32>,
     }
 
     // request distance evaluation
diff --git a/pallets/duniter-account/src/benchmarking.rs b/pallets/duniter-account/src/benchmarking.rs
index 6c99b5532..27a839e1a 100644
--- a/pallets/duniter-account/src/benchmarking.rs
+++ b/pallets/duniter-account/src/benchmarking.rs
@@ -65,13 +65,13 @@ benchmarks! {
     }: _<T::RuntimeOrigin>(origin.into())
     on_initialize_sufficient  {
         let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false, true)?;
-    }: { Pallet::<T>::on_initialize(T::BlockNumber::one()); }
+    }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); }
     on_initialize_with_balance {
         let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, true, false)?;
-    }: { Pallet::<T>::on_initialize(T::BlockNumber::one()); }
+    }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); }
     on_initialize_no_balance {
         let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false, false)?;
-    }: { Pallet::<T>::on_initialize(T::BlockNumber::one()); }
+    }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); }
     on_filled_randomness_pending {
         let caller: T::AccountId = whitelisted_caller();
         let randomness = H256(T::AccountIdToSalt::convert(caller.clone()));
diff --git a/pallets/identity/src/benchmarking.rs b/pallets/identity/src/benchmarking.rs
index f7ba053f6..0d4fe93e4 100644
--- a/pallets/identity/src/benchmarking.rs
+++ b/pallets/identity/src/benchmarking.rs
@@ -69,7 +69,7 @@ fn create_one_identity<T: Config>(owner_key: T::AccountId) -> Result<Account<T>,
     // Reset next_creatable_identity_on to add more identities with Alice
     <Identities<T>>::mutate_exists(T::IdtyIndex::from(1u32), |idty_val_opt| {
         if let Some(ref mut idty_val) = idty_val_opt {
-            idty_val.next_creatable_identity_on = T::BlockNumber::zero();
+            idty_val.next_creatable_identity_on = BlockNumberFor::<T>::zero();
         }
     });
     Ok(Account {
@@ -84,10 +84,10 @@ fn create_one_identity<T: Config>(owner_key: T::AccountId) -> Result<Account<T>,
 fn create_dummy_identity<T: Config>(i: u32) -> Result<(), &'static str> {
     let idty_index: T::IdtyIndex = i.into();
     let owner_key: T::AccountId = account("Bob", i, SEED);
-    let next_scheduled = T::BlockNumber::zero();
+    let next_scheduled = BlockNumberFor::<T>::zero();
     let value = IdtyValue {
         data: Default::default(),
-        next_creatable_identity_on: T::BlockNumber::zero(),
+        next_creatable_identity_on: BlockNumberFor::<T>::zero(),
         old_owner_key: None,
         owner_key: owner_key.clone(),
         next_scheduled,
@@ -155,7 +155,7 @@ benchmarks! {
         let account: Account<T> = create_one_identity(old_key.clone())?;
 
         // Change key a first time to add an old-old key
-        let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero());
+        let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
         let new_key_payload = IdtyIndexAccountIdPayload {
             genesis_hash: &genesis_hash,
             idty_index: account.index,
@@ -170,7 +170,7 @@ benchmarks! {
         // Change key a second time to benchmark
         //  The sufficients for the old_old key will drop to 0 during benchmark
         let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
-        let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero());
+        let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
         let new_key_payload = IdtyIndexAccountIdPayload {
             genesis_hash: &genesis_hash,
             idty_index: account.index,
@@ -194,7 +194,7 @@ benchmarks! {
 
         // Change key
         //  The sufficients for the old key will drop to 0 during benchmark (not for revoke, only for remove)
-        let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero());
+        let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
         let new_key_payload = IdtyIndexAccountIdPayload {
             genesis_hash: &genesis_hash,
             idty_index: account.index,
@@ -206,7 +206,7 @@ benchmarks! {
         let signature = sr25519_sign(0.into(), &caller_public, &message).unwrap().into();
         Pallet::<T>::change_owner_key(account.origin.clone(), caller.clone(), signature)?;
 
-        let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero());
+        let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
         let revocation_payload = RevocationPayload {
             genesis_hash: &genesis_hash,
             idty_index: account.index,
@@ -255,7 +255,7 @@ benchmarks! {
         let bob_public = sr25519_generate(0.into(), None);
         let bob: T::AccountId = MultiSigner::Sr25519(bob_public).into_account().into();
         frame_system::Pallet::<T>::inc_providers(&bob);
-        let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero());
+        let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
         let payload = (
             LINK_IDTY_PAYLOAD_PREFIX, genesis_hash, T::IdtyIndex::one(), bob.clone(),
         ).encode();
@@ -308,21 +308,21 @@ benchmarks! {
 
     // --- prune identities
     prune_identities_noop {
-        assert!(IdentityChangeSchedule::<T>::try_get(T::BlockNumber::zero()).is_err());
-    }: {Pallet::<T>::prune_identities(T::BlockNumber::zero());}
+        assert!(IdentityChangeSchedule::<T>::try_get(BlockNumberFor::<T>::zero()).is_err());
+    }: {Pallet::<T>::prune_identities(BlockNumberFor::<T>::zero());}
 
     prune_identities_none {
         let idty_index: T::IdtyIndex = 100u32.into();
-        IdentityChangeSchedule::<T>::append(T::BlockNumber::zero(), idty_index);
-        assert!(IdentityChangeSchedule::<T>::try_get(T::BlockNumber::zero()).is_ok());
+        IdentityChangeSchedule::<T>::append(BlockNumberFor::<T>::zero(), idty_index);
+        assert!(IdentityChangeSchedule::<T>::try_get(BlockNumberFor::<T>::zero()).is_ok());
         assert!(<Identities<T>>::try_get(idty_index).is_err());
-    }: {Pallet::<T>::prune_identities(T::BlockNumber::zero());}
+    }: {Pallet::<T>::prune_identities(BlockNumberFor::<T>::zero());}
 
     prune_identities_err {
         let idty_index: T::IdtyIndex = 100u32.into();
         create_dummy_identity::<T>(100u32)?;
-        IdentityChangeSchedule::<T>::append(T::BlockNumber::zero(), idty_index);
-    }: {Pallet::<T>::prune_identities(T::BlockNumber::zero());}
+        IdentityChangeSchedule::<T>::append(BlockNumberFor::<T>::zero(), idty_index);
+    }: {Pallet::<T>::prune_identities(BlockNumberFor::<T>::zero());}
 
     impl_benchmark_test_suite!(
         Pallet,
diff --git a/pallets/membership/src/benchmarking.rs b/pallets/membership/src/benchmarking.rs
index 84216da89..a3475c7d0 100644
--- a/pallets/membership/src/benchmarking.rs
+++ b/pallets/membership/src/benchmarking.rs
@@ -34,7 +34,7 @@ benchmarks! {
     where_clause {
         where
             T::IdtyId: From<u32>,
-            <T as frame_system::Config>::BlockNumber: From<u32>,
+            BlockNumberFor<T>: From<u32>,
     }
 
     // TODO membership add and renewal should be included to distance on_new_session as worst case scenario
@@ -52,7 +52,7 @@ benchmarks! {
         let mut idties: Vec<T::IdtyId> = Vec::new();
         for j in 1..i+1 {
             let j: T::IdtyId = j.into();
-            Membership::<T>::insert(j, MembershipData::<T::BlockNumber>::default());
+            Membership::<T>::insert(j, MembershipData::<BlockNumberFor<T>>::default());
             idties.push(j);
         }
         MembershipsExpireOn::<T>::insert(block_number, idties);
diff --git a/pallets/oneshot-account/src/benchmarking.rs b/pallets/oneshot-account/src/benchmarking.rs
index 69bdf381d..dcc72ff2e 100644
--- a/pallets/oneshot-account/src/benchmarking.rs
+++ b/pallets/oneshot-account/src/benchmarking.rs
@@ -71,7 +71,7 @@ benchmarks! {
         let _ = T::Currency::make_free_balance_be(&recipient, existential_deposit.into());
     }: _(
         RawOrigin::Signed(caller.clone()),
-        T::BlockNumber::zero(),
+        BlockNumberFor::<T>::zero(),
         Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient_lookup)
     )
     verify {
@@ -104,7 +104,7 @@ benchmarks! {
         let _ = T::Currency::make_free_balance_be(&recipient2, existential_deposit.into());
     }: _(
         RawOrigin::Signed(caller.clone()),
-        T::BlockNumber::zero(),
+        BlockNumberFor::<T>::zero(),
         Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient1_lookup),
         Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient2_lookup),
         existential_deposit.into()
diff --git a/pallets/provide-randomness/src/benchmarking.rs b/pallets/provide-randomness/src/benchmarking.rs
index cbbf0f685..56dfe1590 100644
--- a/pallets/provide-randomness/src/benchmarking.rs
+++ b/pallets/provide-randomness/src/benchmarking.rs
@@ -23,6 +23,7 @@ use frame_support::ensure;
 use frame_support::pallet_prelude::IsType;
 use frame_support::sp_runtime::{traits::One, Saturating};
 use frame_support::traits::{Currency, Get, OnInitialize};
+use frame_system::pallet_prelude::BlockNumberFor;
 use frame_system::RawOrigin;
 use sp_core::H256;
 
@@ -64,7 +65,7 @@ benchmarks! {
         T: pallet_balances::Config,
         T::Balance: From<u64>,
         <T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>,
-        T::BlockNumber: From<u32>,
+        BlockNumberFor<T>: From<u32>,
     }
     request {
         // Get account
@@ -94,7 +95,7 @@ benchmarks! {
             core::mem::replace(next_in, next_in.saturating_sub(1))
         });
         ensure!(next_epoch_hook_in != 1, "Will be next epoch.");
-    }: { Pallet::<T>::on_initialize(T::BlockNumber::one()); }
+    }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); }
     verify {
         ensure!(RequestsIds::<T>::count() == 0, "List not processed.");
         ensure!(RequestsReadyAtNextBlock::<T>::get().is_empty(), "List not processed.");
diff --git a/pallets/quota/src/benchmarking.rs b/pallets/quota/src/benchmarking.rs
index 124f2e66f..bae829e73 100644
--- a/pallets/quota/src/benchmarking.rs
+++ b/pallets/quota/src/benchmarking.rs
@@ -59,14 +59,14 @@ benchmarks! {
         IdtyQuota::<T>::insert(
             idty_id,
             Quota {
-                last_use: T::BlockNumber::zero(),
+                last_use: BlockNumberFor::<T>::zero(),
                 amount: quota_amount.into(),
             },
         );
     }: { Pallet::<T>::spend_quota(idty_id, amount.into()) }
     verify {
         let quota_growth = sp_runtime::Perbill::from_rational(
-            T::BlockNumber::one(),
+            BlockNumberFor::<T>::one(),
             T::ReloadRate::get(),
         ).mul_floor(T::MaxQuota::get());
         assert_eq!(IdtyQuota::<T>::get(idty_id).unwrap().amount,  quota_growth +quota_amount.into() - amount.into());
@@ -77,7 +77,7 @@ benchmarks! {
         IdtyQuota::<T>::insert(
             idty_id,
             Quota {
-                last_use: T::BlockNumber::zero(),
+                last_use: BlockNumberFor::<T>::zero(),
                 amount: 10u64.into(),
             },
         );
@@ -127,7 +127,7 @@ benchmarks! {
         IdtyQuota::<T>::insert(
             idty_id,
             Quota {
-                last_use: T::BlockNumber::zero(),
+                last_use: BlockNumberFor::<T>::zero(),
                 amount: 10u64.into(),
             },
         );
-- 
GitLab