|
| 1 | +//! Confidential Docs pallet benchmarking. |
| 2 | +
|
| 3 | +#![cfg(feature = "runtime-benchmarks")] |
| 4 | + |
| 5 | +use super::*; |
| 6 | +use crate::Pallet as ConfidentialDocs; |
| 7 | + |
| 8 | +use frame_benchmarking::v2::*; |
| 9 | +use frame_system::RawOrigin; |
| 10 | +use sp_runtime::traits::Bounded; |
| 11 | +use types::ExtraFlags; |
| 12 | + |
| 13 | +const SEED: u32 = 0; |
| 14 | + |
| 15 | +#[instance_benchmarks] |
| 16 | +mod benchmarks { |
| 17 | + use super::*; |
| 18 | + |
| 19 | + // Benchmark `transfer` extrinsic with the worst possible conditions: |
| 20 | + // * Transfer will kill the sender account. |
| 21 | + // * Transfer will create the recipient account. |
| 22 | + #[benchmark] |
| 23 | + fn set_vault() { |
| 24 | + let existential_deposit = T::ExistentialDeposit::get(); |
| 25 | + let caller = whitelisted_caller(); |
| 26 | + |
| 27 | + // Give some multiple of the existential deposit |
| 28 | + let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into()); |
| 29 | + let _ = <Balances<T, I> as Currency<_>>::make_free_balance_be(&caller, balance); |
| 30 | + |
| 31 | + // Transfer `e - 1` existential deposits + 1 unit, which guarantees to create one account, |
| 32 | + // and reap this user. |
| 33 | + let recipient: T::AccountId = account("recipient", 0, SEED); |
| 34 | + let recipient_lookup = T::Lookup::unlookup(recipient.clone()); |
| 35 | + let transfer_amount = |
| 36 | + existential_deposit.saturating_mul((ED_MULTIPLIER - 1).into()) + 1u32.into(); |
| 37 | + |
| 38 | + #[extrinsic_call] |
| 39 | + _(RawOrigin::Signed(caller.clone()), recipient_lookup, transfer_amount); |
| 40 | + |
| 41 | + assert_eq!(Balances::<T, I>::free_balance(&caller), Zero::zero()); |
| 42 | + assert_eq!(Balances::<T, I>::free_balance(&recipient), transfer_amount); |
| 43 | + } |
| 44 | + |
| 45 | + impl_benchmark_test_suite! { |
| 46 | + Balances, |
| 47 | + crate::tests::ExtBuilder::default().build(), |
| 48 | + crate::tests::Test, |
| 49 | + } |
| 50 | +} |
0 commit comments