git.delta.rocks / unique-network / refs/commits / e5f149d8dd11

difftreelog

test fix unit tests

Yaroslav Bolyukin2022-02-08parent: #b8e9f67.patch.diff
in: master

5 files changed

modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -4,7 +4,7 @@
 
 use frame_support::{
 	assert_ok, parameter_types,
-	traits::{Currency, OnInitialize, Everything},
+	traits::{Currency, OnInitialize, Everything, ConstU32},
 };
 use frame_system::RawOrigin;
 use sp_core::H256;
@@ -81,6 +81,7 @@
 	type SystemWeightInfo = ();
 	type SS58Prefix = SS58Prefix;
 	type OnSetCode = ();
+	type MaxConsumers = ConstU32<16>;
 }
 
 parameter_types! {
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -674,7 +674,9 @@
 	use super::*;
 
 	use frame_support::{
-		ord_parameter_types, parameter_types, traits::Contains, weights::constants::RocksDbWeight,
+		ord_parameter_types, parameter_types,
+		traits::{Contains, ConstU32, EnsureOneOf},
+		weights::constants::RocksDbWeight,
 	};
 	use sp_core::H256;
 	use sp_runtime::{
@@ -682,7 +684,7 @@
 		testing::Header,
 		traits::{BlakeTwo256, IdentityLookup},
 	};
-	use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};
+	use frame_system::{EnsureRoot, EnsureSignedBy};
 	use crate as scheduler;
 
 	mod logger {
@@ -779,6 +781,7 @@
 		type SystemWeightInfo = ();
 		type SS58Prefix = ();
 		type OnSetCode = ();
+		type MaxConsumers = ConstU32<16>;
 	}
 	impl logger::Config for Test {
 		type Event = Event;
@@ -797,7 +800,7 @@
 		type PalletsOrigin = OriginCaller;
 		type Call = Call;
 		type MaximumWeight = MaximumSchedulerWeight;
-		type ScheduleOrigin = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
+		type ScheduleOrigin = EnsureOneOf<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
 		type MaxScheduledPerBlock = MaxScheduledPerBlock;
 		type WeightInfo = ();
 		type SponsorshipHandler = ();
modifiedpallets/unique/src/mock.rsdiffbeforeafterboth
before · pallets/unique/src/mock.rs
1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::{H160, H256};5use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};6use sp_runtime::{7	traits::{BlakeTwo256, IdentityLookup},8	testing::Header,9};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;12use pallet_evm::AddressMapping;13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};15use scale_info::TypeInfo;1617type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type Block = frame_system::mocking::MockBlock<Test>;1920// Configure a mock runtime to test the pallet.21frame_support::construct_runtime!(22	pub enum Test where23		Block = Block,24		NodeBlock = Block,25		UncheckedExtrinsic = UncheckedExtrinsic,26	{27		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},28		TemplateModule: pallet_template::{Pallet, Call, Storage},29		Balances: pallet_balances::{Pallet, Call, Storage},30		Common: pallet_common::{Pallet, Storage, Event<T>},31		Fungible: pallet_fungible::{Pallet, Storage},32		Refungible: pallet_refungible::{Pallet, Storage},33		Nonfungible: pallet_nonfungible::{Pallet, Storage},34	}35);3637parameter_types! {38	pub const BlockHashCount: u64 = 250;39	pub const SS58Prefix: u8 = 42;40}4142impl system::Config for Test {43	type BaseCallFilter = Everything;44	type BlockWeights = ();45	type BlockLength = ();46	type DbWeight = ();47	type Origin = Origin;48	type Call = Call;49	type Index = u64;50	type BlockNumber = u64;51	type Hash = H256;52	type Hashing = BlakeTwo256;53	type AccountId = u64;54	type Lookup = IdentityLookup<Self::AccountId>;55	type Header = Header;56	type Event = ();57	type BlockHashCount = BlockHashCount;58	type Version = ();59	type PalletInfo = PalletInfo;60	type AccountData = pallet_balances::AccountData<u64>;61	type OnNewAccount = ();62	type OnKilledAccount = ();63	type SystemWeightInfo = ();64	type SS58Prefix = SS58Prefix;65	type OnSetCode = ();66}6768parameter_types! {69	pub const ExistentialDeposit: u64 = 1;70	pub const MaxLocks: u32 = 50;71}72//frame_system::Module<Test>;73impl pallet_balances::Config for Test {74	type AccountStore = System;75	type Balance = u64;76	type DustRemoval = ();77	type Event = ();78	type ExistentialDeposit = ExistentialDeposit;79	type WeightInfo = ();80	type MaxLocks = MaxLocks;81	type MaxReserves = ();82	type ReserveIdentifier = [u8; 8];83}8485parameter_types! {86	pub const TransactionByteFee: u64 = 1;87	pub const OperationalFeeMultiplier: u8 = 5;88}8990impl pallet_transaction_payment::Config for Test {91	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;92	type TransactionByteFee = TransactionByteFee;93	type WeightToFee = IdentityFee<u64>;94	type FeeMultiplierUpdate = ();95	type OperationalFeeMultiplier = OperationalFeeMultiplier;96}9798parameter_types! {99	pub const MinimumPeriod: u64 = 1;100}101impl pallet_timestamp::Config for Test {102	type Moment = u64;103	type OnTimestampSet = ();104	type MinimumPeriod = MinimumPeriod;105	type WeightInfo = ();106}107108parameter_types! {109	pub const CollectionCreationPrice: u32 = 0;110	pub TreasuryAccountId: u64 = 1234;111	pub EthereumChainId: u32 = 1111;112}113114pub struct TestEvmAddressMapping;115impl AddressMapping<u64> for TestEvmAddressMapping {116	fn into_account_id(_addr: sp_core::H160) -> u64 {117		unimplemented!()118	}119}120121pub struct TestEvmBackwardsAddressMapping;122impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {123	fn from_account_id(_account_id: u64) -> sp_core::H160 {124		unimplemented!()125	}126}127128#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]129pub struct TestCrossAccountId(u64, sp_core::H160);130impl CrossAccountId<u64> for TestCrossAccountId {131	fn as_sub(&self) -> &u64 {132		&self.0133	}134	fn as_eth(&self) -> &sp_core::H160 {135		&self.1136	}137	fn from_sub(sub: u64) -> Self {138		let mut eth = [0; 20];139		eth[12..20].copy_from_slice(&sub.to_be_bytes());140		Self(sub, sp_core::H160(eth))141	}142	fn from_eth(eth: sp_core::H160) -> Self {143		let mut sub_raw = [0; 8];144		sub_raw.copy_from_slice(&eth.0[0..8]);145		let sub = u64::from_be_bytes(sub_raw);146		Self(sub, eth)147	}148	fn conv_eq(&self, other: &Self) -> bool {149		self.as_sub() == other.as_sub()150	}151}152153impl Default for TestCrossAccountId {154	fn default() -> Self {155		Self::from_sub(0)156	}157}158159pub struct TestEtheremTransactionSender;160impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {161	fn submit_logs_transaction(162		_source: H160,163		_tx: pallet_ethereum::Transaction,164		_logs: Vec<pallet_ethereum::Log>,165	) {166	}167}168169impl pallet_evm_coder_substrate::Config for Test {170	type EthereumTransactionSender = TestEtheremTransactionSender;171	type GasWeightMapping = ();172}173174impl pallet_common::Config for Test {175	type Event = ();176	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;177	type EvmAddressMapping = TestEvmAddressMapping;178	type CrossAccountId = TestCrossAccountId;179180	type Currency = Balances;181	type CollectionCreationPrice = CollectionCreationPrice;182	type TreasuryAccountId = TreasuryAccountId;183}184185impl pallet_fungible::Config for Test {186	type WeightInfo = ();187}188impl pallet_refungible::Config for Test {189	type WeightInfo = ();190}191impl pallet_nonfungible::Config for Test {192	type WeightInfo = ();193}194195impl pallet_template::Config for Test {196	type Event = ();197	type WeightInfo = ();198}199200// Build genesis storage according to the mock runtime.201pub fn new_test_ext() -> sp_io::TestExternalities {202	system::GenesisConfig::default()203		.build_storage::<Test>()204		.unwrap()205		.into()206}
after · pallets/unique/src/mock.rs
1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::{H160, H256};5use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};6use sp_runtime::{7	traits::{BlakeTwo256, IdentityLookup},8	testing::Header,9};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;12use pallet_evm::{AddressMapping, runner::stack::MaybeMirroredLog};13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode, MaxEncodedLen};15use scale_info::TypeInfo;16use up_data_structs::ConstU32;1718type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;19type Block = frame_system::mocking::MockBlock<Test>;2021// Configure a mock runtime to test the pallet.22frame_support::construct_runtime!(23	pub enum Test where24		Block = Block,25		NodeBlock = Block,26		UncheckedExtrinsic = UncheckedExtrinsic,27	{28		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},29		TemplateModule: pallet_template::{Pallet, Call, Storage},30		Balances: pallet_balances::{Pallet, Call, Storage},31		Common: pallet_common::{Pallet, Storage, Event<T>},32		Fungible: pallet_fungible::{Pallet, Storage},33		Refungible: pallet_refungible::{Pallet, Storage},34		Nonfungible: pallet_nonfungible::{Pallet, Storage},35	}36);3738parameter_types! {39	pub const BlockHashCount: u64 = 250;40	pub const SS58Prefix: u8 = 42;41}4243impl system::Config for Test {44	type BaseCallFilter = Everything;45	type BlockWeights = ();46	type BlockLength = ();47	type DbWeight = ();48	type Origin = Origin;49	type Call = Call;50	type Index = u64;51	type BlockNumber = u64;52	type Hash = H256;53	type Hashing = BlakeTwo256;54	type AccountId = u64;55	type Lookup = IdentityLookup<Self::AccountId>;56	type Header = Header;57	type Event = ();58	type BlockHashCount = BlockHashCount;59	type Version = ();60	type PalletInfo = PalletInfo;61	type AccountData = pallet_balances::AccountData<u64>;62	type OnNewAccount = ();63	type OnKilledAccount = ();64	type SystemWeightInfo = ();65	type SS58Prefix = SS58Prefix;66	type OnSetCode = ();67	type MaxConsumers = ConstU32<16>;68}6970parameter_types! {71	pub const ExistentialDeposit: u64 = 1;72	pub const MaxLocks: u32 = 50;73}74//frame_system::Module<Test>;75impl pallet_balances::Config for Test {76	type AccountStore = System;77	type Balance = u64;78	type DustRemoval = ();79	type Event = ();80	type ExistentialDeposit = ExistentialDeposit;81	type WeightInfo = ();82	type MaxLocks = MaxLocks;83	type MaxReserves = ();84	type ReserveIdentifier = [u8; 8];85}8687parameter_types! {88	pub const TransactionByteFee: u64 = 1;89	pub const OperationalFeeMultiplier: u8 = 5;90}9192impl pallet_transaction_payment::Config for Test {93	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;94	type TransactionByteFee = TransactionByteFee;95	type WeightToFee = IdentityFee<u64>;96	type FeeMultiplierUpdate = ();97	type OperationalFeeMultiplier = OperationalFeeMultiplier;98}99100parameter_types! {101	pub const MinimumPeriod: u64 = 1;102}103impl pallet_timestamp::Config for Test {104	type Moment = u64;105	type OnTimestampSet = ();106	type MinimumPeriod = MinimumPeriod;107	type WeightInfo = ();108}109110parameter_types! {111	pub const CollectionCreationPrice: u32 = 0;112	pub TreasuryAccountId: u64 = 1234;113	pub EthereumChainId: u32 = 1111;114}115116pub struct TestEvmAddressMapping;117impl AddressMapping<u64> for TestEvmAddressMapping {118	fn into_account_id(_addr: sp_core::H160) -> u64 {119		unimplemented!()120	}121}122123pub struct TestEvmBackwardsAddressMapping;124impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {125	fn from_account_id(_account_id: u64) -> sp_core::H160 {126		unimplemented!()127	}128}129130#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]131pub struct TestCrossAccountId(u64, sp_core::H160);132impl CrossAccountId<u64> for TestCrossAccountId {133	fn as_sub(&self) -> &u64 {134		&self.0135	}136	fn as_eth(&self) -> &sp_core::H160 {137		&self.1138	}139	fn from_sub(sub: u64) -> Self {140		let mut eth = [0; 20];141		eth[12..20].copy_from_slice(&sub.to_be_bytes());142		Self(sub, sp_core::H160(eth))143	}144	fn from_eth(eth: sp_core::H160) -> Self {145		let mut sub_raw = [0; 8];146		sub_raw.copy_from_slice(&eth.0[0..8]);147		let sub = u64::from_be_bytes(sub_raw);148		Self(sub, eth)149	}150	fn conv_eq(&self, other: &Self) -> bool {151		self.as_sub() == other.as_sub()152	}153}154155impl Default for TestCrossAccountId {156	fn default() -> Self {157		Self::from_sub(0)158	}159}160161pub struct TestEtheremTransactionSender;162impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {163	fn submit_logs_transaction(164		_source: H160,165		_tx: pallet_ethereum::Transaction,166		_logs: Vec<MaybeMirroredLog>,167	) {168	}169}170171impl pallet_evm_coder_substrate::Config for Test {172	type EthereumTransactionSender = TestEtheremTransactionSender;173	type GasWeightMapping = ();174}175176impl pallet_common::Config for Test {177	type Event = ();178	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;179	type EvmAddressMapping = TestEvmAddressMapping;180	type CrossAccountId = TestCrossAccountId;181182	type Currency = Balances;183	type CollectionCreationPrice = CollectionCreationPrice;184	type TreasuryAccountId = TreasuryAccountId;185}186187impl pallet_fungible::Config for Test {188	type WeightInfo = ();189}190impl pallet_refungible::Config for Test {191	type WeightInfo = ();192}193impl pallet_nonfungible::Config for Test {194	type WeightInfo = ();195}196197impl pallet_template::Config for Test {198	type Event = ();199	type WeightInfo = ();200}201202// Build genesis storage according to the mock runtime.203pub fn new_test_ext() -> sp_io::TestExternalities {204	system::GenesisConfig::default()205		.build_storage::<Test>()206		.unwrap()207		.into()208}
modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
--- a/pallets/unique/src/tests.rs
+++ b/pallets/unique/src/tests.rs
@@ -41,9 +41,9 @@
 	let origin1 = Origin::signed(owner);
 	assert_ok!(TemplateModule::create_collection(
 		origin1,
-		col_name1,
-		col_desc1,
-		token_prefix1,
+		col_name1.try_into().unwrap(),
+		col_desc1.try_into().unwrap(),
+		token_prefix1.try_into().unwrap(),
 		mode.clone()
 	));
 
