Skip to content

Commit

Permalink
remove pallet::getter from pallet-offences (#6027)
Browse files Browse the repository at this point in the history
# Description
Part of #3326
Removes pallet::getter from pallet-offences from type `Reports`.
Adds a test to verify that retrieval of `Reports` still works with
storage::getter.

polkadot address: 155YyFVoMnv9BY6qxy2i5wxtveUw7WE1n5H81fL8PZKTA1Sd

---------

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Dónal Murray <donal.murray@parity.io>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent 5a8e082 commit fbd69a3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
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
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)
}

/// 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

0 comments on commit fbd69a3

Please sign in to comment.