Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove pallet::getter from pallet-offences #6027

Merged
merged 7 commits into from
Oct 16, 2024
9 changes: 9 additions & 0 deletions prdoc/pr_6027.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: Remove pallet::getter from pallet-offences
doc:
- audience: Runtime Dev
description: |
This PR removes pallet::getter from pallet-offences from type Reports. It also adds a test to verify that retrieval of Reports still works with storage::getter.

crates:
- name: pallet-offences
bump: patch
seadanda marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion substrate/frame/offences/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub mod pallet {

/// The primary structure that holds all offence records keyed by report identifiers.
#[pallet::storage]
#[pallet::getter(fn reports)]
pub type Reports<T: Config> = StorageMap<
_,
Twox64Concat,
Expand Down Expand Up @@ -152,6 +151,13 @@ where
}

impl<T: Config> Pallet<T> {
/// Get the offence details from reports of given ID.
pub fn reports(
report_id: ReportIdOf<T>,
) -> Option<OffenceDetails<T::AccountId, T::IdentificationTuple>> {
Reports::<T>::get(report_id)
}

Comment on lines +154 to +160
Copy link
Member

@shawntabrizi shawntabrizi Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, this is really all you need to do :)

Looking forward to seeing more contributions

/// Compute the ID for the given report properties.
///
/// The report id depends on the offence kind, time slot and the id of offender.
Expand Down
26 changes: 24 additions & 2 deletions substrate/frame/offences/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,34 @@

use super::*;
use crate::mock::{
new_test_ext, offence_reports, with_on_offence_fractions, Offence, Offences, RuntimeEvent,
System, KIND,
new_test_ext, offence_reports, with_on_offence_fractions, Offence, Offences, Runtime,
RuntimeEvent, System, KIND,
};
use frame_system::{EventRecord, Phase};
use sp_core::H256;
use sp_runtime::Perbill;

#[test]
fn should_get_reports_with_storagemap_getter_and_function_getter() {
new_test_ext().execute_with(|| {
// given
let report_id: ReportIdOf<Runtime> = H256::from_low_u64_be(1);
let offence_details = OffenceDetails { offender: 1, reporters: vec![2, 3] };

Reports::<Runtime>::insert(report_id, offence_details.clone());

// when
let stored_offence_details = Offences::reports(report_id);
// then
assert_eq!(stored_offence_details, Some(offence_details.clone()));

// when
let stored_offence_details = Reports::<Runtime>::get(report_id);
// then
assert_eq!(stored_offence_details, Some(offence_details.clone()));
});
}

#[test]
fn should_report_an_authority_and_trigger_on_offence() {
new_test_ext().execute_with(|| {
Expand Down
Loading