#![cfg(feature = "std")]
#![allow(unused)]
use crate as pallet_xp;
use crate::{types::*, Config};
use frame_suite::misc::Ignore;
pub use frame_support::instances::Instance1;
pub use frame_support::instances::Instance2;
use frame_support::{derive_impl, pallet_prelude::*, traits::VariantCount};
use sp_core::ConstBool;
use sp_runtime::{BuildStorage, RuntimeDebug};
use serde::{Deserialize, Serialize};
pub type Block = frame_system::mocking::MockBlock<Test>;
pub type AccountId = u64;
pub type Account = frame_system::Account<Test>;
pub type ReserveId =
IdXp<crate::types::ReserveReason<Test, Instance1>, <Test as Config<Instance1>>::Xp>;
pub type LockId = IdXp<crate::types::LockReason<Test, Instance1>, <Test as Config<Instance1>>::Xp>;
pub type Pallet = crate::Pallet<Test, Instance1>;
pub type Error = crate::Error<Test, Instance1>;
pub type Event = crate::Event<Test, Instance1>;
pub type MockXp = crate::types::Xp<Test, Instance1>;
pub type MockXp2 = crate::types::Xp<Test, Instance2>;
pub type XpOf = crate::XpOf<Test, Instance1>;
pub type XpOf2 = crate::XpOf<Test, Instance2>;
pub type LockedXpOf = crate::LockedXpOf<Test, Instance1>;
pub type ReservedXpOf = crate::ReservedXpOf<Test, Instance1>;
pub type LockedXpOf2 = crate::LockedXpOf<Test, Instance2>;
pub type ReservedXpOf2 = crate::ReservedXpOf<Test, Instance2>;
pub type XpOwners = crate::XpOwners<Test, Instance1>;
pub type XpOwners2 = crate::XpOwners<Test, Instance2>;
pub type ReapedXp = crate::ReapedXp<Test, Instance1>;
pub type ReapedXp2 = crate::ReapedXp<Test, Instance2>;
pub type InitXp = crate::InitXp<Test, Instance1>;
pub type InitXp2 = crate::InitXp<Test, Instance2>;
pub type Stepper = crate::types::Stepper<Test, Instance1>;
pub type Stepper2 = crate::types::Stepper<Test, Instance2>;
pub type Accumulator = crate::types::Accumulator<Test, Instance1>;
pub type PulseFactor = crate::PulseFactor<Test, Instance1>;
pub type PulseFactor2 = crate::PulseFactor<Test, Instance2>;
pub type MinPulse = crate::MinPulse<Test, Instance1>;
pub type MinPulse2 = crate::MinPulse<Test, Instance2>;
pub type MinTimeStamp = crate::MinTimeStamp<Test, Instance1>;
pub type MinTimeStamp2 = crate::MinTimeStamp<Test, Instance2>;
pub type Call = <Test as Config<Instance1>>::RuntimeCall;
pub const ALICE: AccountId = 1;
pub const BOB: AccountId = 2;
pub const CHARLIE: AccountId = 3;
pub const XP_ALPHA: <Test as Config<Instance1>>::Xp = 1;
pub const XP_BETA: <Test as Config<Instance1>>::Xp = 2;
pub const XP_GAMMA: <Test as Config<Instance1>>::Xp = 3;
pub const STAKING: Reason = Reason::Staking;
pub const REASON_TREASURY: Reason = Reason::Treasury;
pub const GOVERNANCE: Reason = Reason::Governance;
pub const DEFAULT_POINTS: <Test as Config<Instance1>>::Xp = 10;
pub const INVALID_POINTS: <Test as Config<Instance1>>::Xp = 0;
pub const XP_REWARD_COMMENT: <Test as Config<Instance1>>::Xp = 5;
pub const XP_REWARD_PROPOSAL: <Test as Config<Instance1>>::Xp = 10;
pub const SATURATED_MAX: <Test as Config<Instance1>>::Xp = <Test as Config<Instance1>>::Xp::MAX;
#[derive(
Clone,
Copy,
PartialEq,
PartialOrd,
Ord,
Eq,
DecodeWithMemTracking,
RuntimeDebug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
Serialize,
Deserialize,
Default,
)]
pub enum Reason {
#[default]
Staking,
Treasury,
Governance,
}
impl VariantCount for Reason {
const VARIANT_COUNT: u32 = 3;
}
pub fn xp_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
pallet_xp::GenesisConfig::<Test, pallet_xp::Instance1> {
min_pulse: 1,
init_xp: 10,
pulse_factor: Stepper::new(50u8.into(), 10u8.into()).unwrap(),
genesis_acc: vec![],
}
.assimilate_storage(&mut t)
.unwrap();
pallet_xp::GenesisConfig::<Test, pallet_xp::Instance2> {
min_pulse: 5,
init_xp: 1,
pulse_factor: Stepper2::new(20u8.into(), 6u8.into()).unwrap(),
genesis_acc: vec![],
}
.assimilate_storage(&mut t)
.unwrap();
t.into()
}
#[frame_support::runtime]
pub mod runtime {
#[runtime::runtime]
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeFreezeReason,
RuntimeHoldReason,
RuntimeSlashReason,
RuntimeLockId,
RuntimeTask,
RuntimeViewFunction
)]
pub struct Test;
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Test>;
#[runtime::pallet_index(1)]
pub type Xp = pallet_xp::Pallet<Test, Instance1>;
#[runtime::pallet_index(2)]
pub type Xp2 = pallet_xp::Pallet<Test, Instance2>;
}
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type Block = Block;
type AccountId = AccountId;
}
impl pallet_xp::Config<Instance1> for Test {
type Xp = u64;
type Pulse = u32;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type LockReason = Reason;
type ReserveReason = Reason;
type Extensions = Ignore<Xp>;
type WeightInfo = ();
type EmitEvents = ConstBool<true>;
}
impl pallet_xp::Config<Instance2> for Test {
type Xp = u64;
type Pulse = u32;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type LockReason = Reason;
type ReserveReason = Reason;
type Extensions = Ignore<Xp2>;
type WeightInfo = ();
type EmitEvents = ConstBool<true>;
}