correct benchmarking of self applause and remove of unnecessary storage during tests
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
decf6665df
commit
d6ecdcd468
@ -50,10 +50,15 @@ benchmarks! {
|
||||
|
||||
self_applause {
|
||||
let session_index = T::ValidatorSet::session_index();
|
||||
let authorities = vec![T::AuthorityId::generate_pair(None)];
|
||||
let next_session_index = session_index.saturating_add(1);
|
||||
let authorities = vec![
|
||||
T::AuthorityId::generate_pair(None),
|
||||
T::AuthorityId::generate_pair(None),
|
||||
];
|
||||
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities.clone())
|
||||
.map_err(|()| "more than the maximum number of keys provided")?;
|
||||
Authorities::<T>::set(&session_index, bounded_authorities);
|
||||
Authorities::<T>::set(&session_index, bounded_authorities.clone());
|
||||
Authorities::<T>::set(&next_session_index, bounded_authorities);
|
||||
|
||||
let minimum_balance = <<T as pallet::Config>::Currency>::minimum_balance();
|
||||
let receiver = create_account::<T>();
|
||||
@ -68,6 +73,7 @@ benchmarks! {
|
||||
&network_id,
|
||||
);
|
||||
let storage_key = (session_index, &transaction_hash, &unique_transaction_hash);
|
||||
let next_storage_key = (next_session_index, &transaction_hash, &unique_transaction_hash);
|
||||
|
||||
<Pallet::<T>>::trigger_nullification_for_benchmark();
|
||||
let clap = Clap {
|
||||
@ -86,11 +92,18 @@ benchmarks! {
|
||||
.expect("first authority should exist");
|
||||
let encoded_clap = clap.encode();
|
||||
let signature = authority_id.sign(&encoded_clap).unwrap();
|
||||
<Pallet<T>>::slow_clap(RawOrigin::None.into(), clap, signature)?;
|
||||
<Pallet::<T>>::trigger_nullification_for_benchmark();
|
||||
Pallet::<T>::slow_clap(RawOrigin::None.into(), clap, signature)?;
|
||||
Pallet::<T>::trigger_nullification_for_benchmark();
|
||||
|
||||
assert_eq!(<<T as pallet::Config>::Currency>::total_balance(&receiver), Default::default());
|
||||
assert_eq!(ApplausesForTransaction::<T>::get(&storage_key), false);
|
||||
|
||||
frame_system::Pallet::<T>::on_initialize(1u32.into());
|
||||
|
||||
let mut fake_received_clap =
|
||||
BoundedBTreeSet::<AuthIndex, T::MaxAuthorities>::new();
|
||||
assert_eq!(fake_received_clap.try_insert(1).unwrap(), true);
|
||||
pallet::ReceivedClaps::<T>::insert(&next_storage_key, fake_received_clap);
|
||||
}: _(RawOrigin::Signed(receiver_clone), network_id, session_index, transaction_hash, receiver_clone.clone(), amount)
|
||||
verify {
|
||||
assert_eq!(<<T as pallet::Config>::Currency>::total_balance(&receiver), amount);
|
||||
|
||||
@ -954,7 +954,6 @@ fn should_self_applause_if_enough_claps() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let _ = prepare_evm_network(Some(network_id), Some(0));
|
||||
let session_index = advance_session_and_get_index();
|
||||
let next_session_index = session_index.saturating_add(1);
|
||||
let storage_key = (session_index, transaction_hash, unique_transaction_hash);
|
||||
|
||||
assert_err!(
|
||||
@ -978,29 +977,12 @@ fn should_self_applause_if_enough_claps() {
|
||||
assert_ok!(do_clap_from(session_index, network_id, 0, false));
|
||||
advance_session();
|
||||
|
||||
let mut fake_claps_in_session = sp_std::collections::btree_map::BTreeMap::new();
|
||||
fake_claps_in_session.insert(
|
||||
1,
|
||||
SessionAuthorityInfo {
|
||||
claps: 1,
|
||||
disabled: false,
|
||||
},
|
||||
);
|
||||
fake_claps_in_session.insert(
|
||||
2,
|
||||
SessionAuthorityInfo {
|
||||
claps: 1,
|
||||
disabled: false,
|
||||
},
|
||||
);
|
||||
|
||||
let mut fake_received_clap =
|
||||
BoundedBTreeSet::<AuthIndex, <Runtime as pallet::Config>::MaxAuthorities>::new();
|
||||
assert_eq!(fake_received_clap.try_insert(1).unwrap(), true);
|
||||
assert_eq!(fake_received_clap.try_insert(2).unwrap(), true);
|
||||
|
||||
pallet::ReceivedClaps::<Runtime>::insert(&storage_key, fake_received_clap);
|
||||
pallet::ClapsInSession::<Runtime>::insert(&next_session_index, fake_claps_in_session);
|
||||
|
||||
assert_ok!(SlowClap::self_applause(
|
||||
RuntimeOrigin::signed(receiver),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user