1234567891011121314151617#![allow(clippy::from_over_into)]1819use sp_core::{H160, H256, U256};20use frame_support::{21 parameter_types,22 traits::{Everything, ConstU32, ConstU64},23 weights::IdentityFee,24};25use sp_runtime::{26 traits::{BlakeTwo256, IdentityLookup},27 testing::Header,28};29use pallet_transaction_payment::{CurrencyAdapter};30use frame_system as system;31use pallet_evm::{32 AddressMapping, account::CrossAccountId, EnsureAddressNever, SubstrateBlockHashMapping,33};34use fp_evm_mapping::EvmBackwardsAddressMapping;35use parity_scale_codec::{Encode, Decode, MaxEncodedLen};36use scale_info::TypeInfo;3738use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};3940#[path = "../../common/dispatch.rs"]41mod dispatch;4243use dispatch::CollectionDispatchT;4445#[path = "../../common/weights.rs"]46mod weights;4748use weights::CommonWeights;4950type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;51type Block = frame_system::mocking::MockBlock<Test>;5253#[cfg(test)]54mod tests;555657frame_support::construct_runtime!(58 pub enum Test where59 Block = Block,60 NodeBlock = Block,61 UncheckedExtrinsic = UncheckedExtrinsic,62 {63 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},64 Unique: pallet_unique::{Pallet, Call, Storage},65 Balances: pallet_balances::{Pallet, Call, Storage},66 Common: pallet_common::{Pallet, Storage, Event<T>},67 Fungible: pallet_fungible::{Pallet, Storage},68 Refungible: pallet_refungible::{Pallet, Storage},69 Nonfungible: pallet_nonfungible::{Pallet, Storage},70 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},71 }72);7374parameter_types! {75 pub const BlockHashCount: u64 = 250;76 pub const SS58Prefix: u8 = 42;77}7879impl system::Config for Test {80 type BaseCallFilter = Everything;81 type BlockWeights = ();82 type BlockLength = ();83 type DbWeight = ();84 type Origin = Origin;85 type Call = Call;86 type Index = u64;87 type BlockNumber = u64;88 type Hash = H256;89 type Hashing = BlakeTwo256;90 type AccountId = u64;91 type Lookup = IdentityLookup<Self::AccountId>;92 type Header = Header;93 type Event = ();94 type BlockHashCount = BlockHashCount;95 type Version = ();96 type PalletInfo = PalletInfo;97 type AccountData = pallet_balances::AccountData<u64>;98 type OnNewAccount = ();99 type OnKilledAccount = ();100 type SystemWeightInfo = ();101 type SS58Prefix = SS58Prefix;102 type OnSetCode = ();103 type MaxConsumers = ConstU32<16>;104}105106parameter_types! {107 pub const ExistentialDeposit: u64 = 1;108 pub const MaxLocks: u32 = 50;109}110111impl pallet_balances::Config for Test {112 type AccountStore = System;113 type Balance = u64;114 type DustRemoval = ();115 type Event = ();116 type ExistentialDeposit = ExistentialDeposit;117 type WeightInfo = ();118 type MaxLocks = MaxLocks;119 type MaxReserves = ();120 type ReserveIdentifier = [u8; 8];121}122123parameter_types! {124 pub const OperationalFeeMultiplier: u8 = 5;125}126127impl pallet_transaction_payment::Config for Test {128 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;129 type LengthToFee = IdentityFee<u64>;130 type WeightToFee = IdentityFee<u64>;131 type FeeMultiplierUpdate = ();132 type OperationalFeeMultiplier = OperationalFeeMultiplier;133}134135parameter_types! {136 pub const MinimumPeriod: u64 = 1;137}138impl pallet_timestamp::Config for Test {139 type Moment = u64;140 type OnTimestampSet = ();141 type MinimumPeriod = MinimumPeriod;142 type WeightInfo = ();143}144145parameter_types! {146 pub const CollectionCreationPrice: u32 = 100;147 pub TreasuryAccountId: u64 = 1234;148 pub EthereumChainId: u32 = 1111;149}150151pub struct TestEvmAddressMapping;152impl AddressMapping<u64> for TestEvmAddressMapping {153 fn into_account_id(_addr: sp_core::H160) -> u64 {154 unimplemented!()155 }156}157158pub struct TestEvmBackwardsAddressMapping;159impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {160 fn from_account_id(_account_id: u64) -> sp_core::H160 {161 unimplemented!()162 }163}164165#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]166pub struct TestCrossAccountId(u64, sp_core::H160);167impl CrossAccountId<u64> for TestCrossAccountId {168 fn as_sub(&self) -> &u64 {169 &self.0170 }171 fn as_eth(&self) -> &sp_core::H160 {172 &self.1173 }174 fn from_sub(sub: u64) -> Self {175 let mut eth = [0; 20];176 eth[12..20].copy_from_slice(&sub.to_be_bytes());177 Self(sub, sp_core::H160(eth))178 }179 fn from_eth(eth: sp_core::H160) -> Self {180 let mut sub_raw = [0; 8];181 sub_raw.copy_from_slice(ð.0[0..8]);182 let sub = u64::from_be_bytes(sub_raw);183 Self(sub, eth)184 }185 fn conv_eq(&self, other: &Self) -> bool {186 self.as_sub() == other.as_sub()187 }188}189190impl Default for TestCrossAccountId {191 fn default() -> Self {192 Self::from_sub(0)193 }194}195196parameter_types! {197 pub BlockGasLimit: U256 = 0u32.into();198}199200impl pallet_evm::Config for Test {201 type Event = ();202 type FeeCalculator = ();203 type GasWeightMapping = ();204 type CallOrigin = EnsureAddressNever<Self::CrossAccountId>;205 type WithdrawOrigin = EnsureAddressNever<Self::CrossAccountId>;206 type AddressMapping = TestEvmAddressMapping;207 type Currency = Balances;208 type PrecompilesType = ();209 type PrecompilesValue = ();210 type Runner = pallet_evm::runner::stack::Runner<Self>;211 type ChainId = ConstU64<0>;212 type BlockGasLimit = BlockGasLimit;213 type OnMethodCall = ();214 type OnCreate = ();215 type OnChargeTransaction = ();216 type FindAuthor = ();217 type BlockHashMapping = SubstrateBlockHashMapping<Self>;218 type TransactionValidityHack = ();219}220impl pallet_evm_coder_substrate::Config for Test {}221222impl pallet_common::Config for Test {223 type WeightInfo = ();224 type Event = ();225 type Currency = Balances;226 type CollectionCreationPrice = CollectionCreationPrice;227 type TreasuryAccountId = TreasuryAccountId;228229 type CollectionDispatch = CollectionDispatchT<Self>;230 type EvmTokenAddressMapping = EvmTokenAddressMapping;231 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;232 type ContractAddress = EvmCollectionHelpersAddress;233}234235impl pallet_evm::account::Config for Test {236 type CrossAccountId = TestCrossAccountId;237 type EvmAddressMapping = TestEvmAddressMapping;238 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;239}240241impl pallet_structure::Config for Test {242 type WeightInfo = ();243 type Event = ();244 type Call = Call;245}246impl pallet_fungible::Config for Test {247 type WeightInfo = ();248}249impl pallet_refungible::Config for Test {250 type WeightInfo = ();251}252impl pallet_nonfungible::Config for Test {253 type WeightInfo = ();254}255256parameter_types! {257 258 pub const EvmCollectionHelpersAddress: H160 = H160([259 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,260 ]);261}262263impl pallet_unique::Config for Test {264 type Event = ();265 type WeightInfo = ();266 type CommonWeightInfo = CommonWeights<Self>;267 type RefungibleExtensionsWeightInfo = CommonWeights<Self>;268}269270271pub fn new_test_ext() -> sp_io::TestExternalities {272 system::GenesisConfig::default()273 .build_storage::<Test>()274 .unwrap()275 .into()276}