From 48e38b0b08711859e874bf06ee1c64296b9ab2ce Mon Sep 17 00:00:00 2001 From: Dusan Morhac <55763425+dudo50@users.noreply.github.com> Date: Sun, 3 Nov 2024 01:20:35 +0100 Subject: [PATCH] fmt --- templates/parachain/pallets/xcnft/src/lib.rs | 8 +- templates/parachain/pallets/xcnft/src/mock.rs | 36 +- .../parachain/pallets/xcnft/src/tests.rs | 1617 +++++++++-------- .../parachain_two/pallets/xcnft/src/lib.rs | 11 +- .../parachain_two/pallets/xcnft/src/mock.rs | 36 +- .../parachain_two/pallets/xcnft/src/tests.rs | 1226 +++++++------ .../pallets/xcnft/src/xmacros.rs | 7 +- 7 files changed, 1574 insertions(+), 1367 deletions(-) diff --git a/templates/parachain/pallets/xcnft/src/lib.rs b/templates/parachain/pallets/xcnft/src/lib.rs index 740b7ea7a4f1..d94576e2cb68 100644 --- a/templates/parachain/pallets/xcnft/src/lib.rs +++ b/templates/parachain/pallets/xcnft/src/lib.rs @@ -921,7 +921,9 @@ pub mod pallet { // storage and emit event. if unwrapped_proposal.number_of_votes.aye.len() < number_of_votes / 2 || unwrapped_proposal.number_of_votes.aye.len() == 0 && - unwrapped_proposal.number_of_votes.nay.len() == 0 || unwrapped_proposal.number_of_votes.aye.len() == 0 && unwrapped_proposal.number_of_votes.nay.len() == 1 + unwrapped_proposal.number_of_votes.nay.len() == 0 || + unwrapped_proposal.number_of_votes.aye.len() == 0 && + unwrapped_proposal.number_of_votes.nay.len() == 1 { CrossChainProposals::::remove(proposal_id); @@ -1040,7 +1042,9 @@ pub mod pallet { if proposal.number_of_votes.aye.len() < number_of_votes / 2 || proposal.number_of_votes.aye.len() == 0 && - proposal.number_of_votes.nay.len() == 0 || proposal.number_of_votes.aye.len() == 0 && proposal.number_of_votes.nay.len() == 1 + proposal.number_of_votes.nay.len() == 0 || + proposal.number_of_votes.aye.len() == 0 && + proposal.number_of_votes.nay.len() == 1 { Self::deposit_event(Event::ProposalDidNotPass { proposal_id }); diff --git a/templates/parachain/pallets/xcnft/src/mock.rs b/templates/parachain/pallets/xcnft/src/mock.rs index bc113d442218..b5ef74496a8b 100644 --- a/templates/parachain/pallets/xcnft/src/mock.rs +++ b/templates/parachain/pallets/xcnft/src/mock.rs @@ -1,20 +1,14 @@ -use frame_support::weights::constants::RocksDbWeight; -use frame_system::{mocking::MockBlock, GenesisConfig}; -use sp_runtime::{traits::ConstU64, BuildStorage}; -use frame_support::parameter_types; +use frame_support::{parameter_types, traits::VariantCountOf, weights::constants::RocksDbWeight}; +use frame_system::{mocking::MockBlock, EnsureRoot, EnsureSigned, GenesisConfig}; use pallet_balances::AccountData; -use xcm_builder::WithUniqueTopic; -use sp_runtime::MultiSignature; -use sp_runtime::traits::Verify; -use frame_system::EnsureRoot; -use frame_system::EnsureSigned; use sp_core::ConstU32; -use frame_support::traits::VariantCountOf; -use sp_runtime::AccountId32 as AccountId; +use sp_runtime::{ + traits::{ConstU64, Verify}, + AccountId32 as AccountId, BuildStorage, MultiSignature, +}; +use xcm_builder::WithUniqueTopic; -pub type XcmRouter = WithUniqueTopic<( - (), -)>; +pub type XcmRouter = WithUniqueTopic<((),)>; // Configure a mock runtime to test the pallet. #[frame_support::runtime] @@ -39,14 +33,14 @@ mod test_runtime { #[runtime::pallet_index(1)] pub type XcNFT = crate; - #[runtime::pallet_index(2)] - pub type Balances = pallet_balances; + #[runtime::pallet_index(2)] + pub type Balances = pallet_balances; #[runtime::pallet_index(3)] pub type NFTs = pallet_nfts; - #[runtime::pallet_index(4)] - pub type ParachainInfo = parachain_info; + #[runtime::pallet_index(4)] + pub type ParachainInfo = parachain_info; } /// Balance of an account. @@ -88,7 +82,7 @@ impl frame_system::Config for Test { impl parachain_info::Config for Test {} impl crate::Config for Test { - type RuntimeEvent = RuntimeEvent; + type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type XcmSender = XcmRouter; type RuntimeCall = RuntimeCall; @@ -119,10 +113,10 @@ impl pallet_balances::Config for Test { parameter_types! { pub const SS58Prefix: u16 = 42; - pub const ExistentialDeposit: u128 = 500; + pub const ExistentialDeposit: u128 = 500; 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; diff --git a/templates/parachain/pallets/xcnft/src/tests.rs b/templates/parachain/pallets/xcnft/src/tests.rs index 699caa5cf3c2..e516cd7629a4 100644 --- a/templates/parachain/pallets/xcnft/src/tests.rs +++ b/templates/parachain/pallets/xcnft/src/tests.rs @@ -1,923 +1,1028 @@ -use crate::{mock::*, Error, Event, GeneralizedDestroyWitness, Proposal, ReceivedAssets, ReceivedCollections, ReceivedCols, ReceivedStruct, SentAssets, SentStruct}; +use crate::{ + mock::*, Error, Event, GeneralizedDestroyWitness, Proposal, ReceivedAssets, + ReceivedCollections, ReceivedCols, ReceivedStruct, SentAssets, SentStruct, +}; use frame_support::assert_noop; -use pallet_nfts::{CollectionConfigFor, CollectionSettings, MintSettings}; +use pallet_nfts::{CollectionConfigFor, CollectionSettings, Event::Destroyed, MintSettings}; use sp_runtime::{AccountId32, BoundedVec}; -use pallet_nfts::Event::Destroyed; pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); - #[test] fn try_sending_collection_that_doesnt_exist() { - - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - assert_noop!( - XcNFT::collection_x_transfer(RuntimeOrigin::signed(ALICE), COLLECTION_ID, Some(COLLECTION_ID), 2000.into(), None), - Error::::CollectionDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; + + assert_noop!( + XcNFT::collection_x_transfer( + RuntimeOrigin::signed(ALICE), + COLLECTION_ID, + Some(COLLECTION_ID), + 2000.into(), + None + ), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_sending_collection_that_user_doesnt_own() { - - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - assert_noop!( - XcNFT::collection_x_transfer(RuntimeOrigin::signed(BOB), 0, Some(COLLECTION_ID), 2000.into(), None), - Error::::NotCollectionOwner - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + assert_noop!( + XcNFT::collection_x_transfer( + RuntimeOrigin::signed(BOB), + 0, + Some(COLLECTION_ID), + 2000.into(), + None + ), + Error::::NotCollectionOwner + ); + }); } #[test] fn try_voting_on_non_existing_proposal() { - - new_test_ext().execute_with(|| { - System::set_block_number(1); - - assert_noop!( - XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 0, crate::Vote::Aye), - Error::::ProposalDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + + assert_noop!( + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 0, crate::Vote::Aye), + Error::::ProposalDoesNotExist + ); + }); } #[test] fn try_voting_on_proposal_when_no_owner() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: BoundedVec::new(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: BoundedVec::new() }, + end_time: 20u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + assert_noop!( + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(BOB), 1, crate::Vote::Aye), + Error::::NotNFTOwner + ); + }); +} - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: BoundedVec::new(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: BoundedVec::new(), - }, - end_time: 20u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - assert_noop!( - XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(BOB), 1, crate::Vote::Aye), - Error::::NotNFTOwner - ); - }); - -} - -#[test] -fn try_voting_on_proposal_expired(){ - - new_test_ext().execute_with(|| { - System::set_block_number(3); - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: owners.clone(), - nay: BoundedVec::new(), - }, - end_time: 1u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - let _ = XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); - - System::assert_last_event(RuntimeEvent::XcNFT(Event::ProposalExpired { - proposal_id: 1, - })); - }); +#[test] +fn try_voting_on_proposal_expired() { + new_test_ext().execute_with(|| { + System::set_block_number(3); + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: owners.clone(), nay: BoundedVec::new() }, + end_time: 1u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + let _ = + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + + System::assert_last_event(RuntimeEvent::XcNFT(Event::ProposalExpired { proposal_id: 1 })); + }); } #[test] fn try_voting_on_proposal_did_not_pass() { - new_test_ext().execute_with(|| { - System::set_block_number(3); - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 1u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - let _ = XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); - - System::assert_last_event(RuntimeEvent::XcNFT(Event::ProposalDidNotPass { - proposal_id: 1, - })); - }); + new_test_ext().execute_with(|| { + System::set_block_number(3); + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 1u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + let _ = + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + + System::assert_last_event(RuntimeEvent::XcNFT(Event::ProposalDidNotPass { + proposal_id: 1, + })); + }); } #[test] fn try_voting_on_proposal_again_same_vote() { - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 3u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - let _ = XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); - - assert_noop!( - XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye), - Error::::AlreadyVotedThis - ); - - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 3u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + let _ = + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + + assert_noop!( + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye), + Error::::AlreadyVotedThis + ); + }); } #[test] fn vote_on_proposal_successfuly() { - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 2u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - let _ = XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); - - System::assert_last_event(RuntimeEvent::XcNFT(Event::CrossChainPropoposalVoteRegistered { proposal_id: 1, voter: ALICE, vote: crate::Vote::Aye })); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 2u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + let _ = + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + + System::assert_last_event(RuntimeEvent::XcNFT(Event::CrossChainPropoposalVoteRegistered { + proposal_id: 1, + voter: ALICE, + vote: crate::Vote::Aye, + })); + }); } #[test] fn try_initiating_proposal_doesnt_exist() { - new_test_ext().execute_with(|| { - System::set_block_number(1); - - assert_noop!( - XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), - Error::::ProposalDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + + assert_noop!( + XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), + Error::::ProposalDoesNotExist + ); + }); } #[test] fn try_initiating_proposal_collection_doesnt_exist() { - new_test_ext().execute_with(|| { - System::set_block_number(1); - - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 2u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - assert_noop!( - XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), - Error::::CollectionDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 2u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + assert_noop!( + XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_initiating_proposal_no_collection_owner() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(BOB), ALICE, def_config); - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(BOB).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: 0, - proposed_collection_owner: BOB, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 1u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - assert_noop!( - XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), - Error::::NotCollectionOwner - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(BOB), ALICE, def_config); + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(BOB).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: 0, + proposed_collection_owner: BOB, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 1u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + assert_noop!( + XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), + Error::::NotCollectionOwner + ); + }); } - #[test] fn try_initiating_proposal_that_did_not_pass() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: 0, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 1u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1); - - System::assert_has_event(RuntimeEvent::XcNFT(Event::ProposalDidNotPass { proposal_id: 1, })); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: 0, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 1u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + let _ = XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1); + + System::assert_has_event(RuntimeEvent::XcNFT(Event::ProposalDidNotPass { proposal_id: 1 })); + }); } #[test] fn try_sending_nft_no_collection() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - assert_noop!( - XcNFT::nft_x_transfer(RuntimeOrigin::signed(ALICE), 1, 0, 1000.into(), 1, 1), - Error::::CollectionDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + assert_noop!( + XcNFT::nft_x_transfer(RuntimeOrigin::signed(ALICE), 1, 0, 1000.into(), 1, 1), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_sending_nft_no_nft() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - assert_noop!( - XcNFT::nft_x_transfer(RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), 1, 1), - Error::::NFTDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + assert_noop!( + XcNFT::nft_x_transfer(RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), 1, 1), + Error::::NFTDoesNotExist + ); + }); } #[test] fn try_sending_nft_not_nft_owner() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - assert_noop!( - XcNFT::nft_x_transfer(RuntimeOrigin::signed(BOB), 0, 0, 1000.into(), 1, 1), - Error::::NotNFTOwner - ); - }); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); + + assert_noop!( + XcNFT::nft_x_transfer(RuntimeOrigin::signed(BOB), 0, 0, 1000.into(), 1, 1), + Error::::NotNFTOwner + ); + }); } #[test] fn try_claiming_nft_no_collection() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), - Error::::CollectionDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_claiming_nft_no_collection_origin() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), - Error::::CollectionDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_claiming_nft_wrong_origin_collection() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - let collections: ReceivedCols:: = ReceivedCols:: { - origin_para_id: 1000.into(), - origin_collection_id: 10, - received_collection_id: 20, - }; - - let _ = ReceivedCollections::::insert(0, collections); - - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 1u32), - Error::::WrongOriginCollectionAtOrigin - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + let collections: ReceivedCols = ReceivedCols:: { + origin_para_id: 1000.into(), + origin_collection_id: 10, + received_collection_id: 20, + }; + + let _ = ReceivedCollections::::insert(0, collections); + + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 1u32), + Error::::WrongOriginCollectionAtOrigin + ); + }); } #[test] fn try_claiming_nft_wrong_nft() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - let collections: ReceivedCols:: = ReceivedCols:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - received_collection_id: 0, - }; - - let _ = ReceivedCollections::::insert(0, collections); - - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 0u32), - Error::::NFTNotReceived - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + let collections: ReceivedCols = ReceivedCols:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + received_collection_id: 0, + }; + + let _ = ReceivedCollections::::insert(0, collections); + + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 0u32), + Error::::NFTNotReceived + ); + }); } #[test] fn try_claiming_nft_not_owner() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE, None); - - System::set_block_number(3); - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE, None); - - let collections: ReceivedCols:: = ReceivedCols:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - received_collection_id: 0, - }; - - let _ = ReceivedCollections::::insert(0, collections); - - let nfts: ReceivedStruct:: = ReceivedStruct:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - origin_asset_id: 0, - received_collection_id: 1, - received_asset_id: 0, - }; - - let _ = ReceivedAssets::::insert((1, 0), nfts); - - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(BOB), 0u32, 0u32, 0u32, 1u32, 0u32), - Error::::NotNFTOwner - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE, None); + + System::set_block_number(3); + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE, None); + + let collections: ReceivedCols = ReceivedCols:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + received_collection_id: 0, + }; + + let _ = ReceivedCollections::::insert(0, collections); + + let nfts: ReceivedStruct = ReceivedStruct:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + origin_asset_id: 0, + received_collection_id: 1, + received_asset_id: 0, + }; + + let _ = ReceivedAssets::::insert((1, 0), nfts); + + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(BOB), 0u32, 0u32, 0u32, 1u32, 0u32), + Error::::NotNFTOwner + ); + }); } #[test] fn try_claiming_nft_success() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE, None); - - System::set_block_number(3); - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE, None); - - let collections: ReceivedCols:: = ReceivedCols:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - received_collection_id: 0, - }; - - let _ = ReceivedCollections::::insert(0, collections); - - let nfts: ReceivedStruct:: = ReceivedStruct:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - origin_asset_id: 0, - received_collection_id: 1, - received_asset_id: 0, - }; - - let _ = ReceivedAssets::::insert((1, 0), nfts); - System::set_block_number(3); - - let _ = XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 0u32, 1u32, 0u32); - - System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTClaimed { collection_claimed_from: 1, asset_removed: 0, collection_claimed_to: 0, asset_claimed: 0 })); - - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE, None); + + System::set_block_number(3); + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE, None); + + let collections: ReceivedCols = ReceivedCols:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + received_collection_id: 0, + }; + + let _ = ReceivedCollections::::insert(0, collections); + + let nfts: ReceivedStruct = ReceivedStruct:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + origin_asset_id: 0, + received_collection_id: 1, + received_asset_id: 0, + }; + + let _ = ReceivedAssets::::insert((1, 0), nfts); + System::set_block_number(3); + + let _ = XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 0u32, 1u32, 0u32); + + System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTClaimed { + collection_claimed_from: 1, + asset_removed: 0, + collection_claimed_to: 0, + asset_claimed: 0, + })); + }); } #[test] fn try_collection_parse_empty_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let _ = XcNFT::parse_collection_empty(RuntimeOrigin::signed(ALICE), 1, None, BoundedVec::new(), None); - - System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionReceived { origin_collection_id: 1, received_collection_id: 1, to_address: ALICE })); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let _ = XcNFT::parse_collection_empty( + RuntimeOrigin::signed(ALICE), + 1, + None, + BoundedVec::new(), + None, + ); + + System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionReceived { + origin_collection_id: 1, + received_collection_id: 1, + to_address: ALICE, + })); + }); } #[test] -fn try_parse_collection_burn_successful(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); +fn try_parse_collection_burn_successful() { + new_test_ext().execute_with(|| { + System::set_block_number(2); - let destroy_witness = GeneralizedDestroyWitness { - item_meta: 0, - item_configs: 0, - attributes: 0, - }; + let destroy_witness = + GeneralizedDestroyWitness { item_meta: 0, item_configs: 0, attributes: 0 }; - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = XcNFT::parse_collection_burn(RuntimeOrigin::signed(ALICE), 0, destroy_witness); + let _ = XcNFT::parse_collection_burn(RuntimeOrigin::signed(ALICE), 0, destroy_witness); - System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::Destroyed { collection: 0 })); - }); + System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::Destroyed { + collection: 0, + })); + }); } #[test] fn try_parse_collection_metadata_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - let _ = XcNFT::parse_collection_metadata(RuntimeOrigin::signed(ALICE), 0, BoundedVec::new()); - - System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::CollectionMetadataSet { collection: 0, data: BoundedVec::new() })); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + let _ = + XcNFT::parse_collection_metadata(RuntimeOrigin::signed(ALICE), 0, BoundedVec::new()); + + System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::CollectionMetadataSet { + collection: 0, + data: BoundedVec::new(), + })); + }); } #[test] fn try_parse_collection_owner_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - pallet_nfts::OwnershipAcceptance::::insert(BOB, 0); - - let _ = XcNFT::parse_collection_owner(RuntimeOrigin::signed(ALICE), BOB, 0); + pallet_nfts::OwnershipAcceptance::::insert(BOB, 0); - System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::OwnerChanged { collection: 0, new_owner: BOB })); - }); + let _ = XcNFT::parse_collection_owner(RuntimeOrigin::signed(ALICE), BOB, 0); + + System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::OwnerChanged { + collection: 0, + new_owner: BOB, + })); + }); } #[test] fn try_parse_nft_burn_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); - let _ = XcNFT::parse_nft_burn(RuntimeOrigin::signed(ALICE), 0, 0); + let _ = XcNFT::parse_nft_burn(RuntimeOrigin::signed(ALICE), 0, 0); - System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::Burned { collection: 0, item: 0, owner: ALICE })); - }); + System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::Burned { + collection: 0, + item: 0, + owner: ALICE, + })); + }); } #[test] fn try_parse_nft_metadata_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); - let _ = XcNFT::parse_nft_metadata(RuntimeOrigin::signed(ALICE), 0, 0, BoundedVec::new()); + let _ = XcNFT::parse_nft_metadata(RuntimeOrigin::signed(ALICE), 0, 0, BoundedVec::new()); - System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::ItemMetadataSet { collection: 0, item: 0, data: BoundedVec::new() })); - }); + System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::ItemMetadataSet { + collection: 0, + item: 0, + data: BoundedVec::new(), + })); + }); } #[test] fn try_parse_nft_owner_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); - let _ = XcNFT::parse_nft_owner(RuntimeOrigin::signed(ALICE), BOB ,0, 0); + let _ = XcNFT::parse_nft_owner(RuntimeOrigin::signed(ALICE), BOB, 0, 0); - System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::Transferred { collection: 0, item: 0, from: ALICE, to: BOB })); - }); + System::assert_has_event(RuntimeEvent::NFTs(pallet_nfts::Event::Transferred { + collection: 0, + item: 0, + from: ALICE, + to: BOB, + })); + }); } #[test] fn try_parse_nft_transfer_no_collection() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - assert_noop!(XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,1000.into()), Error::::CollectionDoesNotExist); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + assert_noop!( + XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into() + ), + Error::::CollectionDoesNotExist + ); + }); } - #[test] fn try_parse_nft_transfer_already_received() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); - - let nfts: ReceivedStruct:: = ReceivedStruct:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - origin_asset_id: 0, - received_collection_id: 0, - received_asset_id: 0, - }; - - let _ = ReceivedAssets::::insert((0, 0), nfts); - - - assert_noop!(XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,1000.into()), Error::::NFTAlreadyReceived); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); + + let nfts: ReceivedStruct = ReceivedStruct:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + origin_asset_id: 0, + received_collection_id: 0, + received_asset_id: 0, + }; + + let _ = ReceivedAssets::::insert((0, 0), nfts); + + assert_noop!( + XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into() + ), + Error::::NFTAlreadyReceived + ); + }); } #[test] fn try_parse_nft_transfer_not_collection_owner() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); - - - assert_noop!(XcNFT::parse_nft_transfer(RuntimeOrigin::signed(BOB),0,0,BoundedVec::new(),0,0,1000.into()), Error::::NotCollectionOwner); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); + + assert_noop!( + XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(BOB), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into() + ), + Error::::NotCollectionOwner + ); + }); } #[test] fn try_parse_nft_transfer_not_existing_nft() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); - - - assert_noop!(XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,1000.into()), Error::::NFTExists); - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = NFTs::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE, None); + + assert_noop!( + XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into() + ), + Error::::NFTExists + ); + }); } #[test] -fn try_parse_nft_transfer_successful(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - let _ = XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,1000.into()); - System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTReceived { origin_collection_id: 0, origin_asset_id: 0, received_collection_id: 0, received_asset_id: 0, to_address: ALICE})); -}); +fn try_parse_nft_transfer_successful() { + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + let _ = XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into(), + ); + System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTReceived { + origin_collection_id: 0, + origin_asset_id: 0, + received_collection_id: 0, + received_asset_id: 0, + to_address: ALICE, + })); + }); } #[test] -fn try_parse_nft_transfer_return_to_origin(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); - - let sent = SentStruct:: { - - origin_para_id: ParachainInfo::parachain_id(), - origin_collection_id: 0, - origin_asset_id: 0, - destination_collection_id: 0, - destination_asset_id: 0, - }; - - let _ = SentAssets::::insert((0, 0), sent); - - //Set parachain id to 1000 - ParachainInfo::parachain_id(); - - let _ = XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,ParachainInfo::parachain_id()); - System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTReturnedToOrigin { returned_from_collection_id: 0, returned_from_asset_id: 0, to_address: ALICE })); - - }); +fn try_parse_nft_transfer_return_to_origin() { + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let _ = NFTs::create(RuntimeOrigin::signed(ALICE), ALICE, def_config); + + let sent = SentStruct:: { + origin_para_id: ParachainInfo::parachain_id(), + origin_collection_id: 0, + origin_asset_id: 0, + destination_collection_id: 0, + destination_asset_id: 0, + }; + + let _ = SentAssets::::insert((0, 0), sent); + + //Set parachain id to 1000 + ParachainInfo::parachain_id(); + + let _ = XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + ParachainInfo::parachain_id(), + ); + System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTReturnedToOrigin { + returned_from_collection_id: 0, + returned_from_asset_id: 0, + to_address: ALICE, + })); + }); } #[test] -fn parse_collection_same_owner_successful(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let mut nfts: Vec<(u32, BoundedVec)> = Vec::new(); - nfts.push((1, BoundedVec::new())); - - let _ = XcNFT::parse_collection_same_owner(RuntimeOrigin::signed(ALICE), Some(def_config), BoundedVec::new(), nfts.clone(), 1000.into(), 0, None); - System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionWithNftsReceived { collection_id: 0, items: nfts.clone() })); - }); +fn parse_collection_same_owner_successful() { + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let mut nfts: Vec<(u32, BoundedVec)> = Vec::new(); + nfts.push((1, BoundedVec::new())); + + let _ = XcNFT::parse_collection_same_owner( + RuntimeOrigin::signed(ALICE), + Some(def_config), + BoundedVec::new(), + nfts.clone(), + 1000.into(), + 0, + None, + ); + System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionWithNftsReceived { + collection_id: 0, + items: nfts.clone(), + })); + }); } #[test] -fn parse_collection_diff_nft_owners_successful(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let def_config: CollectionConfigFor = CollectionConfigFor:: { - settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, /* No maximum supply defined - * initially */ - mint_settings: MintSettings::default(), // Use default mint settings - }; - - let mut nfts: Vec<(u32, AccountId32, BoundedVec)> = Vec::new(); - nfts.push((1, BOB, BoundedVec::new())); - - let _ = XcNFT::parse_collection_diff_owners(RuntimeOrigin::signed(ALICE), Some(def_config), BoundedVec::new(), nfts.clone(), 1000.into(), 0, None); - System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionWithNftsDiffOwnersReceived { collection_id: 0, items: nfts.clone() })); - }); -} \ No newline at end of file +fn parse_collection_diff_nft_owners_successful() { + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let def_config: CollectionConfigFor = CollectionConfigFor:: { + settings: CollectionSettings::all_enabled(), // Default settings (all enabled) + max_supply: None, /* No maximum supply defined + * initially */ + mint_settings: MintSettings::default(), // Use default mint settings + }; + + let mut nfts: Vec<(u32, AccountId32, BoundedVec)> = Vec::new(); + nfts.push((1, BOB, BoundedVec::new())); + + let _ = XcNFT::parse_collection_diff_owners( + RuntimeOrigin::signed(ALICE), + Some(def_config), + BoundedVec::new(), + nfts.clone(), + 1000.into(), + 0, + None, + ); + System::assert_has_event(RuntimeEvent::XcNFT( + Event::CollectionWithNftsDiffOwnersReceived { collection_id: 0, items: nfts.clone() }, + )); + }); +} diff --git a/templates/parachain_two/pallets/xcnft/src/lib.rs b/templates/parachain_two/pallets/xcnft/src/lib.rs index 2e7565034299..071b4c5328cb 100644 --- a/templates/parachain_two/pallets/xcnft/src/lib.rs +++ b/templates/parachain_two/pallets/xcnft/src/lib.rs @@ -54,10 +54,9 @@ //! - `pallet-uniques` //! - `pallet-balances` //! - `parachain-info` -//! +//! //! Other pallets: //! - `enumflags2`` -//! #![cfg_attr(not(feature = "std"), no_std)] pub use pallet::*; @@ -1071,7 +1070,9 @@ pub mod pallet { // storage and emit event. if unwrapped_proposal.number_of_votes.aye.len() < number_of_votes / 2 || unwrapped_proposal.number_of_votes.aye.len() == 0 && - unwrapped_proposal.number_of_votes.nay.len() == 0 || unwrapped_proposal.number_of_votes.aye.len() == 0 && unwrapped_proposal.number_of_votes.nay.len() == 1 + unwrapped_proposal.number_of_votes.nay.len() == 0 || + unwrapped_proposal.number_of_votes.aye.len() == 0 && + unwrapped_proposal.number_of_votes.nay.len() == 1 { CrossChainProposals::::remove(proposal_id); @@ -1190,7 +1191,9 @@ pub mod pallet { if proposal.number_of_votes.aye.len() < number_of_votes / 2 || proposal.number_of_votes.aye.len() == 0 && - proposal.number_of_votes.nay.len() == 0 || proposal.number_of_votes.aye.len() == 0 && proposal.number_of_votes.nay.len() == 1 + proposal.number_of_votes.nay.len() == 0 || + proposal.number_of_votes.aye.len() == 0 && + proposal.number_of_votes.nay.len() == 1 { Self::deposit_event(Event::ProposalDidNotPass { proposal_id }); diff --git a/templates/parachain_two/pallets/xcnft/src/mock.rs b/templates/parachain_two/pallets/xcnft/src/mock.rs index 2f46dcb0f9b8..a87e24a6d2df 100644 --- a/templates/parachain_two/pallets/xcnft/src/mock.rs +++ b/templates/parachain_two/pallets/xcnft/src/mock.rs @@ -1,20 +1,14 @@ -use frame_support::weights::constants::RocksDbWeight; -use frame_system::{mocking::MockBlock, GenesisConfig}; -use sp_runtime::{traits::ConstU64, BuildStorage}; -use frame_support::parameter_types; +use frame_support::{parameter_types, traits::VariantCountOf, weights::constants::RocksDbWeight}; +use frame_system::{mocking::MockBlock, EnsureRoot, EnsureSigned, GenesisConfig}; use pallet_balances::AccountData; -use xcm_builder::WithUniqueTopic; -use sp_runtime::MultiSignature; -use sp_runtime::traits::Verify; -use frame_system::EnsureRoot; -use frame_system::EnsureSigned; use sp_core::ConstU32; -use frame_support::traits::VariantCountOf; -use sp_runtime::AccountId32 as AccountId; +use sp_runtime::{ + traits::{ConstU64, Verify}, + AccountId32 as AccountId, BuildStorage, MultiSignature, +}; +use xcm_builder::WithUniqueTopic; -pub type XcmRouter = WithUniqueTopic<( - (), -)>; +pub type XcmRouter = WithUniqueTopic<((),)>; // Configure a mock runtime to test the pallet. #[frame_support::runtime] @@ -39,14 +33,14 @@ mod test_runtime { #[runtime::pallet_index(1)] pub type XcNFT = crate; - #[runtime::pallet_index(2)] - pub type Balances = pallet_balances; + #[runtime::pallet_index(2)] + pub type Balances = pallet_balances; #[runtime::pallet_index(3)] pub type Uniques = pallet_uniques; - #[runtime::pallet_index(4)] - pub type ParachainInfo = parachain_info; + #[runtime::pallet_index(4)] + pub type ParachainInfo = parachain_info; } /// Balance of an account. @@ -88,7 +82,7 @@ impl frame_system::Config for Test { impl parachain_info::Config for Test {} impl crate::Config for Test { - type RuntimeEvent = RuntimeEvent; + type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type XcmSender = XcmRouter; type RuntimeCall = RuntimeCall; @@ -119,10 +113,10 @@ impl pallet_balances::Config for Test { parameter_types! { pub const SS58Prefix: u16 = 42; - pub const ExistentialDeposit: u128 = 500; + pub const ExistentialDeposit: u128 = 500; 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; diff --git a/templates/parachain_two/pallets/xcnft/src/tests.rs b/templates/parachain_two/pallets/xcnft/src/tests.rs index 1b60448fcd8e..f634a81b53cb 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests.rs @@ -1,765 +1,873 @@ -use crate::{mock::*, Error, Event, GeneralizedDestroyWitness, Proposal, ReceivedAssets, ReceivedCollections, ReceivedCols, ReceivedStruct, SentAssets, SentStruct}; +use crate::{ + mock::*, Error, Event, GeneralizedDestroyWitness, Proposal, ReceivedAssets, + ReceivedCollections, ReceivedCols, ReceivedStruct, SentAssets, SentStruct, +}; use frame_support::assert_noop; -use sp_runtime::{AccountId32, BoundedVec}; use pallet_uniques::Event::Destroyed; +use sp_runtime::{AccountId32, BoundedVec}; pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); - #[test] fn try_sending_collection_that_doesnt_exist() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - assert_noop!( - XcNFT::collection_x_transfer(RuntimeOrigin::signed(ALICE), COLLECTION_ID, Some(COLLECTION_ID), 2000.into(), None), - Error::::CollectionDoesNotExist - ); - }); + assert_noop!( + XcNFT::collection_x_transfer( + RuntimeOrigin::signed(ALICE), + COLLECTION_ID, + Some(COLLECTION_ID), + 2000.into(), + None + ), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_sending_collection_that_user_doesnt_own() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - assert_noop!( - XcNFT::collection_x_transfer(RuntimeOrigin::signed(BOB), 0, Some(COLLECTION_ID), 2000.into(), None), - Error::::NotCollectionOwner - ); - }); + assert_noop!( + XcNFT::collection_x_transfer( + RuntimeOrigin::signed(BOB), + 0, + Some(COLLECTION_ID), + 2000.into(), + None + ), + Error::::NotCollectionOwner + ); + }); } #[test] fn try_voting_on_non_existing_proposal() { - - new_test_ext().execute_with(|| { - System::set_block_number(1); - - assert_noop!( - XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 0, crate::Vote::Aye), - Error::::ProposalDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + + assert_noop!( + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 0, crate::Vote::Aye), + Error::::ProposalDoesNotExist + ); + }); } #[test] fn try_voting_on_proposal_when_no_owner() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: BoundedVec::new(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: BoundedVec::new() }, + end_time: 20u64.into(), + }; - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: BoundedVec::new(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: BoundedVec::new(), - }, - end_time: 20u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - assert_noop!( - XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(BOB), 1, crate::Vote::Aye), - Error::::NotNFTOwner - ); - }); - -} - -#[test] -fn try_voting_on_proposal_expired(){ - - new_test_ext().execute_with(|| { - System::set_block_number(3); - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: owners.clone(), - nay: BoundedVec::new(), - }, - end_time: 1u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - let _ = XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); - - System::assert_last_event(RuntimeEvent::XcNFT(Event::ProposalExpired { - proposal_id: 1, - })); - }); + let _ = crate::CrossChainProposals::insert(1, proposal); + + assert_noop!( + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(BOB), 1, crate::Vote::Aye), + Error::::NotNFTOwner + ); + }); +} + +#[test] +fn try_voting_on_proposal_expired() { + new_test_ext().execute_with(|| { + System::set_block_number(3); + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: owners.clone(), nay: BoundedVec::new() }, + end_time: 1u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + let _ = + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + + System::assert_last_event(RuntimeEvent::XcNFT(Event::ProposalExpired { proposal_id: 1 })); + }); } #[test] fn try_voting_on_proposal_did_not_pass() { - new_test_ext().execute_with(|| { - System::set_block_number(3); - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 1u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - let _ = XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); - - System::assert_last_event(RuntimeEvent::XcNFT(Event::ProposalDidNotPass { - proposal_id: 1, - })); - }); + new_test_ext().execute_with(|| { + System::set_block_number(3); + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 1u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + let _ = + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + + System::assert_last_event(RuntimeEvent::XcNFT(Event::ProposalDidNotPass { + proposal_id: 1, + })); + }); } #[test] fn try_voting_on_proposal_again_same_vote() { - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 3u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - let _ = XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); - - assert_noop!( - XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye), - Error::::AlreadyVotedThis - ); - - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 3u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + let _ = + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + + assert_noop!( + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye), + Error::::AlreadyVotedThis + ); + }); } #[test] fn vote_on_proposal_successfuly() { - new_test_ext().execute_with(|| { - System::set_block_number(1); - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 2u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - let _ = XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); - - System::assert_last_event(RuntimeEvent::XcNFT(Event::CrossChainPropoposalVoteRegistered { proposal_id: 1, voter: ALICE, vote: crate::Vote::Aye })); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 2u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + let _ = + XcNFT::collection_x_transfer_vote(RuntimeOrigin::signed(ALICE), 1, crate::Vote::Aye); + + System::assert_last_event(RuntimeEvent::XcNFT(Event::CrossChainPropoposalVoteRegistered { + proposal_id: 1, + voter: ALICE, + vote: crate::Vote::Aye, + })); + }); } #[test] fn try_initiating_proposal_doesnt_exist() { - new_test_ext().execute_with(|| { - System::set_block_number(1); + new_test_ext().execute_with(|| { + System::set_block_number(1); - assert_noop!( - XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), - Error::::ProposalDoesNotExist - ); - }); + assert_noop!( + XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), + Error::::ProposalDoesNotExist + ); + }); } #[test] fn try_initiating_proposal_collection_doesnt_exist() { - new_test_ext().execute_with(|| { - System::set_block_number(1); - - const COLLECTION_ID: u32 = 1; - - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); - - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: COLLECTION_ID, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 2u64.into(), - }; - - let _ = crate::CrossChainProposals::insert(1, proposal); - - assert_noop!( - XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), - Error::::CollectionDoesNotExist - ); - }); + new_test_ext().execute_with(|| { + System::set_block_number(1); + + const COLLECTION_ID: u32 = 1; + + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); + + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: COLLECTION_ID, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 2u64.into(), + }; + + let _ = crate::CrossChainProposals::insert(1, proposal); + + assert_noop!( + XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_initiating_proposal_no_collection_owner() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(BOB), 0, ALICE); + new_test_ext().execute_with(|| { + System::set_block_number(2); + let _ = Uniques::create(RuntimeOrigin::signed(BOB), 0, ALICE); - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(BOB).expect("Failed to push owner"); + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(BOB).expect("Failed to push owner"); - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: 0, - proposed_collection_owner: BOB, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 1u64.into(), - }; + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: 0, + proposed_collection_owner: BOB, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 1u64.into(), + }; - let _ = crate::CrossChainProposals::insert(1, proposal); + let _ = crate::CrossChainProposals::insert(1, proposal); - assert_noop!( - XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), - Error::::NotCollectionOwner - ); - }); + assert_noop!( + XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1), + Error::::NotCollectionOwner + ); + }); } - #[test] fn try_initiating_proposal_that_did_not_pass() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - //Create owners vector - let mut owners = BoundedVec::new(); - owners.try_push(ALICE).expect("Failed to push owner"); + //Create owners vector + let mut owners = BoundedVec::new(); + owners.try_push(ALICE).expect("Failed to push owner"); - //Create proposal - let proposal = Proposal:: { - proposal_id: 1, - collection_id: 0, - proposed_collection_owner: ALICE, - proposed_destination_para: 2000.into(), - proposed_dest_collection_id: None, - proposed_destination_config: None, - owners: owners.clone(), - number_of_votes: crate::Votes { - aye: BoundedVec::new(), - nay: owners.clone(), - }, - end_time: 1u64.into(), - }; + //Create proposal + let proposal = Proposal:: { + proposal_id: 1, + collection_id: 0, + proposed_collection_owner: ALICE, + proposed_destination_para: 2000.into(), + proposed_dest_collection_id: None, + proposed_destination_config: None, + owners: owners.clone(), + number_of_votes: crate::Votes { aye: BoundedVec::new(), nay: owners.clone() }, + end_time: 1u64.into(), + }; - let _ = crate::CrossChainProposals::insert(1, proposal); - let _ = XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1); + let _ = crate::CrossChainProposals::insert(1, proposal); + let _ = XcNFT::collection_x_transfer_initiate(RuntimeOrigin::signed(ALICE), 1); - System::assert_has_event(RuntimeEvent::XcNFT(Event::ProposalDidNotPass { proposal_id: 1, })); - }); + System::assert_has_event(RuntimeEvent::XcNFT(Event::ProposalDidNotPass { proposal_id: 1 })); + }); } #[test] fn try_sending_nft_no_collection() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - assert_noop!( - XcNFT::nft_x_transfer(RuntimeOrigin::signed(ALICE), 1, 0, 1000.into(), 1, 1), - Error::::CollectionDoesNotExist - ); - }); + assert_noop!( + XcNFT::nft_x_transfer(RuntimeOrigin::signed(ALICE), 1, 0, 1000.into(), 1, 1), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_sending_nft_no_nft() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - assert_noop!( - XcNFT::nft_x_transfer(RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), 1, 1), - Error::::NFTDoesNotExist - ); - }); + assert_noop!( + XcNFT::nft_x_transfer(RuntimeOrigin::signed(ALICE), 0, 0, 1000.into(), 1, 1), + Error::::NFTDoesNotExist + ); + }); } #[test] fn try_sending_nft_not_nft_owner() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - assert_noop!( - XcNFT::nft_x_transfer(RuntimeOrigin::signed(BOB), 0, 0, 1000.into(), 1, 1), - Error::::NotNFTOwner - ); - }); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); + + assert_noop!( + XcNFT::nft_x_transfer(RuntimeOrigin::signed(BOB), 0, 0, 1000.into(), 1, 1), + Error::::NotNFTOwner + ); + }); } #[test] fn try_claiming_nft_no_collection() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), - Error::::CollectionDoesNotExist - ); - }); + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_claiming_nft_no_collection_origin() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), - Error::::CollectionDoesNotExist - ); - }); + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 1u32, 0u32, 100u32.into(), 1u32, 1u32), + Error::::CollectionDoesNotExist + ); + }); } #[test] fn try_claiming_nft_wrong_origin_collection() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let collections: ReceivedCols:: = ReceivedCols:: { - origin_para_id: 1000.into(), - origin_collection_id: 10, - received_collection_id: 20, - }; + let collections: ReceivedCols = ReceivedCols:: { + origin_para_id: 1000.into(), + origin_collection_id: 10, + received_collection_id: 20, + }; - let _ = ReceivedCollections::::insert(0, collections); + let _ = ReceivedCollections::::insert(0, collections); - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 1u32), - Error::::WrongOriginCollectionAtOrigin - ); - }); + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 1u32), + Error::::WrongOriginCollectionAtOrigin + ); + }); } #[test] fn try_claiming_nft_wrong_nft() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let collections: ReceivedCols:: = ReceivedCols:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - received_collection_id: 0, - }; + let collections: ReceivedCols = ReceivedCols:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + received_collection_id: 0, + }; - let _ = ReceivedCollections::::insert(0, collections); + let _ = ReceivedCollections::::insert(0, collections); - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 0u32), - Error::::NFTNotReceived - ); - }); + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 100u32.into(), 0u32, 0u32), + Error::::NFTNotReceived + ); + }); } #[test] fn try_claiming_nft_not_owner() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE); + System::set_block_number(3); - System::set_block_number(3); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 1, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 1, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE); + let collections: ReceivedCols = ReceivedCols:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + received_collection_id: 0, + }; - let collections: ReceivedCols:: = ReceivedCols:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - received_collection_id: 0, - }; + let _ = ReceivedCollections::::insert(0, collections); - let _ = ReceivedCollections::::insert(0, collections); + let nfts: ReceivedStruct = ReceivedStruct:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + origin_asset_id: 0, + received_collection_id: 1, + received_asset_id: 0, + }; - let nfts: ReceivedStruct:: = ReceivedStruct:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - origin_asset_id: 0, - received_collection_id: 1, - received_asset_id: 0, - }; + let _ = ReceivedAssets::::insert((1, 0), nfts); - let _ = ReceivedAssets::::insert((1, 0), nfts); - - assert_noop!( - XcNFT::nft_x_claim(RuntimeOrigin::signed(BOB), 0u32, 0u32, 0u32, 1u32, 0u32), - Error::::NotNFTOwner - ); - }); + assert_noop!( + XcNFT::nft_x_claim(RuntimeOrigin::signed(BOB), 0u32, 0u32, 0u32, 1u32, 0u32), + Error::::NotNFTOwner + ); + }); } #[test] fn try_claiming_nft_success() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0u32, 0u32, ALICE); + System::set_block_number(3); - System::set_block_number(3); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 1, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 1, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 1u32, 0u32, ALICE); + let collections: ReceivedCols = ReceivedCols:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + received_collection_id: 0, + }; - let collections: ReceivedCols:: = ReceivedCols:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - received_collection_id: 0, - }; + let _ = ReceivedCollections::::insert(0, collections); - let _ = ReceivedCollections::::insert(0, collections); + let nfts: ReceivedStruct = ReceivedStruct:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + origin_asset_id: 0, + received_collection_id: 1, + received_asset_id: 0, + }; - let nfts: ReceivedStruct:: = ReceivedStruct:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - origin_asset_id: 0, - received_collection_id: 1, - received_asset_id: 0, - }; + let _ = ReceivedAssets::::insert((1, 0), nfts); + System::set_block_number(3); - let _ = ReceivedAssets::::insert((1, 0), nfts); - System::set_block_number(3); + let _ = XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 0u32, 1u32, 0u32); - let _ = XcNFT::nft_x_claim(RuntimeOrigin::signed(ALICE), 0u32, 0u32, 0u32, 1u32, 0u32); - - System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTClaimed { collection_claimed_from: 1, asset_removed: 0, collection_claimed_to: 0, asset_claimed: 0 })); - - }); + System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTClaimed { + collection_claimed_from: 1, + asset_removed: 0, + collection_claimed_to: 0, + asset_claimed: 0, + })); + }); } #[test] fn try_collection_parse_empty_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = XcNFT::parse_collection_empty(RuntimeOrigin::signed(ALICE), 1, None, BoundedVec::new(), None); + let _ = XcNFT::parse_collection_empty( + RuntimeOrigin::signed(ALICE), + 1, + None, + BoundedVec::new(), + None, + ); - System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionReceived { origin_collection_id: 1, received_collection_id: 1, to_address: ALICE })); - }); + System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionReceived { + origin_collection_id: 1, + received_collection_id: 1, + to_address: ALICE, + })); + }); } #[test] -fn try_parse_collection_burn_successful(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); +fn try_parse_collection_burn_successful() { + new_test_ext().execute_with(|| { + System::set_block_number(2); - let destroy_witness = GeneralizedDestroyWitness { - item_meta: 0, - item_configs: 0, - attributes: 0, - }; + let destroy_witness = + GeneralizedDestroyWitness { item_meta: 0, item_configs: 0, attributes: 0 }; - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = XcNFT::parse_collection_burn(RuntimeOrigin::signed(ALICE), 0, destroy_witness); + let _ = XcNFT::parse_collection_burn(RuntimeOrigin::signed(ALICE), 0, destroy_witness); - System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::Destroyed { collection: 0 })); - }); + System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::Destroyed { + collection: 0, + })); + }); } #[test] fn try_parse_collection_metadata_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = XcNFT::parse_collection_metadata(RuntimeOrigin::signed(ALICE), 0, BoundedVec::new()); + let _ = + XcNFT::parse_collection_metadata(RuntimeOrigin::signed(ALICE), 0, BoundedVec::new()); - System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::CollectionMetadataSet { collection: 0, data: BoundedVec::new(), is_frozen: false })); - }); + System::assert_has_event(RuntimeEvent::Uniques( + pallet_uniques::Event::CollectionMetadataSet { + collection: 0, + data: BoundedVec::new(), + is_frozen: false, + }, + )); + }); } #[test] fn try_parse_collection_owner_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - pallet_uniques::OwnershipAcceptance::::insert(BOB, 0); - - let _ = XcNFT::parse_collection_owner(RuntimeOrigin::signed(ALICE), BOB, 0); + pallet_uniques::OwnershipAcceptance::::insert(BOB, 0); - System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::OwnerChanged { collection: 0, new_owner: BOB })); - }); + let _ = XcNFT::parse_collection_owner(RuntimeOrigin::signed(ALICE), BOB, 0); + + System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::OwnerChanged { + collection: 0, + new_owner: BOB, + })); + }); } #[test] fn try_parse_nft_burn_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - let _ = XcNFT::parse_nft_burn(RuntimeOrigin::signed(ALICE), 0, 0); + let _ = XcNFT::parse_nft_burn(RuntimeOrigin::signed(ALICE), 0, 0); - System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::Burned { collection: 0, item: 0, owner: ALICE })); - }); + System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::Burned { + collection: 0, + item: 0, + owner: ALICE, + })); + }); } #[test] fn try_parse_nft_metadata_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - let _ = XcNFT::parse_nft_metadata(RuntimeOrigin::signed(ALICE), 0, 0, BoundedVec::new()); + let _ = XcNFT::parse_nft_metadata(RuntimeOrigin::signed(ALICE), 0, 0, BoundedVec::new()); - System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::MetadataSet { collection: 0, item: 0, data: BoundedVec::new(), is_frozen: false })); - }); + System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::MetadataSet { + collection: 0, + item: 0, + data: BoundedVec::new(), + is_frozen: false, + })); + }); } #[test] fn try_parse_nft_owner_successful() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - let _ = XcNFT::parse_nft_owner(RuntimeOrigin::signed(ALICE), BOB ,0, 0); + let _ = XcNFT::parse_nft_owner(RuntimeOrigin::signed(ALICE), BOB, 0, 0); - System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::Transferred { collection: 0, item: 0, from: ALICE, to: BOB })); - }); + System::assert_has_event(RuntimeEvent::Uniques(pallet_uniques::Event::Transferred { + collection: 0, + item: 0, + from: ALICE, + to: BOB, + })); + }); } #[test] fn try_parse_nft_transfer_no_collection() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - assert_noop!(XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,1000.into()), Error::::CollectionDoesNotExist); - }); + assert_noop!( + XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into() + ), + Error::::CollectionDoesNotExist + ); + }); } - #[test] fn try_parse_nft_transfer_already_received() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - let nfts: ReceivedStruct:: = ReceivedStruct:: { - origin_para_id: 1000.into(), - origin_collection_id: 0, - origin_asset_id: 0, - received_collection_id: 0, - received_asset_id: 0, - }; + let nfts: ReceivedStruct = ReceivedStruct:: { + origin_para_id: 1000.into(), + origin_collection_id: 0, + origin_asset_id: 0, + received_collection_id: 0, + received_asset_id: 0, + }; - let _ = ReceivedAssets::::insert((0, 0), nfts); - + let _ = ReceivedAssets::::insert((0, 0), nfts); - assert_noop!(XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,1000.into()), Error::::NFTAlreadyReceived); - }); + assert_noop!( + XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into() + ), + Error::::NFTAlreadyReceived + ); + }); } #[test] fn try_parse_nft_transfer_not_collection_owner() { - new_test_ext().execute_with(|| { - System::set_block_number(2); + new_test_ext().execute_with(|| { + System::set_block_number(2); - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - assert_noop!(XcNFT::parse_nft_transfer(RuntimeOrigin::signed(BOB),0,0,BoundedVec::new(),0,0,1000.into()), Error::::NotCollectionOwner); - }); + assert_noop!( + XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(BOB), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into() + ), + Error::::NotCollectionOwner + ); + }); } #[test] fn try_parse_nft_transfer_not_existing_nft() { - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); - - - assert_noop!(XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,1000.into()), Error::::NFTExists); - }); -} - -#[test] -fn try_parse_nft_transfer_successful(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - let _ = XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,1000.into()); - System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTReceived { origin_collection_id: 0, origin_asset_id: 0, received_collection_id: 0, received_asset_id: 0, to_address: ALICE})); -}); -} - -#[test] -fn try_parse_nft_transfer_return_to_origin(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); - - let sent = SentStruct:: { - - origin_para_id: ParachainInfo::parachain_id(), - origin_collection_id: 0, - origin_asset_id: 0, - destination_collection_id: 0, - destination_asset_id: 0, - }; - - let _ = SentAssets::::insert((0, 0), sent); - - //Set parachain id to 1000 - ParachainInfo::parachain_id(); - - let _ = XcNFT::parse_nft_transfer(RuntimeOrigin::signed(ALICE),0,0,BoundedVec::new(),0,0,ParachainInfo::parachain_id()); - System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTReturnedToOrigin { returned_from_collection_id: 0, returned_from_asset_id: 0, to_address: ALICE })); - - }); + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = Uniques::mint(RuntimeOrigin::signed(ALICE), 0, 0, ALICE); + + assert_noop!( + XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into() + ), + Error::::NFTExists + ); + }); +} + +#[test] +fn try_parse_nft_transfer_successful() { + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + let _ = XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + 1000.into(), + ); + System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTReceived { + origin_collection_id: 0, + origin_asset_id: 0, + received_collection_id: 0, + received_asset_id: 0, + to_address: ALICE, + })); + }); +} + +#[test] +fn try_parse_nft_transfer_return_to_origin() { + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let _ = Uniques::create(RuntimeOrigin::signed(ALICE), 0, ALICE); + + let sent = SentStruct:: { + origin_para_id: ParachainInfo::parachain_id(), + origin_collection_id: 0, + origin_asset_id: 0, + destination_collection_id: 0, + destination_asset_id: 0, + }; + + let _ = SentAssets::::insert((0, 0), sent); + + //Set parachain id to 1000 + ParachainInfo::parachain_id(); + + let _ = XcNFT::parse_nft_transfer( + RuntimeOrigin::signed(ALICE), + 0, + 0, + BoundedVec::new(), + 0, + 0, + ParachainInfo::parachain_id(), + ); + System::assert_has_event(RuntimeEvent::XcNFT(Event::NFTReturnedToOrigin { + returned_from_collection_id: 0, + returned_from_asset_id: 0, + to_address: ALICE, + })); + }); +} + +#[test] +fn parse_collection_same_owner_successful() { + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let mut nfts: Vec<(u32, BoundedVec)> = Vec::new(); + nfts.push((1, BoundedVec::new())); + + let _ = XcNFT::parse_collection_same_owner( + RuntimeOrigin::signed(ALICE), + None, + BoundedVec::new(), + nfts.clone(), + 1000.into(), + 0, + None, + ); + System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionWithNftsReceived { + collection_id: 0, + items: nfts.clone(), + })); + }); +} + +#[test] +fn parse_collection_diff_nft_owners_successful() { + new_test_ext().execute_with(|| { + System::set_block_number(2); + + let mut nfts: Vec<(u32, AccountId32, BoundedVec)> = Vec::new(); + nfts.push((1, BOB, BoundedVec::new())); + + let _ = XcNFT::parse_collection_diff_owners( + RuntimeOrigin::signed(ALICE), + None, + BoundedVec::new(), + nfts.clone(), + 1000.into(), + 0, + None, + ); + System::assert_has_event(RuntimeEvent::XcNFT( + Event::CollectionWithNftsDiffOwnersReceived { collection_id: 0, items: nfts.clone() }, + )); + }); } - -#[test] -fn parse_collection_same_owner_successful(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); - - - let mut nfts: Vec<(u32, BoundedVec)> = Vec::new(); - nfts.push((1, BoundedVec::new())); - - let _ = XcNFT::parse_collection_same_owner(RuntimeOrigin::signed(ALICE), None, BoundedVec::new(), nfts.clone(), 1000.into(), 0, None); - System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionWithNftsReceived { collection_id: 0, items: nfts.clone() })); - }); -} - -#[test] -fn parse_collection_diff_nft_owners_successful(){ - new_test_ext().execute_with(|| { - System::set_block_number(2); - - let mut nfts: Vec<(u32, AccountId32, BoundedVec)> = Vec::new(); - nfts.push((1, BOB, BoundedVec::new())); - - let _ = XcNFT::parse_collection_diff_owners(RuntimeOrigin::signed(ALICE), None, BoundedVec::new(), nfts.clone(), 1000.into(), 0, None); - System::assert_has_event(RuntimeEvent::XcNFT(Event::CollectionWithNftsDiffOwnersReceived { collection_id: 0, items: nfts.clone() })); - }); -} \ No newline at end of file diff --git a/templates/parachain_two/pallets/xcnft/src/xmacros.rs b/templates/parachain_two/pallets/xcnft/src/xmacros.rs index 2333646a5d13..08defb3d1e21 100644 --- a/templates/parachain_two/pallets/xcnft/src/xmacros.rs +++ b/templates/parachain_two/pallets/xcnft/src/xmacros.rs @@ -1,8 +1,7 @@ /// 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 { @@ -40,4 +39,4 @@ macro_rules! impl_codec_bitflags { } }; } -pub(crate) use impl_codec_bitflags; \ No newline at end of file +pub(crate) use impl_codec_bitflags;