mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 22:27:56 +00:00
bda8641892
* Draft of new sessions * Reintroduce tuple impls * Move staking module to new session API * More work on staking and grandpa. * Use iterator to avoid cloning and tuple macro * Make runtime build again * Polish the OpaqueKeys devex * Move consensus logic into system & aura. * Fix up system module * Get build mostly going. Stuck at service.rs * Building again * Update srml/staking/src/lib.rs Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * Refactoring out Consensus module, AuthorityIdOf, &c. * Refactored out DigestItem::AuthoritiesChanged. Building. * Remove tentative code * Remove invalid comment * Make Seal opaque and introduce nice methods for handling opaque items. * Start to use proper digest for Aura authorities tracking. * Fix up grandpa, remove system::Raw/Log * Refactor Grandpa to use new logging infrastructure. Also make authorityid/sessionkey static. Switch over to storing authorities in a straight Vec. * Building again * Tidy up some AuthorityIds * Expunge most of the rest of the AuthorityKey confusion. Also, de-generify Babe and re-generify Aura. * Remove cruft * Untangle last of the `AuthorityId`s. * Sort out finality_tracker * Refactor median getting * Apply suggestions from code review Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> * Session tests works * Update core/sr-primitives/src/generic/digest.rs Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * Session tests works * Fix for staking from @dvc94ch * log an error * fix test runtime build * Some test fixes * Staking mock update to new session api. * Fix build. * Move OpaqueKeys to primitives. * Use on_initialize instead of check_rotate_session. * Update tests to new staking api. * fixup mock * Fix bond_extra_and_withdraw_unbonded_works. * Fix bond_with_little_staked_value_bounded_by_slot_stake. * Fix bond_with_no_staked_value. * Fix change_controller_works. * Fix less_than_needed_candidates_works. * Fix multi_era_reward_should_work. * Fix nominating_and_rewards_should_work. * Fix nominators_also_get_slashed. * Fix phragmen_large_scale_test. * Fix phragmen_poc_works. * Fix phragmen_score_should_be_accurate_on_large_stakes. * Fix phragmen_should_not_overflow. * Fix reward_destination_works. * Fix rewards_should_work. * Fix sessions_and_eras_should_work. * Fix slot_stake_is_least_staked_validator. * Fix too_many_unbond_calls_should_not_work. * Fix wrong_vote_is_null. * Fix runtime. * Fix wasm runtime build. * Update Cargo.lock * Fix warnings. * Fix grandpa tests. * Fix test-runtime build. * Fix template node build. * Fix stuff. * Update Cargo.lock to fix CI * Re-add missing AuRa logs Runtimes are required to know about every digest they receive ― they panic otherwise. This re-adds support for AuRa pre-runtime digests. * Update core/consensus/babe/src/digest.rs Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * Kill log trait and all that jazz. * Refactor staking tests. * Fix ci runtime wasm check. * Line length 120. * Make tests build again * Remove trailing commas in function declarations The `extern_functions!` macro doesn’t like them, perhaps due to a bug in rustc. * Fix type error * Fix compilation errors * Fix a test * Another couple of fixes * Fix another test * More test fixes * Another test fix * Bump runtime. * Wrap long line * Fix build, remove redundant code. * Issue to track TODO * Leave the benchmark code alone. * Fix missing `std::time::{Instant, Duration}` * Indentation * Aura ConsensusLog as enum
123 lines
3.9 KiB
Rust
123 lines
3.9 KiB
Rust
/// 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/srml/example/src/lib.rs
|
|
|
|
use support::{decl_module, decl_storage, decl_event, StorageValue, 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(something)` is the default getter which returns either the stored `u32` or `None` if nothing stored
|
|
Something get(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<T>() = 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<T>>::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 runtime_io::with_externalities;
|
|
use primitives::{H256, Blake2Hasher};
|
|
use support::{impl_outer_origin, assert_ok};
|
|
use runtime_primitives::{
|
|
BuildStorage,
|
|
traits::{BlakeTwo256, IdentityLookup},
|
|
testing::Header,
|
|
};
|
|
|
|
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;
|
|
impl system::Trait for Test {
|
|
type Origin = Origin;
|
|
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 = ();
|
|
}
|
|
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<Blake2Hasher> {
|
|
system::GenesisConfig::<Test>::default().build_storage().unwrap().0.into()
|
|
}
|
|
|
|
#[test]
|
|
fn it_works_for_default_value() {
|
|
with_externalities(&mut new_test_ext(), || {
|
|
// 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));
|
|
});
|
|
}
|
|
}
|