fix: CI quick-checks - fmt, taplo, umbrella version
This commit is contained in:
@@ -25,9 +25,9 @@ fn main() {
|
||||
mod cli {
|
||||
include!("src/cli.rs");
|
||||
|
||||
use bizinikiwi_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
|
||||
use clap::{CommandFactory, ValueEnum};
|
||||
use clap_complete::{generate_to, Shell};
|
||||
use bizinikiwi_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
|
||||
use std::{env, fs, path::Path};
|
||||
|
||||
pub fn main() {
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
use pezkuwi_sdk::*;
|
||||
|
||||
use pezsc_service::Properties;
|
||||
use pez_kitchensink_runtime::{
|
||||
genesis_config_presets::{Staker, ENDOWMENT, STASH},
|
||||
wasm_binary_unwrap, Block, MaxNominations, StakerStatus,
|
||||
@@ -29,6 +28,7 @@ use pezpallet_im_online::sr25519::AuthorityId as ImOnlineId;
|
||||
use pezpallet_revive::is_eth_derived;
|
||||
use pezsc_chain_spec::ChainSpecExtension;
|
||||
use pezsc_service::ChainType;
|
||||
use pezsc_service::Properties;
|
||||
use pezsc_telemetry::TelemetryEndpoints;
|
||||
use pezsp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
|
||||
use pezsp_consensus_babe::AuthorityId as BabeId;
|
||||
|
||||
@@ -39,7 +39,7 @@ serde = { workspace = true, default-features = true }
|
||||
serde_json = { workspace = true, default-features = true }
|
||||
|
||||
[dev-dependencies]
|
||||
# bizinikiwi-test-runtime = { workspace = true } # publish=false
|
||||
bizinikiwi-test-runtime = { workspace = true }
|
||||
cmd_lib = { workspace = true }
|
||||
pretty_assertions = { workspace = true }
|
||||
|
||||
@@ -47,7 +47,7 @@ pretty_assertions = { workspace = true }
|
||||
# `cargo build --feature=generate-readme` updates the `README.md` file.
|
||||
generate-readme = []
|
||||
runtime-benchmarks = [
|
||||
# "bizinikiwi-test-runtime/runtime-benchmarks",
|
||||
"bizinikiwi-test-runtime/runtime-benchmarks",
|
||||
"pezsc-chain-spec/runtime-benchmarks",
|
||||
]
|
||||
std = [
|
||||
|
||||
@@ -32,12 +32,18 @@ const DUMMY_PATH: &str = "fake-runtime-path";
|
||||
|
||||
const OUTPUT_FILE: &str = "/tmp/chain_spec_builder.test_output_file.json";
|
||||
|
||||
// Get the chain-spec-builder binary path from environment
|
||||
fn get_chain_spec_builder_bin() -> String {
|
||||
std::env::var("CARGO_BIN_EXE_chain-spec-builder")
|
||||
.expect("CARGO_BIN_EXE_chain-spec-builder must be set - run with `cargo test`")
|
||||
}
|
||||
|
||||
// Used for running commands visually pleasing in doc tests.
|
||||
macro_rules! bash(
|
||||
( chain-spec-builder $($a:tt)* ) => {{
|
||||
let bin_path = env!("CARGO_BIN_EXE_chain-spec-builder");
|
||||
let bin = get_chain_spec_builder_bin();
|
||||
spawn_with_output!(
|
||||
$bin_path $($a)*
|
||||
$bin $($a)*
|
||||
)
|
||||
.expect("a process running. qed")
|
||||
.wait_with_output()
|
||||
|
||||
@@ -36,12 +36,8 @@ enum Method {
|
||||
Compiled { instantiation_strategy: InstantiationStrategy, precompile: bool },
|
||||
}
|
||||
|
||||
// This is just a bog-standard Dicle runtime with an extra
|
||||
// `test_empty_return` and `test_dirty_plenty_memory` functions
|
||||
// copy-pasted from the test runtime.
|
||||
fn dicle_runtime() -> &'static [u8] {
|
||||
include_bytes!("dicle_runtime.wasm")
|
||||
}
|
||||
// Note: Production runtime benchmarking was removed because the WASM files
|
||||
// need to be pre-built. Use the test_runtime for benchmarking instead.
|
||||
|
||||
fn initialize(
|
||||
_tmpdir: &mut Option<tempfile::TempDir>,
|
||||
@@ -204,7 +200,7 @@ fn bench_call_instance(c: &mut Criterion) {
|
||||
),
|
||||
];
|
||||
|
||||
let runtimes = [("dicle_runtime", dicle_runtime()), ("test_runtime", test_runtime())];
|
||||
let runtimes = [("test_runtime", test_runtime())];
|
||||
|
||||
let thread_counts = [1, 2, 4, 8, 16];
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ xcm-builder = { workspace = true }
|
||||
[dev-dependencies]
|
||||
array-bytes = { workspace = true, default-features = true }
|
||||
assert_matches = { workspace = true }
|
||||
# pezpallet-contracts-fixtures = { workspace = true } # Commented for crates.io publish (test-only crate)
|
||||
pezpallet-contracts-fixtures = { workspace = true }
|
||||
pretty_assertions = { workspace = true }
|
||||
wat = { workspace = true }
|
||||
|
||||
@@ -103,7 +103,7 @@ runtime-benchmarks = [
|
||||
"pezframe-support/runtime-benchmarks",
|
||||
"pezframe-system/runtime-benchmarks",
|
||||
"pezpallet-balances/runtime-benchmarks",
|
||||
# "pezpallet-contracts-fixtures/runtime-benchmarks", # Commented for crates.io publish
|
||||
"pezpallet-contracts-fixtures/runtime-benchmarks",
|
||||
"pezpallet-insecure-randomness-collective-flip/runtime-benchmarks",
|
||||
"pezpallet-proxy/runtime-benchmarks",
|
||||
"pezpallet-timestamp/runtime-benchmarks",
|
||||
|
||||
@@ -36,9 +36,9 @@ serde = { features = ["alloc", "derive"], workspace = true }
|
||||
# Optional imports for benchmarking
|
||||
pezframe-benchmarking = { optional = true, workspace = true }
|
||||
|
||||
# bizinikiwi-test-utils moved to integration tests to break circular dependency
|
||||
[dev-dependencies]
|
||||
anyhow = { workspace = true }
|
||||
bizinikiwi-test-utils = { workspace = true }
|
||||
env_logger = { workspace = true }
|
||||
pezframe-benchmarking = { workspace = true, default-features = true }
|
||||
pezframe-support = { features = [
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[cfg(test)]
|
||||
use super::{Config, Runtime};
|
||||
#[cfg(test)]
|
||||
use crate::{derive_impl, pezpallet_prelude::inject_runtime_type};
|
||||
#[cfg(test)]
|
||||
use static_assertions::assert_type_eq_all;
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn derive_impl_works_with_runtime_type_injection() {
|
||||
assert_type_eq_all!(<Runtime as Config>::RuntimeOrigin, super::RuntimeOrigin);
|
||||
assert_type_eq_all!(<Runtime as Config>::RuntimeCall, super::RuntimeCall);
|
||||
assert_type_eq_all!(<Runtime as Config>::PalletInfo, super::PalletInfo);
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn derive_impl_works_with_no_aggregated_types() {
|
||||
struct DummyRuntime;
|
||||
|
||||
#[derive_impl(
|
||||
super::pezframe_system::config_preludes::TestDefaultConfig as super::pezframe_system::DefaultConfig,
|
||||
no_aggregated_types
|
||||
)]
|
||||
impl Config for DummyRuntime {
|
||||
type Block = super::Block;
|
||||
type AccountId = super::AccountId;
|
||||
type PalletInfo = super::PalletInfo;
|
||||
type ExampleConstant = ();
|
||||
}
|
||||
|
||||
assert_type_eq_all!(<DummyRuntime as Config>::RuntimeOrigin, ());
|
||||
assert_type_eq_all!(<DummyRuntime as Config>::RuntimeCall, ());
|
||||
}
|
||||
@@ -1,738 +0,0 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use pezframe_support::*;
|
||||
use pezframe_support_procedural::import_section;
|
||||
#[cfg(test)]
|
||||
use pezsp_io::{MultiRemovalResults, TestExternalities};
|
||||
#[cfg(test)]
|
||||
use pezsp_metadata_ir::{
|
||||
PalletStorageMetadataIR, StorageEntryMetadataIR, StorageEntryModifierIR, StorageEntryTypeIR,
|
||||
StorageHasherIR,
|
||||
};
|
||||
#[cfg(test)]
|
||||
use pezsp_runtime::BuildStorage;
|
||||
use pezsp_runtime::{generic, traits::BlakeTwo256};
|
||||
|
||||
pub use self::pezframe_system::{pezpallet_prelude::*, Config, Pezpallet};
|
||||
|
||||
mod inject_runtime_type;
|
||||
mod runtime;
|
||||
mod tasks;
|
||||
|
||||
#[import_section(tasks::tasks_example)]
|
||||
#[pezpallet]
|
||||
pub mod pezframe_system {
|
||||
#[allow(unused)]
|
||||
use super::{pezframe_system, pezframe_system::pezpallet_prelude::*};
|
||||
pub use crate::dispatch::RawOrigin;
|
||||
use crate::{pezpallet_prelude::*, traits::tasks::Task as TaskTrait};
|
||||
|
||||
pub mod config_preludes {
|
||||
use super::{inject_runtime_type, DefaultConfig};
|
||||
pub struct TestDefaultConfig;
|
||||
|
||||
#[crate::register_default_impl(TestDefaultConfig)]
|
||||
impl DefaultConfig for TestDefaultConfig {
|
||||
type AccountId = u64;
|
||||
type BaseCallFilter = pezframe_support::traits::Everything;
|
||||
#[inject_runtime_type]
|
||||
type RuntimeOrigin = ();
|
||||
#[inject_runtime_type]
|
||||
type RuntimeCall = ();
|
||||
#[inject_runtime_type]
|
||||
type PalletInfo = ();
|
||||
#[inject_runtime_type]
|
||||
type RuntimeTask = ();
|
||||
type DbWeight = ();
|
||||
}
|
||||
}
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pezpallet::config(with_default, pezframe_system_config)]
|
||||
#[pezpallet::disable_pezframe_system_supertrait_check]
|
||||
pub trait Config: 'static {
|
||||
#[pezpallet::no_default]
|
||||
type Block: Parameter + pezsp_runtime::traits::Block;
|
||||
type AccountId;
|
||||
#[pezpallet::no_default_bounds]
|
||||
type BaseCallFilter: crate::traits::Contains<Self::RuntimeCall>;
|
||||
#[pezpallet::no_default_bounds]
|
||||
type RuntimeOrigin;
|
||||
#[pezpallet::no_default_bounds]
|
||||
type RuntimeCall;
|
||||
#[pezpallet::no_default_bounds]
|
||||
type RuntimeTask: crate::traits::tasks::Task;
|
||||
#[pezpallet::no_default_bounds]
|
||||
type PalletInfo: crate::traits::PalletInfo;
|
||||
type DbWeight: Get<crate::weights::RuntimeDbWeight>;
|
||||
}
|
||||
|
||||
#[pezpallet::error]
|
||||
pub enum Error<T> {
|
||||
/// Required by construct_runtime
|
||||
CallFiltered,
|
||||
/// Used in tasks example.
|
||||
NotFound,
|
||||
/// The specified [`Task`] is not valid.
|
||||
InvalidTask,
|
||||
/// The specified [`Task`] failed during execution.
|
||||
FailedTask,
|
||||
}
|
||||
|
||||
#[pezpallet::origin]
|
||||
pub type Origin<T> = RawOrigin<<T as Config>::AccountId>;
|
||||
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
#[pezpallet::call_index(0)]
|
||||
#[pezpallet::weight(task.weight())]
|
||||
pub fn do_task(_origin: OriginFor<T>, task: T::RuntimeTask) -> DispatchResultWithPostInfo {
|
||||
if !task.is_valid() {
|
||||
return Err(Error::<T>::InvalidTask.into());
|
||||
}
|
||||
|
||||
if let Err(_err) = task.run() {
|
||||
return Err(Error::<T>::FailedTask.into());
|
||||
}
|
||||
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
|
||||
#[pezpallet::storage]
|
||||
pub type Data<T> = StorageMap<_, Twox64Concat, u32, u64, ValueQuery>;
|
||||
|
||||
#[pezpallet::storage]
|
||||
pub type OptionLinkedMap<T> = StorageMap<_, Blake2_128Concat, u32, u32, OptionQuery>;
|
||||
|
||||
#[pezpallet::storage]
|
||||
pub type GenericData<T: Config> =
|
||||
StorageMap<_, Identity, BlockNumberFor<T>, BlockNumberFor<T>, ValueQuery>;
|
||||
|
||||
#[pezpallet::storage]
|
||||
pub type GenericData2<T: Config> =
|
||||
StorageMap<_, Blake2_128Concat, BlockNumberFor<T>, BlockNumberFor<T>, OptionQuery>;
|
||||
|
||||
#[pezpallet::storage]
|
||||
pub type DataDM<T> =
|
||||
StorageDoubleMap<_, Twox64Concat, u32, Blake2_128Concat, u32, u64, ValueQuery>;
|
||||
|
||||
#[pezpallet::storage]
|
||||
pub type GenericDataDM<T: Config> = StorageDoubleMap<
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
BlockNumberFor<T>,
|
||||
Identity,
|
||||
BlockNumberFor<T>,
|
||||
BlockNumberFor<T>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[pezpallet::storage]
|
||||
pub type GenericData2DM<T: Config> = StorageDoubleMap<
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
BlockNumberFor<T>,
|
||||
Twox64Concat,
|
||||
BlockNumberFor<T>,
|
||||
BlockNumberFor<T>,
|
||||
OptionQuery,
|
||||
>;
|
||||
|
||||
#[pezpallet::storage]
|
||||
#[pezpallet::unbounded]
|
||||
pub type AppendableDM<T: Config> = StorageDoubleMap<
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
u32,
|
||||
Blake2_128Concat,
|
||||
BlockNumberFor<T>,
|
||||
Vec<u32>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[pezpallet::genesis_config]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
pub data: Vec<(u32, u64)>,
|
||||
pub test_config: Vec<(u32, u32, u64)>,
|
||||
#[serde(skip)]
|
||||
pub _config: core::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: Config> Default for GenesisConfig<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
_config: Default::default(),
|
||||
data: vec![(15u32, 42u64)],
|
||||
test_config: vec![(15u32, 16u32, 42u64)],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pezpallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {
|
||||
for (k, v) in &self.data {
|
||||
<Data<T>>::insert(k, v);
|
||||
}
|
||||
for (k1, k2, v) in &self.test_config {
|
||||
<DataDM<T>>::insert(k1, k2, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Some running total.
|
||||
#[pezpallet::storage]
|
||||
pub type Total<T: Config> = StorageValue<_, (u32, u32), ValueQuery>;
|
||||
|
||||
/// Numbers to be added into the total.
|
||||
#[pezpallet::storage]
|
||||
pub type Numbers<T: Config> = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>;
|
||||
|
||||
pub mod pezpallet_prelude {
|
||||
pub type OriginFor<T> = <T as super::Config>::RuntimeOrigin;
|
||||
|
||||
pub type HeaderFor<T> =
|
||||
<<T as super::Config>::Block as pezsp_runtime::traits::HeaderProvider>::HeaderT;
|
||||
|
||||
pub type BlockNumberFor<T> = <HeaderFor<T> as pezsp_runtime::traits::Header>::Number;
|
||||
}
|
||||
}
|
||||
|
||||
type BlockNumber = u32;
|
||||
type AccountId = u32;
|
||||
type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, RuntimeCall, (), ()>;
|
||||
type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
|
||||
#[crate::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(
|
||||
RuntimeCall,
|
||||
RuntimeEvent,
|
||||
RuntimeError,
|
||||
RuntimeOrigin,
|
||||
RuntimeFreezeReason,
|
||||
RuntimeHoldReason,
|
||||
RuntimeSlashReason,
|
||||
RuntimeLockId,
|
||||
RuntimeTask,
|
||||
RuntimeViewFunction
|
||||
)]
|
||||
pub struct Runtime;
|
||||
|
||||
#[runtime::pezpallet_index(0)]
|
||||
pub type System = self::pezframe_system;
|
||||
}
|
||||
|
||||
#[crate::derive_impl(self::pezframe_system::config_preludes::TestDefaultConfig as self::pezframe_system::DefaultConfig)]
|
||||
impl Config for Runtime {
|
||||
type Block = Block;
|
||||
type AccountId = AccountId;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn new_test_ext() -> TestExternalities {
|
||||
RuntimeGenesisConfig::default().build_storage().unwrap().into()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
trait Sorted {
|
||||
fn sorted(self) -> Self;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<T: Ord> Sorted for Vec<T> {
|
||||
fn sorted(mut self) -> Self {
|
||||
self.sort();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_issue_3318() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type OptionLinkedMap = self::pezframe_system::OptionLinkedMap<Runtime>;
|
||||
|
||||
OptionLinkedMap::insert(1, 1);
|
||||
assert_eq!(OptionLinkedMap::get(1), Some(1));
|
||||
OptionLinkedMap::insert(1, 2);
|
||||
assert_eq!(OptionLinkedMap::get(1), Some(2));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_swap_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type OptionLinkedMap = self::pezframe_system::OptionLinkedMap<Runtime>;
|
||||
|
||||
OptionLinkedMap::insert(0, 0);
|
||||
OptionLinkedMap::insert(1, 1);
|
||||
OptionLinkedMap::insert(2, 2);
|
||||
OptionLinkedMap::insert(3, 3);
|
||||
|
||||
let collect = || OptionLinkedMap::iter().collect::<Vec<_>>().sorted();
|
||||
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
|
||||
|
||||
// Two existing
|
||||
OptionLinkedMap::swap(1, 2);
|
||||
assert_eq!(collect(), vec![(0, 0), (1, 2), (2, 1), (3, 3)]);
|
||||
|
||||
// Back to normal
|
||||
OptionLinkedMap::swap(2, 1);
|
||||
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
|
||||
|
||||
// Left existing
|
||||
OptionLinkedMap::swap(2, 5);
|
||||
assert_eq!(collect(), vec![(0, 0), (1, 1), (3, 3), (5, 2)]);
|
||||
|
||||
// Right existing
|
||||
OptionLinkedMap::swap(5, 2);
|
||||
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_map_swap_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type DataDM = self::pezframe_system::DataDM<Runtime>;
|
||||
|
||||
DataDM::insert(0, 1, 1);
|
||||
DataDM::insert(1, 0, 2);
|
||||
DataDM::insert(1, 1, 3);
|
||||
|
||||
let get_all = || {
|
||||
vec![
|
||||
DataDM::get(0, 1),
|
||||
DataDM::get(1, 0),
|
||||
DataDM::get(1, 1),
|
||||
DataDM::get(2, 0),
|
||||
DataDM::get(2, 1),
|
||||
]
|
||||
};
|
||||
assert_eq!(get_all(), vec![1, 2, 3, 0, 0]);
|
||||
|
||||
// Two existing
|
||||
DataDM::swap(0, 1, 1, 0);
|
||||
assert_eq!(get_all(), vec![2, 1, 3, 0, 0]);
|
||||
|
||||
// Left existing
|
||||
DataDM::swap(1, 0, 2, 0);
|
||||
assert_eq!(get_all(), vec![2, 0, 3, 1, 0]);
|
||||
|
||||
// Right existing
|
||||
DataDM::swap(2, 1, 1, 1);
|
||||
assert_eq!(get_all(), vec![2, 0, 0, 1, 3]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_basic_insert_remove_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type Map = self::pezframe_system::Data<Runtime>;
|
||||
|
||||
// initialized during genesis
|
||||
assert_eq!(Map::get(&15u32), 42u64);
|
||||
|
||||
// get / insert / take
|
||||
let key = 17u32;
|
||||
assert_eq!(Map::get(&key), 0u64);
|
||||
Map::insert(key, 4u64);
|
||||
assert_eq!(Map::get(&key), 4u64);
|
||||
assert_eq!(Map::take(&key), 4u64);
|
||||
assert_eq!(Map::get(&key), 0u64);
|
||||
|
||||
// mutate
|
||||
Map::mutate(&key, |val| {
|
||||
*val = 15;
|
||||
});
|
||||
assert_eq!(Map::get(&key), 15u64);
|
||||
|
||||
// remove
|
||||
Map::remove(&key);
|
||||
assert_eq!(Map::get(&key), 0u64);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_iteration_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type Map = self::pezframe_system::Data<Runtime>;
|
||||
|
||||
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(15, 42)]);
|
||||
// insert / remove
|
||||
let key = 17u32;
|
||||
Map::insert(key, 4u64);
|
||||
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(15, 42), (key, 4)]);
|
||||
assert_eq!(Map::take(&15), 42u64);
|
||||
assert_eq!(Map::take(&key), 4u64);
|
||||
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![]);
|
||||
|
||||
// Add couple of more elements
|
||||
Map::insert(key, 42u64);
|
||||
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key, 42)]);
|
||||
Map::insert(key + 1, 43u64);
|
||||
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key, 42), (key + 1, 43)]);
|
||||
|
||||
// mutate
|
||||
let key = key + 2;
|
||||
Map::mutate(&key, |val| {
|
||||
*val = 15;
|
||||
});
|
||||
assert_eq!(
|
||||
Map::iter().collect::<Vec<_>>().sorted(),
|
||||
vec![(key - 2, 42), (key - 1, 43), (key, 15)]
|
||||
);
|
||||
Map::mutate(&key, |val| {
|
||||
*val = 17;
|
||||
});
|
||||
assert_eq!(
|
||||
Map::iter().collect::<Vec<_>>().sorted(),
|
||||
vec![(key - 2, 42), (key - 1, 43), (key, 17)]
|
||||
);
|
||||
|
||||
// remove first
|
||||
Map::remove(&key);
|
||||
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 2, 42), (key - 1, 43)]);
|
||||
|
||||
// remove last from the list
|
||||
Map::remove(&(key - 2));
|
||||
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 1, 43)]);
|
||||
|
||||
// remove the last element
|
||||
Map::remove(&(key - 1));
|
||||
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_map_basic_insert_remove_remove_prefix_with_commit_should_work() {
|
||||
let key1 = 17u32;
|
||||
let key2 = 18u32;
|
||||
type DoubleMap = self::pezframe_system::DataDM<Runtime>;
|
||||
let mut e = new_test_ext();
|
||||
e.execute_with(|| {
|
||||
// initialized during genesis
|
||||
assert_eq!(DoubleMap::get(&15u32, &16u32), 42u64);
|
||||
|
||||
// get / insert / take
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
||||
DoubleMap::insert(&key1, &key2, &4u64);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 4u64);
|
||||
assert_eq!(DoubleMap::take(&key1, &key2), 4u64);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
||||
|
||||
// mutate
|
||||
DoubleMap::mutate(&key1, &key2, |val| *val = 15);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 15u64);
|
||||
|
||||
// remove
|
||||
DoubleMap::remove(&key1, &key2);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
||||
|
||||
// remove prefix
|
||||
DoubleMap::insert(&key1, &key2, &4u64);
|
||||
DoubleMap::insert(&key1, &(key2 + 1), &4u64);
|
||||
DoubleMap::insert(&(key1 + 1), &key2, &4u64);
|
||||
DoubleMap::insert(&(key1 + 1), &(key2 + 1), &4u64);
|
||||
});
|
||||
e.commit_all().unwrap();
|
||||
e.execute_with(|| {
|
||||
assert!(matches!(
|
||||
DoubleMap::clear_prefix(&key1, u32::max_value(), None),
|
||||
MultiRemovalResults { maybe_cursor: None, backend: 2, unique: 2, loops: 2 }
|
||||
));
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
||||
assert_eq!(DoubleMap::get(&key1, &(key2 + 1)), 0u64);
|
||||
assert_eq!(DoubleMap::get(&(key1 + 1), &key2), 4u64);
|
||||
assert_eq!(DoubleMap::get(&(key1 + 1), &(key2 + 1)), 4u64);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_map_basic_insert_remove_remove_prefix_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let key1 = 17u32;
|
||||
let key2 = 18u32;
|
||||
type DoubleMap = self::pezframe_system::DataDM<Runtime>;
|
||||
|
||||
// initialized during genesis
|
||||
assert_eq!(DoubleMap::get(&15u32, &16u32), 42u64);
|
||||
|
||||
// get / insert / take
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
||||
DoubleMap::insert(&key1, &key2, &4u64);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 4u64);
|
||||
assert_eq!(DoubleMap::take(&key1, &key2), 4u64);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
||||
|
||||
// mutate
|
||||
DoubleMap::mutate(&key1, &key2, |val| *val = 15);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 15u64);
|
||||
|
||||
// remove
|
||||
DoubleMap::remove(&key1, &key2);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
||||
|
||||
// remove prefix
|
||||
DoubleMap::insert(&key1, &key2, &4u64);
|
||||
DoubleMap::insert(&key1, &(key2 + 1), &4u64);
|
||||
DoubleMap::insert(&(key1 + 1), &key2, &4u64);
|
||||
DoubleMap::insert(&(key1 + 1), &(key2 + 1), &4u64);
|
||||
// all in overlay
|
||||
assert!(matches!(
|
||||
DoubleMap::clear_prefix(&key1, u32::max_value(), None),
|
||||
MultiRemovalResults { maybe_cursor: None, backend: 0, unique: 0, loops: 0 }
|
||||
));
|
||||
// Note this is the incorrect answer (for now), since we are using v2 of
|
||||
// `clear_prefix`.
|
||||
// When we switch to v3, then this will become:
|
||||
// MultiRemovalResults:: { maybe_cursor: None, backend: 0, unique: 2, loops: 2 },
|
||||
assert!(matches!(
|
||||
DoubleMap::clear_prefix(&key1, u32::max_value(), None),
|
||||
MultiRemovalResults { maybe_cursor: None, backend: 0, unique: 0, loops: 0 }
|
||||
));
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
||||
assert_eq!(DoubleMap::get(&key1, &(key2 + 1)), 0u64);
|
||||
assert_eq!(DoubleMap::get(&(key1 + 1), &key2), 4u64);
|
||||
assert_eq!(DoubleMap::get(&(key1 + 1), &(key2 + 1)), 4u64);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_map_append_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type DoubleMap = self::pezframe_system::AppendableDM<Runtime>;
|
||||
|
||||
let key1 = 17u32;
|
||||
let key2 = 18u32;
|
||||
|
||||
DoubleMap::insert(&key1, &key2, &vec![1]);
|
||||
DoubleMap::append(&key1, &key2, 2);
|
||||
assert_eq!(DoubleMap::get(&key1, &key2), &[1, 2]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_map_mutate_exists_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type DoubleMap = self::pezframe_system::DataDM<Runtime>;
|
||||
|
||||
let (key1, key2) = (11, 13);
|
||||
|
||||
// mutated
|
||||
DoubleMap::mutate_exists(key1, key2, |v| *v = Some(1));
|
||||
assert_eq!(DoubleMap::get(&key1, key2), 1);
|
||||
|
||||
// removed if mutated to `None`
|
||||
DoubleMap::mutate_exists(key1, key2, |v| *v = None);
|
||||
assert!(!DoubleMap::contains_key(&key1, key2));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_map_try_mutate_exists_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type DoubleMap = self::pezframe_system::DataDM<Runtime>;
|
||||
type TestResult = Result<(), &'static str>;
|
||||
|
||||
let (key1, key2) = (11, 13);
|
||||
|
||||
// mutated if `Ok`
|
||||
assert_ok!(DoubleMap::try_mutate_exists(key1, key2, |v| -> TestResult {
|
||||
*v = Some(1);
|
||||
Ok(())
|
||||
}));
|
||||
assert_eq!(DoubleMap::get(&key1, key2), 1);
|
||||
|
||||
// no-op if `Err`
|
||||
assert_noop!(
|
||||
DoubleMap::try_mutate_exists(key1, key2, |v| -> TestResult {
|
||||
*v = Some(2);
|
||||
Err("nah")
|
||||
}),
|
||||
"nah"
|
||||
);
|
||||
|
||||
// removed if mutated to`None`
|
||||
assert_ok!(DoubleMap::try_mutate_exists(key1, key2, |v| -> TestResult {
|
||||
*v = None;
|
||||
Ok(())
|
||||
}));
|
||||
assert!(!DoubleMap::contains_key(&key1, key2));
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn expected_metadata() -> PalletStorageMetadataIR {
|
||||
PalletStorageMetadataIR {
|
||||
prefix: "System",
|
||||
entries: vec![
|
||||
StorageEntryMetadataIR {
|
||||
name: "Data",
|
||||
modifier: StorageEntryModifierIR::Default,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![StorageHasherIR::Twox64Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u64>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "OptionLinkedMap",
|
||||
modifier: StorageEntryModifierIR::Optional,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![StorageHasherIR::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "GenericData",
|
||||
modifier: StorageEntryModifierIR::Default,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![StorageHasherIR::Identity],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "GenericData2",
|
||||
modifier: StorageEntryModifierIR::Optional,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![StorageHasherIR::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "DataDM",
|
||||
modifier: StorageEntryModifierIR::Default,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![StorageHasherIR::Twox64Concat, StorageHasherIR::Blake2_128Concat],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<u64>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "GenericDataDM",
|
||||
modifier: StorageEntryModifierIR::Default,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![StorageHasherIR::Blake2_128Concat, StorageHasherIR::Identity],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0, 0, 0, 0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "GenericData2DM",
|
||||
modifier: StorageEntryModifierIR::Optional,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![StorageHasherIR::Blake2_128Concat, StorageHasherIR::Twox64Concat],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "AppendableDM",
|
||||
modifier: StorageEntryModifierIR::Default,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![
|
||||
StorageHasherIR::Blake2_128Concat,
|
||||
StorageHasherIR::Blake2_128Concat,
|
||||
],
|
||||
key: scale_info::meta_type::<(u32, u32)>(),
|
||||
value: scale_info::meta_type::<Vec<u32>>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "Total",
|
||||
modifier: StorageEntryModifierIR::Default,
|
||||
ty: StorageEntryTypeIR::Plain(scale_info::meta_type::<(u32, u32)>()),
|
||||
default: vec![0, 0, 0, 0, 0, 0, 0, 0],
|
||||
docs: vec![" Some running total."],
|
||||
},
|
||||
StorageEntryMetadataIR {
|
||||
name: "Numbers",
|
||||
modifier: StorageEntryModifierIR::Optional,
|
||||
ty: StorageEntryTypeIR::Map {
|
||||
hashers: vec![StorageHasherIR::Twox64Concat],
|
||||
key: scale_info::meta_type::<u32>(),
|
||||
value: scale_info::meta_type::<u32>(),
|
||||
},
|
||||
default: vec![0],
|
||||
docs: vec![" Numbers to be added into the total."],
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn store_metadata() {
|
||||
let metadata = Pezpallet::<Runtime>::storage_metadata();
|
||||
pretty_assertions::assert_eq!(expected_metadata(), metadata);
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
storage StorageParameter: u64 = 10;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_storage_parameter_type_works() {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
assert_eq!(pezsp_io::hashing::twox_128(b":StorageParameter:"), StorageParameter::key());
|
||||
|
||||
assert_eq!(10, StorageParameter::get());
|
||||
|
||||
StorageParameter::set(&300);
|
||||
assert_eq!(300, StorageParameter::get());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derive_partial_eq_no_bound_core_mod() {
|
||||
mod core {}
|
||||
|
||||
#[derive(
|
||||
crate::PartialEqNoBound,
|
||||
crate::CloneNoBound,
|
||||
crate::DebugNoBound,
|
||||
crate::DefaultNoBound,
|
||||
crate::EqNoBound,
|
||||
)]
|
||||
struct Test;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -1,133 +0,0 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#![allow(deprecated, clippy::deprecated_semver)]
|
||||
|
||||
use super::{pezframe_system, Block};
|
||||
use crate::derive_impl;
|
||||
|
||||
#[crate::pezpallet(dev_mode)]
|
||||
mod pezpallet_basic {
|
||||
use super::pezframe_system;
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
}
|
||||
|
||||
impl pezpallet_basic::Config for Runtime {}
|
||||
|
||||
#[crate::pezpallet(dev_mode)]
|
||||
mod pezpallet_with_disabled_call {
|
||||
use super::pezframe_system;
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
}
|
||||
|
||||
impl pezpallet_with_disabled_call::Config for Runtime {}
|
||||
|
||||
#[crate::pezpallet(dev_mode)]
|
||||
mod pezpallet_with_disabled_unsigned {
|
||||
use super::pezframe_system;
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
}
|
||||
|
||||
impl pezpallet_with_disabled_unsigned::Config for Runtime {}
|
||||
|
||||
#[crate::pezpallet]
|
||||
mod pezpallet_with_instance {
|
||||
use super::pezframe_system;
|
||||
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T, I = ()>(_);
|
||||
|
||||
#[pezpallet::config]
|
||||
pub trait Config<I: 'static = ()>: pezframe_system::Config {}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
type Instance1 = pezpallet_with_instance::Pezpallet<pezpallet_with_instance::Instance1>;
|
||||
|
||||
impl pezpallet_with_instance::Config<pezpallet_with_instance::Instance1> for Runtime {}
|
||||
|
||||
#[allow(unused)]
|
||||
type Instance2 = pezpallet_with_instance::Pezpallet<pezpallet_with_instance::Instance2>;
|
||||
|
||||
impl pezpallet_with_instance::Config<pezpallet_with_instance::Instance2> for Runtime {}
|
||||
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Runtime {
|
||||
type Block = Block;
|
||||
}
|
||||
|
||||
#[docify::export(runtime_macro)]
|
||||
#[crate::runtime]
|
||||
mod runtime {
|
||||
// The main runtime
|
||||
#[runtime::runtime]
|
||||
// Runtime Types to be generated
|
||||
#[runtime::derive(
|
||||
RuntimeCall,
|
||||
RuntimeEvent,
|
||||
RuntimeError,
|
||||
RuntimeOrigin,
|
||||
RuntimeFreezeReason,
|
||||
RuntimeHoldReason,
|
||||
RuntimeSlashReason,
|
||||
RuntimeLockId,
|
||||
RuntimeTask,
|
||||
RuntimeViewFunction
|
||||
)]
|
||||
pub struct Runtime;
|
||||
|
||||
// Use the concrete pezpallet type
|
||||
#[runtime::pezpallet_index(0)]
|
||||
pub type System = pezframe_system::Pezpallet<Runtime>;
|
||||
|
||||
// Use path to the pezpallet
|
||||
#[runtime::pezpallet_index(1)]
|
||||
pub type Basic = pezpallet_basic;
|
||||
|
||||
// Use the concrete pezpallet type with instance
|
||||
#[runtime::pezpallet_index(2)]
|
||||
pub type PalletWithInstance1 = pezpallet_with_instance::Pezpallet<Runtime, Instance1>;
|
||||
|
||||
// Use path to the pezpallet with instance
|
||||
#[runtime::pezpallet_index(3)]
|
||||
pub type PalletWithInstance2 = pezpallet_with_instance<Instance2>;
|
||||
|
||||
// Ensure that the runtime does not export the calls from the pezpallet
|
||||
#[runtime::pezpallet_index(4)]
|
||||
#[runtime::disable_call]
|
||||
#[deprecated = "example"]
|
||||
pub type PalletWithDisabledCall = pezpallet_with_disabled_call::Pezpallet<Runtime>;
|
||||
|
||||
// Ensure that the runtime does not export the unsigned calls from the pezpallet
|
||||
#[runtime::pezpallet_index(5)]
|
||||
#[runtime::disable_unsigned]
|
||||
pub type PalletWithDisabledUnsigned = pezpallet_with_disabled_unsigned::Pezpallet<Runtime>;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[cfg(test)]
|
||||
use super::{
|
||||
assert_ok,
|
||||
pezframe_system::{Numbers, Total},
|
||||
Runtime, RuntimeOrigin, RuntimeTask, System,
|
||||
};
|
||||
use pezframe_support_procedural::pezpallet_section;
|
||||
|
||||
#[pezpallet_section]
|
||||
mod tasks_example {
|
||||
#[docify::export(tasks_example)]
|
||||
#[pezpallet::tasks_experimental]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// Add a pair of numbers into the totals and remove them.
|
||||
#[pezpallet::task_list(Numbers::<T>::iter_keys())]
|
||||
#[pezpallet::task_condition(|i| Numbers::<T>::contains_key(i))]
|
||||
#[pezpallet::task_weight(0.into())]
|
||||
#[pezpallet::task_index(0)]
|
||||
pub fn add_number_into_total(i: u32) -> DispatchResult {
|
||||
let v = Numbers::<T>::take(i).ok_or(Error::<T>::NotFound)?;
|
||||
Total::<T>::mutate(|(total_keys, total_values)| {
|
||||
*total_keys += i;
|
||||
*total_values += v;
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn tasks_work() {
|
||||
super::new_test_ext().execute_with(|| {
|
||||
Numbers::<Runtime>::insert(0, 1);
|
||||
|
||||
let task =
|
||||
RuntimeTask::System(super::pezframe_system::Task::<Runtime>::AddNumberIntoTotal {
|
||||
i: 0u32,
|
||||
});
|
||||
|
||||
assert_ok!(System::do_task(RuntimeOrigin::signed(1), task.clone(),));
|
||||
assert_eq!(Numbers::<Runtime>::get(0), None);
|
||||
assert_eq!(Total::<Runtime>::get(), (0, 1));
|
||||
});
|
||||
}
|
||||
@@ -810,12 +810,10 @@ pub fn register_default_impl(attrs: TokenStream, tokens: TokenStream) -> TokenSt
|
||||
/// Attaching this attribute to such an item ensures that the combined impl generated via
|
||||
/// [`#[derive_impl(..)]`](macro@derive_impl) will use the correct type auto-generated by
|
||||
/// `construct_runtime!`.
|
||||
#[doc = docify::embed!("examples/proc_main/inject_runtime_type.rs", derive_impl_works_with_runtime_type_injection)]
|
||||
///
|
||||
/// However, if `no_aggregated_types` is specified while using
|
||||
/// [`#[derive_impl(..)]`](macro@derive_impl), then these items are attached verbatim to the
|
||||
/// combined impl.
|
||||
#[doc = docify::embed!("examples/proc_main/inject_runtime_type.rs", derive_impl_works_with_no_aggregated_types)]
|
||||
#[proc_macro_attribute]
|
||||
pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream {
|
||||
let item = tokens.clone();
|
||||
@@ -1162,9 +1160,8 @@ pub fn composite_enum(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
/// When submitted as unsigned transactions, note that the tasks will be executed in a random order.
|
||||
///
|
||||
/// ## Example
|
||||
#[doc = docify::embed!("examples/proc_main/tasks.rs", tasks_example)]
|
||||
/// Now, this can be executed as follows:
|
||||
#[doc = docify::embed!("examples/proc_main/tasks.rs", tasks_work)]
|
||||
///
|
||||
/// See the `tasks` module in `pezframe-support` for usage examples.
|
||||
#[proc_macro_attribute]
|
||||
pub fn tasks_experimental(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pezpallet_macro_stub()
|
||||
@@ -1292,7 +1289,8 @@ pub fn import_section(attr: TokenStream, tokens: TokenStream) -> TokenStream {
|
||||
/// Construct a runtime, with the given name and the given pallets.
|
||||
///
|
||||
/// # Example:
|
||||
#[doc = docify::embed!("examples/proc_main/runtime.rs", runtime_macro)]
|
||||
///
|
||||
/// See runtime construction examples in the `pezkuwi-sdk` documentation.
|
||||
///
|
||||
/// # Supported Attributes:
|
||||
///
|
||||
|
||||
@@ -24,8 +24,8 @@ clap = { features = ["derive"], workspace = true }
|
||||
codec = { workspace = true, default-features = true }
|
||||
comfy-table = { workspace = true }
|
||||
env_filter = { workspace = true }
|
||||
# frame-storage-access-test-runtime moved to integration tests to break circular dependency
|
||||
gethostname = { workspace = true }
|
||||
pezframe-storage-access-test-runtime = { workspace = true, optional = true }
|
||||
handlebars = { workspace = true }
|
||||
itertools = { workspace = true }
|
||||
linked-hash-map = { workspace = true }
|
||||
@@ -81,22 +81,21 @@ thiserror = { workspace = true }
|
||||
thousands = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
# bizinikiwi-test-runtime = { workspace = true, default-features = true }
|
||||
# pezcumulus-test-runtime = { workspace = true, default-features = true }
|
||||
# zagros-runtime = { workspace = true, default-features = true }
|
||||
bizinikiwi-test-runtime = { workspace = true, default-features = true }
|
||||
pezcumulus-test-runtime = { workspace = true, default-features = true }
|
||||
zagros-runtime = { workspace = true, default-features = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
# Enable storage benchmark command (requires frame-storage-access-test-runtime)
|
||||
storage-benchmark = []
|
||||
# Enable storage benchmark command
|
||||
storage-benchmark = ["pezframe-storage-access-test-runtime"]
|
||||
# Enable teyrchain/parachain benchmark inherent data
|
||||
# Note: requires pezcumulus-client-teyrchain-inherent with mock feature (needs pezcumulus-test-relay-sproof-builder)
|
||||
teyrchain-benchmarks = []
|
||||
teyrchain-benchmarks = ["pezcumulus-client-teyrchain-inherent/mock"]
|
||||
runtime-benchmarks = [
|
||||
# "bizinikiwi-test-runtime/runtime-benchmarks",
|
||||
"bizinikiwi-test-runtime/runtime-benchmarks",
|
||||
"pezcumulus-client-teyrchain-inherent/runtime-benchmarks",
|
||||
"pezcumulus-primitives-proof-size-hostfunction/runtime-benchmarks",
|
||||
# "pezcumulus-test-runtime/runtime-benchmarks",
|
||||
"pezcumulus-test-runtime/runtime-benchmarks",
|
||||
"pezframe-benchmarking/runtime-benchmarks",
|
||||
"pezframe-support/runtime-benchmarks",
|
||||
"pezframe-system/runtime-benchmarks",
|
||||
@@ -127,7 +126,7 @@ runtime-benchmarks = [
|
||||
"pezsp-transaction-pool/runtime-benchmarks",
|
||||
"pezsp-trie/runtime-benchmarks",
|
||||
"pezsp-version/runtime-benchmarks",
|
||||
# "zagros-runtime/runtime-benchmarks", # Not a dependency of this crate
|
||||
"zagros-runtime/runtime-benchmarks",
|
||||
]
|
||||
rocksdb = ["pezsc-cli/rocksdb", "pezsc-client-db/rocksdb"]
|
||||
std = [
|
||||
|
||||
@@ -28,7 +28,7 @@ pub(crate) const MAX_BATCH_SIZE_FOR_BLOCK_VALIDATION: usize = 10_000;
|
||||
|
||||
pub(crate) fn get_wasm_module() -> Box<dyn pezsc_executor_common::wasm_runtime::WasmModule> {
|
||||
let blob = pezsc_executor_common::runtime_blob::RuntimeBlob::uncompress_if_needed(
|
||||
frame_storage_access_test_runtime::WASM_BINARY
|
||||
pezframe_storage_access_test_runtime::WASM_BINARY
|
||||
.expect("You need to build the WASM binaries to run the benchmark!"),
|
||||
)
|
||||
.expect("Failed to create runtime blob");
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
use codec::Encode;
|
||||
use frame_storage_access_test_runtime::StorageAccessParams;
|
||||
use log::{debug, info};
|
||||
use pezframe_storage_access_test_runtime::StorageAccessParams;
|
||||
use pezsc_cli::{Error, Result};
|
||||
use pezsc_client_api::{Backend as ClientBackend, StorageProvider, UsageProvider};
|
||||
use pezsp_api::CallApiAt;
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
use codec::Encode;
|
||||
use frame_storage_access_test_runtime::StorageAccessParams;
|
||||
use log::{debug, info, trace, warn};
|
||||
use pezframe_storage_access_test_runtime::StorageAccessParams;
|
||||
use pezsc_cli::Result;
|
||||
use pezsc_client_api::{Backend as ClientBackend, StorageProvider, UsageProvider};
|
||||
use pezsc_client_db::{DbHash, DbState, DbStateBuilder};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "frame-storage-access-test-runtime"
|
||||
name = "pezframe-storage-access-test-runtime"
|
||||
description = "A runtime for testing storage access on block validation"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
|
||||
Reference in New Issue
Block a user