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
44
5use 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}
8586
86parameter_types! {87parameter_types! {
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
675675
676 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;
687689
688 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 = ();
modifiedpallets/unique/src/mock.rsdiffbeforeafterboth
9};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;
1617
17type 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}
6769
68parameter_types! {70parameter_types! {
125 }127 }
126}128}
127129
128#[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}
modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
41 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 ));
4949
131 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>::CollectionDecimalPointLimitExceeded
2271 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::NFT
2278 ),2278 ),
2279 CommonError::<Test>::TotalCollectionsLimitExceeded2279 CommonError::<Test>::TotalCollectionsLimitExceeded
2372 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 ));
23772377
2378 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 ));
24042407
2405 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 ));
24372440
2438 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 ));
24642467
2465 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>>::FungibleItemsDontHaveData
2492 );2495 );
2493 });2496 });
2494}2497}
2495
2496#[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));
2500
2501 let origin1 = Origin::signed(1);
2502
2503 let data = default_nft_data();
2504 create_test_item(collection_id, &data.into());
2505
2506 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_data
2513 )
2514 .map_err(|e| e.error),
2515 CommonError::<Test>::TokenVariableDataLimitExceeded
2516 );
2517 });
2518}
2519
2520#[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));
2524
2525 let origin1 = Origin::signed(1);
2526
2527 let data = default_re_fungible_data();
2528 create_test_item(collection_id, &data.into());
2529
2530 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_data
2537 )
2538 .map_err(|e| e.error),
2539 CommonError::<Test>::TokenVariableDataLimitExceeded
2540 );
2541 });
2542}
25432498
2544#[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 ));
25692524
2570 assert_eq!(2525 assert_eq!(
2576 });2531 });
2577}2532}
2578
2579#[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));
2584
2585 let origin1 = Origin::signed(1);
2586
2587 assert_ok!(TemplateModule::set_mint_permission(
2588 origin1.clone(),
2589 collection_id,
2590 true
2591 ));
2592 assert_ok!(TemplateModule::add_to_allow_list(
2593 origin1.clone(),
2594 collection_id,
2595 account(1)
2596 ));
2597
2598 let data = default_nft_data();
2599 create_test_item(collection_id, &data.into());
2600
2601 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2602 origin1.clone(),
2603 collection_id,
2604 MetaUpdatePermission::ItemOwner,
2605 ));
2606
2607 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>::TokenVariableDataLimitExceeded
2617 );
2618 })
2619}
26202533
2621#[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 ));
27172630
2718 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>::NoPermission
2819 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>::NoPermission
modifiedruntime/src/lib.rsdiffbeforeafterboth
68use 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,