@@ -131,9 +131,9 @@
 		assert_noop!(
 			TemplateModule::create_collection(
 				origin1,
-				col_name1,
-				col_desc1,
-				token_prefix1,
+				col_name1.try_into().unwrap(),
+				col_desc1.try_into().unwrap(),
+				token_prefix1.try_into().unwrap(),
 				CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)
 			),
 			Error::<Test>::CollectionDecimalPointLimitExceeded
@@ -2271,9 +2271,9 @@
 		assert_noop!(
 			TemplateModule::create_collection(
 				origin1,
-				col_name1,
-				col_desc1,
-				token_prefix1,
+				col_name1.try_into().unwrap(),
+				col_desc1.try_into().unwrap(),
+				token_prefix1.try_into().unwrap(),
 				CollectionMode::NFT
 			),
 			CommonError::<Test>::TotalCollectionsLimitExceeded
@@ -2372,7 +2372,7 @@
 		assert_ok!(TemplateModule::set_const_on_chain_schema(
 			origin1,
 			collection_id,
-			b"test const on chain schema".to_vec()
+			b"test const on chain schema".to_vec().try_into().unwrap()
 		));
 
 		assert_eq!(
@@ -2399,7 +2399,10 @@
 		assert_ok!(TemplateModule::set_variable_on_chain_schema(
 			origin1,
 			collection_id,
-			b"test variable on chain schema".to_vec()
+			b"test variable on chain schema"
+				.to_vec()
+				.try_into()
+				.unwrap()
 		));
 
 		assert_eq!(
@@ -2432,7 +2435,7 @@
 			origin1,
 			collection_id,
 			TokenId(1),
-			variable_data.clone()
+			variable_data.clone().try_into().unwrap()
 		));
 
 		assert_eq!(
@@ -2459,7 +2462,7 @@
 			origin1,
 			collection_id,
 			TokenId(1),
-			variable_data.clone()
+			variable_data.clone().try_into().unwrap()
 		));
 
 		assert_eq!(
@@ -2485,7 +2488,7 @@
 				origin1,
 				collection_id,
 				TokenId(0),
-				variable_data
+				variable_data.try_into().unwrap()
 			)
 			.map_err(|e| e.error),
 			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData
@@ -2494,54 +2497,6 @@
 }
 
 #[test]
-fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
-	new_test_ext().execute_with(|| {
-		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
-
-		let origin1 = Origin::signed(1);
-
-		let data = default_nft_data();
-		create_test_item(collection_id, &data.into());
-
-		let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
-		assert_noop!(
-			TemplateModule::set_variable_meta_data(
-				origin1,
-				collection_id,
-				TokenId(1),
-				variable_data
-			)
-			.map_err(|e| e.error),
-			CommonError::<Test>::TokenVariableDataLimitExceeded
-		);
-	});
-}
-
-#[test]
-fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {
-	new_test_ext().execute_with(|| {
-		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
-
-		let origin1 = Origin::signed(1);
-
-		let data = default_re_fungible_data();
-		create_test_item(collection_id, &data.into());
-
-		let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
-		assert_noop!(
-			TemplateModule::set_variable_meta_data(
-				origin1,
-				collection_id,
-				TokenId(1),
-				variable_data
-			)
-			.map_err(|e| e.error),
-			CommonError::<Test>::TokenVariableDataLimitExceeded
-		);
-	});
-}
-
-#[test]
 fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {
 	new_test_ext().execute_with(|| {
 		//default_limits();
@@ -2564,7 +2519,7 @@
 			origin1,
 			collection_id,
 			TokenId(1),
-			variable_data.clone()
+			variable_data.clone().try_into().unwrap()
 		));
 
 		assert_eq!(
@@ -2574,48 +2529,6 @@
 			variable_data
 		);
 	});
