-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathmock.rs
More file actions
130 lines (107 loc) · 3.27 KB
/
Copy pathmock.rs
File metadata and controls
130 lines (107 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Mocks for the vesting module.
#![cfg(test)]
use super::*;
use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{ConstU32, ConstU64, EnsureOrigin},
};
use frame_system::RawOrigin;
use sp_runtime::{traits::IdentityLookup, BuildStorage};
use crate as vesting;
pub type AccountId = u128;
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type AccountData = pallet_balances::AccountData<Balance>;
}
type Balance = u64;
impl pallet_balances::Config for Runtime {
type Balance = Balance;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ConstU64<1>;
type AccountStore = frame_system::Pallet<Runtime>;
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type WeightInfo = ();
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type FreezeIdentifier = [u8; 8];
type MaxFreezes = ();
type DoneSlashHandler = ();
}
pub struct EnsureAliceOrBob;
impl EnsureOrigin<RuntimeOrigin> for EnsureAliceOrBob {
type Success = AccountId;
fn try_origin(o: RuntimeOrigin) -> Result<Self::Success, RuntimeOrigin> {
Into::<Result<RawOrigin<AccountId>, RuntimeOrigin>>::into(o).and_then(|o| match o {
RawOrigin::Signed(ALICE) => Ok(ALICE),
RawOrigin::Signed(BOB) => Ok(BOB),
r => Err(RuntimeOrigin::from(r)),
})
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<RuntimeOrigin, ()> {
let zero_account_id = AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
.expect("infinite length input; no invalid inputs for type; qed");
Ok(RuntimeOrigin::from(RawOrigin::Signed(zero_account_id)))
}
}
parameter_types! {
pub static MockBlockNumberProvider: u64 = 0;
}
impl BlockNumberProvider for MockBlockNumberProvider {
type BlockNumber = u64;
fn current_block_number() -> BlockNumberFor<Runtime> {
Self::get()
}
}
impl Config for Runtime {
type Currency = PalletBalances;
type MinVestedTransfer = ConstU64<5>;
type VestedTransferOrigin = EnsureAliceOrBob;
type WeightInfo = ();
type MaxVestingSchedules = ConstU32<2>;
type BlockNumberProvider = MockBlockNumberProvider;
}
type Block = frame_system::mocking::MockBlock<Runtime>;
construct_runtime!(
pub enum Runtime {
System: frame_system,
Vesting: vesting,
PalletBalances: pallet_balances,
}
);
pub const ALICE: AccountId = 1;
pub const BOB: AccountId = 2;
pub const CHARLIE: AccountId = 3;
pub const ALICE_BALANCE: u64 = 100;
pub const CHARLIE_BALANCE: u64 = 50;
#[derive(Default)]
pub struct ExtBuilder;
impl ExtBuilder {
pub fn build() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(ALICE, ALICE_BALANCE), (CHARLIE, CHARLIE_BALANCE)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
vesting::GenesisConfig::<Runtime> {
vesting: vec![
// who, start, period, period_count, per_period
(CHARLIE, 2, 3, 1, 5),
(CHARLIE, 2 + 3, 3, 3, 5),
],
}
.assimilate_storage(&mut t)
.unwrap();
t.into()
}
}