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

difftreelog

source

pallets/unique/src/tests.rs69.7 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Tests to be written here18use super::*;19use crate::mock::*;20use crate::{AccessMode, CollectionMode};21use sp_runtime::AccountId32;22use up_data_structs::{23	COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,24	CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,25	TokenId, MAX_TOKEN_OWNERSHIP,26};27use frame_support::{assert_noop, assert_ok, assert_err};28use sp_std::convert::TryInto;29use pallet_balances;3031fn add_balance(user: u64, value: u64) {32	const DONOR_USER: u64 = 999;33	assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(34		Origin::root(),35		DONOR_USER,36		value,37		038	));39	assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(40		Origin::root(),41		DONOR_USER,42		user,43		value44	));45}4647fn default_nft_data() -> CreateNftData {48	CreateNftData {49		const_data: vec![1, 2, 3].try_into().unwrap(),50		variable_data: vec![3, 2, 1].try_into().unwrap(),51	}52}5354fn default_fungible_data() -> CreateFungibleData {55	CreateFungibleData { value: 5 }56}5758fn default_re_fungible_data() -> CreateReFungibleData {59	CreateReFungibleData {60		const_data: vec![1, 2, 3].try_into().unwrap(),61		variable_data: vec![3, 2, 1].try_into().unwrap(),62		pieces: 1023,63	}64}6566fn create_test_collection_for_owner(67	mode: &CollectionMode,68	owner: u64,69	id: CollectionId,70) -> CollectionId {71	add_balance(owner, CollectionCreationPrice::get() as u64 + 1);7273	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();74	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();75	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();7677	let data: CreateCollectionData<u64> = CreateCollectionData {78		name: col_name1.try_into().unwrap(),79		description: col_desc1.try_into().unwrap(),80		token_prefix: token_prefix1.try_into().unwrap(),81		mode: mode.clone(),82		..Default::default()83	};8485	let origin1 = Origin::signed(owner);86	assert_ok!(TemplateModule::create_collection_ex(origin1, data));8788	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();89	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();90	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();91	assert_eq!(92		<pallet_common::CollectionById<Test>>::get(id)93			.unwrap()94			.owner,95		owner96	);97	assert_eq!(98		<pallet_common::CollectionById<Test>>::get(id).unwrap().name,99		saved_col_name100	);101	assert_eq!(102		<pallet_common::CollectionById<Test>>::get(id).unwrap().mode,103		*mode104	);105	assert_eq!(106		<pallet_common::CollectionById<Test>>::get(id)107			.unwrap()108			.description,109		saved_description110	);111	assert_eq!(112		<pallet_common::CollectionById<Test>>::get(id)113			.unwrap()114			.token_prefix,115		saved_prefix116	);117	id118}119120fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {121	create_test_collection_for_owner(&mode, 1, id)122}123124fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {125	let origin1 = Origin::signed(1);126	assert_ok!(TemplateModule::create_item(127		origin1,128		collection_id,129		account(1),130		data.clone()131	));132}133134fn account(sub: u64) -> TestCrossAccountId {135	TestCrossAccountId::from_sub(sub)136}137138// Use cases tests region139// #region140141#[test]142fn set_version_schema() {143	new_test_ext().execute_with(|| {144		let origin1 = Origin::signed(1);145		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));146147		assert_ok!(TemplateModule::set_schema_version(148			origin1,149			collection_id,150			SchemaVersion::Unique151		));152		assert_eq!(153			<pallet_common::CollectionById<Test>>::get(collection_id)154				.unwrap()155				.schema_version,156			SchemaVersion::Unique157		);158	});159}160161#[test]162fn check_not_sufficient_founds() {163	new_test_ext().execute_with(|| {164		let acc: u64 = 1;165		<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();166167		let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();168		let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();169		let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();170171		let data: CreateCollectionData<<Test as system::Config>::AccountId> =172			CreateCollectionData {173				name: name.try_into().unwrap(),174				description: description.try_into().unwrap(),175				token_prefix: token_prefix.try_into().unwrap(),176				mode: CollectionMode::NFT,177				..Default::default()178			};179180		let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);181		assert_err!(result, <CommonError<Test>>::NotSufficientFounds);182	});183}184185#[test]186fn create_fungible_collection_fails_with_large_decimal_numbers() {187	new_test_ext().execute_with(|| {188		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();189		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();190		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();191192		let data: CreateCollectionData<u64> = CreateCollectionData {193			name: col_name1.try_into().unwrap(),194			description: col_desc1.try_into().unwrap(),195			token_prefix: token_prefix1.try_into().unwrap(),196			mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),197			..Default::default()198		};199200		let origin1 = Origin::signed(1);201		assert_noop!(202			TemplateModule::create_collection_ex(origin1, data),203			Error::<Test>::CollectionDecimalPointLimitExceeded204		);205	});206}207208#[test]209fn create_nft_item() {210	new_test_ext().execute_with(|| {211		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));212213		let data = default_nft_data();214		create_test_item(collection_id, &data.clone().into());215216		let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();217		assert_eq!(item.const_data, data.const_data.into_inner());218		assert_eq!(item.variable_data, data.variable_data.into_inner());219	});220}221222// Use cases tests region223// #region224#[test]225fn create_nft_multiple_items() {226	new_test_ext().execute_with(|| {227		create_test_collection(&CollectionMode::NFT, CollectionId(1));228229		let origin1 = Origin::signed(1);230231		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];232233		assert_ok!(TemplateModule::create_multiple_items(234			origin1,235			CollectionId(1),236			account(1),237			items_data238				.clone()239				.into_iter()240				.map(|d| { d.into() })241				.collect()242		));243		for (index, data) in items_data.into_iter().enumerate() {244			let item = <pallet_nonfungible::TokenData<Test>>::get((245				CollectionId(1),246				TokenId((index + 1) as u32),247			))248			.unwrap();249			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());250			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());251		}252	});253}254255#[test]256fn create_refungible_item() {257	new_test_ext().execute_with(|| {258		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));259260		let data = default_re_fungible_data();261		create_test_item(collection_id, &data.clone().into());262		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));263		let balance =264			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));265		assert_eq!(item.const_data, data.const_data.into_inner());266		assert_eq!(item.variable_data, data.variable_data.into_inner());267		assert_eq!(balance, 1023);268	});269}270271#[test]272fn create_multiple_refungible_items() {273	new_test_ext().execute_with(|| {274		create_test_collection(&CollectionMode::ReFungible, CollectionId(1));275276		let origin1 = Origin::signed(1);277278		let items_data = vec![279			default_re_fungible_data(),280			default_re_fungible_data(),281			default_re_fungible_data(),282		];283284		assert_ok!(TemplateModule::create_multiple_items(285			origin1,286			CollectionId(1),287			account(1),288			items_data289				.clone()290				.into_iter()291				.map(|d| { d.into() })292				.collect()293		));294		for (index, data) in items_data.into_iter().enumerate() {295			let item = <pallet_refungible::TokenData<Test>>::get((296				CollectionId(1),297				TokenId((index + 1) as u32),298			));299			let balance =300				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));301			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());302			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());303			assert_eq!(balance, 1023);304		}305	});306}307308#[test]309fn create_fungible_item() {310	new_test_ext().execute_with(|| {311		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));312313		let data = default_fungible_data();314		create_test_item(collection_id, &data.into());315316		assert_eq!(317			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),318			5319		);320	});321}322323//#[test]324// fn create_multiple_fungible_items() {325//     new_test_ext().execute_with(|| {326//         default_limits();327328//         create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));329330//         let origin1 = Origin::signed(1);331332//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];333334//         assert_ok!(TemplateModule::create_multiple_items(335//             origin1.clone(),336//             1,337//             1,338//             items_data.clone().into_iter().map(|d| { d.into() }).collect()339//         ));340341//         for (index, _) in items_data.iter().enumerate() {342//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);343//         }344//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);345//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);346//     });347// }348349#[test]350fn transfer_fungible_item() {351	new_test_ext().execute_with(|| {352		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));353354		let origin1 = Origin::signed(1);355		let origin2 = Origin::signed(2);356357		let data = default_fungible_data();358		create_test_item(collection_id, &data.into());359360		assert_eq!(361			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),362			5363		);364365		// change owner scenario366		assert_ok!(TemplateModule::transfer(367			origin1,368			account(2),369			CollectionId(1),370			TokenId(0),371			5372		));373		assert_eq!(374			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),375			0376		);377378		// split item scenario379		assert_ok!(TemplateModule::transfer(380			origin2.clone(),381			account(3),382			CollectionId(1),383			TokenId(0),384			3385		));386387		// split item and new owner has account scenario388		assert_ok!(TemplateModule::transfer(389			origin2,390			account(3),391			CollectionId(1),392			TokenId(0),393			1394		));395		assert_eq!(396			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),397			1398		);399		assert_eq!(400			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),401			4402		);403	});404}405406#[test]407fn transfer_refungible_item() {408	new_test_ext().execute_with(|| {409		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));410411		// Create RFT 1 in 1023 pieces for account 1412		let data = default_re_fungible_data();413		create_test_item(collection_id, &data.clone().into());414		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));415		assert_eq!(item.const_data, data.const_data.into_inner());416		assert_eq!(item.variable_data, data.variable_data.into_inner());417		assert_eq!(418			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),419			1420		);421		assert_eq!(422			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),423			1023424		);425		assert_eq!(426			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),427			true428		);429430		// Account 1 transfers all 1023 pieces of RFT 1 to account 2431		let origin1 = Origin::signed(1);432		let origin2 = Origin::signed(2);433		assert_ok!(TemplateModule::transfer(434			origin1,435			account(2),436			CollectionId(1),437			TokenId(1),438			1023439		));440		assert_eq!(441			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),442			1023443		);444		assert_eq!(445			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),446			0447		);448		assert_eq!(449			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),450			1451		);452		assert_eq!(453			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),454			false455		);456		assert_eq!(457			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),458			true459		);460461		// Account 2 transfers 500 pieces of RFT 1 to account 3462		assert_ok!(TemplateModule::transfer(463			origin2.clone(),464			account(3),465			CollectionId(1),466			TokenId(1),467			500468		));469		assert_eq!(470			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),471			523472		);473		assert_eq!(474			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),475			500476		);477		assert_eq!(478			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),479			1480		);481		assert_eq!(482			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),483			1484		);485		assert_eq!(486			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),487			true488		);489		assert_eq!(490			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),491			true492		);493494		// Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance495		assert_ok!(TemplateModule::transfer(496			origin2,497			account(3),498			CollectionId(1),499			TokenId(1),500			200501		));502		assert_eq!(503			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),504			323505		);506		assert_eq!(507			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),508			700509		);510		assert_eq!(511			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),512			1513		);514		assert_eq!(515			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),516			1517		);518		assert_eq!(519			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),520			true521		);522		assert_eq!(523			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),524			true525		);526	});527}528529#[test]530fn transfer_nft_item() {531	new_test_ext().execute_with(|| {532		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));533534		let data = default_nft_data();535		create_test_item(collection_id, &data.into());536		assert_eq!(537			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),538			1539		);540		assert_eq!(541			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),542			true543		);544545		let origin1 = Origin::signed(1);546		// default scenario547		assert_ok!(TemplateModule::transfer(548			origin1,549			account(2),550			CollectionId(1),551			TokenId(1),552			1553		));554		assert_eq!(555			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),556			0557		);558		assert_eq!(559			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),560			1561		);562		assert_eq!(563			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),564			false565		);566		assert_eq!(567			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),568			true569		);570	});571}572573#[test]574fn transfer_nft_item_wrong_value() {575	new_test_ext().execute_with(|| {576		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));577578		let data = default_nft_data();579		create_test_item(collection_id, &data.into());580		assert_eq!(581			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),582			1583		);584		assert_eq!(585			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),586			true587		);588589		let origin1 = Origin::signed(1);590591		assert_noop!(592			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)593				.map_err(|e| e.error),594			<pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount595		);596	});597}598599#[test]600fn transfer_nft_item_zero_value() {601	new_test_ext().execute_with(|| {602		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));603604		let data = default_nft_data();605		create_test_item(collection_id, &data.into());606		assert_eq!(607			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),608			1609		);610		assert_eq!(611			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),612			true613		);614615		let origin1 = Origin::signed(1);616617		// Transferring 0 amount works on NFT...618		assert_ok!(TemplateModule::transfer(619			origin1,620			account(2),621			CollectionId(1),622			TokenId(1),623			0624		));625		// ... and results in no transfer626		assert_eq!(627			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),628			1629		);630		assert_eq!(631			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),632			true633		);634	});635}636637#[test]638fn nft_approve_and_transfer_from() {639	new_test_ext().execute_with(|| {640		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));641642		let data = default_nft_data();643		create_test_item(collection_id, &data.into());644645		let origin1 = Origin::signed(1);646		let origin2 = Origin::signed(2);647648		assert_eq!(649			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),650			1651		);652		assert_eq!(653			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),654			true655		);656657		// neg transfer_from658		assert_noop!(659			TemplateModule::transfer_from(660				origin2.clone(),661				account(1),662				account(2),663				CollectionId(1),664				TokenId(1),665				1666			)667			.map_err(|e| e.error),668			CommonError::<Test>::ApprovedValueTooLow669		);670671		// do approve672		assert_ok!(TemplateModule::approve(673			origin1,674			account(2),675			CollectionId(1),676			TokenId(1),677			1678		));679		assert_eq!(680			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),681			account(2)682		);683684		assert_ok!(TemplateModule::transfer_from(685			origin2,686			account(1),687			account(3),688			CollectionId(1),689			TokenId(1),690			1691		));692		assert!(693			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()694		);695	});696}697698#[test]699fn nft_approve_and_transfer_from_allow_list() {700	new_test_ext().execute_with(|| {701		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));702703		let origin1 = Origin::signed(1);704		let origin2 = Origin::signed(2);705706		// Create NFT 1 for account 1707		let data = default_nft_data();708		create_test_item(collection_id, &data.clone().into());709		assert_eq!(710			&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))711				.unwrap()712				.const_data,713			&data.const_data.into_inner()714		);715		assert_eq!(716			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),717			1718		);719		assert_eq!(720			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),721			true722		);723724		// Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list725		assert_ok!(TemplateModule::set_mint_permission(726			origin1.clone(),727			CollectionId(1),728			true729		));730		assert_ok!(TemplateModule::set_public_access_mode(731			origin1.clone(),732			CollectionId(1),733			AccessMode::AllowList734		));735		assert_ok!(TemplateModule::add_to_allow_list(736			origin1.clone(),737			CollectionId(1),738			account(1)739		));740		assert_ok!(TemplateModule::add_to_allow_list(741			origin1.clone(),742			CollectionId(1),743			account(2)744		));745		assert_ok!(TemplateModule::add_to_allow_list(746			origin1.clone(),747			CollectionId(1),748			account(3)749		));750751		// Account 1 approves account 2 for NFT 1752		assert_ok!(TemplateModule::approve(753			origin1.clone(),754			account(2),755			CollectionId(1),756			TokenId(1),757			1758		));759		assert_eq!(760			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),761			account(2)762		);763764		// Account 2 transfers NFT 1 from account 1 to account 3765		assert_ok!(TemplateModule::transfer_from(766			origin2,767			account(1),768			account(3),769			CollectionId(1),770			TokenId(1),771			1772		));773		assert!(774			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()775		);776	});777}778779#[test]780fn refungible_approve_and_transfer_from() {781	new_test_ext().execute_with(|| {782		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));783784		let origin1 = Origin::signed(1);785		let origin2 = Origin::signed(2);786787		// Create RFT 1 in 1023 pieces for account 1788		let data = default_re_fungible_data();789		create_test_item(collection_id, &data.into());790791		assert_eq!(792			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),793			1794		);795		assert_eq!(796			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),797			1023798		);799		assert_eq!(800			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),801			true802		);803804		// Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list805		assert_ok!(TemplateModule::set_mint_permission(806			origin1.clone(),807			CollectionId(1),808			true809		));810		assert_ok!(TemplateModule::set_public_access_mode(811			origin1.clone(),812			CollectionId(1),813			AccessMode::AllowList814		));815		assert_ok!(TemplateModule::add_to_allow_list(816			origin1.clone(),817			CollectionId(1),818			account(1)819		));820		assert_ok!(TemplateModule::add_to_allow_list(821			origin1.clone(),822			CollectionId(1),823			account(2)824		));825		assert_ok!(TemplateModule::add_to_allow_list(826			origin1.clone(),827			CollectionId(1),828			account(3)829		));830831		// Account 1 approves account 2 for 1023 pieces of RFT 1832		assert_ok!(TemplateModule::approve(833			origin1,834			account(2),835			CollectionId(1),836			TokenId(1),837			1023838		));839		assert_eq!(840			<pallet_refungible::Allowance<Test>>::get((841				CollectionId(1),842				TokenId(1),843				account(1),844				account(2)845			)),846			1023847		);848849		// Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3850		assert_ok!(TemplateModule::transfer_from(851			origin2,852			account(1),853			account(3),854			CollectionId(1),855			TokenId(1),856			100857		));858		assert_eq!(859			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),860			1861		);862		assert_eq!(863			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),864			1865		);866		assert_eq!(867			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),868			923869		);870		assert_eq!(871			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),872			100873		);874		assert_eq!(875			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),876			true877		);878		assert_eq!(879			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),880			true881		);882		assert_eq!(883			<pallet_refungible::Allowance<Test>>::get((884				CollectionId(1),885				TokenId(1),886				account(1),887				account(2)888			)),889			923890		);891	});892}893894#[test]895fn fungible_approve_and_transfer_from() {896	new_test_ext().execute_with(|| {897		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));898899		let data = default_fungible_data();900		create_test_item(collection_id, &data.into());901902		let origin1 = Origin::signed(1);903		let origin2 = Origin::signed(2);904905		assert_ok!(TemplateModule::set_mint_permission(906			origin1.clone(),907			CollectionId(1),908			true909		));910		assert_ok!(TemplateModule::set_public_access_mode(911			origin1.clone(),912			CollectionId(1),913			AccessMode::AllowList914		));915		assert_ok!(TemplateModule::add_to_allow_list(916			origin1.clone(),917			CollectionId(1),918			account(1)919		));920		assert_ok!(TemplateModule::add_to_allow_list(921			origin1.clone(),922			CollectionId(1),923			account(2)924		));925		assert_ok!(TemplateModule::add_to_allow_list(926			origin1.clone(),927			CollectionId(1),928			account(3)929		));930931		// do approve932		assert_ok!(TemplateModule::approve(933			origin1.clone(),934			account(2),935			CollectionId(1),936			TokenId(0),937			5938		));939		assert_eq!(940			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),941			5942		);943		assert_ok!(TemplateModule::approve(944			origin1,945			account(3),946			CollectionId(1),947			TokenId(0),948			5949		));950		assert_eq!(951			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),952			5953		);954		assert_eq!(955			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),956			5957		);958959		assert_ok!(TemplateModule::transfer_from(960			origin2.clone(),961			account(1),962			account(3),963			CollectionId(1),964			TokenId(0),965			4966		));967968		assert_eq!(969			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),970			1971		);972973		assert_noop!(974			TemplateModule::transfer_from(975				origin2,976				account(1),977				account(3),978				CollectionId(1),979				TokenId(0),980				4981			)982			.map_err(|e| e.error),983			CommonError::<Test>::ApprovedValueTooLow984		);985	});986}987988#[test]989fn change_collection_owner() {990	new_test_ext().execute_with(|| {991		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));992993		let origin1 = Origin::signed(1);994		assert_ok!(TemplateModule::change_collection_owner(995			origin1,996			collection_id,997			2998		));999		assert_eq!(1000			<pallet_common::CollectionById<Test>>::get(collection_id)1001				.unwrap()1002				.owner,1003			21004		);1005	});1006}10071008#[test]1009fn destroy_collection() {1010	new_test_ext().execute_with(|| {1011		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10121013		let origin1 = Origin::signed(1);1014		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1015	});1016}10171018#[test]1019fn burn_nft_item() {1020	new_test_ext().execute_with(|| {1021		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10221023		let origin1 = Origin::signed(1);10241025		let data = default_nft_data();1026		create_test_item(collection_id, &data.into());10271028		// check balance (collection with id = 1, user id = 1)1029		assert_eq!(1030			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1031			11032		);10331034		// burn item1035		assert_ok!(TemplateModule::burn_item(1036			origin1.clone(),1037			collection_id,1038			TokenId(1),1039			11040		));1041		assert_eq!(1042			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1043			01044		);1045	});1046}10471048#[test]1049fn burn_same_nft_item_twice() {1050	new_test_ext().execute_with(|| {1051		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10521053		let origin1 = Origin::signed(1);10541055		let data = default_nft_data();1056		create_test_item(collection_id, &data.into());10571058		// check balance (collection with id = 1, user id = 1)1059		assert_eq!(1060			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1061			11062		);10631064		// burn item1065		assert_ok!(TemplateModule::burn_item(1066			origin1.clone(),1067			collection_id,1068			TokenId(1),1069			11070		));10711072		// burn item again1073		assert_noop!(1074			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1075			CommonError::<Test>::TokenNotFound1076		);10771078		assert_eq!(1079			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1080			01081		);1082	});1083}10841085#[test]1086fn burn_fungible_item() {1087	new_test_ext().execute_with(|| {1088		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10891090		let origin1 = Origin::signed(1);1091		assert_ok!(TemplateModule::add_collection_admin(1092			origin1.clone(),1093			collection_id,1094			account(2)1095		));10961097		let data = default_fungible_data();1098		create_test_item(collection_id, &data.into());10991100		// check balance (collection with id = 1, user id = 1)1101		assert_eq!(1102			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1103			51104		);11051106		// burn item1107		assert_ok!(TemplateModule::burn_item(1108			origin1.clone(),1109			CollectionId(1),1110			TokenId(0),1111			51112		));1113		assert_noop!(1114			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1115			CommonError::<Test>::TokenValueTooLow1116		);11171118		assert_eq!(1119			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1120			01121		);1122	});1123}11241125#[test]1126fn burn_fungible_item_with_token_id() {1127	new_test_ext().execute_with(|| {1128		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11291130		let origin1 = Origin::signed(1);1131		assert_ok!(TemplateModule::add_collection_admin(1132			origin1.clone(),1133			collection_id,1134			account(2)1135		));11361137		let data = default_fungible_data();1138		create_test_item(collection_id, &data.into());11391140		// check balance (collection with id = 1, user id = 1)1141		assert_eq!(1142			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1143			51144		);11451146		// Try to burn item using Token ID1147		assert_noop!(1148			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1149			<pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1150		);1151	});1152}1153#[test]1154fn burn_refungible_item() {1155	new_test_ext().execute_with(|| {1156		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1157		let origin1 = Origin::signed(1);11581159		assert_ok!(TemplateModule::set_mint_permission(1160			origin1.clone(),1161			collection_id,1162			true1163		));1164		assert_ok!(TemplateModule::set_public_access_mode(1165			origin1.clone(),1166			collection_id,1167			AccessMode::AllowList1168		));1169		assert_ok!(TemplateModule::add_to_allow_list(1170			origin1.clone(),1171			collection_id,1172			account(1)1173		));11741175		assert_ok!(TemplateModule::add_collection_admin(1176			origin1.clone(),1177			collection_id,1178			account(2)1179		));11801181		let data = default_re_fungible_data();1182		create_test_item(collection_id, &data.into());11831184		// check balance (collection with id = 1, user id = 2)1185		assert_eq!(1186			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1187			11188		);1189		assert_eq!(1190			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1191			10231192		);11931194		// burn item1195		assert_ok!(TemplateModule::burn_item(1196			origin1.clone(),1197			collection_id,1198			TokenId(1),1199			10231200		));1201		assert_noop!(1202			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1203				.map_err(|e| e.error),1204			CommonError::<Test>::TokenValueTooLow1205		);12061207		assert_eq!(1208			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1209			01210		);1211	});1212}12131214#[test]1215fn add_collection_admin() {1216	new_test_ext().execute_with(|| {1217		let collection1_id =1218			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1219		let origin1 = Origin::signed(1);12201221		// Add collection admins1222		assert_ok!(TemplateModule::add_collection_admin(1223			origin1.clone(),1224			collection1_id,1225			account(2)1226		));1227		assert_ok!(TemplateModule::add_collection_admin(1228			origin1,1229			collection1_id,1230			account(3)1231		));12321233		// Owner is not an admin by default1234		assert_eq!(1235			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1236			false1237		);1238		assert!(<pallet_common::IsAdmin<Test>>::get((1239			CollectionId(1),1240			account(2)1241		)));1242		assert!(<pallet_common::IsAdmin<Test>>::get((1243			CollectionId(1),1244			account(3)1245		)));1246	});1247}12481249#[test]1250fn remove_collection_admin() {1251	new_test_ext().execute_with(|| {1252		let collection1_id =1253			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1254		let origin1 = Origin::signed(1);1255		let origin2 = Origin::signed(2);12561257		// Add collection admins 2 and 31258		assert_ok!(TemplateModule::add_collection_admin(1259			origin1.clone(),1260			collection1_id,1261			account(2)1262		));1263		assert_ok!(TemplateModule::add_collection_admin(1264			origin1,1265			collection1_id,1266			account(3)1267		));12681269		assert!(<pallet_common::IsAdmin<Test>>::get((1270			CollectionId(1),1271			account(2)1272		)));1273		assert!(<pallet_common::IsAdmin<Test>>::get((1274			CollectionId(1),1275			account(3)1276		)));12771278		// remove admin 31279		assert_ok!(TemplateModule::remove_collection_admin(1280			origin2,1281			CollectionId(1),1282			account(3)1283		));12841285		// 2 is still admin, 3 is not an admin anymore1286		assert!(<pallet_common::IsAdmin<Test>>::get((1287			CollectionId(1),1288			account(2)1289		)));1290		assert_eq!(1291			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1292			false1293		);1294	});1295}12961297#[test]1298fn balance_of() {1299	new_test_ext().execute_with(|| {1300		let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1301		let fungible_collection_id =1302			create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1303		let re_fungible_collection_id =1304			create_test_collection(&CollectionMode::ReFungible, CollectionId(3));13051306		// check balance before1307		assert_eq!(1308			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1309			01310		);1311		assert_eq!(1312			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1313			01314		);1315		assert_eq!(1316			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1317			01318		);13191320		let nft_data = default_nft_data();1321		create_test_item(nft_collection_id, &nft_data.into());13221323		let fungible_data = default_fungible_data();1324		create_test_item(fungible_collection_id, &fungible_data.into());13251326		let re_fungible_data = default_re_fungible_data();1327		create_test_item(re_fungible_collection_id, &re_fungible_data.into());13281329		// check balance (collection with id = 1, user id = 1)1330		assert_eq!(1331			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1332			11333		);1334		assert_eq!(1335			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1336			51337		);1338		assert_eq!(1339			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1340			11341		);13421343		assert_eq!(1344			<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1345			true1346		);1347		assert_eq!(1348			<pallet_refungible::Owned<Test>>::get((1349				re_fungible_collection_id,1350				account(1),1351				TokenId(1)1352			)),1353			true1354		);1355	});1356}13571358#[test]1359fn approve() {1360	new_test_ext().execute_with(|| {1361		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13621363		let data = default_nft_data();1364		create_test_item(collection_id, &data.into());13651366		let origin1 = Origin::signed(1);13671368		// approve1369		assert_ok!(TemplateModule::approve(1370			origin1,1371			account(2),1372			CollectionId(1),1373			TokenId(1),1374			11375		));1376		assert_eq!(1377			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1378			account(2)1379		);1380	});1381}13821383#[test]1384fn transfer_from() {1385	new_test_ext().execute_with(|| {1386		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1387		let origin1 = Origin::signed(1);1388		let origin2 = Origin::signed(2);13891390		let data = default_nft_data();1391		create_test_item(collection_id, &data.into());13921393		// approve1394		assert_ok!(TemplateModule::approve(1395			origin1.clone(),1396			account(2),1397			CollectionId(1),1398			TokenId(1),1399			11400		));1401		assert_eq!(1402			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1403			account(2)1404		);14051406		assert_ok!(TemplateModule::set_mint_permission(1407			origin1.clone(),1408			CollectionId(1),1409			true1410		));1411		assert_ok!(TemplateModule::set_public_access_mode(1412			origin1.clone(),1413			CollectionId(1),1414			AccessMode::AllowList1415		));1416		assert_ok!(TemplateModule::add_to_allow_list(1417			origin1.clone(),1418			CollectionId(1),1419			account(1)1420		));1421		assert_ok!(TemplateModule::add_to_allow_list(1422			origin1.clone(),1423			CollectionId(1),1424			account(2)1425		));1426		assert_ok!(TemplateModule::add_to_allow_list(1427			origin1,1428			CollectionId(1),1429			account(3)1430		));14311432		assert_ok!(TemplateModule::transfer_from(1433			origin2,1434			account(1),1435			account(2),1436			CollectionId(1),1437			TokenId(1),1438			11439		));14401441		// after transfer1442		assert_eq!(1443			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1444			01445		);1446		assert_eq!(1447			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1448			11449		);1450	});1451}14521453// #endregion14541455// Coverage tests region1456// #region14571458#[test]1459fn owner_can_add_address_to_allow_list() {1460	new_test_ext().execute_with(|| {1461		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14621463		let origin1 = Origin::signed(1);1464		assert_ok!(TemplateModule::add_to_allow_list(1465			origin1,1466			collection_id,1467			account(2)1468		));1469		assert!(<pallet_common::Allowlist<Test>>::get((1470			collection_id,1471			account(2)1472		)));1473	});1474}14751476#[test]1477fn admin_can_add_address_to_allow_list() {1478	new_test_ext().execute_with(|| {1479		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1480		let origin1 = Origin::signed(1);1481		let origin2 = Origin::signed(2);14821483		assert_ok!(TemplateModule::add_collection_admin(1484			origin1,1485			collection_id,1486			account(2)1487		));1488		assert_ok!(TemplateModule::add_to_allow_list(1489			origin2,1490			collection_id,1491			account(3)1492		));1493		assert!(<pallet_common::Allowlist<Test>>::get((1494			collection_id,1495			account(3)1496		)));1497	});1498}14991500#[test]1501fn nonprivileged_user_cannot_add_address_to_allow_list() {1502	new_test_ext().execute_with(|| {1503		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15041505		let origin2 = Origin::signed(2);1506		assert_noop!(1507			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1508			CommonError::<Test>::NoPermission1509		);1510	});1511}15121513#[test]1514fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1515	new_test_ext().execute_with(|| {1516		let origin1 = Origin::signed(1);15171518		assert_noop!(1519			TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1520			CommonError::<Test>::CollectionNotFound1521		);1522	});1523}15241525#[test]1526fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1527	new_test_ext().execute_with(|| {1528		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15291530		let origin1 = Origin::signed(1);1531		assert_ok!(TemplateModule::destroy_collection(1532			origin1.clone(),1533			collection_id1534		));1535		assert_noop!(1536			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1537			CommonError::<Test>::CollectionNotFound1538		);1539	});1540}15411542// If address is already added to allow list, nothing happens1543#[test]1544fn address_is_already_added_to_allow_list() {1545	new_test_ext().execute_with(|| {1546		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1547		let origin1 = Origin::signed(1);15481549		assert_ok!(TemplateModule::add_to_allow_list(1550			origin1.clone(),1551			collection_id,1552			account(2)1553		));1554		assert_ok!(TemplateModule::add_to_allow_list(1555			origin1,1556			collection_id,1557			account(2)1558		));1559		assert!(<pallet_common::Allowlist<Test>>::get((1560			collection_id,1561			account(2)1562		)));1563	});1564}15651566#[test]1567fn owner_can_remove_address_from_allow_list() {1568	new_test_ext().execute_with(|| {1569		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15701571		let origin1 = Origin::signed(1);1572		assert_ok!(TemplateModule::add_to_allow_list(1573			origin1.clone(),1574			collection_id,1575			account(2)1576		));1577		assert_ok!(TemplateModule::remove_from_allow_list(1578			origin1,1579			collection_id,1580			account(2)1581		));1582		assert_eq!(1583			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1584			false1585		);1586	});1587}15881589#[test]1590fn admin_can_remove_address_from_allow_list() {1591	new_test_ext().execute_with(|| {1592		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1593		let origin1 = Origin::signed(1);1594		let origin2 = Origin::signed(2);15951596		// Owner adds admin1597		assert_ok!(TemplateModule::add_collection_admin(1598			origin1.clone(),1599			collection_id,1600			account(2)1601		));16021603		// Owner adds address 3 to allow list1604		assert_ok!(TemplateModule::add_to_allow_list(1605			origin1,1606			collection_id,1607			account(3)1608		));16091610		// Admin removes address 3 from allow list1611		assert_ok!(TemplateModule::remove_from_allow_list(1612			origin2,1613			collection_id,1614			account(3)1615		));1616		assert_eq!(1617			<pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1618			false1619		);1620	});1621}16221623#[test]1624fn nonprivileged_user_cannot_remove_address_from_allow_list() {1625	new_test_ext().execute_with(|| {1626		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1627		let origin1 = Origin::signed(1);1628		let origin2 = Origin::signed(2);16291630		assert_ok!(TemplateModule::add_to_allow_list(1631			origin1,1632			collection_id,1633			account(2)1634		));1635		assert_noop!(1636			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1637			CommonError::<Test>::NoPermission1638		);1639		assert!(<pallet_common::Allowlist<Test>>::get((1640			collection_id,1641			account(2)1642		)));1643	});1644}16451646#[test]1647fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1648	new_test_ext().execute_with(|| {1649		let origin1 = Origin::signed(1);16501651		assert_noop!(1652			TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1653			CommonError::<Test>::CollectionNotFound1654		);1655	});1656}16571658#[test]1659fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1660	new_test_ext().execute_with(|| {1661		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1662		let origin1 = Origin::signed(1);1663		let origin2 = Origin::signed(2);16641665		// Add account 2 to allow list1666		assert_ok!(TemplateModule::add_to_allow_list(1667			origin1.clone(),1668			collection_id,1669			account(2)1670		));16711672		// Account 2 is in collection allow-list1673		assert!(<pallet_common::Allowlist<Test>>::get((1674			collection_id,1675			account(2)1676		)));16771678		// Destroy collection1679		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16801681		// Attempt to remove account 2 from collection allow-list => error1682		assert_noop!(1683			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1684			CommonError::<Test>::CollectionNotFound1685		);16861687		// Account 2 is not found in collection allow-list anyway1688		assert_eq!(1689			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1690			false1691		);1692	});1693}16941695// If address is already removed from allow list, nothing happens1696#[test]1697fn address_is_already_removed_from_allow_list() {1698	new_test_ext().execute_with(|| {1699		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1700		let origin1 = Origin::signed(1);17011702		assert_ok!(TemplateModule::add_to_allow_list(1703			origin1.clone(),1704			collection_id,1705			account(2)1706		));1707		assert_ok!(TemplateModule::remove_from_allow_list(1708			origin1.clone(),1709			collection_id,1710			account(2)1711		));1712		assert_eq!(1713			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1714			false1715		);1716		assert_ok!(TemplateModule::remove_from_allow_list(1717			origin1,1718			collection_id,1719			account(2)1720		));1721		assert_eq!(1722			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1723			false1724		);1725	});1726}17271728// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1729#[test]1730fn allow_list_test_1() {1731	new_test_ext().execute_with(|| {1732		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17331734		let origin1 = Origin::signed(1);17351736		let data = default_nft_data();1737		create_test_item(collection_id, &data.into());17381739		assert_ok!(TemplateModule::set_public_access_mode(1740			origin1.clone(),1741			collection_id,1742			AccessMode::AllowList1743		));1744		assert_ok!(TemplateModule::add_to_allow_list(1745			origin1.clone(),1746			collection_id,1747			account(2)1748		));17491750		assert_noop!(1751			TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1752				.map_err(|e| e.error),1753			CommonError::<Test>::AddressNotInAllowlist1754		);1755	});1756}17571758#[test]1759fn allow_list_test_2() {1760	new_test_ext().execute_with(|| {1761		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1762		let origin1 = Origin::signed(1);17631764		let data = default_nft_data();1765		create_test_item(collection_id, &data.into());17661767		assert_ok!(TemplateModule::set_public_access_mode(1768			origin1.clone(),1769			collection_id,1770			AccessMode::AllowList1771		));1772		assert_ok!(TemplateModule::add_to_allow_list(1773			origin1.clone(),1774			collection_id,1775			account(1)1776		));1777		assert_ok!(TemplateModule::add_to_allow_list(1778			origin1.clone(),1779			collection_id,1780			account(2)1781		));17821783		// do approve1784		assert_ok!(TemplateModule::approve(1785			origin1.clone(),1786			account(1),1787			collection_id,1788			TokenId(1),1789			11790		));1791		assert_eq!(1792			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1793			account(1)1794		);17951796		assert_ok!(TemplateModule::remove_from_allow_list(1797			origin1.clone(),1798			collection_id,1799			account(1)1800		));18011802		assert_noop!(1803			TemplateModule::transfer_from(1804				origin1,1805				account(1),1806				account(3),1807				CollectionId(1),1808				TokenId(1),1809				11810			)1811			.map_err(|e| e.error),1812			CommonError::<Test>::AddressNotInAllowlist1813		);1814	});1815}18161817// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1818#[test]1819fn allow_list_test_3() {1820	new_test_ext().execute_with(|| {1821		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18221823		let origin1 = Origin::signed(1);18241825		let data = default_nft_data();1826		create_test_item(collection_id, &data.into());18271828		assert_ok!(TemplateModule::set_public_access_mode(1829			origin1.clone(),1830			collection_id,1831			AccessMode::AllowList1832		));1833		assert_ok!(TemplateModule::add_to_allow_list(1834			origin1.clone(),1835			collection_id,1836			account(1)1837		));18381839		assert_noop!(1840			TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1841				.map_err(|e| e.error),1842			CommonError::<Test>::AddressNotInAllowlist1843		);1844	});1845}18461847#[test]1848fn allow_list_test_4() {1849	new_test_ext().execute_with(|| {1850		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18511852		let origin1 = Origin::signed(1);18531854		let data = default_nft_data();1855		create_test_item(collection_id, &data.into());18561857		assert_ok!(TemplateModule::set_public_access_mode(1858			origin1.clone(),1859			collection_id,1860			AccessMode::AllowList1861		));1862		assert_ok!(TemplateModule::add_to_allow_list(1863			origin1.clone(),1864			collection_id,1865			account(1)1866		));1867		assert_ok!(TemplateModule::add_to_allow_list(1868			origin1.clone(),1869			collection_id,1870			account(2)1871		));18721873		// do approve1874		assert_ok!(TemplateModule::approve(1875			origin1.clone(),1876			account(1),1877			collection_id,1878			TokenId(1),1879			11880		));1881		assert_eq!(1882			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1883			account(1)1884		);18851886		assert_ok!(TemplateModule::remove_from_allow_list(1887			origin1.clone(),1888			collection_id,1889			account(2)1890		));18911892		assert_noop!(1893			TemplateModule::transfer_from(1894				origin1,1895				account(1),1896				account(3),1897				collection_id,1898				TokenId(1),1899				11900			)1901			.map_err(|e| e.error),1902			CommonError::<Test>::AddressNotInAllowlist1903		);1904	});1905}19061907// If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)1908#[test]1909fn allow_list_test_5() {1910	new_test_ext().execute_with(|| {1911		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19121913		let origin1 = Origin::signed(1);19141915		let data = default_nft_data();1916		create_test_item(collection_id, &data.into());19171918		assert_ok!(TemplateModule::set_public_access_mode(1919			origin1.clone(),1920			collection_id,1921			AccessMode::AllowList1922		));1923		assert_noop!(1924			TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1925				.map_err(|e| e.error),1926			CommonError::<Test>::AddressNotInAllowlist1927		);1928	});1929}19301931// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1932#[test]1933fn allow_list_test_6() {1934	new_test_ext().execute_with(|| {1935		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19361937		let origin1 = Origin::signed(1);19381939		let data = default_nft_data();1940		create_test_item(collection_id, &data.into());19411942		assert_ok!(TemplateModule::set_public_access_mode(1943			origin1.clone(),1944			collection_id,1945			AccessMode::AllowList1946		));19471948		// do approve1949		assert_noop!(1950			TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1951				.map_err(|e| e.error),1952			CommonError::<Test>::AddressNotInAllowlist1953		);1954	});1955}19561957// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1958//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1959#[test]1960fn allow_list_test_7() {1961	new_test_ext().execute_with(|| {1962		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19631964		let data = default_nft_data();1965		create_test_item(collection_id, &data.into());19661967		let origin1 = Origin::signed(1);19681969		assert_ok!(TemplateModule::set_public_access_mode(1970			origin1.clone(),1971			collection_id,1972			AccessMode::AllowList1973		));1974		assert_ok!(TemplateModule::add_to_allow_list(1975			origin1.clone(),1976			collection_id,1977			account(1)1978		));1979		assert_ok!(TemplateModule::add_to_allow_list(1980			origin1.clone(),1981			collection_id,1982			account(2)1983		));19841985		assert_ok!(TemplateModule::transfer(1986			origin1,1987			account(2),1988			CollectionId(1),1989			TokenId(1),1990			11991		));1992	});1993}19941995#[test]1996fn allow_list_test_8() {1997	new_test_ext().execute_with(|| {1998		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19992000		// Create NFT for account 12001		let data = default_nft_data();2002		create_test_item(collection_id, &data.into());20032004		let origin1 = Origin::signed(1);20052006		// Toggle Allow List mode and add accounts 1 and 22007		assert_ok!(TemplateModule::set_public_access_mode(2008			origin1.clone(),2009			collection_id,2010			AccessMode::AllowList2011		));2012		assert_ok!(TemplateModule::add_to_allow_list(2013			origin1.clone(),2014			collection_id,2015			account(1)2016		));2017		assert_ok!(TemplateModule::add_to_allow_list(2018			origin1.clone(),2019			collection_id,2020			account(2)2021		));20222023		// Sself-approve account 1 for NFT 12024		assert_ok!(TemplateModule::approve(2025			origin1.clone(),2026			account(1),2027			CollectionId(1),2028			TokenId(1),2029			12030		));2031		assert_eq!(2032			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2033			account(1)2034		);20352036		// Transfer from 1 to 22037		assert_ok!(TemplateModule::transfer_from(2038			origin1,2039			account(1),2040			account(2),2041			CollectionId(1),2042			TokenId(1),2043			12044		));2045	});2046}20472048// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2049#[test]2050fn allow_list_test_9() {2051	new_test_ext().execute_with(|| {2052		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2053		let origin1 = Origin::signed(1);20542055		assert_ok!(TemplateModule::set_public_access_mode(2056			origin1.clone(),2057			collection_id,2058			AccessMode::AllowList2059		));2060		assert_ok!(TemplateModule::set_mint_permission(2061			origin1,2062			collection_id,2063			false2064		));20652066		let data = default_nft_data();2067		create_test_item(collection_id, &data.into());2068	});2069}20702071// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2072#[test]2073fn allow_list_test_10() {2074	new_test_ext().execute_with(|| {2075		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20762077		let origin1 = Origin::signed(1);2078		let origin2 = Origin::signed(2);20792080		assert_ok!(TemplateModule::set_public_access_mode(2081			origin1.clone(),2082			collection_id,2083			AccessMode::AllowList2084		));2085		assert_ok!(TemplateModule::set_mint_permission(2086			origin1.clone(),2087			collection_id,2088			false2089		));20902091		assert_ok!(TemplateModule::add_collection_admin(2092			origin1,2093			collection_id,2094			account(2)2095		));20962097		assert_ok!(TemplateModule::create_item(2098			origin2,2099			collection_id,2100			account(2),2101			default_nft_data().into()2102		));2103	});2104}21052106// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.2107#[test]2108fn allow_list_test_11() {2109	new_test_ext().execute_with(|| {2110		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21112112		let origin1 = Origin::signed(1);2113		let origin2 = Origin::signed(2);21142115		assert_ok!(TemplateModule::set_public_access_mode(2116			origin1.clone(),2117			collection_id,2118			AccessMode::AllowList2119		));2120		assert_ok!(TemplateModule::set_mint_permission(2121			origin1.clone(),2122			collection_id,2123			false2124		));2125		assert_ok!(TemplateModule::add_to_allow_list(2126			origin1,2127			collection_id,2128			account(2)2129		));21302131		assert_noop!(2132			TemplateModule::create_item(2133				origin2,2134				CollectionId(1),2135				account(2),2136				default_nft_data().into()2137			)2138			.map_err(|e| e.error),2139			CommonError::<Test>::PublicMintingNotAllowed2140		);2141	});2142}21432144// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.2145#[test]2146fn allow_list_test_12() {2147	new_test_ext().execute_with(|| {2148		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21492150		let origin1 = Origin::signed(1);2151		let origin2 = Origin::signed(2);21522153		assert_ok!(TemplateModule::set_public_access_mode(2154			origin1.clone(),2155			collection_id,2156			AccessMode::AllowList2157		));2158		assert_ok!(TemplateModule::set_mint_permission(2159			origin1,2160			collection_id,2161			false2162		));21632164		assert_noop!(2165			TemplateModule::create_item(2166				origin2,2167				CollectionId(1),2168				account(2),2169				default_nft_data().into()2170			)2171			.map_err(|e| e.error),2172			CommonError::<Test>::PublicMintingNotAllowed2173		);2174	});2175}21762177// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2178#[test]2179fn allow_list_test_13() {2180	new_test_ext().execute_with(|| {2181		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21822183		let origin1 = Origin::signed(1);21842185		assert_ok!(TemplateModule::set_public_access_mode(2186			origin1.clone(),2187			collection_id,2188			AccessMode::AllowList2189		));2190		assert_ok!(TemplateModule::set_mint_permission(2191			origin1,2192			collection_id,2193			true2194		));21952196		let data = default_nft_data();2197		create_test_item(collection_id, &data.into());2198	});2199}22002201// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2202#[test]2203fn allow_list_test_14() {2204	new_test_ext().execute_with(|| {2205		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22062207		let origin1 = Origin::signed(1);2208		let origin2 = Origin::signed(2);22092210		assert_ok!(TemplateModule::set_public_access_mode(2211			origin1.clone(),2212			collection_id,2213			AccessMode::AllowList2214		));2215		assert_ok!(TemplateModule::set_mint_permission(2216			origin1.clone(),2217			collection_id,2218			true2219		));22202221		assert_ok!(TemplateModule::add_collection_admin(2222			origin1,2223			collection_id,2224			account(2)2225		));22262227		assert_ok!(TemplateModule::create_item(2228			origin2,2229			collection_id,2230			account(2),2231			default_nft_data().into()2232		));2233	});2234}22352236// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.2237#[test]2238fn allow_list_test_15() {2239	new_test_ext().execute_with(|| {2240		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22412242		let origin1 = Origin::signed(1);2243		let origin2 = Origin::signed(2);22442245		assert_ok!(TemplateModule::set_public_access_mode(2246			origin1.clone(),2247			collection_id,2248			AccessMode::AllowList2249		));2250		assert_ok!(TemplateModule::set_mint_permission(2251			origin1,2252			collection_id,2253			true2254		));22552256		assert_noop!(2257			TemplateModule::create_item(2258				origin2,2259				collection_id,2260				account(2),2261				default_nft_data().into()2262			)2263			.map_err(|e| e.error),2264			CommonError::<Test>::AddressNotInAllowlist2265		);2266	});2267}22682269// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.2270#[test]2271fn allow_list_test_16() {2272	new_test_ext().execute_with(|| {2273		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22742275		let origin1 = Origin::signed(1);2276		let origin2 = Origin::signed(2);22772278		assert_ok!(TemplateModule::set_public_access_mode(2279			origin1.clone(),2280			collection_id,2281			AccessMode::AllowList2282		));2283		assert_ok!(TemplateModule::set_mint_permission(2284			origin1.clone(),2285			collection_id,2286			true2287		));2288		assert_ok!(TemplateModule::add_to_allow_list(2289			origin1,2290			collection_id,2291			account(2)2292		));22932294		assert_ok!(TemplateModule::create_item(2295			origin2,2296			collection_id,2297			account(2),2298			default_nft_data().into()2299		));2300	});2301}23022303// Total number of collections. Positive test2304#[test]2305fn total_number_collections_bound() {2306	new_test_ext().execute_with(|| {2307		create_test_collection(&CollectionMode::NFT, CollectionId(1));2308	});2309}23102311#[test]2312fn create_max_collections() {2313	new_test_ext().execute_with(|| {2314		for i in 1..COLLECTION_NUMBER_LIMIT {2315			create_test_collection(&CollectionMode::NFT, CollectionId(i));2316		}2317	});2318}23192320// Total number of collections. Negative test2321#[test]2322fn total_number_collections_bound_neg() {2323	new_test_ext().execute_with(|| {2324		let origin1 = Origin::signed(1);23252326		for i in 1..=COLLECTION_NUMBER_LIMIT {2327			create_test_collection(&CollectionMode::NFT, CollectionId(i));2328		}23292330		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2331		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2332		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23332334		let data: CreateCollectionData<u64> = CreateCollectionData {2335			name: col_name1.try_into().unwrap(),2336			description: col_desc1.try_into().unwrap(),2337			token_prefix: token_prefix1.try_into().unwrap(),2338			mode: CollectionMode::NFT,2339			..Default::default()2340		};23412342		// 11-th collection in chain. Expects error2343		assert_noop!(2344			TemplateModule::create_collection_ex(origin1, data),2345			CommonError::<Test>::TotalCollectionsLimitExceeded2346		);2347	});2348}23492350// Owned tokens by a single address. Positive test2351#[test]2352fn owned_tokens_bound() {2353	new_test_ext().execute_with(|| {2354		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23552356		let data = default_nft_data();2357		create_test_item(collection_id, &data.clone().into());2358		create_test_item(collection_id, &data.into());2359	});2360}23612362// Owned tokens by a single address. Negotive test2363#[test]2364fn owned_tokens_bound_neg() {2365	new_test_ext().execute_with(|| {2366		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23672368		let origin1 = Origin::signed(1);23692370		for _ in 1..=MAX_TOKEN_OWNERSHIP {2371			let data = default_nft_data();2372			create_test_item(collection_id, &data.clone().into());2373		}23742375		let data = default_nft_data();2376		assert_noop!(2377			TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2378				.map_err(|e| e.error),2379			CommonError::<Test>::AccountTokenLimitExceeded2380		);2381	});2382}23832384// Number of collection admins. Positive test2385#[test]2386fn collection_admins_bound() {2387	new_test_ext().execute_with(|| {2388		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23892390		let origin1 = Origin::signed(1);23912392		assert_ok!(TemplateModule::add_collection_admin(2393			origin1.clone(),2394			collection_id,2395			account(2)2396		));2397		assert_ok!(TemplateModule::add_collection_admin(2398			origin1,2399			collection_id,2400			account(3)2401		));2402	});2403}24042405// Number of collection admins. Negotive test2406#[test]2407fn collection_admins_bound_neg() {2408	new_test_ext().execute_with(|| {2409		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24102411		let origin1 = Origin::signed(1);24122413		for i in 0..COLLECTION_ADMINS_LIMIT {2414			assert_ok!(TemplateModule::add_collection_admin(2415				origin1.clone(),2416				collection_id,2417				account((2 + i).into())2418			));2419		}2420		assert_noop!(2421			TemplateModule::add_collection_admin(2422				origin1,2423				collection_id,2424				account((3 + COLLECTION_ADMINS_LIMIT).into())2425			),2426			CommonError::<Test>::CollectionAdminCountExceeded2427		);2428	});2429}2430// #endregion24312432#[test]2433fn set_const_on_chain_schema() {2434	new_test_ext().execute_with(|| {2435		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24362437		let origin1 = Origin::signed(1);2438		assert_ok!(TemplateModule::set_const_on_chain_schema(2439			origin1,2440			collection_id,2441			b"test const on chain schema".to_vec().try_into().unwrap()2442		));24432444		assert_eq!(2445			<pallet_common::CollectionById<Test>>::get(collection_id)2446				.unwrap()2447				.const_on_chain_schema,2448			b"test const on chain schema".to_vec()2449		);2450		assert_eq!(2451			<pallet_common::CollectionById<Test>>::get(collection_id)2452				.unwrap()2453				.variable_on_chain_schema,2454			b"".to_vec()2455		);2456	});2457}24582459#[test]2460fn set_variable_on_chain_schema() {2461	new_test_ext().execute_with(|| {2462		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24632464		let origin1 = Origin::signed(1);2465		assert_ok!(TemplateModule::set_variable_on_chain_schema(2466			origin1,2467			collection_id,2468			b"test variable on chain schema"2469				.to_vec()2470				.try_into()2471				.unwrap()2472		));24732474		assert_eq!(2475			<pallet_common::CollectionById<Test>>::get(collection_id)2476				.unwrap()2477				.const_on_chain_schema,2478			b"".to_vec()2479		);2480		assert_eq!(2481			<pallet_common::CollectionById<Test>>::get(collection_id)2482				.unwrap()2483				.variable_on_chain_schema,2484			b"test variable on chain schema".to_vec()2485		);2486	});2487}24882489#[test]2490fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2491	new_test_ext().execute_with(|| {2492		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24932494		let origin1 = Origin::signed(1);24952496		let data = default_nft_data();2497		create_test_item(CollectionId(1), &data.into());24982499		let variable_data = b"test data".to_vec();2500		assert_ok!(TemplateModule::set_variable_meta_data(2501			origin1,2502			collection_id,2503			TokenId(1),2504			variable_data.clone().try_into().unwrap()2505		));25062507		assert_eq!(2508			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2509				.unwrap()2510				.variable_data,2511			variable_data2512		);2513	});2514}25152516#[test]2517fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2518	new_test_ext().execute_with(|| {2519		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));25202521		let origin1 = Origin::signed(1);25222523		let data = default_re_fungible_data();2524		create_test_item(collection_id, &data.into());25252526		let variable_data = b"test data".to_vec();2527		assert_ok!(TemplateModule::set_variable_meta_data(2528			origin1,2529			collection_id,2530			TokenId(1),2531			variable_data.clone().try_into().unwrap()2532		));25332534		assert_eq!(2535			<pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2536			variable_data2537		);2538	});2539}25402541#[test]2542fn set_variable_meta_data_on_fungible_token_fails() {2543	new_test_ext().execute_with(|| {2544		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));25452546		let origin1 = Origin::signed(1);25472548		let data = default_fungible_data();2549		create_test_item(collection_id, &data.into());25502551		let variable_data = b"test data".to_vec();2552		assert_noop!(2553			TemplateModule::set_variable_meta_data(2554				origin1,2555				collection_id,2556				TokenId(0),2557				variable_data.try_into().unwrap()2558			)2559			.map_err(|e| e.error),2560			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2561		);2562	});2563}25642565#[test]2566fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2567	new_test_ext().execute_with(|| {2568		//default_limits();25692570		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25712572		let origin1 = Origin::signed(1);25732574		let data = default_nft_data();2575		create_test_item(collection_id, &data.into());25762577		assert_ok!(TemplateModule::set_meta_update_permission_flag(2578			origin1.clone(),2579			collection_id,2580			MetaUpdatePermission::ItemOwner,2581		));25822583		let variable_data = b"ten chars.".to_vec();2584		assert_ok!(TemplateModule::set_variable_meta_data(2585			origin1,2586			collection_id,2587			TokenId(1),2588			variable_data.clone().try_into().unwrap()2589		));25902591		assert_eq!(2592			<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2593				.unwrap()2594				.variable_data,2595			variable_data2596		);2597	});2598}25992600#[test]2601fn collection_transfer_flag_works() {2602	new_test_ext().execute_with(|| {2603		let origin1 = Origin::signed(1);26042605		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2606		assert_ok!(TemplateModule::set_transfers_enabled_flag(2607			origin1,2608			collection_id,2609			true2610		));26112612		let data = default_nft_data();2613		create_test_item(collection_id, &data.into());2614		assert_eq!(2615			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2616			12617		);2618		assert_eq!(2619			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2620			true2621		);26222623		let origin1 = Origin::signed(1);26242625		// default scenario2626		assert_ok!(TemplateModule::transfer(2627			origin1,2628			account(2),2629			collection_id,2630			TokenId(1),2631			12632		));2633		assert_eq!(2634			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2635			false2636		);2637		assert_eq!(2638			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2639			true2640		);2641		assert_eq!(2642			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2643			02644		);2645		assert_eq!(2646			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2647			12648		);2649	});2650}26512652#[test]2653fn set_variable_meta_data_on_nft_with_admin_flag() {2654	new_test_ext().execute_with(|| {2655		// default_limits();26562657		let collection_id =2658			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26592660		let origin1 = Origin::signed(1);2661		let origin2 = Origin::signed(2);26622663		assert_ok!(TemplateModule::set_mint_permission(2664			origin2.clone(),2665			collection_id,2666			true2667		));2668		assert_ok!(TemplateModule::add_to_allow_list(2669			origin2.clone(),2670			collection_id,2671			account(1)2672		));26732674		assert_ok!(TemplateModule::add_collection_admin(2675			origin2.clone(),2676			collection_id,2677			account(1)2678		));26792680		let data = default_nft_data();2681		create_test_item(collection_id, &data.into());26822683		assert_ok!(TemplateModule::set_meta_update_permission_flag(2684			origin2.clone(),2685			collection_id,2686			MetaUpdatePermission::Admin,2687		));26882689		let variable_data = b"test.".to_vec();2690		assert_ok!(TemplateModule::set_variable_meta_data(2691			origin1,2692			collection_id,2693			TokenId(1),2694			variable_data.clone().try_into().unwrap()2695		));26962697		assert_eq!(2698			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2699				.unwrap()2700				.variable_data,2701			variable_data2702		);2703	});2704}27052706#[test]2707fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2708	new_test_ext().execute_with(|| {2709		// default_limits();27102711		let collection_id =2712			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27132714		let origin1 = Origin::signed(1);2715		let origin2 = Origin::signed(2);27162717		assert_ok!(TemplateModule::set_mint_permission(2718			origin2.clone(),2719			collection_id,2720			true2721		));2722		assert_ok!(TemplateModule::add_to_allow_list(2723			origin2.clone(),2724			collection_id,2725			account(1)2726		));27272728		let data = default_nft_data();2729		create_test_item(collection_id, &data.into());27302731		assert_ok!(TemplateModule::set_meta_update_permission_flag(2732			origin2.clone(),2733			collection_id,2734			MetaUpdatePermission::Admin,2735		));27362737		let variable_data = b"test.".to_vec();2738		assert_noop!(2739			TemplateModule::set_variable_meta_data(2740				origin1,2741				collection_id,2742				TokenId(1),2743				variable_data.try_into().unwrap()2744			)2745			.map_err(|e| e.error),2746			CommonError::<Test>::NoPermission2747		);2748	});2749}27502751#[test]2752fn set_variable_meta_flag_after_freeze() {2753	new_test_ext().execute_with(|| {2754		// default_limits();27552756		let collection_id =2757			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27582759		let origin2 = Origin::signed(2);27602761		assert_ok!(TemplateModule::set_meta_update_permission_flag(2762			origin2.clone(),2763			collection_id,2764			MetaUpdatePermission::None,2765		));2766		assert_noop!(2767			TemplateModule::set_meta_update_permission_flag(2768				origin2.clone(),2769				collection_id,2770				MetaUpdatePermission::Admin2771			),2772			CommonError::<Test>::MetadataFlagFrozen2773		);2774	});2775}27762777#[test]2778fn set_variable_meta_data_on_nft_with_none_flag_neg() {2779	new_test_ext().execute_with(|| {2780		// default_limits();27812782		let collection_id =2783			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2784		let origin1 = Origin::signed(1);27852786		let data = default_nft_data();2787		create_test_item(collection_id, &data.into());27882789		assert_ok!(TemplateModule::set_meta_update_permission_flag(2790			origin1.clone(),2791			collection_id,2792			MetaUpdatePermission::None,2793		));27942795		let variable_data = b"test.".to_vec();2796		assert_noop!(2797			TemplateModule::set_variable_meta_data(2798				origin1.clone(),2799				collection_id,2800				TokenId(1),2801				variable_data.try_into().unwrap()2802			)2803			.map_err(|e| e.error),2804			CommonError::<Test>::NoPermission2805		);2806	});2807}28082809#[test]2810fn collection_transfer_flag_works_neg() {2811	new_test_ext().execute_with(|| {2812		let origin1 = Origin::signed(1);28132814		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2815		assert_ok!(TemplateModule::set_transfers_enabled_flag(2816			origin1,2817			collection_id,2818			false2819		));28202821		let data = default_nft_data();2822		create_test_item(collection_id, &data.into());2823		assert_eq!(2824			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2825			12826		);2827		assert_eq!(2828			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2829			true2830		);28312832		let origin1 = Origin::signed(1);28332834		// default scenario2835		assert_noop!(2836			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2837				.map_err(|e| e.error),2838			CommonError::<Test>::TransferNotAllowed2839		);2840		assert_eq!(2841			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2842			12843		);2844		assert_eq!(2845			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2846			02847		);2848		assert_eq!(2849			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2850			true2851		);2852		assert_eq!(2853			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2854			false2855		);2856	});2857}28582859#[test]2860fn collection_sponsoring() {2861	new_test_ext().execute_with(|| {2862		// default_limits();2863		let user1 = 1_u64;2864		let user2 = 777_u64;2865		let origin1 = Origin::signed(user1);2866		let origin2 = Origin::signed(user2);2867		let account2 = account(user2);28682869		let collection_id =2870			create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));2871		assert_ok!(TemplateModule::set_collection_sponsor(2872			origin1.clone(),2873			collection_id,2874			user12875		));2876		assert_ok!(TemplateModule::confirm_sponsorship(2877			origin1.clone(),2878			collection_id2879		));28802881		// Expect error while have no permissions2882		assert!(TemplateModule::create_item(2883			origin2.clone(),2884			collection_id,2885			account2.clone(),2886			default_nft_data().into()2887		)2888		.is_err());28892890		assert_ok!(TemplateModule::set_public_access_mode(2891			origin1.clone(),2892			collection_id,2893			AccessMode::AllowList2894		));2895		assert_ok!(TemplateModule::add_to_allow_list(2896			origin1.clone(),2897			collection_id,2898			account2.clone()2899		));2900		assert_ok!(TemplateModule::set_mint_permission(2901			origin1.clone(),2902			collection_id,2903			true2904		));29052906		assert_ok!(TemplateModule::create_item(2907			origin2,2908			collection_id,2909			account2,2910			default_nft_data().into()2911		));2912	});2913}