1
// Copyright 2024 Moonbeam foundation
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonbeam is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
//! A minimal runtime including the multi block migrations pallet
18

            
19
use super::*;
20
use crate as pallet_moonbeam_lazy_migrations;
21
use frame_support::weights::constants::RocksDbWeight;
22
use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight};
23
use pallet_evm::{EnsureAddressNever, EnsureAddressRoot, FrameSystemAccountProvider};
24
use precompile_utils::testing::MockAccount;
25
use sp_core::{H160, H256, U256};
26
use sp_runtime::{
27
	traits::{BlakeTwo256, IdentityLookup},
28
	BuildStorage, Perbill,
29
};
30

            
31
pub type AssetId = u128;
32
pub type Balance = u128;
33
pub type AccountId = MockAccount;
34
type Block = frame_system::mocking::MockBlock<Test>;
35

            
36
// Configure a mock runtime to test the pallet.
37
22
construct_runtime!(
38
22
	pub enum Test
39
22
	{
40
22
		System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
41
22
		Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
42
22
		Timestamp: pallet_timestamp,
43
22
		EVM: pallet_evm,
44
22
		LazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call},
45
22
	}
46
22
);
47

            
48
parameter_types! {
49
	pub const BlockHashCount: u32 = 250;
50
	pub const MaximumBlockWeight: Weight = Weight::from_parts(1024, 1);
51
	pub const MaximumBlockLength: u32 = 2 * 1024;
52
	pub const AvailableBlockRatio: Perbill = Perbill::one();
53
	pub const SS58Prefix: u8 = 42;
54
}
55

            
56
impl frame_system::Config for Test {
57
	type BaseCallFilter = Everything;
58
	type DbWeight = RocksDbWeight;
59
	type RuntimeOrigin = RuntimeOrigin;
60
	type RuntimeTask = RuntimeTask;
61
	type Nonce = u64;
62
	type Block = Block;
63
	type RuntimeCall = RuntimeCall;
64
	type Hash = H256;
65
	type Hashing = BlakeTwo256;
66
	type AccountId = AccountId;
67
	type Lookup = IdentityLookup<Self::AccountId>;
68
	type RuntimeEvent = RuntimeEvent;
69
	type BlockHashCount = BlockHashCount;
70
	type Version = ();
71
	type PalletInfo = PalletInfo;
72
	type AccountData = pallet_balances::AccountData<Balance>;
73
	type OnNewAccount = ();
74
	type OnKilledAccount = ();
75
	type SystemWeightInfo = ();
76
	type BlockWeights = ();
77
	type BlockLength = ();
78
	type SS58Prefix = SS58Prefix;
79
	type OnSetCode = ();
80
	type MaxConsumers = frame_support::traits::ConstU32<16>;
81
	type SingleBlockMigrations = ();
82
	type MultiBlockMigrator = ();
83
	type PreInherents = ();
84
	type PostInherents = ();
85
	type PostTransactions = ();
86
	type ExtensionsWeightInfo = ();
87
}
88

            
89
parameter_types! {
90
	pub const ExistentialDeposit: u128 = 0;
91
}
92
impl pallet_balances::Config for Test {
93
	type MaxReserves = ();
94
	type ReserveIdentifier = ();
95
	type MaxLocks = ();
96
	type Balance = Balance;
97
	type RuntimeEvent = RuntimeEvent;
98
	type DustRemoval = ();
99
	type ExistentialDeposit = ExistentialDeposit;
100
	type AccountStore = System;
101
	type WeightInfo = ();
102
	type RuntimeHoldReason = ();
103
	type FreezeIdentifier = ();
104
	type MaxFreezes = ();
105
	type RuntimeFreezeReason = ();
106
	type DoneSlashHandler = ();
107
}
108

            
109
parameter_types! {
110
	pub const MinimumPeriod: u64 = 6000 / 2;
111
}
112

            
113
impl pallet_timestamp::Config for Test {
114
	type Moment = u64;
115
	type OnTimestampSet = ();
116
	type MinimumPeriod = MinimumPeriod;
117
	type WeightInfo = ();
118
}
119

            
120
parameter_types! {
121
	pub BlockGasLimit: U256 = U256::from(u64::MAX);
122
	pub const WeightPerGas: Weight = Weight::from_parts(1, 0);
123
	pub GasLimitPovSizeRatio: u64 = 16;
124
	pub GasLimitStorageGrowthRatio: u64 = 366;
125
	pub SuicideQuickClearLimit: u32 = 0;
126
}
127

            
128
impl pallet_evm::Config for Test {
129
	type FeeCalculator = ();
130
	type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
131
	type WeightPerGas = WeightPerGas;
132
	type CallOrigin = EnsureAddressRoot<AccountId>;
133
	type WithdrawOrigin = EnsureAddressNever<AccountId>;
134
	type AddressMapping = AccountId;
135
	type Currency = Balances;
136
	type RuntimeEvent = RuntimeEvent;
137
	type Runner = pallet_evm::runner::stack::Runner<Self>;
138
	type PrecompilesType = ();
139
	type PrecompilesValue = ();
140
	type ChainId = ();
141
	type OnChargeTransaction = ();
142
	type BlockGasLimit = BlockGasLimit;
143
	type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping<Self>;
144
	type FindAuthor = ();
145
	type OnCreate = ();
146
	type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
147
	type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
148
	type Timestamp = Timestamp;
149
	type WeightInfo = ();
150
	type AccountProvider = FrameSystemAccountProvider<Test>;
151
	type CreateOriginFilter = ();
152
	type CreateInnerOriginFilter = ();
153
}
154

            
155
parameter_types! {
156
	pub const AssetDeposit: u128 = 1;
157
	pub const MetadataDepositBase: u128 = 1;
158
	pub const MetadataDepositPerByte: u128 = 1;
159
	pub const ApprovalDeposit: u128 = 1;
160
	pub const AssetsStringLimit: u32 = 50;
161
	pub const AssetAccountDeposit: u128 = 1;
162
}
163

            
164
impl Config for Test {
165
	type WeightInfo = ();
166
}
167

            
168
// Constants for test accounts
169
pub const ALITH: AccountId = MockAccount(H160([1; 20]));
170
pub const BOB: AccountId = MockAccount(H160([2; 20]));
171

            
172
pub const PARA_A: AccountId = MockAccount(H160([2; 20]));
173
pub const PARA_B: AccountId = MockAccount(H160([2; 20]));
174
pub const PARA_C: AccountId = MockAccount(H160([2; 20]));
175

            
176
/// Externality builder for pallet migration's mock runtime
177
#[allow(dead_code)]
178
pub(crate) struct ExtBuilder {
179
	// endowed accounts with balances
180
	balances: Vec<(AccountId, Balance)>,
181
}
182

            
183
impl Default for ExtBuilder {
184
	#[allow(dead_code)]
185
2
	fn default() -> ExtBuilder {
186
2
		ExtBuilder {
187
2
			balances: vec![(ALITH, 1000), (BOB, 1000)],
188
2
		}
189
2
	}
190
}
191

            
192
impl ExtBuilder {
193
	#[allow(dead_code)]
194
2
	pub(crate) fn build(self) -> sp_io::TestExternalities {
195
2
		let mut storage = frame_system::GenesisConfig::<Test>::default()
196
2
			.build_storage()
197
2
			.expect("Frame system builds valid default genesis config");
198
2

            
199
2
		pallet_balances::GenesisConfig::<Test> {
200
2
			balances: self.balances,
201
2
			dev_accounts: None,
202
2
		}
203
2
		.assimilate_storage(&mut storage)
204
2
		.expect("Pallet balances storage can be assimilated");
205
2

            
206
2
		let mut ext = sp_io::TestExternalities::new(storage);
207
2
		ext.execute_with(|| System::set_block_number(1));
208
2
		ext
209
2
	}
210
}