mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 06:08:00 +00:00
363db4f086
* Initial abstraction * Alter rest of APIs * Fixes * Some extra getters in Gilt pallet. * Refactor Gilt to avoid u128 conversions * Simplify and improve pow in per_things * Add scalar division to per_things * Renaming from_fraction -> from_float, drop _approximation * Fixes * Fixes * Fixes * Fixes * Make stuff build * Fixes * Fixes * Fixes * Fixes * Update .gitignore Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/gilt/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/gilt/src/mock.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fixes * Fixes * Fixes Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
197 lines
5.8 KiB
Rust
197 lines
5.8 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
|
|
// 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.
|
|
|
|
//! Mock file for session benchmarking.
|
|
|
|
#![cfg(test)]
|
|
|
|
use sp_runtime::traits::IdentityLookup;
|
|
use frame_election_provider_support::onchain;
|
|
use frame_support::parameter_types;
|
|
|
|
type AccountId = u64;
|
|
type AccountIndex = u32;
|
|
type BlockNumber = u64;
|
|
type Balance = u64;
|
|
|
|
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
|
type Block = frame_system::mocking::MockBlock<Test>;
|
|
|
|
frame_support::construct_runtime!(
|
|
pub enum Test where
|
|
Block = Block,
|
|
NodeBlock = Block,
|
|
UncheckedExtrinsic = UncheckedExtrinsic,
|
|
{
|
|
System: frame_system::{Module, Call, Config, Storage, 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>},
|
|
}
|
|
);
|
|
|
|
impl frame_system::Config for Test {
|
|
type BaseCallFilter = ();
|
|
type BlockWeights = ();
|
|
type BlockLength = ();
|
|
type DbWeight = ();
|
|
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 Version = ();
|
|
type PalletInfo = PalletInfo;
|
|
type AccountData = pallet_balances::AccountData<u64>;
|
|
type OnNewAccount = ();
|
|
type OnKilledAccount = ();
|
|
type SystemWeightInfo = ();
|
|
type SS58Prefix = ();
|
|
}
|
|
parameter_types! {
|
|
pub const ExistentialDeposit: Balance = 10;
|
|
}
|
|
impl pallet_balances::Config for Test {
|
|
type MaxLocks = ();
|
|
type Balance = Balance;
|
|
type Event = Event;
|
|
type DustRemoval = ();
|
|
type ExistentialDeposit = ExistentialDeposit;
|
|
type AccountStore = System;
|
|
type WeightInfo = ();
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const MinimumPeriod: u64 = 5;
|
|
}
|
|
impl pallet_timestamp::Config for Test {
|
|
type Moment = u64;
|
|
type OnTimestampSet = ();
|
|
type MinimumPeriod = MinimumPeriod;
|
|
type WeightInfo = ();
|
|
}
|
|
impl pallet_session::historical::Config 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) {}
|
|
}
|
|
|
|
impl pallet_session::Config for Test {
|
|
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Test, Staking>;
|
|
type Keys = SessionKeys;
|
|
type ShouldEndSession = pallet_session::PeriodicSessions<(), ()>;
|
|
type NextSessionRotation = pallet_session::PeriodicSessions<(), ()>;
|
|
type SessionHandler = TestSessionHandler;
|
|
type Event = Event;
|
|
type ValidatorId = AccountId;
|
|
type ValidatorIdOf = pallet_staking::StashOf<Test>;
|
|
type DisabledValidatorsThreshold = ();
|
|
type WeightInfo = ();
|
|
}
|
|
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 const UnsignedPriority: u64 = 1 << 20;
|
|
}
|
|
|
|
pub type Extrinsic = sp_runtime::testing::TestXt<Call, ()>;
|
|
|
|
impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
|
|
where
|
|
Call: From<C>,
|
|
{
|
|
type OverarchingCall = Call;
|
|
type Extrinsic = Extrinsic;
|
|
}
|
|
|
|
impl onchain::Config for Test {
|
|
type AccountId = AccountId;
|
|
type BlockNumber = BlockNumber;
|
|
type BlockWeights = ();
|
|
type Accuracy = sp_runtime::Perbill;
|
|
type DataProvider = Staking;
|
|
}
|
|
|
|
impl pallet_staking::Config for Test {
|
|
type Currency = Balances;
|
|
type UnixTime = pallet_timestamp::Module<Self>;
|
|
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
|
|
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 EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
|
|
type NextNewSession = Session;
|
|
type ElectionLookahead = ();
|
|
type Call = Call;
|
|
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
|
|
type UnsignedPriority = UnsignedPriority;
|
|
type MaxIterations = ();
|
|
type MinSolutionScoreBump = ();
|
|
type OffchainSolutionWeightLimit = ();
|
|
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
|
|
type WeightInfo = ();
|
|
}
|
|
|
|
impl crate::Config for Test {}
|
|
|
|
pub fn new_test_ext() -> sp_io::TestExternalities {
|
|
let t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
|
sp_io::TestExternalities::new(t)
|
|
}
|