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

difftreelog

source

pallets/unique/src/tests.rs67.7 KiBsourcehistory
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 DONOR_USER: u64 = 999;16	assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(17		Origin::root(),18		DONOR_USER,19		value,20		021	));22	assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(23		Origin::root(),24		DONOR_USER,25		user,26		value27	));28}2930fn default_nft_data() -> CreateNftData {31	CreateNftData {32		const_data: vec![1, 2, 3].try_into().unwrap(),33		variable_data: vec![3, 2, 1].try_into().unwrap(),34	}35}3637fn default_fungible_data() -> CreateFungibleData {38	CreateFungibleData { value: 5 }39}4041fn default_re_fungible_data() -> CreateReFungibleData {42	CreateReFungibleData {43		const_data: vec![1, 2, 3].try_into().unwrap(),44		variable_data: vec![3, 2, 1].try_into().unwrap(),45		pieces: 1023,46	}47}4849fn create_test_collection_for_owner(50	mode: &CollectionMode,51	owner: u64,52	id: CollectionId,53) -> CollectionId {54	add_balance(owner, CollectionCreationPrice::get() as u64 + 1);5556	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();57	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();58	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();5960	let data: CreateCollectionData<u64> = CreateCollectionData {61		name: col_name1.try_into().unwrap(),62		description: col_desc1.try_into().unwrap(),63		token_prefix: token_prefix1.try_into().unwrap(),64		mode: mode.clone(),65		..Default::default()66	};6768	let origin1 = Origin::signed(owner);69	assert_ok!(TemplateModule::create_collection_ex(origin1, data));7071	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();72	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();73	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();74	assert_eq!(75		<pallet_common::CollectionById<Test>>::get(id)76			.unwrap()77			.owner,78		owner79	);80	assert_eq!(81		<pallet_common::CollectionById<Test>>::get(id).unwrap().name,82		saved_col_name83	);84	assert_eq!(85		<pallet_common::CollectionById<Test>>::get(id).unwrap().mode,86		*mode87	);88	assert_eq!(89		<pallet_common::CollectionById<Test>>::get(id)90			.unwrap()91			.description,92		saved_description93	);94	assert_eq!(95		<pallet_common::CollectionById<Test>>::get(id)96			.unwrap()97			.token_prefix,98		saved_prefix99	);100	id101}102103fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {104	create_test_collection_for_owner(&mode, 1, id)105}106107fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {108	let origin1 = Origin::signed(1);109	assert_ok!(TemplateModule::create_item(110		origin1,111		collection_id,112		account(1),113		data.clone()114	));115}116117fn account(sub: u64) -> TestCrossAccountId {118	TestCrossAccountId::from_sub(sub)119}120121// Use cases tests region122// #region123124#[test]125fn set_version_schema() {126	new_test_ext().execute_with(|| {127		let origin1 = Origin::signed(1);128		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));129130		assert_ok!(TemplateModule::set_schema_version(131			origin1,132			collection_id,133			SchemaVersion::Unique134		));135		assert_eq!(136			<pallet_common::CollectionById<Test>>::get(collection_id)137				.unwrap()138				.schema_version,139			SchemaVersion::Unique140		);141	});142}143144#[test]145fn check_not_sufficient_founds() {146	new_test_ext().execute_with(|| {147		let acc: u64 = 1;148		<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();149150		let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();151		let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();152		let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();153154		let data: CreateCollectionData<<Test as system::Config>::AccountId> =155			CreateCollectionData {156				name: name.try_into().unwrap(),157				description: description.try_into().unwrap(),158				token_prefix: token_prefix.try_into().unwrap(),159				mode: CollectionMode::NFT,160				..Default::default()161			};162163		let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);164		assert_err!(result, <CommonError<Test>>::NotSufficientFounds);165	});166}167168#[test]169fn create_fungible_collection_fails_with_large_decimal_numbers() {170	new_test_ext().execute_with(|| {171		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();172		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();173		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();174175		let data: CreateCollectionData<u64> = CreateCollectionData {176			name: col_name1.try_into().unwrap(),177			description: col_desc1.try_into().unwrap(),178			token_prefix: token_prefix1.try_into().unwrap(),179			mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),180			..Default::default()181		};182183		let origin1 = Origin::signed(1);184		assert_noop!(185			TemplateModule::create_collection_ex(origin1, data),186			Error::<Test>::CollectionDecimalPointLimitExceeded187		);188	});189}190191#[test]192fn create_nft_item() {193	new_test_ext().execute_with(|| {194		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));195196		let data = default_nft_data();197		create_test_item(collection_id, &data.clone().into());198199		let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();200		assert_eq!(item.const_data, data.const_data.into_inner());201		assert_eq!(item.variable_data, data.variable_data.into_inner());202	});203}204205// Use cases tests region206// #region207#[test]208fn create_nft_multiple_items() {209	new_test_ext().execute_with(|| {210		create_test_collection(&CollectionMode::NFT, CollectionId(1));211212		let origin1 = Origin::signed(1);213214		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];215216		assert_ok!(TemplateModule::create_multiple_items(217			origin1,218			CollectionId(1),219			account(1),220			items_data221				.clone()222				.into_iter()223				.map(|d| { d.into() })224				.collect()225		));226		for (index, data) in items_data.into_iter().enumerate() {227			let item = <pallet_nonfungible::TokenData<Test>>::get((228				CollectionId(1),229				TokenId((index + 1) as u32),230			))231			.unwrap();232			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());233			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());234		}235	});236}237238#[test]239fn create_refungible_item() {240	new_test_ext().execute_with(|| {241		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));242243		let data = default_re_fungible_data();244		create_test_item(collection_id, &data.clone().into());245		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));246		let balance =247			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));248		assert_eq!(item.const_data, data.const_data.into_inner());249		assert_eq!(item.variable_data, data.variable_data.into_inner());250		assert_eq!(balance, 1023);251	});252}253254#[test]255fn create_multiple_refungible_items() {256	new_test_ext().execute_with(|| {257		create_test_collection(&CollectionMode::ReFungible, CollectionId(1));258259		let origin1 = Origin::signed(1);260261		let items_data = vec![262			default_re_fungible_data(),263			default_re_fungible_data(),264			default_re_fungible_data(),265		];266267		assert_ok!(TemplateModule::create_multiple_items(268			origin1,269			CollectionId(1),270			account(1),271			items_data272				.clone()273				.into_iter()274				.map(|d| { d.into() })275				.collect()276		));277		for (index, data) in items_data.into_iter().enumerate() {278			let item = <pallet_refungible::TokenData<Test>>::get((279				CollectionId(1),280				TokenId((index + 1) as u32),281			));282			let balance =283				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));284			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());285			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());286			assert_eq!(balance, 1023);287		}288	});289}290291#[test]292fn create_fungible_item() {293	new_test_ext().execute_with(|| {294		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));295296		let data = default_fungible_data();297		create_test_item(collection_id, &data.into());298299		assert_eq!(300			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),301			5302		);303	});304}305306//#[test]307// fn create_multiple_fungible_items() {308//     new_test_ext().execute_with(|| {309//         default_limits();310311//         create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));312313//         let origin1 = Origin::signed(1);314315//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];316317//         assert_ok!(TemplateModule::create_multiple_items(318//             origin1.clone(),319//             1,320//             1,321//             items_data.clone().into_iter().map(|d| { d.into() }).collect()322//         ));323324//         for (index, _) in items_data.iter().enumerate() {325//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);326//         }327//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);328//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);329//     });330// }331332#[test]333fn transfer_fungible_item() {334	new_test_ext().execute_with(|| {335		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));336337		let origin1 = Origin::signed(1);338		let origin2 = Origin::signed(2);339340		let data = default_fungible_data();341		create_test_item(collection_id, &data.into());342343		assert_eq!(344			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),345			5346		);347348		// change owner scenario349		assert_ok!(TemplateModule::transfer(350			origin1,351			account(2),352			CollectionId(1),353			TokenId(0),354			5355		));356		assert_eq!(357			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),358			0359		);360361		// split item scenario362		assert_ok!(TemplateModule::transfer(363			origin2.clone(),364			account(3),365			CollectionId(1),366			TokenId(0),367			3368		));369370		// split item and new owner has account scenario371		assert_ok!(TemplateModule::transfer(372			origin2,373			account(3),374			CollectionId(1),375			TokenId(0),376			1377		));378		assert_eq!(379			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),380			1381		);382		assert_eq!(383			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),384			4385		);386	});387}388389#[test]390fn transfer_refungible_item() {391	new_test_ext().execute_with(|| {392		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));393394		// Create RFT 1 in 1023 pieces for account 1395		let data = default_re_fungible_data();396		create_test_item(collection_id, &data.clone().into());397		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));398		assert_eq!(item.const_data, data.const_data.into_inner());399		assert_eq!(item.variable_data, data.variable_data.into_inner());400		assert_eq!(401			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),402			1403		);404		assert_eq!(405			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),406			1023407		);408		assert_eq!(409			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),410			true411		);412413		// Account 1 transfers all 1023 pieces of RFT 1 to account 2414		let origin1 = Origin::signed(1);415		let origin2 = Origin::signed(2);416		assert_ok!(TemplateModule::transfer(417			origin1,418			account(2),419			CollectionId(1),420			TokenId(1),421			1023422		));423		assert_eq!(424			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),425			1023426		);427		assert_eq!(428			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),429			0430		);431		assert_eq!(432			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),433			1434		);435		assert_eq!(436			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),437			false438		);439		assert_eq!(440			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),441			true442		);443444		// Account 2 transfers 500 pieces of RFT 1 to account 3445		assert_ok!(TemplateModule::transfer(446			origin2.clone(),447			account(3),448			CollectionId(1),449			TokenId(1),450			500451		));452		assert_eq!(453			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),454			523455		);456		assert_eq!(457			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),458			500459		);460		assert_eq!(461			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),462			1463		);464		assert_eq!(465			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),466			1467		);468		assert_eq!(469			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),470			true471		);472		assert_eq!(473			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),474			true475		);476477		// Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance478		assert_ok!(TemplateModule::transfer(479			origin2,480			account(3),481			CollectionId(1),482			TokenId(1),483			200484		));485		assert_eq!(486			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),487			323488		);489		assert_eq!(490			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),491			700492		);493		assert_eq!(494			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),495			1496		);497		assert_eq!(498			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),499			1500		);501		assert_eq!(502			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),503			true504		);505		assert_eq!(506			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),507			true508		);509	});510}511512#[test]513fn transfer_nft_item() {514	new_test_ext().execute_with(|| {515		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));516517		let data = default_nft_data();518		create_test_item(collection_id, &data.into());519		assert_eq!(520			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),521			1522		);523		assert_eq!(524			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),525			true526		);527528		let origin1 = Origin::signed(1);529		// default scenario530		assert_ok!(TemplateModule::transfer(531			origin1,532			account(2),533			CollectionId(1),534			TokenId(1),535			1536		));537		assert_eq!(538			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),539			0540		);541		assert_eq!(542			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),543			1544		);545		assert_eq!(546			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),547			false548		);549		assert_eq!(550			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),551			true552		);553	});554}555556#[test]557fn transfer_nft_item_wrong_value() {558	new_test_ext().execute_with(|| {559		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));560561		let data = default_nft_data();562		create_test_item(collection_id, &data.into());563		assert_eq!(564			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),565			1566		);567		assert_eq!(568			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),569			true570		);571572		let origin1 = Origin::signed(1);573574		assert_noop!(575			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)576				.map_err(|e| e.error),577			<pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount578		);579	});580}581582#[test]583fn transfer_nft_item_zero_value() {584	new_test_ext().execute_with(|| {585		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));586587		let data = default_nft_data();588		create_test_item(collection_id, &data.into());589		assert_eq!(590			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),591			1592		);593		assert_eq!(594			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),595			true596		);597598		let origin1 = Origin::signed(1);599600		// Transferring 0 amount works on NFT...601		assert_ok!(TemplateModule::transfer(602			origin1,603			account(2),604			CollectionId(1),605			TokenId(1),606			0607		));608		// ... and results in no transfer609		assert_eq!(610			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),611			1612		);613		assert_eq!(614			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),615			true616		);617	});618}619620#[test]621fn nft_approve_and_transfer_from() {622	new_test_ext().execute_with(|| {623		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));624625		let data = default_nft_data();626		create_test_item(collection_id, &data.into());627628		let origin1 = Origin::signed(1);629		let origin2 = Origin::signed(2);630631		assert_eq!(632			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),633			1634		);635		assert_eq!(636			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),637			true638		);639640		// neg transfer_from641		assert_noop!(642			TemplateModule::transfer_from(643				origin2.clone(),644				account(1),645				account(2),646				CollectionId(1),647				TokenId(1),648				1649			)650			.map_err(|e| e.error),651			CommonError::<Test>::ApprovedValueTooLow652		);653654		// do approve655		assert_ok!(TemplateModule::approve(656			origin1,657			account(2),658			CollectionId(1),659			TokenId(1),660			1661		));662		assert_eq!(663			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),664			account(2)665		);666667		assert_ok!(TemplateModule::transfer_from(668			origin2,669			account(1),670			account(3),671			CollectionId(1),672			TokenId(1),673			1674		));675		assert!(676			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()677		);678	});679}680681#[test]682fn nft_approve_and_transfer_from_allow_list() {683	new_test_ext().execute_with(|| {684		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));685686		let origin1 = Origin::signed(1);687		let origin2 = Origin::signed(2);688689		// Create NFT 1 for account 1690		let data = default_nft_data();691		create_test_item(collection_id, &data.clone().into());692		assert_eq!(693			&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))694				.unwrap()695				.const_data,696			&data.const_data.into_inner()697		);698		assert_eq!(699			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),700			1701		);702		assert_eq!(703			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),704			true705		);706707		// Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list708		assert_ok!(TemplateModule::set_mint_permission(709			origin1.clone(),710			CollectionId(1),711			true712		));713		assert_ok!(TemplateModule::set_public_access_mode(714			origin1.clone(),715			CollectionId(1),716			AccessMode::AllowList717		));718		assert_ok!(TemplateModule::add_to_allow_list(719			origin1.clone(),720			CollectionId(1),721			account(1)722		));723		assert_ok!(TemplateModule::add_to_allow_list(724			origin1.clone(),725			CollectionId(1),726			account(2)727		));728		assert_ok!(TemplateModule::add_to_allow_list(729			origin1.clone(),730			CollectionId(1),731			account(3)732		));733734		// Account 1 approves account 2 for NFT 1735		assert_ok!(TemplateModule::approve(736			origin1.clone(),737			account(2),738			CollectionId(1),739			TokenId(1),740			1741		));742		assert_eq!(743			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),744			account(2)745		);746747		// Account 2 transfers NFT 1 from account 1 to account 3748		assert_ok!(TemplateModule::transfer_from(749			origin2,750			account(1),751			account(3),752			CollectionId(1),753			TokenId(1),754			1755		));756		assert!(757			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()758		);759	});760}761762#[test]763fn refungible_approve_and_transfer_from() {764	new_test_ext().execute_with(|| {765		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));766767		let origin1 = Origin::signed(1);768		let origin2 = Origin::signed(2);769770		// Create RFT 1 in 1023 pieces for account 1771		let data = default_re_fungible_data();772		create_test_item(collection_id, &data.into());773774		assert_eq!(775			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),776			1777		);778		assert_eq!(779			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),780			1023781		);782		assert_eq!(783			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),784			true785		);786787		// Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list788		assert_ok!(TemplateModule::set_mint_permission(789			origin1.clone(),790			CollectionId(1),791			true792		));793		assert_ok!(TemplateModule::set_public_access_mode(794			origin1.clone(),795			CollectionId(1),796			AccessMode::AllowList797		));798		assert_ok!(TemplateModule::add_to_allow_list(799			origin1.clone(),800			CollectionId(1),801			account(1)802		));803		assert_ok!(TemplateModule::add_to_allow_list(804			origin1.clone(),805			CollectionId(1),806			account(2)807		));808		assert_ok!(TemplateModule::add_to_allow_list(809			origin1.clone(),810			CollectionId(1),811			account(3)812		));813814		// Account 1 approves account 2 for 1023 pieces of RFT 1815		assert_ok!(TemplateModule::approve(816			origin1,817			account(2),818			CollectionId(1),819			TokenId(1),820			1023821		));822		assert_eq!(823			<pallet_refungible::Allowance<Test>>::get((824				CollectionId(1),825				TokenId(1),826				account(1),827				account(2)828			)),829			1023830		);831832		// Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3833		assert_ok!(TemplateModule::transfer_from(834			origin2,835			account(1),836			account(3),837			CollectionId(1),838			TokenId(1),839			100840		));841		assert_eq!(842			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),843			1844		);845		assert_eq!(846			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),847			1848		);849		assert_eq!(850			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),851			923852		);853		assert_eq!(854			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),855			100856		);857		assert_eq!(858			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),859			true860		);861		assert_eq!(862			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),863			true864		);865		assert_eq!(866			<pallet_refungible::Allowance<Test>>::get((867				CollectionId(1),868				TokenId(1),869				account(1),870				account(2)871			)),872			923873		);874	});875}876877#[test]878fn fungible_approve_and_transfer_from() {879	new_test_ext().execute_with(|| {880		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));881882		let data = default_fungible_data();883		create_test_item(collection_id, &data.into());884885		let origin1 = Origin::signed(1);886		let origin2 = Origin::signed(2);887888		assert_ok!(TemplateModule::set_mint_permission(889			origin1.clone(),890			CollectionId(1),891			true892		));893		assert_ok!(TemplateModule::set_public_access_mode(894			origin1.clone(),895			CollectionId(1),896			AccessMode::AllowList897		));898		assert_ok!(TemplateModule::add_to_allow_list(899			origin1.clone(),900			CollectionId(1),901			account(1)902		));903		assert_ok!(TemplateModule::add_to_allow_list(904			origin1.clone(),905			CollectionId(1),906			account(2)907		));908		assert_ok!(TemplateModule::add_to_allow_list(909			origin1.clone(),910			CollectionId(1),911			account(3)912		));913914		// do approve915		assert_ok!(TemplateModule::approve(916			origin1.clone(),917			account(2),918			CollectionId(1),919			TokenId(0),920			5921		));922		assert_eq!(923			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),924			5925		);926		assert_ok!(TemplateModule::approve(927			origin1,928			account(3),929			CollectionId(1),930			TokenId(0),931			5932		));933		assert_eq!(934			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),935			5936		);937		assert_eq!(938			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),939			5940		);941942		assert_ok!(TemplateModule::transfer_from(943			origin2.clone(),944			account(1),945			account(3),946			CollectionId(1),947			TokenId(0),948			4949		));950951		assert_eq!(952			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),953			1954		);955956		assert_noop!(957			TemplateModule::transfer_from(958				origin2,959				account(1),960				account(3),961				CollectionId(1),962				TokenId(0),963				4964			)965			.map_err(|e| e.error),966			CommonError::<Test>::ApprovedValueTooLow967		);968	});969}970971#[test]972fn change_collection_owner() {973	new_test_ext().execute_with(|| {974		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));975976		let origin1 = Origin::signed(1);977		assert_ok!(TemplateModule::change_collection_owner(978			origin1,979			collection_id,980			2981		));982		assert_eq!(983			<pallet_common::CollectionById<Test>>::get(collection_id)984				.unwrap()985				.owner,986			2987		);988	});989}990991#[test]992fn destroy_collection() {993	new_test_ext().execute_with(|| {994		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));995996		let origin1 = Origin::signed(1);997		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));998	});999}10001001#[test]1002fn burn_nft_item() {1003	new_test_ext().execute_with(|| {1004		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10051006		let origin1 = Origin::signed(1);10071008		let data = default_nft_data();1009		create_test_item(collection_id, &data.into());10101011		// check balance (collection with id = 1, user id = 1)1012		assert_eq!(1013			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1014			11015		);10161017		// burn item1018		assert_ok!(TemplateModule::burn_item(1019			origin1.clone(),1020			collection_id,1021			TokenId(1),1022			11023		));1024		assert_eq!(1025			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1026			01027		);1028	});1029}10301031#[test]1032fn burn_same_nft_item_twice() {1033	new_test_ext().execute_with(|| {1034		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10351036		let origin1 = Origin::signed(1);10371038		let data = default_nft_data();1039		create_test_item(collection_id, &data.into());10401041		// check balance (collection with id = 1, user id = 1)1042		assert_eq!(1043			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1044			11045		);10461047		// burn item1048		assert_ok!(TemplateModule::burn_item(1049			origin1.clone(),1050			collection_id,1051			TokenId(1),1052			11053		));10541055		// burn item again1056		assert_noop!(1057			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1058			CommonError::<Test>::TokenNotFound1059		);10601061		assert_eq!(1062			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1063			01064		);1065	});1066}10671068#[test]1069fn burn_fungible_item() {1070	new_test_ext().execute_with(|| {1071		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10721073		let origin1 = Origin::signed(1);1074		assert_ok!(TemplateModule::add_collection_admin(1075			origin1.clone(),1076			collection_id,1077			account(2)1078		));10791080		let data = default_fungible_data();1081		create_test_item(collection_id, &data.into());10821083		// check balance (collection with id = 1, user id = 1)1084		assert_eq!(1085			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1086			51087		);10881089		// burn item1090		assert_ok!(TemplateModule::burn_item(1091			origin1.clone(),1092			CollectionId(1),1093			TokenId(0),1094			51095		));1096		assert_noop!(1097			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1098			CommonError::<Test>::TokenValueTooLow1099		);11001101		assert_eq!(1102			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1103			01104		);1105	});1106}11071108#[test]1109fn burn_fungible_item_with_token_id() {1110	new_test_ext().execute_with(|| {1111		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11121113		let origin1 = Origin::signed(1);1114		assert_ok!(TemplateModule::add_collection_admin(1115			origin1.clone(),1116			collection_id,1117			account(2)1118		));11191120		let data = default_fungible_data();1121		create_test_item(collection_id, &data.into());11221123		// check balance (collection with id = 1, user id = 1)1124		assert_eq!(1125			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1126			51127		);11281129		// Try to burn item using Token ID1130		assert_noop!(1131			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1132			<pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1133		);1134	});1135}1136#[test]1137fn burn_refungible_item() {1138	new_test_ext().execute_with(|| {1139		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1140		let origin1 = Origin::signed(1);11411142		assert_ok!(TemplateModule::set_mint_permission(1143			origin1.clone(),1144			collection_id,1145			true1146		));1147		assert_ok!(TemplateModule::set_public_access_mode(1148			origin1.clone(),1149			collection_id,1150			AccessMode::AllowList1151		));1152		assert_ok!(TemplateModule::add_to_allow_list(1153			origin1.clone(),1154			collection_id,1155			account(1)1156		));11571158		assert_ok!(TemplateModule::add_collection_admin(1159			origin1.clone(),1160			collection_id,1161			account(2)1162		));11631164		let data = default_re_fungible_data();1165		create_test_item(collection_id, &data.into());11661167		// check balance (collection with id = 1, user id = 2)1168		assert_eq!(1169			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1170			11171		);1172		assert_eq!(1173			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1174			10231175		);11761177		// burn item1178		assert_ok!(TemplateModule::burn_item(1179			origin1.clone(),1180			collection_id,1181			TokenId(1),1182			10231183		));1184		assert_noop!(1185			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1186				.map_err(|e| e.error),1187			CommonError::<Test>::TokenValueTooLow1188		);11891190		assert_eq!(1191			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1192			01193		);1194	});1195}11961197#[test]1198fn add_collection_admin() {1199	new_test_ext().execute_with(|| {1200		let collection1_id =1201			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1202		let origin1 = Origin::signed(1);12031204		// Add collection admins1205		assert_ok!(TemplateModule::add_collection_admin(1206			origin1.clone(),1207			collection1_id,1208			account(2)1209		));1210		assert_ok!(TemplateModule::add_collection_admin(1211			origin1,1212			collection1_id,1213			account(3)1214		));12151216		// Owner is not an admin by default1217		assert_eq!(1218			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1219			false1220		);1221		assert!(<pallet_common::IsAdmin<Test>>::get((1222			CollectionId(1),1223			account(2)1224		)));1225		assert!(<pallet_common::IsAdmin<Test>>::get((1226			CollectionId(1),1227			account(3)1228		)));1229	});1230}12311232#[test]1233fn remove_collection_admin() {1234	new_test_ext().execute_with(|| {1235		let collection1_id =1236			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1237		let origin1 = Origin::signed(1);1238		let origin2 = Origin::signed(2);12391240		// Add collection admins 2 and 31241		assert_ok!(TemplateModule::add_collection_admin(1242			origin1.clone(),1243			collection1_id,1244			account(2)1245		));1246		assert_ok!(TemplateModule::add_collection_admin(1247			origin1,1248			collection1_id,1249			account(3)1250		));12511252		assert!(<pallet_common::IsAdmin<Test>>::get((1253			CollectionId(1),1254			account(2)1255		)));1256		assert!(<pallet_common::IsAdmin<Test>>::get((1257			CollectionId(1),1258			account(3)1259		)));12601261		// remove admin 31262		assert_ok!(TemplateModule::remove_collection_admin(1263			origin2,1264			CollectionId(1),1265			account(3)1266		));12671268		// 2 is still admin, 3 is not an admin anymore1269		assert!(<pallet_common::IsAdmin<Test>>::get((1270			CollectionId(1),1271			account(2)1272		)));1273		assert_eq!(1274			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1275			false1276		);1277	});1278}12791280#[test]1281fn balance_of() {1282	new_test_ext().execute_with(|| {1283		let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1284		let fungible_collection_id =1285			create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1286		let re_fungible_collection_id =1287			create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12881289		// check balance before1290		assert_eq!(1291			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1292			01293		);1294		assert_eq!(1295			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1296			01297		);1298		assert_eq!(1299			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1300			01301		);13021303		let nft_data = default_nft_data();1304		create_test_item(nft_collection_id, &nft_data.into());13051306		let fungible_data = default_fungible_data();1307		create_test_item(fungible_collection_id, &fungible_data.into());13081309		let re_fungible_data = default_re_fungible_data();1310		create_test_item(re_fungible_collection_id, &re_fungible_data.into());13111312		// check balance (collection with id = 1, user id = 1)1313		assert_eq!(1314			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1315			11316		);1317		assert_eq!(1318			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1319			51320		);1321		assert_eq!(1322			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1323			11324		);13251326		assert_eq!(1327			<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1328			true1329		);1330		assert_eq!(1331			<pallet_refungible::Owned<Test>>::get((1332				re_fungible_collection_id,1333				account(1),1334				TokenId(1)1335			)),1336			true1337		);1338	});1339}13401341#[test]1342fn approve() {1343	new_test_ext().execute_with(|| {1344		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13451346		let data = default_nft_data();1347		create_test_item(collection_id, &data.into());13481349		let origin1 = Origin::signed(1);13501351		// approve1352		assert_ok!(TemplateModule::approve(1353			origin1,1354			account(2),1355			CollectionId(1),1356			TokenId(1),1357			11358		));1359		assert_eq!(1360			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1361			account(2)1362		);1363	});1364}13651366#[test]1367fn transfer_from() {1368	new_test_ext().execute_with(|| {1369		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1370		let origin1 = Origin::signed(1);1371		let origin2 = Origin::signed(2);13721373		let data = default_nft_data();1374		create_test_item(collection_id, &data.into());13751376		// approve1377		assert_ok!(TemplateModule::approve(1378			origin1.clone(),1379			account(2),1380			CollectionId(1),1381			TokenId(1),1382			11383		));1384		assert_eq!(1385			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1386			account(2)1387		);13881389		assert_ok!(TemplateModule::set_mint_permission(1390			origin1.clone(),1391			CollectionId(1),1392			true1393		));1394		assert_ok!(TemplateModule::set_public_access_mode(1395			origin1.clone(),1396			CollectionId(1),1397			AccessMode::AllowList1398		));1399		assert_ok!(TemplateModule::add_to_allow_list(1400			origin1.clone(),1401			CollectionId(1),1402			account(1)1403		));1404		assert_ok!(TemplateModule::add_to_allow_list(1405			origin1.clone(),1406			CollectionId(1),1407			account(2)1408		));1409		assert_ok!(TemplateModule::add_to_allow_list(1410			origin1,1411			CollectionId(1),1412			account(3)1413		));14141415		assert_ok!(TemplateModule::transfer_from(1416			origin2,1417			account(1),1418			account(2),1419			CollectionId(1),1420			TokenId(1),1421			11422		));14231424		// after transfer1425		assert_eq!(1426			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1427			01428		);1429		assert_eq!(1430			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1431			11432		);1433	});1434}14351436// #endregion14371438// Coverage tests region1439// #region14401441#[test]1442fn owner_can_add_address_to_allow_list() {1443	new_test_ext().execute_with(|| {1444		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14451446		let origin1 = Origin::signed(1);1447		assert_ok!(TemplateModule::add_to_allow_list(1448			origin1,1449			collection_id,1450			account(2)1451		));1452		assert!(<pallet_common::Allowlist<Test>>::get((1453			collection_id,1454			account(2)1455		)));1456	});1457}14581459#[test]1460fn admin_can_add_address_to_allow_list() {1461	new_test_ext().execute_with(|| {1462		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1463		let origin1 = Origin::signed(1);1464		let origin2 = Origin::signed(2);14651466		assert_ok!(TemplateModule::add_collection_admin(1467			origin1,1468			collection_id,1469			account(2)1470		));1471		assert_ok!(TemplateModule::add_to_allow_list(1472			origin2,1473			collection_id,1474			account(3)1475		));1476		assert!(<pallet_common::Allowlist<Test>>::get((1477			collection_id,1478			account(3)1479		)));1480	});1481}14821483#[test]1484fn nonprivileged_user_cannot_add_address_to_allow_list() {1485	new_test_ext().execute_with(|| {1486		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14871488		let origin2 = Origin::signed(2);1489		assert_noop!(1490			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1491			CommonError::<Test>::NoPermission1492		);1493	});1494}14951496#[test]1497fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1498	new_test_ext().execute_with(|| {1499		let origin1 = Origin::signed(1);15001501		assert_noop!(1502			TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1503			CommonError::<Test>::CollectionNotFound1504		);1505	});1506}15071508#[test]1509fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1510	new_test_ext().execute_with(|| {1511		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15121513		let origin1 = Origin::signed(1);1514		assert_ok!(TemplateModule::destroy_collection(1515			origin1.clone(),1516			collection_id1517		));1518		assert_noop!(1519			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1520			CommonError::<Test>::CollectionNotFound1521		);1522	});1523}15241525// If address is already added to allow list, nothing happens1526#[test]1527fn address_is_already_added_to_allow_list() {1528	new_test_ext().execute_with(|| {1529		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1530		let origin1 = Origin::signed(1);15311532		assert_ok!(TemplateModule::add_to_allow_list(1533			origin1.clone(),1534			collection_id,1535			account(2)1536		));1537		assert_ok!(TemplateModule::add_to_allow_list(1538			origin1,1539			collection_id,1540			account(2)1541		));1542		assert!(<pallet_common::Allowlist<Test>>::get((1543			collection_id,1544			account(2)1545		)));1546	});1547}15481549#[test]1550fn owner_can_remove_address_from_allow_list() {1551	new_test_ext().execute_with(|| {1552		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15531554		let origin1 = Origin::signed(1);1555		assert_ok!(TemplateModule::add_to_allow_list(1556			origin1.clone(),1557			collection_id,1558			account(2)1559		));1560		assert_ok!(TemplateModule::remove_from_allow_list(1561			origin1,1562			collection_id,1563			account(2)1564		));1565		assert_eq!(1566			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1567			false1568		);1569	});1570}15711572#[test]1573fn admin_can_remove_address_from_allow_list() {1574	new_test_ext().execute_with(|| {1575		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1576		let origin1 = Origin::signed(1);1577		let origin2 = Origin::signed(2);15781579		// Owner adds admin1580		assert_ok!(TemplateModule::add_collection_admin(1581			origin1.clone(),1582			collection_id,1583			account(2)1584		));15851586		// Owner adds address 3 to allow list1587		assert_ok!(TemplateModule::add_to_allow_list(1588			origin1,1589			collection_id,1590			account(3)1591		));15921593		// Admin removes address 3 from allow list1594		assert_ok!(TemplateModule::remove_from_allow_list(1595			origin2,1596			collection_id,1597			account(3)1598		));1599		assert_eq!(1600			<pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1601			false1602		);1603	});1604}16051606#[test]1607fn nonprivileged_user_cannot_remove_address_from_allow_list() {1608	new_test_ext().execute_with(|| {1609		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1610		let origin1 = Origin::signed(1);1611		let origin2 = Origin::signed(2);16121613		assert_ok!(TemplateModule::add_to_allow_list(1614			origin1,1615			collection_id,1616			account(2)1617		));1618		assert_noop!(1619			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1620			CommonError::<Test>::NoPermission1621		);1622		assert!(<pallet_common::Allowlist<Test>>::get((1623			collection_id,1624			account(2)1625		)));1626	});1627}16281629#[test]1630fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1631	new_test_ext().execute_with(|| {1632		let origin1 = Origin::signed(1);16331634		assert_noop!(1635			TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1636			CommonError::<Test>::CollectionNotFound1637		);1638	});1639}16401641#[test]1642fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1643	new_test_ext().execute_with(|| {1644		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1645		let origin1 = Origin::signed(1);1646		let origin2 = Origin::signed(2);16471648		// Add account 2 to allow list1649		assert_ok!(TemplateModule::add_to_allow_list(1650			origin1.clone(),1651			collection_id,1652			account(2)1653		));16541655		// Account 2 is in collection allow-list1656		assert!(<pallet_common::Allowlist<Test>>::get((1657			collection_id,1658			account(2)1659		)));16601661		// Destroy collection1662		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16631664		// Attempt to remove account 2 from collection allow-list => error1665		assert_noop!(1666			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1667			CommonError::<Test>::CollectionNotFound1668		);16691670		// Account 2 is not found in collection allow-list anyway1671		assert_eq!(1672			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1673			false1674		);1675	});1676}16771678// If address is already removed from allow list, nothing happens1679#[test]1680fn address_is_already_removed_from_allow_list() {1681	new_test_ext().execute_with(|| {1682		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1683		let origin1 = Origin::signed(1);16841685		assert_ok!(TemplateModule::add_to_allow_list(1686			origin1.clone(),1687			collection_id,1688			account(2)1689		));1690		assert_ok!(TemplateModule::remove_from_allow_list(1691			origin1.clone(),1692			collection_id,1693			account(2)1694		));1695		assert_eq!(1696			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1697			false1698		);1699		assert_ok!(TemplateModule::remove_from_allow_list(1700			origin1,1701			collection_id,1702			account(2)1703		));1704		assert_eq!(1705			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1706			false1707		);1708	});1709}17101711// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1712#[test]1713fn allow_list_test_1() {1714	new_test_ext().execute_with(|| {1715		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17161717		let origin1 = Origin::signed(1);17181719		let data = default_nft_data();1720		create_test_item(collection_id, &data.into());17211722		assert_ok!(TemplateModule::set_public_access_mode(1723			origin1.clone(),1724			collection_id,1725			AccessMode::AllowList1726		));1727		assert_ok!(TemplateModule::add_to_allow_list(1728			origin1.clone(),1729			collection_id,1730			account(2)1731		));17321733		assert_noop!(1734			TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1735				.map_err(|e| e.error),1736			CommonError::<Test>::AddressNotInAllowlist1737		);1738	});1739}17401741#[test]1742fn allow_list_test_2() {1743	new_test_ext().execute_with(|| {1744		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1745		let origin1 = Origin::signed(1);17461747		let data = default_nft_data();1748		create_test_item(collection_id, &data.into());17491750		assert_ok!(TemplateModule::set_public_access_mode(1751			origin1.clone(),1752			collection_id,1753			AccessMode::AllowList1754		));1755		assert_ok!(TemplateModule::add_to_allow_list(1756			origin1.clone(),1757			collection_id,1758			account(1)1759		));1760		assert_ok!(TemplateModule::add_to_allow_list(1761			origin1.clone(),1762			collection_id,1763			account(2)1764		));17651766		// do approve1767		assert_ok!(TemplateModule::approve(1768			origin1.clone(),1769			account(1),1770			collection_id,1771			TokenId(1),1772			11773		));1774		assert_eq!(1775			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1776			account(1)1777		);17781779		assert_ok!(TemplateModule::remove_from_allow_list(1780			origin1.clone(),1781			collection_id,1782			account(1)1783		));17841785		assert_noop!(1786			TemplateModule::transfer_from(1787				origin1,1788				account(1),1789				account(3),1790				CollectionId(1),1791				TokenId(1),1792				11793			)1794			.map_err(|e| e.error),1795			CommonError::<Test>::AddressNotInAllowlist1796		);1797	});1798}17991800// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1801#[test]1802fn allow_list_test_3() {1803	new_test_ext().execute_with(|| {1804		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18051806		let origin1 = Origin::signed(1);18071808		let data = default_nft_data();1809		create_test_item(collection_id, &data.into());18101811		assert_ok!(TemplateModule::set_public_access_mode(1812			origin1.clone(),1813			collection_id,1814			AccessMode::AllowList1815		));1816		assert_ok!(TemplateModule::add_to_allow_list(1817			origin1.clone(),1818			collection_id,1819			account(1)1820		));18211822		assert_noop!(1823			TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1824				.map_err(|e| e.error),1825			CommonError::<Test>::AddressNotInAllowlist1826		);1827	});1828}18291830#[test]1831fn allow_list_test_4() {1832	new_test_ext().execute_with(|| {1833		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18341835		let origin1 = Origin::signed(1);18361837		let data = default_nft_data();1838		create_test_item(collection_id, &data.into());18391840		assert_ok!(TemplateModule::set_public_access_mode(1841			origin1.clone(),1842			collection_id,1843			AccessMode::AllowList1844		));1845		assert_ok!(TemplateModule::add_to_allow_list(1846			origin1.clone(),1847			collection_id,1848			account(1)1849		));1850		assert_ok!(TemplateModule::add_to_allow_list(1851			origin1.clone(),1852			collection_id,1853			account(2)1854		));18551856		// do approve1857		assert_ok!(TemplateModule::approve(1858			origin1.clone(),1859			account(1),1860			collection_id,1861			TokenId(1),1862			11863		));1864		assert_eq!(1865			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1866			account(1)1867		);18681869		assert_ok!(TemplateModule::remove_from_allow_list(1870			origin1.clone(),1871			collection_id,1872			account(2)1873		));18741875		assert_noop!(1876			TemplateModule::transfer_from(1877				origin1,1878				account(1),1879				account(3),1880				collection_id,1881				TokenId(1),1882				11883			)1884			.map_err(|e| e.error),1885			CommonError::<Test>::AddressNotInAllowlist1886		);1887	});1888}18891890// 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)1891#[test]1892fn allow_list_test_5() {1893	new_test_ext().execute_with(|| {1894		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18951896		let origin1 = Origin::signed(1);18971898		let data = default_nft_data();1899		create_test_item(collection_id, &data.into());19001901		assert_ok!(TemplateModule::set_public_access_mode(1902			origin1.clone(),1903			collection_id,1904			AccessMode::AllowList1905		));1906		assert_noop!(1907			TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1908				.map_err(|e| e.error),1909			CommonError::<Test>::AddressNotInAllowlist1910		);1911	});1912}19131914// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1915#[test]1916fn allow_list_test_6() {1917	new_test_ext().execute_with(|| {1918		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19191920		let origin1 = Origin::signed(1);19211922		let data = default_nft_data();1923		create_test_item(collection_id, &data.into());19241925		assert_ok!(TemplateModule::set_public_access_mode(1926			origin1.clone(),1927			collection_id,1928			AccessMode::AllowList1929		));19301931		// do approve1932		assert_noop!(1933			TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1934				.map_err(|e| e.error),1935			CommonError::<Test>::AddressNotInAllowlist1936		);1937	});1938}19391940// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1941//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1942#[test]1943fn allow_list_test_7() {1944	new_test_ext().execute_with(|| {1945		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19461947		let data = default_nft_data();1948		create_test_item(collection_id, &data.into());19491950		let origin1 = Origin::signed(1);19511952		assert_ok!(TemplateModule::set_public_access_mode(1953			origin1.clone(),1954			collection_id,1955			AccessMode::AllowList1956		));1957		assert_ok!(TemplateModule::add_to_allow_list(1958			origin1.clone(),1959			collection_id,1960			account(1)1961		));1962		assert_ok!(TemplateModule::add_to_allow_list(1963			origin1.clone(),1964			collection_id,1965			account(2)1966		));19671968		assert_ok!(TemplateModule::transfer(1969			origin1,1970			account(2),1971			CollectionId(1),1972			TokenId(1),1973			11974		));1975	});1976}19771978#[test]1979fn allow_list_test_8() {1980	new_test_ext().execute_with(|| {1981		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19821983		// Create NFT for account 11984		let data = default_nft_data();1985		create_test_item(collection_id, &data.into());19861987		let origin1 = Origin::signed(1);19881989		// Toggle Allow List mode and add accounts 1 and 21990		assert_ok!(TemplateModule::set_public_access_mode(1991			origin1.clone(),1992			collection_id,1993			AccessMode::AllowList1994		));1995		assert_ok!(TemplateModule::add_to_allow_list(1996			origin1.clone(),1997			collection_id,1998			account(1)1999		));2000		assert_ok!(TemplateModule::add_to_allow_list(2001			origin1.clone(),2002			collection_id,2003			account(2)2004		));20052006		// Sself-approve account 1 for NFT 12007		assert_ok!(TemplateModule::approve(2008			origin1.clone(),2009			account(1),2010			CollectionId(1),2011			TokenId(1),2012			12013		));2014		assert_eq!(2015			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2016			account(1)2017		);20182019		// Transfer from 1 to 22020		assert_ok!(TemplateModule::transfer_from(2021			origin1,2022			account(1),2023			account(2),2024			CollectionId(1),2025			TokenId(1),2026			12027		));2028	});2029}20302031// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2032#[test]2033fn allow_list_test_9() {2034	new_test_ext().execute_with(|| {2035		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2036		let origin1 = Origin::signed(1);20372038		assert_ok!(TemplateModule::set_public_access_mode(2039			origin1.clone(),2040			collection_id,2041			AccessMode::AllowList2042		));2043		assert_ok!(TemplateModule::set_mint_permission(2044			origin1,2045			collection_id,2046			false2047		));20482049		let data = default_nft_data();2050		create_test_item(collection_id, &data.into());2051	});2052}20532054// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2055#[test]2056fn allow_list_test_10() {2057	new_test_ext().execute_with(|| {2058		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20592060		let origin1 = Origin::signed(1);2061		let origin2 = Origin::signed(2);20622063		assert_ok!(TemplateModule::set_public_access_mode(2064			origin1.clone(),2065			collection_id,2066			AccessMode::AllowList2067		));2068		assert_ok!(TemplateModule::set_mint_permission(2069			origin1.clone(),2070			collection_id,2071			false2072		));20732074		assert_ok!(TemplateModule::add_collection_admin(2075			origin1,2076			collection_id,2077			account(2)2078		));20792080		assert_ok!(TemplateModule::create_item(2081			origin2,2082			collection_id,2083			account(2),2084			default_nft_data().into()2085		));2086	});2087}20882089// 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.2090#[test]2091fn allow_list_test_11() {2092	new_test_ext().execute_with(|| {2093		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20942095		let origin1 = Origin::signed(1);2096		let origin2 = Origin::signed(2);20972098		assert_ok!(TemplateModule::set_public_access_mode(2099			origin1.clone(),2100			collection_id,2101			AccessMode::AllowList2102		));2103		assert_ok!(TemplateModule::set_mint_permission(2104			origin1.clone(),2105			collection_id,2106			false2107		));2108		assert_ok!(TemplateModule::add_to_allow_list(2109			origin1,2110			collection_id,2111			account(2)2112		));21132114		assert_noop!(2115			TemplateModule::create_item(2116				origin2,2117				CollectionId(1),2118				account(2),2119				default_nft_data().into()2120			)2121			.map_err(|e| e.error),2122			CommonError::<Test>::PublicMintingNotAllowed2123		);2124	});2125}21262127// 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.2128#[test]2129fn allow_list_test_12() {2130	new_test_ext().execute_with(|| {2131		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21322133		let origin1 = Origin::signed(1);2134		let origin2 = Origin::signed(2);21352136		assert_ok!(TemplateModule::set_public_access_mode(2137			origin1.clone(),2138			collection_id,2139			AccessMode::AllowList2140		));2141		assert_ok!(TemplateModule::set_mint_permission(2142			origin1,2143			collection_id,2144			false2145		));21462147		assert_noop!(2148			TemplateModule::create_item(2149				origin2,2150				CollectionId(1),2151				account(2),2152				default_nft_data().into()2153			)2154			.map_err(|e| e.error),2155			CommonError::<Test>::PublicMintingNotAllowed2156		);2157	});2158}21592160// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2161#[test]2162fn allow_list_test_13() {2163	new_test_ext().execute_with(|| {2164		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21652166		let origin1 = Origin::signed(1);21672168		assert_ok!(TemplateModule::set_public_access_mode(2169			origin1.clone(),2170			collection_id,2171			AccessMode::AllowList2172		));2173		assert_ok!(TemplateModule::set_mint_permission(2174			origin1,2175			collection_id,2176			true2177		));21782179		let data = default_nft_data();2180		create_test_item(collection_id, &data.into());2181	});2182}21832184// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2185#[test]2186fn allow_list_test_14() {2187	new_test_ext().execute_with(|| {2188		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21892190		let origin1 = Origin::signed(1);2191		let origin2 = Origin::signed(2);21922193		assert_ok!(TemplateModule::set_public_access_mode(2194			origin1.clone(),2195			collection_id,2196			AccessMode::AllowList2197		));2198		assert_ok!(TemplateModule::set_mint_permission(2199			origin1.clone(),2200			collection_id,2201			true2202		));22032204		assert_ok!(TemplateModule::add_collection_admin(2205			origin1,2206			collection_id,2207			account(2)2208		));22092210		assert_ok!(TemplateModule::create_item(2211			origin2,2212			collection_id,2213			account(2),2214			default_nft_data().into()2215		));2216	});2217}22182219// 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.2220#[test]2221fn allow_list_test_15() {2222	new_test_ext().execute_with(|| {2223		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22242225		let origin1 = Origin::signed(1);2226		let origin2 = Origin::signed(2);22272228		assert_ok!(TemplateModule::set_public_access_mode(2229			origin1.clone(),2230			collection_id,2231			AccessMode::AllowList2232		));2233		assert_ok!(TemplateModule::set_mint_permission(2234			origin1,2235			collection_id,2236			true2237		));22382239		assert_noop!(2240			TemplateModule::create_item(2241				origin2,2242				collection_id,2243				account(2),2244				default_nft_data().into()2245			)2246			.map_err(|e| e.error),2247			CommonError::<Test>::AddressNotInAllowlist2248		);2249	});2250}22512252// 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.2253#[test]2254fn allow_list_test_16() {2255	new_test_ext().execute_with(|| {2256		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22572258		let origin1 = Origin::signed(1);2259		let origin2 = Origin::signed(2);22602261		assert_ok!(TemplateModule::set_public_access_mode(2262			origin1.clone(),2263			collection_id,2264			AccessMode::AllowList2265		));2266		assert_ok!(TemplateModule::set_mint_permission(2267			origin1.clone(),2268			collection_id,2269			true2270		));2271		assert_ok!(TemplateModule::add_to_allow_list(2272			origin1,2273			collection_id,2274			account(2)2275		));22762277		assert_ok!(TemplateModule::create_item(2278			origin2,2279			collection_id,2280			account(2),2281			default_nft_data().into()2282		));2283	});2284}22852286// Total number of collections. Positive test2287#[test]2288fn total_number_collections_bound() {2289	new_test_ext().execute_with(|| {2290		create_test_collection(&CollectionMode::NFT, CollectionId(1));2291	});2292}22932294#[test]2295fn create_max_collections() {2296	new_test_ext().execute_with(|| {2297		for i in 1..COLLECTION_NUMBER_LIMIT {2298			create_test_collection(&CollectionMode::NFT, CollectionId(i));2299		}2300	});2301}23022303// Total number of collections. Negative test2304#[test]2305fn total_number_collections_bound_neg() {2306	new_test_ext().execute_with(|| {2307		let origin1 = Origin::signed(1);23082309		for i in 1..=COLLECTION_NUMBER_LIMIT {2310			create_test_collection(&CollectionMode::NFT, CollectionId(i));2311		}23122313		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2314		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2315		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23162317		let data: CreateCollectionData<u64> = CreateCollectionData {2318			name: col_name1.try_into().unwrap(),2319			description: col_desc1.try_into().unwrap(),2320			token_prefix: token_prefix1.try_into().unwrap(),2321			mode: CollectionMode::NFT,2322			..Default::default()2323		};23242325		// 11-th collection in chain. Expects error2326		assert_noop!(2327			TemplateModule::create_collection_ex(origin1, data),2328			CommonError::<Test>::TotalCollectionsLimitExceeded2329		);2330	});2331}23322333// Owned tokens by a single address. Positive test2334#[test]2335fn owned_tokens_bound() {2336	new_test_ext().execute_with(|| {2337		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23382339		let data = default_nft_data();2340		create_test_item(collection_id, &data.clone().into());2341		create_test_item(collection_id, &data.into());2342	});2343}23442345// Owned tokens by a single address. Negotive test2346#[test]2347fn owned_tokens_bound_neg() {2348	new_test_ext().execute_with(|| {2349		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23502351		let origin1 = Origin::signed(1);23522353		for _ in 1..=MAX_TOKEN_OWNERSHIP {2354			let data = default_nft_data();2355			create_test_item(collection_id, &data.clone().into());2356		}23572358		let data = default_nft_data();2359		assert_noop!(2360			TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2361				.map_err(|e| e.error),2362			CommonError::<Test>::AccountTokenLimitExceeded2363		);2364	});2365}23662367// Number of collection admins. Positive test2368#[test]2369fn collection_admins_bound() {2370	new_test_ext().execute_with(|| {2371		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23722373		let origin1 = Origin::signed(1);23742375		assert_ok!(TemplateModule::add_collection_admin(2376			origin1.clone(),2377			collection_id,2378			account(2)2379		));2380		assert_ok!(TemplateModule::add_collection_admin(2381			origin1,2382			collection_id,2383			account(3)2384		));2385	});2386}23872388// Number of collection admins. Negotive test2389#[test]2390fn collection_admins_bound_neg() {2391	new_test_ext().execute_with(|| {2392		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23932394		let origin1 = Origin::signed(1);23952396		for i in 0..COLLECTION_ADMINS_LIMIT {2397			assert_ok!(TemplateModule::add_collection_admin(2398				origin1.clone(),2399				collection_id,2400				account((2 + i).into())2401			));2402		}2403		assert_noop!(2404			TemplateModule::add_collection_admin(2405				origin1,2406				collection_id,2407				account((3 + COLLECTION_ADMINS_LIMIT).into())2408			),2409			CommonError::<Test>::CollectionAdminCountExceeded2410		);2411	});2412}2413// #endregion24142415#[test]2416fn set_const_on_chain_schema() {2417	new_test_ext().execute_with(|| {2418		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24192420		let origin1 = Origin::signed(1);2421		assert_ok!(TemplateModule::set_const_on_chain_schema(2422			origin1,2423			collection_id,2424			b"test const on chain schema".to_vec().try_into().unwrap()2425		));24262427		assert_eq!(2428			<pallet_common::CollectionById<Test>>::get(collection_id)2429				.unwrap()2430				.const_on_chain_schema,2431			b"test const on chain schema".to_vec()2432		);2433		assert_eq!(2434			<pallet_common::CollectionById<Test>>::get(collection_id)2435				.unwrap()2436				.variable_on_chain_schema,2437			b"".to_vec()2438		);2439	});2440}24412442#[test]2443fn set_variable_on_chain_schema() {2444	new_test_ext().execute_with(|| {2445		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24462447		let origin1 = Origin::signed(1);2448		assert_ok!(TemplateModule::set_variable_on_chain_schema(2449			origin1,2450			collection_id,2451			b"test variable on chain schema"2452				.to_vec()2453				.try_into()2454				.unwrap()2455		));24562457		assert_eq!(2458			<pallet_common::CollectionById<Test>>::get(collection_id)2459				.unwrap()2460				.const_on_chain_schema,2461			b"".to_vec()2462		);2463		assert_eq!(2464			<pallet_common::CollectionById<Test>>::get(collection_id)2465				.unwrap()2466				.variable_on_chain_schema,2467			b"test variable on chain schema".to_vec()2468		);2469	});2470}24712472#[test]2473fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2474	new_test_ext().execute_with(|| {2475		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24762477		let origin1 = Origin::signed(1);24782479		let data = default_nft_data();2480		create_test_item(CollectionId(1), &data.into());24812482		let variable_data = b"test data".to_vec();2483		assert_ok!(TemplateModule::set_variable_meta_data(2484			origin1,2485			collection_id,2486			TokenId(1),2487			variable_data.clone().try_into().unwrap()2488		));24892490		assert_eq!(2491			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2492				.unwrap()2493				.variable_data,2494			variable_data2495		);2496	});2497}24982499#[test]2500fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2501	new_test_ext().execute_with(|| {2502		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));25032504		let origin1 = Origin::signed(1);25052506		let data = default_re_fungible_data();2507		create_test_item(collection_id, &data.into());25082509		let variable_data = b"test data".to_vec();2510		assert_ok!(TemplateModule::set_variable_meta_data(2511			origin1,2512			collection_id,2513			TokenId(1),2514			variable_data.clone().try_into().unwrap()2515		));25162517		assert_eq!(2518			<pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2519			variable_data2520		);2521	});2522}25232524#[test]2525fn set_variable_meta_data_on_fungible_token_fails() {2526	new_test_ext().execute_with(|| {2527		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));25282529		let origin1 = Origin::signed(1);25302531		let data = default_fungible_data();2532		create_test_item(collection_id, &data.into());25332534		let variable_data = b"test data".to_vec();2535		assert_noop!(2536			TemplateModule::set_variable_meta_data(2537				origin1,2538				collection_id,2539				TokenId(0),2540				variable_data.try_into().unwrap()2541			)2542			.map_err(|e| e.error),2543			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2544		);2545	});2546}25472548#[test]2549fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2550	new_test_ext().execute_with(|| {2551		//default_limits();25522553		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25542555		let origin1 = Origin::signed(1);25562557		let data = default_nft_data();2558		create_test_item(collection_id, &data.into());25592560		assert_ok!(TemplateModule::set_meta_update_permission_flag(2561			origin1.clone(),2562			collection_id,2563			MetaUpdatePermission::ItemOwner,2564		));25652566		let variable_data = b"ten chars.".to_vec();2567		assert_ok!(TemplateModule::set_variable_meta_data(2568			origin1,2569			collection_id,2570			TokenId(1),2571			variable_data.clone().try_into().unwrap()2572		));25732574		assert_eq!(2575			<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2576				.unwrap()2577				.variable_data,2578			variable_data2579		);2580	});2581}25822583#[test]2584fn collection_transfer_flag_works() {2585	new_test_ext().execute_with(|| {2586		let origin1 = Origin::signed(1);25872588		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2589		assert_ok!(TemplateModule::set_transfers_enabled_flag(2590			origin1,2591			collection_id,2592			true2593		));25942595		let data = default_nft_data();2596		create_test_item(collection_id, &data.into());2597		assert_eq!(2598			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2599			12600		);2601		assert_eq!(2602			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2603			true2604		);26052606		let origin1 = Origin::signed(1);26072608		// default scenario2609		assert_ok!(TemplateModule::transfer(2610			origin1,2611			account(2),2612			collection_id,2613			TokenId(1),2614			12615		));2616		assert_eq!(2617			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2618			false2619		);2620		assert_eq!(2621			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2622			true2623		);2624		assert_eq!(2625			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2626			02627		);2628		assert_eq!(2629			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2630			12631		);2632	});2633}26342635#[test]2636fn set_variable_meta_data_on_nft_with_admin_flag() {2637	new_test_ext().execute_with(|| {2638		// default_limits();26392640		let collection_id =2641			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26422643		let origin1 = Origin::signed(1);2644		let origin2 = Origin::signed(2);26452646		assert_ok!(TemplateModule::set_mint_permission(2647			origin2.clone(),2648			collection_id,2649			true2650		));2651		assert_ok!(TemplateModule::add_to_allow_list(2652			origin2.clone(),2653			collection_id,2654			account(1)2655		));26562657		assert_ok!(TemplateModule::add_collection_admin(2658			origin2.clone(),2659			collection_id,2660			account(1)2661		));26622663		let data = default_nft_data();2664		create_test_item(collection_id, &data.into());26652666		assert_ok!(TemplateModule::set_meta_update_permission_flag(2667			origin2.clone(),2668			collection_id,2669			MetaUpdatePermission::Admin,2670		));26712672		let variable_data = b"test.".to_vec();2673		assert_ok!(TemplateModule::set_variable_meta_data(2674			origin1,2675			collection_id,2676			TokenId(1),2677			variable_data.clone().try_into().unwrap()2678		));26792680		assert_eq!(2681			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2682				.unwrap()2683				.variable_data,2684			variable_data2685		);2686	});2687}26882689#[test]2690fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2691	new_test_ext().execute_with(|| {2692		// default_limits();26932694		let collection_id =2695			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26962697		let origin1 = Origin::signed(1);2698		let origin2 = Origin::signed(2);26992700		assert_ok!(TemplateModule::set_mint_permission(2701			origin2.clone(),2702			collection_id,2703			true2704		));2705		assert_ok!(TemplateModule::add_to_allow_list(2706			origin2.clone(),2707			collection_id,2708			account(1)2709		));27102711		let data = default_nft_data();2712		create_test_item(collection_id, &data.into());27132714		assert_ok!(TemplateModule::set_meta_update_permission_flag(2715			origin2.clone(),2716			collection_id,2717			MetaUpdatePermission::Admin,2718		));27192720		let variable_data = b"test.".to_vec();2721		assert_noop!(2722			TemplateModule::set_variable_meta_data(2723				origin1,2724				collection_id,2725				TokenId(1),2726				variable_data.try_into().unwrap()2727			)2728			.map_err(|e| e.error),2729			CommonError::<Test>::NoPermission2730		);2731	});2732}27332734#[test]2735fn set_variable_meta_flag_after_freeze() {2736	new_test_ext().execute_with(|| {2737		// default_limits();27382739		let collection_id =2740			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27412742		let origin2 = Origin::signed(2);27432744		assert_ok!(TemplateModule::set_meta_update_permission_flag(2745			origin2.clone(),2746			collection_id,2747			MetaUpdatePermission::None,2748		));2749		assert_noop!(2750			TemplateModule::set_meta_update_permission_flag(2751				origin2.clone(),2752				collection_id,2753				MetaUpdatePermission::Admin2754			),2755			CommonError::<Test>::MetadataFlagFrozen2756		);2757	});2758}27592760#[test]2761fn set_variable_meta_data_on_nft_with_none_flag_neg() {2762	new_test_ext().execute_with(|| {2763		// default_limits();27642765		let collection_id =2766			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2767		let origin1 = Origin::signed(1);27682769		let data = default_nft_data();2770		create_test_item(collection_id, &data.into());27712772		assert_ok!(TemplateModule::set_meta_update_permission_flag(2773			origin1.clone(),2774			collection_id,2775			MetaUpdatePermission::None,2776		));27772778		let variable_data = b"test.".to_vec();2779		assert_noop!(2780			TemplateModule::set_variable_meta_data(2781				origin1.clone(),2782				collection_id,2783				TokenId(1),2784				variable_data.try_into().unwrap()2785			)2786			.map_err(|e| e.error),2787			CommonError::<Test>::NoPermission2788		);2789	});2790}27912792#[test]2793fn collection_transfer_flag_works_neg() {2794	new_test_ext().execute_with(|| {2795		let origin1 = Origin::signed(1);27962797		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2798		assert_ok!(TemplateModule::set_transfers_enabled_flag(2799			origin1,2800			collection_id,2801			false2802		));28032804		let data = default_nft_data();2805		create_test_item(collection_id, &data.into());2806		assert_eq!(2807			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2808			12809		);2810		assert_eq!(2811			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2812			true2813		);28142815		let origin1 = Origin::signed(1);28162817		// default scenario2818		assert_noop!(2819			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2820				.map_err(|e| e.error),2821			CommonError::<Test>::TransferNotAllowed2822		);2823		assert_eq!(2824			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2825			12826		);2827		assert_eq!(2828			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2829			02830		);2831		assert_eq!(2832			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2833			true2834		);2835		assert_eq!(2836			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2837			false2838		);2839	});2840}