feat: initialize Kurdistan SDK - independent fork of Polkadot SDK
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
[package]
|
||||
name = "pallet-dev-mode"
|
||||
version = "10.0.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license = "MIT-0"
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
description = "FRAME example pallet"
|
||||
readme = "README.md"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
codec = { workspace = true }
|
||||
frame-support = { workspace = true }
|
||||
frame-system = { workspace = true }
|
||||
log = { workspace = true }
|
||||
pallet-balances = { workspace = true }
|
||||
scale-info = { features = ["derive"], workspace = true }
|
||||
sp-io = { workspace = true }
|
||||
sp-runtime = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
sp-core = { workspace = true }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"codec/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"log/std",
|
||||
"pallet-balances/std",
|
||||
"scale-info/std",
|
||||
"sp-core/std",
|
||||
"sp-io/std",
|
||||
"sp-runtime/std",
|
||||
]
|
||||
try-runtime = [
|
||||
"frame-support/try-runtime",
|
||||
"frame-system/try-runtime",
|
||||
"pallet-balances/try-runtime",
|
||||
"sp-runtime/try-runtime",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"frame-support/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
"sp-io/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
]
|
||||
@@ -0,0 +1,11 @@
|
||||
<!-- markdown-link-check-disable -->
|
||||
# Dev Mode Example Pallet
|
||||
|
||||
A simple example of a FRAME pallet demonstrating
|
||||
the ease of requirements for a pallet in dev mode.
|
||||
|
||||
Run `cargo doc --package pallet-dev-mode --open` to view this pallet's documentation.
|
||||
|
||||
**Dev mode is not meant to be used in production.**
|
||||
|
||||
License: MIT-0
|
||||
@@ -0,0 +1,124 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: MIT-0
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! <!-- markdown-link-check-disable -->
|
||||
//! # Dev Mode Example Pallet
|
||||
//!
|
||||
//! A simple example of a FRAME pallet demonstrating
|
||||
//! the ease of requirements for a pallet in dev mode.
|
||||
//!
|
||||
//! Run `cargo doc --package pallet-dev-mode --open` to view this pallet's documentation.
|
||||
//!
|
||||
//! **Dev mode is not meant to be used in production.**
|
||||
|
||||
// Ensure we're `no_std` when compiling for Wasm.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::{vec, vec::Vec};
|
||||
use frame_support::dispatch::DispatchResult;
|
||||
use frame_system::ensure_signed;
|
||||
|
||||
// Re-export pallet items so that they can be accessed from the crate namespace.
|
||||
pub use pallet::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
/// A type alias for the balance type from this pallet's point of view.
|
||||
type BalanceOf<T> = <T as pallet_balances::Config>::Balance;
|
||||
|
||||
/// Enable `dev_mode` for this pallet.
|
||||
#[frame_support::pallet(dev_mode)]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: pallet_balances::Config + frame_system::Config {}
|
||||
|
||||
// Simple declaration of the `Pallet` type. It is placeholder we use to implement traits and
|
||||
// method.
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
// No need to define a `call_index` attribute here because of `dev_mode`.
|
||||
// No need to define a `weight` attribute here because of `dev_mode`.
|
||||
pub fn add_dummy(origin: OriginFor<T>, id: T::AccountId) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
|
||||
if let Some(mut dummies) = Dummy::<T>::get() {
|
||||
dummies.push(id.clone());
|
||||
Dummy::<T>::set(Some(dummies));
|
||||
} else {
|
||||
Dummy::<T>::set(Some(vec![id.clone()]));
|
||||
}
|
||||
|
||||
// Let's deposit an event to let the outside world know this happened.
|
||||
Self::deposit_event(Event::AddDummy { account: id });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// No need to define a `call_index` attribute here because of `dev_mode`.
|
||||
// No need to define a `weight` attribute here because of `dev_mode`.
|
||||
pub fn set_bar(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] new_value: T::Balance,
|
||||
) -> DispatchResult {
|
||||
let sender = ensure_signed(origin)?;
|
||||
|
||||
// Put the new value into storage.
|
||||
<Bar<T>>::insert(&sender, new_value);
|
||||
|
||||
Self::deposit_event(Event::SetBar { account: sender, balance: new_value });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
AddDummy { account: T::AccountId },
|
||||
SetBar { account: T::AccountId, balance: BalanceOf<T> },
|
||||
}
|
||||
|
||||
/// The MEL requirement for bounded pallets is skipped by `dev_mode`.
|
||||
/// This means that all storages are marked as unbounded.
|
||||
/// This is equivalent to specifying `#[pallet::unbounded]` on this type definitions.
|
||||
/// When the dev_mode is removed, we would need to implement implement `MaxEncodedLen`.
|
||||
#[pallet::storage]
|
||||
pub type Dummy<T: Config> = StorageValue<_, Vec<T::AccountId>>;
|
||||
|
||||
/// The Hasher requirement is skipped by `dev_mode`. So, second parameter can be `_`
|
||||
/// and `Blake2_128Concat` is used as a default.
|
||||
/// When the dev_mode is removed, we would need to specify the hasher like so:
|
||||
/// `pub type Bar<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance>;`.
|
||||
#[pallet::storage]
|
||||
pub type Bar<T: Config> = StorageMap<_, _, T::AccountId, T::Balance>;
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: MIT-0
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
//! Tests for pallet-dev-mode.
|
||||
|
||||
use crate::*;
|
||||
use frame_support::{assert_ok, derive_impl};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
BuildStorage,
|
||||
};
|
||||
// Reexport crate as its pallet name for construct_runtime.
|
||||
use crate as pallet_dev_mode;
|
||||
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
|
||||
// For testing the pallet, we construct a mock runtime.
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Test
|
||||
{
|
||||
System: frame_system,
|
||||
Balances: pallet_balances,
|
||||
Example: pallet_dev_mode,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Nonce = u64;
|
||||
type Hash = H256;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Block = Block;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Version = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
}
|
||||
|
||||
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
|
||||
impl pallet_balances::Config for Test {
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
impl Config for Test {}
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let t = RuntimeGenesisConfig {
|
||||
// We use default for brevity, but you can configure as desired if needed.
|
||||
system: Default::default(),
|
||||
balances: Default::default(),
|
||||
}
|
||||
.build_storage()
|
||||
.unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works_for_optional_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Dummy::<Test>::get(), None);
|
||||
|
||||
let val1 = 42;
|
||||
assert_ok!(Example::add_dummy(RuntimeOrigin::root(), val1));
|
||||
assert_eq!(Dummy::<Test>::get(), Some(vec![val1]));
|
||||
|
||||
// Check that accumulate works when we have Some value in Dummy already.
|
||||
let val2 = 27;
|
||||
assert_ok!(Example::add_dummy(RuntimeOrigin::root(), val2));
|
||||
assert_eq!(Dummy::<Test>::get(), Some(vec![val1, val2]));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_dummy_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let test_val = 133;
|
||||
assert_ok!(Example::set_bar(RuntimeOrigin::signed(1), test_val.into()));
|
||||
assert_eq!(Bar::<Test>::get(1), Some(test_val));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user