mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 09:27:59 +00:00
66c02fe651
* really rough mock runtime * start to work on offences * Make sure to start the session. * Update to latest master. * Add verify. * Fix on_initialize benchmark. * Add grandpa offence. * Add Babe offence benchmarking. * Enable babe test. * Address review grumbles. * Address review grumbles. * Address review grumbles part 1/2 * use currency trait * features * Check events explicitly. * Auto-impl tuple converter. * Removed dead code. * add test feature flag * dont use std Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
215 lines
6.3 KiB
Rust
215 lines
6.3 KiB
Rust
// Copyright 2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Mock file for offences benchmarking.
|
|
|
|
#![cfg(test)]
|
|
|
|
use super::*;
|
|
use frame_support::parameter_types;
|
|
use frame_system as system;
|
|
use sp_runtime::{
|
|
SaturatedConversion,
|
|
traits::{IdentityLookup, Block as BlockT},
|
|
testing::{Header, UintAuthorityId},
|
|
};
|
|
|
|
|
|
type AccountId = u64;
|
|
type AccountIndex = u32;
|
|
type BlockNumber = u64;
|
|
type Balance = u64;
|
|
|
|
impl frame_system::Trait for Test {
|
|
type Origin = Origin;
|
|
type Index = AccountIndex;
|
|
type BlockNumber = BlockNumber;
|
|
type Call = Call;
|
|
type Hash = sp_core::H256;
|
|
type Hashing = ::sp_runtime::traits::BlakeTwo256;
|
|
type AccountId = AccountId;
|
|
type Lookup = IdentityLookup<Self::AccountId>;
|
|
type Header = sp_runtime::testing::Header;
|
|
type Event = Event;
|
|
type BlockHashCount = ();
|
|
type MaximumBlockWeight = ();
|
|
type DbWeight = ();
|
|
type AvailableBlockRatio = ();
|
|
type MaximumBlockLength = ();
|
|
type Version = ();
|
|
type ModuleToIndex = ();
|
|
type AccountData = pallet_balances::AccountData<u64>;
|
|
type OnNewAccount = ();
|
|
type OnKilledAccount = (Balances,);
|
|
type BlockExecutionWeight = ();
|
|
type ExtrinsicBaseWeight = ();
|
|
}
|
|
parameter_types! {
|
|
pub const ExistentialDeposit: Balance = 10;
|
|
}
|
|
impl pallet_balances::Trait for Test {
|
|
type Balance = Balance;
|
|
type Event = Event;
|
|
type DustRemoval = ();
|
|
type ExistentialDeposit = ExistentialDeposit;
|
|
type AccountStore = System;
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const MinimumPeriod: u64 = 5;
|
|
}
|
|
impl pallet_timestamp::Trait for Test {
|
|
type Moment = u64;
|
|
type OnTimestampSet = ();
|
|
type MinimumPeriod = MinimumPeriod;
|
|
}
|
|
impl pallet_session::historical::Trait for Test {
|
|
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
|
|
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
|
|
}
|
|
|
|
sp_runtime::impl_opaque_keys! {
|
|
pub struct SessionKeys {
|
|
pub foo: sp_runtime::testing::UintAuthorityId,
|
|
}
|
|
}
|
|
|
|
pub struct TestSessionHandler;
|
|
impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
|
|
const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[];
|
|
|
|
fn on_genesis_session<Ks: sp_runtime::traits::OpaqueKeys>(_validators: &[(AccountId, Ks)]) {}
|
|
|
|
fn on_new_session<Ks: sp_runtime::traits::OpaqueKeys>(
|
|
_: bool,
|
|
_: &[(AccountId, Ks)],
|
|
_: &[(AccountId, Ks)],
|
|
) {}
|
|
|
|
fn on_disabled(_: usize) {}
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const Period: u64 = 1;
|
|
pub const Offset: u64 = 0;
|
|
}
|
|
|
|
impl pallet_session::Trait for Test {
|
|
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Test, Staking>;
|
|
type Keys = SessionKeys;
|
|
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
|
|
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
|
|
type SessionHandler = TestSessionHandler;
|
|
type Event = Event;
|
|
type ValidatorId = AccountId;
|
|
type ValidatorIdOf = pallet_staking::StashOf<Test>;
|
|
type DisabledValidatorsThreshold = ();
|
|
}
|
|
pallet_staking_reward_curve::build! {
|
|
const I_NPOS: sp_runtime::curve::PiecewiseLinear<'static> = curve!(
|
|
min_inflation: 0_025_000,
|
|
max_inflation: 0_100_000,
|
|
ideal_stake: 0_500_000,
|
|
falloff: 0_050_000,
|
|
max_piece_count: 40,
|
|
test_precision: 0_005_000,
|
|
);
|
|
}
|
|
parameter_types! {
|
|
pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS;
|
|
pub const MaxNominatorRewardedPerValidator: u32 = 64;
|
|
}
|
|
|
|
pub type Extrinsic = sp_runtime::testing::TestXt<Call, ()>;
|
|
|
|
pub struct CurrencyToVoteHandler;
|
|
impl Convert<u64, u64> for CurrencyToVoteHandler {
|
|
fn convert(x: u64) -> u64 {
|
|
x
|
|
}
|
|
}
|
|
impl Convert<u128, u64> for CurrencyToVoteHandler {
|
|
fn convert(x: u128) -> u64 {
|
|
x.saturated_into()
|
|
}
|
|
}
|
|
|
|
impl pallet_staking::Trait for Test {
|
|
type Currency = Balances;
|
|
type UnixTime = pallet_timestamp::Module<Self>;
|
|
type CurrencyToVote = CurrencyToVoteHandler;
|
|
type RewardRemainder = ();
|
|
type Event = Event;
|
|
type Slash = ();
|
|
type Reward = ();
|
|
type SessionsPerEra = ();
|
|
type SlashDeferDuration = ();
|
|
type SlashCancelOrigin = frame_system::EnsureRoot<Self::AccountId>;
|
|
type BondingDuration = ();
|
|
type SessionInterface = Self;
|
|
type RewardCurve = RewardCurve;
|
|
type NextNewSession = Session;
|
|
type ElectionLookahead = ();
|
|
type Call = Call;
|
|
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
|
|
type UnsignedPriority = ();
|
|
type MaxIterations = ();
|
|
}
|
|
|
|
impl pallet_im_online::Trait for Test {
|
|
type AuthorityId = UintAuthorityId;
|
|
type Event = Event;
|
|
type SessionDuration = Period;
|
|
type ReportUnresponsiveness = Offences;
|
|
type UnsignedPriority = ();
|
|
}
|
|
|
|
impl pallet_offences::Trait for Test {
|
|
type Event = Event;
|
|
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
|
|
type OnOffenceHandler = Staking;
|
|
}
|
|
|
|
impl<T> frame_system::offchain::SendTransactionTypes<T> for Test where Call: From<T> {
|
|
type Extrinsic = Extrinsic;
|
|
type OverarchingCall = Call;
|
|
}
|
|
|
|
impl crate::Trait for Test {}
|
|
|
|
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
|
|
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, Call, u64, ()>;
|
|
|
|
frame_support::construct_runtime!(
|
|
pub enum Test where
|
|
Block = Block,
|
|
NodeBlock = Block,
|
|
UncheckedExtrinsic = UncheckedExtrinsic
|
|
{
|
|
System: system::{Module, Call, Event<T>},
|
|
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
|
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
|
|
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
|
|
ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
|
|
Offences: pallet_offences::{Module, Call, Storage, Event},
|
|
}
|
|
);
|
|
|
|
pub fn new_test_ext() -> sp_io::TestExternalities {
|
|
let t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
|
sp_io::TestExternalities::new(t)
|
|
}
|