git.delta.rocks / unique-network / refs/commits / 48ebb54c2948

difftreelog

fix weights in tests

Daniel Shiposha2023-03-27parent: #f2aedb5.patch.diff
in: master

4 files changed

deletedruntime/common/weights.rsdiffbeforeafterboth
--- a/runtime/common/weights.rs
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-use core::marker::PhantomData;
-use frame_support::{weights::Weight};
-use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};
-
-use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};
-use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};
-
-#[cfg(feature = "refungible")]
-use pallet_refungible::{
-	Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,
-};
-use up_data_structs::{CreateItemExData, CreateItemData};
-
-pub mod xcm;
-
-macro_rules! max_weight_of {
-	($method:ident ( $($args:tt)* )) => {{
-		let max_weight = <FungibleWeights<T>>::$method($($args)*)
-			.max(<NonfungibleWeights<T>>::$method($($args)*));
-
-		#[cfg(feature = "refungible")]
-		let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));
-
-		max_weight
-	}};
-}
-
-#[cfg(not(feature = "refungible"))]
-pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}
-
-#[cfg(not(feature = "refungible"))]
-impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}
-
-#[cfg(feature = "refungible")]
-pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}
-
-#[cfg(feature = "refungible")]
-impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}
-
-pub struct CommonWeights<T>(PhantomData<T>);
-
-impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>
-where
-	T: CommonWeightConfigs,
-{
-	fn create_item(data: &CreateItemData) -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(create_item(data))
-	}
-
-	fn create_multiple_items(data: &[CreateItemData]) -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))
-	}
-
-	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))
-	}
-
-	fn burn_item() -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(burn_item())
-	}
-
-	fn set_collection_properties(amount: u32) -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))
-	}
-
-	fn delete_collection_properties(amount: u32) -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))
-	}
-
-	fn set_token_properties(amount: u32) -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))
-	}
-
-	fn delete_token_properties(amount: u32) -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))
-	}
-
-	fn set_token_property_permissions(amount: u32) -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))
-	}
-
-	fn transfer() -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(transfer())
-	}
-
-	fn approve() -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(approve())
-	}
-
-	fn approve_from() -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(approve_from())
-	}
-
-	fn transfer_from() -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(transfer_from())
-	}
-
-	fn burn_from() -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(burn_from())
-	}
-
-	fn burn_recursively_self_raw() -> Weight {
-		max_weight_of!(burn_recursively_self_raw())
-	}
-
-	fn burn_recursively_breadth_raw(amount: u32) -> Weight {
-		max_weight_of!(burn_recursively_breadth_raw(amount))
-	}
-
-	fn token_owner() -> Weight {
-		max_weight_of!(token_owner())
-	}
-
-	fn set_allowance_for_all() -> Weight {
-		max_weight_of!(set_allowance_for_all())
-	}
-
-	fn force_repair_item() -> Weight {
-		max_weight_of!(force_repair_item())
-	}
-}
-
-#[cfg(feature = "refungible")]
-impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>
-where
-	T: FungibleConfig + NonfungibleConfig + RefungibleConfig,
-{
-	fn repartition() -> Weight {
-		dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()
-	}
-}
-
-#[cfg(not(feature = "refungible"))]
-impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>
-where
-	T: FungibleConfig + NonfungibleConfig,
-{
-	fn repartition() -> Weight {
-		dispatch_weight::<T>()
-	}
-}
addedruntime/common/weights/mod.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/weights/mod.rs
@@ -0,0 +1,157 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+use core::marker::PhantomData;
+use frame_support::{weights::Weight};
+use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};
+
+use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};
+use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};
+
+#[cfg(feature = "refungible")]
+use pallet_refungible::{
+	Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,
+};
+use up_data_structs::{CreateItemExData, CreateItemData};
+
+pub mod xcm;
+
+macro_rules! max_weight_of {
+	($method:ident ( $($args:tt)* )) => {{
+		let max_weight = <FungibleWeights<T>>::$method($($args)*)
+			.max(<NonfungibleWeights<T>>::$method($($args)*));
+
+		#[cfg(feature = "refungible")]
+		let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));
+
+		max_weight
+	}};
+}
+
+#[cfg(not(feature = "refungible"))]
+pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}
+
+#[cfg(not(feature = "refungible"))]
+impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}
+
+#[cfg(feature = "refungible")]
+pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}
+
+#[cfg(feature = "refungible")]
+impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}
+
+pub struct CommonWeights<T>(PhantomData<T>);
+
+impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>
+where
+	T: CommonWeightConfigs,
+{
+	fn create_item(data: &CreateItemData) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(create_item(data))
+	}
+
+	fn create_multiple_items(data: &[CreateItemData]) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))
+	}
+
+	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))
+	}
+
+	fn burn_item() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(burn_item())
+	}
+
+	fn set_collection_properties(amount: u32) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))
+	}
+
+	fn delete_collection_properties(amount: u32) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))
+	}
+
+	fn set_token_properties(amount: u32) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))
+	}
+
+	fn delete_token_properties(amount: u32) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))
+	}
+
+	fn set_token_property_permissions(amount: u32) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))
+	}
+
+	fn transfer() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(transfer())
+	}
+
+	fn approve() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(approve())
+	}
+
+	fn approve_from() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(approve_from())
+	}
+
+	fn transfer_from() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(transfer_from())
+	}
+
+	fn burn_from() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(burn_from())
+	}
+
+	fn burn_recursively_self_raw() -> Weight {
+		max_weight_of!(burn_recursively_self_raw())
+	}
+
+	fn burn_recursively_breadth_raw(amount: u32) -> Weight {
+		max_weight_of!(burn_recursively_breadth_raw(amount))
+	}
+
+	fn token_owner() -> Weight {
+		max_weight_of!(token_owner())
+	}
+
+	fn set_allowance_for_all() -> Weight {
+		max_weight_of!(set_allowance_for_all())
+	}
+
+	fn force_repair_item() -> Weight {
+		max_weight_of!(force_repair_item())
+	}
+}
+
+#[cfg(feature = "refungible")]
+impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>
+where
+	T: FungibleConfig + NonfungibleConfig + RefungibleConfig,
+{
+	fn repartition() -> Weight {
+		dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()
+	}
+}
+
+#[cfg(not(feature = "refungible"))]
+impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>
+where
+	T: FungibleConfig + NonfungibleConfig,
+{
+	fn repartition() -> Weight {
+		dispatch_weight::<T>()
+	}
+}
modifiedruntime/tests/Cargo.tomldiffbeforeafterboth
--- a/runtime/tests/Cargo.toml
+++ b/runtime/tests/Cargo.toml
@@ -43,4 +43,5 @@
 evm-coder = { workspace = true }
 up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.39" }
 xcm = { workspace = true }
