1234567891011121314151617#![allow(clippy::from_over_into)]1819use frame_support::{20 pallet_prelude::Weight,21 parameter_types,22 traits::{fungible::Inspect, ConstU32, ConstU64, Everything},23 weights::IdentityFee,24};25use frame_system as system;26use pallet_ethereum::PostLogContent;27use pallet_evm::{28 account::CrossAccountId, AddressMapping, BackwardsAddressMapping, EnsureAddressNever,29 SubstrateBlockHashMapping,30};31use pallet_transaction_payment::CurrencyAdapter;32use parity_scale_codec::{Decode, Encode, MaxEncodedLen};33use scale_info::TypeInfo;34use sp_core::{H160, H256, U256};35use sp_runtime::{36 testing::Header,37 traits::{BlakeTwo256, IdentityLookup},38};39use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4041#[path = "../../common/dispatch.rs"]42mod dispatch;4344use dispatch::CollectionDispatchT;4546#[path = "../../common/weights/mod.rs"]47mod weights;4849use weights::CommonWeights;5051type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;52type Block = frame_system::mocking::MockBlock<Test>;5354#[cfg(test)]55mod tests;565758frame_support::construct_runtime!(59 pub enum Test {60 System: frame_system,61 Timestamp: pallet_timestamp,62 Unique: pallet_unique,63 Balances: pallet_balances,64 Common: pallet_common,65 Fungible: pallet_fungible,66 Refungible: pallet_refungible,67 Nonfungible: pallet_nonfungible,68 Structure: pallet_structure,69 TransactionPayment: pallet_transaction_payment,70 Ethereum: pallet_ethereum,71 EVM: pallet_evm,72 }73);7475parameter_types! {76 pub const BlockHashCount: u64 = 250;77 pub const SS58Prefix: u8 = 42;78}7980impl system::Config for Test {81 type RuntimeEvent = RuntimeEvent;82 type BaseCallFilter = Everything;83 type BlockWeights = ();84 type BlockLength = ();85 type DbWeight = ();86 type RuntimeOrigin = RuntimeOrigin;87 type RuntimeCall = RuntimeCall;88 type Nonce = u64;89 type Hash = H256;90 type Hashing = BlakeTwo256;91 type AccountId = u64;92 type Lookup = IdentityLookup<Self::AccountId>;93 type BlockHashCount = BlockHashCount;94 type Version = ();95 type PalletInfo = PalletInfo;96 type AccountData = pallet_balances::AccountData<u64>;97 type OnNewAccount = ();98 type OnKilledAccount = ();99 type SystemWeightInfo = ();100 type SS58Prefix = SS58Prefix;101 type OnSetCode = ();102 type MaxConsumers = ConstU32<16>;103}104105parameter_types! {106 pub const ExistentialDeposit: u64 = 1;107 pub const MaxLocks: u32 = 50;108}109110impl pallet_balances::Config for Test {111 type RuntimeEvent = RuntimeEvent;112 type AccountStore = System;113 type Balance = u64;114 type DustRemoval = ();115 type ExistentialDeposit = ExistentialDeposit;116 type WeightInfo = ();117 type MaxLocks = MaxLocks;118 type MaxReserves = ();119 type ReserveIdentifier = [u8; 8];120 type MaxFreezes = MaxLocks;121 type FreezeIdentifier = [u8; 8];122 type MaxHolds = MaxLocks;123}124125parameter_types! {126 pub const OperationalFeeMultiplier: u8 = 5;127}128129impl pallet_transaction_payment::Config for Test {130 type RuntimeEvent = RuntimeEvent;131 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;132 type LengthToFee = IdentityFee<u64>;133 type WeightToFee = IdentityFee<u64>;134 type FeeMultiplierUpdate = ();135 type OperationalFeeMultiplier = OperationalFeeMultiplier;136}137138parameter_types! {139 pub const MinimumPeriod: u64 = 1;140}141impl pallet_timestamp::Config for Test {142 type Moment = u64;143 type OnTimestampSet = ();144 type MinimumPeriod = MinimumPeriod;145 type WeightInfo = ();146}147148parameter_types! {149 pub const CollectionCreationPrice: u32 = 100;150 pub TreasuryAccountId: u64 = 1234;151 pub EthereumChainId: u32 = 1111;152}153154pub struct TestEvmAddressMapping;155impl AddressMapping<u64> for TestEvmAddressMapping {156 fn into_account_id(_addr: sp_core::H160) -> u64 {157 unimplemented!()158 }159}160161pub struct TestEvmBackwardsAddressMapping;162impl BackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {163 fn from_account_id(_account_id: u64) -> sp_core::H160 {164 unimplemented!()165 }166}167168#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]169pub struct TestCrossAccountId(u64, sp_core::H160, bool);170impl CrossAccountId<u64> for TestCrossAccountId {171 fn as_sub(&self) -> &u64 {172 &self.0173 }174 fn as_eth(&self) -> &sp_core::H160 {175 &self.1176 }177 fn from_sub(sub: u64) -> Self {178 let mut eth = [0; 20];179 eth[12..20].copy_from_slice(&sub.to_be_bytes());180 Self(sub, sp_core::H160(eth), true)181 }182 fn from_eth(eth: sp_core::H160) -> Self {183 let mut sub_raw = [0; 8];184 sub_raw.copy_from_slice(ð.0[0..8]);185 let sub = u64::from_be_bytes(sub_raw);186 Self(sub, eth, false)187 }188 fn conv_eq(&self, other: &Self) -> bool {189 self.as_sub() == other.as_sub()190 }191 fn is_canonical_substrate(&self) -> bool {192 self.2193 }194}195196impl Default for TestCrossAccountId {197 fn default() -> Self {198 Self::from_sub(0)199 }200}201202parameter_types! {203 pub BlockGasLimit: U256 = 0u32.into();204 pub WeightPerGas: Weight = Weight::from_parts(20, 0);205 pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;206}207208impl pallet_ethereum::Config for Test {209 type RuntimeEvent = RuntimeEvent;210 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;211 type PostLogContent = PostBlockAndTxnHashes;212 type ExtraDataLength = ConstU32<32>;213}214215impl pallet_evm::Config for Test {216 type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;217 type CrossAccountId = TestCrossAccountId;218 type AddressMapping = TestEvmAddressMapping;219 type BackwardsAddressMapping = TestEvmBackwardsAddressMapping;220 type RuntimeEvent = RuntimeEvent;221 type FeeCalculator = ();222 type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;223 type WeightPerGas = WeightPerGas;224 type CallOrigin = EnsureAddressNever<Self>;225 type WithdrawOrigin = EnsureAddressNever<Self>;226 type Currency = Balances;227 type PrecompilesType = ();228 type PrecompilesValue = ();229 type Runner = pallet_evm::runner::stack::Runner<Self>;230 type ChainId = ConstU64<0>;231 type BlockGasLimit = BlockGasLimit;232 type OnMethodCall = ();233 type OnCreate = ();234 type OnChargeTransaction = ();235 type FindAuthor = ();236 type BlockHashMapping = SubstrateBlockHashMapping<Self>;237 type Timestamp = Timestamp;238 type GasLimitPovSizeRatio = ConstU64<0>;239}240impl pallet_evm_coder_substrate::Config for Test {}241242impl pallet_common::Config for Test {243 type WeightInfo = ();244 type RuntimeEvent = RuntimeEvent;245 type Currency = Balances;246 type CollectionCreationPrice = CollectionCreationPrice;247 type TreasuryAccountId = TreasuryAccountId;248249 type CollectionDispatch = CollectionDispatchT<Self>;250 type EvmTokenAddressMapping = EvmTokenAddressMapping;251 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;252 type ContractAddress = EvmCollectionHelpersAddress;253}254255impl pallet_structure::Config for Test {256 type WeightInfo = ();257 type RuntimeEvent = RuntimeEvent;258 type RuntimeCall = RuntimeCall;259}260impl pallet_fungible::Config for Test {261 type WeightInfo = ();262}263impl pallet_refungible::Config for Test {264 type WeightInfo = ();265}266impl pallet_nonfungible::Config for Test {267 type WeightInfo = ();268}269parameter_types! {270 pub const Decimals: u8 = 18;271 pub Name: String = "Test".to_string();272 pub Symbol: String = "TST".to_string();273}274impl pallet_balances_adapter::Config for Test {275 type Inspect = Balances;276 type Mutate = Balances;277 type CurrencyBalance = <Balances as Inspect<Self::AccountId>>::Balance;278 type Decimals = Decimals;279 type Name = Name;280 type Symbol = Symbol;281 type WeightInfo = ();282}283284parameter_types! {285 286 pub const EvmCollectionHelpersAddress: H160 = H160([287 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,288 ]);289}290291impl pallet_unique::Config for Test {292 type WeightInfo = ();293 type CommonWeightInfo = CommonWeights<Self>;294 type RefungibleExtensionsWeightInfo = CommonWeights<Self>;295}296297298pub fn new_test_ext() -> sp_io::TestExternalities {299 system::GenesisConfig::default()300 .build_storage::<Test>()301 .unwrap()302 .into()303}