1234567891011121314151617#![allow(clippy::from_over_into)]1819use sp_core::{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 unique_runtime_common::{dispatch::CollectionDispatchT, weights::CommonWeights};39use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4041type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;42type Block = frame_system::mocking::MockBlock<Test>;4344#[cfg(test)]45mod tests;464748frame_support::construct_runtime!(49 pub enum Test where50 Block = Block,51 NodeBlock = Block,52 UncheckedExtrinsic = UncheckedExtrinsic,53 {54 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},55 Unique: pallet_unique::{Pallet, Call, Storage},56 Balances: pallet_balances::{Pallet, Call, Storage},57 Common: pallet_common::{Pallet, Storage, Event<T>},58 Fungible: pallet_fungible::{Pallet, Storage},59 Refungible: pallet_refungible::{Pallet, Storage},60 Nonfungible: pallet_nonfungible::{Pallet, Storage},61 }62);6364parameter_types! {65 pub const BlockHashCount: u64 = 250;66 pub const SS58Prefix: u8 = 42;67}6869impl system::Config for Test {70 type BaseCallFilter = Everything;71 type BlockWeights = ();72 type BlockLength = ();73 type DbWeight = ();74 type Origin = Origin;75 type Call = Call;76 type Index = u64;77 type BlockNumber = u64;78 type Hash = H256;79 type Hashing = BlakeTwo256;80 type AccountId = u64;81 type Lookup = IdentityLookup<Self::AccountId>;82 type Header = Header;83 type Event = ();84 type BlockHashCount = BlockHashCount;85 type Version = ();86 type PalletInfo = PalletInfo;87 type AccountData = pallet_balances::AccountData<u64>;88 type OnNewAccount = ();89 type OnKilledAccount = ();90 type SystemWeightInfo = ();91 type SS58Prefix = SS58Prefix;92 type OnSetCode = ();93 type MaxConsumers = ConstU32<16>;94}9596parameter_types! {97 pub const ExistentialDeposit: u64 = 1;98 pub const MaxLocks: u32 = 50;99}100101impl pallet_balances::Config for Test {102 type AccountStore = System;103 type Balance = u64;104 type DustRemoval = ();105 type Event = ();106 type ExistentialDeposit = ExistentialDeposit;107 type WeightInfo = ();108 type MaxLocks = MaxLocks;109 type MaxReserves = ();110 type ReserveIdentifier = [u8; 8];111}112113parameter_types! {114 pub const OperationalFeeMultiplier: u8 = 5;115}116117impl pallet_transaction_payment::Config for Test {118 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;119 type LengthToFee = IdentityFee<u64>;120 type WeightToFee = IdentityFee<u64>;121 type FeeMultiplierUpdate = ();122 type OperationalFeeMultiplier = OperationalFeeMultiplier;123}124125parameter_types! {126 pub const MinimumPeriod: u64 = 1;127}128impl pallet_timestamp::Config for Test {129 type Moment = u64;130 type OnTimestampSet = ();131 type MinimumPeriod = MinimumPeriod;132 type WeightInfo = ();133}134135parameter_types! {136 pub const CollectionCreationPrice: u32 = 100;137 pub TreasuryAccountId: u64 = 1234;138 pub EthereumChainId: u32 = 1111;139}140141pub struct TestEvmAddressMapping;142impl AddressMapping<u64> for TestEvmAddressMapping {143 fn into_account_id(_addr: sp_core::H160) -> u64 {144 unimplemented!()145 }146}147148pub struct TestEvmBackwardsAddressMapping;149impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {150 fn from_account_id(_account_id: u64) -> sp_core::H160 {151 unimplemented!()152 }153}154155#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]156pub struct TestCrossAccountId(u64, sp_core::H160);157impl CrossAccountId<u64> for TestCrossAccountId {158 fn as_sub(&self) -> &u64 {159 &self.0160 }161 fn as_eth(&self) -> &sp_core::H160 {162 &self.1163 }164 fn from_sub(sub: u64) -> Self {165 let mut eth = [0; 20];166 eth[12..20].copy_from_slice(&sub.to_be_bytes());167 Self(sub, sp_core::H160(eth))168 }169 fn from_eth(eth: sp_core::H160) -> Self {170 let mut sub_raw = [0; 8];171 sub_raw.copy_from_slice(ð.0[0..8]);172 let sub = u64::from_be_bytes(sub_raw);173 Self(sub, eth)174 }175 fn conv_eq(&self, other: &Self) -> bool {176 self.as_sub() == other.as_sub()177 }178}179180impl Default for TestCrossAccountId {181 fn default() -> Self {182 Self::from_sub(0)183 }184}185186parameter_types! {187 pub BlockGasLimit: U256 = 0u32.into();188}189190impl pallet_evm::Config for Test {191 type Event = ();192 type FeeCalculator = ();193 type GasWeightMapping = ();194 type CallOrigin = EnsureAddressNever<Self::CrossAccountId>;195 type WithdrawOrigin = EnsureAddressNever<Self::CrossAccountId>;196 type AddressMapping = TestEvmAddressMapping;197 type Currency = Balances;198 type PrecompilesType = ();199 type PrecompilesValue = ();200 type Runner = pallet_evm::runner::stack::Runner<Self>;201 type ChainId = ConstU64<0>;202 type BlockGasLimit = BlockGasLimit;203 type OnMethodCall = ();204 type OnCreate = ();205 type OnChargeTransaction = ();206 type FindAuthor = ();207 type BlockHashMapping = SubstrateBlockHashMapping<Self>;208 type TransactionValidityHack = ();209}210impl pallet_evm_coder_substrate::Config for Test {211 type GasWeightMapping = ();212}213214impl pallet_common::Config for Test {215 type Event = ();216 type Currency = Balances;217 type CollectionCreationPrice = CollectionCreationPrice;218 type TreasuryAccountId = TreasuryAccountId;219220 type CollectionDispatch = CollectionDispatchT<Self>;221 type EvmTokenAddressMapping = EvmTokenAddressMapping;222 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;223}224225impl pallet_evm::account::Config for Test {226 type CrossAccountId = TestCrossAccountId;227 type EvmAddressMapping = TestEvmAddressMapping;228 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;229}230231impl pallet_structure::Config for Test {232 type WeightInfo = ();233 type Event = ();234 type Call = Call;235}236impl pallet_fungible::Config for Test {237 type WeightInfo = ();238}239impl pallet_refungible::Config for Test {240 type WeightInfo = ();241}242impl pallet_nonfungible::Config for Test {243 type WeightInfo = ();244}245246impl pallet_unique::Config for Test {247 type Event = ();248 type WeightInfo = ();249 type CommonWeightInfo = CommonWeights<Self>;250}251252253pub fn new_test_ext() -> sp_io::TestExternalities {254 system::GenesisConfig::default()255 .build_storage::<Test>()256 .unwrap()257 .into()258}