cumulus_test_runtime/
test_pallet.rs1pub use pallet::*;
19
20pub const TEST_RUNTIME_UPGRADE_KEY: &[u8] = b"+test_runtime_upgrade_key+";
23
24#[frame_support::pallet(dev_mode)]
25pub mod pallet {
26 use crate::test_pallet::TEST_RUNTIME_UPGRADE_KEY;
27 use alloc::vec;
28 use frame_support::pallet_prelude::*;
29 use frame_system::pallet_prelude::*;
30
31 #[pallet::pallet]
32 pub struct Pallet<T>(_);
33
34 #[pallet::config]
35 pub trait Config: frame_system::Config + cumulus_pallet_parachain_system::Config {}
36
37 #[pallet::storage]
39 pub type TestMap<T: Config> = StorageMap<_, Twox64Concat, u32, (), ValueQuery>;
40
41 #[pallet::hooks]
42 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
43
44 #[pallet::call]
45 impl<T: Config> Pallet<T> {
46 #[pallet::weight(0)]
48 pub fn set_custom_validation_head_data(
49 _: OriginFor<T>,
50 custom_header: alloc::vec::Vec<u8>,
51 ) -> DispatchResult {
52 cumulus_pallet_parachain_system::Pallet::<T>::set_custom_validation_head_data(
53 custom_header,
54 );
55 Ok(())
56 }
57
58 #[pallet::weight(0)]
62 pub fn read_and_write_child_tries(_: OriginFor<T>) -> DispatchResult {
63 let key = &b"hello"[..];
64 let first_trie = &b"first"[..];
65 let second_trie = &b"second"[..];
66 let first_value = "world1".encode();
67 let second_value = "world2".encode();
68
69 if let Some(res) = sp_io::default_child_storage::get(first_trie, key) {
70 assert_eq!(first_value, res);
71 }
72 if let Some(res) = sp_io::default_child_storage::get(second_trie, key) {
73 assert_eq!(second_value, res);
74 }
75
76 sp_io::default_child_storage::set(first_trie, key, &first_value);
77 sp_io::default_child_storage::set(second_trie, key, &second_value);
78
79 Ok(())
80 }
81
82 pub fn read_and_write_big_value(_: OriginFor<T>) -> DispatchResult {
86 let key = &b"really_huge_value"[..];
87 sp_io::storage::get(key);
88 sp_io::storage::set(key, &vec![0u8; 1024 * 1024 * 5]);
89
90 Ok(())
91 }
92
93 #[pallet::weight(0)]
95 pub fn store_values_in_map(_: OriginFor<T>, max_key: u32) -> DispatchResult {
96 for i in 0..=max_key {
97 TestMap::<T>::insert(i, ());
98 }
99 Ok(())
100 }
101
102 #[pallet::weight(0)]
104 pub fn remove_value_from_map(_: OriginFor<T>, key: u32) -> DispatchResult {
105 TestMap::<T>::remove(key);
106 Ok(())
107 }
108 }
109
110 #[derive(frame_support::DefaultNoBound)]
111 #[pallet::genesis_config]
112 pub struct GenesisConfig<T: Config> {
113 #[serde(skip)]
114 pub _config: core::marker::PhantomData<T>,
115 }
116
117 #[pallet::genesis_build]
118 impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
119 fn build(&self) {
120 sp_io::storage::set(TEST_RUNTIME_UPGRADE_KEY, &[1, 2, 3, 4]);
121 }
122 }
123}