+pallet-xcm = { workspace = true }
 pallet-configuration = { workspace = true }
modifiedruntime/tests/src/lib.rsdiffbeforeafterboth
before · runtime/tests/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![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	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};35use pallet_ethereum::PostLogContent;36use fp_evm_mapping::EvmBackwardsAddressMapping;37use parity_scale_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.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;5758// Configure a mock runtime to test the pallet.59frame_support::construct_runtime!(60	pub enum Test where61		Block = Block,62		NodeBlock = Block,63		UncheckedExtrinsic = UncheckedExtrinsic,64	{65		System: frame_system,66		Unique: pallet_unique::{Pallet, Call, Storage},67		Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},68		Common: pallet_common::{Pallet, Storage, Event<T>},69		Fungible: pallet_fungible::{Pallet, Storage},70		Refungible: pallet_refungible::{Pallet, Storage},71		Nonfungible: pallet_nonfungible::{Pallet, Storage},72		Structure: pallet_structure::{Pallet, Storage, Event<T>},73		TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},74		Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin},75		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},76	}77);7879parameter_types! {80	pub const BlockHashCount: u64 = 250;81	pub const SS58Prefix: u8 = 42;82}8384impl system::Config for Test {85	type RuntimeEvent = RuntimeEvent;86	type BaseCallFilter = Everything;87	type BlockWeights = ();88	type BlockLength = ();89	type DbWeight = ();90	type RuntimeOrigin = RuntimeOrigin;91	type RuntimeCall = RuntimeCall;92	type Index = u64;93	type BlockNumber = u64;94	type Hash = H256;95	type Hashing = BlakeTwo256;96	type AccountId = u64;97	type Lookup = IdentityLookup<Self::AccountId>;98	type Header = Header;99	type BlockHashCount = BlockHashCount;100	type Version = ();101	type PalletInfo = PalletInfo;102	type AccountData = pallet_balances::AccountData<u64>;103	type OnNewAccount = ();104	type OnKilledAccount = ();105	type SystemWeightInfo = ();106	type SS58Prefix = SS58Prefix;107	type OnSetCode = ();108	type MaxConsumers = ConstU32<16>;109}110111parameter_types! {112	pub const ExistentialDeposit: u64 = 1;113	pub const MaxLocks: u32 = 50;114}115//frame_system::Module<Test>;116impl pallet_balances::Config for Test {117	type RuntimeEvent = RuntimeEvent;118	type AccountStore = System;119	type Balance = u64;120	type DustRemoval = ();121	type ExistentialDeposit = ExistentialDeposit;122	type WeightInfo = ();123	type MaxLocks = MaxLocks;124	type MaxReserves = ();125	type ReserveIdentifier = [u8; 8];126}127128parameter_types! {129	pub const OperationalFeeMultiplier: u8 = 5;130}131132impl pallet_transaction_payment::Config for Test {133	type RuntimeEvent = RuntimeEvent;134	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;135	type LengthToFee = IdentityFee<u64>;136	type WeightToFee = IdentityFee<u64>;137	type FeeMultiplierUpdate = ();138	type OperationalFeeMultiplier = OperationalFeeMultiplier;139}140141parameter_types! {142	pub const MinimumPeriod: u64 = 1;143}144impl pallet_timestamp::Config for Test {145	type Moment = u64;146	type OnTimestampSet = ();147	type MinimumPeriod = MinimumPeriod;148	type WeightInfo = ();149}150151parameter_types! {152	pub const CollectionCreationPrice: u32 = 100;153	pub TreasuryAccountId: u64 = 1234;154	pub EthereumChainId: u32 = 1111;155}156157pub struct TestEvmAddressMapping;158impl AddressMapping<u64> for TestEvmAddressMapping {159	fn into_account_id(_addr: sp_core::H160) -> u64 {160		unimplemented!()161	}162}163164pub struct TestEvmBackwardsAddressMapping;165impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {166	fn from_account_id(_account_id: u64) -> sp_core::H160 {167		unimplemented!()168	}169}170171#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]172pub struct TestCrossAccountId(u64, sp_core::H160, bool);173impl CrossAccountId<u64> for TestCrossAccountId {174	fn as_sub(&self) -> &u64 {175		&self.0176	}177	fn as_eth(&self) -> &sp_core::H160 {178		&self.1179	}180	fn from_sub(sub: u64) -> Self {181		let mut eth = [0; 20];182		eth[12..20].copy_from_slice(&sub.to_be_bytes());183		Self(sub, sp_core::H160(eth), true)184	}185	fn from_eth(eth: sp_core::H160) -> Self {186		let mut sub_raw = [0; 8];187		sub_raw.copy_from_slice(&eth.0[0..8]);188		let sub = u64::from_be_bytes(sub_raw);189		Self(sub, eth, false)190	}191	fn conv_eq(&self, other: &Self) -> bool {192		self.as_sub() == other.as_sub()193	}194	fn is_canonical_substrate(&self) -> bool {195		self.2196	}197}198199impl Default for TestCrossAccountId {200	fn default() -> Self {201		Self::from_sub(0)202	}203}204205parameter_types! {206	pub BlockGasLimit: U256 = 0u32.into();207	pub WeightPerGas: Weight = Weight::from_ref_time(20);208	pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;209}210211impl pallet_ethereum::Config for Test {212	type RuntimeEvent = RuntimeEvent;213	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;214	type PostLogContent = PostBlockAndTxnHashes;215}216217impl pallet_evm::Config for Test {218	type CrossAccountId = TestCrossAccountId;219	type EvmAddressMapping = TestEvmAddressMapping;220	type EvmBackwardsAddressMapping = 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 AddressMapping = TestEvmAddressMapping;228	type Currency = Balances;229	type PrecompilesType = ();230	type PrecompilesValue = ();231	type Runner = pallet_evm::runner::stack::Runner<Self>;232	type ChainId = ConstU64<0>;233	type BlockGasLimit = BlockGasLimit;234	type OnMethodCall = ();235	type OnCreate = ();236	type OnChargeTransaction = ();237	type FindAuthor = ();238	type BlockHashMapping = SubstrateBlockHashMapping<Self>;239	type TransactionValidityHack = ();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}270271parameter_types! {272	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f273	pub const EvmCollectionHelpersAddress: H160 = H160([274		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,275	]);276}277278impl pallet_unique::Config for Test {279	type WeightInfo = ();280	type CommonWeightInfo = CommonWeights<Self>;281	type RefungibleExtensionsWeightInfo = CommonWeights<Self>;282}283284// Build genesis storage according to the mock runtime.285pub fn new_test_ext() -> sp_io::TestExternalities {286	system::GenesisConfig::default()287		.build_storage::<Test>()288		.unwrap()289		.into()290}
after · runtime/tests/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![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	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};35use pallet_ethereum::PostLogContent;36use fp_evm_mapping::EvmBackwardsAddressMapping;37use parity_scale_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;5758// Configure a mock runtime to test the pallet.59frame_support::construct_runtime!(60	pub enum Test where61		Block = Block,62		NodeBlock = Block,63		UncheckedExtrinsic = UncheckedExtrinsic,64	{65		System: frame_system,66		Unique: pallet_unique::{Pallet, Call, Storage},67		Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},68		Common: pallet_common::{Pallet, Storage, Event<T>},69		Fungible: pallet_fungible::{Pallet, Storage},70		Refungible: pallet_refungible::{Pallet, Storage},71		Nonfungible: pallet_nonfungible::{Pallet, Storage},72		Structure: pallet_structure::{Pallet, Storage, Event<T>},73		TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},74		Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin},75		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},76	}77);7879parameter_types! {80	pub const BlockHashCount: u64 = 250;81	pub const SS58Prefix: u8 = 42;82}8384impl system::Config for Test {85	type RuntimeEvent = RuntimeEvent;86	type BaseCallFilter = Everything;87	type BlockWeights = ();88	type BlockLength = ();89	type DbWeight = ();90	type RuntimeOrigin = RuntimeOrigin;91	type RuntimeCall = RuntimeCall;92	type Index = u64;93	type BlockNumber = u64;94	type Hash = H256;95	type Hashing = BlakeTwo256;96	type AccountId = u64;97	type Lookup = IdentityLookup<Self::AccountId>;98	type Header = Header;99	type BlockHashCount = BlockHashCount;100	type Version = ();101	type PalletInfo = PalletInfo;102	type AccountData = pallet_balances::AccountData<u64>;103	type OnNewAccount = ();104	type OnKilledAccount = ();105	type SystemWeightInfo = ();106	type SS58Prefix = SS58Prefix;107	type OnSetCode = ();108	type MaxConsumers = ConstU32<16>;109}110111parameter_types! {112	pub const ExistentialDeposit: u64 = 1;113	pub const MaxLocks: u32 = 50;114}115//frame_system::Module<Test>;116impl pallet_balances::Config for Test {117	type RuntimeEvent = RuntimeEvent;118	type AccountStore = System;119	type Balance = u64;120	type DustRemoval = ();121	type ExistentialDeposit = ExistentialDeposit;122	type WeightInfo = ();123	type MaxLocks = MaxLocks;124	type MaxReserves = ();125	type ReserveIdentifier = [u8; 8];126}127128parameter_types! {129	pub const OperationalFeeMultiplier: u8 = 5;130}131132impl pallet_transaction_payment::Config for Test {133	type RuntimeEvent = RuntimeEvent;134	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;135	type LengthToFee = IdentityFee<u64>;136	type WeightToFee = IdentityFee<u64>;137	type FeeMultiplierUpdate = ();138	type OperationalFeeMultiplier = OperationalFeeMultiplier;139}140141parameter_types! {142	pub const MinimumPeriod: u64 = 1;143}144impl pallet_timestamp::Config for Test {145	type Moment = u64;146	type OnTimestampSet = ();147	type MinimumPeriod = MinimumPeriod;148	type WeightInfo = ();149}150151parameter_types! {152	pub const CollectionCreationPrice: u32 = 100;153	pub TreasuryAccountId: u64 = 1234;154	pub EthereumChainId: u32 = 1111;155}156157pub struct TestEvmAddressMapping;158impl AddressMapping<u64> for TestEvmAddressMapping {159	fn into_account_id(_addr: sp_core::H160) -> u64 {160		unimplemented!()161	}162}163164pub struct TestEvmBackwardsAddressMapping;165impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {166	fn from_account_id(_account_id: u64) -> sp_core::H160 {167		unimplemented!()168	}169}170171#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]172pub struct TestCrossAccountId(u64, sp_core::H160, bool);173impl CrossAccountId<u64> for TestCrossAccountId {174	fn as_sub(&self) -> &u64 {175		&self.0176	}177	fn as_eth(&self) -> &sp_core::H160 {178		&self.1179	}180	fn from_sub(sub: u64) -> Self {181		let mut eth = [0; 20];182		eth[12..20].copy_from_slice(&sub.to_be_bytes());183		Self(sub, sp_core::H160(eth), true)184	}185	fn from_eth(eth: sp_core::H160) -> Self {186		let mut sub_raw = [0; 8];187		sub_raw.copy_from_slice(&eth.0[0..8]);188		let sub = u64::from_be_bytes(sub_raw);189		Self(sub, eth, false)190	}191	fn conv_eq(&self, other: &Self) -> bool {192		self.as_sub() == other.as_sub()193	}194	fn is_canonical_substrate(&self) -> bool {195		self.2196	}197}198199impl Default for TestCrossAccountId {200	fn default() -> Self {201		Self::from_sub(0)202	}203}204205parameter_types! {206	pub BlockGasLimit: U256 = 0u32.into();207	pub WeightPerGas: Weight = Weight::from_ref_time(20);208	pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;209}210211impl pallet_ethereum::Config for Test {212	type RuntimeEvent = RuntimeEvent;213	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;214	type PostLogContent = PostBlockAndTxnHashes;215}216217impl pallet_evm::Config for Test {218	type CrossAccountId = TestCrossAccountId;219	type EvmAddressMapping = TestEvmAddressMapping;220	type EvmBackwardsAddressMapping = 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 AddressMapping = TestEvmAddressMapping;228	type Currency = Balances;229	type PrecompilesType = ();230	type PrecompilesValue = ();231	type Runner = pallet_evm::runner::stack::Runner<Self>;232	type ChainId = ConstU64<0>;233	type BlockGasLimit = BlockGasLimit;234	type OnMethodCall = ();235	type OnCreate = ();236	type OnChargeTransaction = ();237	type FindAuthor = ();238	type BlockHashMapping = SubstrateBlockHashMapping<Self>;239	type TransactionValidityHack = ();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}270271parameter_types! {272	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f273	pub const EvmCollectionHelpersAddress: H160 = H160([274		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,275	]);276}277278impl pallet_unique::Config for Test {279	type WeightInfo = ();280	type CommonWeightInfo = CommonWeights<Self>;281	type RefungibleExtensionsWeightInfo = CommonWeights<Self>;282}283284// Build genesis storage according to the mock runtime.285pub fn new_test_ext() -> sp_io::TestExternalities {286	system::GenesisConfig::default()287		.build_storage::<Test>()288		.unwrap()289		.into()290}