-}
-
-#[test]
-fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {
-	new_test_ext().execute_with(|| {
-		let collection_id =
-			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
-
-		let origin1 = Origin::signed(1);
-
-		assert_ok!(TemplateModule::set_mint_permission(
-			origin1.clone(),
-			collection_id,
-			true
-		));
-		assert_ok!(TemplateModule::add_to_allow_list(
-			origin1.clone(),
-			collection_id,
-			account(1)
-		));
-
-		let data = default_nft_data();
-		create_test_item(collection_id, &data.into());
-
-		assert_ok!(TemplateModule::set_meta_update_permission_flag(
-			origin1.clone(),
-			collection_id,
-			MetaUpdatePermission::ItemOwner,
-		));
-
-		let variable_data = b"1234567890123".to_vec();
-		assert_noop!(
-			TemplateModule::set_variable_meta_data(
-				origin1,
-				collection_id,
-				TokenId(1),
-				variable_data.clone()
-			)
-			.map_err(|e| e.error),
-			CommonError::<Test>::TokenVariableDataLimitExceeded
-		);
-	})
 }
 
 #[test]
@@ -2712,7 +2625,7 @@
 			origin1,
 			collection_id,
 			TokenId(1),
-			variable_data.clone()
+			variable_data.clone().try_into().unwrap()
 		));
 
 		assert_eq!(
@@ -2761,7 +2674,7 @@
 				origin1,
 				collection_id,
 				TokenId(1),
-				variable_data.clone()
+				variable_data.try_into().unwrap()
 			)
 			.map_err(|e| e.error),
 			CommonError::<Test>::NoPermission
@@ -2819,7 +2732,7 @@
 				origin1.clone(),
 				collection_id,
 				TokenId(1),
-				variable_data.clone()
+				variable_data.try_into().unwrap()
 			)
 			.map_err(|e| e.error),
 			CommonError::<Test>::NoPermission
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -68,7 +68,6 @@
 use codec::{Encode, Decode};
 use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};
 use fp_rpc::TransactionStatus;
-use sp_core::crypto::Public;
 use sp_runtime::{
 	traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf},
 	transaction_validity::TransactionValidityError,