123#![cfg(test)]45use super::*;6use frame_support::{7 construct_runtime, parameter_types,8 traits::{EnsureOrigin, Everything},9};10use frame_system::RawOrigin;11use sp_core::H256;12use sp_runtime::{testing::Header, traits::IdentityLookup};1314use crate as vesting;1516parameter_types! {17 pub const BlockHashCount: u64 = 250;18}1920pub type AccountId = u128;21impl frame_system::Config for Runtime {22 type Origin = Origin;23 type Call = Call;24 type Index = u64;25 type BlockNumber = u64;26 type Hash = H256;27 type Hashing = ::sp_runtime::traits::BlakeTwo256;28 type AccountId = AccountId;29 type Lookup = IdentityLookup<Self::AccountId>;30 type Header = Header;31 type Event = Event;32 type BlockHashCount = BlockHashCount;33 type BlockWeights = ();34 type BlockLength = ();35 type Version = ();36 type PalletInfo = PalletInfo;37 type AccountData = pallet_balances::AccountData<u64>;38 type OnNewAccount = ();39 type OnKilledAccount = ();40 type DbWeight = ();41 type BaseCallFilter = Everything;42 type SystemWeightInfo = ();43 type SS58Prefix = ();44 type OnSetCode = ();45}4647type Balance = u64;4849parameter_types! {50 pub const ExistentialDeposit: u64 = 1;51}5253impl pallet_balances::Config for Runtime {54 type Balance = Balance;55 type DustRemoval = ();56 type Event = Event;57 type ExistentialDeposit = ExistentialDeposit;58 type AccountStore = frame_system::Pallet<Runtime>;59 type MaxLocks = ();60 type MaxReserves = ();61 type ReserveIdentifier = [u8; 8];62 type WeightInfo = ();63}6465pub struct EnsureAliceOrBob;66impl EnsureOrigin<Origin> for EnsureAliceOrBob {67 type Success = AccountId;6869 fn try_origin(o: Origin) -> Result<Self::Success, Origin> {70 Into::<Result<RawOrigin<AccountId>, Origin>>::into(o).and_then(|o| match o {71 RawOrigin::Signed(ALICE) => Ok(ALICE),72 RawOrigin::Signed(BOB) => Ok(BOB),73 r => Err(Origin::from(r)),74 })75 }7677 #[cfg(feature = "runtime-benchmarks")]78 fn successful_origin() -> Origin {79 Origin::from(RawOrigin::Signed(Default::default()))80 }81}8283parameter_types! {84 pub const MaxVestingSchedule: u32 = 2;85 pub const MinVestedTransfer: u64 = 5;86 pub static MockBlockNumberProvider: u64 = 0;87}8889impl BlockNumberProvider for MockBlockNumberProvider {90 type BlockNumber = u64;9192 fn current_block_number() -> Self::BlockNumber {93 Self::get()94 }95}9697impl Config for Runtime {98 type Event = Event;99 type Currency = PalletBalances;100 type MinVestedTransfer = MinVestedTransfer;101 type VestedTransferOrigin = EnsureAliceOrBob;102 type WeightInfo = ();103 type MaxVestingSchedules = MaxVestingSchedule;104 type BlockNumberProvider = MockBlockNumberProvider;105}106107type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;108type Block = frame_system::mocking::MockBlock<Runtime>;109110construct_runtime!(111 pub enum Runtime where112 Block = Block,113 NodeBlock = Block,114 UncheckedExtrinsic = UncheckedExtrinsic,115 {116 System: frame_system::{Pallet, Call, Storage, Config, Event<T>},117 Vesting: vesting::{Pallet, Storage, Call, Event<T>, Config<T>},118 PalletBalances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},119 }120);121122pub const ALICE: AccountId = 1;123pub const BOB: AccountId = 2;124pub const CHARLIE: AccountId = 3;125126#[derive(Default)]127pub struct ExtBuilder;128129impl ExtBuilder {130 pub fn build() -> sp_io::TestExternalities {131 let mut t = frame_system::GenesisConfig::default()132 .build_storage::<Runtime>()133 .unwrap();134135 pallet_balances::GenesisConfig::<Runtime> {136 balances: vec![(ALICE, 100), (CHARLIE, 50)],137 }138 .assimilate_storage(&mut t)139 .unwrap();140141 vesting::GenesisConfig::<Runtime> {142 vesting: vec![143 144 (CHARLIE, 2, 3, 1, 5),145 (CHARLIE, 2 + 3, 3, 3, 5),146 ],147 }148 .assimilate_storage(&mut t)149 .unwrap();150151 t.into()152 }153}