mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 22:37:57 +00:00
pallet-referenda: Detect incorrect pre-image length (#3850)
There has been a case that a referenda failed because the length given to `submit` was incorrect. The pallet can actually check the length if the pre-image already exists to ensure that these kind of issues are not happening again.
This commit is contained in:
@@ -424,6 +424,8 @@ pub mod pallet {
|
||||
BadStatus,
|
||||
/// The preimage does not exist.
|
||||
PreimageNotExist,
|
||||
/// The preimage is stored with a different length than the one provided.
|
||||
PreimageStoredWithDifferentLength,
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
@@ -462,6 +464,16 @@ pub mod pallet {
|
||||
let proposal_origin = *proposal_origin;
|
||||
let who = T::SubmitOrigin::ensure_origin(origin, &proposal_origin)?;
|
||||
|
||||
// If the pre-image is already stored, ensure that it has the same length as given in
|
||||
// `proposal`.
|
||||
if let (Some(preimage_len), Some(proposal_len)) =
|
||||
(proposal.lookup_hash().and_then(|h| T::Preimages::len(&h)), proposal.lookup_len())
|
||||
{
|
||||
if preimage_len != proposal_len {
|
||||
return Err(Error::<T, I>::PreimageStoredWithDifferentLength.into())
|
||||
}
|
||||
}
|
||||
|
||||
let track =
|
||||
T::Tracks::track_for(&proposal_origin).map_err(|_| Error::<T, I>::NoTrack)?;
|
||||
let submission_deposit = Self::take_deposit(who, T::SubmissionDeposit::get())?;
|
||||
|
||||
@@ -666,3 +666,19 @@ fn clear_metadata_works() {
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detects_incorrect_len() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let hash = note_preimage(1);
|
||||
assert_noop!(
|
||||
Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
frame_support::traits::Bounded::Lookup { hash, len: 3 },
|
||||
DispatchTime::At(1),
|
||||
),
|
||||
Error::<Test>::PreimageStoredWithDifferentLength
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user