-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added more test cases based on the comment and added benchmark setup
- Loading branch information
1 parent
12fdab4
commit 0254064
Showing
2 changed files
with
136 additions
and
40 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,35 +1,52 @@ | ||
//! Benchmarking setup for pallet-disputes | ||
#![cfg(feature = "runtime-benchmarks")] | ||
use super::*; | ||
|
||
#[allow(unused)] | ||
use crate::Pallet as Disputes; | ||
use frame_benchmarking::v2::*; | ||
use frame_system::RawOrigin; | ||
use crate::Pallet as PalletDisputes; | ||
use crate::{traits::DisputeRaiser}; | ||
use frame_benchmarking::{v2::*}; | ||
use frame_support::assert_ok; | ||
use sp_runtime::SaturatedConversion; | ||
use orml_traits::{MultiCurrency}; | ||
use common_types::CurrencyId; | ||
|
||
|
||
#[benchmarks( where <T as frame_system::Config>::AccountId: AsRef<[u8]>, crate::Event::<T>: Into<<T as frame_system::Config>::RuntimeEvent>)] | ||
#[benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn do_something() { | ||
let value = 100u32.into(); | ||
let caller: T::AccountId = whitelisted_caller(); | ||
#[extrinsic_call] | ||
do_something(RawOrigin::Signed(caller), value); | ||
|
||
assert_eq!(Something::<T>::get(), Some(value)); | ||
fn raise_a_dispute() { | ||
let alice: T::AccountId = create_funded_user::<T>("alice", 1, 1_000_000_000_000_000_000u128); | ||
let bob: T::AccountId = create_funded_user::<T>("bob", 1, 1_000_000_000_000_000_000u128); | ||
let charlie: T::AccountId = create_funded_user::<T>("charlie", 1, 1_000_000_000_000_000_000u128); | ||
let dispute_key = 10; | ||
let jury = get_jury::<Test>(vec![alice, bob]); | ||
let specifics = get_specifics::<Test>(vec![0, 1]); | ||
assert_ok!(<PalletDisputes as DisputeRaiser<AccountId>>::raise_dispute( | ||
dispute_key, | ||
alice, | ||
jury, | ||
specifics, | ||
)); | ||
assert!(PalletDisputes::disputes(dispute_key).is_some()); | ||
assert_eq!(1, PalletDisputes::disputes(dispute_key).iter().count()); | ||
} | ||
|
||
#[benchmark] | ||
fn cause_error() { | ||
Something::<T>::put(100u32); | ||
let caller: T::AccountId = whitelisted_caller(); | ||
#[extrinsic_call] | ||
cause_error(RawOrigin::Signed(caller)); | ||
|
||
assert_eq!(Something::<T>::get(), Some(101u32)); | ||
} | ||
impl_benchmark_test_suite!(PalletDisputes, crate::mock::new_test_ext(), crate::mock::Test); | ||
} | ||
|
||
impl_benchmark_test_suite!(Disputes, crate::mock::new_test_ext(), crate::mock::Test); | ||
pub fn create_funded_user<T: Config>( | ||
seed: &'static str, | ||
n: u32, | ||
balance_factor: u128, | ||
) -> T::AccountId { | ||
let user = account(seed, n, 0); | ||
assert_ok!(<T::MultiCurrency as MultiCurrency< | ||
<T as frame_system::Config>::AccountId, | ||
>>::deposit( | ||
CurrencyId::Native, &user, balance_factor.saturated_into() | ||
)); | ||
user | ||
} | ||
|
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