diff --git a/templates/parachain/pallets/xcnft/src/benchmarking.rs b/templates/parachain/pallets/xcnft/src/benchmarking.rs index effa5829a0ac..0a49318dd2f3 100644 --- a/templates/parachain/pallets/xcnft/src/benchmarking.rs +++ b/templates/parachain/pallets/xcnft/src/benchmarking.rs @@ -2,15 +2,15 @@ use super::*; +use enumflags2::{BitFlag, BitFlags}; use frame_benchmarking::v2::*; +use frame_support::{assert_ok, traits::Currency, BoundedVec}; use frame_system::RawOrigin; -use sp_runtime::traits::{Bounded, StaticLookup}; use pallet_nfts::{ - CollectionSetting, CollectionSettings, CollectionConfig, - CollectionConfigFor, MintSettings, BenchmarkHelper, DepositBalanceOf, + BenchmarkHelper, CollectionConfig, CollectionConfigFor, CollectionSetting, CollectionSettings, + DepositBalanceOf, MintSettings, }; -use enumflags2::{BitFlag, BitFlags}; -use frame_support::{traits::Currency, assert_ok, BoundedVec}; +use sp_runtime::traits::{Bounded, StaticLookup}; use sp_std::vec; fn make_collection_config, I: 'static>( @@ -27,11 +27,10 @@ fn default_collection_config, I: 'static>() -> CollectionConfigFor< make_collection_config::(CollectionSetting::empty()) } - #[instance_benchmarks] mod benchmarks { use super::*; - + // Benchmark tries the first scenario of collection_x_transfer (transfering empty collection) #[benchmark] fn transfer_collection_empty, I: 'static>() { @@ -41,13 +40,24 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_nfts::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::())); + assert_ok!(pallet_nfts::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + caller_lookup.clone(), + default_collection_config::() + )); #[extrinsic_call] - collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None); + collection_x_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + None, + 1000.into(), + None, + ); } - // Benchmark tries the second scenario of collection_x_transfer (transfering collection with items same owner) + // Benchmark tries the second scenario of collection_x_transfer (transfering collection with + // items same owner) #[benchmark] fn transfer_collection_same_owner, I: 'static>() { let caller: T::AccountId = whitelisted_caller(); @@ -57,15 +67,31 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_nfts::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::())); - assert_ok!(pallet_nfts::Pallet::::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone(), None)); - + assert_ok!(pallet_nfts::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + caller_lookup.clone(), + default_collection_config::() + )); + assert_ok!(pallet_nfts::Pallet::::mint( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + item.clone(), + caller_lookup.clone(), + None + )); #[extrinsic_call] - collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None); + collection_x_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + None, + 1000.into(), + None, + ); } - // Benchmark tries the third scenario of collection_x_transfer (transfering collection with items different owners) + // Benchmark tries the third scenario of collection_x_transfer (transfering collection with + // items different owners) #[benchmark] fn transfer_collection_other_owners, I: 'static>() { let caller: T::AccountId = whitelisted_caller(); @@ -76,16 +102,36 @@ mod benchmarks { let item = T::Helper::item(0); let item2 = T::Helper::item(1); - T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_nfts::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::())); - assert_ok!(pallet_nfts::Pallet::::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone(), None)); - assert_ok!(pallet_nfts::Pallet::::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item2.clone(), caller_lookup2.clone(), None)); - + assert_ok!(pallet_nfts::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + caller_lookup.clone(), + default_collection_config::() + )); + assert_ok!(pallet_nfts::Pallet::::mint( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + item.clone(), + caller_lookup.clone(), + None + )); + assert_ok!(pallet_nfts::Pallet::::mint( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + item2.clone(), + caller_lookup2.clone(), + None + )); #[extrinsic_call] - collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None); + collection_x_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + None, + 1000.into(), + None, + ); } //Benchmark tries nft transfer @@ -98,13 +144,30 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_nfts::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::())); - assert_ok!(pallet_nfts::Pallet::::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone(), None)); + assert_ok!(pallet_nfts::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + caller_lookup.clone(), + default_collection_config::() + )); + assert_ok!(pallet_nfts::Pallet::::mint( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + item.clone(), + caller_lookup.clone(), + None + )); #[extrinsic_call] - nft_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , item.clone(), 1000.into(), collection.clone() , item.clone()); + nft_x_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + item.clone(), + 1000.into(), + collection.clone(), + item.clone(), + ); } - + //Benchmark tries collection empty parse #[benchmark] fn parse_empty_col, I: 'static>() { @@ -114,7 +177,13 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); #[extrinsic_call] - parse_collection_empty(RawOrigin::Signed(caller.into()),collection.clone() , None, BoundedVec::new(), None); + parse_collection_empty( + RawOrigin::Signed(caller.into()), + collection.clone(), + None, + BoundedVec::new(), + None, + ); } //Benchmark tries collection parse with items @@ -127,9 +196,16 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - #[extrinsic_call] - parse_collection_same_owner(RawOrigin::Signed(caller.into()),None, BoundedVec::new(), nfts.clone() ,1000.into(), collection.clone(), None); + parse_collection_same_owner( + RawOrigin::Signed(caller.into()), + None, + BoundedVec::new(), + nfts.clone(), + 1000.into(), + collection.clone(), + None, + ); } //Benchmark tries collection parse with items and different owners @@ -145,7 +221,15 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); #[extrinsic_call] - parse_collection_diff_owners(RawOrigin::Signed(caller.into()),None, BoundedVec::new(), nfts.clone() ,1000.into(), collection.clone(), None); + parse_collection_diff_owners( + RawOrigin::Signed(caller.into()), + None, + BoundedVec::new(), + nfts.clone(), + 1000.into(), + collection.clone(), + None, + ); } //Benchmark tries collection parse item @@ -158,10 +242,22 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_nfts::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), caller_lookup.clone() ,default_collection_config::())); + assert_ok!(pallet_nfts::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + caller_lookup.clone(), + default_collection_config::() + )); #[extrinsic_call] - parse_nft_transfer(RawOrigin::Signed(caller.into()),collection.clone(), item.clone(), BoundedVec::new(), collection.clone(), item.clone() ,1000.into()); + parse_nft_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + item.clone(), + BoundedVec::new(), + collection.clone(), + item.clone(), + 1000.into(), + ); } impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/templates/parachain/pallets/xcnft/src/tests.rs b/templates/parachain/pallets/xcnft/src/tests.rs index 4e4db01db33d..384181ccd57c 100644 --- a/templates/parachain/pallets/xcnft/src/tests.rs +++ b/templates/parachain/pallets/xcnft/src/tests.rs @@ -6,20 +6,20 @@ use crate::{ pub mod testpara; pub mod testrelay; +use crate::tests::testpara::XcNFT; +use cumulus_primitives_core::Parachain; use frame_support::assert_noop; use pallet_nfts::{CollectionConfigFor, CollectionSettings, Event::Destroyed, MintSettings}; use sp_runtime::{traits::Bounded, AccountId32, BoundedVec, BuildStorage}; -use cumulus_primitives_core::Parachain; -use xcm_executor::traits::ConvertLocation; use xcm::prelude::*; -use crate::tests::testpara::XcNFT; +use xcm_executor::traits::ConvertLocation; pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); pub const INITIAL_BALANCE: u128 = 1_000_000_000; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; use sp_tracing; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; pub fn parent_account_id() -> testpara::AccountId { let location = (Parent,); @@ -71,8 +71,6 @@ decl_test_network! { } } - - pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { use testpara::{MsgQueue, Runtime, System}; @@ -94,7 +92,7 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { } pub fn relay_ext() -> sp_io::TestExternalities { - use testrelay::{Runtime, RuntimeOrigin, System, NFTs}; + use testrelay::{NFTs, Runtime, RuntimeOrigin, System}; let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); @@ -135,11 +133,16 @@ fn try_sending_collection_empty_success() { 0, Some(COLLECTION_ID), 2000.into(), - None + None, ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionTransferred { origin_collection_id: 0, origin_collection_metadata: BoundedVec::new(), destination_para_id: 2000.into()})); - + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionTransferred { + origin_collection_id: 0, + origin_collection_metadata: BoundedVec::new(), + destination_para_id: 2000.into(), + }, + )); }); } @@ -157,7 +160,7 @@ fn try_sending_collection_same_owner_success() { }; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0,ALICE, None); + let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 1, ALICE, None); let _ = testpara::XcNFT::collection_x_transfer( @@ -165,13 +168,18 @@ fn try_sending_collection_same_owner_success() { 0, Some(COLLECTION_ID), 2000.into(), - None + None, ); let nft_ids = vec![0, 1]; - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionAndNFTsTransferred { origin_collection_id: 0, nft_ids, destination_para_id: 2000.into()})); - + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionAndNFTsTransferred { + origin_collection_id: 0, + nft_ids, + destination_para_id: 2000.into(), + }, + )); }); } @@ -189,7 +197,7 @@ fn try_sending_collection_different_owners_success() { }; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0,ALICE, None); + let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 1, BOB, None); let _ = testpara::XcNFT::collection_x_transfer( @@ -197,11 +205,17 @@ fn try_sending_collection_different_owners_success() { 0, Some(COLLECTION_ID), 2000.into(), - None + None, ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionTransferProposalCreated { proposal_id: 0, collection_id: 0, proposer: ALICE, destination: 2000.into()})); - + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionTransferProposalCreated { + proposal_id: 0, + collection_id: 0, + proposer: ALICE, + destination: 2000.into(), + }, + )); }); } @@ -233,14 +247,17 @@ fn try_sending_collection_that_user_doesnt_own() { }); } - #[test] fn try_voting_on_non_existing_proposal() { ParaA::execute_with(|| { testpara::System::set_block_number(1); assert_noop!( - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 0, crate::Vote::Aye), + testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 0, + crate::Vote::Aye + ), Error::::ProposalDoesNotExist ); }); @@ -268,7 +285,11 @@ fn try_voting_on_proposal_when_no_owner() { let _ = crate::CrossChainProposals::insert(1, proposal); assert_noop!( - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(BOB), 1, crate::Vote::Aye), + testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(BOB), + 1, + crate::Vote::Aye + ), Error::::NotNFTOwner ); }); @@ -299,10 +320,15 @@ fn try_voting_on_proposal_expired() { let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::ProposalExpired { proposal_id: 1 })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::ProposalExpired { + proposal_id: 1, + })); }); } @@ -331,12 +357,15 @@ fn try_voting_on_proposal_did_not_pass() { let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::ProposalDidNotPass { - proposal_id: 1, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::ProposalDidNotPass { proposal_id: 1 }, + )); }); } @@ -365,11 +394,18 @@ fn try_voting_on_proposal_again_same_vote() { let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye, + ); assert_noop!( - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye), + testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye + ), Error::::AlreadyVotedThis ); }); @@ -400,14 +436,19 @@ fn vote_on_proposal_successfuly() { let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CrossChainPropoposalVoteRegistered { - proposal_id: 1, - voter: ALICE, - vote: crate::Vote::Aye, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CrossChainPropoposalVoteRegistered { + proposal_id: 1, + voter: ALICE, + vote: crate::Vote::Aye, + }, + )); }); } @@ -425,7 +466,7 @@ fn initiate_proposal_successfuly() { }; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0,ALICE, None); + let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 1, BOB, None); let _ = testpara::XcNFT::collection_x_transfer( @@ -433,19 +474,32 @@ fn initiate_proposal_successfuly() { 0, Some(COLLECTION_ID), 2000.into(), - None + None, ); - let _ = testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 0, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 0, + crate::Vote::Aye, + ); testpara::System::set_block_number(11); - let _ = testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 0); + let _ = testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 0, + ); let nfts = vec![(0, ALICE, BoundedVec::new()), (1, BOB, BoundedVec::new())]; - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionAndNFTsDiffTransferred { origin_collection_id: 0, nfts: nfts, destination_para_id: 2000.into(), to_address: ALICE })); - + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionAndNFTsDiffTransferred { + origin_collection_id: 0, + nfts, + destination_para_id: 2000.into(), + to_address: ALICE, + }, + )); }); } @@ -455,7 +509,10 @@ fn try_initiating_proposal_doesnt_exist() { testpara::System::set_block_number(1); assert_noop!( - testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 1), + testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 1 + ), Error::::ProposalDoesNotExist ); }); @@ -488,7 +545,10 @@ fn try_initiating_proposal_collection_doesnt_exist() { let _ = crate::CrossChainProposals::insert(1, proposal); assert_noop!( - testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 1), + testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 1 + ), Error::::CollectionDoesNotExist ); }); @@ -527,7 +587,10 @@ fn try_initiating_proposal_no_collection_owner() { let _ = crate::CrossChainProposals::insert(1, proposal); assert_noop!( - testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 1), + testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 1 + ), Error::::NotCollectionOwner ); }); @@ -564,15 +627,19 @@ fn try_initiating_proposal_that_did_not_pass() { }; let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 1); + let _ = testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 1, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::ProposalDidNotPass { proposal_id: 1 })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::ProposalDidNotPass { proposal_id: 1 }, + )); }); } #[test] fn try_sending_nft_successful() { - ParaA::execute_with(|| { testpara::System::set_block_number(2); @@ -584,11 +651,24 @@ fn try_sending_nft_successful() { }; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0,ALICE, None); + let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); - let _ = testpara::XcNFT::nft_x_transfer(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), 1, 1); + let _ = testpara::XcNFT::nft_x_transfer( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + 1000.into(), + 1, + 1, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTTransferred { origin_collection_id: 0, origin_asset_id: 0, destination_para_id: 1000.into(), destination_collection_id: 1, destination_asset_id: 1 })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTTransferred { + origin_collection_id: 0, + origin_asset_id: 0, + destination_para_id: 1000.into(), + destination_collection_id: 1, + destination_asset_id: 1, + })); }); } @@ -598,7 +678,14 @@ fn try_sending_nft_no_collection() { testpara::System::set_block_number(2); assert_noop!( - testpara::XcNFT::nft_x_transfer(testpara::RuntimeOrigin::signed(ALICE), 1, 0, 1000.into(), 1, 1), + testpara::XcNFT::nft_x_transfer( + testpara::RuntimeOrigin::signed(ALICE), + 1, + 0, + 1000.into(), + 1, + 1 + ), Error::::CollectionDoesNotExist ); }); @@ -618,7 +705,14 @@ fn try_sending_nft_no_nft() { let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); assert_noop!( - testpara::XcNFT::nft_x_transfer(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), 1, 1), + testpara::XcNFT::nft_x_transfer( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + 1000.into(), + 1, + 1 + ), Error::::NFTDoesNotExist ); }); @@ -641,7 +735,14 @@ fn try_sending_nft_not_nft_owner() { let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); assert_noop!( - testpara::XcNFT::nft_x_transfer(testpara::RuntimeOrigin::signed(BOB), 0, 0, 1000.into(), 1, 1), + testpara::XcNFT::nft_x_transfer( + testpara::RuntimeOrigin::signed(BOB), + 0, + 0, + 1000.into(), + 1, + 1 + ), Error::::NotNFTOwner ); }); @@ -653,7 +754,14 @@ fn try_claiming_nft_no_collection() { testpara::System::set_block_number(2); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 1u32, + 0u32, + 100u32.into(), + 1u32, + 1u32 + ), Error::::CollectionDoesNotExist ); }); @@ -674,7 +782,14 @@ fn try_claiming_nft_no_collection_origin() { let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 1u32, + 0u32, + 100u32.into(), + 1u32, + 1u32 + ), Error::::CollectionDoesNotExist ); }); @@ -703,7 +818,14 @@ fn try_claiming_nft_wrong_origin_collection() { let _ = ReceivedCollections::::insert(0, collections); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 1u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 0u32, + 0u32, + 100u32.into(), + 0u32, + 1u32 + ), Error::::WrongOriginCollectionAtOrigin ); }); @@ -732,7 +854,14 @@ fn try_claiming_nft_wrong_nft() { let _ = ReceivedCollections::::insert(0, collections); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 0u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 0u32, + 0u32, + 100u32.into(), + 0u32, + 0u32 + ), Error::::NFTNotReceived ); }); @@ -751,12 +880,14 @@ fn try_claiming_nft_not_owner() { }; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE, None); + let _ = + testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE, None); testpara::System::set_block_number(3); let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE, None); + let _ = + testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE, None); let collections: ReceivedCols = ReceivedCols:: { origin_para_id: 1000.into(), @@ -777,7 +908,14 @@ fn try_claiming_nft_not_owner() { let _ = ReceivedAssets::::insert((1, 0), nfts); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(BOB), 0u32, 0u32, 0u32, 1u32, 0u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(BOB), + 0u32, + 0u32, + 0u32, + 1u32, + 0u32 + ), Error::::NotNFTOwner ); }); @@ -796,12 +934,14 @@ fn try_claiming_nft_success() { }; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE, None); + let _ = + testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE, None); System::set_block_number(3); let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE, None); + let _ = + testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE, None); let collections: ReceivedCols = ReceivedCols:: { origin_para_id: 1000.into(), @@ -822,7 +962,14 @@ fn try_claiming_nft_success() { let _ = ReceivedAssets::::insert((1, 0), nfts); testpara::System::set_block_number(3); - let _ = testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, 0u32, 1u32, 0u32); + let _ = testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 0u32, + 0u32, + 0u32, + 1u32, + 0u32, + ); testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTClaimed { collection_claimed_from: 1, @@ -846,11 +993,13 @@ fn try_collection_parse_empty_successful() { None, ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionReceived { - origin_collection_id: 1, - received_collection_id: 1, - to_address: ALICE, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionReceived { + origin_collection_id: 1, + received_collection_id: 1, + to_address: ALICE, + }, + )); }); } @@ -871,11 +1020,15 @@ fn try_parse_collection_burn_successful() { let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = testpara::XcNFT::parse_collection_burn(testpara::RuntimeOrigin::signed(ALICE), 0, destroy_witness); + let _ = testpara::XcNFT::parse_collection_burn( + testpara::RuntimeOrigin::signed(ALICE), + 0, + destroy_witness, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_nfts::Event::Destroyed { - collection: 0, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_nfts::Event::Destroyed { collection: 0 }, + )); }); } @@ -893,13 +1046,15 @@ fn try_parse_collection_metadata_successful() { let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = - testpara::XcNFT::parse_collection_metadata(testpara::RuntimeOrigin::signed(ALICE), 0, BoundedVec::new()); + let _ = testpara::XcNFT::parse_collection_metadata( + testpara::RuntimeOrigin::signed(ALICE), + 0, + BoundedVec::new(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_nfts::Event::CollectionMetadataSet { - collection: 0, - data: BoundedVec::new(), - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_nfts::Event::CollectionMetadataSet { collection: 0, data: BoundedVec::new() }, + )); }); } @@ -919,12 +1074,12 @@ fn try_parse_collection_owner_successful() { pallet_nfts::OwnershipAcceptance::::insert(BOB, 0); - let _ = testpara::XcNFT::parse_collection_owner(testpara::RuntimeOrigin::signed(ALICE), BOB, 0); + let _ = + testpara::XcNFT::parse_collection_owner(testpara::RuntimeOrigin::signed(ALICE), BOB, 0); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_nfts::Event::OwnerChanged { - collection: 0, - new_owner: BOB, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_nfts::Event::OwnerChanged { collection: 0, new_owner: BOB }, + )); }); } @@ -946,11 +1101,9 @@ fn try_parse_nft_burn_successful() { let _ = testpara::XcNFT::parse_nft_burn(testpara::RuntimeOrigin::signed(ALICE), 0, 0); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_nfts::Event::Burned { - collection: 0, - item: 0, - owner: ALICE, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_nfts::Event::Burned { collection: 0, item: 0, owner: ALICE }, + )); }); } @@ -970,13 +1123,16 @@ fn try_parse_nft_metadata_successful() { let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); - let _ = testpara::XcNFT::parse_nft_metadata(testpara::RuntimeOrigin::signed(ALICE), 0, 0, BoundedVec::new()); + let _ = testpara::XcNFT::parse_nft_metadata( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_nfts::Event::ItemMetadataSet { - collection: 0, - item: 0, - data: BoundedVec::new(), - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_nfts::Event::ItemMetadataSet { collection: 0, item: 0, data: BoundedVec::new() }, + )); }); } @@ -998,12 +1154,9 @@ fn try_parse_nft_owner_successful() { let _ = testpara::XcNFT::parse_nft_owner(testpara::RuntimeOrigin::signed(ALICE), BOB, 0, 0); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_nfts::Event::Transferred { - collection: 0, - item: 0, - from: ALICE, - to: BOB, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_nfts::Event::Transferred { collection: 0, item: 0, from: ALICE, to: BOB }, + )); }); } @@ -1196,11 +1349,13 @@ fn try_parse_nft_transfer_return_to_origin() { 0, ParachainInfo::parachain_id(), ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTReturnedToOrigin { - returned_from_collection_id: 0, - returned_from_asset_id: 0, - to_address: ALICE, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::NFTReturnedToOrigin { + returned_from_collection_id: 0, + returned_from_asset_id: 0, + to_address: ALICE, + }, + )); }); } @@ -1228,10 +1383,9 @@ fn parse_collection_same_owner_successful() { 0, None, ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionWithNftsReceived { - collection_id: 0, - items: nfts.clone(), - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionWithNftsReceived { collection_id: 0, items: nfts.clone() }, + )); }); } @@ -1247,7 +1401,8 @@ fn parse_collection_diff_nft_owners_successful() { mint_settings: MintSettings::default(), // Use default mint settings }; - let mut nfts: Vec<(u32, AccountId32, BoundedVec)> = Vec::new(); + let mut nfts: Vec<(u32, AccountId32, BoundedVec)> = + Vec::new(); nfts.push((1, BOB, BoundedVec::new())); let _ = testpara::XcNFT::parse_collection_diff_owners( @@ -1266,37 +1421,72 @@ fn parse_collection_diff_nft_owners_successful() { } #[test] -fn try_collection_metadata_success(){ +fn try_collection_metadata_success() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::collection_x_update(testpara::RuntimeOrigin::signed(ALICE), 0, 1000.into(), BoundedVec::new()); + let _ = testpara::XcNFT::collection_x_update( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 1000.into(), + BoundedVec::new(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionMetadataSent { collection_id: 0, proposed_data: BoundedVec::new(), owner: ALICE, destination: 1000.into()})); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionMetadataSent { + collection_id: 0, + proposed_data: BoundedVec::new(), + owner: ALICE, + destination: 1000.into(), + }, + )); }); } #[test] -fn try_collection_owner_send_success(){ +fn try_collection_owner_send_success() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::collection_x_change_owner(testpara::RuntimeOrigin::signed(ALICE), 0, 1000.into(), BOB); + let _ = testpara::XcNFT::collection_x_change_owner( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 1000.into(), + BOB, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionOwnershipSent { collection_id: 0, proposed_owner: BOB, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionOwnershipSent { + collection_id: 0, + proposed_owner: BOB, + destination: 1000.into(), + }, + )); }); } #[test] -fn try_collection_burn_success(){ +fn try_collection_burn_success() { ParaA::execute_with(|| { testpara::System::set_block_number(2); let witness = GeneralizedDestroyWitness { item_meta: 0, item_configs: 0, attributes: 0 }; - let _ = testpara::XcNFT::collection_x_burn(testpara::RuntimeOrigin::signed(ALICE), 0, 1000.into(), witness.clone()); + let _ = testpara::XcNFT::collection_x_burn( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 1000.into(), + witness.clone(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionBurnSent { collection_id: 0, burn_data: witness.clone(), owner: ALICE, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionBurnSent { + collection_id: 0, + burn_data: witness.clone(), + owner: ALICE, + destination: 1000.into(), + }, + )); }); } @@ -1305,9 +1495,21 @@ fn try_nft_metadata_successful() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::nft_x_update(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), BoundedVec::new()); + let _ = testpara::XcNFT::nft_x_update( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + 1000.into(), + BoundedVec::new(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTMetadataSent { collection_id: 0, asset_id: 0, proposed_data: BoundedVec::new(), owner: ALICE, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTMetadataSent { + collection_id: 0, + asset_id: 0, + proposed_data: BoundedVec::new(), + owner: ALICE, + destination: 1000.into(), + })); }); } @@ -1316,9 +1518,22 @@ fn try_nft_owner_successful() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::nft_x_change_owner(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), BOB); + let _ = testpara::XcNFT::nft_x_change_owner( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + 1000.into(), + BOB, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTOwnershipSent { collection_id: 0, asset_id: 0, proposed_owner: BOB, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::NFTOwnershipSent { + collection_id: 0, + asset_id: 0, + proposed_owner: BOB, + destination: 1000.into(), + }, + )); }); } @@ -1327,8 +1542,14 @@ fn try_nft_burn_successful() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::nft_x_burn(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into()); + let _ = + testpara::XcNFT::nft_x_burn(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into()); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTBurnSent { collection_id: 0, asset_id: 0, owner: ALICE, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTBurnSent { + collection_id: 0, + asset_id: 0, + owner: ALICE, + destination: 1000.into(), + })); }); -} \ No newline at end of file +} diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara.rs b/templates/parachain/pallets/xcnft/src/tests/testpara.rs index 96301ed16d18..489358e912a4 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara.rs @@ -23,15 +23,16 @@ use parachain_info; use core::marker::PhantomData; use frame_support::{ - construct_runtime, derive_impl, parameter_types, + construct_runtime, derive_impl, + pallet_prelude::Get, + parameter_types, traits::{ConstU128, ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, Nothing}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; -use frame_support::pallet_prelude::Get; use frame_system::{EnsureRoot, EnsureSigned}; use sp_core::ConstU32; use sp_runtime::{ - traits::{ConstU64, Verify, IdentityLookup}, + traits::{ConstU64, IdentityLookup, Verify}, AccountId32, BuildStorage, MultiSignature, }; use xcm::latest::prelude::*; @@ -61,12 +62,11 @@ impl pallet_balances::Config for Runtime { type AccountStore = System; } - pub const UNIT: Balance = 1; parameter_types! { pub const CollectionDeposit: Balance = 0 * UNIT; // 1 UNIT deposit to create asset collection pub const ItemDeposit: Balance = 0 * UNIT; // 1/100 UNIT deposit to create asset item - pub const KeyLimit: u32 = 32; + pub const KeyLimit: u32 = 32; pub const ValueLimit: u32 = 64; pub const UniquesMetadataDepositBase: Balance = 0 * UNIT; pub const AttributeDepositBase: Balance = 0 * UNIT; @@ -210,8 +210,8 @@ construct_runtime!( Balances: pallet_balances, MsgQueue: mock_message_queue, PolkadotXcm: pallet_xcm, - NFTs: pallet_nfts, - XcNFT: crate, - ParachainInfo: parachain_info, + NFTs: pallet_nfts, + XcNFT: crate, + ParachainInfo: parachain_info, } -); \ No newline at end of file +); diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/asset_transactor.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/asset_transactor.rs index 4d1e5d1ea4d3..0de69ae2790a 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/asset_transactor.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/asset_transactor.rs @@ -15,11 +15,11 @@ // along with Polkadot. If not, see . use crate::tests::testpara::{ - constants::KsmLocation, location_converter::LocationConverter, AccountId, Balances -}; -use xcm_builder::{FungibleAdapter, IsConcrete + constants::KsmLocation, location_converter::LocationConverter, AccountId, Balances, }; +use xcm_builder::{FungibleAdapter, IsConcrete}; -type LocalAssetTransactor = FungibleAdapter, LocationConverter, AccountId, ()>; +type LocalAssetTransactor = + FungibleAdapter, LocationConverter, AccountId, ()>; -pub type AssetTransactor = LocalAssetTransactor; \ No newline at end of file +pub type AssetTransactor = LocalAssetTransactor; diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/barrier.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/barrier.rs index b0ac69069cf1..25db7638accd 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/barrier.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/barrier.rs @@ -17,4 +17,4 @@ use frame_support::traits::Everything; use xcm_builder::AllowExplicitUnpaidExecutionFrom; -pub type Barrier = AllowExplicitUnpaidExecutionFrom; \ No newline at end of file +pub type Barrier = AllowExplicitUnpaidExecutionFrom; diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/constants.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/constants.rs index 59e1f077d87c..62460e30dc67 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/constants.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/constants.rs @@ -28,4 +28,4 @@ parameter_types! { pub const KsmLocation: Location = Location::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainId::::get().into())].into(); -} \ No newline at end of file +} diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/location_converter.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/location_converter.rs index 235bf3bfd6de..70608e0b7d26 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/location_converter.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/location_converter.rs @@ -22,4 +22,4 @@ type LocationToAccountId = ( AccountId32Aliases, ); -pub type LocationConverter = LocationToAccountId; \ No newline at end of file +pub type LocationConverter = LocationToAccountId; diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/mod.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/mod.rs index 44a7f3dc14c8..b44ef42cc068 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/mod.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/mod.rs @@ -62,4 +62,4 @@ impl xcm_executor::Config for XcmConfig { type HrmpChannelAcceptedHandler = (); type HrmpChannelClosingHandler = (); type XcmRecorder = PolkadotXcm; -} \ No newline at end of file +} diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/origin_converter.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/origin_converter.rs index aa3a32ee5abe..ee06ced0f0c0 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/origin_converter.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/origin_converter.rs @@ -26,4 +26,4 @@ type XcmOriginToCallOrigin = ( XcmPassthrough, ); -pub type OriginConverter = XcmOriginToCallOrigin; \ No newline at end of file +pub type OriginConverter = XcmOriginToCallOrigin; diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/reserve.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/reserve.rs index f0700b59bb3a..7ef801b543ee 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/reserve.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/reserve.rs @@ -18,4 +18,4 @@ use crate::tests::testpara::teleporter::TrustedTeleporters; use frame_support::traits::EverythingBut; use xcm_builder::NativeAsset; -pub type TrustedReserves = (NativeAsset, EverythingBut); \ No newline at end of file +pub type TrustedReserves = (NativeAsset, EverythingBut); diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/teleporter.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/teleporter.rs index a068087953cd..41cb7a5eb2de 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/teleporter.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/teleporter.rs @@ -24,4 +24,4 @@ parameter_types! { = (NftCollectionOne::get(), (Parent,).into()); } -pub type TrustedTeleporters = xcm_builder::Case; \ No newline at end of file +pub type TrustedTeleporters = xcm_builder::Case; diff --git a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/weigher.rs b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/weigher.rs index 74ad2278aa14..d8284310cb3c 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/weigher.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testpara/xcm_config/weigher.rs @@ -24,4 +24,4 @@ parameter_types! { pub const MaxInstructions: u32 = 100; } -pub type Weigher = FixedWeightBounds; \ No newline at end of file +pub type Weigher = FixedWeightBounds; diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay.rs index 5db585281297..c8bf72b0b280 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay.rs @@ -27,14 +27,17 @@ use frame_support::{ weights::{Weight, WeightMeter}, }; -use frame_system::{EnsureRoot,EnsureSigned}; -use sp_core::ConstU32; -use sp_runtime::{traits::{Verify,IdentityLookup}, AccountId32,MultiSignature}; +use frame_system::{EnsureRoot, EnsureSigned}; use polkadot_runtime_parachains::{ configuration, inclusion::{AggregateMessageOrigin, UmpQueueId}, origin, shared, }; +use sp_core::ConstU32; +use sp_runtime::{ + traits::{IdentityLookup, Verify}, + AccountId32, MultiSignature, +}; use xcm::latest::prelude::*; use xcm_builder::{IsConcrete, SignedToAccountId32}; use xcm_executor::XcmExecutor; @@ -65,7 +68,7 @@ pub const UNIT: Balance = 1; parameter_types! { pub const CollectionDeposit: Balance = 0 * UNIT; // 1 UNIT deposit to create asset collection pub const ItemDeposit: Balance = 0 * UNIT; // 1/100 UNIT deposit to create asset item - pub const KeyLimit: u32 = 32; + pub const KeyLimit: u32 = 32; pub const ValueLimit: u32 = 64; pub const UniquesMetadataDepositBase: Balance = 0 * UNIT; pub const AttributeDepositBase: Balance = 0 * UNIT; @@ -207,4 +210,4 @@ construct_runtime!( NFTs: pallet_nfts, MessageQueue: pallet_message_queue, } -); \ No newline at end of file +); diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/asset_transactor.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/asset_transactor.rs index 9b316306a5b3..8db9559ba49b 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/asset_transactor.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/asset_transactor.rs @@ -23,6 +23,7 @@ use xcm_builder::{ }; use xcm_executor::traits::JustTry; -type LocalAssetTransactor = FungibleAdapter, LocationConverter, AccountId, ()>; +type LocalAssetTransactor = + FungibleAdapter, LocationConverter, AccountId, ()>; -pub type AssetTransactor = LocalAssetTransactor; \ No newline at end of file +pub type AssetTransactor = LocalAssetTransactor; diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/barrier.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/barrier.rs index b0ac69069cf1..25db7638accd 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/barrier.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/barrier.rs @@ -17,4 +17,4 @@ use frame_support::traits::Everything; use xcm_builder::AllowExplicitUnpaidExecutionFrom; -pub type Barrier = AllowExplicitUnpaidExecutionFrom; \ No newline at end of file +pub type Barrier = AllowExplicitUnpaidExecutionFrom; diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/constants.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/constants.rs index 2266c223f40d..f590c42990da 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/constants.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/constants.rs @@ -28,4 +28,4 @@ parameter_types! { pub RelayNetwork: NetworkId = ByGenesis([0; 32]); pub UniversalLocation: InteriorLocation = RelayNetwork::get().into(); pub UnitWeightCost: u64 = 1_000; -} \ No newline at end of file +} diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/location_converter.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/location_converter.rs index 88c26f6f7947..ad9acb3bdd54 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/location_converter.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/location_converter.rs @@ -22,4 +22,4 @@ type LocationToAccountId = ( AccountId32Aliases, ); -pub type LocationConverter = LocationToAccountId; \ No newline at end of file +pub type LocationConverter = LocationToAccountId; diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/mod.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/mod.rs index d483a20d83a0..9bd37855b18e 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/mod.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/mod.rs @@ -25,8 +25,7 @@ pub mod weigher; use crate::tests::testrelay::{RuntimeCall, XcmPallet}; use frame_support::traits::{Everything, Nothing}; use xcm_builder::{EnsureDecodableXcm, FixedRateOfFungible, FrameTransactionalProcessor}; -use xcm_executor::Config; -use xcm_executor::traits::WithOriginFilter; +use xcm_executor::{traits::WithOriginFilter, Config}; // Generated from `decl_test_network!` pub type XcmRouter = EnsureDecodableXcm; @@ -62,4 +61,4 @@ impl Config for XcmConfig { type HrmpChannelAcceptedHandler = (); type HrmpChannelClosingHandler = (); type XcmRecorder = XcmPallet; -} \ No newline at end of file +} diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/origin_converter.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/origin_converter.rs index ea14cbfd38e2..c8eba67237c0 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/origin_converter.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/origin_converter.rs @@ -31,4 +31,4 @@ type LocalOriginConverter = ( ChildSystemParachainAsSuperuser, ); -pub type OriginConverter = LocalOriginConverter; \ No newline at end of file +pub type OriginConverter = LocalOriginConverter; diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/teleporter.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/teleporter.rs index 0d322538c592..92e5065044e6 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/teleporter.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/teleporter.rs @@ -23,4 +23,4 @@ parameter_types! { pub NftCollectionForChild: (AssetFilter, Location) = (NftCollectionOnRelay::get(), Parachain(1).into()); } -pub type TrustedTeleporters = xcm_builder::Case; \ No newline at end of file +pub type TrustedTeleporters = xcm_builder::Case; diff --git a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/weigher.rs b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/weigher.rs index b99051539394..2cab9a91a1b7 100644 --- a/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/weigher.rs +++ b/templates/parachain/pallets/xcnft/src/tests/testrelay/xcm_config/weigher.rs @@ -24,4 +24,4 @@ parameter_types! { pub const MaxInstructions: u32 = 100; } -pub type Weigher = FixedWeightBounds; \ No newline at end of file +pub type Weigher = FixedWeightBounds; diff --git a/templates/parachain_two/pallets/xcnft/src/benchmarking.rs b/templates/parachain_two/pallets/xcnft/src/benchmarking.rs index 474912d0877a..bc729c911bbe 100644 --- a/templates/parachain_two/pallets/xcnft/src/benchmarking.rs +++ b/templates/parachain_two/pallets/xcnft/src/benchmarking.rs @@ -4,17 +4,19 @@ use super::*; use frame_benchmarking::v2::*; +use frame_support::{assert_ok, traits::Currency, BoundedVec}; use frame_system::RawOrigin; -use sp_std::vec; -use sp_runtime::traits::{Bounded, StaticLookup}; use pallet_uniques::BenchmarkHelper; -use frame_support::{traits::Currency, assert_ok, BoundedVec}; -type DepositBalanceOf = <>::Currency as Currency<::AccountId>>::Balance; +use sp_runtime::traits::{Bounded, StaticLookup}; +use sp_std::vec; +type DepositBalanceOf = <>::Currency as Currency< + ::AccountId, +>>::Balance; #[instance_benchmarks] mod benchmarks { use super::*; - + // Benchmark tries the first scenario of collection_x_transfer (transfering empty collection) #[benchmark] fn transfer_collection_empty, I: 'static>() { @@ -22,15 +24,26 @@ mod benchmarks { let caller_lookup = T::Lookup::unlookup(caller.clone()); let collection = T::Helper::collection(0); - T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); + T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_uniques::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), collection.clone() ,caller_lookup.clone())); + assert_ok!(pallet_uniques::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + caller_lookup.clone() + )); #[extrinsic_call] - collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None); + collection_x_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + None, + 1000.into(), + None, + ); } - // Benchmark tries the second scenario of collection_x_transfer (transfering collection with items same owner) + // Benchmark tries the second scenario of collection_x_transfer (transfering collection with + // items same owner) #[benchmark] fn transfer_collection_same_owner, I: 'static>() { let caller: T::AccountId = whitelisted_caller(); @@ -40,15 +53,30 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_uniques::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), collection.clone() ,caller_lookup.clone())); - assert_ok!(pallet_uniques::Pallet::::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone())); - + assert_ok!(pallet_uniques::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + caller_lookup.clone() + )); + assert_ok!(pallet_uniques::Pallet::::mint( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + item.clone(), + caller_lookup.clone() + )); #[extrinsic_call] - collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None); + collection_x_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + None, + 1000.into(), + None, + ); } - // Benchmark tries the third scenario of collection_x_transfer (transfering collection with items different owners) + // Benchmark tries the third scenario of collection_x_transfer (transfering collection with + // items different owners) #[benchmark] fn transfer_collection_other_owners, I: 'static>() { let caller: T::AccountId = whitelisted_caller(); @@ -61,13 +89,32 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_uniques::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), collection.clone() ,caller_lookup.clone())); - assert_ok!(pallet_uniques::Pallet::::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone())); - assert_ok!(pallet_uniques::Pallet::::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item2.clone(), caller_lookup2.clone())); - + assert_ok!(pallet_uniques::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + caller_lookup.clone() + )); + assert_ok!(pallet_uniques::Pallet::::mint( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + item.clone(), + caller_lookup.clone() + )); + assert_ok!(pallet_uniques::Pallet::::mint( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + item2.clone(), + caller_lookup2.clone() + )); #[extrinsic_call] - collection_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , None, 1000.into(), None); + collection_x_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + None, + 1000.into(), + None, + ); } //Benchmark tries nft transfer @@ -80,14 +127,29 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!(pallet_uniques::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), collection.clone() ,caller_lookup.clone())); - assert_ok!(pallet_uniques::Pallet::::mint(RawOrigin::Signed(caller.clone()).into(), collection.clone(), item.clone(), caller_lookup.clone())); - + assert_ok!(pallet_uniques::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + caller_lookup.clone() + )); + assert_ok!(pallet_uniques::Pallet::::mint( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + item.clone(), + caller_lookup.clone() + )); #[extrinsic_call] - nft_x_transfer(RawOrigin::Signed(caller.into()),collection.clone() , item.clone(), 1000.into(), collection.clone() , item.clone()); + nft_x_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + item.clone(), + 1000.into(), + collection.clone(), + item.clone(), + ); } - + //Benchmark tries collection empty parse #[benchmark] fn parse_empty_col, I: 'static>() { @@ -97,7 +159,13 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); #[extrinsic_call] - parse_collection_empty(RawOrigin::Signed(caller.into()),collection.clone() , None, BoundedVec::new(), None); + parse_collection_empty( + RawOrigin::Signed(caller.into()), + collection.clone(), + None, + BoundedVec::new(), + None, + ); } //Benchmark tries collection parse with items @@ -110,9 +178,16 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - #[extrinsic_call] - parse_collection_same_owner(RawOrigin::Signed(caller.into()),None, BoundedVec::new(), nfts.clone() ,1000.into(), collection.clone(), None); + parse_collection_same_owner( + RawOrigin::Signed(caller.into()), + None, + BoundedVec::new(), + nfts.clone(), + 1000.into(), + collection.clone(), + None, + ); } //Benchmark tries collection parse with items and different owners @@ -128,7 +203,15 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); #[extrinsic_call] - parse_collection_diff_owners(RawOrigin::Signed(caller.into()),None, BoundedVec::new(), nfts.clone() ,1000.into(), collection.clone(), None); + parse_collection_diff_owners( + RawOrigin::Signed(caller.into()), + None, + BoundedVec::new(), + nfts.clone(), + 1000.into(), + collection.clone(), + None, + ); } //Benchmark tries collection parse item @@ -141,12 +224,23 @@ mod benchmarks { T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - assert_ok!( - pallet_uniques::Pallet::::create(RawOrigin::Signed(caller.clone()).into(), collection.clone(),caller_lookup.clone())); + assert_ok!(pallet_uniques::Pallet::::create( + RawOrigin::Signed(caller.clone()).into(), + collection.clone(), + caller_lookup.clone() + )); #[extrinsic_call] - parse_nft_transfer(RawOrigin::Signed(caller.into()),collection.clone(), item.clone(), BoundedVec::new(), collection.clone(), item.clone() ,1000.into()); + parse_nft_transfer( + RawOrigin::Signed(caller.into()), + collection.clone(), + item.clone(), + BoundedVec::new(), + collection.clone(), + item.clone(), + 1000.into(), + ); } - + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); } diff --git a/templates/parachain_two/pallets/xcnft/src/lib.rs b/templates/parachain_two/pallets/xcnft/src/lib.rs index c2a9f071b081..071b4c5328cb 100644 --- a/templates/parachain_two/pallets/xcnft/src/lib.rs +++ b/templates/parachain_two/pallets/xcnft/src/lib.rs @@ -114,7 +114,7 @@ pub mod pallet { /// A type representing the weights required by the dispatchables of this pallet. type WeightInfo: crate::weights::WeightInfo; - + /// Specifies how long should cross-chain proposals last type ProposalTimeInBlocks: Get; diff --git a/templates/parachain_two/pallets/xcnft/src/tests.rs b/templates/parachain_two/pallets/xcnft/src/tests.rs index d1e4deff6060..10efb390113a 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests.rs @@ -6,19 +6,19 @@ use crate::{ pub mod testpara; pub mod testrelay; +use cumulus_primitives_core::Parachain; use frame_support::assert_noop; +use pallet_uniques; use sp_runtime::{AccountId32, BoundedVec, BuildStorage}; -use cumulus_primitives_core::Parachain; -use xcm_executor::traits::ConvertLocation; use xcm::prelude::*; -use pallet_uniques; +use xcm_executor::traits::ConvertLocation; pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); pub const INITIAL_BALANCE: u128 = 1_000_000_000; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; use sp_tracing; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; pub fn parent_account_id() -> testpara::AccountId { let location = (Parent,); @@ -70,8 +70,6 @@ decl_test_network! { } } - - pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { use testpara::{MsgQueue, Runtime, System}; @@ -93,7 +91,7 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { } pub fn relay_ext() -> sp_io::TestExternalities { - use testrelay::{Runtime, RuntimeOrigin, System, NFTs}; + use testrelay::{NFTs, Runtime, RuntimeOrigin, System}; let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); @@ -127,11 +125,16 @@ fn try_sending_collection_empty_success() { 0, Some(COLLECTION_ID), 2000.into(), - None + None, ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionTransferred { origin_collection_id: 0, origin_collection_metadata: BoundedVec::new(), destination_para_id: 2000.into()})); - + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionTransferred { + origin_collection_id: 0, + origin_collection_metadata: BoundedVec::new(), + destination_para_id: 2000.into(), + }, + )); }); } @@ -142,7 +145,7 @@ fn try_sending_collection_same_owner_success() { const COLLECTION_ID: u32 = 1; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0,ALICE); + let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE); let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 1, ALICE); let _ = testpara::XcNFT::collection_x_transfer( @@ -150,13 +153,18 @@ fn try_sending_collection_same_owner_success() { 0, Some(COLLECTION_ID), 2000.into(), - None + None, ); let nft_ids = vec![0, 1]; - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionAndNFTsTransferred { origin_collection_id: 0, nft_ids, destination_para_id: 2000.into()})); - + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionAndNFTsTransferred { + origin_collection_id: 0, + nft_ids, + destination_para_id: 2000.into(), + }, + )); }); } @@ -167,7 +175,7 @@ fn try_sending_collection_different_owners_success() { const COLLECTION_ID: u32 = 1; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0,ALICE); + let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE); let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 1, BOB); let _ = testpara::XcNFT::collection_x_transfer( @@ -175,11 +183,17 @@ fn try_sending_collection_different_owners_success() { 0, Some(COLLECTION_ID), 2000.into(), - None + None, ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionTransferProposalCreated { proposal_id: 0, collection_id: 0, proposer: ALICE, destination: 2000.into()})); - + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionTransferProposalCreated { + proposal_id: 0, + collection_id: 0, + proposer: ALICE, + destination: 2000.into(), + }, + )); }); } @@ -204,14 +218,17 @@ fn try_sending_collection_that_user_doesnt_own() { }); } - #[test] fn try_voting_on_non_existing_proposal() { ParaA::execute_with(|| { testpara::System::set_block_number(1); assert_noop!( - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 0, crate::Vote::Aye), + testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 0, + crate::Vote::Aye + ), Error::::ProposalDoesNotExist ); }); @@ -239,7 +256,11 @@ fn try_voting_on_proposal_when_no_owner() { let _ = crate::CrossChainProposals::insert(1, proposal); assert_noop!( - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(BOB), 1, crate::Vote::Aye), + testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(BOB), + 1, + crate::Vote::Aye + ), Error::::NotNFTOwner ); }); @@ -270,10 +291,15 @@ fn try_voting_on_proposal_expired() { let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::ProposalExpired { proposal_id: 1 })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::ProposalExpired { + proposal_id: 1, + })); }); } @@ -302,12 +328,15 @@ fn try_voting_on_proposal_did_not_pass() { let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::ProposalDidNotPass { - proposal_id: 1, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::ProposalDidNotPass { proposal_id: 1 }, + )); }); } @@ -336,11 +365,18 @@ fn try_voting_on_proposal_again_same_vote() { let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye, + ); assert_noop!( - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye), + testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye + ), Error::::AlreadyVotedThis ); }); @@ -371,14 +407,19 @@ fn vote_on_proposal_successfuly() { let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = - testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 1, + crate::Vote::Aye, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CrossChainPropoposalVoteRegistered { - proposal_id: 1, - voter: ALICE, - vote: crate::Vote::Aye, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CrossChainPropoposalVoteRegistered { + proposal_id: 1, + voter: ALICE, + vote: crate::Vote::Aye, + }, + )); }); } @@ -389,7 +430,7 @@ fn initiate_proposal_successfuly() { const COLLECTION_ID: u32 = 1; let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0,ALICE); + let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE); let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 1, BOB); let _ = testpara::XcNFT::collection_x_transfer( @@ -397,19 +438,32 @@ fn initiate_proposal_successfuly() { 0, Some(COLLECTION_ID), 2000.into(), - None + None, ); - let _ = testpara::XcNFT::collection_x_transfer_vote(testpara::RuntimeOrigin::signed(ALICE), 0, crate::Vote::Aye); + let _ = testpara::XcNFT::collection_x_transfer_vote( + testpara::RuntimeOrigin::signed(ALICE), + 0, + crate::Vote::Aye, + ); testpara::System::set_block_number(11); - let _ = testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 0); + let _ = testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 0, + ); let nfts = vec![(0, ALICE, BoundedVec::new()), (1, BOB, BoundedVec::new())]; - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionAndNFTsDiffTransferred { origin_collection_id: 0, nfts: nfts, destination_para_id: 2000.into(), to_address: ALICE })); - + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionAndNFTsDiffTransferred { + origin_collection_id: 0, + nfts, + destination_para_id: 2000.into(), + to_address: ALICE, + }, + )); }); } @@ -419,7 +473,10 @@ fn try_initiating_proposal_doesnt_exist() { testpara::System::set_block_number(1); assert_noop!( - testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 1), + testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 1 + ), Error::::ProposalDoesNotExist ); }); @@ -452,7 +509,10 @@ fn try_initiating_proposal_collection_doesnt_exist() { let _ = crate::CrossChainProposals::insert(1, proposal); assert_noop!( - testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 1), + testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 1 + ), Error::::CollectionDoesNotExist ); }); @@ -485,7 +545,10 @@ fn try_initiating_proposal_no_collection_owner() { let _ = crate::CrossChainProposals::insert(1, proposal); assert_noop!( - testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 1), + testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 1 + ), Error::::NotCollectionOwner ); }); @@ -516,24 +579,41 @@ fn try_initiating_proposal_that_did_not_pass() { }; let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = testpara::XcNFT::collection_x_transfer_initiate(testpara::RuntimeOrigin::signed(ALICE), 1); + let _ = testpara::XcNFT::collection_x_transfer_initiate( + testpara::RuntimeOrigin::signed(ALICE), + 1, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::ProposalDidNotPass { proposal_id: 1 })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::ProposalDidNotPass { proposal_id: 1 }, + )); }); } #[test] fn try_sending_nft_successful() { - ParaA::execute_with(|| { testpara::System::set_block_number(2); let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0,ALICE); + let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - let _ = testpara::XcNFT::nft_x_transfer(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), 1, 1); + let _ = testpara::XcNFT::nft_x_transfer( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + 1000.into(), + 1, + 1, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTTransferred { origin_collection_id: 0, origin_asset_id: 0, destination_para_id: 1000.into(), destination_collection_id: 1, destination_asset_id: 1 })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTTransferred { + origin_collection_id: 0, + origin_asset_id: 0, + destination_para_id: 1000.into(), + destination_collection_id: 1, + destination_asset_id: 1, + })); }); } @@ -543,7 +623,14 @@ fn try_sending_nft_no_collection() { testpara::System::set_block_number(2); assert_noop!( - testpara::XcNFT::nft_x_transfer(testpara::RuntimeOrigin::signed(ALICE), 1, 0, 1000.into(), 1, 1), + testpara::XcNFT::nft_x_transfer( + testpara::RuntimeOrigin::signed(ALICE), + 1, + 0, + 1000.into(), + 1, + 1 + ), Error::::CollectionDoesNotExist ); }); @@ -557,7 +644,14 @@ fn try_sending_nft_no_nft() { let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); assert_noop!( - testpara::XcNFT::nft_x_transfer(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), 1, 1), + testpara::XcNFT::nft_x_transfer( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + 1000.into(), + 1, + 1 + ), Error::::NFTDoesNotExist ); }); @@ -573,7 +667,14 @@ fn try_sending_nft_not_nft_owner() { let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE); assert_noop!( - testpara::XcNFT::nft_x_transfer(testpara::RuntimeOrigin::signed(BOB), 0, 0, 1000.into(), 1, 1), + testpara::XcNFT::nft_x_transfer( + testpara::RuntimeOrigin::signed(BOB), + 0, + 0, + 1000.into(), + 1, + 1 + ), Error::::NotNFTOwner ); }); @@ -585,7 +686,14 @@ fn try_claiming_nft_no_collection() { testpara::System::set_block_number(2); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 1u32, + 0u32, + 100u32.into(), + 1u32, + 1u32 + ), Error::::CollectionDoesNotExist ); }); @@ -599,7 +707,14 @@ fn try_claiming_nft_no_collection_origin() { let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 1u32, + 0u32, + 100u32.into(), + 1u32, + 1u32 + ), Error::::CollectionDoesNotExist ); }); @@ -621,7 +736,14 @@ fn try_claiming_nft_wrong_origin_collection() { let _ = ReceivedCollections::::insert(0, collections); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 1u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 0u32, + 0u32, + 100u32.into(), + 0u32, + 1u32 + ), Error::::WrongOriginCollectionAtOrigin ); }); @@ -632,7 +754,6 @@ fn try_claiming_nft_wrong_nft() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); let collections: ReceivedCols = ReceivedCols:: { @@ -644,7 +765,14 @@ fn try_claiming_nft_wrong_nft() { let _ = ReceivedCollections::::insert(0, collections); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 0u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 0u32, + 0u32, + 100u32.into(), + 0u32, + 0u32 + ), Error::::NFTNotReceived ); }); @@ -682,7 +810,14 @@ fn try_claiming_nft_not_owner() { let _ = ReceivedAssets::::insert((1, 0), nfts); assert_noop!( - testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(BOB), 0u32, 0u32, 0u32, 1u32, 0u32), + testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(BOB), + 0u32, + 0u32, + 0u32, + 1u32, + 0u32 + ), Error::::NotNFTOwner ); }); @@ -720,7 +855,14 @@ fn try_claiming_nft_success() { let _ = ReceivedAssets::::insert((1, 0), nfts); testpara::System::set_block_number(3); - let _ = testpara::XcNFT::nft_x_claim(testpara::RuntimeOrigin::signed(ALICE), 0u32, 0u32, 0u32, 1u32, 0u32); + let _ = testpara::XcNFT::nft_x_claim( + testpara::RuntimeOrigin::signed(ALICE), + 0u32, + 0u32, + 0u32, + 1u32, + 0u32, + ); testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTClaimed { collection_claimed_from: 1, @@ -744,11 +886,13 @@ fn try_collection_parse_empty_successful() { None, ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionReceived { - origin_collection_id: 1, - received_collection_id: 1, - to_address: ALICE, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionReceived { + origin_collection_id: 1, + received_collection_id: 1, + to_address: ALICE, + }, + )); }); } @@ -762,11 +906,15 @@ fn try_parse_collection_burn_successful() { let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = testpara::XcNFT::parse_collection_burn(testpara::RuntimeOrigin::signed(ALICE), 0, destroy_witness); + let _ = testpara::XcNFT::parse_collection_burn( + testpara::RuntimeOrigin::signed(ALICE), + 0, + destroy_witness, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_uniques::Event::Destroyed { - collection: 0, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_uniques::Event::Destroyed { collection: 0 }, + )); }); } @@ -777,14 +925,19 @@ fn try_parse_collection_metadata_successful() { let _ = testpara::NFTs::create(testpara::RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = - testpara::XcNFT::parse_collection_metadata(testpara::RuntimeOrigin::signed(ALICE), 0, BoundedVec::new()); + let _ = testpara::XcNFT::parse_collection_metadata( + testpara::RuntimeOrigin::signed(ALICE), + 0, + BoundedVec::new(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_uniques::Event::CollectionMetadataSet { - collection: 0, - data: BoundedVec::new(), - is_frozen: false, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_uniques::Event::CollectionMetadataSet { + collection: 0, + data: BoundedVec::new(), + is_frozen: false, + }, + )); }); } @@ -799,11 +952,9 @@ fn try_parse_nft_burn_successful() { let _ = testpara::XcNFT::parse_nft_burn(testpara::RuntimeOrigin::signed(ALICE), 0, 0); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_uniques::Event::Burned { - collection: 0, - item: 0, - owner: ALICE, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_uniques::Event::Burned { collection: 0, item: 0, owner: ALICE }, + )); }); } @@ -816,14 +967,21 @@ fn try_parse_nft_metadata_successful() { let _ = testpara::NFTs::mint(testpara::RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - let _ = testpara::XcNFT::parse_nft_metadata(testpara::RuntimeOrigin::signed(ALICE), 0, 0, BoundedVec::new()); + let _ = testpara::XcNFT::parse_nft_metadata( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_uniques::Event::MetadataSet { - collection: 0, - item: 0, - data: BoundedVec::new(), - is_frozen: false - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_uniques::Event::MetadataSet { + collection: 0, + item: 0, + data: BoundedVec::new(), + is_frozen: false, + }, + )); }); } @@ -838,12 +996,9 @@ fn try_parse_nft_owner_successful() { let _ = testpara::XcNFT::parse_nft_owner(testpara::RuntimeOrigin::signed(ALICE), BOB, 0, 0); - testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs(pallet_uniques::Event::Transferred { - collection: 0, - item: 0, - from: ALICE, - to: BOB, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::NFTs( + pallet_uniques::Event::Transferred { collection: 0, item: 0, from: ALICE, to: BOB }, + )); }); } @@ -1001,11 +1156,13 @@ fn try_parse_nft_transfer_return_to_origin() { 0, ParachainInfo::parachain_id(), ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTReturnedToOrigin { - returned_from_collection_id: 0, - returned_from_asset_id: 0, - to_address: ALICE, - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::NFTReturnedToOrigin { + returned_from_collection_id: 0, + returned_from_asset_id: 0, + to_address: ALICE, + }, + )); }); } @@ -1026,10 +1183,9 @@ fn parse_collection_same_owner_successful() { 0, None, ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionWithNftsReceived { - collection_id: 0, - items: nfts.clone(), - })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionWithNftsReceived { collection_id: 0, items: nfts.clone() }, + )); }); } @@ -1038,7 +1194,8 @@ fn parse_collection_diff_nft_owners_successful() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let mut nfts: Vec<(u32, AccountId32, BoundedVec)> = Vec::new(); + let mut nfts: Vec<(u32, AccountId32, BoundedVec)> = + Vec::new(); nfts.push((1, BOB, BoundedVec::new())); let _ = testpara::XcNFT::parse_collection_diff_owners( @@ -1057,37 +1214,72 @@ fn parse_collection_diff_nft_owners_successful() { } #[test] -fn try_collection_metadata_success(){ +fn try_collection_metadata_success() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::collection_x_update(testpara::RuntimeOrigin::signed(ALICE), 0, 1000.into(), BoundedVec::new()); + let _ = testpara::XcNFT::collection_x_update( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 1000.into(), + BoundedVec::new(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionMetadataSent { collection_id: 0, proposed_data: BoundedVec::new(), owner: ALICE, destination: 1000.into()})); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionMetadataSent { + collection_id: 0, + proposed_data: BoundedVec::new(), + owner: ALICE, + destination: 1000.into(), + }, + )); }); } #[test] -fn try_collection_owner_send_success(){ +fn try_collection_owner_send_success() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::collection_x_change_owner(testpara::RuntimeOrigin::signed(ALICE), 0, 1000.into(), BOB); + let _ = testpara::XcNFT::collection_x_change_owner( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 1000.into(), + BOB, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionOwnershipSent { collection_id: 0, proposed_owner: BOB, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionOwnershipSent { + collection_id: 0, + proposed_owner: BOB, + destination: 1000.into(), + }, + )); }); } #[test] -fn try_collection_burn_success(){ +fn try_collection_burn_success() { ParaA::execute_with(|| { testpara::System::set_block_number(2); let witness = GeneralizedDestroyWitness { item_meta: 0, item_configs: 0, attributes: 0 }; - let _ = testpara::XcNFT::collection_x_burn(testpara::RuntimeOrigin::signed(ALICE), 0, 1000.into(), witness.clone()); + let _ = testpara::XcNFT::collection_x_burn( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 1000.into(), + witness.clone(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::CollectionBurnSent { collection_id: 0, burn_data: witness.clone(), owner: ALICE, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::CollectionBurnSent { + collection_id: 0, + burn_data: witness.clone(), + owner: ALICE, + destination: 1000.into(), + }, + )); }); } @@ -1096,9 +1288,21 @@ fn try_nft_metadata_successful() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::nft_x_update(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), BoundedVec::new()); + let _ = testpara::XcNFT::nft_x_update( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + 1000.into(), + BoundedVec::new(), + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTMetadataSent { collection_id: 0, asset_id: 0, proposed_data: BoundedVec::new(), owner: ALICE, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTMetadataSent { + collection_id: 0, + asset_id: 0, + proposed_data: BoundedVec::new(), + owner: ALICE, + destination: 1000.into(), + })); }); } @@ -1107,9 +1311,22 @@ fn try_nft_owner_successful() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::nft_x_change_owner(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), BOB); + let _ = testpara::XcNFT::nft_x_change_owner( + testpara::RuntimeOrigin::signed(ALICE), + 0, + 0, + 1000.into(), + BOB, + ); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTOwnershipSent { collection_id: 0, asset_id: 0, proposed_owner: BOB, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT( + Event::NFTOwnershipSent { + collection_id: 0, + asset_id: 0, + proposed_owner: BOB, + destination: 1000.into(), + }, + )); }); } @@ -1118,8 +1335,14 @@ fn try_nft_burn_successful() { ParaA::execute_with(|| { testpara::System::set_block_number(2); - let _ = testpara::XcNFT::nft_x_burn(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into()); + let _ = + testpara::XcNFT::nft_x_burn(testpara::RuntimeOrigin::signed(ALICE), 0, 0, 1000.into()); - testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTBurnSent { collection_id: 0, asset_id: 0, owner: ALICE, destination: 1000.into() })); + testpara::System::assert_has_event(testpara::RuntimeEvent::XcNFT(Event::NFTBurnSent { + collection_id: 0, + asset_id: 0, + owner: ALICE, + destination: 1000.into(), + })); }); -} \ No newline at end of file +} diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara.rs index 4a455c83a463..c9c37b93d34c 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara.rs @@ -23,15 +23,16 @@ use parachain_info; use core::marker::PhantomData; use frame_support::{ - construct_runtime, derive_impl, parameter_types, + construct_runtime, derive_impl, + pallet_prelude::Get, + parameter_types, traits::{ConstU128, ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, Nothing}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; -use frame_support::pallet_prelude::Get; use frame_system::{EnsureRoot, EnsureSigned}; use sp_core::ConstU32; use sp_runtime::{ - traits::{ConstU64, Verify, IdentityLookup}, + traits::{ConstU64, IdentityLookup, Verify}, AccountId32, BuildStorage, MultiSignature, }; use xcm::latest::prelude::*; @@ -61,12 +62,11 @@ impl pallet_balances::Config for Runtime { type AccountStore = System; } - pub const UNIT: Balance = 1; parameter_types! { pub const CollectionDeposit: Balance = 0 * UNIT; // 1 UNIT deposit to create asset collection pub const ItemDeposit: Balance = 0 * UNIT; // 1/100 UNIT deposit to create asset item - pub const KeyLimit: u32 = 32; + pub const KeyLimit: u32 = 32; pub const ValueLimit: u32 = 64; pub const UniquesMetadataDepositBase: Balance = 0 * UNIT; pub const AttributeDepositBase: Balance = 0 * UNIT; @@ -199,8 +199,8 @@ construct_runtime!( Balances: pallet_balances, MsgQueue: mock_message_queue, PolkadotXcm: pallet_xcm, - NFTs: pallet_uniques, - XcNFT: crate, - ParachainInfo: parachain_info, + NFTs: pallet_uniques, + XcNFT: crate, + ParachainInfo: parachain_info, } -); \ No newline at end of file +); diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/asset_transactor.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/asset_transactor.rs index 4d1e5d1ea4d3..0de69ae2790a 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/asset_transactor.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/asset_transactor.rs @@ -15,11 +15,11 @@ // along with Polkadot. If not, see . use crate::tests::testpara::{ - constants::KsmLocation, location_converter::LocationConverter, AccountId, Balances -}; -use xcm_builder::{FungibleAdapter, IsConcrete + constants::KsmLocation, location_converter::LocationConverter, AccountId, Balances, }; +use xcm_builder::{FungibleAdapter, IsConcrete}; -type LocalAssetTransactor = FungibleAdapter, LocationConverter, AccountId, ()>; +type LocalAssetTransactor = + FungibleAdapter, LocationConverter, AccountId, ()>; -pub type AssetTransactor = LocalAssetTransactor; \ No newline at end of file +pub type AssetTransactor = LocalAssetTransactor; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/barrier.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/barrier.rs index b0ac69069cf1..25db7638accd 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/barrier.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/barrier.rs @@ -17,4 +17,4 @@ use frame_support::traits::Everything; use xcm_builder::AllowExplicitUnpaidExecutionFrom; -pub type Barrier = AllowExplicitUnpaidExecutionFrom; \ No newline at end of file +pub type Barrier = AllowExplicitUnpaidExecutionFrom; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/constants.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/constants.rs index 59e1f077d87c..62460e30dc67 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/constants.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/constants.rs @@ -28,4 +28,4 @@ parameter_types! { pub const KsmLocation: Location = Location::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainId::::get().into())].into(); -} \ No newline at end of file +} diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/location_converter.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/location_converter.rs index 235bf3bfd6de..70608e0b7d26 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/location_converter.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/location_converter.rs @@ -22,4 +22,4 @@ type LocationToAccountId = ( AccountId32Aliases, ); -pub type LocationConverter = LocationToAccountId; \ No newline at end of file +pub type LocationConverter = LocationToAccountId; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/mod.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/mod.rs index 44a7f3dc14c8..b44ef42cc068 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/mod.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/mod.rs @@ -62,4 +62,4 @@ impl xcm_executor::Config for XcmConfig { type HrmpChannelAcceptedHandler = (); type HrmpChannelClosingHandler = (); type XcmRecorder = PolkadotXcm; -} \ No newline at end of file +} diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/origin_converter.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/origin_converter.rs index aa3a32ee5abe..ee06ced0f0c0 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/origin_converter.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/origin_converter.rs @@ -26,4 +26,4 @@ type XcmOriginToCallOrigin = ( XcmPassthrough, ); -pub type OriginConverter = XcmOriginToCallOrigin; \ No newline at end of file +pub type OriginConverter = XcmOriginToCallOrigin; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/reserve.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/reserve.rs index f0700b59bb3a..7ef801b543ee 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/reserve.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/reserve.rs @@ -18,4 +18,4 @@ use crate::tests::testpara::teleporter::TrustedTeleporters; use frame_support::traits::EverythingBut; use xcm_builder::NativeAsset; -pub type TrustedReserves = (NativeAsset, EverythingBut); \ No newline at end of file +pub type TrustedReserves = (NativeAsset, EverythingBut); diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/teleporter.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/teleporter.rs index a068087953cd..41cb7a5eb2de 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/teleporter.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/teleporter.rs @@ -24,4 +24,4 @@ parameter_types! { = (NftCollectionOne::get(), (Parent,).into()); } -pub type TrustedTeleporters = xcm_builder::Case; \ No newline at end of file +pub type TrustedTeleporters = xcm_builder::Case; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/weigher.rs b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/weigher.rs index 74ad2278aa14..d8284310cb3c 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/weigher.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testpara/xcm_config/weigher.rs @@ -24,4 +24,4 @@ parameter_types! { pub const MaxInstructions: u32 = 100; } -pub type Weigher = FixedWeightBounds; \ No newline at end of file +pub type Weigher = FixedWeightBounds; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay.rs index 3d0d78f5b573..ac0673b67b13 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay.rs @@ -27,14 +27,17 @@ use frame_support::{ weights::{Weight, WeightMeter}, }; -use frame_system::{EnsureRoot,EnsureSigned}; -use sp_core::ConstU32; -use sp_runtime::{traits::{Verify,IdentityLookup}, AccountId32,MultiSignature}; +use frame_system::{EnsureRoot, EnsureSigned}; use polkadot_runtime_parachains::{ configuration, inclusion::{AggregateMessageOrigin, UmpQueueId}, origin, shared, }; +use sp_core::ConstU32; +use sp_runtime::{ + traits::{IdentityLookup, Verify}, + AccountId32, MultiSignature, +}; use xcm::latest::prelude::*; use xcm_builder::{IsConcrete, SignedToAccountId32}; use xcm_executor::XcmExecutor; @@ -65,7 +68,7 @@ pub const UNIT: Balance = 1; parameter_types! { pub const CollectionDeposit: Balance = 0 * UNIT; // 1 UNIT deposit to create asset collection pub const ItemDeposit: Balance = 0 * UNIT; // 1/100 UNIT deposit to create asset item - pub const KeyLimit: u32 = 32; + pub const KeyLimit: u32 = 32; pub const ValueLimit: u32 = 64; pub const UniquesMetadataDepositBase: Balance = 0 * UNIT; pub const AttributeDepositBase: Balance = 0 * UNIT; @@ -196,4 +199,4 @@ construct_runtime!( NFTs: pallet_uniques, MessageQueue: pallet_message_queue, } -); \ No newline at end of file +); diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/asset_transactor.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/asset_transactor.rs index 9b316306a5b3..8db9559ba49b 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/asset_transactor.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/asset_transactor.rs @@ -23,6 +23,7 @@ use xcm_builder::{ }; use xcm_executor::traits::JustTry; -type LocalAssetTransactor = FungibleAdapter, LocationConverter, AccountId, ()>; +type LocalAssetTransactor = + FungibleAdapter, LocationConverter, AccountId, ()>; -pub type AssetTransactor = LocalAssetTransactor; \ No newline at end of file +pub type AssetTransactor = LocalAssetTransactor; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/barrier.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/barrier.rs index b0ac69069cf1..25db7638accd 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/barrier.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/barrier.rs @@ -17,4 +17,4 @@ use frame_support::traits::Everything; use xcm_builder::AllowExplicitUnpaidExecutionFrom; -pub type Barrier = AllowExplicitUnpaidExecutionFrom; \ No newline at end of file +pub type Barrier = AllowExplicitUnpaidExecutionFrom; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/constants.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/constants.rs index 2266c223f40d..f590c42990da 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/constants.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/constants.rs @@ -28,4 +28,4 @@ parameter_types! { pub RelayNetwork: NetworkId = ByGenesis([0; 32]); pub UniversalLocation: InteriorLocation = RelayNetwork::get().into(); pub UnitWeightCost: u64 = 1_000; -} \ No newline at end of file +} diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/location_converter.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/location_converter.rs index 88c26f6f7947..ad9acb3bdd54 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/location_converter.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/location_converter.rs @@ -22,4 +22,4 @@ type LocationToAccountId = ( AccountId32Aliases, ); -pub type LocationConverter = LocationToAccountId; \ No newline at end of file +pub type LocationConverter = LocationToAccountId; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/mod.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/mod.rs index d483a20d83a0..9bd37855b18e 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/mod.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/mod.rs @@ -25,8 +25,7 @@ pub mod weigher; use crate::tests::testrelay::{RuntimeCall, XcmPallet}; use frame_support::traits::{Everything, Nothing}; use xcm_builder::{EnsureDecodableXcm, FixedRateOfFungible, FrameTransactionalProcessor}; -use xcm_executor::Config; -use xcm_executor::traits::WithOriginFilter; +use xcm_executor::{traits::WithOriginFilter, Config}; // Generated from `decl_test_network!` pub type XcmRouter = EnsureDecodableXcm; @@ -62,4 +61,4 @@ impl Config for XcmConfig { type HrmpChannelAcceptedHandler = (); type HrmpChannelClosingHandler = (); type XcmRecorder = XcmPallet; -} \ No newline at end of file +} diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/origin_converter.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/origin_converter.rs index ea14cbfd38e2..c8eba67237c0 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/origin_converter.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/origin_converter.rs @@ -31,4 +31,4 @@ type LocalOriginConverter = ( ChildSystemParachainAsSuperuser, ); -pub type OriginConverter = LocalOriginConverter; \ No newline at end of file +pub type OriginConverter = LocalOriginConverter; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/teleporter.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/teleporter.rs index 0d322538c592..92e5065044e6 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/teleporter.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/teleporter.rs @@ -23,4 +23,4 @@ parameter_types! { pub NftCollectionForChild: (AssetFilter, Location) = (NftCollectionOnRelay::get(), Parachain(1).into()); } -pub type TrustedTeleporters = xcm_builder::Case; \ No newline at end of file +pub type TrustedTeleporters = xcm_builder::Case; diff --git a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/weigher.rs b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/weigher.rs index b99051539394..2cab9a91a1b7 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/weigher.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests/testrelay/xcm_config/weigher.rs @@ -24,4 +24,4 @@ parameter_types! { pub const MaxInstructions: u32 = 100; } -pub type Weigher = FixedWeightBounds; \ No newline at end of file +pub type Weigher = FixedWeightBounds; diff --git a/templates/parachain_two/pallets/xcnft/src/xmacros.rs b/templates/parachain_two/pallets/xcnft/src/xmacros.rs index 08defb3d1e21..8520eb3f343e 100644 --- a/templates/parachain_two/pallets/xcnft/src/xmacros.rs +++ b/templates/parachain_two/pallets/xcnft/src/xmacros.rs @@ -1,7 +1,6 @@ /// Code originates from pallet_nfts /// /// Used to mimic CollectionConfigFor parameter from NFTs pallet -/// macro_rules! impl_codec_bitflags { ($wrapper:ty, $size:ty, $bitflag_enum:ty) => { impl MaxEncodedLen for $wrapper {