-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d36ae2c
commit a08e30d
Showing
14 changed files
with
461 additions
and
63 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
//! DdcStaking pallet benchmarking. | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
use crate::Pallet as DdcCustomers; | ||
use ddc_primitives::{ClusterGovParams, ClusterId, ClusterParams}; | ||
use frame_benchmarking::{account, benchmarks, whitelist_account}; | ||
use frame_support::traits::Currency; | ||
use sp_runtime::Perquintill; | ||
use sp_std::prelude::*; | ||
|
||
pub type BalanceOf<T> = | ||
<<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance; | ||
|
||
use frame_system::{Pallet as System, RawOrigin}; | ||
|
||
const USER_SEED: u32 = 999666; | ||
|
||
benchmarks! { | ||
create_bucket { | ||
let cluster_id = ClusterId::from([1; 20]); | ||
let user = account::<T::AccountId>("user", USER_SEED, 0u32); | ||
|
||
let cluster_gov_params: ClusterGovParams<BalanceOf<T>, T::BlockNumber> = ClusterGovParams { | ||
treasury_share: Perquintill::default(), | ||
validators_share: Perquintill::default(), | ||
cluster_reserve_share: Perquintill::default(), | ||
cdn_bond_size: 100u32.into(), | ||
cdn_chill_delay: 50u32.into(), | ||
cdn_unbonding_delay: 50u32.into(), | ||
storage_bond_size: 100u32.into(), | ||
storage_chill_delay: 50u32.into(), | ||
storage_unbonding_delay: 50u32.into(), | ||
unit_per_mb_stored: 10, | ||
unit_per_mb_streamed: 10, | ||
unit_per_put_request: 10, | ||
unit_per_get_request: 10, | ||
}; | ||
|
||
let _ = <T as pallet::Config>::ClusterCreator::create_new_cluster( | ||
ClusterId::from([1; 20]), | ||
user.clone(), | ||
user.clone(), | ||
ClusterParams { node_provider_auth_contract: user.clone() }, | ||
cluster_gov_params | ||
); | ||
|
||
whitelist_account!(user); | ||
}: _(RawOrigin::Signed(user), cluster_id) | ||
verify { | ||
assert_eq!(Pallet::<T>::buckets_count(), 1); | ||
} | ||
|
||
deposit { | ||
let user = account::<T::AccountId>("user", USER_SEED, 0u32); | ||
let balance = <T as pallet::Config>::Currency::minimum_balance() * 100u32.into(); | ||
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance); | ||
let amount = <T as pallet::Config>::Currency::minimum_balance() * 50u32.into(); | ||
|
||
whitelist_account!(user); | ||
}: _(RawOrigin::Signed(user.clone()), amount) | ||
verify { | ||
assert!(Ledger::<T>::contains_key(user)); | ||
} | ||
|
||
deposit_extra { | ||
let user = account::<T::AccountId>("user", USER_SEED, 0u32); | ||
let balance = <T as pallet::Config>::Currency::minimum_balance() * 200u32.into(); | ||
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance); | ||
let amount = <T as pallet::Config>::Currency::minimum_balance() * 50u32.into(); | ||
|
||
let _ = DdcCustomers::<T>::deposit(RawOrigin::Signed(user.clone()).into(), amount); | ||
|
||
whitelist_account!(user); | ||
}: _(RawOrigin::Signed(user.clone()), amount) | ||
verify { | ||
assert!(Ledger::<T>::contains_key(user)); | ||
} | ||
|
||
unlock_deposit { | ||
let user = account::<T::AccountId>("user", USER_SEED, 0u32); | ||
let balance = <T as pallet::Config>::Currency::minimum_balance() * 200u32.into(); | ||
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance); | ||
let amount = <T as pallet::Config>::Currency::minimum_balance() * 50u32.into(); | ||
|
||
let _ = DdcCustomers::<T>::deposit(RawOrigin::Signed(user.clone()).into(), amount); | ||
|
||
whitelist_account!(user); | ||
}: unlock_deposit(RawOrigin::Signed(user.clone()), amount) | ||
verify { | ||
assert!(Ledger::<T>::contains_key(user)); | ||
} | ||
|
||
// Worst case scenario, 31/32 chunks unlocked after the unlocking duration | ||
withdraw_unlocked_deposit_update { | ||
|
||
System::<T>::set_block_number(1u32.into()); | ||
|
||
let user = account::<T::AccountId>("user", USER_SEED, 0u32); | ||
let balance = <T as pallet::Config>::Currency::minimum_balance() * 2000u32.into(); | ||
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance); | ||
let amount = <T as pallet::Config>::Currency::minimum_balance() * 32u32.into(); | ||
|
||
let _ = DdcCustomers::<T>::deposit(RawOrigin::Signed(user.clone()).into(), amount); | ||
|
||
for _k in 1 .. 32 { | ||
let _ = DdcCustomers::<T>::unlock_deposit(RawOrigin::Signed(user.clone()).into(), <T as pallet::Config>::Currency::minimum_balance() * 1u32.into()); | ||
} | ||
|
||
System::<T>::set_block_number(5256001u32.into()); | ||
|
||
whitelist_account!(user); | ||
}: withdraw_unlocked_deposit(RawOrigin::Signed(user.clone())) | ||
verify { | ||
let ledger = Ledger::<T>::try_get(user).unwrap(); | ||
assert_eq!(ledger.active, amount / 32u32.into()); | ||
} | ||
|
||
// Worst case scenario, everything is removed after the unlocking duration | ||
withdraw_unlocked_deposit_kill { | ||
|
||
System::<T>::set_block_number(1u32.into()); | ||
|
||
let user = account::<T::AccountId>("user", USER_SEED, 0u32); | ||
let user2 = account::<T::AccountId>("user", USER_SEED, 1u32); | ||
let balance = <T as pallet::Config>::Currency::minimum_balance() * 2000u32.into(); | ||
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance); | ||
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user2, balance); | ||
let amount = <T as pallet::Config>::Currency::minimum_balance() * 32u32.into(); | ||
|
||
let _ = DdcCustomers::<T>::deposit(RawOrigin::Signed(user.clone()).into(), amount); | ||
// To keep the balance of pallet positive | ||
let _ = DdcCustomers::<T>::deposit(RawOrigin::Signed(user2).into(), amount); | ||
|
||
|
||
for _k in 1 .. 33 { | ||
let _ = DdcCustomers::<T>::unlock_deposit(RawOrigin::Signed(user.clone()).into(), <T as pallet::Config>::Currency::minimum_balance() * 1u32.into()); | ||
} | ||
|
||
System::<T>::set_block_number(5256001u32.into()); | ||
|
||
whitelist_account!(user); | ||
}: withdraw_unlocked_deposit(RawOrigin::Signed(user.clone())) | ||
verify { | ||
assert!(!Ledger::<T>::contains_key(user)); | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
DdcCustomers, | ||
crate::mock::ExtBuilder.build(), | ||
crate::mock::Test, | ||
); | ||
} |
Oops, something went wrong.