pallet_timegraph/
benchmarking.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#![cfg(feature = "runtime-benchmarks")]
#![allow(clippy::duplicated_attributes)]
use super::*;

#[allow(unused)]
use crate::Pallet as Timegraph;

use polkadot_sdk::{frame_benchmarking, frame_support, frame_system};

use frame_benchmarking::v2::*;
use frame_system::RawOrigin;

#[benchmarks]
mod benchmarks {
	use super::*;
	use frame_support::traits::{Currency, ReservableCurrency};

	#[benchmark]
	fn deposit() {
		let caller = whitelisted_caller();
		let amount: BalanceOf<T> = 5_000_000u32.into();
		let amount_be: BalanceOf<T> = amount * 100u32.into();
		T::Currency::resolve_creating(&caller, T::Currency::issue(amount_be));
		#[extrinsic_call]
		deposit(RawOrigin::Signed(caller), amount);
	}

	#[benchmark]
	fn withdraw() {
		let caller = whitelisted_caller();
		let amount: BalanceOf<T> = 5_000_000u32.into();
		let amount_be: BalanceOf<T> = amount * 100u32.into();
		T::Currency::resolve_creating(&caller, T::Currency::issue(amount_be));
		let _ = T::Currency::reserve(&caller, Threshold::<T>::get() + amount);

		#[extrinsic_call]
		withdraw(RawOrigin::Signed(caller), amount);
	}

	#[benchmark]
	fn transfer_to_pool() {
		let caller: T::AccountId = whitelisted_caller();
		let account: T::AccountId = account("name", 0, 0);
		let amount: BalanceOf<T> = 5_000_000_u32.into();
		T::Currency::resolve_creating(
			&account,
			T::Currency::issue(amount * 100u32.into() + Threshold::<T>::get()),
		);
		TimegraphAccount::<T>::set(caller.clone());
		let _ = T::Currency::reserve(&account, Threshold::<T>::get() + amount);

		#[extrinsic_call]
		transfer_to_pool(RawOrigin::Signed(caller), account, amount);
	}

	#[benchmark]
	fn transfer_award_to_user() {
		let caller: T::AccountId = whitelisted_caller();
		let account: T::AccountId = account("name", 0, 0);
		let amount: BalanceOf<T> = 5_000_000_u32.into();

		T::Currency::resolve_creating(&caller, T::Currency::issue(amount * 200u32.into()));

		T::Currency::resolve_creating(&account, T::Currency::issue(amount * 100u32.into()));

		TimegraphAccount::<T>::set(caller.clone());
		RewardPoolAccount::<T>::set(caller.clone());

		#[extrinsic_call]
		transfer_award_to_user(RawOrigin::Signed(caller), account, amount);
	}

	#[benchmark]
	fn set_timegraph_account() {
		let new_account: T::AccountId = account("name", 0, 0);
		#[extrinsic_call]
		// Example new account
		set_timegraph_account(RawOrigin::Root, new_account);
	}

	#[benchmark]
	fn set_reward_pool_account() {
		let new_account: T::AccountId = account("name", 0, 0);

		#[extrinsic_call]
		set_reward_pool_account(RawOrigin::Root, new_account);
	}

	#[benchmark]
	fn set_threshold() {
		let amount: BalanceOf<T> = 5_000_000_u32.into();

		#[extrinsic_call]
		set_threshold(RawOrigin::Root, amount);
	}

	impl_benchmark_test_suite!(Timegraph, crate::mock::new_test_ext(), crate::mock::Test);
}