diff --git a/pallets/slow-clap/src/benchmarking.rs b/pallets/slow-clap/src/benchmarking.rs index 20ca428..432ce5f 100644 --- a/pallets/slow-clap/src/benchmarking.rs +++ b/pallets/slow-clap/src/benchmarking.rs @@ -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::::set(&session_index, bounded_authorities); + Authorities::::set(&session_index, bounded_authorities.clone()); + Authorities::::set(&next_session_index, bounded_authorities); let minimum_balance = <::Currency>::minimum_balance(); let receiver = create_account::(); @@ -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); >::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(); - >::slow_clap(RawOrigin::None.into(), clap, signature)?; - >::trigger_nullification_for_benchmark(); + Pallet::::slow_clap(RawOrigin::None.into(), clap, signature)?; + Pallet::::trigger_nullification_for_benchmark(); assert_eq!(<::Currency>::total_balance(&receiver), Default::default()); assert_eq!(ApplausesForTransaction::::get(&storage_key), false); + + frame_system::Pallet::::on_initialize(1u32.into()); + + let mut fake_received_clap = + BoundedBTreeSet::::new(); + assert_eq!(fake_received_clap.try_insert(1).unwrap(), true); + pallet::ReceivedClaps::::insert(&next_storage_key, fake_received_clap); }: _(RawOrigin::Signed(receiver_clone), network_id, session_index, transaction_hash, receiver_clone.clone(), amount) verify { assert_eq!(<::Currency>::total_balance(&receiver), amount); diff --git a/pallets/slow-clap/src/tests.rs b/pallets/slow-clap/src/tests.rs index 47b859b..4ea4424 100644 --- a/pallets/slow-clap/src/tests.rs +++ b/pallets/slow-clap/src/tests.rs @@ -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::::MaxAuthorities>::new(); assert_eq!(fake_received_clap.try_insert(1).unwrap(), true); assert_eq!(fake_received_clap.try_insert(2).unwrap(), true); pallet::ReceivedClaps::::insert(&storage_key, fake_received_clap); - pallet::ClapsInSession::::insert(&next_session_index, fake_claps_in_session); assert_ok!(SlowClap::self_applause( RuntimeOrigin::signed(receiver),