mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 05:47:58 +00:00
0b77060986
* Vesting pallet - make WithdrawReasons configurable * Update `pallet-vesting` README Co-authored-by: parity-processbot <>
160 lines
4.7 KiB
Rust
160 lines
4.7 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2019-2022 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.
|
|
|
|
use frame_support::{
|
|
parameter_types,
|
|
traits::{ConstU32, ConstU64, GenesisBuild, WithdrawReasons},
|
|
};
|
|
use sp_core::H256;
|
|
use sp_runtime::{
|
|
testing::Header,
|
|
traits::{BlakeTwo256, Identity, IdentityLookup},
|
|
};
|
|
|
|
use super::*;
|
|
use crate as pallet_vesting;
|
|
|
|
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::{Pallet, Call, Config, Storage, Event<T>},
|
|
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
|
Vesting: pallet_vesting::{Pallet, Call, Storage, Event<T>, Config<T>},
|
|
}
|
|
);
|
|
|
|
parameter_types! {
|
|
pub BlockWeights: frame_system::limits::BlockWeights =
|
|
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
|
|
}
|
|
impl frame_system::Config for Test {
|
|
type AccountData = pallet_balances::AccountData<u64>;
|
|
type AccountId = u64;
|
|
type BaseCallFilter = frame_support::traits::Everything;
|
|
type BlockHashCount = ConstU64<250>;
|
|
type BlockLength = ();
|
|
type BlockNumber = u64;
|
|
type BlockWeights = ();
|
|
type RuntimeCall = RuntimeCall;
|
|
type DbWeight = ();
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type Hash = H256;
|
|
type Hashing = BlakeTwo256;
|
|
type Header = Header;
|
|
type Index = u64;
|
|
type Lookup = IdentityLookup<Self::AccountId>;
|
|
type OnKilledAccount = ();
|
|
type OnNewAccount = ();
|
|
type OnSetCode = ();
|
|
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
|
type RuntimeOrigin = RuntimeOrigin;
|
|
type PalletInfo = PalletInfo;
|
|
type SS58Prefix = ();
|
|
type SystemWeightInfo = ();
|
|
type Version = ();
|
|
}
|
|
|
|
impl pallet_balances::Config for Test {
|
|
type AccountStore = System;
|
|
type Balance = u64;
|
|
type DustRemoval = ();
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type ExistentialDeposit = ExistentialDeposit;
|
|
type MaxLocks = ConstU32<10>;
|
|
type MaxReserves = ();
|
|
type ReserveIdentifier = [u8; 8];
|
|
type WeightInfo = ();
|
|
}
|
|
parameter_types! {
|
|
pub const MinVestedTransfer: u64 = 256 * 2;
|
|
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
|
|
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
|
|
pub static ExistentialDeposit: u64 = 0;
|
|
}
|
|
impl Config for Test {
|
|
type BlockNumberToBalance = Identity;
|
|
type Currency = Balances;
|
|
type RuntimeEvent = RuntimeEvent;
|
|
const MAX_VESTING_SCHEDULES: u32 = 3;
|
|
type MinVestedTransfer = MinVestedTransfer;
|
|
type WeightInfo = ();
|
|
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
|
|
}
|
|
|
|
pub struct ExtBuilder {
|
|
existential_deposit: u64,
|
|
vesting_genesis_config: Option<Vec<(u64, u64, u64, u64)>>,
|
|
}
|
|
|
|
impl Default for ExtBuilder {
|
|
fn default() -> Self {
|
|
Self { existential_deposit: 1, vesting_genesis_config: None }
|
|
}
|
|
}
|
|
|
|
impl ExtBuilder {
|
|
pub fn existential_deposit(mut self, existential_deposit: u64) -> Self {
|
|
self.existential_deposit = existential_deposit;
|
|
self
|
|
}
|
|
|
|
pub fn vesting_genesis_config(mut self, config: Vec<(u64, u64, u64, u64)>) -> Self {
|
|
self.vesting_genesis_config = Some(config);
|
|
self
|
|
}
|
|
|
|
pub fn build(self) -> sp_io::TestExternalities {
|
|
EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit);
|
|
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
|
pallet_balances::GenesisConfig::<Test> {
|
|
balances: vec![
|
|
(1, 10 * self.existential_deposit),
|
|
(2, 20 * self.existential_deposit),
|
|
(3, 30 * self.existential_deposit),
|
|
(4, 40 * self.existential_deposit),
|
|
(12, 10 * self.existential_deposit),
|
|
(13, 9999 * self.existential_deposit),
|
|
],
|
|
}
|
|
.assimilate_storage(&mut t)
|
|
.unwrap();
|
|
|
|
let vesting = if let Some(vesting_config) = self.vesting_genesis_config {
|
|
vesting_config
|
|
} else {
|
|
vec![
|
|
(1, 0, 10, 5 * self.existential_deposit),
|
|
(2, 10, 20, 0),
|
|
(12, 10, 20, 5 * self.existential_deposit),
|
|
]
|
|
};
|
|
|
|
pallet_vesting::GenesisConfig::<Test> { vesting }
|
|
.assimilate_storage(&mut t)
|
|
.unwrap();
|
|
let mut ext = sp_io::TestExternalities::new(t);
|
|
ext.execute_with(|| System::set_block_number(1));
|
|
ext
|
|
}
|
|
}
|