From 1e1d9cd1f60dacd907e08cd7b9d2cce2101545f3 Mon Sep 17 00:00:00 2001 From: bgallois <benjamin@gallois.cc> Date: Mon, 13 Nov 2023 16:01:30 +0100 Subject: [PATCH] tmp --- pallets/quota/src/benchmarking.rs | 34 ++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/pallets/quota/src/benchmarking.rs b/pallets/quota/src/benchmarking.rs index 587ff9cc5..cd1a584fb 100644 --- a/pallets/quota/src/benchmarking.rs +++ b/pallets/quota/src/benchmarking.rs @@ -34,17 +34,41 @@ benchmarks! { } queue_refund { let account: T::AccountId = account("Alice", 1, 1); + let dummy_refund = Refund { + account: account.clone(), + identity: 0u32.into(), + amount: 20u64.into(), + }; let refund = Refund { account, identity: 1u32.into(), amount: 10u64.into(), }; - }: { Pallet::<T>::queue_refund(refund) } + // Complexity is bound to MAX_QUEUD_REFUNDS where an insertion is O(n-1) + for i in 0..MAX_QUEUED_REFUNDS-1 { + Pallet::<T>::queue_refund(dummy_refund.clone()) + } + }: { Pallet::<T>::queue_refund(refund.clone()) } + verify { + assert_eq!(RefundQueue::<T>::get().last(), Some(refund).as_ref()); + assert_eq!(RefundQueue::<T>::get().len() as u32, MAX_QUEUED_REFUNDS); + } spend_quota { - let idty_id = 1u32; - let amount = 1u64; + let idty_id: IdtyId<T> = 1u32.into(); + let amount = 2u64; + IdtyQuota::<T>::insert( + idty_id, + Quota { + last_use: T::BlockNumber::zero(), + amount: 10u64.into(), + }, + ); }: { Pallet::<T>::spend_quota(idty_id.into(), amount.into()) } - try_refund { + verify { + // Initially 10, updated to 11, minus 2 + assert_eq!(IdtyQuota::<T>::get(idty_id).unwrap().amount, 9u64.into()); + } + /*try_refund { let account: T::AccountId = account("Alice", 1, 1); let refund = Refund { account, @@ -60,5 +84,5 @@ benchmarks! { amount: 10u64.into(), }; let amount = 5u64.into(); - }: { Pallet::<T>::do_refund(refund, amount) } + }: { Pallet::<T>::do_refund(refund, amount) }*/ } -- GitLab