mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 10:31:03 +00:00
Whitelist pallet preimage provider upgrade (#12834)
* whitelist preimage provider upgrade * rustdocs unresolved link error fix * ".git/.scripts/bench-bot.sh" pallet dev pallet_whitelist * PreimageHash alias, remove type annotation Co-authored-by: command-bot <>
This commit is contained in:
@@ -20,7 +20,10 @@
|
||||
use crate::mock::*;
|
||||
use codec::Encode;
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, dispatch::GetDispatchInfo, traits::PreimageProvider, weights::Weight,
|
||||
assert_noop, assert_ok,
|
||||
dispatch::GetDispatchInfo,
|
||||
traits::{QueryPreimage, StorePreimage},
|
||||
weights::Weight,
|
||||
};
|
||||
use sp_runtime::{traits::Hash, DispatchError};
|
||||
|
||||
@@ -43,7 +46,7 @@ fn test_whitelist_call_and_remove() {
|
||||
|
||||
assert_ok!(Whitelist::whitelist_call(RuntimeOrigin::root(), call_hash));
|
||||
|
||||
assert!(Preimage::preimage_requested(&call_hash));
|
||||
assert!(Preimage::is_requested(&call_hash));
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::whitelist_call(RuntimeOrigin::root(), call_hash),
|
||||
@@ -57,7 +60,7 @@ fn test_whitelist_call_and_remove() {
|
||||
|
||||
assert_ok!(Whitelist::remove_whitelisted_call(RuntimeOrigin::root(), call_hash));
|
||||
|
||||
assert!(!Preimage::preimage_requested(&call_hash));
|
||||
assert!(!Preimage::is_requested(&call_hash));
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::remove_whitelisted_call(RuntimeOrigin::root(), call_hash),
|
||||
@@ -72,33 +75,50 @@ fn test_whitelist_call_and_execute() {
|
||||
let call = RuntimeCall::System(frame_system::Call::remark_with_event { remark: vec![1] });
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let encoded_call = call.encode();
|
||||
let call_encoded_len = encoded_call.len() as u32;
|
||||
let call_hash = <Test as frame_system::Config>::Hashing::hash(&encoded_call[..]);
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::dispatch_whitelisted_call(RuntimeOrigin::root(), call_hash, call_weight),
|
||||
Whitelist::dispatch_whitelisted_call(
|
||||
RuntimeOrigin::root(),
|
||||
call_hash,
|
||||
call_encoded_len,
|
||||
call_weight
|
||||
),
|
||||
crate::Error::<Test>::CallIsNotWhitelisted,
|
||||
);
|
||||
|
||||
assert_ok!(Whitelist::whitelist_call(RuntimeOrigin::root(), call_hash));
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::dispatch_whitelisted_call(RuntimeOrigin::signed(1), call_hash, call_weight),
|
||||
Whitelist::dispatch_whitelisted_call(
|
||||
RuntimeOrigin::signed(1),
|
||||
call_hash,
|
||||
call_encoded_len,
|
||||
call_weight
|
||||
),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::dispatch_whitelisted_call(RuntimeOrigin::root(), call_hash, call_weight),
|
||||
crate::Error::<Test>::UnavailablePreImage,
|
||||
);
|
||||
|
||||
assert_ok!(Preimage::note_preimage(RuntimeOrigin::root(), encoded_call));
|
||||
|
||||
assert!(Preimage::preimage_requested(&call_hash));
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::dispatch_whitelisted_call(
|
||||
RuntimeOrigin::root(),
|
||||
call_hash,
|
||||
call_encoded_len,
|
||||
call_weight
|
||||
),
|
||||
crate::Error::<Test>::UnavailablePreImage,
|
||||
);
|
||||
|
||||
assert_ok!(Preimage::note(encoded_call.into()));
|
||||
|
||||
assert!(Preimage::is_requested(&call_hash));
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::dispatch_whitelisted_call(
|
||||
RuntimeOrigin::root(),
|
||||
call_hash,
|
||||
call_encoded_len,
|
||||
call_weight - Weight::from_ref_time(1)
|
||||
),
|
||||
crate::Error::<Test>::InvalidCallWeightWitness,
|
||||
@@ -107,13 +127,19 @@ fn test_whitelist_call_and_execute() {
|
||||
assert_ok!(Whitelist::dispatch_whitelisted_call(
|
||||
RuntimeOrigin::root(),
|
||||
call_hash,
|
||||
call_encoded_len,
|
||||
call_weight
|
||||
));
|
||||
|
||||
assert!(!Preimage::preimage_requested(&call_hash));
|
||||
assert!(!Preimage::is_requested(&call_hash));
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::dispatch_whitelisted_call(RuntimeOrigin::root(), call_hash, call_weight),
|
||||
Whitelist::dispatch_whitelisted_call(
|
||||
RuntimeOrigin::root(),
|
||||
call_hash,
|
||||
call_encoded_len,
|
||||
call_weight
|
||||
),
|
||||
crate::Error::<Test>::CallIsNotWhitelisted,
|
||||
);
|
||||
});
|
||||
@@ -124,21 +150,24 @@ fn test_whitelist_call_and_execute_failing_call() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let call = RuntimeCall::Whitelist(crate::Call::dispatch_whitelisted_call {
|
||||
call_hash: Default::default(),
|
||||
call_encoded_len: Default::default(),
|
||||
call_weight_witness: Weight::zero(),
|
||||
});
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let encoded_call = call.encode();
|
||||
let call_encoded_len = encoded_call.len() as u32;
|
||||
let call_hash = <Test as frame_system::Config>::Hashing::hash(&encoded_call[..]);
|
||||
|
||||
assert_ok!(Whitelist::whitelist_call(RuntimeOrigin::root(), call_hash));
|
||||
assert_ok!(Preimage::note_preimage(RuntimeOrigin::root(), encoded_call));
|
||||
assert!(Preimage::preimage_requested(&call_hash));
|
||||
assert_ok!(Preimage::note(encoded_call.into()));
|
||||
assert!(Preimage::is_requested(&call_hash));
|
||||
assert_ok!(Whitelist::dispatch_whitelisted_call(
|
||||
RuntimeOrigin::root(),
|
||||
call_hash,
|
||||
call_encoded_len,
|
||||
call_weight
|
||||
));
|
||||
assert!(!Preimage::preimage_requested(&call_hash));
|
||||
assert!(!Preimage::is_requested(&call_hash));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -151,14 +180,14 @@ fn test_whitelist_call_and_execute_without_note_preimage() {
|
||||
let call_hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
|
||||
|
||||
assert_ok!(Whitelist::whitelist_call(RuntimeOrigin::root(), call_hash));
|
||||
assert!(Preimage::preimage_requested(&call_hash));
|
||||
assert!(Preimage::is_requested(&call_hash));
|
||||
|
||||
assert_ok!(Whitelist::dispatch_whitelisted_call_with_preimage(
|
||||
RuntimeOrigin::root(),
|
||||
call.clone()
|
||||
));
|
||||
|
||||
assert!(!Preimage::preimage_requested(&call_hash));
|
||||
assert!(!Preimage::is_requested(&call_hash));
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::dispatch_whitelisted_call_with_preimage(RuntimeOrigin::root(), call),
|
||||
@@ -176,14 +205,20 @@ fn test_whitelist_call_and_execute_decode_consumes_all() {
|
||||
// Appending something does not make the encoded call invalid.
|
||||
// This tests that the decode function consumes all data.
|
||||
call.extend(call.clone());
|
||||
let call_encoded_len = call.len() as u32;
|
||||
|
||||
let call_hash = <Test as frame_system::Config>::Hashing::hash(&call[..]);
|
||||
|
||||
assert_ok!(Preimage::note_preimage(RuntimeOrigin::root(), call));
|
||||
assert_ok!(Preimage::note(call.into()));
|
||||
assert_ok!(Whitelist::whitelist_call(RuntimeOrigin::root(), call_hash));
|
||||
|
||||
assert_noop!(
|
||||
Whitelist::dispatch_whitelisted_call(RuntimeOrigin::root(), call_hash, call_weight),
|
||||
Whitelist::dispatch_whitelisted_call(
|
||||
RuntimeOrigin::root(),
|
||||
call_hash,
|
||||
call_encoded_len,
|
||||
call_weight
|
||||
),
|
||||
crate::Error::<Test>::UndecodableCall,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user