difftreelog
test fix unit tests
in: master
5 files changed
pallets/inflation/src/tests.rsdiffbeforeafterboth445use frame_support::{5use frame_support::{6 assert_ok, parameter_types,6 assert_ok, parameter_types,7 traits::{Currency, OnInitialize, Everything},7 traits::{Currency, OnInitialize, Everything, ConstU32},8};8};9use frame_system::RawOrigin;9use frame_system::RawOrigin;10use sp_core::H256;10use sp_core::H256;81 type SystemWeightInfo = ();81 type SystemWeightInfo = ();82 type SS58Prefix = SS58Prefix;82 type SS58Prefix = SS58Prefix;83 type OnSetCode = ();83 type OnSetCode = ();84 type MaxConsumers = ConstU32<16>;84}85}858686parameter_types! {87parameter_types! {pallets/scheduler/src/lib.rsdiffbeforeafterboth675675676 use frame_support::{676 use frame_support::{677 ord_parameter_types, parameter_types, traits::Contains, weights::constants::RocksDbWeight,677 ord_parameter_types, parameter_types,678 traits::{Contains, ConstU32, EnsureOneOf},679 weights::constants::RocksDbWeight,678 };680 };679 use sp_core::H256;681 use sp_core::H256;680 use sp_runtime::{682 use sp_runtime::{681 Perbill,683 Perbill,682 testing::Header,684 testing::Header,683 traits::{BlakeTwo256, IdentityLookup},685 traits::{BlakeTwo256, IdentityLookup},684 };686 };685 use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};687 use frame_system::{EnsureRoot, EnsureSignedBy};686 use crate as scheduler;688 use crate as scheduler;687689688 mod logger {690 mod logger {779 type SystemWeightInfo = ();781 type SystemWeightInfo = ();780 type SS58Prefix = ();782 type SS58Prefix = ();781 type OnSetCode = ();783 type OnSetCode = ();784 type MaxConsumers = ConstU32<16>;782 }785 }783 impl logger::Config for Test {786 impl logger::Config for Test {784 type Event = Event;787 type Event = Event;797 type PalletsOrigin = OriginCaller;800 type PalletsOrigin = OriginCaller;798 type Call = Call;801 type Call = Call;799 type MaximumWeight = MaximumSchedulerWeight;802 type MaximumWeight = MaximumSchedulerWeight;800 type ScheduleOrigin = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<One, u64>>;803 type ScheduleOrigin = EnsureOneOf<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;801 type MaxScheduledPerBlock = MaxScheduledPerBlock;804 type MaxScheduledPerBlock = MaxScheduledPerBlock;802 type WeightInfo = ();805 type WeightInfo = ();803 type SponsorshipHandler = ();806 type SponsorshipHandler = ();pallets/unique/src/mock.rsdiffbeforeafterboth9};9};10use pallet_transaction_payment::{CurrencyAdapter};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;11use frame_system as system;12use pallet_evm::AddressMapping;12use pallet_evm::{AddressMapping, runner::stack::MaybeMirroredLog};13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};14use codec::{Encode, Decode, MaxEncodedLen};15use scale_info::TypeInfo;15use scale_info::TypeInfo;16use up_data_structs::ConstU32;161717type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type Block = frame_system::mocking::MockBlock<Test>;19type Block = frame_system::mocking::MockBlock<Test>;63 type SystemWeightInfo = ();64 type SystemWeightInfo = ();64 type SS58Prefix = SS58Prefix;65 type SS58Prefix = SS58Prefix;65 type OnSetCode = ();66 type OnSetCode = ();67 type MaxConsumers = ConstU32<16>;66}68}676968parameter_types! {70parameter_types! {125 }127 }126}128}127129128#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]130#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]129pub struct TestCrossAccountId(u64, sp_core::H160);131pub struct TestCrossAccountId(u64, sp_core::H160);130impl CrossAccountId<u64> for TestCrossAccountId {132impl CrossAccountId<u64> for TestCrossAccountId {131 fn as_sub(&self) -> &u64 {133 fn as_sub(&self) -> &u64 {161 fn submit_logs_transaction(163 fn submit_logs_transaction(162 _source: H160,164 _source: H160,163 _tx: pallet_ethereum::Transaction,165 _tx: pallet_ethereum::Transaction,164 _logs: Vec<pallet_ethereum::Log>,166 _logs: Vec<MaybeMirroredLog>,165 ) {167 ) {166 }168 }167}169}pallets/unique/src/tests.rsdiffbeforeafterboth41 let origin1 = Origin::signed(owner);41 let origin1 = Origin::signed(owner);42 assert_ok!(TemplateModule::create_collection(42 assert_ok!(TemplateModule::create_collection(43 origin1,43 origin1,44 col_name1,44 col_name1.try_into().unwrap(),45 col_desc1,45 col_desc1.try_into().unwrap(),46 token_prefix1,46 token_prefix1.try_into().unwrap(),47 mode.clone()47 mode.clone()48 ));48 ));4949131 assert_noop!(131 assert_noop!(132 TemplateModule::create_collection(132 TemplateModule::create_collection(133 origin1,133 origin1,134 col_name1,134 col_name1.try_into().unwrap(),135 col_desc1,135 col_desc1.try_into().unwrap(),136 token_prefix1,136 token_prefix1.try_into().unwrap(),137 CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)137 CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)138 ),138 ),139 Error::<Test>::CollectionDecimalPointLimitExceeded139 Error::<Test>::CollectionDecimalPointLimitExceeded2271 assert_noop!(2271 assert_noop!(2272 TemplateModule::create_collection(2272 TemplateModule::create_collection(2273 origin1,2273 origin1,2274 col_name1,2274 col_name1.try_into().unwrap(),2275 col_desc1,2275 col_desc1.try_into().unwrap(),2276 token_prefix1,2276 token_prefix1.try_into().unwrap(),2277 CollectionMode::NFT2277 CollectionMode::NFT2278 ),2278 ),2279 CommonError::<Test>::TotalCollectionsLimitExceeded2279 CommonError::<Test>::TotalCollectionsLimitExceeded2372 assert_ok!(TemplateModule::set_const_on_chain_schema(2372 assert_ok!(TemplateModule::set_const_on_chain_schema(2373 origin1,2373 origin1,2374 collection_id,2374 collection_id,2375 b"test const on chain schema".to_vec()2375 b"test const on chain schema".to_vec().try_into().unwrap()2376 ));2376 ));237723772378 assert_eq!(2378 assert_eq!(2401 collection_id,2401 collection_id,2402 b"test variable on chain schema".to_vec()2402 b"test variable on chain schema"2403 .to_vec()2404 .try_into()2405 .unwrap()2403 ));2406 ));240424072405 assert_eq!(2408 assert_eq!(2432 origin1,2435 origin1,2433 collection_id,2436 collection_id,2434 TokenId(1),2437 TokenId(1),2435 variable_data.clone()2438 variable_data.clone().try_into().unwrap()2436 ));2439 ));243724402438 assert_eq!(2441 assert_eq!(2459 origin1,2462 origin1,2460 collection_id,2463 collection_id,2461 TokenId(1),2464 TokenId(1),2462 variable_data.clone()2465 variable_data.clone().try_into().unwrap()2463 ));2466 ));246424672465 assert_eq!(2468 assert_eq!(2485 origin1,2488 origin1,2486 collection_id,2489 collection_id,2487 TokenId(0),2490 TokenId(0),2488 variable_data2491 variable_data.try_into().unwrap()2489 )2492 )2490 .map_err(|e| e.error),2493 .map_err(|e| e.error),2491 <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2494 <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2492 );2495 );2493 });2496 });2494}2497}24952496#[test]2497fn set_variable_meta_data_on_nft_token_fails_for_big_data() {2498 new_test_ext().execute_with(|| {2499 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25002501 let origin1 = Origin::signed(1);25022503 let data = default_nft_data();2504 create_test_item(collection_id, &data.into());25052506 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2507 assert_noop!(2508 TemplateModule::set_variable_meta_data(2509 origin1,2510 collection_id,2511 TokenId(1),2512 variable_data2513 )2514 .map_err(|e| e.error),2515 CommonError::<Test>::TokenVariableDataLimitExceeded2516 );2517 });2518}25192520#[test]2521fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {2522 new_test_ext().execute_with(|| {2523 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));25242525 let origin1 = Origin::signed(1);25262527 let data = default_re_fungible_data();2528 create_test_item(collection_id, &data.into());25292530 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2531 assert_noop!(2532 TemplateModule::set_variable_meta_data(2533 origin1,2534 collection_id,2535 TokenId(1),2536 variable_data2537 )2538 .map_err(|e| e.error),2539 CommonError::<Test>::TokenVariableDataLimitExceeded2540 );2541 });2542}254324982544#[test]2499#[test]2545fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2500fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2564 origin1,2519 origin1,2565 collection_id,2520 collection_id,2566 TokenId(1),2521 TokenId(1),2567 variable_data.clone()2522 variable_data.clone().try_into().unwrap()2568 ));2523 ));256925242570 assert_eq!(2525 assert_eq!(2576 });2531 });2577}2532}25782579#[test]2580fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {2581 new_test_ext().execute_with(|| {2582 let collection_id =2583 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));25842585 let origin1 = Origin::signed(1);25862587 assert_ok!(TemplateModule::set_mint_permission(2588 origin1.clone(),2589 collection_id,2590 true2591 ));2592 assert_ok!(TemplateModule::add_to_allow_list(2593 origin1.clone(),2594 collection_id,2595 account(1)2596 ));25972598 let data = default_nft_data();2599 create_test_item(collection_id, &data.into());26002601 assert_ok!(TemplateModule::set_meta_update_permission_flag(2602 origin1.clone(),2603 collection_id,2604 MetaUpdatePermission::ItemOwner,2605 ));26062607 let variable_data = b"1234567890123".to_vec();2608 assert_noop!(2609 TemplateModule::set_variable_meta_data(2610 origin1,2611 collection_id,2612 TokenId(1),2613 variable_data.clone()2614 )2615 .map_err(|e| e.error),2616 CommonError::<Test>::TokenVariableDataLimitExceeded2617 );2618 })2619}262025332621#[test]2534#[test]2622fn collection_transfer_flag_works() {2535fn collection_transfer_flag_works() {2712 origin1,2625 origin1,2713 collection_id,2626 collection_id,2714 TokenId(1),2627 TokenId(1),2715 variable_data.clone()2628 variable_data.clone().try_into().unwrap()2716 ));2629 ));271726302718 assert_eq!(2631 assert_eq!(2761 origin1,2674 origin1,2762 collection_id,2675 collection_id,2763 TokenId(1),2676 TokenId(1),2764 variable_data.clone()2677 variable_data.try_into().unwrap()2765 )2678 )2766 .map_err(|e| e.error),2679 .map_err(|e| e.error),2767 CommonError::<Test>::NoPermission2680 CommonError::<Test>::NoPermission2819 origin1.clone(),2732 origin1.clone(),2820 collection_id,2733 collection_id,2821 TokenId(1),2734 TokenId(1),2822 variable_data.clone()2735 variable_data.try_into().unwrap()2823 )2736 )2824 .map_err(|e| e.error),2737 .map_err(|e| e.error),2825 CommonError::<Test>::NoPermission2738 CommonError::<Test>::NoPermissionruntime/src/lib.rsdiffbeforeafterboth68use codec::{Encode, Decode};68use codec::{Encode, Decode};69use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};69use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};70use fp_rpc::TransactionStatus;70use fp_rpc::TransactionStatus;71use sp_core::crypto::Public;72use sp_runtime::{71use sp_runtime::{73 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf},72 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf},74 transaction_validity::TransactionValidityError,73 transaction_validity::TransactionValidityError,