git.delta.rocks / unique-network / refs/commits / 76d8b567eabc

difftreelog

Fix Refungible balance tests

Greg Zaitsev2021-11-22parent: #d8ceb96.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/mock.rsdiffbeforeafterboth
--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -10,7 +10,7 @@
 use pallet_transaction_payment::{CurrencyAdapter};
 use frame_system as system;
 use pallet_evm::AddressMapping;
-use crate::{EvmBackwardsAddressMapping, CrossAccountId};
+use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};
 use codec::{Encode, Decode};
 use scale_info::TypeInfo;
 
@@ -158,14 +158,7 @@
 }
 
 impl pallet_template::Config for Test {
-	type Event = ();
 	type WeightInfo = ();
-	type CollectionCreationPrice = CollectionCreationPrice;
-	type Currency = pallet_balances::Pallet<Test>;
-	type TreasuryAccountId = TreasuryAccountId;
-	type EvmAddressMapping = TestEvmAddressMapping;
-	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;
-	type CrossAccountId = TestCrossAccountId;
 }
 
 // Build genesis storage according to the mock runtime.
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
before · pallets/nft/src/tests.rs
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode, Ownership, CreateItemData};5use nft_data_structs::{6	CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,7	MAX_DECIMAL_POINTS,8};9use frame_support::{assert_noop, assert_ok};10use sp_std::convert::TryInto;1112fn default_nft_data() -> CreateNftData {13	CreateNftData {14		const_data: vec![1, 2, 3].try_into().unwrap(),15		variable_data: vec![3, 2, 1].try_into().unwrap(),16	}17}1819fn default_fungible_data() -> CreateFungibleData {20	CreateFungibleData { value: 5 }21}2223fn default_re_fungible_data() -> CreateReFungibleData {24	CreateReFungibleData {25		const_data: vec![1, 2, 3].try_into().unwrap(),26		variable_data: vec![3, 2, 1].try_into().unwrap(),27		pieces: 1023,28	}29}3031fn create_test_collection_for_owner(32	mode: &CollectionMode,33	owner: u64,34	id: CollectionId,35) -> CollectionId {36	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();37	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();38	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();3940	let origin1 = Origin::signed(owner);41	assert_ok!(TemplateModule::create_collection(42		origin1,43		col_name1,44		col_desc1,45		token_prefix1,46		mode.clone()47	));4849	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();50	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();51	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();52	assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);53	assert_eq!(54		TemplateModule::collection_id(id).unwrap().name,55		saved_col_name56	);57	assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);58	assert_eq!(59		TemplateModule::collection_id(id).unwrap().description,60		saved_description61	);62	assert_eq!(63		TemplateModule::collection_id(id).unwrap().token_prefix,64		saved_prefix65	);66	id67}6869fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {70	create_test_collection_for_owner(&mode, 1, id)71}7273fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {74	let origin1 = Origin::signed(1);75	assert_ok!(TemplateModule::create_item(76		origin1,77		collection_id,78		account(1),79		data.clone()80	));81}8283fn account(sub: u64) -> TestCrossAccountId {84	TestCrossAccountId::from_sub(sub)85}8687// Use cases tests region88// #region8990#[test]91fn set_version_schema() {92	new_test_ext().execute_with(|| {93		let origin1 = Origin::signed(1);94		let collection_id = create_test_collection(&CollectionMode::NFT, 1);9596		assert_ok!(TemplateModule::set_schema_version(97			origin1,98			collection_id,99			SchemaVersion::Unique100		));101		assert_eq!(102			TemplateModule::collection_id(collection_id)103				.unwrap()104				.schema_version,105			SchemaVersion::Unique106		);107	});108}109110#[test]111fn create_fungible_collection_fails_with_large_decimal_numbers() {112	new_test_ext().execute_with(|| {113		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();114		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();115		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();116117		let origin1 = Origin::signed(1);118		assert_noop!(119			TemplateModule::create_collection(120				origin1,121				col_name1,122				col_desc1,123				token_prefix1,124				CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)125			),126			Error::<Test>::CollectionDecimalPointLimitExceeded127		);128	});129}130131#[test]132fn create_nft_item() {133	new_test_ext().execute_with(|| {134		let collection_id = create_test_collection(&CollectionMode::NFT, 1);135136		let data = default_nft_data();137		create_test_item(collection_id, &data.clone().into());138		let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();139		assert_eq!(item.const_data, data.const_data.into_inner());140		assert_eq!(item.variable_data, data.variable_data.into_inner());141	});142}143144// Use cases tests region145// #region146#[test]147fn create_nft_multiple_items() {148	new_test_ext().execute_with(|| {149		create_test_collection(&CollectionMode::NFT, 1);150151		let origin1 = Origin::signed(1);152153		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];154155		assert_ok!(TemplateModule::create_multiple_items(156			origin1,157			1,158			account(1),159			items_data160				.clone()161				.into_iter()162				.map(|d| { d.into() })163				.collect()164		));165		for (index, data) in items_data.into_iter().enumerate() {166			let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap();167			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());168			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());169		}170	});171}172173#[test]174fn create_refungible_item() {175	new_test_ext().execute_with(|| {176		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);177178		let data = default_re_fungible_data();179		create_test_item(collection_id, &data.clone().into());180		let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();181		assert_eq!(item.const_data, data.const_data.into_inner());182		assert_eq!(item.variable_data, data.variable_data.into_inner());183		assert_eq!(184			item.owner[0],185			Ownership {186				owner: account(1),187				fraction: 1023188			}189		);190	});191}192193#[test]194fn create_multiple_refungible_items() {195	new_test_ext().execute_with(|| {196		create_test_collection(&CollectionMode::ReFungible, 1);197198		let origin1 = Origin::signed(1);199200		let items_data = vec![201			default_re_fungible_data(),202			default_re_fungible_data(),203			default_re_fungible_data(),204		];205206		assert_ok!(TemplateModule::create_multiple_items(207			origin1,208			1,209			account(1),210			items_data211				.clone()212				.into_iter()213				.map(|d| { d.into() })214				.collect()215		));216		for (index, data) in items_data.into_iter().enumerate() {217			let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();218			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());219			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());220			assert_eq!(221				item.owner[0],222				Ownership {223					owner: account(1),224					fraction: 1023225				}226			);227		}228	});229}230231#[test]232fn create_fungible_item() {233	new_test_ext().execute_with(|| {234		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);235236		let data = default_fungible_data();237		create_test_item(collection_id, &data.into());238239		assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);240	});241}242243//#[test]244// fn create_multiple_fungible_items() {245//     new_test_ext().execute_with(|| {246//         default_limits();247248//         create_test_collection(&CollectionMode::Fungible(3), 1);249250//         let origin1 = Origin::signed(1);251252//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];253254//         assert_ok!(TemplateModule::create_multiple_items(255//             origin1.clone(),256//             1,257//             1,258//             items_data.clone().into_iter().map(|d| { d.into() }).collect()259//         ));260261//         for (index, _) in items_data.iter().enumerate() {262//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);263//         }264//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);265//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);266//     });267// }268269#[test]270fn transfer_fungible_item() {271	new_test_ext().execute_with(|| {272		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);273274		let origin1 = Origin::signed(1);275		let origin2 = Origin::signed(2);276277		let data = default_fungible_data();278		create_test_item(collection_id, &data.into());279280		assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);281		assert_eq!(TemplateModule::balance_count(1, 1), 5);282283		// change owner scenario284		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 5));285		assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);286		assert_eq!(TemplateModule::balance_count(1, 1), 0);287		assert_eq!(TemplateModule::balance_count(1, 2), 5);288289		// split item scenario290		assert_ok!(TemplateModule::transfer(291			origin2.clone(),292			account(3),293			1,294			1,295			3296		));297		assert_eq!(TemplateModule::balance_count(1, 2), 2);298		assert_eq!(TemplateModule::balance_count(1, 3), 3);299300		// split item and new owner has account scenario301		assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 1));302		assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);303		assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);304		assert_eq!(TemplateModule::balance_count(1, 2), 1);305		assert_eq!(TemplateModule::balance_count(1, 3), 4);306	});307}308309#[test]310fn transfer_refungible_item() {311	new_test_ext().execute_with(|| {312		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);313314		let data = default_re_fungible_data();315		create_test_item(collection_id, &data.clone().into());316317		let origin1 = Origin::signed(1);318		let origin2 = Origin::signed(2);319		{320			let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();321			assert_eq!(item.const_data, data.const_data.into_inner());322			assert_eq!(item.variable_data, data.variable_data.into_inner());323			assert_eq!(324				item.owner[0],325				Ownership {326					owner: account(1),327					fraction: 1023328				}329			);330		}331		assert_eq!(TemplateModule::balance_count(1, 1), 1023);332		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);333334		// change owner scenario335		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));336		assert_eq!(337			TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],338			Ownership {339				owner: account(2),340				fraction: 1023341			}342		);343		assert_eq!(TemplateModule::balance_count(1, 1), 0);344		assert_eq!(TemplateModule::balance_count(1, 2), 1023);345		// assert_eq!(TemplateModule::address_tokens(1, 1), []);346		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);347348		// split item scenario349		assert_ok!(TemplateModule::transfer(350			origin2.clone(),351			account(3),352			1,353			1,354			500355		));356		{357			let item = TemplateModule::refungible_item_id(1, 1).unwrap();358			assert_eq!(359				item.owner[0],360				Ownership {361					owner: account(2),362					fraction: 523363				}364			);365			assert_eq!(366				item.owner[1],367				Ownership {368					owner: account(3),369					fraction: 500370				}371			);372		}373		assert_eq!(TemplateModule::balance_count(1, 2), 523);374		assert_eq!(TemplateModule::balance_count(1, 3), 500);375		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);376		assert_eq!(TemplateModule::address_tokens(1, 3), [1]);377378		// split item and new owner has account scenario379		assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));380		{381			let item = TemplateModule::refungible_item_id(1, 1).unwrap();382			assert_eq!(383				item.owner[0],384				Ownership {385					owner: account(2),386					fraction: 323387				}388			);389			assert_eq!(390				item.owner[1],391				Ownership {392					owner: account(3),393					fraction: 700394				}395			);396		}397		assert_eq!(TemplateModule::balance_count(1, 2), 323);398		assert_eq!(TemplateModule::balance_count(1, 3), 700);399		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);400		assert_eq!(TemplateModule::address_tokens(1, 3), [1]);401	});402}403404#[test]405fn transfer_nft_item() {406	new_test_ext().execute_with(|| {407		let collection_id = create_test_collection(&CollectionMode::NFT, 1);408409		let data = default_nft_data();410		create_test_item(collection_id, &data.into());411		assert_eq!(TemplateModule::balance_count(1, 1), 1);412		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);413414		let origin1 = Origin::signed(1);415		// default scenario416		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));417		assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));418		assert_eq!(TemplateModule::balance_count(1, 1), 0);419		assert_eq!(TemplateModule::balance_count(1, 2), 1);420		// assert_eq!(TemplateModule::address_tokens(1, 1), []);421		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);422	});423}424425#[test]426fn nft_approve_and_transfer_from() {427	new_test_ext().execute_with(|| {428		let collection_id = create_test_collection(&CollectionMode::NFT, 1);429430		let data = default_nft_data();431		create_test_item(collection_id, &data.into());432433		let origin1 = Origin::signed(1);434		let origin2 = Origin::signed(2);435436		assert_eq!(TemplateModule::balance_count(1, 1), 1);437		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);438439		// neg transfer440		assert_noop!(441			TemplateModule::transfer_from(origin2.clone(), account(1), account(2), 1, 1, 1),442			Error::<Test>::NoPermission443		);444445		// do approve446		assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 5));447		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);448		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);449450		assert_ok!(TemplateModule::transfer_from(451			origin2,452			account(1),453			account(3),454			1,455			1,456			1457		));458		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);459	});460}461462#[test]463fn nft_approve_and_transfer_from_allow_list() {464	new_test_ext().execute_with(|| {465		let collection_id = create_test_collection(&CollectionMode::NFT, 1);466467		let origin1 = Origin::signed(1);468		let origin2 = Origin::signed(2);469470		let data = default_nft_data();471		create_test_item(collection_id, &data.clone().into());472473		assert_eq!(474			&TemplateModule::nft_item_id(1, 1).unwrap().const_data,475			&data.const_data.into_inner()476		);477		assert_eq!(TemplateModule::balance_count(1, 1), 1);478		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);479480		assert_ok!(TemplateModule::set_mint_permission(481			origin1.clone(),482			1,483			true484		));485		assert_ok!(TemplateModule::set_public_access_mode(486			origin1.clone(),487			1,488			AccessMode::AllowList489		));490		assert_ok!(TemplateModule::add_to_allow_list(491			origin1.clone(),492			1,493			account(1)494		));495		assert_ok!(TemplateModule::add_to_allow_list(496			origin1.clone(),497			1,498			account(2)499		));500		assert_ok!(TemplateModule::add_to_allow_list(501			origin1.clone(),502			1,503			account(3)504		));505506		// do approve507		assert_ok!(TemplateModule::approve(508			origin1.clone(),509			account(2),510			1,511			1,512			5513		));514		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);515		assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));516		assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);517518		assert_ok!(TemplateModule::transfer_from(519			origin2,520			account(1),521			account(3),522			1,523			1,524			1525		));526		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);527	});528}529530#[test]531fn refungible_approve_and_transfer_from() {532	new_test_ext().execute_with(|| {533		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);534535		let origin1 = Origin::signed(1);536		let origin2 = Origin::signed(2);537538		let data = default_re_fungible_data();539		create_test_item(collection_id, &data.into());540541		assert_eq!(TemplateModule::balance_count(1, 1), 1023);542		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);543544		assert_ok!(TemplateModule::set_mint_permission(545			origin1.clone(),546			1,547			true548		));549		assert_ok!(TemplateModule::set_public_access_mode(550			origin1.clone(),551			1,552			AccessMode::AllowList553		));554		assert_ok!(TemplateModule::add_to_allow_list(555			origin1.clone(),556			1,557			account(1)558		));559		assert_ok!(TemplateModule::add_to_allow_list(560			origin1.clone(),561			1,562			account(2)563		));564		assert_ok!(TemplateModule::add_to_allow_list(565			origin1.clone(),566			1,567			account(3)568		));569570		// do approve571		assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1023));572		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);573574		assert_ok!(TemplateModule::transfer_from(575			origin2,576			account(1),577			account(3),578			1,579			1,580			100581		));582		assert_eq!(TemplateModule::balance_count(1, 1), 923);583		assert_eq!(TemplateModule::balance_count(1, 3), 100);584		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);585		assert_eq!(TemplateModule::address_tokens(1, 3), [1]);586587		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 923);588	});589}590591#[test]592fn fungible_approve_and_transfer_from() {593	new_test_ext().execute_with(|| {594		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);595596		let data = default_fungible_data();597		create_test_item(collection_id, &data.into());598599		let origin1 = Origin::signed(1);600		let origin2 = Origin::signed(2);601602		assert_eq!(TemplateModule::balance_count(1, 1), 5);603604		assert_ok!(TemplateModule::set_mint_permission(605			origin1.clone(),606			1,607			true608		));609		assert_ok!(TemplateModule::set_public_access_mode(610			origin1.clone(),611			1,612			AccessMode::AllowList613		));614		assert_ok!(TemplateModule::add_to_allow_list(615			origin1.clone(),616			1,617			account(1)618		));619		assert_ok!(TemplateModule::add_to_allow_list(620			origin1.clone(),621			1,622			account(2)623		));624		assert_ok!(TemplateModule::add_to_allow_list(625			origin1.clone(),626			1,627			account(3)628		));629630		// do approve631		assert_ok!(TemplateModule::approve(632			origin1.clone(),633			account(2),634			1,635			1,636			5637		));638		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);639		assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));640		assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);641		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);642643		assert_ok!(TemplateModule::transfer_from(644			origin2.clone(),645			account(1),646			account(3),647			1,648			1,649			4650		));651		assert_eq!(TemplateModule::balance_count(1, 1), 1);652		assert_eq!(TemplateModule::balance_count(1, 3), 4);653654		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);655656		assert_noop!(657			TemplateModule::transfer_from(origin2, account(1), account(3), 1, 1, 4),658			Error::<Test>::NoPermission659		);660	});661}662663#[test]664fn change_collection_owner() {665	new_test_ext().execute_with(|| {666		let collection_id = create_test_collection(&CollectionMode::NFT, 1);667668		let origin1 = Origin::signed(1);669		assert_ok!(TemplateModule::change_collection_owner(670			origin1,671			collection_id,672			2673		));674		assert_eq!(675			TemplateModule::collection_id(collection_id).unwrap().owner,676			2677		);678	});679}680681#[test]682fn destroy_collection() {683	new_test_ext().execute_with(|| {684		let collection_id = create_test_collection(&CollectionMode::NFT, 1);685686		let origin1 = Origin::signed(1);687		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));688	});689}690691#[test]692fn burn_nft_item() {693	new_test_ext().execute_with(|| {694		let collection_id = create_test_collection(&CollectionMode::NFT, 1);695696		let origin1 = Origin::signed(1);697		assert_ok!(TemplateModule::add_collection_admin(698			origin1.clone(),699			collection_id,700			account(2)701		));702703		let data = default_nft_data();704		create_test_item(collection_id, &data.into());705706		// check balance (collection with id = 1, user id = 1)707		assert_eq!(TemplateModule::balance_count(1, 1), 1);708709		// burn item710		assert_ok!(TemplateModule::burn_item(711			origin1.clone(),712			collection_id,713			1,714			1715		));716		assert_noop!(717			TemplateModule::burn_item(origin1, collection_id, 1, 1),718			Error::<Test>::TokenNotFound719		);720721		assert_eq!(TemplateModule::balance_count(1, 1), 0);722	});723}724725#[test]726fn burn_fungible_item() {727	new_test_ext().execute_with(|| {728		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);729730		let origin1 = Origin::signed(1);731		assert_ok!(TemplateModule::add_collection_admin(732			origin1.clone(),733			collection_id,734			account(2)735		));736737		let data = default_fungible_data();738		create_test_item(collection_id, &data.into());739740		// check balance (collection with id = 1, user id = 1)741		assert_eq!(TemplateModule::balance_count(1, 1), 5);742743		// burn item744		assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));745		assert_noop!(746			TemplateModule::burn_item(origin1, 1, 1, 5),747			Error::<Test>::TokenValueNotEnough748		);749750		assert_eq!(TemplateModule::balance_count(1, 1), 0);751	});752}753754#[test]755fn burn_refungible_item() {756	new_test_ext().execute_with(|| {757		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);758		let origin1 = Origin::signed(1);759760		assert_ok!(TemplateModule::set_mint_permission(761			origin1.clone(),762			collection_id,763			true764		));765		assert_ok!(TemplateModule::set_public_access_mode(766			origin1.clone(),767			collection_id,768			AccessMode::AllowList769		));770		assert_ok!(TemplateModule::add_to_allow_list(771			origin1.clone(),772			1,773			account(1)774		));775776		assert_ok!(TemplateModule::add_collection_admin(777			origin1.clone(),778			1,779			account(2)780		));781782		let data = default_re_fungible_data();783		create_test_item(collection_id, &data.into());784785		// check balance (collection with id = 1, user id = 2)786		assert_eq!(TemplateModule::balance_count(1, 1), 1023);787788		// burn item789		assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));790		assert_noop!(791			TemplateModule::burn_item(origin1, 1, 1, 1023),792			Error::<Test>::TokenNotFound793		);794795		assert_eq!(TemplateModule::balance_count(1, 1), 0);796	});797}798799#[test]800fn add_collection_admin() {801	new_test_ext().execute_with(|| {802		let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);803		create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);804		create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);805806		let origin1 = Origin::signed(1);807808		// collection admin809		assert_ok!(TemplateModule::add_collection_admin(810			origin1.clone(),811			collection1_id,812			account(2)813		));814		assert_ok!(TemplateModule::add_collection_admin(815			origin1,816			collection1_id,817			account(3)818		));819820		assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)),);821		assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)),);822	});823}824825#[test]826fn remove_collection_admin() {827	new_test_ext().execute_with(|| {828		let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);829		create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);830		create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);831832		let origin1 = Origin::signed(1);833		let origin2 = Origin::signed(2);834835		// collection admin836		assert_ok!(TemplateModule::add_collection_admin(837			origin1.clone(),838			collection1_id,839			account(2)840		));841		assert_ok!(TemplateModule::add_collection_admin(842			origin1,843			collection1_id,844			account(3)845		));846847		assert!(TemplateModule::admin_list_collection(1).contains(&account(2)),);848		assert!(TemplateModule::admin_list_collection(1).contains(&account(3)),);849850		// remove admin851		assert_ok!(TemplateModule::remove_collection_admin(852			origin2,853			1,854			account(3)855		));856		assert!(!TemplateModule::admin_list_collection(1).contains(&account(3)),);857	});858}859860#[test]861fn balance_of() {862	new_test_ext().execute_with(|| {863		let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);864		let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);865		let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);866867		// check balance before868		assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);869		assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);870		assert_eq!(871			TemplateModule::balance_count(re_fungible_collection_id, 1),872			0873		);874875		let nft_data = default_nft_data();876		create_test_item(nft_collection_id, &nft_data.into());877878		let fungible_data = default_fungible_data();879		create_test_item(fungible_collection_id, &fungible_data.into());880881		let re_fungible_data = default_re_fungible_data();882		create_test_item(re_fungible_collection_id, &re_fungible_data.into());883884		// check balance (collection with id = 1, user id = 1)885		assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);886		assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);887		assert_eq!(888			TemplateModule::balance_count(re_fungible_collection_id, 1),889			1023890		);891		assert_eq!(892			TemplateModule::nft_item_id(nft_collection_id, 1)893				.unwrap()894				.owner,895			account(1)896		);897		assert_eq!(898			TemplateModule::fungible_item_id(fungible_collection_id, 1).value,899			5900		);901		assert_eq!(902			TemplateModule::refungible_item_id(re_fungible_collection_id, 1)903				.unwrap()904				.owner[0]905				.owner,906			account(1)907		);908	});909}910911#[test]912fn approve() {913	new_test_ext().execute_with(|| {914		let collection_id = create_test_collection(&CollectionMode::NFT, 1);915916		let data = default_nft_data();917		create_test_item(collection_id, &data.into());918919		let origin1 = Origin::signed(1);920921		// approve922		assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1));923		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);924	});925}926927#[test]928fn transfer_from() {929	new_test_ext().execute_with(|| {930		let collection_id = create_test_collection(&CollectionMode::NFT, 1);931		let origin1 = Origin::signed(1);932		let origin2 = Origin::signed(2);933934		let data = default_nft_data();935		create_test_item(collection_id, &data.into());936937		// approve938		assert_ok!(TemplateModule::approve(939			origin1.clone(),940			account(2),941			1,942			1,943			1944		));945		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);946947		assert_ok!(TemplateModule::set_mint_permission(948			origin1.clone(),949			1,950			true951		));952		assert_ok!(TemplateModule::set_public_access_mode(953			origin1.clone(),954			1,955			AccessMode::AllowList956		));957		assert_ok!(TemplateModule::add_to_allow_list(958			origin1.clone(),959			1,960			account(1)961		));962		assert_ok!(TemplateModule::add_to_allow_list(963			origin1.clone(),964			1,965			account(2)966		));967		assert_ok!(TemplateModule::add_to_allow_list(origin1, 1, account(3)));968969		assert_ok!(TemplateModule::transfer_from(970			origin2,971			account(1),972			account(2),973			1,974			1,975			1976		));977978		// after transfer979		assert_eq!(TemplateModule::balance_count(1, 1), 0);980		assert_eq!(TemplateModule::balance_count(1, 2), 1);981	});982}983984// #endregion985986// Coverage tests region987// #region988989#[test]990fn owner_can_add_address_to_allow_list() {991	new_test_ext().execute_with(|| {992		let collection_id = create_test_collection(&CollectionMode::NFT, 1);993994		let origin1 = Origin::signed(1);995		assert_ok!(TemplateModule::add_to_allow_list(996			origin1,997			collection_id,998			account(2)999		));1000		assert!(TemplateModule::allow_list(collection_id, 2));1001	});1002}10031004#[test]1005fn admin_can_add_address_to_allow_list() {1006	new_test_ext().execute_with(|| {1007		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1008		let origin1 = Origin::signed(1);1009		let origin2 = Origin::signed(2);10101011		assert_ok!(TemplateModule::add_collection_admin(1012			origin1,1013			collection_id,1014			account(2)1015		));1016		assert_ok!(TemplateModule::add_to_allow_list(1017			origin2,1018			collection_id,1019			account(3)1020		));1021		assert!(TemplateModule::allow_list(collection_id, 3));1022	});1023}10241025#[test]1026fn nonprivileged_user_cannot_add_address_to_allow_list() {1027	new_test_ext().execute_with(|| {1028		let collection_id = create_test_collection(&CollectionMode::NFT, 1);10291030		let origin2 = Origin::signed(2);1031		assert_noop!(1032			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1033			Error::<Test>::NoPermission1034		);1035	});1036}10371038#[test]1039fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1040	new_test_ext().execute_with(|| {1041		let origin1 = Origin::signed(1);10421043		assert_noop!(1044			TemplateModule::add_to_allow_list(origin1, 1, account(2)),1045			Error::<Test>::CollectionNotFound1046		);1047	});1048}10491050#[test]1051fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1052	new_test_ext().execute_with(|| {1053		let collection_id = create_test_collection(&CollectionMode::NFT, 1);10541055		let origin1 = Origin::signed(1);1056		assert_ok!(TemplateModule::destroy_collection(1057			origin1.clone(),1058			collection_id1059		));1060		assert_noop!(1061			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1062			Error::<Test>::CollectionNotFound1063		);1064	});1065}10661067// If address is already added to allow list, nothing happens1068#[test]1069fn address_is_already_added_to_allow_list() {1070	new_test_ext().execute_with(|| {1071		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1072		let origin1 = Origin::signed(1);10731074		assert_ok!(TemplateModule::add_to_allow_list(1075			origin1.clone(),1076			collection_id,1077			account(2)1078		));1079		assert_ok!(TemplateModule::add_to_allow_list(1080			origin1,1081			collection_id,1082			account(2)1083		));1084		assert!(TemplateModule::allow_list(collection_id, 2));1085	});1086}10871088#[test]1089fn owner_can_remove_address_from_allow_list() {1090	new_test_ext().execute_with(|| {1091		let collection_id = create_test_collection(&CollectionMode::NFT, 1);10921093		let origin1 = Origin::signed(1);1094		assert_ok!(TemplateModule::add_to_allow_list(1095			origin1.clone(),1096			collection_id,1097			account(2)1098		));1099		assert_ok!(TemplateModule::remove_from_allow_list(1100			origin1,1101			collection_id,1102			account(2)1103		));1104		assert!(!TemplateModule::allow_list(collection_id, 2));1105	});1106}11071108#[test]1109fn admin_can_remove_address_from_allow_list() {1110	new_test_ext().execute_with(|| {1111		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1112		let origin1 = Origin::signed(1);1113		let origin2 = Origin::signed(2);11141115		assert_ok!(TemplateModule::add_collection_admin(1116			origin1.clone(),1117			collection_id,1118			account(2)1119		));11201121		assert_ok!(TemplateModule::add_to_allow_list(1122			origin1,1123			collection_id,1124			account(3)1125		));1126		assert_ok!(TemplateModule::remove_from_allow_list(1127			origin2,1128			collection_id,1129			account(3)1130		));1131		assert!(!TemplateModule::allow_list(collection_id, 3));1132	});1133}11341135#[test]1136fn nonprivileged_user_cannot_remove_address_from_allow_list() {1137	new_test_ext().execute_with(|| {1138		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1139		let origin1 = Origin::signed(1);1140		let origin2 = Origin::signed(2);11411142		assert_ok!(TemplateModule::add_to_allow_list(1143			origin1,1144			collection_id,1145			account(2)1146		));1147		assert_noop!(1148			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1149			Error::<Test>::NoPermission1150		);1151		assert!(TemplateModule::allow_list(collection_id, 2));1152	});1153}11541155#[test]1156fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1157	new_test_ext().execute_with(|| {1158		let origin1 = Origin::signed(1);11591160		assert_noop!(1161			TemplateModule::remove_from_allow_list(origin1, 1, account(2)),1162			Error::<Test>::CollectionNotFound1163		);1164	});1165}11661167#[test]1168fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1169	new_test_ext().execute_with(|| {1170		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1171		let origin1 = Origin::signed(1);1172		let origin2 = Origin::signed(2);11731174		assert_ok!(TemplateModule::add_to_allow_list(1175			origin1.clone(),1176			collection_id,1177			account(2)1178		));1179		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1180		assert_noop!(1181			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1182			Error::<Test>::CollectionNotFound1183		);1184		assert!(!TemplateModule::allow_list(collection_id, 2));1185	});1186}11871188// If address is already removed from allow list, nothing happens1189#[test]1190fn address_is_already_removed_from_allow_list() {1191	new_test_ext().execute_with(|| {1192		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1193		let origin1 = Origin::signed(1);11941195		assert_ok!(TemplateModule::add_to_allow_list(1196			origin1.clone(),1197			collection_id,1198			account(2)1199		));1200		assert_ok!(TemplateModule::remove_from_allow_list(1201			origin1.clone(),1202			collection_id,1203			account(2)1204		));1205		assert_ok!(TemplateModule::remove_from_allow_list(1206			origin1,1207			collection_id,1208			account(2)1209		));1210		assert!(!TemplateModule::allow_list(collection_id, 2));1211	});1212}12131214// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1215#[test]1216fn allow_list_test_1() {1217	new_test_ext().execute_with(|| {1218		let collection_id = create_test_collection(&CollectionMode::NFT, 1);12191220		let origin1 = Origin::signed(1);12211222		let data = default_nft_data();1223		create_test_item(collection_id, &data.into());12241225		assert_ok!(TemplateModule::set_public_access_mode(1226			origin1.clone(),1227			collection_id,1228			AccessMode::AllowList1229		));1230		assert_ok!(TemplateModule::add_to_allow_list(1231			origin1.clone(),1232			collection_id,1233			account(2)1234		));12351236		assert_noop!(1237			TemplateModule::transfer(origin1, account(3), 1, 1, 1),1238			Error::<Test>::AddresNotInAllowList1239		);1240	});1241}12421243#[test]1244fn allow_list_test_2() {1245	new_test_ext().execute_with(|| {1246		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1247		let origin1 = Origin::signed(1);12481249		let data = default_nft_data();1250		create_test_item(collection_id, &data.into());12511252		assert_ok!(TemplateModule::set_public_access_mode(1253			origin1.clone(),1254			collection_id,1255			AccessMode::AllowList1256		));1257		assert_ok!(TemplateModule::add_to_allow_list(1258			origin1.clone(),1259			1,1260			account(1)1261		));1262		assert_ok!(TemplateModule::add_to_allow_list(1263			origin1.clone(),1264			1,1265			account(2)1266		));12671268		// do approve1269		assert_ok!(TemplateModule::approve(1270			origin1.clone(),1271			account(1),1272			1,1273			1,1274			11275		));1276		assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);12771278		assert_ok!(TemplateModule::remove_from_allow_list(1279			origin1.clone(),1280			1,1281			account(1)1282		));12831284		assert_noop!(1285			TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1286			Error::<Test>::AddresNotInAllowList1287		);1288	});1289}12901291// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1292#[test]1293fn allow_list_test_3() {1294	new_test_ext().execute_with(|| {1295		let collection_id = create_test_collection(&CollectionMode::NFT, 1);12961297		let origin1 = Origin::signed(1);12981299		let data = default_nft_data();1300		create_test_item(collection_id, &data.into());13011302		assert_ok!(TemplateModule::set_public_access_mode(1303			origin1.clone(),1304			collection_id,1305			AccessMode::AllowList1306		));1307		assert_ok!(TemplateModule::add_to_allow_list(1308			origin1.clone(),1309			1,1310			account(1)1311		));13121313		assert_noop!(1314			TemplateModule::transfer(origin1, account(3), 1, 1, 1),1315			Error::<Test>::AddresNotInAllowList1316		);1317	});1318}13191320#[test]1321fn allow_list_test_4() {1322	new_test_ext().execute_with(|| {1323		let collection_id = create_test_collection(&CollectionMode::NFT, 1);13241325		let origin1 = Origin::signed(1);13261327		let data = default_nft_data();1328		create_test_item(collection_id, &data.into());13291330		assert_ok!(TemplateModule::set_public_access_mode(1331			origin1.clone(),1332			collection_id,1333			AccessMode::AllowList1334		));1335		assert_ok!(TemplateModule::add_to_allow_list(1336			origin1.clone(),1337			collection_id,1338			account(1)1339		));1340		assert_ok!(TemplateModule::add_to_allow_list(1341			origin1.clone(),1342			collection_id,1343			account(2)1344		));13451346		// do approve1347		assert_ok!(TemplateModule::approve(1348			origin1.clone(),1349			account(1),1350			1,1351			1,1352			11353		));1354		assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);13551356		assert_ok!(TemplateModule::remove_from_allow_list(1357			origin1.clone(),1358			collection_id,1359			account(2)1360		));13611362		assert_noop!(1363			TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1364			Error::<Test>::AddresNotInAllowList1365		);1366	});1367}13681369// 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)1370#[test]1371fn allow_list_test_5() {1372	new_test_ext().execute_with(|| {1373		let collection_id = create_test_collection(&CollectionMode::NFT, 1);13741375		let origin1 = Origin::signed(1);13761377		let data = default_nft_data();1378		create_test_item(collection_id, &data.into());13791380		assert_ok!(TemplateModule::set_public_access_mode(1381			origin1.clone(),1382			collection_id,1383			AccessMode::AllowList1384		));1385		assert_noop!(1386			TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1387			Error::<Test>::AddresNotInAllowList1388		);1389	});1390}13911392// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1393#[test]1394fn allow_list_test_6() {1395	new_test_ext().execute_with(|| {1396		let collection_id = create_test_collection(&CollectionMode::NFT, 1);13971398		let origin1 = Origin::signed(1);13991400		let data = default_nft_data();1401		create_test_item(collection_id, &data.into());14021403		assert_ok!(TemplateModule::set_public_access_mode(1404			origin1.clone(),1405			collection_id,1406			AccessMode::AllowList1407		));14081409		// do approve1410		assert_noop!(1411			TemplateModule::approve(origin1, account(1), 1, 1, 5),1412			Error::<Test>::AddresNotInAllowList1413		);1414	});1415}14161417// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1418//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1419#[test]1420fn allow_list_test_7() {1421	new_test_ext().execute_with(|| {1422		let collection_id = create_test_collection(&CollectionMode::NFT, 1);14231424		let data = default_nft_data();1425		create_test_item(collection_id, &data.into());14261427		let origin1 = Origin::signed(1);14281429		assert_ok!(TemplateModule::set_public_access_mode(1430			origin1.clone(),1431			collection_id,1432			AccessMode::AllowList1433		));1434		assert_ok!(TemplateModule::add_to_allow_list(1435			origin1.clone(),1436			collection_id,1437			account(1)1438		));1439		assert_ok!(TemplateModule::add_to_allow_list(1440			origin1.clone(),1441			collection_id,1442			account(2)1443		));14441445		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1));1446	});1447}14481449#[test]1450fn allow_list_test_8() {1451	new_test_ext().execute_with(|| {1452		let collection_id = create_test_collection(&CollectionMode::NFT, 1);14531454		let data = default_nft_data();1455		create_test_item(collection_id, &data.into());14561457		let origin1 = Origin::signed(1);14581459		assert_ok!(TemplateModule::set_public_access_mode(1460			origin1.clone(),1461			collection_id,1462			AccessMode::AllowList1463		));1464		assert_ok!(TemplateModule::add_to_allow_list(1465			origin1.clone(),1466			collection_id,1467			account(1)1468		));1469		assert_ok!(TemplateModule::add_to_allow_list(1470			origin1.clone(),1471			collection_id,1472			account(2)1473		));14741475		// do approve1476		assert_ok!(TemplateModule::approve(1477			origin1.clone(),1478			account(1),1479			1,1480			1,1481			51482		));1483		assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);14841485		assert_ok!(TemplateModule::transfer_from(1486			origin1,1487			account(1),1488			account(2),1489			1,1490			1,1491			11492		));1493	});1494}14951496// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.1497#[test]1498fn allow_list_test_9() {1499	new_test_ext().execute_with(|| {1500		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1501		let origin1 = Origin::signed(1);15021503		assert_ok!(TemplateModule::set_public_access_mode(1504			origin1.clone(),1505			collection_id,1506			AccessMode::AllowList1507		));1508		assert_ok!(TemplateModule::set_mint_permission(1509			origin1,1510			collection_id,1511			false1512		));15131514		let data = default_nft_data();1515		create_test_item(collection_id, &data.into());1516	});1517}15181519// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.1520#[test]1521fn allow_list_test_10() {1522	new_test_ext().execute_with(|| {1523		let collection_id = create_test_collection(&CollectionMode::NFT, 1);15241525		let origin1 = Origin::signed(1);1526		let origin2 = Origin::signed(2);15271528		assert_ok!(TemplateModule::set_public_access_mode(1529			origin1.clone(),1530			collection_id,1531			AccessMode::AllowList1532		));1533		assert_ok!(TemplateModule::set_mint_permission(1534			origin1.clone(),1535			collection_id,1536			false1537		));15381539		assert_ok!(TemplateModule::add_collection_admin(1540			origin1,1541			collection_id,1542			account(2)1543		));15441545		assert_ok!(TemplateModule::create_item(1546			origin2,1547			collection_id,1548			account(2),1549			default_nft_data().into()1550		));1551	});1552}15531554// 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.1555#[test]1556fn allow_list_test_11() {1557	new_test_ext().execute_with(|| {1558		let collection_id = create_test_collection(&CollectionMode::NFT, 1);15591560		let origin1 = Origin::signed(1);1561		let origin2 = Origin::signed(2);15621563		assert_ok!(TemplateModule::set_public_access_mode(1564			origin1.clone(),1565			collection_id,1566			AccessMode::AllowList1567		));1568		assert_ok!(TemplateModule::set_mint_permission(1569			origin1.clone(),1570			collection_id,1571			false1572		));1573		assert_ok!(TemplateModule::add_to_allow_list(1574			origin1,1575			collection_id,1576			account(2)1577		));15781579		assert_noop!(1580			TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1581			Error::<Test>::PublicMintingNotAllowed1582		);1583	});1584}15851586// 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.1587#[test]1588fn allow_list_test_12() {1589	new_test_ext().execute_with(|| {1590		let collection_id = create_test_collection(&CollectionMode::NFT, 1);15911592		let origin1 = Origin::signed(1);1593		let origin2 = Origin::signed(2);15941595		assert_ok!(TemplateModule::set_public_access_mode(1596			origin1.clone(),1597			collection_id,1598			AccessMode::AllowList1599		));1600		assert_ok!(TemplateModule::set_mint_permission(1601			origin1,1602			collection_id,1603			false1604		));16051606		assert_noop!(1607			TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1608			Error::<Test>::PublicMintingNotAllowed1609		);1610	});1611}16121613// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.1614#[test]1615fn allow_list_test_13() {1616	new_test_ext().execute_with(|| {1617		let collection_id = create_test_collection(&CollectionMode::NFT, 1);16181619		let origin1 = Origin::signed(1);16201621		assert_ok!(TemplateModule::set_public_access_mode(1622			origin1.clone(),1623			collection_id,1624			AccessMode::AllowList1625		));1626		assert_ok!(TemplateModule::set_mint_permission(1627			origin1,1628			collection_id,1629			true1630		));16311632		let data = default_nft_data();1633		create_test_item(collection_id, &data.into());1634	});1635}16361637// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.1638#[test]1639fn allow_list_test_14() {1640	new_test_ext().execute_with(|| {1641		let collection_id = create_test_collection(&CollectionMode::NFT, 1);16421643		let origin1 = Origin::signed(1);1644		let origin2 = Origin::signed(2);16451646		assert_ok!(TemplateModule::set_public_access_mode(1647			origin1.clone(),1648			collection_id,1649			AccessMode::AllowList1650		));1651		assert_ok!(TemplateModule::set_mint_permission(1652			origin1.clone(),1653			collection_id,1654			true1655		));16561657		assert_ok!(TemplateModule::add_collection_admin(1658			origin1,1659			collection_id,1660			account(2)1661		));16621663		assert_ok!(TemplateModule::create_item(1664			origin2,1665			1,1666			account(2),1667			default_nft_data().into()1668		));1669	});1670}16711672// 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.1673#[test]1674fn allow_list_test_15() {1675	new_test_ext().execute_with(|| {1676		let collection_id = create_test_collection(&CollectionMode::NFT, 1);16771678		let origin1 = Origin::signed(1);1679		let origin2 = Origin::signed(2);16801681		assert_ok!(TemplateModule::set_public_access_mode(1682			origin1.clone(),1683			collection_id,1684			AccessMode::AllowList1685		));1686		assert_ok!(TemplateModule::set_mint_permission(1687			origin1,1688			collection_id,1689			true1690		));16911692		assert_noop!(1693			TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1694			Error::<Test>::AddresNotInAllowList1695		);1696	});1697}16981699// 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.1700#[test]1701fn allow_list_test_16() {1702	new_test_ext().execute_with(|| {1703		let collection_id = create_test_collection(&CollectionMode::NFT, 1);17041705		let origin1 = Origin::signed(1);1706		let origin2 = Origin::signed(2);17071708		assert_ok!(TemplateModule::set_public_access_mode(1709			origin1.clone(),1710			collection_id,1711			AccessMode::AllowList1712		));1713		assert_ok!(TemplateModule::set_mint_permission(1714			origin1.clone(),1715			collection_id,1716			true1717		));1718		assert_ok!(TemplateModule::add_to_allow_list(1719			origin1,1720			collection_id,1721			account(2)1722		));17231724		assert_ok!(TemplateModule::create_item(1725			origin2,1726			1,1727			account(2),1728			default_nft_data().into()1729		));1730	});1731}17321733// Total number of collections. Positive test1734#[test]1735fn total_number_collections_bound() {1736	new_test_ext().execute_with(|| {1737		create_test_collection(&CollectionMode::NFT, 1);1738	});1739}17401741// Total number of collections. Negotive test1742#[test]1743fn total_number_collections_bound_neg() {1744	new_test_ext().execute_with(|| {1745		let origin1 = Origin::signed(1);17461747		for i in 0..COLLECTION_NUMBER_LIMIT {1748			create_test_collection(&CollectionMode::NFT, i + 1);1749		}17501751		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1752		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();1753		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();17541755		// 11-th collection in chain. Expects error1756		assert_noop!(1757			TemplateModule::create_collection(1758				origin1,1759				col_name1,1760				col_desc1,1761				token_prefix1,1762				CollectionMode::NFT1763			),1764			Error::<Test>::TotalCollectionsLimitExceeded1765		);1766	});1767}17681769// Owned tokens by a single address. Positive test1770#[test]1771fn owned_tokens_bound() {1772	new_test_ext().execute_with(|| {1773		let collection_id = create_test_collection(&CollectionMode::NFT, 1);17741775		let data = default_nft_data();1776		create_test_item(collection_id, &data.clone().into());1777		create_test_item(collection_id, &data.into());1778	});1779}17801781// Owned tokens by a single address. Negotive test1782#[test]1783fn owned_tokens_bound_neg() {1784	new_test_ext().execute_with(|| {1785		let collection_id = create_test_collection(&CollectionMode::NFT, 1);17861787		let origin1 = Origin::signed(1);17881789		for _ in 0..ACCOUNT_TOKEN_OWNERSHIP_LIMIT {1790			let data = default_nft_data();1791			create_test_item(collection_id, &data.clone().into());1792		}17931794		let data = default_nft_data();1795		assert_noop!(1796			TemplateModule::create_item(origin1, 1, account(1), data.into()),1797			Error::<Test>::AccountTokenLimitExceeded1798		);1799	});1800}18011802// Number of collection admins. Positive test1803#[test]1804fn collection_admins_bound() {1805	new_test_ext().execute_with(|| {1806		let collection_id = create_test_collection(&CollectionMode::NFT, 1);18071808		let origin1 = Origin::signed(1);18091810		assert_ok!(TemplateModule::add_collection_admin(1811			origin1.clone(),1812			collection_id,1813			account(2)1814		));1815		assert_ok!(TemplateModule::add_collection_admin(1816			origin1,1817			collection_id,1818			account(3)1819		));1820	});1821}18221823// Number of collection admins. Negotive test1824#[test]1825fn collection_admins_bound_neg() {1826	new_test_ext().execute_with(|| {1827		let collection_id = create_test_collection(&CollectionMode::NFT, 1);18281829		let origin1 = Origin::signed(1);18301831		for i in 0..COLLECTION_ADMINS_LIMIT {1832			assert_ok!(TemplateModule::add_collection_admin(1833				origin1.clone(),1834				collection_id,1835				account(2 + i)1836			));1837		}1838		assert_noop!(1839			TemplateModule::add_collection_admin(1840				origin1,1841				collection_id,1842				account(3 + COLLECTION_ADMINS_LIMIT)1843			),1844			Error::<Test>::CollectionAdminsLimitExceeded1845		);1846	});1847}1848// #endregion18491850#[test]1851fn set_const_on_chain_schema() {1852	new_test_ext().execute_with(|| {1853		let collection_id = create_test_collection(&CollectionMode::NFT, 1);18541855		let origin1 = Origin::signed(1);1856		assert_ok!(TemplateModule::set_const_on_chain_schema(1857			origin1,1858			collection_id,1859			b"test const on chain schema".to_vec()1860		));18611862		assert_eq!(1863			TemplateModule::collection_id(collection_id)1864				.unwrap()1865				.const_on_chain_schema,1866			b"test const on chain schema".to_vec()1867		);1868		assert_eq!(1869			TemplateModule::collection_id(collection_id)1870				.unwrap()1871				.variable_on_chain_schema,1872			b"".to_vec()1873		);1874	});1875}18761877#[test]1878fn set_variable_on_chain_schema() {1879	new_test_ext().execute_with(|| {1880		let collection_id = create_test_collection(&CollectionMode::NFT, 1);18811882		let origin1 = Origin::signed(1);1883		assert_ok!(TemplateModule::set_variable_on_chain_schema(1884			origin1,1885			collection_id,1886			b"test variable on chain schema".to_vec()1887		));18881889		assert_eq!(1890			TemplateModule::collection_id(collection_id)1891				.unwrap()1892				.const_on_chain_schema,1893			b"".to_vec()1894		);1895		assert_eq!(1896			TemplateModule::collection_id(collection_id)1897				.unwrap()1898				.variable_on_chain_schema,1899			b"test variable on chain schema".to_vec()1900		);1901	});1902}19031904#[test]1905fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1906	new_test_ext().execute_with(|| {1907		let collection_id = create_test_collection(&CollectionMode::NFT, 1);19081909		let origin1 = Origin::signed(1);19101911		let data = default_nft_data();1912		create_test_item(1, &data.into());19131914		let variable_data = b"test data".to_vec();1915		assert_ok!(TemplateModule::set_variable_meta_data(1916			origin1,1917			collection_id,1918			1,1919			variable_data.clone()1920		));19211922		assert_eq!(1923			TemplateModule::nft_item_id(collection_id, 1)1924				.unwrap()1925				.variable_data,1926			variable_data1927		);1928	});1929}19301931#[test]1932fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1933	new_test_ext().execute_with(|| {1934		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);19351936		let origin1 = Origin::signed(1);19371938		let data = default_re_fungible_data();1939		create_test_item(1, &data.into());19401941		let variable_data = b"test data".to_vec();1942		assert_ok!(TemplateModule::set_variable_meta_data(1943			origin1,1944			collection_id,1945			1,1946			variable_data.clone()1947		));19481949		assert_eq!(1950			TemplateModule::refungible_item_id(collection_id, 1)1951				.unwrap()1952				.variable_data,1953			variable_data1954		);1955	});1956}19571958#[test]1959fn set_variable_meta_data_on_fungible_token_fails() {1960	new_test_ext().execute_with(|| {1961		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);19621963		let origin1 = Origin::signed(1);19641965		let data = default_fungible_data();1966		create_test_item(1, &data.into());19671968		let variable_data = b"test data".to_vec();1969		assert_noop!(1970			TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),1971			Error::<Test>::CantStoreMetadataInFungibleTokens1972		);1973	});1974}19751976#[test]1977fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1978	new_test_ext().execute_with(|| {1979		let collection_id = create_test_collection(&CollectionMode::NFT, 1);19801981		let origin1 = Origin::signed(1);19821983		let data = default_nft_data();1984		create_test_item(1, &data.into());19851986		let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1987		assert_noop!(1988			TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),1989			Error::<Test>::TokenVariableDataLimitExceeded1990		);1991	});1992}19931994#[test]1995fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {1996	new_test_ext().execute_with(|| {1997		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);19981999		let origin1 = Origin::signed(1);20002001		let data = default_re_fungible_data();2002		create_test_item(1, &data.into());20032004		let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2005		assert_noop!(2006			TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),2007			Error::<Test>::TokenVariableDataLimitExceeded2008		);2009	});2010}20112012#[test]2013fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2014	new_test_ext().execute_with(|| {2015		//default_limits();20162017		let collection_id = create_test_collection(&CollectionMode::NFT, 1);20182019		let origin1 = Origin::signed(1);20202021		let data = default_nft_data();2022		create_test_item(1, &data.into());20232024		assert_ok!(TemplateModule::set_meta_update_permission_flag(2025			origin1.clone(),2026			collection_id,2027			MetaUpdatePermission::ItemOwner,2028		));20292030		let variable_data = b"ten chars.".to_vec();2031		assert_ok!(TemplateModule::set_variable_meta_data(2032			origin1,2033			collection_id,2034			1,2035			variable_data.clone()2036		));20372038		assert_eq!(2039			TemplateModule::nft_item_id(collection_id, 1)2040				.unwrap()2041				.variable_data,2042			variable_data2043		);2044	});2045}20462047#[test]2048fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {2049	new_test_ext().execute_with(|| {2050		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);20512052		let origin1 = Origin::signed(1);20532054		assert_ok!(TemplateModule::set_mint_permission(2055			origin1.clone(),2056			collection_id,2057			true2058		));2059		assert_ok!(TemplateModule::add_to_allow_list(2060			origin1.clone(),2061			collection_id,2062			account(1)2063		));20642065		let data = default_nft_data();2066		create_test_item(1, &data.into());20672068		assert_ok!(TemplateModule::set_meta_update_permission_flag(2069			origin1.clone(),2070			collection_id,2071			MetaUpdatePermission::ItemOwner,2072		));20732074		let variable_data = b"1234567890123".to_vec();2075		assert_noop!(2076			TemplateModule::set_variable_meta_data(2077				origin1,2078				collection_id,2079				1,2080				variable_data.clone()2081			),2082			Error::<Test>::TokenVariableDataLimitExceeded2083		);2084	})2085}20862087#[test]2088fn collection_transfer_flag_works() {2089	new_test_ext().execute_with(|| {2090		let origin1 = Origin::signed(1);20912092		let collection_id = create_test_collection(&CollectionMode::NFT, 1);2093		assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));20942095		let data = default_nft_data();2096		create_test_item(collection_id, &data.into());2097		assert_eq!(TemplateModule::balance_count(1, 1), 1);2098		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);20992100		let origin1 = Origin::signed(1);21012102		// default scenario2103		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));2104		assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));2105		assert_eq!(TemplateModule::balance_count(1, 1), 0);2106		assert_eq!(TemplateModule::balance_count(1, 2), 1);21072108		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);2109	});2110}21112112#[test]2113fn set_variable_meta_data_on_nft_with_admin_flag() {2114	new_test_ext().execute_with(|| {2115		// default_limits();21162117		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);21182119		let origin1 = Origin::signed(1);2120		let origin2 = Origin::signed(2);21212122		assert_ok!(TemplateModule::set_mint_permission(2123			origin2.clone(),2124			collection_id,2125			true2126		));2127		assert_ok!(TemplateModule::add_to_allow_list(2128			origin2.clone(),2129			collection_id,2130			account(1)2131		));21322133		assert_ok!(TemplateModule::add_collection_admin(2134			origin2.clone(),2135			collection_id,2136			account(1)2137		));21382139		let data = default_nft_data();2140		create_test_item(1, &data.into());21412142		assert_ok!(TemplateModule::set_meta_update_permission_flag(2143			origin2.clone(),2144			collection_id,2145			MetaUpdatePermission::Admin,2146		));21472148		let variable_data = b"test.".to_vec();2149		assert_ok!(TemplateModule::set_variable_meta_data(2150			origin1,2151			collection_id,2152			1,2153			variable_data.clone()2154		));21552156		assert_eq!(2157			TemplateModule::nft_item_id(collection_id, 1)2158				.unwrap()2159				.variable_data,2160			variable_data2161		);2162	});2163}21642165#[test]2166fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2167	new_test_ext().execute_with(|| {2168		// default_limits();21692170		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);21712172		let origin1 = Origin::signed(1);2173		let origin2 = Origin::signed(2);21742175		assert_ok!(TemplateModule::set_mint_permission(2176			origin2.clone(),2177			collection_id,2178			true2179		));2180		assert_ok!(TemplateModule::add_to_allow_list(2181			origin2.clone(),2182			collection_id,2183			account(1)2184		));21852186		let data = default_nft_data();2187		create_test_item(1, &data.into());21882189		assert_ok!(TemplateModule::set_meta_update_permission_flag(2190			origin2.clone(),2191			collection_id,2192			MetaUpdatePermission::Admin,2193		));21942195		let variable_data = b"test.".to_vec();2196		assert_noop!(2197			TemplateModule::set_variable_meta_data(2198				origin1,2199				collection_id,2200				1,2201				variable_data.clone()2202			),2203			Error::<Test>::NoPermission2204		);2205	});2206}22072208#[test]2209fn set_variable_meta_flag_after_freeze() {2210	new_test_ext().execute_with(|| {2211		// default_limits();22122213		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);22142215		let origin2 = Origin::signed(2);22162217		assert_ok!(TemplateModule::set_meta_update_permission_flag(2218			origin2.clone(),2219			collection_id,2220			MetaUpdatePermission::None,2221		));2222		assert_noop!(2223			TemplateModule::set_meta_update_permission_flag(2224				origin2.clone(),2225				collection_id,2226				MetaUpdatePermission::Admin2227			),2228			Error::<Test>::MetadataFlagFrozen2229		);2230	});2231}22322233#[test]2234fn set_variable_meta_data_on_nft_with_none_flag_neg() {2235	new_test_ext().execute_with(|| {2236		// default_limits();22372238		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);2239		let origin1 = Origin::signed(1);22402241		let data = default_nft_data();2242		create_test_item(1, &data.into());22432244		assert_ok!(TemplateModule::set_meta_update_permission_flag(2245			origin1.clone(),2246			collection_id,2247			MetaUpdatePermission::None,2248		));22492250		let variable_data = b"test.".to_vec();2251		assert_noop!(2252			TemplateModule::set_variable_meta_data(2253				origin1.clone(),2254				collection_id,2255				1,2256				variable_data.clone()2257			),2258			Error::<Test>::MetadataUpdateDenied2259		);2260	});2261}22622263#[test]2264fn collection_transfer_flag_works_neg() {2265	new_test_ext().execute_with(|| {2266		let origin1 = Origin::signed(1);22672268		let collection_id = create_test_collection(&CollectionMode::NFT, 1);2269		assert_ok!(TemplateModule::set_transfers_enabled_flag(2270			origin1, 1, false2271		));22722273		let data = default_nft_data();2274		create_test_item(collection_id, &data.into());2275		assert_eq!(TemplateModule::balance_count(1, 1), 1);2276		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);22772278		let origin1 = Origin::signed(1);22792280		// default scenario2281		assert_noop!(2282			TemplateModule::transfer(origin1, account(2), 1, 1, 1000),2283			Error::<Test>::TransferNotAllowed2284		);2285		assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));2286		assert_eq!(TemplateModule::balance_count(1, 1), 1);2287		assert_eq!(TemplateModule::balance_count(1, 2), 0);22882289		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2290	});2291}
after · pallets/nft/src/tests.rs
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode, CreateItemData};5use nft_data_structs::{6	CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,7	MAX_DECIMAL_POINTS,8};9use frame_support::{assert_noop, assert_ok};10use sp_std::convert::TryInto;1112fn default_nft_data() -> CreateNftData {13	CreateNftData {14		const_data: vec![1, 2, 3].try_into().unwrap(),15		variable_data: vec![3, 2, 1].try_into().unwrap(),16	}17}1819fn default_fungible_data() -> CreateFungibleData {20	CreateFungibleData { value: 5 }21}2223fn default_re_fungible_data() -> CreateReFungibleData {24	CreateReFungibleData {25		const_data: vec![1, 2, 3].try_into().unwrap(),26		variable_data: vec![3, 2, 1].try_into().unwrap(),27		pieces: 1023,28	}29}3031fn create_test_collection_for_owner(32	mode: &CollectionMode,33	owner: u64,34	id: CollectionId,35) -> CollectionId {36	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();37	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();38	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();3940	let origin1 = Origin::signed(owner);41	assert_ok!(TemplateModule::create_collection(42		origin1,43		col_name1,44		col_desc1,45		token_prefix1,46		mode.clone()47	));4849	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();50	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();51	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();52	assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);53	assert_eq!(54		TemplateModule::collection_id(id).unwrap().name,55		saved_col_name56	);57	assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);58	assert_eq!(59		TemplateModule::collection_id(id).unwrap().description,60		saved_description61	);62	assert_eq!(63		TemplateModule::collection_id(id).unwrap().token_prefix,64		saved_prefix65	);66	id67}6869fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {70	create_test_collection_for_owner(&mode, 1, id)71}7273fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {74	let origin1 = Origin::signed(1);75	assert_ok!(TemplateModule::create_item(76		origin1,77		collection_id,78		account(1),79		data.clone()80	));81}8283fn account(sub: u64) -> TestCrossAccountId {84	TestCrossAccountId::from_sub(sub)85}8687// Use cases tests region88// #region8990#[test]91fn set_version_schema() {92	new_test_ext().execute_with(|| {93		let origin1 = Origin::signed(1);94		let collection_id = create_test_collection(&CollectionMode::NFT, 1);9596		assert_ok!(TemplateModule::set_schema_version(97			origin1,98			collection_id,99			SchemaVersion::Unique100		));101		assert_eq!(102			TemplateModule::collection_id(collection_id)103				.unwrap()104				.schema_version,105			SchemaVersion::Unique106		);107	});108}109110#[test]111fn create_fungible_collection_fails_with_large_decimal_numbers() {112	new_test_ext().execute_with(|| {113		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();114		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();115		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();116117		let origin1 = Origin::signed(1);118		assert_noop!(119			TemplateModule::create_collection(120				origin1,121				col_name1,122				col_desc1,123				token_prefix1,124				CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)125			),126			Error::<Test>::CollectionDecimalPointLimitExceeded127		);128	});129}130131#[test]132fn create_nft_item() {133	new_test_ext().execute_with(|| {134		let collection_id = create_test_collection(&CollectionMode::NFT, 1);135136		let data = default_nft_data();137		create_test_item(collection_id, &data.clone().into());138		let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();139		assert_eq!(item.const_data, data.const_data.into_inner());140		assert_eq!(item.variable_data, data.variable_data.into_inner());141	});142}143144// Use cases tests region145// #region146#[test]147fn create_nft_multiple_items() {148	new_test_ext().execute_with(|| {149		create_test_collection(&CollectionMode::NFT, 1);150151		let origin1 = Origin::signed(1);152153		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];154155		assert_ok!(TemplateModule::create_multiple_items(156			origin1,157			1,158			account(1),159			items_data160				.clone()161				.into_iter()162				.map(|d| { d.into() })163				.collect()164		));165		for (index, data) in items_data.into_iter().enumerate() {166			let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap();167			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());168			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());169		}170	});171}172173#[test]174fn create_refungible_item() {175	new_test_ext().execute_with(|| {176		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);177178		let data = default_re_fungible_data();179		create_test_item(collection_id, &data.clone().into());180		let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();181		let balance = TemplateModule::balance(collection_id, 1, account(1));182		assert_eq!(item.const_data, data.const_data.into_inner());183		assert_eq!(item.variable_data, data.variable_data.into_inner());184		assert_eq!(balance, 1023);185	});186}187188#[test]189fn create_multiple_refungible_items() {190	new_test_ext().execute_with(|| {191		create_test_collection(&CollectionMode::ReFungible, 1);192193		let origin1 = Origin::signed(1);194195		let items_data = vec![196			default_re_fungible_data(),197			default_re_fungible_data(),198			default_re_fungible_data(),199		];200201		assert_ok!(TemplateModule::create_multiple_items(202			origin1,203			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 = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();213			let balance = TemplateModule::balance(1, 1, account(1));214			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());215			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());216			assert_eq!(balance, 1023);217		}218	});219}220221#[test]222fn create_fungible_item() {223	new_test_ext().execute_with(|| {224		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);225226		let data = default_fungible_data();227		create_test_item(collection_id, &data.into());228229		assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);230	});231}232233//#[test]234// fn create_multiple_fungible_items() {235//     new_test_ext().execute_with(|| {236//         default_limits();237238//         create_test_collection(&CollectionMode::Fungible(3), 1);239240//         let origin1 = Origin::signed(1);241242//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];243244//         assert_ok!(TemplateModule::create_multiple_items(245//             origin1.clone(),246//             1,247//             1,248//             items_data.clone().into_iter().map(|d| { d.into() }).collect()249//         ));250251//         for (index, _) in items_data.iter().enumerate() {252//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);253//         }254//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);255//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);256//     });257// }258259#[test]260fn transfer_fungible_item() {261	new_test_ext().execute_with(|| {262		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);263264		let origin1 = Origin::signed(1);265		let origin2 = Origin::signed(2);266267		let data = default_fungible_data();268		create_test_item(collection_id, &data.into());269270		assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);271		assert_eq!(TemplateModule::balance_count(1, 1), 5);272273		// change owner scenario274		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 5));275		assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);276		assert_eq!(TemplateModule::balance_count(1, 1), 0);277		assert_eq!(TemplateModule::balance_count(1, 2), 5);278279		// split item scenario280		assert_ok!(TemplateModule::transfer(281			origin2.clone(),282			account(3),283			1,284			1,285			3286		));287		assert_eq!(TemplateModule::balance_count(1, 2), 2);288		assert_eq!(TemplateModule::balance_count(1, 3), 3);289290		// split item and new owner has account scenario291		assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 1));292		assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);293		assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);294		assert_eq!(TemplateModule::balance_count(1, 2), 1);295		assert_eq!(TemplateModule::balance_count(1, 3), 4);296	});297}298299#[test]300fn transfer_refungible_item() {301	new_test_ext().execute_with(|| {302		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);303304		let data = default_re_fungible_data();305		create_test_item(collection_id, &data.clone().into());306307		let origin1 = Origin::signed(1);308		let origin2 = Origin::signed(2);309		{310			let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();311			let balance = TemplateModule::balance(collection_id, 1, account(1));312			assert_eq!(item.const_data, data.const_data.into_inner());313			assert_eq!(item.variable_data, data.variable_data.into_inner());314			assert_eq!(balance, 1023);315		}316		assert_eq!(TemplateModule::balance_count(1, 1), 1023);317		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);318319		// change owner scenario320		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));321322		let balance2 = TemplateModule::balance(collection_id, 1, account(2));323		assert_eq!(balance2, 1023);324		assert_eq!(TemplateModule::balance_count(1, 1), 0);325		assert_eq!(TemplateModule::balance_count(1, 2), 1023);326		// assert_eq!(TemplateModule::address_tokens(1, 1), []);327		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);328329		// split item scenario330		assert_ok!(TemplateModule::transfer(331			origin2.clone(),332			account(3),333			1,334			1,335			500336		));337		{338			let item = TemplateModule::refungible_item_id(1, 1).unwrap();339			let balance2 = TemplateModule::balance(collection_id, 1, account(2));340			let balance3 = TemplateModule::balance(collection_id, 1, account(3));341			assert_eq!(balance2, 523);342			assert_eq!(balance3, 500);343		}344		assert_eq!(TemplateModule::balance_count(1, 2), 523);345		assert_eq!(TemplateModule::balance_count(1, 3), 500);346		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);347		assert_eq!(TemplateModule::address_tokens(1, 3), [1]);348349		// split item and new owner has account scenario350		assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));351		{352			let item = TemplateModule::refungible_item_id(1, 1).unwrap();353			let balance2 = TemplateModule::balance(collection_id, 1, account(2));354			let balance3 = TemplateModule::balance(collection_id, 1, account(3));355			assert_eq!(balance2, 323);356			assert_eq!(balance3, 700);357		}358		assert_eq!(TemplateModule::balance_count(1, 2), 323);359		assert_eq!(TemplateModule::balance_count(1, 3), 700);360		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);361		assert_eq!(TemplateModule::address_tokens(1, 3), [1]);362	});363}364365#[test]366fn transfer_nft_item() {367	new_test_ext().execute_with(|| {368		let collection_id = create_test_collection(&CollectionMode::NFT, 1);369370		let data = default_nft_data();371		create_test_item(collection_id, &data.into());372		assert_eq!(TemplateModule::balance_count(1, 1), 1);373		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);374375		let origin1 = Origin::signed(1);376		// default scenario377		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));378		assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));379		assert_eq!(TemplateModule::balance_count(1, 1), 0);380		assert_eq!(TemplateModule::balance_count(1, 2), 1);381		// assert_eq!(TemplateModule::address_tokens(1, 1), []);382		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);383	});384}385386#[test]387fn nft_approve_and_transfer_from() {388	new_test_ext().execute_with(|| {389		let collection_id = create_test_collection(&CollectionMode::NFT, 1);390391		let data = default_nft_data();392		create_test_item(collection_id, &data.into());393394		let origin1 = Origin::signed(1);395		let origin2 = Origin::signed(2);396397		assert_eq!(TemplateModule::balance_count(1, 1), 1);398		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);399400		// neg transfer401		assert_noop!(402			TemplateModule::transfer_from(origin2.clone(), account(1), account(2), 1, 1, 1),403			Error::<Test>::NoPermission404		);405406		// do approve407		assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 5));408		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);409		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);410411		assert_ok!(TemplateModule::transfer_from(412			origin2,413			account(1),414			account(3),415			1,416			1,417			1418		));419		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);420	});421}422423#[test]424fn nft_approve_and_transfer_from_allow_list() {425	new_test_ext().execute_with(|| {426		let collection_id = create_test_collection(&CollectionMode::NFT, 1);427428		let origin1 = Origin::signed(1);429		let origin2 = Origin::signed(2);430431		let data = default_nft_data();432		create_test_item(collection_id, &data.clone().into());433434		assert_eq!(435			&TemplateModule::nft_item_id(1, 1).unwrap().const_data,436			&data.const_data.into_inner()437		);438		assert_eq!(TemplateModule::balance_count(1, 1), 1);439		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);440441		assert_ok!(TemplateModule::set_mint_permission(442			origin1.clone(),443			1,444			true445		));446		assert_ok!(TemplateModule::set_public_access_mode(447			origin1.clone(),448			1,449			AccessMode::AllowList450		));451		assert_ok!(TemplateModule::add_to_allow_list(452			origin1.clone(),453			1,454			account(1)455		));456		assert_ok!(TemplateModule::add_to_allow_list(457			origin1.clone(),458			1,459			account(2)460		));461		assert_ok!(TemplateModule::add_to_allow_list(462			origin1.clone(),463			1,464			account(3)465		));466467		// do approve468		assert_ok!(TemplateModule::approve(469			origin1.clone(),470			account(2),471			1,472			1,473			5474		));475		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);476		assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));477		assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);478479		assert_ok!(TemplateModule::transfer_from(480			origin2,481			account(1),482			account(3),483			1,484			1,485			1486		));487		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);488	});489}490491#[test]492fn refungible_approve_and_transfer_from() {493	new_test_ext().execute_with(|| {494		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);495496		let origin1 = Origin::signed(1);497		let origin2 = Origin::signed(2);498499		let data = default_re_fungible_data();500		create_test_item(collection_id, &data.into());501502		assert_eq!(TemplateModule::balance_count(1, 1), 1023);503		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);504505		assert_ok!(TemplateModule::set_mint_permission(506			origin1.clone(),507			1,508			true509		));510		assert_ok!(TemplateModule::set_public_access_mode(511			origin1.clone(),512			1,513			AccessMode::AllowList514		));515		assert_ok!(TemplateModule::add_to_allow_list(516			origin1.clone(),517			1,518			account(1)519		));520		assert_ok!(TemplateModule::add_to_allow_list(521			origin1.clone(),522			1,523			account(2)524		));525		assert_ok!(TemplateModule::add_to_allow_list(526			origin1.clone(),527			1,528			account(3)529		));530531		// do approve532		assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1023));533		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);534535		assert_ok!(TemplateModule::transfer_from(536			origin2,537			account(1),538			account(3),539			1,540			1,541			100542		));543		assert_eq!(TemplateModule::balance_count(1, 1), 923);544		assert_eq!(TemplateModule::balance_count(1, 3), 100);545		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);546		assert_eq!(TemplateModule::address_tokens(1, 3), [1]);547548		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 923);549	});550}551552#[test]553fn fungible_approve_and_transfer_from() {554	new_test_ext().execute_with(|| {555		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);556557		let data = default_fungible_data();558		create_test_item(collection_id, &data.into());559560		let origin1 = Origin::signed(1);561		let origin2 = Origin::signed(2);562563		assert_eq!(TemplateModule::balance_count(1, 1), 5);564565		assert_ok!(TemplateModule::set_mint_permission(566			origin1.clone(),567			1,568			true569		));570		assert_ok!(TemplateModule::set_public_access_mode(571			origin1.clone(),572			1,573			AccessMode::AllowList574		));575		assert_ok!(TemplateModule::add_to_allow_list(576			origin1.clone(),577			1,578			account(1)579		));580		assert_ok!(TemplateModule::add_to_allow_list(581			origin1.clone(),582			1,583			account(2)584		));585		assert_ok!(TemplateModule::add_to_allow_list(586			origin1.clone(),587			1,588			account(3)589		));590591		// do approve592		assert_ok!(TemplateModule::approve(593			origin1.clone(),594			account(2),595			1,596			1,597			5598		));599		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);600		assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));601		assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);602		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);603604		assert_ok!(TemplateModule::transfer_from(605			origin2.clone(),606			account(1),607			account(3),608			1,609			1,610			4611		));612		assert_eq!(TemplateModule::balance_count(1, 1), 1);613		assert_eq!(TemplateModule::balance_count(1, 3), 4);614615		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);616617		assert_noop!(618			TemplateModule::transfer_from(origin2, account(1), account(3), 1, 1, 4),619			Error::<Test>::NoPermission620		);621	});622}623624#[test]625fn change_collection_owner() {626	new_test_ext().execute_with(|| {627		let collection_id = create_test_collection(&CollectionMode::NFT, 1);628629		let origin1 = Origin::signed(1);630		assert_ok!(TemplateModule::change_collection_owner(631			origin1,632			collection_id,633			2634		));635		assert_eq!(636			TemplateModule::collection_id(collection_id).unwrap().owner,637			2638		);639	});640}641642#[test]643fn destroy_collection() {644	new_test_ext().execute_with(|| {645		let collection_id = create_test_collection(&CollectionMode::NFT, 1);646647		let origin1 = Origin::signed(1);648		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));649	});650}651652#[test]653fn burn_nft_item() {654	new_test_ext().execute_with(|| {655		let collection_id = create_test_collection(&CollectionMode::NFT, 1);656657		let origin1 = Origin::signed(1);658		assert_ok!(TemplateModule::add_collection_admin(659			origin1.clone(),660			collection_id,661			account(2)662		));663664		let data = default_nft_data();665		create_test_item(collection_id, &data.into());666667		// check balance (collection with id = 1, user id = 1)668		assert_eq!(TemplateModule::balance_count(1, 1), 1);669670		// burn item671		assert_ok!(TemplateModule::burn_item(672			origin1.clone(),673			collection_id,674			1,675			1676		));677		assert_noop!(678			TemplateModule::burn_item(origin1, collection_id, 1, 1),679			Error::<Test>::TokenNotFound680		);681682		assert_eq!(TemplateModule::balance_count(1, 1), 0);683	});684}685686#[test]687fn burn_fungible_item() {688	new_test_ext().execute_with(|| {689		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);690691		let origin1 = Origin::signed(1);692		assert_ok!(TemplateModule::add_collection_admin(693			origin1.clone(),694			collection_id,695			account(2)696		));697698		let data = default_fungible_data();699		create_test_item(collection_id, &data.into());700701		// check balance (collection with id = 1, user id = 1)702		assert_eq!(TemplateModule::balance_count(1, 1), 5);703704		// burn item705		assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));706		assert_noop!(707			TemplateModule::burn_item(origin1, 1, 1, 5),708			Error::<Test>::TokenValueNotEnough709		);710711		assert_eq!(TemplateModule::balance_count(1, 1), 0);712	});713}714715#[test]716fn burn_refungible_item() {717	new_test_ext().execute_with(|| {718		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);719		let origin1 = Origin::signed(1);720721		assert_ok!(TemplateModule::set_mint_permission(722			origin1.clone(),723			collection_id,724			true725		));726		assert_ok!(TemplateModule::set_public_access_mode(727			origin1.clone(),728			collection_id,729			AccessMode::AllowList730		));731		assert_ok!(TemplateModule::add_to_allow_list(732			origin1.clone(),733			1,734			account(1)735		));736737		assert_ok!(TemplateModule::add_collection_admin(738			origin1.clone(),739			1,740			account(2)741		));742743		let data = default_re_fungible_data();744		create_test_item(collection_id, &data.into());745746		// check balance (collection with id = 1, user id = 2)747		assert_eq!(TemplateModule::balance_count(1, 1), 1023);748749		// burn item750		assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));751		assert_noop!(752			TemplateModule::burn_item(origin1, 1, 1, 1023),753			Error::<Test>::TokenNotFound754		);755756		assert_eq!(TemplateModule::balance_count(1, 1), 0);757	});758}759760#[test]761fn add_collection_admin() {762	new_test_ext().execute_with(|| {763		let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);764		create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);765		create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);766767		let origin1 = Origin::signed(1);768769		// collection admin770		assert_ok!(TemplateModule::add_collection_admin(771			origin1.clone(),772			collection1_id,773			account(2)774		));775		assert_ok!(TemplateModule::add_collection_admin(776			origin1,777			collection1_id,778			account(3)779		));780781		assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)),);782		assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)),);783	});784}785786#[test]787fn remove_collection_admin() {788	new_test_ext().execute_with(|| {789		let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);790		create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);791		create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);792793		let origin1 = Origin::signed(1);794		let origin2 = Origin::signed(2);795796		// collection admin797		assert_ok!(TemplateModule::add_collection_admin(798			origin1.clone(),799			collection1_id,800			account(2)801		));802		assert_ok!(TemplateModule::add_collection_admin(803			origin1,804			collection1_id,805			account(3)806		));807808		assert!(TemplateModule::admin_list_collection(1).contains(&account(2)),);809		assert!(TemplateModule::admin_list_collection(1).contains(&account(3)),);810811		// remove admin812		assert_ok!(TemplateModule::remove_collection_admin(813			origin2,814			1,815			account(3)816		));817		assert!(!TemplateModule::admin_list_collection(1).contains(&account(3)),);818	});819}820821#[test]822fn balance_of() {823	new_test_ext().execute_with(|| {824		let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);825		let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);826		let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);827828		// check balance before829		assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);830		assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);831		assert_eq!(832			TemplateModule::balance_count(re_fungible_collection_id, 1),833			0834		);835836		let nft_data = default_nft_data();837		create_test_item(nft_collection_id, &nft_data.into());838839		let fungible_data = default_fungible_data();840		create_test_item(fungible_collection_id, &fungible_data.into());841842		let re_fungible_data = default_re_fungible_data();843		create_test_item(re_fungible_collection_id, &re_fungible_data.into());844845		// check balance (collection with id = 1, user id = 1)846		assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);847		assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);848		assert_eq!(849			TemplateModule::balance_count(re_fungible_collection_id, 1),850			1023851		);852		assert_eq!(853			TemplateModule::nft_item_id(nft_collection_id, 1)854				.unwrap()855				.owner,856			account(1)857		);858		assert_eq!(859			TemplateModule::fungible_item_id(fungible_collection_id, 1).value,860			5861		);862		assert_eq!(863			TemplateModule::refungible_item_id(re_fungible_collection_id, 1)864				.unwrap()865				.owner[0]866				.owner,867			account(1)868		);869	});870}871872#[test]873fn approve() {874	new_test_ext().execute_with(|| {875		let collection_id = create_test_collection(&CollectionMode::NFT, 1);876877		let data = default_nft_data();878		create_test_item(collection_id, &data.into());879880		let origin1 = Origin::signed(1);881882		// approve883		assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1));884		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);885	});886}887888#[test]889fn transfer_from() {890	new_test_ext().execute_with(|| {891		let collection_id = create_test_collection(&CollectionMode::NFT, 1);892		let origin1 = Origin::signed(1);893		let origin2 = Origin::signed(2);894895		let data = default_nft_data();896		create_test_item(collection_id, &data.into());897898		// approve899		assert_ok!(TemplateModule::approve(900			origin1.clone(),901			account(2),902			1,903			1,904			1905		));906		assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);907908		assert_ok!(TemplateModule::set_mint_permission(909			origin1.clone(),910			1,911			true912		));913		assert_ok!(TemplateModule::set_public_access_mode(914			origin1.clone(),915			1,916			AccessMode::AllowList917		));918		assert_ok!(TemplateModule::add_to_allow_list(919			origin1.clone(),920			1,921			account(1)922		));923		assert_ok!(TemplateModule::add_to_allow_list(924			origin1.clone(),925			1,926			account(2)927		));928		assert_ok!(TemplateModule::add_to_allow_list(origin1, 1, account(3)));929930		assert_ok!(TemplateModule::transfer_from(931			origin2,932			account(1),933			account(2),934			1,935			1,936			1937		));938939		// after transfer940		assert_eq!(TemplateModule::balance_count(1, 1), 0);941		assert_eq!(TemplateModule::balance_count(1, 2), 1);942	});943}944945// #endregion946947// Coverage tests region948// #region949950#[test]951fn owner_can_add_address_to_allow_list() {952	new_test_ext().execute_with(|| {953		let collection_id = create_test_collection(&CollectionMode::NFT, 1);954955		let origin1 = Origin::signed(1);956		assert_ok!(TemplateModule::add_to_allow_list(957			origin1,958			collection_id,959			account(2)960		));961		assert!(TemplateModule::allow_list(collection_id, 2));962	});963}964965#[test]966fn admin_can_add_address_to_allow_list() {967	new_test_ext().execute_with(|| {968		let collection_id = create_test_collection(&CollectionMode::NFT, 1);969		let origin1 = Origin::signed(1);970		let origin2 = Origin::signed(2);971972		assert_ok!(TemplateModule::add_collection_admin(973			origin1,974			collection_id,975			account(2)976		));977		assert_ok!(TemplateModule::add_to_allow_list(978			origin2,979			collection_id,980			account(3)981		));982		assert!(TemplateModule::allow_list(collection_id, 3));983	});984}985986#[test]987fn nonprivileged_user_cannot_add_address_to_allow_list() {988	new_test_ext().execute_with(|| {989		let collection_id = create_test_collection(&CollectionMode::NFT, 1);990991		let origin2 = Origin::signed(2);992		assert_noop!(993			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),994			Error::<Test>::NoPermission995		);996	});997}998999#[test]1000fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1001	new_test_ext().execute_with(|| {1002		let origin1 = Origin::signed(1);10031004		assert_noop!(1005			TemplateModule::add_to_allow_list(origin1, 1, account(2)),1006			Error::<Test>::CollectionNotFound1007		);1008	});1009}10101011#[test]1012fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1013	new_test_ext().execute_with(|| {1014		let collection_id = create_test_collection(&CollectionMode::NFT, 1);10151016		let origin1 = Origin::signed(1);1017		assert_ok!(TemplateModule::destroy_collection(1018			origin1.clone(),1019			collection_id1020		));1021		assert_noop!(1022			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1023			Error::<Test>::CollectionNotFound1024		);1025	});1026}10271028// If address is already added to allow list, nothing happens1029#[test]1030fn address_is_already_added_to_allow_list() {1031	new_test_ext().execute_with(|| {1032		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1033		let origin1 = Origin::signed(1);10341035		assert_ok!(TemplateModule::add_to_allow_list(1036			origin1.clone(),1037			collection_id,1038			account(2)1039		));1040		assert_ok!(TemplateModule::add_to_allow_list(1041			origin1,1042			collection_id,1043			account(2)1044		));1045		assert!(TemplateModule::allow_list(collection_id, 2));1046	});1047}10481049#[test]1050fn owner_can_remove_address_from_allow_list() {1051	new_test_ext().execute_with(|| {1052		let collection_id = create_test_collection(&CollectionMode::NFT, 1);10531054		let origin1 = Origin::signed(1);1055		assert_ok!(TemplateModule::add_to_allow_list(1056			origin1.clone(),1057			collection_id,1058			account(2)1059		));1060		assert_ok!(TemplateModule::remove_from_allow_list(1061			origin1,1062			collection_id,1063			account(2)1064		));1065		assert!(!TemplateModule::allow_list(collection_id, 2));1066	});1067}10681069#[test]1070fn admin_can_remove_address_from_allow_list() {1071	new_test_ext().execute_with(|| {1072		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1073		let origin1 = Origin::signed(1);1074		let origin2 = Origin::signed(2);10751076		assert_ok!(TemplateModule::add_collection_admin(1077			origin1.clone(),1078			collection_id,1079			account(2)1080		));10811082		assert_ok!(TemplateModule::add_to_allow_list(1083			origin1,1084			collection_id,1085			account(3)1086		));1087		assert_ok!(TemplateModule::remove_from_allow_list(1088			origin2,1089			collection_id,1090			account(3)1091		));1092		assert!(!TemplateModule::allow_list(collection_id, 3));1093	});1094}10951096#[test]1097fn nonprivileged_user_cannot_remove_address_from_allow_list() {1098	new_test_ext().execute_with(|| {1099		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1100		let origin1 = Origin::signed(1);1101		let origin2 = Origin::signed(2);11021103		assert_ok!(TemplateModule::add_to_allow_list(1104			origin1,1105			collection_id,1106			account(2)1107		));1108		assert_noop!(1109			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1110			Error::<Test>::NoPermission1111		);1112		assert!(TemplateModule::allow_list(collection_id, 2));1113	});1114}11151116#[test]1117fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1118	new_test_ext().execute_with(|| {1119		let origin1 = Origin::signed(1);11201121		assert_noop!(1122			TemplateModule::remove_from_allow_list(origin1, 1, account(2)),1123			Error::<Test>::CollectionNotFound1124		);1125	});1126}11271128#[test]1129fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1130	new_test_ext().execute_with(|| {1131		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1132		let origin1 = Origin::signed(1);1133		let origin2 = Origin::signed(2);11341135		assert_ok!(TemplateModule::add_to_allow_list(1136			origin1.clone(),1137			collection_id,1138			account(2)1139		));1140		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1141		assert_noop!(1142			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1143			Error::<Test>::CollectionNotFound1144		);1145		assert!(!TemplateModule::allow_list(collection_id, 2));1146	});1147}11481149// If address is already removed from allow list, nothing happens1150#[test]1151fn address_is_already_removed_from_allow_list() {1152	new_test_ext().execute_with(|| {1153		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1154		let origin1 = Origin::signed(1);11551156		assert_ok!(TemplateModule::add_to_allow_list(1157			origin1.clone(),1158			collection_id,1159			account(2)1160		));1161		assert_ok!(TemplateModule::remove_from_allow_list(1162			origin1.clone(),1163			collection_id,1164			account(2)1165		));1166		assert_ok!(TemplateModule::remove_from_allow_list(1167			origin1,1168			collection_id,1169			account(2)1170		));1171		assert!(!TemplateModule::allow_list(collection_id, 2));1172	});1173}11741175// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1176#[test]1177fn allow_list_test_1() {1178	new_test_ext().execute_with(|| {1179		let collection_id = create_test_collection(&CollectionMode::NFT, 1);11801181		let origin1 = Origin::signed(1);11821183		let data = default_nft_data();1184		create_test_item(collection_id, &data.into());11851186		assert_ok!(TemplateModule::set_public_access_mode(1187			origin1.clone(),1188			collection_id,1189			AccessMode::AllowList1190		));1191		assert_ok!(TemplateModule::add_to_allow_list(1192			origin1.clone(),1193			collection_id,1194			account(2)1195		));11961197		assert_noop!(1198			TemplateModule::transfer(origin1, account(3), 1, 1, 1),1199			Error::<Test>::AddresNotInAllowList1200		);1201	});1202}12031204#[test]1205fn allow_list_test_2() {1206	new_test_ext().execute_with(|| {1207		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1208		let origin1 = Origin::signed(1);12091210		let data = default_nft_data();1211		create_test_item(collection_id, &data.into());12121213		assert_ok!(TemplateModule::set_public_access_mode(1214			origin1.clone(),1215			collection_id,1216			AccessMode::AllowList1217		));1218		assert_ok!(TemplateModule::add_to_allow_list(1219			origin1.clone(),1220			1,1221			account(1)1222		));1223		assert_ok!(TemplateModule::add_to_allow_list(1224			origin1.clone(),1225			1,1226			account(2)1227		));12281229		// do approve1230		assert_ok!(TemplateModule::approve(1231			origin1.clone(),1232			account(1),1233			1,1234			1,1235			11236		));1237		assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);12381239		assert_ok!(TemplateModule::remove_from_allow_list(1240			origin1.clone(),1241			1,1242			account(1)1243		));12441245		assert_noop!(1246			TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1247			Error::<Test>::AddresNotInAllowList1248		);1249	});1250}12511252// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1253#[test]1254fn allow_list_test_3() {1255	new_test_ext().execute_with(|| {1256		let collection_id = create_test_collection(&CollectionMode::NFT, 1);12571258		let origin1 = Origin::signed(1);12591260		let data = default_nft_data();1261		create_test_item(collection_id, &data.into());12621263		assert_ok!(TemplateModule::set_public_access_mode(1264			origin1.clone(),1265			collection_id,1266			AccessMode::AllowList1267		));1268		assert_ok!(TemplateModule::add_to_allow_list(1269			origin1.clone(),1270			1,1271			account(1)1272		));12731274		assert_noop!(1275			TemplateModule::transfer(origin1, account(3), 1, 1, 1),1276			Error::<Test>::AddresNotInAllowList1277		);1278	});1279}12801281#[test]1282fn allow_list_test_4() {1283	new_test_ext().execute_with(|| {1284		let collection_id = create_test_collection(&CollectionMode::NFT, 1);12851286		let origin1 = Origin::signed(1);12871288		let data = default_nft_data();1289		create_test_item(collection_id, &data.into());12901291		assert_ok!(TemplateModule::set_public_access_mode(1292			origin1.clone(),1293			collection_id,1294			AccessMode::AllowList1295		));1296		assert_ok!(TemplateModule::add_to_allow_list(1297			origin1.clone(),1298			collection_id,1299			account(1)1300		));1301		assert_ok!(TemplateModule::add_to_allow_list(1302			origin1.clone(),1303			collection_id,1304			account(2)1305		));13061307		// do approve1308		assert_ok!(TemplateModule::approve(1309			origin1.clone(),1310			account(1),1311			1,1312			1,1313			11314		));1315		assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);13161317		assert_ok!(TemplateModule::remove_from_allow_list(1318			origin1.clone(),1319			collection_id,1320			account(2)1321		));13221323		assert_noop!(1324			TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1325			Error::<Test>::AddresNotInAllowList1326		);1327	});1328}13291330// 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)1331#[test]1332fn allow_list_test_5() {1333	new_test_ext().execute_with(|| {1334		let collection_id = create_test_collection(&CollectionMode::NFT, 1);13351336		let origin1 = Origin::signed(1);13371338		let data = default_nft_data();1339		create_test_item(collection_id, &data.into());13401341		assert_ok!(TemplateModule::set_public_access_mode(1342			origin1.clone(),1343			collection_id,1344			AccessMode::AllowList1345		));1346		assert_noop!(1347			TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1348			Error::<Test>::AddresNotInAllowList1349		);1350	});1351}13521353// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1354#[test]1355fn allow_list_test_6() {1356	new_test_ext().execute_with(|| {1357		let collection_id = create_test_collection(&CollectionMode::NFT, 1);13581359		let origin1 = Origin::signed(1);13601361		let data = default_nft_data();1362		create_test_item(collection_id, &data.into());13631364		assert_ok!(TemplateModule::set_public_access_mode(1365			origin1.clone(),1366			collection_id,1367			AccessMode::AllowList1368		));13691370		// do approve1371		assert_noop!(1372			TemplateModule::approve(origin1, account(1), 1, 1, 5),1373			Error::<Test>::AddresNotInAllowList1374		);1375	});1376}13771378// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1379//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1380#[test]1381fn allow_list_test_7() {1382	new_test_ext().execute_with(|| {1383		let collection_id = create_test_collection(&CollectionMode::NFT, 1);13841385		let data = default_nft_data();1386		create_test_item(collection_id, &data.into());13871388		let origin1 = Origin::signed(1);13891390		assert_ok!(TemplateModule::set_public_access_mode(1391			origin1.clone(),1392			collection_id,1393			AccessMode::AllowList1394		));1395		assert_ok!(TemplateModule::add_to_allow_list(1396			origin1.clone(),1397			collection_id,1398			account(1)1399		));1400		assert_ok!(TemplateModule::add_to_allow_list(1401			origin1.clone(),1402			collection_id,1403			account(2)1404		));14051406		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1));1407	});1408}14091410#[test]1411fn allow_list_test_8() {1412	new_test_ext().execute_with(|| {1413		let collection_id = create_test_collection(&CollectionMode::NFT, 1);14141415		let data = default_nft_data();1416		create_test_item(collection_id, &data.into());14171418		let origin1 = Origin::signed(1);14191420		assert_ok!(TemplateModule::set_public_access_mode(1421			origin1.clone(),1422			collection_id,1423			AccessMode::AllowList1424		));1425		assert_ok!(TemplateModule::add_to_allow_list(1426			origin1.clone(),1427			collection_id,1428			account(1)1429		));1430		assert_ok!(TemplateModule::add_to_allow_list(1431			origin1.clone(),1432			collection_id,1433			account(2)1434		));14351436		// do approve1437		assert_ok!(TemplateModule::approve(1438			origin1.clone(),1439			account(1),1440			1,1441			1,1442			51443		));1444		assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);14451446		assert_ok!(TemplateModule::transfer_from(1447			origin1,1448			account(1),1449			account(2),1450			1,1451			1,1452			11453		));1454	});1455}14561457// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.1458#[test]1459fn allow_list_test_9() {1460	new_test_ext().execute_with(|| {1461		let collection_id = create_test_collection(&CollectionMode::NFT, 1);1462		let origin1 = Origin::signed(1);14631464		assert_ok!(TemplateModule::set_public_access_mode(1465			origin1.clone(),1466			collection_id,1467			AccessMode::AllowList1468		));1469		assert_ok!(TemplateModule::set_mint_permission(1470			origin1,1471			collection_id,1472			false1473		));14741475		let data = default_nft_data();1476		create_test_item(collection_id, &data.into());1477	});1478}14791480// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.1481#[test]1482fn allow_list_test_10() {1483	new_test_ext().execute_with(|| {1484		let collection_id = create_test_collection(&CollectionMode::NFT, 1);14851486		let origin1 = Origin::signed(1);1487		let origin2 = Origin::signed(2);14881489		assert_ok!(TemplateModule::set_public_access_mode(1490			origin1.clone(),1491			collection_id,1492			AccessMode::AllowList1493		));1494		assert_ok!(TemplateModule::set_mint_permission(1495			origin1.clone(),1496			collection_id,1497			false1498		));14991500		assert_ok!(TemplateModule::add_collection_admin(1501			origin1,1502			collection_id,1503			account(2)1504		));15051506		assert_ok!(TemplateModule::create_item(1507			origin2,1508			collection_id,1509			account(2),1510			default_nft_data().into()1511		));1512	});1513}15141515// 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.1516#[test]1517fn allow_list_test_11() {1518	new_test_ext().execute_with(|| {1519		let collection_id = create_test_collection(&CollectionMode::NFT, 1);15201521		let origin1 = Origin::signed(1);1522		let origin2 = Origin::signed(2);15231524		assert_ok!(TemplateModule::set_public_access_mode(1525			origin1.clone(),1526			collection_id,1527			AccessMode::AllowList1528		));1529		assert_ok!(TemplateModule::set_mint_permission(1530			origin1.clone(),1531			collection_id,1532			false1533		));1534		assert_ok!(TemplateModule::add_to_allow_list(1535			origin1,1536			collection_id,1537			account(2)1538		));15391540		assert_noop!(1541			TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1542			Error::<Test>::PublicMintingNotAllowed1543		);1544	});1545}15461547// 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.1548#[test]1549fn allow_list_test_12() {1550	new_test_ext().execute_with(|| {1551		let collection_id = create_test_collection(&CollectionMode::NFT, 1);15521553		let origin1 = Origin::signed(1);1554		let origin2 = Origin::signed(2);15551556		assert_ok!(TemplateModule::set_public_access_mode(1557			origin1.clone(),1558			collection_id,1559			AccessMode::AllowList1560		));1561		assert_ok!(TemplateModule::set_mint_permission(1562			origin1,1563			collection_id,1564			false1565		));15661567		assert_noop!(1568			TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1569			Error::<Test>::PublicMintingNotAllowed1570		);1571	});1572}15731574// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.1575#[test]1576fn allow_list_test_13() {1577	new_test_ext().execute_with(|| {1578		let collection_id = create_test_collection(&CollectionMode::NFT, 1);15791580		let origin1 = Origin::signed(1);15811582		assert_ok!(TemplateModule::set_public_access_mode(1583			origin1.clone(),1584			collection_id,1585			AccessMode::AllowList1586		));1587		assert_ok!(TemplateModule::set_mint_permission(1588			origin1,1589			collection_id,1590			true1591		));15921593		let data = default_nft_data();1594		create_test_item(collection_id, &data.into());1595	});1596}15971598// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.1599#[test]1600fn allow_list_test_14() {1601	new_test_ext().execute_with(|| {1602		let collection_id = create_test_collection(&CollectionMode::NFT, 1);16031604		let origin1 = Origin::signed(1);1605		let origin2 = Origin::signed(2);16061607		assert_ok!(TemplateModule::set_public_access_mode(1608			origin1.clone(),1609			collection_id,1610			AccessMode::AllowList1611		));1612		assert_ok!(TemplateModule::set_mint_permission(1613			origin1.clone(),1614			collection_id,1615			true1616		));16171618		assert_ok!(TemplateModule::add_collection_admin(1619			origin1,1620			collection_id,1621			account(2)1622		));16231624		assert_ok!(TemplateModule::create_item(1625			origin2,1626			1,1627			account(2),1628			default_nft_data().into()1629		));1630	});1631}16321633// 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.1634#[test]1635fn allow_list_test_15() {1636	new_test_ext().execute_with(|| {1637		let collection_id = create_test_collection(&CollectionMode::NFT, 1);16381639		let origin1 = Origin::signed(1);1640		let origin2 = Origin::signed(2);16411642		assert_ok!(TemplateModule::set_public_access_mode(1643			origin1.clone(),1644			collection_id,1645			AccessMode::AllowList1646		));1647		assert_ok!(TemplateModule::set_mint_permission(1648			origin1,1649			collection_id,1650			true1651		));16521653		assert_noop!(1654			TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1655			Error::<Test>::AddresNotInAllowList1656		);1657	});1658}16591660// 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.1661#[test]1662fn allow_list_test_16() {1663	new_test_ext().execute_with(|| {1664		let collection_id = create_test_collection(&CollectionMode::NFT, 1);16651666		let origin1 = Origin::signed(1);1667		let origin2 = Origin::signed(2);16681669		assert_ok!(TemplateModule::set_public_access_mode(1670			origin1.clone(),1671			collection_id,1672			AccessMode::AllowList1673		));1674		assert_ok!(TemplateModule::set_mint_permission(1675			origin1.clone(),1676			collection_id,1677			true1678		));1679		assert_ok!(TemplateModule::add_to_allow_list(1680			origin1,1681			collection_id,1682			account(2)1683		));16841685		assert_ok!(TemplateModule::create_item(1686			origin2,1687			1,1688			account(2),1689			default_nft_data().into()1690		));1691	});1692}16931694// Total number of collections. Positive test1695#[test]1696fn total_number_collections_bound() {1697	new_test_ext().execute_with(|| {1698		create_test_collection(&CollectionMode::NFT, 1);1699	});1700}17011702// Total number of collections. Negotive test1703#[test]1704fn total_number_collections_bound_neg() {1705	new_test_ext().execute_with(|| {1706		let origin1 = Origin::signed(1);17071708		for i in 0..COLLECTION_NUMBER_LIMIT {1709			create_test_collection(&CollectionMode::NFT, i + 1);1710		}17111712		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1713		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();1714		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();17151716		// 11-th collection in chain. Expects error1717		assert_noop!(1718			TemplateModule::create_collection(1719				origin1,1720				col_name1,1721				col_desc1,1722				token_prefix1,1723				CollectionMode::NFT1724			),1725			Error::<Test>::TotalCollectionsLimitExceeded1726		);1727	});1728}17291730// Owned tokens by a single address. Positive test1731#[test]1732fn owned_tokens_bound() {1733	new_test_ext().execute_with(|| {1734		let collection_id = create_test_collection(&CollectionMode::NFT, 1);17351736		let data = default_nft_data();1737		create_test_item(collection_id, &data.clone().into());1738		create_test_item(collection_id, &data.into());1739	});1740}17411742// Owned tokens by a single address. Negotive test1743#[test]1744fn owned_tokens_bound_neg() {1745	new_test_ext().execute_with(|| {1746		let collection_id = create_test_collection(&CollectionMode::NFT, 1);17471748		let origin1 = Origin::signed(1);17491750		for _ in 0..ACCOUNT_TOKEN_OWNERSHIP_LIMIT {1751			let data = default_nft_data();1752			create_test_item(collection_id, &data.clone().into());1753		}17541755		let data = default_nft_data();1756		assert_noop!(1757			TemplateModule::create_item(origin1, 1, account(1), data.into()),1758			Error::<Test>::AccountTokenLimitExceeded1759		);1760	});1761}17621763// Number of collection admins. Positive test1764#[test]1765fn collection_admins_bound() {1766	new_test_ext().execute_with(|| {1767		let collection_id = create_test_collection(&CollectionMode::NFT, 1);17681769		let origin1 = Origin::signed(1);17701771		assert_ok!(TemplateModule::add_collection_admin(1772			origin1.clone(),1773			collection_id,1774			account(2)1775		));1776		assert_ok!(TemplateModule::add_collection_admin(1777			origin1,1778			collection_id,1779			account(3)1780		));1781	});1782}17831784// Number of collection admins. Negotive test1785#[test]1786fn collection_admins_bound_neg() {1787	new_test_ext().execute_with(|| {1788		let collection_id = create_test_collection(&CollectionMode::NFT, 1);17891790		let origin1 = Origin::signed(1);17911792		for i in 0..COLLECTION_ADMINS_LIMIT {1793			assert_ok!(TemplateModule::add_collection_admin(1794				origin1.clone(),1795				collection_id,1796				account(2 + i)1797			));1798		}1799		assert_noop!(1800			TemplateModule::add_collection_admin(1801				origin1,1802				collection_id,1803				account(3 + COLLECTION_ADMINS_LIMIT)1804			),1805			Error::<Test>::CollectionAdminsLimitExceeded1806		);1807	});1808}1809// #endregion18101811#[test]1812fn set_const_on_chain_schema() {1813	new_test_ext().execute_with(|| {1814		let collection_id = create_test_collection(&CollectionMode::NFT, 1);18151816		let origin1 = Origin::signed(1);1817		assert_ok!(TemplateModule::set_const_on_chain_schema(1818			origin1,1819			collection_id,1820			b"test const on chain schema".to_vec()1821		));18221823		assert_eq!(1824			TemplateModule::collection_id(collection_id)1825				.unwrap()1826				.const_on_chain_schema,1827			b"test const on chain schema".to_vec()1828		);1829		assert_eq!(1830			TemplateModule::collection_id(collection_id)1831				.unwrap()1832				.variable_on_chain_schema,1833			b"".to_vec()1834		);1835	});1836}18371838#[test]1839fn set_variable_on_chain_schema() {1840	new_test_ext().execute_with(|| {1841		let collection_id = create_test_collection(&CollectionMode::NFT, 1);18421843		let origin1 = Origin::signed(1);1844		assert_ok!(TemplateModule::set_variable_on_chain_schema(1845			origin1,1846			collection_id,1847			b"test variable on chain schema".to_vec()1848		));18491850		assert_eq!(1851			TemplateModule::collection_id(collection_id)1852				.unwrap()1853				.const_on_chain_schema,1854			b"".to_vec()1855		);1856		assert_eq!(1857			TemplateModule::collection_id(collection_id)1858				.unwrap()1859				.variable_on_chain_schema,1860			b"test variable on chain schema".to_vec()1861		);1862	});1863}18641865#[test]1866fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1867	new_test_ext().execute_with(|| {1868		let collection_id = create_test_collection(&CollectionMode::NFT, 1);18691870		let origin1 = Origin::signed(1);18711872		let data = default_nft_data();1873		create_test_item(1, &data.into());18741875		let variable_data = b"test data".to_vec();1876		assert_ok!(TemplateModule::set_variable_meta_data(1877			origin1,1878			collection_id,1879			1,1880			variable_data.clone()1881		));18821883		assert_eq!(1884			TemplateModule::nft_item_id(collection_id, 1)1885				.unwrap()1886				.variable_data,1887			variable_data1888		);1889	});1890}18911892#[test]1893fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1894	new_test_ext().execute_with(|| {1895		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);18961897		let origin1 = Origin::signed(1);18981899		let data = default_re_fungible_data();1900		create_test_item(1, &data.into());19011902		let variable_data = b"test data".to_vec();1903		assert_ok!(TemplateModule::set_variable_meta_data(1904			origin1,1905			collection_id,1906			1,1907			variable_data.clone()1908		));19091910		assert_eq!(1911			TemplateModule::refungible_item_id(collection_id, 1)1912				.unwrap()1913				.variable_data,1914			variable_data1915		);1916	});1917}19181919#[test]1920fn set_variable_meta_data_on_fungible_token_fails() {1921	new_test_ext().execute_with(|| {1922		let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);19231924		let origin1 = Origin::signed(1);19251926		let data = default_fungible_data();1927		create_test_item(1, &data.into());19281929		let variable_data = b"test data".to_vec();1930		assert_noop!(1931			TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),1932			Error::<Test>::CantStoreMetadataInFungibleTokens1933		);1934	});1935}19361937#[test]1938fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1939	new_test_ext().execute_with(|| {1940		let collection_id = create_test_collection(&CollectionMode::NFT, 1);19411942		let origin1 = Origin::signed(1);19431944		let data = default_nft_data();1945		create_test_item(1, &data.into());19461947		let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1948		assert_noop!(1949			TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),1950			Error::<Test>::TokenVariableDataLimitExceeded1951		);1952	});1953}19541955#[test]1956fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {1957	new_test_ext().execute_with(|| {1958		let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);19591960		let origin1 = Origin::signed(1);19611962		let data = default_re_fungible_data();1963		create_test_item(1, &data.into());19641965		let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1966		assert_noop!(1967			TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),1968			Error::<Test>::TokenVariableDataLimitExceeded1969		);1970	});1971}19721973#[test]1974fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {1975	new_test_ext().execute_with(|| {1976		//default_limits();19771978		let collection_id = create_test_collection(&CollectionMode::NFT, 1);19791980		let origin1 = Origin::signed(1);19811982		let data = default_nft_data();1983		create_test_item(1, &data.into());19841985		assert_ok!(TemplateModule::set_meta_update_permission_flag(1986			origin1.clone(),1987			collection_id,1988			MetaUpdatePermission::ItemOwner,1989		));19901991		let variable_data = b"ten chars.".to_vec();1992		assert_ok!(TemplateModule::set_variable_meta_data(1993			origin1,1994			collection_id,1995			1,1996			variable_data.clone()1997		));19981999		assert_eq!(2000			TemplateModule::nft_item_id(collection_id, 1)2001				.unwrap()2002				.variable_data,2003			variable_data2004		);2005	});2006}20072008#[test]2009fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {2010	new_test_ext().execute_with(|| {2011		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);20122013		let origin1 = Origin::signed(1);20142015		assert_ok!(TemplateModule::set_mint_permission(2016			origin1.clone(),2017			collection_id,2018			true2019		));2020		assert_ok!(TemplateModule::add_to_allow_list(2021			origin1.clone(),2022			collection_id,2023			account(1)2024		));20252026		let data = default_nft_data();2027		create_test_item(1, &data.into());20282029		assert_ok!(TemplateModule::set_meta_update_permission_flag(2030			origin1.clone(),2031			collection_id,2032			MetaUpdatePermission::ItemOwner,2033		));20342035		let variable_data = b"1234567890123".to_vec();2036		assert_noop!(2037			TemplateModule::set_variable_meta_data(2038				origin1,2039				collection_id,2040				1,2041				variable_data.clone()2042			),2043			Error::<Test>::TokenVariableDataLimitExceeded2044		);2045	})2046}20472048#[test]2049fn collection_transfer_flag_works() {2050	new_test_ext().execute_with(|| {2051		let origin1 = Origin::signed(1);20522053		let collection_id = create_test_collection(&CollectionMode::NFT, 1);2054		assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));20552056		let data = default_nft_data();2057		create_test_item(collection_id, &data.into());2058		assert_eq!(TemplateModule::balance_count(1, 1), 1);2059		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);20602061		let origin1 = Origin::signed(1);20622063		// default scenario2064		assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));2065		assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));2066		assert_eq!(TemplateModule::balance_count(1, 1), 0);2067		assert_eq!(TemplateModule::balance_count(1, 2), 1);20682069		assert_eq!(TemplateModule::address_tokens(1, 2), [1]);2070	});2071}20722073#[test]2074fn set_variable_meta_data_on_nft_with_admin_flag() {2075	new_test_ext().execute_with(|| {2076		// default_limits();20772078		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);20792080		let origin1 = Origin::signed(1);2081		let origin2 = Origin::signed(2);20822083		assert_ok!(TemplateModule::set_mint_permission(2084			origin2.clone(),2085			collection_id,2086			true2087		));2088		assert_ok!(TemplateModule::add_to_allow_list(2089			origin2.clone(),2090			collection_id,2091			account(1)2092		));20932094		assert_ok!(TemplateModule::add_collection_admin(2095			origin2.clone(),2096			collection_id,2097			account(1)2098		));20992100		let data = default_nft_data();2101		create_test_item(1, &data.into());21022103		assert_ok!(TemplateModule::set_meta_update_permission_flag(2104			origin2.clone(),2105			collection_id,2106			MetaUpdatePermission::Admin,2107		));21082109		let variable_data = b"test.".to_vec();2110		assert_ok!(TemplateModule::set_variable_meta_data(2111			origin1,2112			collection_id,2113			1,2114			variable_data.clone()2115		));21162117		assert_eq!(2118			TemplateModule::nft_item_id(collection_id, 1)2119				.unwrap()2120				.variable_data,2121			variable_data2122		);2123	});2124}21252126#[test]2127fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2128	new_test_ext().execute_with(|| {2129		// default_limits();21302131		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);21322133		let origin1 = Origin::signed(1);2134		let origin2 = Origin::signed(2);21352136		assert_ok!(TemplateModule::set_mint_permission(2137			origin2.clone(),2138			collection_id,2139			true2140		));2141		assert_ok!(TemplateModule::add_to_allow_list(2142			origin2.clone(),2143			collection_id,2144			account(1)2145		));21462147		let data = default_nft_data();2148		create_test_item(1, &data.into());21492150		assert_ok!(TemplateModule::set_meta_update_permission_flag(2151			origin2.clone(),2152			collection_id,2153			MetaUpdatePermission::Admin,2154		));21552156		let variable_data = b"test.".to_vec();2157		assert_noop!(2158			TemplateModule::set_variable_meta_data(2159				origin1,2160				collection_id,2161				1,2162				variable_data.clone()2163			),2164			Error::<Test>::NoPermission2165		);2166	});2167}21682169#[test]2170fn set_variable_meta_flag_after_freeze() {2171	new_test_ext().execute_with(|| {2172		// default_limits();21732174		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);21752176		let origin2 = Origin::signed(2);21772178		assert_ok!(TemplateModule::set_meta_update_permission_flag(2179			origin2.clone(),2180			collection_id,2181			MetaUpdatePermission::None,2182		));2183		assert_noop!(2184			TemplateModule::set_meta_update_permission_flag(2185				origin2.clone(),2186				collection_id,2187				MetaUpdatePermission::Admin2188			),2189			Error::<Test>::MetadataFlagFrozen2190		);2191	});2192}21932194#[test]2195fn set_variable_meta_data_on_nft_with_none_flag_neg() {2196	new_test_ext().execute_with(|| {2197		// default_limits();21982199		let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);2200		let origin1 = Origin::signed(1);22012202		let data = default_nft_data();2203		create_test_item(1, &data.into());22042205		assert_ok!(TemplateModule::set_meta_update_permission_flag(2206			origin1.clone(),2207			collection_id,2208			MetaUpdatePermission::None,2209		));22102211		let variable_data = b"test.".to_vec();2212		assert_noop!(2213			TemplateModule::set_variable_meta_data(2214				origin1.clone(),2215				collection_id,2216				1,2217				variable_data.clone()2218			),2219			Error::<Test>::MetadataUpdateDenied2220		);2221	});2222}22232224#[test]2225fn collection_transfer_flag_works_neg() {2226	new_test_ext().execute_with(|| {2227		let origin1 = Origin::signed(1);22282229		let collection_id = create_test_collection(&CollectionMode::NFT, 1);2230		assert_ok!(TemplateModule::set_transfers_enabled_flag(2231			origin1, 1, false2232		));22332234		let data = default_nft_data();2235		create_test_item(collection_id, &data.into());2236		assert_eq!(TemplateModule::balance_count(1, 1), 1);2237		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);22382239		let origin1 = Origin::signed(1);22402241		// default scenario2242		assert_noop!(2243			TemplateModule::transfer(origin1, account(2), 1, 1, 1000),2244			Error::<Test>::TransferNotAllowed2245		);2246		assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));2247		assert_eq!(TemplateModule::balance_count(1, 1), 1);2248		assert_eq!(TemplateModule::balance_count(1, 2), 0);22492250		assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2251	});2252}