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

difftreelog

CORE-296 Add error "NotSufficientFounds" and test it.

Trubnikov Sergey2022-02-28parent: #7f8cc7f.patch.diff
in: master

3 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -318,6 +318,9 @@
 		AddressIsZero,
 		/// Target collection doesn't supports this operation
 		UnsupportedOperation,
+
+		/// Not sufficient founds to perform action
+		NotSufficientFounds,
 	}
 
 	#[pallet::storage]
@@ -470,7 +473,7 @@
 				WithdrawReasons::TRANSFER,
 				ExistenceRequirement::KeepAlive,
 			)
-			.map_err(|_| Error::<T>::NoPermission)?;
+			.map_err(|_| Error::<T>::NotSufficientFounds)?;
 		}
 
 		<CreatedCollectionCount<T>>::put(created_count);
modifiedpallets/unique/src/mock.rsdiffbeforeafterboth
--- a/pallets/unique/src/mock.rs
+++ b/pallets/unique/src/mock.rs
@@ -108,7 +108,7 @@
 }
 
 parameter_types! {
-	pub const CollectionCreationPrice: u32 = 0;
+	pub const CollectionCreationPrice: u32 = 100;
 	pub TreasuryAccountId: u64 = 1234;
 	pub EthereumChainId: u32 = 1111;
 }
modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
before · pallets/unique/src/tests.rs
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode};5use up_data_structs::{6	COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,7	CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,8	TokenId, MAX_TOKEN_OWNERSHIP,9};10use frame_support::{assert_noop, assert_ok};11use sp_std::convert::TryInto;1213fn default_nft_data() -> CreateNftData {14	CreateNftData {15		const_data: vec![1, 2, 3].try_into().unwrap(),16		variable_data: vec![3, 2, 1].try_into().unwrap(),17	}18}1920fn default_fungible_data() -> CreateFungibleData {21	CreateFungibleData { value: 5 }22}2324fn default_re_fungible_data() -> CreateReFungibleData {25	CreateReFungibleData {26		const_data: vec![1, 2, 3].try_into().unwrap(),27		variable_data: vec![3, 2, 1].try_into().unwrap(),28		pieces: 1023,29	}30}3132fn create_test_collection_for_owner(33	mode: &CollectionMode,34	owner: u64,35	id: CollectionId,36) -> CollectionId {37	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();38	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();39	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();4041	let origin1 = Origin::signed(owner);42	assert_ok!(TemplateModule::create_collection(43		origin1,44		col_name1.try_into().unwrap(),45		col_desc1.try_into().unwrap(),46		token_prefix1.try_into().unwrap(),47		mode.clone()48	));4950	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();51	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();52	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();53	assert_eq!(54		<pallet_common::CollectionById<Test>>::get(id)55			.unwrap()56			.owner,57		owner58	);59	assert_eq!(60		<pallet_common::CollectionById<Test>>::get(id).unwrap().name,61		saved_col_name62	);63	assert_eq!(64		<pallet_common::CollectionById<Test>>::get(id).unwrap().mode,65		*mode66	);67	assert_eq!(68		<pallet_common::CollectionById<Test>>::get(id)69			.unwrap()70			.description,71		saved_description72	);73	assert_eq!(74		<pallet_common::CollectionById<Test>>::get(id)75			.unwrap()76			.token_prefix,77		saved_prefix78	);79	id80}8182fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {83	create_test_collection_for_owner(&mode, 1, id)84}8586fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {87	let origin1 = Origin::signed(1);88	assert_ok!(TemplateModule::create_item(89		origin1,90		collection_id,91		account(1),92		data.clone()93	));94}9596fn account(sub: u64) -> TestCrossAccountId {97	TestCrossAccountId::from_sub(sub)98}99100// Use cases tests region101// #region102103#[test]104fn set_version_schema() {105	new_test_ext().execute_with(|| {106		let origin1 = Origin::signed(1);107		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));108109		assert_ok!(TemplateModule::set_schema_version(110			origin1,111			collection_id,112			SchemaVersion::Unique113		));114		assert_eq!(115			<pallet_common::CollectionById<Test>>::get(collection_id)116				.unwrap()117				.schema_version,118			SchemaVersion::Unique119		);120	});121}122123#[test]124fn create_fungible_collection_fails_with_large_decimal_numbers() {125	new_test_ext().execute_with(|| {126		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();127		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();128		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();129130		let origin1 = Origin::signed(1);131		assert_noop!(132			TemplateModule::create_collection(133				origin1,134				col_name1.try_into().unwrap(),135				col_desc1.try_into().unwrap(),136				token_prefix1.try_into().unwrap(),137				CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)138			),139			Error::<Test>::CollectionDecimalPointLimitExceeded140		);141	});142}143144#[test]145fn create_nft_item() {146	new_test_ext().execute_with(|| {147		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));148149		let data = default_nft_data();150		create_test_item(collection_id, &data.clone().into());151152		let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();153		assert_eq!(item.const_data, data.const_data.into_inner());154		assert_eq!(item.variable_data, data.variable_data.into_inner());155	});156}157158// Use cases tests region159// #region160#[test]161fn create_nft_multiple_items() {162	new_test_ext().execute_with(|| {163		create_test_collection(&CollectionMode::NFT, CollectionId(1));164165		let origin1 = Origin::signed(1);166167		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];168169		assert_ok!(TemplateModule::create_multiple_items(170			origin1,171			CollectionId(1),172			account(1),173			items_data174				.clone()175				.into_iter()176				.map(|d| { d.into() })177				.collect()178		));179		for (index, data) in items_data.into_iter().enumerate() {180			let item = <pallet_nonfungible::TokenData<Test>>::get((181				CollectionId(1),182				TokenId((index + 1) as u32),183			))184			.unwrap();185			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());186			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());187		}188	});189}190191#[test]192fn create_refungible_item() {193	new_test_ext().execute_with(|| {194		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));195196		let data = default_re_fungible_data();197		create_test_item(collection_id, &data.clone().into());198		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));199		let balance =200			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));201		assert_eq!(item.const_data, data.const_data.into_inner());202		assert_eq!(item.variable_data, data.variable_data.into_inner());203		assert_eq!(balance, 1023);204	});205}206207#[test]208fn create_multiple_refungible_items() {209	new_test_ext().execute_with(|| {210		create_test_collection(&CollectionMode::ReFungible, CollectionId(1));211212		let origin1 = Origin::signed(1);213214		let items_data = vec![215			default_re_fungible_data(),216			default_re_fungible_data(),217			default_re_fungible_data(),218		];219220		assert_ok!(TemplateModule::create_multiple_items(221			origin1,222			CollectionId(1),223			account(1),224			items_data225				.clone()226				.into_iter()227				.map(|d| { d.into() })228				.collect()229		));230		for (index, data) in items_data.into_iter().enumerate() {231			let item = <pallet_refungible::TokenData<Test>>::get((232				CollectionId(1),233				TokenId((index + 1) as u32),234			));235			let balance =236				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));237			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());238			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());239			assert_eq!(balance, 1023);240		}241	});242}243244#[test]245fn create_fungible_item() {246	new_test_ext().execute_with(|| {247		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));248249		let data = default_fungible_data();250		create_test_item(collection_id, &data.into());251252		assert_eq!(253			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),254			5255		);256	});257}258259//#[test]260// fn create_multiple_fungible_items() {261//     new_test_ext().execute_with(|| {262//         default_limits();263264//         create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));265266//         let origin1 = Origin::signed(1);267268//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];269270//         assert_ok!(TemplateModule::create_multiple_items(271//             origin1.clone(),272//             1,273//             1,274//             items_data.clone().into_iter().map(|d| { d.into() }).collect()275//         ));276277//         for (index, _) in items_data.iter().enumerate() {278//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);279//         }280//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);281//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);282//     });283// }284285#[test]286fn transfer_fungible_item() {287	new_test_ext().execute_with(|| {288		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));289290		let origin1 = Origin::signed(1);291		let origin2 = Origin::signed(2);292293		let data = default_fungible_data();294		create_test_item(collection_id, &data.into());295296		assert_eq!(297			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),298			5299		);300301		// change owner scenario302		assert_ok!(TemplateModule::transfer(303			origin1,304			account(2),305			CollectionId(1),306			TokenId(0),307			5308		));309		assert_eq!(310			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),311			0312		);313314		// split item scenario315		assert_ok!(TemplateModule::transfer(316			origin2.clone(),317			account(3),318			CollectionId(1),319			TokenId(0),320			3321		));322323		// split item and new owner has account scenario324		assert_ok!(TemplateModule::transfer(325			origin2,326			account(3),327			CollectionId(1),328			TokenId(0),329			1330		));331		assert_eq!(332			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),333			1334		);335		assert_eq!(336			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),337			4338		);339	});340}341342#[test]343fn transfer_refungible_item() {344	new_test_ext().execute_with(|| {345		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));346347		// Create RFT 1 in 1023 pieces for account 1348		let data = default_re_fungible_data();349		create_test_item(collection_id, &data.clone().into());350		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));351		assert_eq!(item.const_data, data.const_data.into_inner());352		assert_eq!(item.variable_data, data.variable_data.into_inner());353		assert_eq!(354			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),355			1356		);357		assert_eq!(358			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),359			1023360		);361		assert_eq!(362			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),363			true364		);365366		// Account 1 transfers all 1023 pieces of RFT 1 to account 2367		let origin1 = Origin::signed(1);368		let origin2 = Origin::signed(2);369		assert_ok!(TemplateModule::transfer(370			origin1,371			account(2),372			CollectionId(1),373			TokenId(1),374			1023375		));376		assert_eq!(377			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),378			1023379		);380		assert_eq!(381			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),382			0383		);384		assert_eq!(385			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),386			1387		);388		assert_eq!(389			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),390			false391		);392		assert_eq!(393			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),394			true395		);396397		// Account 2 transfers 500 pieces of RFT 1 to account 3398		assert_ok!(TemplateModule::transfer(399			origin2.clone(),400			account(3),401			CollectionId(1),402			TokenId(1),403			500404		));405		assert_eq!(406			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),407			523408		);409		assert_eq!(410			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),411			500412		);413		assert_eq!(414			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),415			1416		);417		assert_eq!(418			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),419			1420		);421		assert_eq!(422			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),423			true424		);425		assert_eq!(426			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),427			true428		);429430		// Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance431		assert_ok!(TemplateModule::transfer(432			origin2,433			account(3),434			CollectionId(1),435			TokenId(1),436			200437		));438		assert_eq!(439			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),440			323441		);442		assert_eq!(443			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),444			700445		);446		assert_eq!(447			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),448			1449		);450		assert_eq!(451			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),452			1453		);454		assert_eq!(455			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),456			true457		);458		assert_eq!(459			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),460			true461		);462	});463}464465#[test]466fn transfer_nft_item() {467	new_test_ext().execute_with(|| {468		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));469470		let data = default_nft_data();471		create_test_item(collection_id, &data.into());472		assert_eq!(473			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),474			1475		);476		assert_eq!(477			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),478			true479		);480481		let origin1 = Origin::signed(1);482		// default scenario483		assert_ok!(TemplateModule::transfer(484			origin1,485			account(2),486			CollectionId(1),487			TokenId(1),488			1489		));490		assert_eq!(491			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),492			0493		);494		assert_eq!(495			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),496			1497		);498		assert_eq!(499			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),500			false501		);502		assert_eq!(503			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),504			true505		);506	});507}508509#[test]510fn transfer_nft_item_wrong_value() {511	new_test_ext().execute_with(|| {512		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));513514		let data = default_nft_data();515		create_test_item(collection_id, &data.into());516		assert_eq!(517			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),518			1519		);520		assert_eq!(521			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),522			true523		);524525		let origin1 = Origin::signed(1);526527		assert_noop!(528			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)529				.map_err(|e| e.error),530			<pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount531		);532	});533}534535#[test]536fn transfer_nft_item_zero_value() {537	new_test_ext().execute_with(|| {538		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));539540		let data = default_nft_data();541		create_test_item(collection_id, &data.into());542		assert_eq!(543			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),544			1545		);546		assert_eq!(547			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),548			true549		);550551		let origin1 = Origin::signed(1);552553		// Transferring 0 amount works on NFT...554		assert_ok!(TemplateModule::transfer(555			origin1,556			account(2),557			CollectionId(1),558			TokenId(1),559			0560		));561		// ... and results in no transfer562		assert_eq!(563			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),564			1565		);566		assert_eq!(567			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),568			true569		);570	});571}572573#[test]574fn nft_approve_and_transfer_from() {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());580581		let origin1 = Origin::signed(1);582		let origin2 = Origin::signed(2);583584		assert_eq!(585			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),586			1587		);588		assert_eq!(589			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),590			true591		);592593		// neg transfer_from594		assert_noop!(595			TemplateModule::transfer_from(596				origin2.clone(),597				account(1),598				account(2),599				CollectionId(1),600				TokenId(1),601				1602			)603			.map_err(|e| e.error),604			CommonError::<Test>::ApprovedValueTooLow605		);606607		// do approve608		assert_ok!(TemplateModule::approve(609			origin1,610			account(2),611			CollectionId(1),612			TokenId(1),613			1614		));615		assert_eq!(616			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),617			account(2)618		);619620		assert_ok!(TemplateModule::transfer_from(621			origin2,622			account(1),623			account(3),624			CollectionId(1),625			TokenId(1),626			1627		));628		assert!(629			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()630		);631	});632}633634#[test]635fn nft_approve_and_transfer_from_allow_list() {636	new_test_ext().execute_with(|| {637		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));638639		let origin1 = Origin::signed(1);640		let origin2 = Origin::signed(2);641642		// Create NFT 1 for account 1643		let data = default_nft_data();644		create_test_item(collection_id, &data.clone().into());645		assert_eq!(646			&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))647				.unwrap()648				.const_data,649			&data.const_data.into_inner()650		);651		assert_eq!(652			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),653			1654		);655		assert_eq!(656			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),657			true658		);659660		// Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list661		assert_ok!(TemplateModule::set_mint_permission(662			origin1.clone(),663			CollectionId(1),664			true665		));666		assert_ok!(TemplateModule::set_public_access_mode(667			origin1.clone(),668			CollectionId(1),669			AccessMode::AllowList670		));671		assert_ok!(TemplateModule::add_to_allow_list(672			origin1.clone(),673			CollectionId(1),674			account(1)675		));676		assert_ok!(TemplateModule::add_to_allow_list(677			origin1.clone(),678			CollectionId(1),679			account(2)680		));681		assert_ok!(TemplateModule::add_to_allow_list(682			origin1.clone(),683			CollectionId(1),684			account(3)685		));686687		// Account 1 approves account 2 for NFT 1688		assert_ok!(TemplateModule::approve(689			origin1.clone(),690			account(2),691			CollectionId(1),692			TokenId(1),693			1694		));695		assert_eq!(696			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),697			account(2)698		);699700		// Account 2 transfers NFT 1 from account 1 to account 3701		assert_ok!(TemplateModule::transfer_from(702			origin2,703			account(1),704			account(3),705			CollectionId(1),706			TokenId(1),707			1708		));709		assert!(710			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()711		);712	});713}714715#[test]716fn refungible_approve_and_transfer_from() {717	new_test_ext().execute_with(|| {718		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));719720		let origin1 = Origin::signed(1);721		let origin2 = Origin::signed(2);722723		// Create RFT 1 in 1023 pieces for account 1724		let data = default_re_fungible_data();725		create_test_item(collection_id, &data.into());726727		assert_eq!(728			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),729			1730		);731		assert_eq!(732			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),733			1023734		);735		assert_eq!(736			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),737			true738		);739740		// Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list741		assert_ok!(TemplateModule::set_mint_permission(742			origin1.clone(),743			CollectionId(1),744			true745		));746		assert_ok!(TemplateModule::set_public_access_mode(747			origin1.clone(),748			CollectionId(1),749			AccessMode::AllowList750		));751		assert_ok!(TemplateModule::add_to_allow_list(752			origin1.clone(),753			CollectionId(1),754			account(1)755		));756		assert_ok!(TemplateModule::add_to_allow_list(757			origin1.clone(),758			CollectionId(1),759			account(2)760		));761		assert_ok!(TemplateModule::add_to_allow_list(762			origin1.clone(),763			CollectionId(1),764			account(3)765		));766767		// Account 1 approves account 2 for 1023 pieces of RFT 1768		assert_ok!(TemplateModule::approve(769			origin1,770			account(2),771			CollectionId(1),772			TokenId(1),773			1023774		));775		assert_eq!(776			<pallet_refungible::Allowance<Test>>::get((777				CollectionId(1),778				TokenId(1),779				account(1),780				account(2)781			)),782			1023783		);784785		// Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3786		assert_ok!(TemplateModule::transfer_from(787			origin2,788			account(1),789			account(3),790			CollectionId(1),791			TokenId(1),792			100793		));794		assert_eq!(795			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),796			1797		);798		assert_eq!(799			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),800			1801		);802		assert_eq!(803			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),804			923805		);806		assert_eq!(807			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),808			100809		);810		assert_eq!(811			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),812			true813		);814		assert_eq!(815			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),816			true817		);818		assert_eq!(819			<pallet_refungible::Allowance<Test>>::get((820				CollectionId(1),821				TokenId(1),822				account(1),823				account(2)824			)),825			923826		);827	});828}829830#[test]831fn fungible_approve_and_transfer_from() {832	new_test_ext().execute_with(|| {833		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));834835		let data = default_fungible_data();836		create_test_item(collection_id, &data.into());837838		let origin1 = Origin::signed(1);839		let origin2 = Origin::signed(2);840841		assert_ok!(TemplateModule::set_mint_permission(842			origin1.clone(),843			CollectionId(1),844			true845		));846		assert_ok!(TemplateModule::set_public_access_mode(847			origin1.clone(),848			CollectionId(1),849			AccessMode::AllowList850		));851		assert_ok!(TemplateModule::add_to_allow_list(852			origin1.clone(),853			CollectionId(1),854			account(1)855		));856		assert_ok!(TemplateModule::add_to_allow_list(857			origin1.clone(),858			CollectionId(1),859			account(2)860		));861		assert_ok!(TemplateModule::add_to_allow_list(862			origin1.clone(),863			CollectionId(1),864			account(3)865		));866867		// do approve868		assert_ok!(TemplateModule::approve(869			origin1.clone(),870			account(2),871			CollectionId(1),872			TokenId(0),873			5874		));875		assert_eq!(876			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),877			5878		);879		assert_ok!(TemplateModule::approve(880			origin1,881			account(3),882			CollectionId(1),883			TokenId(0),884			5885		));886		assert_eq!(887			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),888			5889		);890		assert_eq!(891			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),892			5893		);894895		assert_ok!(TemplateModule::transfer_from(896			origin2.clone(),897			account(1),898			account(3),899			CollectionId(1),900			TokenId(0),901			4902		));903904		assert_eq!(905			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),906			1907		);908909		assert_noop!(910			TemplateModule::transfer_from(911				origin2,912				account(1),913				account(3),914				CollectionId(1),915				TokenId(0),916				4917			)918			.map_err(|e| e.error),919			CommonError::<Test>::ApprovedValueTooLow920		);921	});922}923924#[test]925fn change_collection_owner() {926	new_test_ext().execute_with(|| {927		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));928929		let origin1 = Origin::signed(1);930		assert_ok!(TemplateModule::change_collection_owner(931			origin1,932			collection_id,933			2934		));935		assert_eq!(936			<pallet_common::CollectionById<Test>>::get(collection_id)937				.unwrap()938				.owner,939			2940		);941	});942}943944#[test]945fn destroy_collection() {946	new_test_ext().execute_with(|| {947		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));948949		let origin1 = Origin::signed(1);950		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));951	});952}953954#[test]955fn burn_nft_item() {956	new_test_ext().execute_with(|| {957		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));958959		let origin1 = Origin::signed(1);960961		let data = default_nft_data();962		create_test_item(collection_id, &data.into());963964		// check balance (collection with id = 1, user id = 1)965		assert_eq!(966			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),967			1968		);969970		// burn item971		assert_ok!(TemplateModule::burn_item(972			origin1.clone(),973			collection_id,974			TokenId(1),975			1976		));977		assert_eq!(978			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),979			0980		);981	});982}983984#[test]985fn burn_same_nft_item_twice() {986	new_test_ext().execute_with(|| {987		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));988989		let origin1 = Origin::signed(1);990991		let data = default_nft_data();992		create_test_item(collection_id, &data.into());993994		// check balance (collection with id = 1, user id = 1)995		assert_eq!(996			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),997			1998		);9991000		// burn item1001		assert_ok!(TemplateModule::burn_item(1002			origin1.clone(),1003			collection_id,1004			TokenId(1),1005			11006		));10071008		// burn item again1009		assert_noop!(1010			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1011			CommonError::<Test>::TokenNotFound1012		);10131014		assert_eq!(1015			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1016			01017		);1018	});1019}10201021#[test]1022fn burn_fungible_item() {1023	new_test_ext().execute_with(|| {1024		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10251026		let origin1 = Origin::signed(1);1027		assert_ok!(TemplateModule::add_collection_admin(1028			origin1.clone(),1029			collection_id,1030			account(2)1031		));10321033		let data = default_fungible_data();1034		create_test_item(collection_id, &data.into());10351036		// check balance (collection with id = 1, user id = 1)1037		assert_eq!(1038			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1039			51040		);10411042		// burn item1043		assert_ok!(TemplateModule::burn_item(1044			origin1.clone(),1045			CollectionId(1),1046			TokenId(0),1047			51048		));1049		assert_noop!(1050			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1051			CommonError::<Test>::TokenValueTooLow1052		);10531054		assert_eq!(1055			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1056			01057		);1058	});1059}10601061#[test]1062fn burn_fungible_item_with_token_id() {1063	new_test_ext().execute_with(|| {1064		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10651066		let origin1 = Origin::signed(1);1067		assert_ok!(TemplateModule::add_collection_admin(1068			origin1.clone(),1069			collection_id,1070			account(2)1071		));10721073		let data = default_fungible_data();1074		create_test_item(collection_id, &data.into());10751076		// check balance (collection with id = 1, user id = 1)1077		assert_eq!(1078			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1079			51080		);10811082		// Try to burn item using Token ID1083		assert_noop!(1084			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1085			<pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1086		);1087	});1088}1089#[test]1090fn burn_refungible_item() {1091	new_test_ext().execute_with(|| {1092		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1093		let origin1 = Origin::signed(1);10941095		assert_ok!(TemplateModule::set_mint_permission(1096			origin1.clone(),1097			collection_id,1098			true1099		));1100		assert_ok!(TemplateModule::set_public_access_mode(1101			origin1.clone(),1102			collection_id,1103			AccessMode::AllowList1104		));1105		assert_ok!(TemplateModule::add_to_allow_list(1106			origin1.clone(),1107			collection_id,1108			account(1)1109		));11101111		assert_ok!(TemplateModule::add_collection_admin(1112			origin1.clone(),1113			collection_id,1114			account(2)1115		));11161117		let data = default_re_fungible_data();1118		create_test_item(collection_id, &data.into());11191120		// check balance (collection with id = 1, user id = 2)1121		assert_eq!(1122			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1123			11124		);1125		assert_eq!(1126			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1127			10231128		);11291130		// burn item1131		assert_ok!(TemplateModule::burn_item(1132			origin1.clone(),1133			collection_id,1134			TokenId(1),1135			10231136		));1137		assert_noop!(1138			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1139				.map_err(|e| e.error),1140			CommonError::<Test>::TokenValueTooLow1141		);11421143		assert_eq!(1144			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1145			01146		);1147	});1148}11491150#[test]1151fn add_collection_admin() {1152	new_test_ext().execute_with(|| {1153		let collection1_id =1154			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1155		let origin1 = Origin::signed(1);11561157		// Add collection admins1158		assert_ok!(TemplateModule::add_collection_admin(1159			origin1.clone(),1160			collection1_id,1161			account(2)1162		));1163		assert_ok!(TemplateModule::add_collection_admin(1164			origin1,1165			collection1_id,1166			account(3)1167		));11681169		// Owner is not an admin by default1170		assert_eq!(1171			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1172			false1173		);1174		assert!(<pallet_common::IsAdmin<Test>>::get((1175			CollectionId(1),1176			account(2)1177		)));1178		assert!(<pallet_common::IsAdmin<Test>>::get((1179			CollectionId(1),1180			account(3)1181		)));1182	});1183}11841185#[test]1186fn remove_collection_admin() {1187	new_test_ext().execute_with(|| {1188		let collection1_id =1189			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1190		let origin1 = Origin::signed(1);1191		let origin2 = Origin::signed(2);11921193		// Add collection admins 2 and 31194		assert_ok!(TemplateModule::add_collection_admin(1195			origin1.clone(),1196			collection1_id,1197			account(2)1198		));1199		assert_ok!(TemplateModule::add_collection_admin(1200			origin1,1201			collection1_id,1202			account(3)1203		));12041205		assert!(<pallet_common::IsAdmin<Test>>::get((1206			CollectionId(1),1207			account(2)1208		)));1209		assert!(<pallet_common::IsAdmin<Test>>::get((1210			CollectionId(1),1211			account(3)1212		)));12131214		// remove admin 31215		assert_ok!(TemplateModule::remove_collection_admin(1216			origin2,1217			CollectionId(1),1218			account(3)1219		));12201221		// 2 is still admin, 3 is not an admin anymore1222		assert!(<pallet_common::IsAdmin<Test>>::get((1223			CollectionId(1),1224			account(2)1225		)));1226		assert_eq!(1227			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1228			false1229		);1230	});1231}12321233#[test]1234fn balance_of() {1235	new_test_ext().execute_with(|| {1236		let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1237		let fungible_collection_id =1238			create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1239		let re_fungible_collection_id =1240			create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12411242		// check balance before1243		assert_eq!(1244			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1245			01246		);1247		assert_eq!(1248			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1249			01250		);1251		assert_eq!(1252			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1253			01254		);12551256		let nft_data = default_nft_data();1257		create_test_item(nft_collection_id, &nft_data.into());12581259		let fungible_data = default_fungible_data();1260		create_test_item(fungible_collection_id, &fungible_data.into());12611262		let re_fungible_data = default_re_fungible_data();1263		create_test_item(re_fungible_collection_id, &re_fungible_data.into());12641265		// check balance (collection with id = 1, user id = 1)1266		assert_eq!(1267			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1268			11269		);1270		assert_eq!(1271			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1272			51273		);1274		assert_eq!(1275			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1276			11277		);12781279		assert_eq!(1280			<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1281			true1282		);1283		assert_eq!(1284			<pallet_refungible::Owned<Test>>::get((1285				re_fungible_collection_id,1286				account(1),1287				TokenId(1)1288			)),1289			true1290		);1291	});1292}12931294#[test]1295fn approve() {1296	new_test_ext().execute_with(|| {1297		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));12981299		let data = default_nft_data();1300		create_test_item(collection_id, &data.into());13011302		let origin1 = Origin::signed(1);13031304		// approve1305		assert_ok!(TemplateModule::approve(1306			origin1,1307			account(2),1308			CollectionId(1),1309			TokenId(1),1310			11311		));1312		assert_eq!(1313			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1314			account(2)1315		);1316	});1317}13181319#[test]1320fn transfer_from() {1321	new_test_ext().execute_with(|| {1322		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1323		let origin1 = Origin::signed(1);1324		let origin2 = Origin::signed(2);13251326		let data = default_nft_data();1327		create_test_item(collection_id, &data.into());13281329		// approve1330		assert_ok!(TemplateModule::approve(1331			origin1.clone(),1332			account(2),1333			CollectionId(1),1334			TokenId(1),1335			11336		));1337		assert_eq!(1338			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1339			account(2)1340		);13411342		assert_ok!(TemplateModule::set_mint_permission(1343			origin1.clone(),1344			CollectionId(1),1345			true1346		));1347		assert_ok!(TemplateModule::set_public_access_mode(1348			origin1.clone(),1349			CollectionId(1),1350			AccessMode::AllowList1351		));1352		assert_ok!(TemplateModule::add_to_allow_list(1353			origin1.clone(),1354			CollectionId(1),1355			account(1)1356		));1357		assert_ok!(TemplateModule::add_to_allow_list(1358			origin1.clone(),1359			CollectionId(1),1360			account(2)1361		));1362		assert_ok!(TemplateModule::add_to_allow_list(1363			origin1,1364			CollectionId(1),1365			account(3)1366		));13671368		assert_ok!(TemplateModule::transfer_from(1369			origin2,1370			account(1),1371			account(2),1372			CollectionId(1),1373			TokenId(1),1374			11375		));13761377		// after transfer1378		assert_eq!(1379			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1380			01381		);1382		assert_eq!(1383			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1384			11385		);1386	});1387}13881389// #endregion13901391// Coverage tests region1392// #region13931394#[test]1395fn owner_can_add_address_to_allow_list() {1396	new_test_ext().execute_with(|| {1397		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13981399		let origin1 = Origin::signed(1);1400		assert_ok!(TemplateModule::add_to_allow_list(1401			origin1,1402			collection_id,1403			account(2)1404		));1405		assert!(<pallet_common::Allowlist<Test>>::get((1406			collection_id,1407			account(2)1408		)));1409	});1410}14111412#[test]1413fn admin_can_add_address_to_allow_list() {1414	new_test_ext().execute_with(|| {1415		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1416		let origin1 = Origin::signed(1);1417		let origin2 = Origin::signed(2);14181419		assert_ok!(TemplateModule::add_collection_admin(1420			origin1,1421			collection_id,1422			account(2)1423		));1424		assert_ok!(TemplateModule::add_to_allow_list(1425			origin2,1426			collection_id,1427			account(3)1428		));1429		assert!(<pallet_common::Allowlist<Test>>::get((1430			collection_id,1431			account(3)1432		)));1433	});1434}14351436#[test]1437fn nonprivileged_user_cannot_add_address_to_allow_list() {1438	new_test_ext().execute_with(|| {1439		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14401441		let origin2 = Origin::signed(2);1442		assert_noop!(1443			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1444			CommonError::<Test>::NoPermission1445		);1446	});1447}14481449#[test]1450fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1451	new_test_ext().execute_with(|| {1452		let origin1 = Origin::signed(1);14531454		assert_noop!(1455			TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1456			CommonError::<Test>::CollectionNotFound1457		);1458	});1459}14601461#[test]1462fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1463	new_test_ext().execute_with(|| {1464		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14651466		let origin1 = Origin::signed(1);1467		assert_ok!(TemplateModule::destroy_collection(1468			origin1.clone(),1469			collection_id1470		));1471		assert_noop!(1472			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1473			CommonError::<Test>::CollectionNotFound1474		);1475	});1476}14771478// If address is already added to allow list, nothing happens1479#[test]1480fn address_is_already_added_to_allow_list() {1481	new_test_ext().execute_with(|| {1482		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1483		let origin1 = Origin::signed(1);14841485		assert_ok!(TemplateModule::add_to_allow_list(1486			origin1.clone(),1487			collection_id,1488			account(2)1489		));1490		assert_ok!(TemplateModule::add_to_allow_list(1491			origin1,1492			collection_id,1493			account(2)1494		));1495		assert!(<pallet_common::Allowlist<Test>>::get((1496			collection_id,1497			account(2)1498		)));1499	});1500}15011502#[test]1503fn owner_can_remove_address_from_allow_list() {1504	new_test_ext().execute_with(|| {1505		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15061507		let origin1 = Origin::signed(1);1508		assert_ok!(TemplateModule::add_to_allow_list(1509			origin1.clone(),1510			collection_id,1511			account(2)1512		));1513		assert_ok!(TemplateModule::remove_from_allow_list(1514			origin1,1515			collection_id,1516			account(2)1517		));1518		assert_eq!(1519			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1520			false1521		);1522	});1523}15241525#[test]1526fn admin_can_remove_address_from_allow_list() {1527	new_test_ext().execute_with(|| {1528		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1529		let origin1 = Origin::signed(1);1530		let origin2 = Origin::signed(2);15311532		// Owner adds admin1533		assert_ok!(TemplateModule::add_collection_admin(1534			origin1.clone(),1535			collection_id,1536			account(2)1537		));15381539		// Owner adds address 3 to allow list1540		assert_ok!(TemplateModule::add_to_allow_list(1541			origin1,1542			collection_id,1543			account(3)1544		));15451546		// Admin removes address 3 from allow list1547		assert_ok!(TemplateModule::remove_from_allow_list(1548			origin2,1549			collection_id,1550			account(3)1551		));1552		assert_eq!(1553			<pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1554			false1555		);1556	});1557}15581559#[test]1560fn nonprivileged_user_cannot_remove_address_from_allow_list() {1561	new_test_ext().execute_with(|| {1562		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1563		let origin1 = Origin::signed(1);1564		let origin2 = Origin::signed(2);15651566		assert_ok!(TemplateModule::add_to_allow_list(1567			origin1,1568			collection_id,1569			account(2)1570		));1571		assert_noop!(1572			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1573			CommonError::<Test>::NoPermission1574		);1575		assert!(<pallet_common::Allowlist<Test>>::get((1576			collection_id,1577			account(2)1578		)));1579	});1580}15811582#[test]1583fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1584	new_test_ext().execute_with(|| {1585		let origin1 = Origin::signed(1);15861587		assert_noop!(1588			TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1589			CommonError::<Test>::CollectionNotFound1590		);1591	});1592}15931594#[test]1595fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1596	new_test_ext().execute_with(|| {1597		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1598		let origin1 = Origin::signed(1);1599		let origin2 = Origin::signed(2);16001601		// Add account 2 to allow list1602		assert_ok!(TemplateModule::add_to_allow_list(1603			origin1.clone(),1604			collection_id,1605			account(2)1606		));16071608		// Account 2 is in collection allow-list1609		assert!(<pallet_common::Allowlist<Test>>::get((1610			collection_id,1611			account(2)1612		)));16131614		// Destroy collection1615		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16161617		// Attempt to remove account 2 from collection allow-list => error1618		assert_noop!(1619			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1620			CommonError::<Test>::CollectionNotFound1621		);16221623		// Account 2 is not found in collection allow-list anyway1624		assert_eq!(1625			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1626			false1627		);1628	});1629}16301631// If address is already removed from allow list, nothing happens1632#[test]1633fn address_is_already_removed_from_allow_list() {1634	new_test_ext().execute_with(|| {1635		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1636		let origin1 = Origin::signed(1);16371638		assert_ok!(TemplateModule::add_to_allow_list(1639			origin1.clone(),1640			collection_id,1641			account(2)1642		));1643		assert_ok!(TemplateModule::remove_from_allow_list(1644			origin1.clone(),1645			collection_id,1646			account(2)1647		));1648		assert_eq!(1649			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1650			false1651		);1652		assert_ok!(TemplateModule::remove_from_allow_list(1653			origin1,1654			collection_id,1655			account(2)1656		));1657		assert_eq!(1658			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1659			false1660		);1661	});1662}16631664// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1665#[test]1666fn allow_list_test_1() {1667	new_test_ext().execute_with(|| {1668		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));16691670		let origin1 = Origin::signed(1);16711672		let data = default_nft_data();1673		create_test_item(collection_id, &data.into());16741675		assert_ok!(TemplateModule::set_public_access_mode(1676			origin1.clone(),1677			collection_id,1678			AccessMode::AllowList1679		));1680		assert_ok!(TemplateModule::add_to_allow_list(1681			origin1.clone(),1682			collection_id,1683			account(2)1684		));16851686		assert_noop!(1687			TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1688				.map_err(|e| e.error),1689			CommonError::<Test>::AddressNotInAllowlist1690		);1691	});1692}16931694#[test]1695fn allow_list_test_2() {1696	new_test_ext().execute_with(|| {1697		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1698		let origin1 = Origin::signed(1);16991700		let data = default_nft_data();1701		create_test_item(collection_id, &data.into());17021703		assert_ok!(TemplateModule::set_public_access_mode(1704			origin1.clone(),1705			collection_id,1706			AccessMode::AllowList1707		));1708		assert_ok!(TemplateModule::add_to_allow_list(1709			origin1.clone(),1710			collection_id,1711			account(1)1712		));1713		assert_ok!(TemplateModule::add_to_allow_list(1714			origin1.clone(),1715			collection_id,1716			account(2)1717		));17181719		// do approve1720		assert_ok!(TemplateModule::approve(1721			origin1.clone(),1722			account(1),1723			collection_id,1724			TokenId(1),1725			11726		));1727		assert_eq!(1728			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1729			account(1)1730		);17311732		assert_ok!(TemplateModule::remove_from_allow_list(1733			origin1.clone(),1734			collection_id,1735			account(1)1736		));17371738		assert_noop!(1739			TemplateModule::transfer_from(1740				origin1,1741				account(1),1742				account(3),1743				CollectionId(1),1744				TokenId(1),1745				11746			)1747			.map_err(|e| e.error),1748			CommonError::<Test>::AddressNotInAllowlist1749		);1750	});1751}17521753// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1754#[test]1755fn allow_list_test_3() {1756	new_test_ext().execute_with(|| {1757		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17581759		let origin1 = Origin::signed(1);17601761		let data = default_nft_data();1762		create_test_item(collection_id, &data.into());17631764		assert_ok!(TemplateModule::set_public_access_mode(1765			origin1.clone(),1766			collection_id,1767			AccessMode::AllowList1768		));1769		assert_ok!(TemplateModule::add_to_allow_list(1770			origin1.clone(),1771			collection_id,1772			account(1)1773		));17741775		assert_noop!(1776			TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1777				.map_err(|e| e.error),1778			CommonError::<Test>::AddressNotInAllowlist1779		);1780	});1781}17821783#[test]1784fn allow_list_test_4() {1785	new_test_ext().execute_with(|| {1786		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17871788		let origin1 = Origin::signed(1);17891790		let data = default_nft_data();1791		create_test_item(collection_id, &data.into());17921793		assert_ok!(TemplateModule::set_public_access_mode(1794			origin1.clone(),1795			collection_id,1796			AccessMode::AllowList1797		));1798		assert_ok!(TemplateModule::add_to_allow_list(1799			origin1.clone(),1800			collection_id,1801			account(1)1802		));1803		assert_ok!(TemplateModule::add_to_allow_list(1804			origin1.clone(),1805			collection_id,1806			account(2)1807		));18081809		// do approve1810		assert_ok!(TemplateModule::approve(1811			origin1.clone(),1812			account(1),1813			collection_id,1814			TokenId(1),1815			11816		));1817		assert_eq!(1818			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1819			account(1)1820		);18211822		assert_ok!(TemplateModule::remove_from_allow_list(1823			origin1.clone(),1824			collection_id,1825			account(2)1826		));18271828		assert_noop!(1829			TemplateModule::transfer_from(1830				origin1,1831				account(1),1832				account(3),1833				collection_id,1834				TokenId(1),1835				11836			)1837			.map_err(|e| e.error),1838			CommonError::<Test>::AddressNotInAllowlist1839		);1840	});1841}18421843// 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)1844#[test]1845fn allow_list_test_5() {1846	new_test_ext().execute_with(|| {1847		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18481849		let origin1 = Origin::signed(1);18501851		let data = default_nft_data();1852		create_test_item(collection_id, &data.into());18531854		assert_ok!(TemplateModule::set_public_access_mode(1855			origin1.clone(),1856			collection_id,1857			AccessMode::AllowList1858		));1859		assert_noop!(1860			TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1861				.map_err(|e| e.error),1862			CommonError::<Test>::AddressNotInAllowlist1863		);1864	});1865}18661867// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1868#[test]1869fn allow_list_test_6() {1870	new_test_ext().execute_with(|| {1871		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18721873		let origin1 = Origin::signed(1);18741875		let data = default_nft_data();1876		create_test_item(collection_id, &data.into());18771878		assert_ok!(TemplateModule::set_public_access_mode(1879			origin1.clone(),1880			collection_id,1881			AccessMode::AllowList1882		));18831884		// do approve1885		assert_noop!(1886			TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1887				.map_err(|e| e.error),1888			CommonError::<Test>::AddressNotInAllowlist1889		);1890	});1891}18921893// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1894//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1895#[test]1896fn allow_list_test_7() {1897	new_test_ext().execute_with(|| {1898		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18991900		let data = default_nft_data();1901		create_test_item(collection_id, &data.into());19021903		let origin1 = Origin::signed(1);19041905		assert_ok!(TemplateModule::set_public_access_mode(1906			origin1.clone(),1907			collection_id,1908			AccessMode::AllowList1909		));1910		assert_ok!(TemplateModule::add_to_allow_list(1911			origin1.clone(),1912			collection_id,1913			account(1)1914		));1915		assert_ok!(TemplateModule::add_to_allow_list(1916			origin1.clone(),1917			collection_id,1918			account(2)1919		));19201921		assert_ok!(TemplateModule::transfer(1922			origin1,1923			account(2),1924			CollectionId(1),1925			TokenId(1),1926			11927		));1928	});1929}19301931#[test]1932fn allow_list_test_8() {1933	new_test_ext().execute_with(|| {1934		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19351936		// Create NFT for account 11937		let data = default_nft_data();1938		create_test_item(collection_id, &data.into());19391940		let origin1 = Origin::signed(1);19411942		// Toggle Allow List mode and add accounts 1 and 21943		assert_ok!(TemplateModule::set_public_access_mode(1944			origin1.clone(),1945			collection_id,1946			AccessMode::AllowList1947		));1948		assert_ok!(TemplateModule::add_to_allow_list(1949			origin1.clone(),1950			collection_id,1951			account(1)1952		));1953		assert_ok!(TemplateModule::add_to_allow_list(1954			origin1.clone(),1955			collection_id,1956			account(2)1957		));19581959		// Sself-approve account 1 for NFT 11960		assert_ok!(TemplateModule::approve(1961			origin1.clone(),1962			account(1),1963			CollectionId(1),1964			TokenId(1),1965			11966		));1967		assert_eq!(1968			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1969			account(1)1970		);19711972		// Transfer from 1 to 21973		assert_ok!(TemplateModule::transfer_from(1974			origin1,1975			account(1),1976			account(2),1977			CollectionId(1),1978			TokenId(1),1979			11980		));1981	});1982}19831984// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.1985#[test]1986fn allow_list_test_9() {1987	new_test_ext().execute_with(|| {1988		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1989		let origin1 = Origin::signed(1);19901991		assert_ok!(TemplateModule::set_public_access_mode(1992			origin1.clone(),1993			collection_id,1994			AccessMode::AllowList1995		));1996		assert_ok!(TemplateModule::set_mint_permission(1997			origin1,1998			collection_id,1999			false2000		));20012002		let data = default_nft_data();2003		create_test_item(collection_id, &data.into());2004	});2005}20062007// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2008#[test]2009fn allow_list_test_10() {2010	new_test_ext().execute_with(|| {2011		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20122013		let origin1 = Origin::signed(1);2014		let origin2 = Origin::signed(2);20152016		assert_ok!(TemplateModule::set_public_access_mode(2017			origin1.clone(),2018			collection_id,2019			AccessMode::AllowList2020		));2021		assert_ok!(TemplateModule::set_mint_permission(2022			origin1.clone(),2023			collection_id,2024			false2025		));20262027		assert_ok!(TemplateModule::add_collection_admin(2028			origin1,2029			collection_id,2030			account(2)2031		));20322033		assert_ok!(TemplateModule::create_item(2034			origin2,2035			collection_id,2036			account(2),2037			default_nft_data().into()2038		));2039	});2040}20412042// 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.2043#[test]2044fn allow_list_test_11() {2045	new_test_ext().execute_with(|| {2046		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20472048		let origin1 = Origin::signed(1);2049		let origin2 = Origin::signed(2);20502051		assert_ok!(TemplateModule::set_public_access_mode(2052			origin1.clone(),2053			collection_id,2054			AccessMode::AllowList2055		));2056		assert_ok!(TemplateModule::set_mint_permission(2057			origin1.clone(),2058			collection_id,2059			false2060		));2061		assert_ok!(TemplateModule::add_to_allow_list(2062			origin1,2063			collection_id,2064			account(2)2065		));20662067		assert_noop!(2068			TemplateModule::create_item(2069				origin2,2070				CollectionId(1),2071				account(2),2072				default_nft_data().into()2073			)2074			.map_err(|e| e.error),2075			CommonError::<Test>::PublicMintingNotAllowed2076		);2077	});2078}20792080// 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.2081#[test]2082fn allow_list_test_12() {2083	new_test_ext().execute_with(|| {2084		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20852086		let origin1 = Origin::signed(1);2087		let origin2 = Origin::signed(2);20882089		assert_ok!(TemplateModule::set_public_access_mode(2090			origin1.clone(),2091			collection_id,2092			AccessMode::AllowList2093		));2094		assert_ok!(TemplateModule::set_mint_permission(2095			origin1,2096			collection_id,2097			false2098		));20992100		assert_noop!(2101			TemplateModule::create_item(2102				origin2,2103				CollectionId(1),2104				account(2),2105				default_nft_data().into()2106			)2107			.map_err(|e| e.error),2108			CommonError::<Test>::PublicMintingNotAllowed2109		);2110	});2111}21122113// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2114#[test]2115fn allow_list_test_13() {2116	new_test_ext().execute_with(|| {2117		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21182119		let origin1 = Origin::signed(1);21202121		assert_ok!(TemplateModule::set_public_access_mode(2122			origin1.clone(),2123			collection_id,2124			AccessMode::AllowList2125		));2126		assert_ok!(TemplateModule::set_mint_permission(2127			origin1,2128			collection_id,2129			true2130		));21312132		let data = default_nft_data();2133		create_test_item(collection_id, &data.into());2134	});2135}21362137// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2138#[test]2139fn allow_list_test_14() {2140	new_test_ext().execute_with(|| {2141		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21422143		let origin1 = Origin::signed(1);2144		let origin2 = Origin::signed(2);21452146		assert_ok!(TemplateModule::set_public_access_mode(2147			origin1.clone(),2148			collection_id,2149			AccessMode::AllowList2150		));2151		assert_ok!(TemplateModule::set_mint_permission(2152			origin1.clone(),2153			collection_id,2154			true2155		));21562157		assert_ok!(TemplateModule::add_collection_admin(2158			origin1,2159			collection_id,2160			account(2)2161		));21622163		assert_ok!(TemplateModule::create_item(2164			origin2,2165			collection_id,2166			account(2),2167			default_nft_data().into()2168		));2169	});2170}21712172// 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.2173#[test]2174fn allow_list_test_15() {2175	new_test_ext().execute_with(|| {2176		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21772178		let origin1 = Origin::signed(1);2179		let origin2 = Origin::signed(2);21802181		assert_ok!(TemplateModule::set_public_access_mode(2182			origin1.clone(),2183			collection_id,2184			AccessMode::AllowList2185		));2186		assert_ok!(TemplateModule::set_mint_permission(2187			origin1,2188			collection_id,2189			true2190		));21912192		assert_noop!(2193			TemplateModule::create_item(2194				origin2,2195				collection_id,2196				account(2),2197				default_nft_data().into()2198			)2199			.map_err(|e| e.error),2200			CommonError::<Test>::AddressNotInAllowlist2201		);2202	});2203}22042205// 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.2206#[test]2207fn allow_list_test_16() {2208	new_test_ext().execute_with(|| {2209		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22102211		let origin1 = Origin::signed(1);2212		let origin2 = Origin::signed(2);22132214		assert_ok!(TemplateModule::set_public_access_mode(2215			origin1.clone(),2216			collection_id,2217			AccessMode::AllowList2218		));2219		assert_ok!(TemplateModule::set_mint_permission(2220			origin1.clone(),2221			collection_id,2222			true2223		));2224		assert_ok!(TemplateModule::add_to_allow_list(2225			origin1,2226			collection_id,2227			account(2)2228		));22292230		assert_ok!(TemplateModule::create_item(2231			origin2,2232			collection_id,2233			account(2),2234			default_nft_data().into()2235		));2236	});2237}22382239// Total number of collections. Positive test2240#[test]2241fn total_number_collections_bound() {2242	new_test_ext().execute_with(|| {2243		create_test_collection(&CollectionMode::NFT, CollectionId(1));2244	});2245}22462247#[test]2248fn create_max_collections() {2249	new_test_ext().execute_with(|| {2250		for i in 1..COLLECTION_NUMBER_LIMIT {2251			create_test_collection(&CollectionMode::NFT, CollectionId(i));2252		}2253	});2254}22552256// Total number of collections. Negative test2257#[test]2258fn total_number_collections_bound_neg() {2259	new_test_ext().execute_with(|| {2260		let origin1 = Origin::signed(1);22612262		for i in 1..=COLLECTION_NUMBER_LIMIT {2263			create_test_collection(&CollectionMode::NFT, CollectionId(i));2264		}22652266		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2267		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2268		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();22692270		// 11-th collection in chain. Expects error2271		assert_noop!(2272			TemplateModule::create_collection(2273				origin1,2274				col_name1.try_into().unwrap(),2275				col_desc1.try_into().unwrap(),2276				token_prefix1.try_into().unwrap(),2277				CollectionMode::NFT2278			),2279			CommonError::<Test>::TotalCollectionsLimitExceeded2280		);2281	});2282}22832284// Owned tokens by a single address. Positive test2285#[test]2286fn owned_tokens_bound() {2287	new_test_ext().execute_with(|| {2288		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22892290		let data = default_nft_data();2291		create_test_item(collection_id, &data.clone().into());2292		create_test_item(collection_id, &data.into());2293	});2294}22952296// Owned tokens by a single address. Negotive test2297#[test]2298fn owned_tokens_bound_neg() {2299	new_test_ext().execute_with(|| {2300		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23012302		let origin1 = Origin::signed(1);23032304		for _ in 1..=MAX_TOKEN_OWNERSHIP {2305			let data = default_nft_data();2306			create_test_item(collection_id, &data.clone().into());2307		}23082309		let data = default_nft_data();2310		assert_noop!(2311			TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2312				.map_err(|e| e.error),2313			CommonError::<Test>::AccountTokenLimitExceeded2314		);2315	});2316}23172318// Number of collection admins. Positive test2319#[test]2320fn collection_admins_bound() {2321	new_test_ext().execute_with(|| {2322		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23232324		let origin1 = Origin::signed(1);23252326		assert_ok!(TemplateModule::add_collection_admin(2327			origin1.clone(),2328			collection_id,2329			account(2)2330		));2331		assert_ok!(TemplateModule::add_collection_admin(2332			origin1,2333			collection_id,2334			account(3)2335		));2336	});2337}23382339// Number of collection admins. Negotive test2340#[test]2341fn collection_admins_bound_neg() {2342	new_test_ext().execute_with(|| {2343		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23442345		let origin1 = Origin::signed(1);23462347		for i in 0..COLLECTION_ADMINS_LIMIT {2348			assert_ok!(TemplateModule::add_collection_admin(2349				origin1.clone(),2350				collection_id,2351				account((2 + i).into())2352			));2353		}2354		assert_noop!(2355			TemplateModule::add_collection_admin(2356				origin1,2357				collection_id,2358				account((3 + COLLECTION_ADMINS_LIMIT).into())2359			),2360			CommonError::<Test>::CollectionAdminCountExceeded2361		);2362	});2363}2364// #endregion23652366#[test]2367fn set_const_on_chain_schema() {2368	new_test_ext().execute_with(|| {2369		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23702371		let origin1 = Origin::signed(1);2372		assert_ok!(TemplateModule::set_const_on_chain_schema(2373			origin1,2374			collection_id,2375			b"test const on chain schema".to_vec().try_into().unwrap()2376		));23772378		assert_eq!(2379			<pallet_common::CollectionById<Test>>::get(collection_id)2380				.unwrap()2381				.const_on_chain_schema,2382			b"test const on chain schema".to_vec()2383		);2384		assert_eq!(2385			<pallet_common::CollectionById<Test>>::get(collection_id)2386				.unwrap()2387				.variable_on_chain_schema,2388			b"".to_vec()2389		);2390	});2391}23922393#[test]2394fn set_variable_on_chain_schema() {2395	new_test_ext().execute_with(|| {2396		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23972398		let origin1 = Origin::signed(1);2399		assert_ok!(TemplateModule::set_variable_on_chain_schema(2400			origin1,2401			collection_id,2402			b"test variable on chain schema"2403				.to_vec()2404				.try_into()2405				.unwrap()2406		));24072408		assert_eq!(2409			<pallet_common::CollectionById<Test>>::get(collection_id)2410				.unwrap()2411				.const_on_chain_schema,2412			b"".to_vec()2413		);2414		assert_eq!(2415			<pallet_common::CollectionById<Test>>::get(collection_id)2416				.unwrap()2417				.variable_on_chain_schema,2418			b"test variable on chain schema".to_vec()2419		);2420	});2421}24222423#[test]2424fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2425	new_test_ext().execute_with(|| {2426		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24272428		let origin1 = Origin::signed(1);24292430		let data = default_nft_data();2431		create_test_item(CollectionId(1), &data.into());24322433		let variable_data = b"test data".to_vec();2434		assert_ok!(TemplateModule::set_variable_meta_data(2435			origin1,2436			collection_id,2437			TokenId(1),2438			variable_data.clone().try_into().unwrap()2439		));24402441		assert_eq!(2442			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2443				.unwrap()2444				.variable_data,2445			variable_data2446		);2447	});2448}24492450#[test]2451fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2452	new_test_ext().execute_with(|| {2453		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));24542455		let origin1 = Origin::signed(1);24562457		let data = default_re_fungible_data();2458		create_test_item(collection_id, &data.into());24592460		let variable_data = b"test data".to_vec();2461		assert_ok!(TemplateModule::set_variable_meta_data(2462			origin1,2463			collection_id,2464			TokenId(1),2465			variable_data.clone().try_into().unwrap()2466		));24672468		assert_eq!(2469			<pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2470			variable_data2471		);2472	});2473}24742475#[test]2476fn set_variable_meta_data_on_fungible_token_fails() {2477	new_test_ext().execute_with(|| {2478		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));24792480		let origin1 = Origin::signed(1);24812482		let data = default_fungible_data();2483		create_test_item(collection_id, &data.into());24842485		let variable_data = b"test data".to_vec();2486		assert_noop!(2487			TemplateModule::set_variable_meta_data(2488				origin1,2489				collection_id,2490				TokenId(0),2491				variable_data.try_into().unwrap()2492			)2493			.map_err(|e| e.error),2494			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2495		);2496	});2497}24982499#[test]2500fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2501	new_test_ext().execute_with(|| {2502		//default_limits();25032504		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25052506		let origin1 = Origin::signed(1);25072508		let data = default_nft_data();2509		create_test_item(collection_id, &data.into());25102511		assert_ok!(TemplateModule::set_meta_update_permission_flag(2512			origin1.clone(),2513			collection_id,2514			MetaUpdatePermission::ItemOwner,2515		));25162517		let variable_data = b"ten chars.".to_vec();2518		assert_ok!(TemplateModule::set_variable_meta_data(2519			origin1,2520			collection_id,2521			TokenId(1),2522			variable_data.clone().try_into().unwrap()2523		));25242525		assert_eq!(2526			<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2527				.unwrap()2528				.variable_data,2529			variable_data2530		);2531	});2532}25332534#[test]2535fn collection_transfer_flag_works() {2536	new_test_ext().execute_with(|| {2537		let origin1 = Origin::signed(1);25382539		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2540		assert_ok!(TemplateModule::set_transfers_enabled_flag(2541			origin1,2542			collection_id,2543			true2544		));25452546		let data = default_nft_data();2547		create_test_item(collection_id, &data.into());2548		assert_eq!(2549			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2550			12551		);2552		assert_eq!(2553			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2554			true2555		);25562557		let origin1 = Origin::signed(1);25582559		// default scenario2560		assert_ok!(TemplateModule::transfer(2561			origin1,2562			account(2),2563			collection_id,2564			TokenId(1),2565			12566		));2567		assert_eq!(2568			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2569			false2570		);2571		assert_eq!(2572			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2573			true2574		);2575		assert_eq!(2576			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2577			02578		);2579		assert_eq!(2580			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2581			12582		);2583	});2584}25852586#[test]2587fn set_variable_meta_data_on_nft_with_admin_flag() {2588	new_test_ext().execute_with(|| {2589		// default_limits();25902591		let collection_id =2592			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));25932594		let origin1 = Origin::signed(1);2595		let origin2 = Origin::signed(2);25962597		assert_ok!(TemplateModule::set_mint_permission(2598			origin2.clone(),2599			collection_id,2600			true2601		));2602		assert_ok!(TemplateModule::add_to_allow_list(2603			origin2.clone(),2604			collection_id,2605			account(1)2606		));26072608		assert_ok!(TemplateModule::add_collection_admin(2609			origin2.clone(),2610			collection_id,2611			account(1)2612		));26132614		let data = default_nft_data();2615		create_test_item(collection_id, &data.into());26162617		assert_ok!(TemplateModule::set_meta_update_permission_flag(2618			origin2.clone(),2619			collection_id,2620			MetaUpdatePermission::Admin,2621		));26222623		let variable_data = b"test.".to_vec();2624		assert_ok!(TemplateModule::set_variable_meta_data(2625			origin1,2626			collection_id,2627			TokenId(1),2628			variable_data.clone().try_into().unwrap()2629		));26302631		assert_eq!(2632			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2633				.unwrap()2634				.variable_data,2635			variable_data2636		);2637	});2638}26392640#[test]2641fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2642	new_test_ext().execute_with(|| {2643		// default_limits();26442645		let collection_id =2646			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26472648		let origin1 = Origin::signed(1);2649		let origin2 = Origin::signed(2);26502651		assert_ok!(TemplateModule::set_mint_permission(2652			origin2.clone(),2653			collection_id,2654			true2655		));2656		assert_ok!(TemplateModule::add_to_allow_list(2657			origin2.clone(),2658			collection_id,2659			account(1)2660		));26612662		let data = default_nft_data();2663		create_test_item(collection_id, &data.into());26642665		assert_ok!(TemplateModule::set_meta_update_permission_flag(2666			origin2.clone(),2667			collection_id,2668			MetaUpdatePermission::Admin,2669		));26702671		let variable_data = b"test.".to_vec();2672		assert_noop!(2673			TemplateModule::set_variable_meta_data(2674				origin1,2675				collection_id,2676				TokenId(1),2677				variable_data.try_into().unwrap()2678			)2679			.map_err(|e| e.error),2680			CommonError::<Test>::NoPermission2681		);2682	});2683}26842685#[test]2686fn set_variable_meta_flag_after_freeze() {2687	new_test_ext().execute_with(|| {2688		// default_limits();26892690		let collection_id =2691			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26922693		let origin2 = Origin::signed(2);26942695		assert_ok!(TemplateModule::set_meta_update_permission_flag(2696			origin2.clone(),2697			collection_id,2698			MetaUpdatePermission::None,2699		));2700		assert_noop!(2701			TemplateModule::set_meta_update_permission_flag(2702				origin2.clone(),2703				collection_id,2704				MetaUpdatePermission::Admin2705			),2706			CommonError::<Test>::MetadataFlagFrozen2707		);2708	});2709}27102711#[test]2712fn set_variable_meta_data_on_nft_with_none_flag_neg() {2713	new_test_ext().execute_with(|| {2714		// default_limits();27152716		let collection_id =2717			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2718		let origin1 = Origin::signed(1);27192720		let data = default_nft_data();2721		create_test_item(collection_id, &data.into());27222723		assert_ok!(TemplateModule::set_meta_update_permission_flag(2724			origin1.clone(),2725			collection_id,2726			MetaUpdatePermission::None,2727		));27282729		let variable_data = b"test.".to_vec();2730		assert_noop!(2731			TemplateModule::set_variable_meta_data(2732				origin1.clone(),2733				collection_id,2734				TokenId(1),2735				variable_data.try_into().unwrap()2736			)2737			.map_err(|e| e.error),2738			CommonError::<Test>::NoPermission2739		);2740	});2741}27422743#[test]2744fn collection_transfer_flag_works_neg() {2745	new_test_ext().execute_with(|| {2746		let origin1 = Origin::signed(1);27472748		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2749		assert_ok!(TemplateModule::set_transfers_enabled_flag(2750			origin1,2751			collection_id,2752			false2753		));27542755		let data = default_nft_data();2756		create_test_item(collection_id, &data.into());2757		assert_eq!(2758			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2759			12760		);2761		assert_eq!(2762			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2763			true2764		);27652766		let origin1 = Origin::signed(1);27672768		// default scenario2769		assert_noop!(2770			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2771				.map_err(|e| e.error),2772			CommonError::<Test>::TransferNotAllowed2773		);2774		assert_eq!(2775			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2776			12777		);2778		assert_eq!(2779			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2780			02781		);2782		assert_eq!(2783			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2784			true2785		);2786		assert_eq!(2787			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2788			false2789		);2790	});2791}
after · pallets/unique/src/tests.rs
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode};5use up_data_structs::{6	COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,7	CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,8	TokenId, MAX_TOKEN_OWNERSHIP,9};10use frame_support::{assert_noop, assert_ok, assert_err};11use sp_std::convert::TryInto;12use pallet_balances;1314fn add_balance(user: u64, value: u64) {15	const RICH_USER: u64 = 999;16	assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), RICH_USER, value, 0));17	assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(Origin::root(), RICH_USER, user, value));18}1920fn default_nft_data() -> CreateNftData {21	CreateNftData {22		const_data: vec![1, 2, 3].try_into().unwrap(),23		variable_data: vec![3, 2, 1].try_into().unwrap(),24	}25}2627fn default_fungible_data() -> CreateFungibleData {28	CreateFungibleData { value: 5 }29}3031fn default_re_fungible_data() -> CreateReFungibleData {32	CreateReFungibleData {33		const_data: vec![1, 2, 3].try_into().unwrap(),34		variable_data: vec![3, 2, 1].try_into().unwrap(),35		pieces: 1023,36	}37}3839fn create_test_collection_for_owner(40	mode: &CollectionMode,41	owner: u64,42	id: CollectionId,43) -> CollectionId {44	add_balance(owner, CollectionCreationPrice::get() as u64 + 1);4546	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();47	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();48	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();4950	let origin1 = Origin::signed(owner);51	assert_ok!(TemplateModule::create_collection(52		origin1,53		col_name1.try_into().unwrap(),54		col_desc1.try_into().unwrap(),55		token_prefix1.try_into().unwrap(),56		mode.clone()57	));5859	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();60	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();61	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();62	assert_eq!(63		<pallet_common::CollectionById<Test>>::get(id)64			.unwrap()65			.owner,66		owner67	);68	assert_eq!(69		<pallet_common::CollectionById<Test>>::get(id).unwrap().name,70		saved_col_name71	);72	assert_eq!(73		<pallet_common::CollectionById<Test>>::get(id).unwrap().mode,74		*mode75	);76	assert_eq!(77		<pallet_common::CollectionById<Test>>::get(id)78			.unwrap()79			.description,80		saved_description81	);82	assert_eq!(83		<pallet_common::CollectionById<Test>>::get(id)84			.unwrap()85			.token_prefix,86		saved_prefix87	);88	id89}9091fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {92	create_test_collection_for_owner(&mode, 1, id)93}9495fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {96	let origin1 = Origin::signed(1);97	assert_ok!(TemplateModule::create_item(98		origin1,99		collection_id,100		account(1),101		data.clone()102	));103}104105fn account(sub: u64) -> TestCrossAccountId {106	TestCrossAccountId::from_sub(sub)107}108109// Use cases tests region110// #region111112#[test]113fn set_version_schema() {114	new_test_ext().execute_with(|| {115		let origin1 = Origin::signed(1);116		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));117118		assert_ok!(TemplateModule::set_schema_version(119			origin1,120			collection_id,121			SchemaVersion::Unique122		));123		assert_eq!(124			<pallet_common::CollectionById<Test>>::get(collection_id)125				.unwrap()126				.schema_version,127			SchemaVersion::Unique128		);129	});130}131132#[test]133fn check_not_sufficient_founds() {134	new_test_ext().execute_with(|| {135		let acc: u64 = 1;136		<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();137138		let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();139		let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();140		let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();141142		let data: CreateCollectionData<<Test as system::Config>::AccountId> = CreateCollectionData {143			name: name.try_into().unwrap(),144			description: description.try_into().unwrap(),145			token_prefix: token_prefix.try_into().unwrap(),146			mode: CollectionMode::NFT,147			..Default::default()148		};149	150		let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);151		assert_err!(result, <CommonError<Test>>::NotSufficientFounds);152	});153}154155#[test]156fn create_fungible_collection_fails_with_large_decimal_numbers() {157	new_test_ext().execute_with(|| {158		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();159		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();160		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();161162		let origin1 = Origin::signed(1);163		assert_noop!(164			TemplateModule::create_collection(165				origin1,166				col_name1.try_into().unwrap(),167				col_desc1.try_into().unwrap(),168				token_prefix1.try_into().unwrap(),169				CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)170			),171			Error::<Test>::CollectionDecimalPointLimitExceeded172		);173	});174}175176#[test]177fn create_nft_item() {178	new_test_ext().execute_with(|| {179		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));180181		let data = default_nft_data();182		create_test_item(collection_id, &data.clone().into());183184		let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();185		assert_eq!(item.const_data, data.const_data.into_inner());186		assert_eq!(item.variable_data, data.variable_data.into_inner());187	});188}189190// Use cases tests region191// #region192#[test]193fn create_nft_multiple_items() {194	new_test_ext().execute_with(|| {195		create_test_collection(&CollectionMode::NFT, CollectionId(1));196197		let origin1 = Origin::signed(1);198199		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];200201		assert_ok!(TemplateModule::create_multiple_items(202			origin1,203			CollectionId(1),204			account(1),205			items_data206				.clone()207				.into_iter()208				.map(|d| { d.into() })209				.collect()210		));211		for (index, data) in items_data.into_iter().enumerate() {212			let item = <pallet_nonfungible::TokenData<Test>>::get((213				CollectionId(1),214				TokenId((index + 1) as u32),215			))216			.unwrap();217			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());218			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());219		}220	});221}222223#[test]224fn create_refungible_item() {225	new_test_ext().execute_with(|| {226		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));227228		let data = default_re_fungible_data();229		create_test_item(collection_id, &data.clone().into());230		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));231		let balance =232			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));233		assert_eq!(item.const_data, data.const_data.into_inner());234		assert_eq!(item.variable_data, data.variable_data.into_inner());235		assert_eq!(balance, 1023);236	});237}238239#[test]240fn create_multiple_refungible_items() {241	new_test_ext().execute_with(|| {242		create_test_collection(&CollectionMode::ReFungible, CollectionId(1));243244		let origin1 = Origin::signed(1);245246		let items_data = vec![247			default_re_fungible_data(),248			default_re_fungible_data(),249			default_re_fungible_data(),250		];251252		assert_ok!(TemplateModule::create_multiple_items(253			origin1,254			CollectionId(1),255			account(1),256			items_data257				.clone()258				.into_iter()259				.map(|d| { d.into() })260				.collect()261		));262		for (index, data) in items_data.into_iter().enumerate() {263			let item = <pallet_refungible::TokenData<Test>>::get((264				CollectionId(1),265				TokenId((index + 1) as u32),266			));267			let balance =268				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));269			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());270			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());271			assert_eq!(balance, 1023);272		}273	});274}275276#[test]277fn create_fungible_item() {278	new_test_ext().execute_with(|| {279		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));280281		let data = default_fungible_data();282		create_test_item(collection_id, &data.into());283284		assert_eq!(285			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),286			5287		);288	});289}290291//#[test]292// fn create_multiple_fungible_items() {293//     new_test_ext().execute_with(|| {294//         default_limits();295296//         create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));297298//         let origin1 = Origin::signed(1);299300//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];301302//         assert_ok!(TemplateModule::create_multiple_items(303//             origin1.clone(),304//             1,305//             1,306//             items_data.clone().into_iter().map(|d| { d.into() }).collect()307//         ));308309//         for (index, _) in items_data.iter().enumerate() {310//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);311//         }312//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);313//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);314//     });315// }316317#[test]318fn transfer_fungible_item() {319	new_test_ext().execute_with(|| {320		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));321322		let origin1 = Origin::signed(1);323		let origin2 = Origin::signed(2);324325		let data = default_fungible_data();326		create_test_item(collection_id, &data.into());327328		assert_eq!(329			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),330			5331		);332333		// change owner scenario334		assert_ok!(TemplateModule::transfer(335			origin1,336			account(2),337			CollectionId(1),338			TokenId(0),339			5340		));341		assert_eq!(342			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),343			0344		);345346		// split item scenario347		assert_ok!(TemplateModule::transfer(348			origin2.clone(),349			account(3),350			CollectionId(1),351			TokenId(0),352			3353		));354355		// split item and new owner has account scenario356		assert_ok!(TemplateModule::transfer(357			origin2,358			account(3),359			CollectionId(1),360			TokenId(0),361			1362		));363		assert_eq!(364			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),365			1366		);367		assert_eq!(368			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),369			4370		);371	});372}373374#[test]375fn transfer_refungible_item() {376	new_test_ext().execute_with(|| {377		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));378379		// Create RFT 1 in 1023 pieces for account 1380		let data = default_re_fungible_data();381		create_test_item(collection_id, &data.clone().into());382		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));383		assert_eq!(item.const_data, data.const_data.into_inner());384		assert_eq!(item.variable_data, data.variable_data.into_inner());385		assert_eq!(386			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),387			1388		);389		assert_eq!(390			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),391			1023392		);393		assert_eq!(394			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),395			true396		);397398		// Account 1 transfers all 1023 pieces of RFT 1 to account 2399		let origin1 = Origin::signed(1);400		let origin2 = Origin::signed(2);401		assert_ok!(TemplateModule::transfer(402			origin1,403			account(2),404			CollectionId(1),405			TokenId(1),406			1023407		));408		assert_eq!(409			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),410			1023411		);412		assert_eq!(413			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),414			0415		);416		assert_eq!(417			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),418			1419		);420		assert_eq!(421			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),422			false423		);424		assert_eq!(425			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),426			true427		);428429		// Account 2 transfers 500 pieces of RFT 1 to account 3430		assert_ok!(TemplateModule::transfer(431			origin2.clone(),432			account(3),433			CollectionId(1),434			TokenId(1),435			500436		));437		assert_eq!(438			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),439			523440		);441		assert_eq!(442			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),443			500444		);445		assert_eq!(446			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),447			1448		);449		assert_eq!(450			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),451			1452		);453		assert_eq!(454			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),455			true456		);457		assert_eq!(458			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),459			true460		);461462		// Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance463		assert_ok!(TemplateModule::transfer(464			origin2,465			account(3),466			CollectionId(1),467			TokenId(1),468			200469		));470		assert_eq!(471			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),472			323473		);474		assert_eq!(475			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),476			700477		);478		assert_eq!(479			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),480			1481		);482		assert_eq!(483			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),484			1485		);486		assert_eq!(487			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),488			true489		);490		assert_eq!(491			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),492			true493		);494	});495}496497#[test]498fn transfer_nft_item() {499	new_test_ext().execute_with(|| {500		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));501502		let data = default_nft_data();503		create_test_item(collection_id, &data.into());504		assert_eq!(505			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),506			1507		);508		assert_eq!(509			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),510			true511		);512513		let origin1 = Origin::signed(1);514		// default scenario515		assert_ok!(TemplateModule::transfer(516			origin1,517			account(2),518			CollectionId(1),519			TokenId(1),520			1521		));522		assert_eq!(523			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),524			0525		);526		assert_eq!(527			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),528			1529		);530		assert_eq!(531			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),532			false533		);534		assert_eq!(535			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),536			true537		);538	});539}540541#[test]542fn transfer_nft_item_wrong_value() {543	new_test_ext().execute_with(|| {544		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));545546		let data = default_nft_data();547		create_test_item(collection_id, &data.into());548		assert_eq!(549			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),550			1551		);552		assert_eq!(553			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),554			true555		);556557		let origin1 = Origin::signed(1);558559		assert_noop!(560			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)561				.map_err(|e| e.error),562			<pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount563		);564	});565}566567#[test]568fn transfer_nft_item_zero_value() {569	new_test_ext().execute_with(|| {570		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));571572		let data = default_nft_data();573		create_test_item(collection_id, &data.into());574		assert_eq!(575			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),576			1577		);578		assert_eq!(579			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),580			true581		);582583		let origin1 = Origin::signed(1);584585		// Transferring 0 amount works on NFT...586		assert_ok!(TemplateModule::transfer(587			origin1,588			account(2),589			CollectionId(1),590			TokenId(1),591			0592		));593		// ... and results in no transfer594		assert_eq!(595			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),596			1597		);598		assert_eq!(599			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),600			true601		);602	});603}604605#[test]606fn nft_approve_and_transfer_from() {607	new_test_ext().execute_with(|| {608		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));609610		let data = default_nft_data();611		create_test_item(collection_id, &data.into());612613		let origin1 = Origin::signed(1);614		let origin2 = Origin::signed(2);615616		assert_eq!(617			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),618			1619		);620		assert_eq!(621			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),622			true623		);624625		// neg transfer_from626		assert_noop!(627			TemplateModule::transfer_from(628				origin2.clone(),629				account(1),630				account(2),631				CollectionId(1),632				TokenId(1),633				1634			)635			.map_err(|e| e.error),636			CommonError::<Test>::ApprovedValueTooLow637		);638639		// do approve640		assert_ok!(TemplateModule::approve(641			origin1,642			account(2),643			CollectionId(1),644			TokenId(1),645			1646		));647		assert_eq!(648			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),649			account(2)650		);651652		assert_ok!(TemplateModule::transfer_from(653			origin2,654			account(1),655			account(3),656			CollectionId(1),657			TokenId(1),658			1659		));660		assert!(661			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()662		);663	});664}665666#[test]667fn nft_approve_and_transfer_from_allow_list() {668	new_test_ext().execute_with(|| {669		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));670671		let origin1 = Origin::signed(1);672		let origin2 = Origin::signed(2);673674		// Create NFT 1 for account 1675		let data = default_nft_data();676		create_test_item(collection_id, &data.clone().into());677		assert_eq!(678			&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))679				.unwrap()680				.const_data,681			&data.const_data.into_inner()682		);683		assert_eq!(684			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),685			1686		);687		assert_eq!(688			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),689			true690		);691692		// Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list693		assert_ok!(TemplateModule::set_mint_permission(694			origin1.clone(),695			CollectionId(1),696			true697		));698		assert_ok!(TemplateModule::set_public_access_mode(699			origin1.clone(),700			CollectionId(1),701			AccessMode::AllowList702		));703		assert_ok!(TemplateModule::add_to_allow_list(704			origin1.clone(),705			CollectionId(1),706			account(1)707		));708		assert_ok!(TemplateModule::add_to_allow_list(709			origin1.clone(),710			CollectionId(1),711			account(2)712		));713		assert_ok!(TemplateModule::add_to_allow_list(714			origin1.clone(),715			CollectionId(1),716			account(3)717		));718719		// Account 1 approves account 2 for NFT 1720		assert_ok!(TemplateModule::approve(721			origin1.clone(),722			account(2),723			CollectionId(1),724			TokenId(1),725			1726		));727		assert_eq!(728			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),729			account(2)730		);731732		// Account 2 transfers NFT 1 from account 1 to account 3733		assert_ok!(TemplateModule::transfer_from(734			origin2,735			account(1),736			account(3),737			CollectionId(1),738			TokenId(1),739			1740		));741		assert!(742			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()743		);744	});745}746747#[test]748fn refungible_approve_and_transfer_from() {749	new_test_ext().execute_with(|| {750		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));751752		let origin1 = Origin::signed(1);753		let origin2 = Origin::signed(2);754755		// Create RFT 1 in 1023 pieces for account 1756		let data = default_re_fungible_data();757		create_test_item(collection_id, &data.into());758759		assert_eq!(760			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),761			1762		);763		assert_eq!(764			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),765			1023766		);767		assert_eq!(768			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),769			true770		);771772		// Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list773		assert_ok!(TemplateModule::set_mint_permission(774			origin1.clone(),775			CollectionId(1),776			true777		));778		assert_ok!(TemplateModule::set_public_access_mode(779			origin1.clone(),780			CollectionId(1),781			AccessMode::AllowList782		));783		assert_ok!(TemplateModule::add_to_allow_list(784			origin1.clone(),785			CollectionId(1),786			account(1)787		));788		assert_ok!(TemplateModule::add_to_allow_list(789			origin1.clone(),790			CollectionId(1),791			account(2)792		));793		assert_ok!(TemplateModule::add_to_allow_list(794			origin1.clone(),795			CollectionId(1),796			account(3)797		));798799		// Account 1 approves account 2 for 1023 pieces of RFT 1800		assert_ok!(TemplateModule::approve(801			origin1,802			account(2),803			CollectionId(1),804			TokenId(1),805			1023806		));807		assert_eq!(808			<pallet_refungible::Allowance<Test>>::get((809				CollectionId(1),810				TokenId(1),811				account(1),812				account(2)813			)),814			1023815		);816817		// Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3818		assert_ok!(TemplateModule::transfer_from(819			origin2,820			account(1),821			account(3),822			CollectionId(1),823			TokenId(1),824			100825		));826		assert_eq!(827			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),828			1829		);830		assert_eq!(831			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),832			1833		);834		assert_eq!(835			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),836			923837		);838		assert_eq!(839			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),840			100841		);842		assert_eq!(843			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),844			true845		);846		assert_eq!(847			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),848			true849		);850		assert_eq!(851			<pallet_refungible::Allowance<Test>>::get((852				CollectionId(1),853				TokenId(1),854				account(1),855				account(2)856			)),857			923858		);859	});860}861862#[test]863fn fungible_approve_and_transfer_from() {864	new_test_ext().execute_with(|| {865		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));866867		let data = default_fungible_data();868		create_test_item(collection_id, &data.into());869870		let origin1 = Origin::signed(1);871		let origin2 = Origin::signed(2);872873		assert_ok!(TemplateModule::set_mint_permission(874			origin1.clone(),875			CollectionId(1),876			true877		));878		assert_ok!(TemplateModule::set_public_access_mode(879			origin1.clone(),880			CollectionId(1),881			AccessMode::AllowList882		));883		assert_ok!(TemplateModule::add_to_allow_list(884			origin1.clone(),885			CollectionId(1),886			account(1)887		));888		assert_ok!(TemplateModule::add_to_allow_list(889			origin1.clone(),890			CollectionId(1),891			account(2)892		));893		assert_ok!(TemplateModule::add_to_allow_list(894			origin1.clone(),895			CollectionId(1),896			account(3)897		));898899		// do approve900		assert_ok!(TemplateModule::approve(901			origin1.clone(),902			account(2),903			CollectionId(1),904			TokenId(0),905			5906		));907		assert_eq!(908			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),909			5910		);911		assert_ok!(TemplateModule::approve(912			origin1,913			account(3),914			CollectionId(1),915			TokenId(0),916			5917		));918		assert_eq!(919			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),920			5921		);922		assert_eq!(923			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),924			5925		);926927		assert_ok!(TemplateModule::transfer_from(928			origin2.clone(),929			account(1),930			account(3),931			CollectionId(1),932			TokenId(0),933			4934		));935936		assert_eq!(937			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),938			1939		);940941		assert_noop!(942			TemplateModule::transfer_from(943				origin2,944				account(1),945				account(3),946				CollectionId(1),947				TokenId(0),948				4949			)950			.map_err(|e| e.error),951			CommonError::<Test>::ApprovedValueTooLow952		);953	});954}955956#[test]957fn change_collection_owner() {958	new_test_ext().execute_with(|| {959		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));960961		let origin1 = Origin::signed(1);962		assert_ok!(TemplateModule::change_collection_owner(963			origin1,964			collection_id,965			2966		));967		assert_eq!(968			<pallet_common::CollectionById<Test>>::get(collection_id)969				.unwrap()970				.owner,971			2972		);973	});974}975976#[test]977fn destroy_collection() {978	new_test_ext().execute_with(|| {979		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));980981		let origin1 = Origin::signed(1);982		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));983	});984}985986#[test]987fn burn_nft_item() {988	new_test_ext().execute_with(|| {989		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));990991		let origin1 = Origin::signed(1);992993		let data = default_nft_data();994		create_test_item(collection_id, &data.into());995996		// check balance (collection with id = 1, user id = 1)997		assert_eq!(998			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),999			11000		);10011002		// burn item1003		assert_ok!(TemplateModule::burn_item(1004			origin1.clone(),1005			collection_id,1006			TokenId(1),1007			11008		));1009		assert_eq!(1010			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1011			01012		);1013	});1014}10151016#[test]1017fn burn_same_nft_item_twice() {1018	new_test_ext().execute_with(|| {1019		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10201021		let origin1 = Origin::signed(1);10221023		let data = default_nft_data();1024		create_test_item(collection_id, &data.into());10251026		// check balance (collection with id = 1, user id = 1)1027		assert_eq!(1028			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1029			11030		);10311032		// burn item1033		assert_ok!(TemplateModule::burn_item(1034			origin1.clone(),1035			collection_id,1036			TokenId(1),1037			11038		));10391040		// burn item again1041		assert_noop!(1042			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1043			CommonError::<Test>::TokenNotFound1044		);10451046		assert_eq!(1047			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1048			01049		);1050	});1051}10521053#[test]1054fn burn_fungible_item() {1055	new_test_ext().execute_with(|| {1056		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10571058		let origin1 = Origin::signed(1);1059		assert_ok!(TemplateModule::add_collection_admin(1060			origin1.clone(),1061			collection_id,1062			account(2)1063		));10641065		let data = default_fungible_data();1066		create_test_item(collection_id, &data.into());10671068		// check balance (collection with id = 1, user id = 1)1069		assert_eq!(1070			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1071			51072		);10731074		// burn item1075		assert_ok!(TemplateModule::burn_item(1076			origin1.clone(),1077			CollectionId(1),1078			TokenId(0),1079			51080		));1081		assert_noop!(1082			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1083			CommonError::<Test>::TokenValueTooLow1084		);10851086		assert_eq!(1087			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1088			01089		);1090	});1091}10921093#[test]1094fn burn_fungible_item_with_token_id() {1095	new_test_ext().execute_with(|| {1096		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10971098		let origin1 = Origin::signed(1);1099		assert_ok!(TemplateModule::add_collection_admin(1100			origin1.clone(),1101			collection_id,1102			account(2)1103		));11041105		let data = default_fungible_data();1106		create_test_item(collection_id, &data.into());11071108		// check balance (collection with id = 1, user id = 1)1109		assert_eq!(1110			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1111			51112		);11131114		// Try to burn item using Token ID1115		assert_noop!(1116			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1117			<pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1118		);1119	});1120}1121#[test]1122fn burn_refungible_item() {1123	new_test_ext().execute_with(|| {1124		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1125		let origin1 = Origin::signed(1);11261127		assert_ok!(TemplateModule::set_mint_permission(1128			origin1.clone(),1129			collection_id,1130			true1131		));1132		assert_ok!(TemplateModule::set_public_access_mode(1133			origin1.clone(),1134			collection_id,1135			AccessMode::AllowList1136		));1137		assert_ok!(TemplateModule::add_to_allow_list(1138			origin1.clone(),1139			collection_id,1140			account(1)1141		));11421143		assert_ok!(TemplateModule::add_collection_admin(1144			origin1.clone(),1145			collection_id,1146			account(2)1147		));11481149		let data = default_re_fungible_data();1150		create_test_item(collection_id, &data.into());11511152		// check balance (collection with id = 1, user id = 2)1153		assert_eq!(1154			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1155			11156		);1157		assert_eq!(1158			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1159			10231160		);11611162		// burn item1163		assert_ok!(TemplateModule::burn_item(1164			origin1.clone(),1165			collection_id,1166			TokenId(1),1167			10231168		));1169		assert_noop!(1170			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1171				.map_err(|e| e.error),1172			CommonError::<Test>::TokenValueTooLow1173		);11741175		assert_eq!(1176			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1177			01178		);1179	});1180}11811182#[test]1183fn add_collection_admin() {1184	new_test_ext().execute_with(|| {1185		let collection1_id =1186			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1187		let origin1 = Origin::signed(1);11881189		// Add collection admins1190		assert_ok!(TemplateModule::add_collection_admin(1191			origin1.clone(),1192			collection1_id,1193			account(2)1194		));1195		assert_ok!(TemplateModule::add_collection_admin(1196			origin1,1197			collection1_id,1198			account(3)1199		));12001201		// Owner is not an admin by default1202		assert_eq!(1203			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1204			false1205		);1206		assert!(<pallet_common::IsAdmin<Test>>::get((1207			CollectionId(1),1208			account(2)1209		)));1210		assert!(<pallet_common::IsAdmin<Test>>::get((1211			CollectionId(1),1212			account(3)1213		)));1214	});1215}12161217#[test]1218fn remove_collection_admin() {1219	new_test_ext().execute_with(|| {1220		let collection1_id =1221			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1222		let origin1 = Origin::signed(1);1223		let origin2 = Origin::signed(2);12241225		// Add collection admins 2 and 31226		assert_ok!(TemplateModule::add_collection_admin(1227			origin1.clone(),1228			collection1_id,1229			account(2)1230		));1231		assert_ok!(TemplateModule::add_collection_admin(1232			origin1,1233			collection1_id,1234			account(3)1235		));12361237		assert!(<pallet_common::IsAdmin<Test>>::get((1238			CollectionId(1),1239			account(2)1240		)));1241		assert!(<pallet_common::IsAdmin<Test>>::get((1242			CollectionId(1),1243			account(3)1244		)));12451246		// remove admin 31247		assert_ok!(TemplateModule::remove_collection_admin(1248			origin2,1249			CollectionId(1),1250			account(3)1251		));12521253		// 2 is still admin, 3 is not an admin anymore1254		assert!(<pallet_common::IsAdmin<Test>>::get((1255			CollectionId(1),1256			account(2)1257		)));1258		assert_eq!(1259			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1260			false1261		);1262	});1263}12641265#[test]1266fn balance_of() {1267	new_test_ext().execute_with(|| {1268		let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1269		let fungible_collection_id =1270			create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1271		let re_fungible_collection_id =1272			create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12731274		// check balance before1275		assert_eq!(1276			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1277			01278		);1279		assert_eq!(1280			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1281			01282		);1283		assert_eq!(1284			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1285			01286		);12871288		let nft_data = default_nft_data();1289		create_test_item(nft_collection_id, &nft_data.into());12901291		let fungible_data = default_fungible_data();1292		create_test_item(fungible_collection_id, &fungible_data.into());12931294		let re_fungible_data = default_re_fungible_data();1295		create_test_item(re_fungible_collection_id, &re_fungible_data.into());12961297		// check balance (collection with id = 1, user id = 1)1298		assert_eq!(1299			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1300			11301		);1302		assert_eq!(1303			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1304			51305		);1306		assert_eq!(1307			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1308			11309		);13101311		assert_eq!(1312			<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1313			true1314		);1315		assert_eq!(1316			<pallet_refungible::Owned<Test>>::get((1317				re_fungible_collection_id,1318				account(1),1319				TokenId(1)1320			)),1321			true1322		);1323	});1324}13251326#[test]1327fn approve() {1328	new_test_ext().execute_with(|| {1329		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13301331		let data = default_nft_data();1332		create_test_item(collection_id, &data.into());13331334		let origin1 = Origin::signed(1);13351336		// approve1337		assert_ok!(TemplateModule::approve(1338			origin1,1339			account(2),1340			CollectionId(1),1341			TokenId(1),1342			11343		));1344		assert_eq!(1345			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1346			account(2)1347		);1348	});1349}13501351#[test]1352fn transfer_from() {1353	new_test_ext().execute_with(|| {1354		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1355		let origin1 = Origin::signed(1);1356		let origin2 = Origin::signed(2);13571358		let data = default_nft_data();1359		create_test_item(collection_id, &data.into());13601361		// approve1362		assert_ok!(TemplateModule::approve(1363			origin1.clone(),1364			account(2),1365			CollectionId(1),1366			TokenId(1),1367			11368		));1369		assert_eq!(1370			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1371			account(2)1372		);13731374		assert_ok!(TemplateModule::set_mint_permission(1375			origin1.clone(),1376			CollectionId(1),1377			true1378		));1379		assert_ok!(TemplateModule::set_public_access_mode(1380			origin1.clone(),1381			CollectionId(1),1382			AccessMode::AllowList1383		));1384		assert_ok!(TemplateModule::add_to_allow_list(1385			origin1.clone(),1386			CollectionId(1),1387			account(1)1388		));1389		assert_ok!(TemplateModule::add_to_allow_list(1390			origin1.clone(),1391			CollectionId(1),1392			account(2)1393		));1394		assert_ok!(TemplateModule::add_to_allow_list(1395			origin1,1396			CollectionId(1),1397			account(3)1398		));13991400		assert_ok!(TemplateModule::transfer_from(1401			origin2,1402			account(1),1403			account(2),1404			CollectionId(1),1405			TokenId(1),1406			11407		));14081409		// after transfer1410		assert_eq!(1411			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1412			01413		);1414		assert_eq!(1415			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1416			11417		);1418	});1419}14201421// #endregion14221423// Coverage tests region1424// #region14251426#[test]1427fn owner_can_add_address_to_allow_list() {1428	new_test_ext().execute_with(|| {1429		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14301431		let origin1 = Origin::signed(1);1432		assert_ok!(TemplateModule::add_to_allow_list(1433			origin1,1434			collection_id,1435			account(2)1436		));1437		assert!(<pallet_common::Allowlist<Test>>::get((1438			collection_id,1439			account(2)1440		)));1441	});1442}14431444#[test]1445fn admin_can_add_address_to_allow_list() {1446	new_test_ext().execute_with(|| {1447		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1448		let origin1 = Origin::signed(1);1449		let origin2 = Origin::signed(2);14501451		assert_ok!(TemplateModule::add_collection_admin(1452			origin1,1453			collection_id,1454			account(2)1455		));1456		assert_ok!(TemplateModule::add_to_allow_list(1457			origin2,1458			collection_id,1459			account(3)1460		));1461		assert!(<pallet_common::Allowlist<Test>>::get((1462			collection_id,1463			account(3)1464		)));1465	});1466}14671468#[test]1469fn nonprivileged_user_cannot_add_address_to_allow_list() {1470	new_test_ext().execute_with(|| {1471		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14721473		let origin2 = Origin::signed(2);1474		assert_noop!(1475			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1476			CommonError::<Test>::NoPermission1477		);1478	});1479}14801481#[test]1482fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1483	new_test_ext().execute_with(|| {1484		let origin1 = Origin::signed(1);14851486		assert_noop!(1487			TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1488			CommonError::<Test>::CollectionNotFound1489		);1490	});1491}14921493#[test]1494fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1495	new_test_ext().execute_with(|| {1496		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14971498		let origin1 = Origin::signed(1);1499		assert_ok!(TemplateModule::destroy_collection(1500			origin1.clone(),1501			collection_id1502		));1503		assert_noop!(1504			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1505			CommonError::<Test>::CollectionNotFound1506		);1507	});1508}15091510// If address is already added to allow list, nothing happens1511#[test]1512fn address_is_already_added_to_allow_list() {1513	new_test_ext().execute_with(|| {1514		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1515		let origin1 = Origin::signed(1);15161517		assert_ok!(TemplateModule::add_to_allow_list(1518			origin1.clone(),1519			collection_id,1520			account(2)1521		));1522		assert_ok!(TemplateModule::add_to_allow_list(1523			origin1,1524			collection_id,1525			account(2)1526		));1527		assert!(<pallet_common::Allowlist<Test>>::get((1528			collection_id,1529			account(2)1530		)));1531	});1532}15331534#[test]1535fn owner_can_remove_address_from_allow_list() {1536	new_test_ext().execute_with(|| {1537		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15381539		let origin1 = Origin::signed(1);1540		assert_ok!(TemplateModule::add_to_allow_list(1541			origin1.clone(),1542			collection_id,1543			account(2)1544		));1545		assert_ok!(TemplateModule::remove_from_allow_list(1546			origin1,1547			collection_id,1548			account(2)1549		));1550		assert_eq!(1551			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1552			false1553		);1554	});1555}15561557#[test]1558fn admin_can_remove_address_from_allow_list() {1559	new_test_ext().execute_with(|| {1560		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1561		let origin1 = Origin::signed(1);1562		let origin2 = Origin::signed(2);15631564		// Owner adds admin1565		assert_ok!(TemplateModule::add_collection_admin(1566			origin1.clone(),1567			collection_id,1568			account(2)1569		));15701571		// Owner adds address 3 to allow list1572		assert_ok!(TemplateModule::add_to_allow_list(1573			origin1,1574			collection_id,1575			account(3)1576		));15771578		// Admin removes address 3 from allow list1579		assert_ok!(TemplateModule::remove_from_allow_list(1580			origin2,1581			collection_id,1582			account(3)1583		));1584		assert_eq!(1585			<pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1586			false1587		);1588	});1589}15901591#[test]1592fn nonprivileged_user_cannot_remove_address_from_allow_list() {1593	new_test_ext().execute_with(|| {1594		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1595		let origin1 = Origin::signed(1);1596		let origin2 = Origin::signed(2);15971598		assert_ok!(TemplateModule::add_to_allow_list(1599			origin1,1600			collection_id,1601			account(2)1602		));1603		assert_noop!(1604			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1605			CommonError::<Test>::NoPermission1606		);1607		assert!(<pallet_common::Allowlist<Test>>::get((1608			collection_id,1609			account(2)1610		)));1611	});1612}16131614#[test]1615fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1616	new_test_ext().execute_with(|| {1617		let origin1 = Origin::signed(1);16181619		assert_noop!(1620			TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1621			CommonError::<Test>::CollectionNotFound1622		);1623	});1624}16251626#[test]1627fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1628	new_test_ext().execute_with(|| {1629		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1630		let origin1 = Origin::signed(1);1631		let origin2 = Origin::signed(2);16321633		// Add account 2 to allow list1634		assert_ok!(TemplateModule::add_to_allow_list(1635			origin1.clone(),1636			collection_id,1637			account(2)1638		));16391640		// Account 2 is in collection allow-list1641		assert!(<pallet_common::Allowlist<Test>>::get((1642			collection_id,1643			account(2)1644		)));16451646		// Destroy collection1647		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16481649		// Attempt to remove account 2 from collection allow-list => error1650		assert_noop!(1651			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1652			CommonError::<Test>::CollectionNotFound1653		);16541655		// Account 2 is not found in collection allow-list anyway1656		assert_eq!(1657			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1658			false1659		);1660	});1661}16621663// If address is already removed from allow list, nothing happens1664#[test]1665fn address_is_already_removed_from_allow_list() {1666	new_test_ext().execute_with(|| {1667		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1668		let origin1 = Origin::signed(1);16691670		assert_ok!(TemplateModule::add_to_allow_list(1671			origin1.clone(),1672			collection_id,1673			account(2)1674		));1675		assert_ok!(TemplateModule::remove_from_allow_list(1676			origin1.clone(),1677			collection_id,1678			account(2)1679		));1680		assert_eq!(1681			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1682			false1683		);1684		assert_ok!(TemplateModule::remove_from_allow_list(1685			origin1,1686			collection_id,1687			account(2)1688		));1689		assert_eq!(1690			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1691			false1692		);1693	});1694}16951696// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1697#[test]1698fn allow_list_test_1() {1699	new_test_ext().execute_with(|| {1700		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17011702		let origin1 = Origin::signed(1);17031704		let data = default_nft_data();1705		create_test_item(collection_id, &data.into());17061707		assert_ok!(TemplateModule::set_public_access_mode(1708			origin1.clone(),1709			collection_id,1710			AccessMode::AllowList1711		));1712		assert_ok!(TemplateModule::add_to_allow_list(1713			origin1.clone(),1714			collection_id,1715			account(2)1716		));17171718		assert_noop!(1719			TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1720				.map_err(|e| e.error),1721			CommonError::<Test>::AddressNotInAllowlist1722		);1723	});1724}17251726#[test]1727fn allow_list_test_2() {1728	new_test_ext().execute_with(|| {1729		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1730		let origin1 = Origin::signed(1);17311732		let data = default_nft_data();1733		create_test_item(collection_id, &data.into());17341735		assert_ok!(TemplateModule::set_public_access_mode(1736			origin1.clone(),1737			collection_id,1738			AccessMode::AllowList1739		));1740		assert_ok!(TemplateModule::add_to_allow_list(1741			origin1.clone(),1742			collection_id,1743			account(1)1744		));1745		assert_ok!(TemplateModule::add_to_allow_list(1746			origin1.clone(),1747			collection_id,1748			account(2)1749		));17501751		// do approve1752		assert_ok!(TemplateModule::approve(1753			origin1.clone(),1754			account(1),1755			collection_id,1756			TokenId(1),1757			11758		));1759		assert_eq!(1760			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1761			account(1)1762		);17631764		assert_ok!(TemplateModule::remove_from_allow_list(1765			origin1.clone(),1766			collection_id,1767			account(1)1768		));17691770		assert_noop!(1771			TemplateModule::transfer_from(1772				origin1,1773				account(1),1774				account(3),1775				CollectionId(1),1776				TokenId(1),1777				11778			)1779			.map_err(|e| e.error),1780			CommonError::<Test>::AddressNotInAllowlist1781		);1782	});1783}17841785// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1786#[test]1787fn allow_list_test_3() {1788	new_test_ext().execute_with(|| {1789		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17901791		let origin1 = Origin::signed(1);17921793		let data = default_nft_data();1794		create_test_item(collection_id, &data.into());17951796		assert_ok!(TemplateModule::set_public_access_mode(1797			origin1.clone(),1798			collection_id,1799			AccessMode::AllowList1800		));1801		assert_ok!(TemplateModule::add_to_allow_list(1802			origin1.clone(),1803			collection_id,1804			account(1)1805		));18061807		assert_noop!(1808			TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1809				.map_err(|e| e.error),1810			CommonError::<Test>::AddressNotInAllowlist1811		);1812	});1813}18141815#[test]1816fn allow_list_test_4() {1817	new_test_ext().execute_with(|| {1818		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18191820		let origin1 = Origin::signed(1);18211822		let data = default_nft_data();1823		create_test_item(collection_id, &data.into());18241825		assert_ok!(TemplateModule::set_public_access_mode(1826			origin1.clone(),1827			collection_id,1828			AccessMode::AllowList1829		));1830		assert_ok!(TemplateModule::add_to_allow_list(1831			origin1.clone(),1832			collection_id,1833			account(1)1834		));1835		assert_ok!(TemplateModule::add_to_allow_list(1836			origin1.clone(),1837			collection_id,1838			account(2)1839		));18401841		// do approve1842		assert_ok!(TemplateModule::approve(1843			origin1.clone(),1844			account(1),1845			collection_id,1846			TokenId(1),1847			11848		));1849		assert_eq!(1850			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1851			account(1)1852		);18531854		assert_ok!(TemplateModule::remove_from_allow_list(1855			origin1.clone(),1856			collection_id,1857			account(2)1858		));18591860		assert_noop!(1861			TemplateModule::transfer_from(1862				origin1,1863				account(1),1864				account(3),1865				collection_id,1866				TokenId(1),1867				11868			)1869			.map_err(|e| e.error),1870			CommonError::<Test>::AddressNotInAllowlist1871		);1872	});1873}18741875// 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)1876#[test]1877fn allow_list_test_5() {1878	new_test_ext().execute_with(|| {1879		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18801881		let origin1 = Origin::signed(1);18821883		let data = default_nft_data();1884		create_test_item(collection_id, &data.into());18851886		assert_ok!(TemplateModule::set_public_access_mode(1887			origin1.clone(),1888			collection_id,1889			AccessMode::AllowList1890		));1891		assert_noop!(1892			TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1893				.map_err(|e| e.error),1894			CommonError::<Test>::AddressNotInAllowlist1895		);1896	});1897}18981899// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1900#[test]1901fn allow_list_test_6() {1902	new_test_ext().execute_with(|| {1903		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19041905		let origin1 = Origin::signed(1);19061907		let data = default_nft_data();1908		create_test_item(collection_id, &data.into());19091910		assert_ok!(TemplateModule::set_public_access_mode(1911			origin1.clone(),1912			collection_id,1913			AccessMode::AllowList1914		));19151916		// do approve1917		assert_noop!(1918			TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1919				.map_err(|e| e.error),1920			CommonError::<Test>::AddressNotInAllowlist1921		);1922	});1923}19241925// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1926//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1927#[test]1928fn allow_list_test_7() {1929	new_test_ext().execute_with(|| {1930		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19311932		let data = default_nft_data();1933		create_test_item(collection_id, &data.into());19341935		let origin1 = Origin::signed(1);19361937		assert_ok!(TemplateModule::set_public_access_mode(1938			origin1.clone(),1939			collection_id,1940			AccessMode::AllowList1941		));1942		assert_ok!(TemplateModule::add_to_allow_list(1943			origin1.clone(),1944			collection_id,1945			account(1)1946		));1947		assert_ok!(TemplateModule::add_to_allow_list(1948			origin1.clone(),1949			collection_id,1950			account(2)1951		));19521953		assert_ok!(TemplateModule::transfer(1954			origin1,1955			account(2),1956			CollectionId(1),1957			TokenId(1),1958			11959		));1960	});1961}19621963#[test]1964fn allow_list_test_8() {1965	new_test_ext().execute_with(|| {1966		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19671968		// Create NFT for account 11969		let data = default_nft_data();1970		create_test_item(collection_id, &data.into());19711972		let origin1 = Origin::signed(1);19731974		// Toggle Allow List mode and add accounts 1 and 21975		assert_ok!(TemplateModule::set_public_access_mode(1976			origin1.clone(),1977			collection_id,1978			AccessMode::AllowList1979		));1980		assert_ok!(TemplateModule::add_to_allow_list(1981			origin1.clone(),1982			collection_id,1983			account(1)1984		));1985		assert_ok!(TemplateModule::add_to_allow_list(1986			origin1.clone(),1987			collection_id,1988			account(2)1989		));19901991		// Sself-approve account 1 for NFT 11992		assert_ok!(TemplateModule::approve(1993			origin1.clone(),1994			account(1),1995			CollectionId(1),1996			TokenId(1),1997			11998		));1999		assert_eq!(2000			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2001			account(1)2002		);20032004		// Transfer from 1 to 22005		assert_ok!(TemplateModule::transfer_from(2006			origin1,2007			account(1),2008			account(2),2009			CollectionId(1),2010			TokenId(1),2011			12012		));2013	});2014}20152016// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2017#[test]2018fn allow_list_test_9() {2019	new_test_ext().execute_with(|| {2020		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2021		let origin1 = Origin::signed(1);20222023		assert_ok!(TemplateModule::set_public_access_mode(2024			origin1.clone(),2025			collection_id,2026			AccessMode::AllowList2027		));2028		assert_ok!(TemplateModule::set_mint_permission(2029			origin1,2030			collection_id,2031			false2032		));20332034		let data = default_nft_data();2035		create_test_item(collection_id, &data.into());2036	});2037}20382039// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2040#[test]2041fn allow_list_test_10() {2042	new_test_ext().execute_with(|| {2043		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20442045		let origin1 = Origin::signed(1);2046		let origin2 = Origin::signed(2);20472048		assert_ok!(TemplateModule::set_public_access_mode(2049			origin1.clone(),2050			collection_id,2051			AccessMode::AllowList2052		));2053		assert_ok!(TemplateModule::set_mint_permission(2054			origin1.clone(),2055			collection_id,2056			false2057		));20582059		assert_ok!(TemplateModule::add_collection_admin(2060			origin1,2061			collection_id,2062			account(2)2063		));20642065		assert_ok!(TemplateModule::create_item(2066			origin2,2067			collection_id,2068			account(2),2069			default_nft_data().into()2070		));2071	});2072}20732074// 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.2075#[test]2076fn allow_list_test_11() {2077	new_test_ext().execute_with(|| {2078		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20792080		let origin1 = Origin::signed(1);2081		let origin2 = Origin::signed(2);20822083		assert_ok!(TemplateModule::set_public_access_mode(2084			origin1.clone(),2085			collection_id,2086			AccessMode::AllowList2087		));2088		assert_ok!(TemplateModule::set_mint_permission(2089			origin1.clone(),2090			collection_id,2091			false2092		));2093		assert_ok!(TemplateModule::add_to_allow_list(2094			origin1,2095			collection_id,2096			account(2)2097		));20982099		assert_noop!(2100			TemplateModule::create_item(2101				origin2,2102				CollectionId(1),2103				account(2),2104				default_nft_data().into()2105			)2106			.map_err(|e| e.error),2107			CommonError::<Test>::PublicMintingNotAllowed2108		);2109	});2110}21112112// 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.2113#[test]2114fn allow_list_test_12() {2115	new_test_ext().execute_with(|| {2116		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21172118		let origin1 = Origin::signed(1);2119		let origin2 = Origin::signed(2);21202121		assert_ok!(TemplateModule::set_public_access_mode(2122			origin1.clone(),2123			collection_id,2124			AccessMode::AllowList2125		));2126		assert_ok!(TemplateModule::set_mint_permission(2127			origin1,2128			collection_id,2129			false2130		));21312132		assert_noop!(2133			TemplateModule::create_item(2134				origin2,2135				CollectionId(1),2136				account(2),2137				default_nft_data().into()2138			)2139			.map_err(|e| e.error),2140			CommonError::<Test>::PublicMintingNotAllowed2141		);2142	});2143}21442145// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2146#[test]2147fn allow_list_test_13() {2148	new_test_ext().execute_with(|| {2149		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21502151		let origin1 = Origin::signed(1);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			true2162		));21632164		let data = default_nft_data();2165		create_test_item(collection_id, &data.into());2166	});2167}21682169// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2170#[test]2171fn allow_list_test_14() {2172	new_test_ext().execute_with(|| {2173		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21742175		let origin1 = Origin::signed(1);2176		let origin2 = Origin::signed(2);21772178		assert_ok!(TemplateModule::set_public_access_mode(2179			origin1.clone(),2180			collection_id,2181			AccessMode::AllowList2182		));2183		assert_ok!(TemplateModule::set_mint_permission(2184			origin1.clone(),2185			collection_id,2186			true2187		));21882189		assert_ok!(TemplateModule::add_collection_admin(2190			origin1,2191			collection_id,2192			account(2)2193		));21942195		assert_ok!(TemplateModule::create_item(2196			origin2,2197			collection_id,2198			account(2),2199			default_nft_data().into()2200		));2201	});2202}22032204// 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.2205#[test]2206fn allow_list_test_15() {2207	new_test_ext().execute_with(|| {2208		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22092210		let origin1 = Origin::signed(1);2211		let origin2 = Origin::signed(2);22122213		assert_ok!(TemplateModule::set_public_access_mode(2214			origin1.clone(),2215			collection_id,2216			AccessMode::AllowList2217		));2218		assert_ok!(TemplateModule::set_mint_permission(2219			origin1,2220			collection_id,2221			true2222		));22232224		assert_noop!(2225			TemplateModule::create_item(2226				origin2,2227				collection_id,2228				account(2),2229				default_nft_data().into()2230			)2231			.map_err(|e| e.error),2232			CommonError::<Test>::AddressNotInAllowlist2233		);2234	});2235}22362237// 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.2238#[test]2239fn allow_list_test_16() {2240	new_test_ext().execute_with(|| {2241		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22422243		let origin1 = Origin::signed(1);2244		let origin2 = Origin::signed(2);22452246		assert_ok!(TemplateModule::set_public_access_mode(2247			origin1.clone(),2248			collection_id,2249			AccessMode::AllowList2250		));2251		assert_ok!(TemplateModule::set_mint_permission(2252			origin1.clone(),2253			collection_id,2254			true2255		));2256		assert_ok!(TemplateModule::add_to_allow_list(2257			origin1,2258			collection_id,2259			account(2)2260		));22612262		assert_ok!(TemplateModule::create_item(2263			origin2,2264			collection_id,2265			account(2),2266			default_nft_data().into()2267		));2268	});2269}22702271// Total number of collections. Positive test2272#[test]2273fn total_number_collections_bound() {2274	new_test_ext().execute_with(|| {2275		create_test_collection(&CollectionMode::NFT, CollectionId(1));2276	});2277}22782279#[test]2280fn create_max_collections() {2281	new_test_ext().execute_with(|| {2282		for i in 1..COLLECTION_NUMBER_LIMIT {2283			create_test_collection(&CollectionMode::NFT, CollectionId(i));2284		}2285	});2286}22872288// Total number of collections. Negative test2289#[test]2290fn total_number_collections_bound_neg() {2291	new_test_ext().execute_with(|| {2292		let origin1 = Origin::signed(1);22932294		for i in 1..=COLLECTION_NUMBER_LIMIT {2295			create_test_collection(&CollectionMode::NFT, CollectionId(i));2296		}22972298		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2299		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2300		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23012302		// 11-th collection in chain. Expects error2303		assert_noop!(2304			TemplateModule::create_collection(2305				origin1,2306				col_name1.try_into().unwrap(),2307				col_desc1.try_into().unwrap(),2308				token_prefix1.try_into().unwrap(),2309				CollectionMode::NFT2310			),2311			CommonError::<Test>::TotalCollectionsLimitExceeded2312		);2313	});2314}23152316// Owned tokens by a single address. Positive test2317#[test]2318fn owned_tokens_bound() {2319	new_test_ext().execute_with(|| {2320		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23212322		let data = default_nft_data();2323		create_test_item(collection_id, &data.clone().into());2324		create_test_item(collection_id, &data.into());2325	});2326}23272328// Owned tokens by a single address. Negotive test2329#[test]2330fn owned_tokens_bound_neg() {2331	new_test_ext().execute_with(|| {2332		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23332334		let origin1 = Origin::signed(1);23352336		for _ in 1..=MAX_TOKEN_OWNERSHIP {2337			let data = default_nft_data();2338			create_test_item(collection_id, &data.clone().into());2339		}23402341		let data = default_nft_data();2342		assert_noop!(2343			TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2344				.map_err(|e| e.error),2345			CommonError::<Test>::AccountTokenLimitExceeded2346		);2347	});2348}23492350// Number of collection admins. Positive test2351#[test]2352fn collection_admins_bound() {2353	new_test_ext().execute_with(|| {2354		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23552356		let origin1 = Origin::signed(1);23572358		assert_ok!(TemplateModule::add_collection_admin(2359			origin1.clone(),2360			collection_id,2361			account(2)2362		));2363		assert_ok!(TemplateModule::add_collection_admin(2364			origin1,2365			collection_id,2366			account(3)2367		));2368	});2369}23702371// Number of collection admins. Negotive test2372#[test]2373fn collection_admins_bound_neg() {2374	new_test_ext().execute_with(|| {2375		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23762377		let origin1 = Origin::signed(1);23782379		for i in 0..COLLECTION_ADMINS_LIMIT {2380			assert_ok!(TemplateModule::add_collection_admin(2381				origin1.clone(),2382				collection_id,2383				account((2 + i).into())2384			));2385		}2386		assert_noop!(2387			TemplateModule::add_collection_admin(2388				origin1,2389				collection_id,2390				account((3 + COLLECTION_ADMINS_LIMIT).into())2391			),2392			CommonError::<Test>::CollectionAdminCountExceeded2393		);2394	});2395}2396// #endregion23972398#[test]2399fn set_const_on_chain_schema() {2400	new_test_ext().execute_with(|| {2401		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24022403		let origin1 = Origin::signed(1);2404		assert_ok!(TemplateModule::set_const_on_chain_schema(2405			origin1,2406			collection_id,2407			b"test const on chain schema".to_vec().try_into().unwrap()2408		));24092410		assert_eq!(2411			<pallet_common::CollectionById<Test>>::get(collection_id)2412				.unwrap()2413				.const_on_chain_schema,2414			b"test const on chain schema".to_vec()2415		);2416		assert_eq!(2417			<pallet_common::CollectionById<Test>>::get(collection_id)2418				.unwrap()2419				.variable_on_chain_schema,2420			b"".to_vec()2421		);2422	});2423}24242425#[test]2426fn set_variable_on_chain_schema() {2427	new_test_ext().execute_with(|| {2428		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24292430		let origin1 = Origin::signed(1);2431		assert_ok!(TemplateModule::set_variable_on_chain_schema(2432			origin1,2433			collection_id,2434			b"test variable on chain schema"2435				.to_vec()2436				.try_into()2437				.unwrap()2438		));24392440		assert_eq!(2441			<pallet_common::CollectionById<Test>>::get(collection_id)2442				.unwrap()2443				.const_on_chain_schema,2444			b"".to_vec()2445		);2446		assert_eq!(2447			<pallet_common::CollectionById<Test>>::get(collection_id)2448				.unwrap()2449				.variable_on_chain_schema,2450			b"test variable on chain schema".to_vec()2451		);2452	});2453}24542455#[test]2456fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2457	new_test_ext().execute_with(|| {2458		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24592460		let origin1 = Origin::signed(1);24612462		let data = default_nft_data();2463		create_test_item(CollectionId(1), &data.into());24642465		let variable_data = b"test data".to_vec();2466		assert_ok!(TemplateModule::set_variable_meta_data(2467			origin1,2468			collection_id,2469			TokenId(1),2470			variable_data.clone().try_into().unwrap()2471		));24722473		assert_eq!(2474			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2475				.unwrap()2476				.variable_data,2477			variable_data2478		);2479	});2480}24812482#[test]2483fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2484	new_test_ext().execute_with(|| {2485		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));24862487		let origin1 = Origin::signed(1);24882489		let data = default_re_fungible_data();2490		create_test_item(collection_id, &data.into());24912492		let variable_data = b"test data".to_vec();2493		assert_ok!(TemplateModule::set_variable_meta_data(2494			origin1,2495			collection_id,2496			TokenId(1),2497			variable_data.clone().try_into().unwrap()2498		));24992500		assert_eq!(2501			<pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2502			variable_data2503		);2504	});2505}25062507#[test]2508fn set_variable_meta_data_on_fungible_token_fails() {2509	new_test_ext().execute_with(|| {2510		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));25112512		let origin1 = Origin::signed(1);25132514		let data = default_fungible_data();2515		create_test_item(collection_id, &data.into());25162517		let variable_data = b"test data".to_vec();2518		assert_noop!(2519			TemplateModule::set_variable_meta_data(2520				origin1,2521				collection_id,2522				TokenId(0),2523				variable_data.try_into().unwrap()2524			)2525			.map_err(|e| e.error),2526			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2527		);2528	});2529}25302531#[test]2532fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2533	new_test_ext().execute_with(|| {2534		//default_limits();25352536		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25372538		let origin1 = Origin::signed(1);25392540		let data = default_nft_data();2541		create_test_item(collection_id, &data.into());25422543		assert_ok!(TemplateModule::set_meta_update_permission_flag(2544			origin1.clone(),2545			collection_id,2546			MetaUpdatePermission::ItemOwner,2547		));25482549		let variable_data = b"ten chars.".to_vec();2550		assert_ok!(TemplateModule::set_variable_meta_data(2551			origin1,2552			collection_id,2553			TokenId(1),2554			variable_data.clone().try_into().unwrap()2555		));25562557		assert_eq!(2558			<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2559				.unwrap()2560				.variable_data,2561			variable_data2562		);2563	});2564}25652566#[test]2567fn collection_transfer_flag_works() {2568	new_test_ext().execute_with(|| {2569		let origin1 = Origin::signed(1);25702571		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2572		assert_ok!(TemplateModule::set_transfers_enabled_flag(2573			origin1,2574			collection_id,2575			true2576		));25772578		let data = default_nft_data();2579		create_test_item(collection_id, &data.into());2580		assert_eq!(2581			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2582			12583		);2584		assert_eq!(2585			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2586			true2587		);25882589		let origin1 = Origin::signed(1);25902591		// default scenario2592		assert_ok!(TemplateModule::transfer(2593			origin1,2594			account(2),2595			collection_id,2596			TokenId(1),2597			12598		));2599		assert_eq!(2600			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2601			false2602		);2603		assert_eq!(2604			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2605			true2606		);2607		assert_eq!(2608			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2609			02610		);2611		assert_eq!(2612			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2613			12614		);2615	});2616}26172618#[test]2619fn set_variable_meta_data_on_nft_with_admin_flag() {2620	new_test_ext().execute_with(|| {2621		// default_limits();26222623		let collection_id =2624			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26252626		let origin1 = Origin::signed(1);2627		let origin2 = Origin::signed(2);26282629		assert_ok!(TemplateModule::set_mint_permission(2630			origin2.clone(),2631			collection_id,2632			true2633		));2634		assert_ok!(TemplateModule::add_to_allow_list(2635			origin2.clone(),2636			collection_id,2637			account(1)2638		));26392640		assert_ok!(TemplateModule::add_collection_admin(2641			origin2.clone(),2642			collection_id,2643			account(1)2644		));26452646		let data = default_nft_data();2647		create_test_item(collection_id, &data.into());26482649		assert_ok!(TemplateModule::set_meta_update_permission_flag(2650			origin2.clone(),2651			collection_id,2652			MetaUpdatePermission::Admin,2653		));26542655		let variable_data = b"test.".to_vec();2656		assert_ok!(TemplateModule::set_variable_meta_data(2657			origin1,2658			collection_id,2659			TokenId(1),2660			variable_data.clone().try_into().unwrap()2661		));26622663		assert_eq!(2664			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2665				.unwrap()2666				.variable_data,2667			variable_data2668		);2669	});2670}26712672#[test]2673fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2674	new_test_ext().execute_with(|| {2675		// default_limits();26762677		let collection_id =2678			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26792680		let origin1 = Origin::signed(1);2681		let origin2 = Origin::signed(2);26822683		assert_ok!(TemplateModule::set_mint_permission(2684			origin2.clone(),2685			collection_id,2686			true2687		));2688		assert_ok!(TemplateModule::add_to_allow_list(2689			origin2.clone(),2690			collection_id,2691			account(1)2692		));26932694		let data = default_nft_data();2695		create_test_item(collection_id, &data.into());26962697		assert_ok!(TemplateModule::set_meta_update_permission_flag(2698			origin2.clone(),2699			collection_id,2700			MetaUpdatePermission::Admin,2701		));27022703		let variable_data = b"test.".to_vec();2704		assert_noop!(2705			TemplateModule::set_variable_meta_data(2706				origin1,2707				collection_id,2708				TokenId(1),2709				variable_data.try_into().unwrap()2710			)2711			.map_err(|e| e.error),2712			CommonError::<Test>::NoPermission2713		);2714	});2715}27162717#[test]2718fn set_variable_meta_flag_after_freeze() {2719	new_test_ext().execute_with(|| {2720		// default_limits();27212722		let collection_id =2723			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27242725		let origin2 = Origin::signed(2);27262727		assert_ok!(TemplateModule::set_meta_update_permission_flag(2728			origin2.clone(),2729			collection_id,2730			MetaUpdatePermission::None,2731		));2732		assert_noop!(2733			TemplateModule::set_meta_update_permission_flag(2734				origin2.clone(),2735				collection_id,2736				MetaUpdatePermission::Admin2737			),2738			CommonError::<Test>::MetadataFlagFrozen2739		);2740	});2741}27422743#[test]2744fn set_variable_meta_data_on_nft_with_none_flag_neg() {2745	new_test_ext().execute_with(|| {2746		// default_limits();27472748		let collection_id =2749			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2750		let origin1 = Origin::signed(1);27512752		let data = default_nft_data();2753		create_test_item(collection_id, &data.into());27542755		assert_ok!(TemplateModule::set_meta_update_permission_flag(2756			origin1.clone(),2757			collection_id,2758			MetaUpdatePermission::None,2759		));27602761		let variable_data = b"test.".to_vec();2762		assert_noop!(2763			TemplateModule::set_variable_meta_data(2764				origin1.clone(),2765				collection_id,2766				TokenId(1),2767				variable_data.try_into().unwrap()2768			)2769			.map_err(|e| e.error),2770			CommonError::<Test>::NoPermission2771		);2772	});2773}27742775#[test]2776fn collection_transfer_flag_works_neg() {2777	new_test_ext().execute_with(|| {2778		let origin1 = Origin::signed(1);27792780		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2781		assert_ok!(TemplateModule::set_transfers_enabled_flag(2782			origin1,2783			collection_id,2784			false2785		));27862787		let data = default_nft_data();2788		create_test_item(collection_id, &data.into());2789		assert_eq!(2790			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2791			12792		);2793		assert_eq!(2794			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2795			true2796		);27972798		let origin1 = Origin::signed(1);27992800		// default scenario2801		assert_noop!(2802			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2803				.map_err(|e| e.error),2804			CommonError::<Test>::TransferNotAllowed2805		);2806		assert_eq!(2807			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2808			12809		);2810		assert_eq!(2811			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2812			02813		);2814		assert_eq!(2815			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2816			true2817		);2818		assert_eq!(2819			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2820			false2821		);2822	});2823}