1
// Copyright 2019-2022 PureStake Inc.
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
//! Test utilities
18
use crate as erc20_xcm_bridge;
19

            
20
use frame_support::traits::Everything;
21
use frame_support::{construct_runtime, pallet_prelude::*, parameter_types};
22
use pallet_evm::{AddressMapping, EnsureAddressTruncated, SubstrateBlockHashMapping};
23
use sp_core::{H160, H256, U256};
24
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
25
use sp_runtime::AccountId32;
26

            
27
pub type Balance = u128;
28

            
29
type Block = frame_system::mocking::MockBlock<Test>;
30

            
31
11
construct_runtime!(
32
	pub enum Test
33
	{
34
		System: frame_system,
35
		Balances: pallet_balances,
36
		Timestamp: pallet_timestamp,
37
		EVM: pallet_evm,
38
		Erc20XcmBridge: erc20_xcm_bridge,
39
	}
40
23
);
41

            
42
parameter_types! {
43
	pub const BlockHashCount: u32 = 250;
44
}
45

            
46
impl frame_system::Config for Test {
47
	type BaseCallFilter = Everything;
48
	type DbWeight = ();
49
	type RuntimeOrigin = RuntimeOrigin;
50
	type RuntimeTask = RuntimeTask;
51
	type Nonce = u64;
52
	type Block = Block;
53
	type RuntimeCall = RuntimeCall;
54
	type Hash = H256;
55
	type Hashing = BlakeTwo256;
56
	type AccountId = AccountId32;
57
	type Lookup = IdentityLookup<Self::AccountId>;
58
	type RuntimeEvent = RuntimeEvent;
59
	type BlockHashCount = BlockHashCount;
60
	type Version = ();
61
	type PalletInfo = PalletInfo;
62
	type AccountData = pallet_balances::AccountData<Balance>;
63
	type OnNewAccount = ();
64
	type OnKilledAccount = ();
65
	type SystemWeightInfo = ();
66
	type BlockWeights = ();
67
	type BlockLength = ();
68
	type SS58Prefix = ();
69
	type OnSetCode = ();
70
	type MaxConsumers = frame_support::traits::ConstU32<16>;
71
	type SingleBlockMigrations = ();
72
	type MultiBlockMigrator = ();
73
	type PreInherents = ();
74
	type PostInherents = ();
75
	type PostTransactions = ();
76
}
77

            
78
parameter_types! {
79
	pub const ExistentialDeposit: u128 = 0;
80
}
81
impl pallet_balances::Config for Test {
82
	type MaxReserves = ();
83
	type ReserveIdentifier = [u8; 4];
84
	type MaxLocks = ();
85
	type Balance = Balance;
86
	type RuntimeEvent = RuntimeEvent;
87
	type DustRemoval = ();
88
	type ExistentialDeposit = ExistentialDeposit;
89
	type AccountStore = System;
90
	type WeightInfo = ();
91
	type RuntimeHoldReason = ();
92
	type FreezeIdentifier = ();
93
	type MaxFreezes = ();
94
	type RuntimeFreezeReason = ();
95
}
96

            
97
parameter_types! {
98
	pub const MinimumPeriod: u64 = 6000 / 2;
99
}
100

            
101
impl pallet_timestamp::Config for Test {
102
	type Moment = u64;
103
	type OnTimestampSet = ();
104
	type MinimumPeriod = MinimumPeriod;
105
	type WeightInfo = ();
106
}
107

            
108
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
109
/// Block storage limit in bytes. Set to 40 KB.
110
const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024;
111

            
112
parameter_types! {
113
	pub BlockGasLimit: U256 = U256::from(u64::MAX);
114
	pub const WeightPerGas: Weight = Weight::from_parts(1, 0);
115
	pub GasLimitPovSizeRatio: u64 = {
116
		let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
117
		block_gas_limit.saturating_div(MAX_POV_SIZE)
118
	};
119
	pub GasLimitStorageGrowthRatio: u64 = {
120
		let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
121
		block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT)
122
	};
123
}
124

            
125
pub struct HashedAddressMapping;
126

            
127
impl AddressMapping<AccountId32> for HashedAddressMapping {
128
	fn into_account_id(address: H160) -> AccountId32 {
129
		let mut data = [0u8; 32];
130
		data[0..20].copy_from_slice(&address[..]);
131
		AccountId32::from(Into::<[u8; 32]>::into(data))
132
	}
133
}
134

            
135
impl pallet_evm::Config for Test {
136
	type FeeCalculator = ();
137
	type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
138
	type WeightPerGas = WeightPerGas;
139
	type CallOrigin = EnsureAddressTruncated;
140
	type WithdrawOrigin = EnsureAddressTruncated;
141
	type AddressMapping = HashedAddressMapping;
142
	type Currency = Balances;
143
	type RuntimeEvent = RuntimeEvent;
144
	type PrecompilesType = ();
145
	type PrecompilesValue = ();
146
	type Runner = pallet_evm::runner::stack::Runner<Self>;
147
	type ChainId = ();
148
	type BlockGasLimit = BlockGasLimit;
149
	type OnChargeTransaction = ();
150
	type FindAuthor = ();
151
	type BlockHashMapping = SubstrateBlockHashMapping<Self>;
152
	type OnCreate = ();
153
	type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
154
	type SuicideQuickClearLimit = ConstU32<0>;
155
	type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
156
	type Timestamp = Timestamp;
157
	type WeightInfo = pallet_evm::weights::SubstrateWeight<Test>;
158
}
159

            
160
parameter_types! {
161
	pub Erc20XcmBridgeTransferGasLimit: u64 = 200_000;
162
}
163
impl crate::Config for Test {
164
	type AccountIdConverter = ();
165
	type Erc20MultilocationPrefix = ();
166
	type Erc20TransferGasLimit = Erc20XcmBridgeTransferGasLimit;
167
	type EvmRunner = pallet_evm::runner::stack::Runner<Self>;
168
}