1234567891011121314151617#![allow(clippy::from_over_into)]1819use sp_core::{H160, H256, U256};20use frame_support::{21 parameter_types,22 traits::{Everything, ConstU32, ConstU64, fungible::Inspect},23 weights::IdentityFee,24 pallet_prelude::Weight,25};26use sp_runtime::{27 traits::{BlakeTwo256, IdentityLookup},28 testing::Header,29};30use pallet_transaction_payment::CurrencyAdapter;31use frame_system as system;32use pallet_evm::{33 AddressMapping, account::CrossAccountId, EnsureAddressNever, SubstrateBlockHashMapping,34 BackwardsAddressMapping,35};36use pallet_ethereum::PostLogContent;37use codec::{Encode, Decode, MaxEncodedLen};38use scale_info::TypeInfo;3940use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4142#[path = "../../common/dispatch.rs"]43mod dispatch;4445use dispatch::CollectionDispatchT;4647#[path = "../../common/weights/mod.rs"]48mod weights;4950use weights::CommonWeights;5152type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;53type Block = frame_system::mocking::MockBlock<Test>;5455#[cfg(test)]56mod tests;575859frame_support::construct_runtime!(60 pub enum Test {61 System: frame_system,62 Timestamp: pallet_timestamp,63 Unique: pallet_unique,64 Balances: pallet_balances,65 Common: pallet_common,66 Fungible: pallet_fungible,67 Refungible: pallet_refungible,68 Nonfungible: pallet_nonfungible,69 Structure: pallet_structure,70 TransactionPayment: pallet_transaction_payment,71 Ethereum: pallet_ethereum,72 EVM: pallet_evm,73 }74);7576parameter_types! {77 pub const BlockHashCount: u64 = 250;78 pub const SS58Prefix: u8 = 42;79}8081impl system::Config for Test {82 type RuntimeEvent = RuntimeEvent;83 type BaseCallFilter = Everything;84 type BlockWeights = ();85 type BlockLength = ();86 type DbWeight = ();87 type RuntimeOrigin = RuntimeOrigin;88 type RuntimeCall = RuntimeCall;89 type Nonce = u64;90 type Hash = H256;91 type Hashing = BlakeTwo256;92 type AccountId = u64;93 type Lookup = IdentityLookup<Self::AccountId>;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 RuntimeEvent = RuntimeEvent;113 type AccountStore = System;114 type Balance = u64;115 type DustRemoval = ();116 type ExistentialDeposit = ExistentialDeposit;117 type WeightInfo = ();118 type MaxLocks = MaxLocks;119 type MaxReserves = ();120 type ReserveIdentifier = [u8; 8];121 type MaxFreezes = MaxLocks;122 type FreezeIdentifier = [u8; 8];123 type MaxHolds = MaxLocks;124}125126parameter_types! {127 pub const OperationalFeeMultiplier: u8 = 5;128}129130impl pallet_transaction_payment::Config for Test {131 type RuntimeEvent = RuntimeEvent;132 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;133 type LengthToFee = IdentityFee<u64>;134 type WeightToFee = IdentityFee<u64>;135 type FeeMultiplierUpdate = ();136 type OperationalFeeMultiplier = OperationalFeeMultiplier;137}138139parameter_types! {140 pub const MinimumPeriod: u64 = 1;141}142impl pallet_timestamp::Config for Test {143 type Moment = u64;144 type OnTimestampSet = ();145 type MinimumPeriod = MinimumPeriod;146 type WeightInfo = ();147}148149parameter_types! {150 pub const CollectionCreationPrice: u32 = 100;151 pub TreasuryAccountId: u64 = 1234;152 pub EthereumChainId: u32 = 1111;153}154155pub struct TestEvmAddressMapping;156impl AddressMapping<u64> for TestEvmAddressMapping {157 fn into_account_id(_addr: sp_core::H160) -> u64 {158 unimplemented!()159 }160}161162pub struct TestEvmBackwardsAddressMapping;163impl BackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {164 fn from_account_id(_account_id: u64) -> sp_core::H160 {165 unimplemented!()166 }167}168169#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]170pub struct TestCrossAccountId(u64, sp_core::H160, bool);171impl CrossAccountId<u64> for TestCrossAccountId {172 fn as_sub(&self) -> &u64 {173 &self.0174 }175 fn as_eth(&self) -> &sp_core::H160 {176 &self.1177 }178 fn from_sub(sub: u64) -> Self {179 let mut eth = [0; 20];180 eth[12..20].copy_from_slice(&sub.to_be_bytes());181 Self(sub, sp_core::H160(eth), true)182 }183 fn from_eth(eth: sp_core::H160) -> Self {184 let mut sub_raw = [0; 8];185 sub_raw.copy_from_slice(ð.0[0..8]);186 let sub = u64::from_be_bytes(sub_raw);187 Self(sub, eth, false)188 }189 fn conv_eq(&self, other: &Self) -> bool {190 self.as_sub() == other.as_sub()191 }192 fn is_canonical_substrate(&self) -> bool {193 self.2194 }195}196197impl Default for TestCrossAccountId {198 fn default() -> Self {199 Self::from_sub(0)200 }201}202203parameter_types! {204 pub BlockGasLimit: U256 = 0u32.into();205 pub WeightPerGas: Weight = Weight::from_parts(20, 0);206 pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;207}208209impl pallet_ethereum::Config for Test {210 type RuntimeEvent = RuntimeEvent;211 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;212 type PostLogContent = PostBlockAndTxnHashes;213 type ExtraDataLength = ConstU32<32>;214}215216impl pallet_evm::Config for Test {217 type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;218 type CrossAccountId = TestCrossAccountId;219 type AddressMapping = TestEvmAddressMapping;220 type BackwardsAddressMapping = TestEvmBackwardsAddressMapping;221 type RuntimeEvent = RuntimeEvent;222 type FeeCalculator = ();223 type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;224 type WeightPerGas = WeightPerGas;225 type CallOrigin = EnsureAddressNever<Self>;226 type WithdrawOrigin = EnsureAddressNever<Self>;227 type Currency = Balances;228 type PrecompilesType = ();229 type PrecompilesValue = ();230 type Runner = pallet_evm::runner::stack::Runner<Self>;231 type ChainId = ConstU64<0>;232 type BlockGasLimit = BlockGasLimit;233 type OnMethodCall = ();234 type OnCreate = ();235 type OnChargeTransaction = ();236 type FindAuthor = ();237 type BlockHashMapping = SubstrateBlockHashMapping<Self>;238 type Timestamp = Timestamp;239 type GasLimitPovSizeRatio = ConstU64<0>;240}241impl pallet_evm_coder_substrate::Config for Test {}242243impl pallet_common::Config for Test {244 type WeightInfo = ();245 type RuntimeEvent = RuntimeEvent;246 type Currency = Balances;247 type CollectionCreationPrice = CollectionCreationPrice;248 type TreasuryAccountId = TreasuryAccountId;249250 type CollectionDispatch = CollectionDispatchT<Self>;251 type EvmTokenAddressMapping = EvmTokenAddressMapping;252 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;253 type ContractAddress = EvmCollectionHelpersAddress;254}255256impl pallet_structure::Config for Test {257 type WeightInfo = ();258 type RuntimeEvent = RuntimeEvent;259 type RuntimeCall = RuntimeCall;260}261impl pallet_fungible::Config for Test {262 type WeightInfo = ();263}264impl pallet_refungible::Config for Test {265 type WeightInfo = ();266}267impl pallet_nonfungible::Config for Test {268 type WeightInfo = ();269}270parameter_types! {271 pub const Decimals: u8 = 18;272 pub Name: String = "Test".to_string();273 pub Symbol: String = "TST".to_string();274}275impl pallet_balances_adapter::Config for Test {276 type Inspect = Balances;277 type Mutate = Balances;278 type CurrencyBalance = <Balances as Inspect<Self::AccountId>>::Balance;279 type Decimals = Decimals;280 type Name = Name;281 type Symbol = Symbol;282 type WeightInfo = ();283}284285parameter_types! {286 287 pub const EvmCollectionHelpersAddress: H160 = H160([288 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,289 ]);290}291292impl pallet_unique::Config for Test {293 type WeightInfo = ();294 type CommonWeightInfo = CommonWeights<Self>;295 type RefungibleExtensionsWeightInfo = CommonWeights<Self>;296}297298299pub fn new_test_ext() -> sp_io::TestExternalities {300 system::GenesisConfig::default()301 .build_storage::<Test>()302 .unwrap()303 .into()304}