mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 08:27:55 +00:00
Reorganising the repository - external renames and moves (#4074)
* Adding first rough ouline of the repository structure * Remove old CI stuff * add title * formatting fixes * move node-exits job's script to scripts dir * Move docs into subdir * move to bin * move maintainence scripts, configs and helpers into its own dir * add .local to ignore * move core->client * start up 'test' area * move test client * move test runtime * make test move compile * Add dependencies rule enforcement. * Fix indexing. * Update docs to reflect latest changes * Moving /srml->/paint * update docs * move client/sr-* -> primitives/ * clean old readme * remove old broken code in rhd * update lock * Step 1. * starting to untangle client * Fix after merge. * start splitting out client interfaces * move children and blockchain interfaces * Move trie and state-machine to primitives. * Fix WASM builds. * fixing broken imports * more interface moves * move backend and light to interfaces * move CallExecutor * move cli off client * moving around more interfaces * re-add consensus crates into the mix * fix subkey path * relieve client from executor * starting to pull out client from grandpa * move is_decendent_of out of client * grandpa still depends on client directly * lemme tests pass * rename srml->paint * Make it compile. * rename interfaces->client-api * Move keyring to primitives. * fixup libp2p dep * fix broken use * allow dependency enforcement to fail * move fork-tree * Moving wasm-builder * make env * move build-script-utils * fixup broken crate depdencies and names * fix imports for authority discovery * fix typo * update cargo.lock * fixing imports * Fix paths and add missing crates * re-add missing crates
This commit is contained in:
committed by
Bastian Köcher
parent
becc3b0a4f
commit
60e5011c72
@@ -0,0 +1,131 @@
|
||||
/// A runtime module template with necessary imports
|
||||
|
||||
/// Feel free to remove or edit this file as needed.
|
||||
/// If you change the name of this file, make sure to update its references in runtime/src/lib.rs
|
||||
/// If you remove this file, you can remove those references
|
||||
|
||||
|
||||
/// For more guidance on Substrate modules, see the example module
|
||||
/// https://github.com/paritytech/substrate/blob/master/paint/example/src/lib.rs
|
||||
|
||||
use support::{decl_module, decl_storage, decl_event, dispatch::Result};
|
||||
use system::ensure_signed;
|
||||
|
||||
/// The module's configuration trait.
|
||||
pub trait Trait: system::Trait {
|
||||
// TODO: Add other types and constants required configure this module.
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
||||
}
|
||||
|
||||
// This module's storage items.
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as TemplateModule {
|
||||
// Just a dummy storage item.
|
||||
// Here we are declaring a StorageValue, `Something` as a Option<u32>
|
||||
// `get(fn something)` is the default getter which returns either the stored `u32` or `None` if nothing stored
|
||||
Something get(fn something): Option<u32>;
|
||||
}
|
||||
}
|
||||
|
||||
// The module's dispatchable functions.
|
||||
decl_module! {
|
||||
/// The module declaration.
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
// Initializing events
|
||||
// this is needed only if you are using events in your module
|
||||
fn deposit_event() = default;
|
||||
|
||||
// Just a dummy entry point.
|
||||
// function that can be called by the external world as an extrinsics call
|
||||
// takes a parameter of the type `AccountId`, stores it and emits an event
|
||||
pub fn do_something(origin, something: u32) -> Result {
|
||||
// TODO: You only need this if you want to check it was signed.
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
// TODO: Code to execute when something calls this.
|
||||
// For example: the following line stores the passed in u32 in the storage
|
||||
Something::put(something);
|
||||
|
||||
// here we are raising the Something event
|
||||
Self::deposit_event(RawEvent::SomethingStored(something, who));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {
|
||||
// Just a dummy event.
|
||||
// Event `Something` is declared with a parameter of the type `u32` and `AccountId`
|
||||
// To emit this event, we call the deposit funtion, from our runtime funtions
|
||||
SomethingStored(u32, AccountId),
|
||||
}
|
||||
);
|
||||
|
||||
/// tests for this module
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use primitives::H256;
|
||||
use support::{impl_outer_origin, assert_ok, parameter_types};
|
||||
use sr_primitives::{
|
||||
traits::{BlakeTwo256, IdentityLookup}, testing::Header, weights::Weight, Perbill,
|
||||
};
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test {}
|
||||
}
|
||||
|
||||
// For testing the module, we construct most of a mock runtime. This means
|
||||
// first constructing a configuration type (`Test`) which `impl`s each of the
|
||||
// configuration traits of modules we want to use.
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const MaximumBlockWeight: Weight = 1024;
|
||||
pub const MaximumBlockLength: u32 = 2 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||
}
|
||||
impl system::Trait for Test {
|
||||
type Origin = Origin;
|
||||
type Call = ();
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = ();
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type MaximumBlockWeight = MaximumBlockWeight;
|
||||
type MaximumBlockLength = MaximumBlockLength;
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
type Version = ();
|
||||
}
|
||||
impl Trait for Test {
|
||||
type Event = ();
|
||||
}
|
||||
type TemplateModule = Module<Test>;
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works_for_default_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Just a dummy test for the dummy funtion `do_something`
|
||||
// calling the `do_something` function with a value 42
|
||||
assert_ok!(TemplateModule::do_something(Origin::signed(1), 42));
|
||||
// asserting that the stored value is equal to what we stored
|
||||
assert_eq!(TemplateModule::something(), Some(42));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user