mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Associated type Hasher for QueryPreimage, StorePreimage and Bounded (#1720)
I hope it's enough to fix #1701 the only solution I found to make it happen is to put an associated type to the `Bounded` enum as well. @liamaharon @kianenigma @bkchr Polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp --------- Signed-off-by: muraca <mmuraca247@gmail.com> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -49,8 +49,8 @@ use frame_support::{
|
||||
ensure,
|
||||
pallet_prelude::Get,
|
||||
traits::{
|
||||
Consideration, Currency, Defensive, FetchResult, Footprint, Hash as PreimageHash,
|
||||
PreimageProvider, PreimageRecipient, QueryPreimage, ReservableCurrency, StorePreimage,
|
||||
Consideration, Currency, Defensive, FetchResult, Footprint, PreimageProvider,
|
||||
PreimageRecipient, QueryPreimage, ReservableCurrency, StorePreimage,
|
||||
},
|
||||
BoundedSlice, BoundedVec,
|
||||
};
|
||||
@@ -531,7 +531,9 @@ impl<T: Config> PreimageRecipient<T::Hash> for Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<Hash = PreimageHash>> QueryPreimage for Pallet<T> {
|
||||
impl<T: Config> QueryPreimage for Pallet<T> {
|
||||
type H = T::Hashing;
|
||||
|
||||
fn len(hash: &T::Hash) -> Option<u32> {
|
||||
Pallet::<T>::len(hash)
|
||||
}
|
||||
@@ -555,7 +557,7 @@ impl<T: Config<Hash = PreimageHash>> QueryPreimage for Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<Hash = PreimageHash>> StorePreimage for Pallet<T> {
|
||||
impl<T: Config> StorePreimage for Pallet<T> {
|
||||
const MAX_LENGTH: usize = MAX_SIZE as usize;
|
||||
|
||||
fn note(bytes: Cow<[u8]>) -> Result<T::Hash, DispatchError> {
|
||||
|
||||
@@ -24,25 +24,32 @@ use crate::mock::*;
|
||||
|
||||
use frame_support::{
|
||||
assert_err, assert_noop, assert_ok, assert_storage_noop,
|
||||
traits::{fungible::InspectHold, Bounded, BoundedInline, Hash as PreimageHash},
|
||||
traits::{fungible::InspectHold, Bounded, BoundedInline},
|
||||
StorageNoopGuard,
|
||||
};
|
||||
use sp_core::{blake2_256, H256};
|
||||
use sp_runtime::{bounded_vec, TokenError};
|
||||
|
||||
/// Returns one `Inline`, `Lookup` and `Legacy` item each with different data and hash.
|
||||
pub fn make_bounded_values() -> (Bounded<Vec<u8>>, Bounded<Vec<u8>>, Bounded<Vec<u8>>) {
|
||||
pub fn make_bounded_values() -> (
|
||||
Bounded<Vec<u8>, <Test as frame_system::Config>::Hashing>,
|
||||
Bounded<Vec<u8>, <Test as frame_system::Config>::Hashing>,
|
||||
Bounded<Vec<u8>, <Test as frame_system::Config>::Hashing>,
|
||||
) {
|
||||
let data: BoundedInline = bounded_vec![1];
|
||||
let inline = Bounded::<Vec<u8>>::Inline(data);
|
||||
let inline = Bounded::<Vec<u8>, <Test as frame_system::Config>::Hashing>::Inline(data);
|
||||
|
||||
let data = vec![1, 2];
|
||||
let hash: H256 = blake2_256(&data[..]).into();
|
||||
let hash = <Test as frame_system::Config>::Hashing::hash(&data[..]).into();
|
||||
let len = data.len() as u32;
|
||||
let lookup = Bounded::<Vec<u8>>::unrequested(hash, len);
|
||||
let lookup =
|
||||
Bounded::<Vec<u8>, <Test as frame_system::Config>::Hashing>::unrequested(hash, len);
|
||||
|
||||
let data = vec![1, 2, 3];
|
||||
let hash: H256 = blake2_256(&data[..]).into();
|
||||
let legacy = Bounded::<Vec<u8>>::Legacy { hash, dummy: Default::default() };
|
||||
let hash = <Test as frame_system::Config>::Hashing::hash(&data[..]).into();
|
||||
let legacy = Bounded::<Vec<u8>, <Test as frame_system::Config>::Hashing>::Legacy {
|
||||
hash,
|
||||
dummy: Default::default(),
|
||||
};
|
||||
|
||||
(inline, lookup, legacy)
|
||||
}
|
||||
@@ -303,7 +310,7 @@ fn query_and_store_preimage_workflow() {
|
||||
let bound = Preimage::bound(data.clone()).unwrap();
|
||||
let (len, hash) = (bound.len().unwrap(), bound.hash());
|
||||
|
||||
assert_eq!(hash, blake2_256(&encoded).into());
|
||||
assert_eq!(hash, <Test as frame_system::Config>::Hashing::hash(&encoded).into());
|
||||
assert_eq!(bound.len(), Some(len));
|
||||
assert!(bound.lookup_needed(), "Should not be Inlined");
|
||||
assert_eq!(bound.lookup_len(), Some(len));
|
||||
@@ -364,7 +371,7 @@ fn query_preimage_request_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let _guard = StorageNoopGuard::default();
|
||||
let data: Vec<u8> = vec![1; 10];
|
||||
let hash: PreimageHash = blake2_256(&data[..]).into();
|
||||
let hash = <Test as frame_system::Config>::Hashing::hash(&data[..]).into();
|
||||
|
||||
// Request the preimage.
|
||||
<Preimage as QueryPreimage>::request(&hash);
|
||||
@@ -454,7 +461,7 @@ fn store_preimage_basic_works() {
|
||||
|
||||
// Cleanup.
|
||||
<Preimage as StorePreimage>::unnote(&bound.hash());
|
||||
let data_hash = blake2_256(&data);
|
||||
let data_hash = <Test as frame_system::Config>::Hashing::hash(&data);
|
||||
<Preimage as StorePreimage>::unnote(&data_hash.into());
|
||||
|
||||
// No storage changes remain. Checked by `StorageNoopGuard`.
|
||||
|
||||
Reference in New Issue
Block a user