difftreelog
fix unit tests
in: master
1 file changed
runtime/tests/src/lib.rsdiffbeforeafterboth1// 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 fp_evm_mapping::EvmBackwardsAddressMapping;36use parity_scale_codec::{Encode, Decode, MaxEncodedLen};37use scale_info::TypeInfo;3839use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4041#[path = "../../common/dispatch.rs"]42mod dispatch;4344use dispatch::CollectionDispatchT;4546#[path = "../../common/weights.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;5657// Configure a mock runtime to test the pallet.58frame_support::construct_runtime!(59 pub enum Test where60 Block = Block,61 NodeBlock = Block,62 UncheckedExtrinsic = UncheckedExtrinsic,63 {64 System: frame_system,65 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>},66 Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},67 Common: pallet_common::{Pallet, Storage, Event<T>},68 Fungible: pallet_fungible::{Pallet, Storage},69 Refungible: pallet_refungible::{Pallet, Storage},70 Nonfungible: pallet_nonfungible::{Pallet, Storage},71 Structure: pallet_structure::{Pallet, Storage, Event<T>},72 TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},73 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin},74 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},75 }76);7778parameter_types! {79 pub const BlockHashCount: u64 = 250;80 pub const SS58Prefix: u8 = 42;81}8283impl system::Config for Test {84 type RuntimeEvent = RuntimeEvent;85 type BaseCallFilter = Everything;86 type BlockWeights = ();87 type BlockLength = ();88 type DbWeight = ();89 type RuntimeOrigin = RuntimeOrigin;90 type RuntimeCall = RuntimeCall;91 type Index = u64;92 type BlockNumber = u64;93 type Hash = H256;94 type Hashing = BlakeTwo256;95 type AccountId = u64;96 type Lookup = IdentityLookup<Self::AccountId>;97 type Header = Header;98 type BlockHashCount = BlockHashCount;99 type Version = ();100 type PalletInfo = PalletInfo;101 type AccountData = pallet_balances::AccountData<u64>;102 type OnNewAccount = ();103 type OnKilledAccount = ();104 type SystemWeightInfo = ();105 type SS58Prefix = SS58Prefix;106 type OnSetCode = ();107 type MaxConsumers = ConstU32<16>;108}109110parameter_types! {111 pub const ExistentialDeposit: u64 = 1;112 pub const MaxLocks: u32 = 50;113}114//frame_system::Module<Test>;115impl pallet_balances::Config for Test {116 type RuntimeEvent = RuntimeEvent;117 type AccountStore = System;118 type Balance = u64;119 type DustRemoval = ();120 type ExistentialDeposit = ExistentialDeposit;121 type WeightInfo = ();122 type MaxLocks = MaxLocks;123 type MaxReserves = ();124 type ReserveIdentifier = [u8; 8];125}126127parameter_types! {128 pub const OperationalFeeMultiplier: u8 = 5;129}130131impl pallet_transaction_payment::Config for Test {132 type RuntimeEvent = RuntimeEvent;133 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;134 type LengthToFee = IdentityFee<u64>;135 type WeightToFee = IdentityFee<u64>;136 type FeeMultiplierUpdate = ();137 type OperationalFeeMultiplier = OperationalFeeMultiplier;138}139140parameter_types! {141 pub const MinimumPeriod: u64 = 1;142}143impl pallet_timestamp::Config for Test {144 type Moment = u64;145 type OnTimestampSet = ();146 type MinimumPeriod = MinimumPeriod;147 type WeightInfo = ();148}149150parameter_types! {151 pub const CollectionCreationPrice: u32 = 100;152 pub TreasuryAccountId: u64 = 1234;153 pub EthereumChainId: u32 = 1111;154}155156pub struct TestEvmAddressMapping;157impl AddressMapping<u64> for TestEvmAddressMapping {158 fn into_account_id(_addr: sp_core::H160) -> u64 {159 unimplemented!()160 }161}162163pub struct TestEvmBackwardsAddressMapping;164impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {165 fn from_account_id(_account_id: u64) -> sp_core::H160 {166 unimplemented!()167 }168}169170#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]171pub struct TestCrossAccountId(u64, sp_core::H160, bool);172impl CrossAccountId<u64> for TestCrossAccountId {173 fn as_sub(&self) -> &u64 {174 &self.0175 }176 fn as_eth(&self) -> &sp_core::H160 {177 &self.1178 }179 fn from_sub(sub: u64) -> Self {180 let mut eth = [0; 20];181 eth[12..20].copy_from_slice(&sub.to_be_bytes());182 Self(sub, sp_core::H160(eth), true)183 }184 fn from_eth(eth: sp_core::H160) -> Self {185 let mut sub_raw = [0; 8];186 sub_raw.copy_from_slice(ð.0[0..8]);187 let sub = u64::from_be_bytes(sub_raw);188 Self(sub, eth, false)189 }190 fn conv_eq(&self, other: &Self) -> bool {191 self.as_sub() == other.as_sub()192 }193 fn is_canonical_substrate(&self) -> bool {194 self.2195 }196}197198impl Default for TestCrossAccountId {199 fn default() -> Self {200 Self::from_sub(0)201 }202}203204parameter_types! {205 pub BlockGasLimit: U256 = 0u32.into();206 pub WeightPerGas: Weight = Weight::from_ref_time(20);207}208209impl pallet_ethereum::Config for Test {210 type RuntimeEvent = RuntimeEvent;211 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;212}213214impl pallet_evm::Config for Test {215 type CrossAccountId = TestCrossAccountId;216 type EvmAddressMapping = TestEvmAddressMapping;217 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;218 type RuntimeEvent = RuntimeEvent;219 type FeeCalculator = ();220 type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;221 type WeightPerGas = WeightPerGas;222 type CallOrigin = EnsureAddressNever<Self>;223 type WithdrawOrigin = EnsureAddressNever<Self>;224 type AddressMapping = TestEvmAddressMapping;225 type Currency = Balances;226 type PrecompilesType = ();227 type PrecompilesValue = ();228 type Runner = pallet_evm::runner::stack::Runner<Self>;229 type ChainId = ConstU64<0>;230 type BlockGasLimit = BlockGasLimit;231 type OnMethodCall = ();232 type OnCreate = ();233 type OnChargeTransaction = ();234 type FindAuthor = ();235 type BlockHashMapping = SubstrateBlockHashMapping<Self>;236 type TransactionValidityHack = ();237}238impl pallet_evm_coder_substrate::Config for Test {}239240impl pallet_common::Config for Test {241 type WeightInfo = ();242 type RuntimeEvent = RuntimeEvent;243 type Currency = Balances;244 type CollectionCreationPrice = CollectionCreationPrice;245 type TreasuryAccountId = TreasuryAccountId;246247 type CollectionDispatch = CollectionDispatchT<Self>;248 type EvmTokenAddressMapping = EvmTokenAddressMapping;249 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;250 type ContractAddress = EvmCollectionHelpersAddress;251}252253impl pallet_structure::Config for Test {254 type WeightInfo = ();255 type RuntimeEvent = RuntimeEvent;256 type RuntimeCall = RuntimeCall;257}258impl pallet_fungible::Config for Test {259 type WeightInfo = ();260}261impl pallet_refungible::Config for Test {262 type WeightInfo = ();263}264impl pallet_nonfungible::Config for Test {265 type WeightInfo = ();266}267268parameter_types! {269 // 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f270 pub const EvmCollectionHelpersAddress: H160 = H160([271 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,272 ]);273}274275impl pallet_unique::Config for Test {276 type RuntimeEvent = RuntimeEvent;277 type WeightInfo = ();278 type CommonWeightInfo = CommonWeights<Self>;279 type RefungibleExtensionsWeightInfo = CommonWeights<Self>;280}281282// Build genesis storage according to the mock runtime.283pub fn new_test_ext() -> sp_io::TestExternalities {284 system::GenesisConfig::default()285 .build_storage::<Test>()286 .unwrap()287 .into()288}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 fp_evm_mapping::EvmBackwardsAddressMapping;36use parity_scale_codec::{Encode, Decode, MaxEncodedLen};37use scale_info::TypeInfo;3839use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};4041#[path = "../../common/dispatch.rs"]42mod dispatch;4344use dispatch::CollectionDispatchT;4546#[path = "../../common/weights.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;5657// Configure a mock runtime to test the pallet.58frame_support::construct_runtime!(59 pub enum Test where60 Block = Block,61 NodeBlock = Block,62 UncheckedExtrinsic = UncheckedExtrinsic,63 {64 System: frame_system,65 Unique: pallet_unique::{Pallet, Call, Storage},66 Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},67 Common: pallet_common::{Pallet, Storage, Event<T>},68 Fungible: pallet_fungible::{Pallet, Storage},69 Refungible: pallet_refungible::{Pallet, Storage},70 Nonfungible: pallet_nonfungible::{Pallet, Storage},71 Structure: pallet_structure::{Pallet, Storage, Event<T>},72 TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},73 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin},74 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},75 }76);7778parameter_types! {79 pub const BlockHashCount: u64 = 250;80 pub const SS58Prefix: u8 = 42;81}8283impl system::Config for Test {84 type RuntimeEvent = RuntimeEvent;85 type BaseCallFilter = Everything;86 type BlockWeights = ();87 type BlockLength = ();88 type DbWeight = ();89 type RuntimeOrigin = RuntimeOrigin;90 type RuntimeCall = RuntimeCall;91 type Index = u64;92 type BlockNumber = u64;93 type Hash = H256;94 type Hashing = BlakeTwo256;95 type AccountId = u64;96 type Lookup = IdentityLookup<Self::AccountId>;97 type Header = Header;98 type BlockHashCount = BlockHashCount;99 type Version = ();100 type PalletInfo = PalletInfo;101 type AccountData = pallet_balances::AccountData<u64>;102 type OnNewAccount = ();103 type OnKilledAccount = ();104 type SystemWeightInfo = ();105 type SS58Prefix = SS58Prefix;106 type OnSetCode = ();107 type MaxConsumers = ConstU32<16>;108}109110parameter_types! {111 pub const ExistentialDeposit: u64 = 1;112 pub const MaxLocks: u32 = 50;113}114//frame_system::Module<Test>;115impl pallet_balances::Config for Test {116 type RuntimeEvent = RuntimeEvent;117 type AccountStore = System;118 type Balance = u64;119 type DustRemoval = ();120 type ExistentialDeposit = ExistentialDeposit;121 type WeightInfo = ();122 type MaxLocks = MaxLocks;123 type MaxReserves = ();124 type ReserveIdentifier = [u8; 8];125}126127parameter_types! {128 pub const OperationalFeeMultiplier: u8 = 5;129}130131impl pallet_transaction_payment::Config for Test {132 type RuntimeEvent = RuntimeEvent;133 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;134 type LengthToFee = IdentityFee<u64>;135 type WeightToFee = IdentityFee<u64>;136 type FeeMultiplierUpdate = ();137 type OperationalFeeMultiplier = OperationalFeeMultiplier;138}139140parameter_types! {141 pub const MinimumPeriod: u64 = 1;142}143impl pallet_timestamp::Config for Test {144 type Moment = u64;145 type OnTimestampSet = ();146 type MinimumPeriod = MinimumPeriod;147 type WeightInfo = ();148}149150parameter_types! {151 pub const CollectionCreationPrice: u32 = 100;152 pub TreasuryAccountId: u64 = 1234;153 pub EthereumChainId: u32 = 1111;154}155156pub struct TestEvmAddressMapping;157impl AddressMapping<u64> for TestEvmAddressMapping {158 fn into_account_id(_addr: sp_core::H160) -> u64 {159 unimplemented!()160 }161}162163pub struct TestEvmBackwardsAddressMapping;164impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {165 fn from_account_id(_account_id: u64) -> sp_core::H160 {166 unimplemented!()167 }168}169170#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]171pub struct TestCrossAccountId(u64, sp_core::H160, bool);172impl CrossAccountId<u64> for TestCrossAccountId {173 fn as_sub(&self) -> &u64 {174 &self.0175 }176 fn as_eth(&self) -> &sp_core::H160 {177 &self.1178 }179 fn from_sub(sub: u64) -> Self {180 let mut eth = [0; 20];181 eth[12..20].copy_from_slice(&sub.to_be_bytes());182 Self(sub, sp_core::H160(eth), true)183 }184 fn from_eth(eth: sp_core::H160) -> Self {185 let mut sub_raw = [0; 8];186 sub_raw.copy_from_slice(ð.0[0..8]);187 let sub = u64::from_be_bytes(sub_raw);188 Self(sub, eth, false)189 }190 fn conv_eq(&self, other: &Self) -> bool {191 self.as_sub() == other.as_sub()192 }193 fn is_canonical_substrate(&self) -> bool {194 self.2195 }196}197198impl Default for TestCrossAccountId {199 fn default() -> Self {200 Self::from_sub(0)201 }202}203204parameter_types! {205 pub BlockGasLimit: U256 = 0u32.into();206 pub WeightPerGas: Weight = Weight::from_ref_time(20);207}208209impl pallet_ethereum::Config for Test {210 type RuntimeEvent = RuntimeEvent;211 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;212}213214impl pallet_evm::Config for Test {215 type CrossAccountId = TestCrossAccountId;216 type EvmAddressMapping = TestEvmAddressMapping;217 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;218 type RuntimeEvent = RuntimeEvent;219 type FeeCalculator = ();220 type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;221 type WeightPerGas = WeightPerGas;222 type CallOrigin = EnsureAddressNever<Self>;223 type WithdrawOrigin = EnsureAddressNever<Self>;224 type AddressMapping = TestEvmAddressMapping;225 type Currency = Balances;226 type PrecompilesType = ();227 type PrecompilesValue = ();228 type Runner = pallet_evm::runner::stack::Runner<Self>;229 type ChainId = ConstU64<0>;230 type BlockGasLimit = BlockGasLimit;231 type OnMethodCall = ();232 type OnCreate = ();233 type OnChargeTransaction = ();234 type FindAuthor = ();235 type BlockHashMapping = SubstrateBlockHashMapping<Self>;236 type TransactionValidityHack = ();237}238impl pallet_evm_coder_substrate::Config for Test {}239240impl pallet_common::Config for Test {241 type WeightInfo = ();242 type RuntimeEvent = RuntimeEvent;243 type Currency = Balances;244 type CollectionCreationPrice = CollectionCreationPrice;245 type TreasuryAccountId = TreasuryAccountId;246247 type CollectionDispatch = CollectionDispatchT<Self>;248 type EvmTokenAddressMapping = EvmTokenAddressMapping;249 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;250 type ContractAddress = EvmCollectionHelpersAddress;251}252253impl pallet_structure::Config for Test {254 type WeightInfo = ();255 type RuntimeEvent = RuntimeEvent;256 type RuntimeCall = RuntimeCall;257}258impl pallet_fungible::Config for Test {259 type WeightInfo = ();260}261impl pallet_refungible::Config for Test {262 type WeightInfo = ();263}264impl pallet_nonfungible::Config for Test {265 type WeightInfo = ();266}267268parameter_types! {269 // 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f270 pub const EvmCollectionHelpersAddress: H160 = H160([271 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,272 ]);273}274275impl pallet_unique::Config for Test {276 type WeightInfo = ();277 type CommonWeightInfo = CommonWeights<Self>;278 type RefungibleExtensionsWeightInfo = CommonWeights<Self>;279}280281// Build genesis storage according to the mock runtime.282pub fn new_test_ext() -> sp_io::TestExternalities {283 system::GenesisConfig::default()284 .build_storage::<Test>()285 .unwrap()286 .into()287}