Skip to content

Commit fde90b4

Browse files
Started developing confidential docs benchmarks.
1 parent f85407c commit fde90b4

File tree

3 files changed

+193
-87
lines changed

3 files changed

+193
-87
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

pallets/confidential-docs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod mock;
1212
mod tests;
1313

1414
// #[cfg(feature = "runtime-benchmarks")]
15-
// mod benchmarking;
15+
mod benchmarking;
1616

1717
mod functions;
1818
pub mod types;

0 commit comments

Comments
 (0)