git.delta.rocks / unique-network / refs/commits / 6c1cc7ee4bff

difftreelog

Merge pull request #242 from UniqueNetwork/feature/fix_unit_tests

kozyrevdev2021-11-25parents: #3def18a #5c2c651.patch.diff
in: master
Fix unit tests

13 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4939,216 +4939,6 @@
 ]
 
 [[package]]
-name = "nft"
-version = "0.9.12"
-dependencies = [
- "cumulus-client-cli",
- "cumulus-client-collator",
- "cumulus-client-consensus-aura",
- "cumulus-client-consensus-common",
- "cumulus-client-network",
- "cumulus-client-service",
- "cumulus-primitives-core",
- "cumulus-primitives-parachain-inherent",
- "fc-consensus",
- "fc-db",
- "fc-mapping-sync",
- "fc-rpc",
- "fc-rpc-core",
- "flexi_logger",
- "fp-rpc",
- "frame-benchmarking",
- "frame-benchmarking-cli",
- "futures 0.3.17",
- "jsonrpc-core",
- "jsonrpc-pubsub",
- "log",
- "nft-data-structs",
- "nft-rpc",
- "nft-runtime",
- "pallet-ethereum",
- "pallet-transaction-payment-rpc",
- "parity-scale-codec",
- "parking_lot 0.11.2",
- "polkadot-cli",
- "polkadot-parachain",
- "polkadot-primitives",
- "polkadot-service",
- "polkadot-test-service",
- "sc-basic-authorship",
- "sc-chain-spec",
- "sc-cli",
- "sc-client-api",
- "sc-consensus",
- "sc-consensus-aura",
- "sc-executor",
- "sc-finality-grandpa",
- "sc-keystore",
- "sc-network",
- "sc-rpc",
- "sc-rpc-api",
- "sc-service",
- "sc-telemetry",
- "sc-tracing",
- "sc-transaction-pool",
- "serde",
- "serde_json",
- "sp-api",
- "sp-block-builder",
- "sp-blockchain",
- "sp-consensus",
- "sp-consensus-aura",
- "sp-core",
- "sp-finality-grandpa",
- "sp-inherents",
- "sp-keystore",
- "sp-offchain",
- "sp-runtime",
- "sp-session",
- "sp-timestamp",
- "sp-transaction-pool",
- "sp-trie",
- "structopt",
- "substrate-build-script-utils",
- "substrate-frame-rpc-system",
- "substrate-prometheus-endpoint",
-]
-
-[[package]]
-name = "nft-data-structs"
-version = "0.9.0"
-dependencies = [
- "derivative",
- "frame-support",
- "frame-system",
- "parity-scale-codec",
- "scale-info",
- "serde",
- "sp-core",
- "sp-runtime",
- "sp-std",
-]
-
-[[package]]
-name = "nft-rpc"
-version = "3.3.1"
-dependencies = [
- "fc-db",
- "fc-mapping-sync",
- "fc-rpc",
- "fc-rpc-core",
- "fp-rpc",
- "futures 0.3.17",
- "jsonrpc-core",
- "jsonrpc-pubsub",
- "nft-runtime",
- "pallet-ethereum",
- "pallet-nft",
- "pallet-transaction-payment-rpc",
- "pallet-transaction-payment-rpc-runtime-api",
- "sc-client-api",
- "sc-consensus-aura",
- "sc-consensus-epochs",
- "sc-finality-grandpa",
- "sc-finality-grandpa-rpc",
- "sc-keystore",
- "sc-network",
- "sc-rpc",
- "sc-rpc-api",
- "sc-service",
- "sc-transaction-pool",
- "sp-api",
- "sp-block-builder",
- "sp-blockchain",
- "sp-consensus",
- "sp-consensus-aura",
- "sp-core",
- "sp-offchain",
- "sp-runtime",
- "sp-session",
- "sp-storage",
- "sp-transaction-pool",
- "substrate-frame-rpc-system",
- "tokio 0.2.25",
- "uc-rpc",
- "up-rpc",
-]
-
-[[package]]
-name = "nft-runtime"
-version = "0.9.12"
-dependencies = [
- "cumulus-pallet-aura-ext",
- "cumulus-pallet-dmp-queue",
- "cumulus-pallet-parachain-system",
- "cumulus-pallet-xcm",
- "cumulus-pallet-xcmp-queue",
- "cumulus-primitives-core",
- "cumulus-primitives-timestamp",
- "cumulus-primitives-utility",
- "derivative",
- "fp-rpc",
- "fp-self-contained",
- "frame-benchmarking",
- "frame-executive",
- "frame-support",
- "frame-system",
- "frame-system-benchmarking",
- "frame-system-rpc-runtime-api",
- "hex-literal",
- "nft-data-structs",
- "orml-vesting",
- "pallet-aura",
- "pallet-balances",
- "pallet-common",
- "pallet-ethereum",
- "pallet-evm",
- "pallet-evm-coder-substrate",
- "pallet-evm-contract-helpers",
- "pallet-evm-migration",
- "pallet-evm-transaction-payment",
- "pallet-fungible",
- "pallet-inflation",
- "pallet-nft",
- "pallet-nonfungible",
- "pallet-randomness-collective-flip",
- "pallet-refungible",
- "pallet-sudo",
- "pallet-template-transaction-payment",
- "pallet-timestamp",
- "pallet-transaction-payment",
- "pallet-transaction-payment-rpc-runtime-api",
- "pallet-treasury",
- "pallet-unq-scheduler",
- "pallet-xcm",
- "parachain-info",
- "parity-scale-codec",
- "polkadot-parachain",
- "scale-info",
- "serde",
- "smallvec",
- "sp-api",
- "sp-arithmetic",
- "sp-block-builder",
- "sp-consensus-aura",
- "sp-core",
- "sp-inherents",
- "sp-io",
- "sp-offchain",
- "sp-runtime",
- "sp-session",
- "sp-std",
- "sp-transaction-pool",
- "sp-version",
- "substrate-wasm-builder",
- "up-evm-mapping",
- "up-rpc",
- "xcm",
- "xcm-builder",
- "xcm-executor",
-]
-
-[[package]]
 name = "nodrop"
 version = "0.1.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -5581,7 +5371,6 @@
  "evm-coder",
  "frame-support",
  "frame-system",
- "nft-data-structs",
  "pallet-evm",
  "pallet-evm-coder-substrate",
  "parity-scale-codec",
@@ -5590,6 +5379,7 @@
  "sp-core",
  "sp-runtime",
  "sp-std",
+ "up-data-structs",
  "up-evm-mapping",
 ]
 
@@ -5853,7 +5643,6 @@
  "frame-benchmarking",
  "frame-support",
  "frame-system",
- "nft-data-structs",
  "pallet-common",
  "pallet-evm-coder-substrate",
  "parity-scale-codec",
@@ -5861,6 +5650,7 @@
  "sp-core",
  "sp-runtime",
  "sp-std",
+ "up-data-structs",
 ]
 
 [[package]]
@@ -5956,7 +5746,7 @@
 
 [[package]]
 name = "pallet-inflation"
-version = "3.0.0"
+version = "0.1.0"
 dependencies = [
  "frame-benchmarking",
  "frame-support",
@@ -6057,43 +5847,6 @@
 ]
 
 [[package]]
-name = "pallet-nft"
-version = "3.0.0"
-dependencies = [
- "ethereum 0.9.0 (git+https://github.com/purestake/ethereum?branch=joshy-scale-info)",
- "evm-coder",
- "fp-evm",
- "frame-benchmarking",
- "frame-support",
- "frame-system",
- "hex-literal",
- "nft-data-structs",
- "pallet-balances",
- "pallet-common",
- "pallet-ethereum",
- "pallet-evm",
- "pallet-evm-coder-substrate",
- "pallet-fungible",
- "pallet-nonfungible",
- "pallet-randomness-collective-flip",
- "pallet-refungible",
- "pallet-timestamp",
- "pallet-transaction-payment",
- "parity-scale-codec",
- "primitive-types 0.10.1",
- "rlp",
- "scale-info",
- "serde",
- "sp-api",
- "sp-core",
- "sp-io",
- "sp-runtime",
- "sp-std",
- "up-evm-mapping",
- "up-sponsorship",
-]
-
-[[package]]
 name = "pallet-nicks"
 version = "4.0.0-dev"
 source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.12#d76f39995315ec36980908e4b99709bd14927044"
@@ -6116,7 +5869,6 @@
  "frame-benchmarking",
  "frame-support",
  "frame-system",
- "nft-data-structs",
  "pallet-common",
  "pallet-evm-coder-substrate",
  "parity-scale-codec",
@@ -6124,6 +5876,7 @@
  "sp-core",
  "sp-runtime",
  "sp-std",
+ "up-data-structs",
 ]
 
 [[package]]
@@ -6216,13 +5969,13 @@
  "frame-benchmarking",
  "frame-support",
  "frame-system",
- "nft-data-structs",
  "pallet-common",
  "parity-scale-codec",
  "scale-info",
  "sp-core",
  "sp-runtime",
  "sp-std",
+ "up-data-structs",
 ]
 
 [[package]]
@@ -6469,8 +6222,45 @@
 ]
 
 [[package]]
+name = "pallet-unique"
+version = "0.1.0"
+dependencies = [
+ "ethereum 0.9.0 (git+https://github.com/purestake/ethereum?branch=joshy-scale-info)",
+ "evm-coder",
+ "fp-evm",
+ "frame-benchmarking",
+ "frame-support",
+ "frame-system",
+ "hex-literal",
+ "pallet-balances",
+ "pallet-common",
+ "pallet-ethereum",
+ "pallet-evm",
+ "pallet-evm-coder-substrate",
+ "pallet-fungible",
+ "pallet-nonfungible",
+ "pallet-randomness-collective-flip",
+ "pallet-refungible",
+ "pallet-timestamp",
+ "pallet-transaction-payment",
+ "parity-scale-codec",
+ "primitive-types 0.10.1",
+ "rlp",
+ "scale-info",
+ "serde",
+ "sp-api",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+ "up-data-structs",
+ "up-evm-mapping",
+ "up-sponsorship",
+]
+
+[[package]]
 name = "pallet-unq-scheduler"
-version = "3.0.0"
+version = "0.1.0"
 dependencies = [
  "frame-benchmarking",
  "frame-support",
@@ -11714,7 +11504,6 @@
  "jsonrpc-core",
  "jsonrpc-core-client",
  "jsonrpc-derive",
- "nft-data-structs",
  "pallet-common",
  "parity-scale-codec",
  "sp-api",
@@ -11722,6 +11511,7 @@
  "sp-core",
  "sp-rpc",
  "sp-runtime",
+ "up-data-structs",
  "up-rpc",
 ]
 
@@ -11786,6 +11576,201 @@
 checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
 
 [[package]]
+name = "unique-node"
+version = "0.9.12"
+dependencies = [
+ "cumulus-client-cli",
+ "cumulus-client-collator",
+ "cumulus-client-consensus-aura",
+ "cumulus-client-consensus-common",
+ "cumulus-client-network",
+ "cumulus-client-service",
+ "cumulus-primitives-core",
+ "cumulus-primitives-parachain-inherent",
+ "fc-consensus",
+ "fc-db",
+ "fc-mapping-sync",
+ "fc-rpc",
+ "fc-rpc-core",
+ "flexi_logger",
+ "fp-rpc",
+ "frame-benchmarking",
+ "frame-benchmarking-cli",
+ "futures 0.3.17",
+ "jsonrpc-core",
+ "jsonrpc-pubsub",
+ "log",
+ "pallet-ethereum",
+ "pallet-transaction-payment-rpc",
+ "parity-scale-codec",
+ "parking_lot 0.11.2",
+ "polkadot-cli",
+ "polkadot-parachain",
+ "polkadot-primitives",
+ "polkadot-service",
+ "polkadot-test-service",
+ "sc-basic-authorship",
+ "sc-chain-spec",
+ "sc-cli",
+ "sc-client-api",
+ "sc-consensus",
+ "sc-consensus-aura",
+ "sc-executor",
+ "sc-finality-grandpa",
+ "sc-keystore",
+ "sc-network",
+ "sc-rpc",
+ "sc-rpc-api",
+ "sc-service",
+ "sc-telemetry",
+ "sc-tracing",
+ "sc-transaction-pool",
+ "serde",
+ "serde_json",
+ "sp-api",
+ "sp-block-builder",
+ "sp-blockchain",
+ "sp-consensus",
+ "sp-consensus-aura",
+ "sp-core",
+ "sp-finality-grandpa",
+ "sp-inherents",
+ "sp-keystore",
+ "sp-offchain",
+ "sp-runtime",
+ "sp-session",
+ "sp-timestamp",
+ "sp-transaction-pool",
+ "sp-trie",
+ "structopt",
+ "substrate-build-script-utils",
+ "substrate-frame-rpc-system",
+ "substrate-prometheus-endpoint",
+ "unique-rpc",
+ "unique-runtime",
+ "up-data-structs",
+]
+
+[[package]]
+name = "unique-rpc"
+version = "0.1.0"
+dependencies = [
+ "fc-db",
+ "fc-mapping-sync",
+ "fc-rpc",
+ "fc-rpc-core",
+ "fp-rpc",
+ "futures 0.3.17",
+ "jsonrpc-core",
+ "jsonrpc-pubsub",
+ "pallet-ethereum",
+ "pallet-transaction-payment-rpc",
+ "pallet-transaction-payment-rpc-runtime-api",
+ "pallet-unique",
+ "sc-client-api",
+ "sc-consensus-aura",
+ "sc-consensus-epochs",
+ "sc-finality-grandpa",
+ "sc-finality-grandpa-rpc",
+ "sc-keystore",
+ "sc-network",
+ "sc-rpc",
+ "sc-rpc-api",
+ "sc-service",
+ "sc-transaction-pool",
+ "sp-api",
+ "sp-block-builder",
+ "sp-blockchain",
+ "sp-consensus",
+ "sp-consensus-aura",
+ "sp-core",
+ "sp-offchain",
+ "sp-runtime",
+ "sp-session",
+ "sp-storage",
+ "sp-transaction-pool",
+ "substrate-frame-rpc-system",
+ "tokio 0.2.25",
+ "uc-rpc",
+ "unique-runtime",
+ "up-rpc",
+]
+
+[[package]]
+name = "unique-runtime"
+version = "0.9.12"
+dependencies = [
+ "cumulus-pallet-aura-ext",
+ "cumulus-pallet-dmp-queue",
+ "cumulus-pallet-parachain-system",
+ "cumulus-pallet-xcm",
+ "cumulus-pallet-xcmp-queue",
+ "cumulus-primitives-core",
+ "cumulus-primitives-timestamp",
+ "cumulus-primitives-utility",
+ "derivative",
+ "fp-rpc",
+ "fp-self-contained",
+ "frame-benchmarking",
+ "frame-executive",
+ "frame-support",
+ "frame-system",
+ "frame-system-benchmarking",
+ "frame-system-rpc-runtime-api",
+ "hex-literal",
+ "orml-vesting",
+ "pallet-aura",
+ "pallet-balances",
+ "pallet-common",
+ "pallet-ethereum",
+ "pallet-evm",
+ "pallet-evm-coder-substrate",
+ "pallet-evm-contract-helpers",
+ "pallet-evm-migration",
+ "pallet-evm-transaction-payment",
+ "pallet-fungible",
+ "pallet-inflation",
+ "pallet-nonfungible",
+ "pallet-randomness-collective-flip",
+ "pallet-refungible",
+ "pallet-sudo",
+ "pallet-template-transaction-payment",
+ "pallet-timestamp",
+ "pallet-transaction-payment",
+ "pallet-transaction-payment-rpc-runtime-api",
+ "pallet-treasury",
+ "pallet-unique",
+ "pallet-unq-scheduler",
+ "pallet-xcm",
+ "parachain-info",
+ "parity-scale-codec",
+ "polkadot-parachain",
+ "scale-info",
+ "serde",
+ "smallvec",
+ "sp-api",
+ "sp-arithmetic",
+ "sp-block-builder",
+ "sp-consensus-aura",
+ "sp-core",
+ "sp-inherents",
+ "sp-io",
+ "sp-offchain",
+ "sp-runtime",
+ "sp-session",
+ "sp-std",
+ "sp-transaction-pool",
+ "sp-version",
+ "substrate-wasm-builder",
+ "up-data-structs",
+ "up-evm-mapping",
+ "up-rpc",
+ "xcm",
+ "xcm-builder",
+ "xcm-executor",
+]
+
+[[package]]
 name = "universal-hash"
 version = "0.4.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -11832,6 +11817,21 @@
 checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
 
 [[package]]
+name = "up-data-structs"
+version = "0.1.0"
+dependencies = [
+ "derivative",
+ "frame-support",
+ "frame-system",
+ "parity-scale-codec",
+ "scale-info",
+ "serde",
+ "sp-core",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
 name = "up-evm-mapping"
 version = "0.1.0"
 dependencies = [
@@ -11843,13 +11843,13 @@
 name = "up-rpc"
 version = "0.1.0"
 dependencies = [
- "nft-data-structs",
  "pallet-common",
  "parity-scale-codec",
  "sp-api",
  "sp-core",
  "sp-runtime",
  "sp-std",
+ "up-data-structs",
 ]
 
 [[package]]
modifiedpallets/common/src/account.rsdiffbeforeafterboth
--- a/pallets/common/src/account.rs
+++ b/pallets/common/src/account.rs
@@ -7,7 +7,7 @@
 use pallet_evm::AddressMapping;
 use sp_std::vec::Vec;
 use sp_std::clone::Clone;
-use up_evm_mapping::EvmBackwardsAddressMapping;
+pub use up_evm_mapping::EvmBackwardsAddressMapping;
 
 pub trait CrossAccountId<AccountId>:
 	Encode + EncodeLike + Decode + TypeInfo + Clone + PartialEq + Ord + core::fmt::Debug + Default
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -273,8 +273,8 @@
 		TotalCollectionsLimitExceeded,
 		/// variable_data exceeded data limit.
 		TokenVariableDataLimitExceeded,
-		/// Exceeded max admin amount
-		CollectionAdminAmountExceeded,
+		/// Exceeded max admin count
+		CollectionAdminCountExceeded,
 
 		/// Collection settings not allowing items transferring
 		TransferNotAllowed,
@@ -506,10 +506,10 @@
 		if admin {
 			let amount = amount
 				.checked_add(1)
-				.ok_or(<Error<T>>::CollectionAdminAmountExceeded)?;
+				.ok_or(<Error<T>>::CollectionAdminCountExceeded)?;
 			ensure!(
 				amount <= Self::collection_admins_limit(),
-				<Error<T>>::CollectionAdminAmountExceeded,
+				<Error<T>>::CollectionAdminCountExceeded,
 			);
 
 			// =========
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -182,7 +182,7 @@
 		_token: TokenId,
 		_data: Vec<u8>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::FungibleItemsHaveData)
+		fail!(<Error<T>>::FungibleItemsDontHaveData)
 	}
 
 	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -35,7 +35,7 @@
 		/// Not default id passed as TokenId argument
 		FungibleItemsHaveNoId,
 		/// Tried to set data for fungible item
-		FungibleItemsHaveData,
+		FungibleItemsDontHaveData,
 	}
 
 	#[pallet::config]
@@ -48,7 +48,7 @@
 	pub struct Pallet<T>(_);
 
 	#[pallet::storage]
-	pub(super) type TotalSupply<T: Config> =
+	pub type TotalSupply<T: Config> =
 		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;
 
 	#[pallet::storage]
@@ -62,7 +62,7 @@
 	>;
 
 	#[pallet::storage]
-	pub(super) type Allowance<T: Config> = StorageNMap<
+	pub type Allowance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
 			Key<Blake2_128, T::CrossAccountId>,
modifiedpallets/inflation/src/lib.rsdiffbeforeafterboth
--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -46,7 +46,8 @@
 pub type BalanceOf<T> =
 	<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
 
-pub const YEAR: u32 = 5_259_600;
+// pub const YEAR: u32 = 5_259_600; // 6-second block
+pub const YEAR: u32 = 2_629_800; // 12-second block
 pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;
 pub const START_INFLATION_PERCENT: u32 = 10;
 pub const END_INFLATION_PERCENT: u32 = 4;
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -18,7 +18,7 @@
 type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
 type Block = frame_system::mocking::MockBlock<Test>;
 
-const YEAR: u64 = 5_259_600;
+const YEAR: u64 = 2_629_800;
 
 parameter_types! {
 	pub const ExistentialDeposit: u64 = 1;
@@ -112,8 +112,8 @@
 		// first inflation deposit should be equal to BlockInflation
 		Inflation::on_initialize(1);
 
-		// SBP M2 review: Verify expected block inflation for year 1
-		assert_eq!(Inflation::block_inflation(), 1901);
+		// Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = 3803
+		assert_eq!(Inflation::block_inflation(), 3803);
 		assert_eq!(
 			Balances::free_balance(1234) - initial_issuance,
 			Inflation::block_inflation()
@@ -158,26 +158,21 @@
 		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 		Inflation::on_initialize(1);
-		let block_inflation_year_0 = Inflation::block_inflation();
 
-		// SBP M2 review: go through all the block inflations for year 1,
+		// Go through all the block inflations for year 1,
 		// total issuance will be updated accordingly
 		for block in (100..YEAR).step_by(100) {
 			Inflation::on_initialize(block);
 		}
 		assert_eq!(
-			initial_issuance + (1901 * (YEAR / 100)),
+			initial_issuance + (3803 * (YEAR / 100)),
 			<Balances as Currency<_>>::total_issuance()
 		);
 
 		Inflation::on_initialize(YEAR);
 		let block_inflation_year_1 = Inflation::block_inflation();
-		// SBP M2 review: Verify expected block inflation for year 2
-		assert_eq!(block_inflation_year_1, 1952);
-
-		// SBP M2 review: this is actually not true
-		// Assert that year 1 inflation is less than year 0
-		// assert!(block_inflation_year_0 > block_inflation_year_1);
+		// Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR = 3904
+		assert_eq!(block_inflation_year_1, 3904);
 	});
 }
 
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -58,7 +58,7 @@
 	}
 
 	#[pallet::pallet]
-	#[pallet::generate_store(pub trait Store)]
+	#[pallet::generate_store(pub(super) trait Store)]
 	pub struct Pallet<T>(_);
 
 	#[pallet::storage]
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -54,7 +54,7 @@
 	}
 
 	#[pallet::pallet]
-	#[pallet::generate_store(pub trait Store)]
+	#[pallet::generate_store(pub(super) trait Store)]
 	pub struct Pallet<T>(_);
 
 	#[pallet::storage]
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -738,9 +738,7 @@
 	use super::*;
 
 	use frame_support::{
-		Hashable, assert_err, assert_noop, assert_ok, ord_parameter_types, parameter_types,
-		traits::{Contains, OnFinalize, OnInitialize},
-		weights::constants::RocksDbWeight,
+		ord_parameter_types, parameter_types, traits::Contains, weights::constants::RocksDbWeight,
 	};
 	use sp_core::H256;
 	use sp_runtime::{
@@ -749,7 +747,6 @@
 		traits::{BlakeTwo256, IdentityLookup},
 	};
 	use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};
-	use substrate_test_utils::assert_eq_uvec;
 	use crate as scheduler;
 
 	mod logger {
@@ -758,9 +755,6 @@
 
 		thread_local! {
 			static LOG: RefCell<Vec<(OriginCaller, u32)>> = RefCell::new(Vec::new());
-		}
-		pub fn log() -> Vec<(OriginCaller, u32)> {
-			LOG.with(|log| log.borrow().clone())
 		}
 		pub trait Config: system::Config {
 			type Event: From<Event> + Into<<Self as system::Config>::Event>;
@@ -871,24 +865,5 @@
 		type MaxScheduledPerBlock = MaxScheduledPerBlock;
 		type WeightInfo = ();
 		type SponsorshipHandler = ();
-	}
-
-	pub fn new_test_ext() -> sp_io::TestExternalities {
-		let t = system::GenesisConfig::default()
-			.build_storage::<Test>()
-			.unwrap();
-		t.into()
-	}
-
-	fn run_to_block(n: u64) {
-		while System::block_number() < n {
-			Scheduler::on_finalize(System::block_number());
-			System::set_block_number(System::block_number() + 1);
-			Scheduler::on_initialize(System::block_number());
-		}
-	}
-
-	fn root() -> OriginCaller {
-		system::RawOrigin::Root.into()
 	}
 }
modifiedpallets/unique/src/mock.rsdiffbeforeafterboth
--- a/pallets/unique/src/mock.rs
+++ b/pallets/unique/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;
 
@@ -27,6 +27,10 @@
 		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
 		TemplateModule: pallet_template::{Pallet, Call, Storage},
 		Balances: pallet_balances::{Pallet, Call, Storage},
+		Common: pallet_common::{Pallet, Storage, Event<T>},
+		Fungible: pallet_fungible::{Pallet, Storage},
+		Refungible: pallet_refungible::{Pallet, Storage},
+		Nonfungible: pallet_nonfungible::{Pallet, Storage},
 	}
 );
 
@@ -124,13 +128,16 @@
 #[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]
 pub struct TestCrossAccountId(u64, sp_core::H160);
 impl CrossAccountId<u64> for TestCrossAccountId {
+	fn as_sub(&self) -> &u64 {
+		&self.0
+	}
+	fn as_eth(&self) -> &sp_core::H160 {
+		&self.1
+	}
 	fn from_sub(sub: u64) -> Self {
 		let mut eth = [0; 20];
 		eth[12..20].copy_from_slice(&sub.to_be_bytes());
 		Self(sub, sp_core::H160(eth))
-	}
-	fn as_sub(&self) -> &u64 {
-		&self.0
 	}
 	fn from_eth(eth: sp_core::H160) -> Self {
 		let mut sub_raw = [0; 8];
@@ -138,11 +145,17 @@
 		let sub = u64::from_be_bytes(sub_raw);
 		Self(sub, eth)
 	}
-	fn as_eth(&self) -> &sp_core::H160 {
-		&self.1
+	fn conv_eq(&self, other: &Self) -> bool {
+		self.as_sub() == other.as_sub()
 	}
 }
 
+impl Default for TestCrossAccountId {
+	fn default() -> Self {
+		Self::from_sub(0)
+	}
+}
+
 pub struct TestEtheremTransactionSender;
 impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {
 	fn submit_logs_transaction(
@@ -157,15 +170,29 @@
 	type EthereumTransactionSender = TestEtheremTransactionSender;
 }
 
-impl pallet_template::Config for Test {
+impl pallet_common::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 EvmAddressMapping = TestEvmAddressMapping;
 	type CrossAccountId = TestCrossAccountId;
+
+	type Currency = Balances;
+	type CollectionCreationPrice = CollectionCreationPrice;
+	type TreasuryAccountId = TreasuryAccountId;
+}
+
+impl pallet_fungible::Config for Test {
+	type WeightInfo = ();
+}
+impl pallet_refungible::Config for Test {
+	type WeightInfo = ();
+}
+impl pallet_nonfungible::Config for Test {
+	type WeightInfo = ();
+}
+
+impl pallet_template::Config for Test {
+	type WeightInfo = ();
 }
 
 // Build genesis storage according to the mock runtime.
modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
before · pallets/unique/src/tests.rs
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode, Ownership, CreateItemData};5use up_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/unique/src/tests.rs
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode};5use up_data_structs::{6	COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,7	CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,8	TokenId,9};10use frame_support::{assert_noop, assert_ok};11use sp_std::convert::TryInto;1213fn default_nft_data() -> CreateNftData {14	CreateNftData {15		const_data: vec![1, 2, 3].try_into().unwrap(),16		variable_data: vec![3, 2, 1].try_into().unwrap(),17	}18}1920fn default_fungible_data() -> CreateFungibleData {21	CreateFungibleData { value: 5 }22}2324fn default_re_fungible_data() -> CreateReFungibleData {25	CreateReFungibleData {26		const_data: vec![1, 2, 3].try_into().unwrap(),27		variable_data: vec![3, 2, 1].try_into().unwrap(),28		pieces: 1023,29	}30}3132fn create_test_collection_for_owner(33	mode: &CollectionMode,34	owner: u64,35	id: CollectionId,36) -> CollectionId {37	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();38	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();39	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();4041	let origin1 = Origin::signed(owner);42	assert_ok!(TemplateModule::create_collection(43		origin1,44		col_name1,45		col_desc1,46		token_prefix1,47		mode.clone()48	));4950	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();51	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();52	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();53	assert_eq!(54		<pallet_common::CollectionById<Test>>::get(id)55			.unwrap()56			.owner,57		owner58	);59	assert_eq!(60		<pallet_common::CollectionById<Test>>::get(id).unwrap().name,61		saved_col_name62	);63	assert_eq!(64		<pallet_common::CollectionById<Test>>::get(id).unwrap().mode,65		*mode66	);67	assert_eq!(68		<pallet_common::CollectionById<Test>>::get(id)69			.unwrap()70			.description,71		saved_description72	);73	assert_eq!(74		<pallet_common::CollectionById<Test>>::get(id)75			.unwrap()76			.token_prefix,77		saved_prefix78	);79	id80}8182fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {83	create_test_collection_for_owner(&mode, 1, id)84}8586fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {87	let origin1 = Origin::signed(1);88	assert_ok!(TemplateModule::create_item(89		origin1,90		collection_id,91		account(1),92		data.clone()93	));94}9596fn account(sub: u64) -> TestCrossAccountId {97	TestCrossAccountId::from_sub(sub)98}99100// Use cases tests region101// #region102103#[test]104fn set_version_schema() {105	new_test_ext().execute_with(|| {106		let origin1 = Origin::signed(1);107		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));108109		assert_ok!(TemplateModule::set_schema_version(110			origin1,111			collection_id,112			SchemaVersion::Unique113		));114		assert_eq!(115			<pallet_common::CollectionById<Test>>::get(collection_id)116				.unwrap()117				.schema_version,118			SchemaVersion::Unique119		);120	});121}122123#[test]124fn create_fungible_collection_fails_with_large_decimal_numbers() {125	new_test_ext().execute_with(|| {126		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();127		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();128		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();129130		let origin1 = Origin::signed(1);131		assert_noop!(132			TemplateModule::create_collection(133				origin1,134				col_name1,135				col_desc1,136				token_prefix1,137				CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)138			),139			Error::<Test>::CollectionDecimalPointLimitExceeded140		);141	});142}143144#[test]145fn create_nft_item() {146	new_test_ext().execute_with(|| {147		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));148149		let data = default_nft_data();150		create_test_item(collection_id, &data.clone().into());151152		let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();153		assert_eq!(item.const_data, data.const_data.into_inner());154		assert_eq!(item.variable_data, data.variable_data.into_inner());155	});156}157158// Use cases tests region159// #region160#[test]161fn create_nft_multiple_items() {162	new_test_ext().execute_with(|| {163		create_test_collection(&CollectionMode::NFT, CollectionId(1));164165		let origin1 = Origin::signed(1);166167		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];168169		assert_ok!(TemplateModule::create_multiple_items(170			origin1,171			CollectionId(1),172			account(1),173			items_data174				.clone()175				.into_iter()176				.map(|d| { d.into() })177				.collect()178		));179		for (index, data) in items_data.into_iter().enumerate() {180			let item = <pallet_nonfungible::TokenData<Test>>::get((181				CollectionId(1),182				TokenId((index + 1) as u32),183			))184			.unwrap();185			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());186			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());187		}188	});189}190191#[test]192fn create_refungible_item() {193	new_test_ext().execute_with(|| {194		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));195196		let data = default_re_fungible_data();197		create_test_item(collection_id, &data.clone().into());198		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));199		let balance =200			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));201		assert_eq!(item.const_data, data.const_data.into_inner());202		assert_eq!(item.variable_data, data.variable_data.into_inner());203		assert_eq!(balance, 1023);204	});205}206207#[test]208fn create_multiple_refungible_items() {209	new_test_ext().execute_with(|| {210		create_test_collection(&CollectionMode::ReFungible, CollectionId(1));211212		let origin1 = Origin::signed(1);213214		let items_data = vec![215			default_re_fungible_data(),216			default_re_fungible_data(),217			default_re_fungible_data(),218		];219220		assert_ok!(TemplateModule::create_multiple_items(221			origin1,222			CollectionId(1),223			account(1),224			items_data225				.clone()226				.into_iter()227				.map(|d| { d.into() })228				.collect()229		));230		for (index, data) in items_data.into_iter().enumerate() {231			let item = <pallet_refungible::TokenData<Test>>::get((232				CollectionId(1),233				TokenId((index + 1) as u32),234			));235			let balance =236				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));237			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());238			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());239			assert_eq!(balance, 1023);240		}241	});242}243244#[test]245fn create_fungible_item() {246	new_test_ext().execute_with(|| {247		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));248249		let data = default_fungible_data();250		create_test_item(collection_id, &data.into());251252		assert_eq!(253			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),254			5255		);256	});257}258259//#[test]260// fn create_multiple_fungible_items() {261//     new_test_ext().execute_with(|| {262//         default_limits();263264//         create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));265266//         let origin1 = Origin::signed(1);267268//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];269270//         assert_ok!(TemplateModule::create_multiple_items(271//             origin1.clone(),272//             1,273//             1,274//             items_data.clone().into_iter().map(|d| { d.into() }).collect()275//         ));276277//         for (index, _) in items_data.iter().enumerate() {278//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);279//         }280//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);281//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);282//     });283// }284285#[test]286fn transfer_fungible_item() {287	new_test_ext().execute_with(|| {288		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));289290		let origin1 = Origin::signed(1);291		let origin2 = Origin::signed(2);292293		let data = default_fungible_data();294		create_test_item(collection_id, &data.into());295296		assert_eq!(297			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),298			5299		);300301		// change owner scenario302		assert_ok!(TemplateModule::transfer(303			origin1,304			account(2),305			CollectionId(1),306			TokenId(0),307			5308		));309		assert_eq!(310			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),311			0312		);313314		// split item scenario315		assert_ok!(TemplateModule::transfer(316			origin2.clone(),317			account(3),318			CollectionId(1),319			TokenId(0),320			3321		));322323		// split item and new owner has account scenario324		assert_ok!(TemplateModule::transfer(325			origin2,326			account(3),327			CollectionId(1),328			TokenId(0),329			1330		));331		assert_eq!(332			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),333			1334		);335		assert_eq!(336			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),337			4338		);339	});340}341342#[test]343fn transfer_refungible_item() {344	new_test_ext().execute_with(|| {345		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));346347		// Create RFT 1 in 1023 pieces for account 1348		let data = default_re_fungible_data();349		create_test_item(collection_id, &data.clone().into());350		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));351		assert_eq!(item.const_data, data.const_data.into_inner());352		assert_eq!(item.variable_data, data.variable_data.into_inner());353		assert_eq!(354			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),355			1356		);357		assert_eq!(358			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),359			1023360		);361		assert_eq!(362			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),363			true364		);365366		// Account 1 transfers all 1023 pieces of RFT 1 to account 2367		let origin1 = Origin::signed(1);368		let origin2 = Origin::signed(2);369		assert_ok!(TemplateModule::transfer(370			origin1,371			account(2),372			CollectionId(1),373			TokenId(1),374			1023375		));376		assert_eq!(377			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),378			1023379		);380		assert_eq!(381			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),382			0383		);384		assert_eq!(385			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),386			1387		);388		assert_eq!(389			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),390			false391		);392		assert_eq!(393			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),394			true395		);396397		// Account 2 transfers 500 pieces of RFT 1 to account 3398		assert_ok!(TemplateModule::transfer(399			origin2.clone(),400			account(3),401			CollectionId(1),402			TokenId(1),403			500404		));405		assert_eq!(406			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),407			523408		);409		assert_eq!(410			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),411			500412		);413		assert_eq!(414			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),415			1416		);417		assert_eq!(418			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),419			1420		);421		assert_eq!(422			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),423			true424		);425		assert_eq!(426			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),427			true428		);429430		// Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance431		assert_ok!(TemplateModule::transfer(432			origin2,433			account(3),434			CollectionId(1),435			TokenId(1),436			200437		));438		assert_eq!(439			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),440			323441		);442		assert_eq!(443			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),444			700445		);446		assert_eq!(447			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),448			1449		);450		assert_eq!(451			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),452			1453		);454		assert_eq!(455			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),456			true457		);458		assert_eq!(459			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),460			true461		);462	});463}464465#[test]466fn transfer_nft_item() {467	new_test_ext().execute_with(|| {468		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));469470		let data = default_nft_data();471		create_test_item(collection_id, &data.into());472		assert_eq!(473			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),474			1475		);476		assert_eq!(477			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),478			true479		);480481		let origin1 = Origin::signed(1);482		// default scenario483		assert_ok!(TemplateModule::transfer(484			origin1,485			account(2),486			CollectionId(1),487			TokenId(1),488			1489		));490		assert_eq!(491			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),492			0493		);494		assert_eq!(495			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),496			1497		);498		assert_eq!(499			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),500			false501		);502		assert_eq!(503			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),504			true505		);506	});507}508509#[test]510fn transfer_nft_item_wrong_value() {511	new_test_ext().execute_with(|| {512		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));513514		let data = default_nft_data();515		create_test_item(collection_id, &data.into());516		assert_eq!(517			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),518			1519		);520		assert_eq!(521			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),522			true523		);524525		let origin1 = Origin::signed(1);526527		assert_noop!(528			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)529				.map_err(|e| e.error),530			<pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount531		);532	});533}534535#[test]536fn transfer_nft_item_zero_value() {537	new_test_ext().execute_with(|| {538		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));539540		let data = default_nft_data();541		create_test_item(collection_id, &data.into());542		assert_eq!(543			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),544			1545		);546		assert_eq!(547			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),548			true549		);550551		let origin1 = Origin::signed(1);552553		// Transferring 0 amount works on NFT...554		assert_ok!(TemplateModule::transfer(555			origin1,556			account(2),557			CollectionId(1),558			TokenId(1),559			0560		));561		// ... and results in no transfer562		assert_eq!(563			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),564			1565		);566		assert_eq!(567			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),568			true569		);570	});571}572573#[test]574fn nft_approve_and_transfer_from() {575	new_test_ext().execute_with(|| {576		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));577578		let data = default_nft_data();579		create_test_item(collection_id, &data.into());580581		let origin1 = Origin::signed(1);582		let origin2 = Origin::signed(2);583584		assert_eq!(585			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),586			1587		);588		assert_eq!(589			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),590			true591		);592593		// neg transfer_from594		assert_noop!(595			TemplateModule::transfer_from(596				origin2.clone(),597				account(1),598				account(2),599				CollectionId(1),600				TokenId(1),601				1602			)603			.map_err(|e| e.error),604			CommonError::<Test>::TokenValueNotEnough605		);606607		// do approve608		assert_ok!(TemplateModule::approve(609			origin1,610			account(2),611			CollectionId(1),612			TokenId(1),613			1614		));615		assert_eq!(616			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),617			account(2)618		);619620		assert_ok!(TemplateModule::transfer_from(621			origin2,622			account(1),623			account(3),624			CollectionId(1),625			TokenId(1),626			1627		));628		assert!(629			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()630		);631	});632}633634#[test]635fn nft_approve_and_transfer_from_allow_list() {636	new_test_ext().execute_with(|| {637		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));638639		let origin1 = Origin::signed(1);640		let origin2 = Origin::signed(2);641642		// Create NFT 1 for account 1643		let data = default_nft_data();644		create_test_item(collection_id, &data.clone().into());645		assert_eq!(646			&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))647				.unwrap()648				.const_data,649			&data.const_data.into_inner()650		);651		assert_eq!(652			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),653			1654		);655		assert_eq!(656			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),657			true658		);659660		// Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list661		assert_ok!(TemplateModule::set_mint_permission(662			origin1.clone(),663			CollectionId(1),664			true665		));666		assert_ok!(TemplateModule::set_public_access_mode(667			origin1.clone(),668			CollectionId(1),669			AccessMode::AllowList670		));671		assert_ok!(TemplateModule::add_to_allow_list(672			origin1.clone(),673			CollectionId(1),674			account(1)675		));676		assert_ok!(TemplateModule::add_to_allow_list(677			origin1.clone(),678			CollectionId(1),679			account(2)680		));681		assert_ok!(TemplateModule::add_to_allow_list(682			origin1.clone(),683			CollectionId(1),684			account(3)685		));686687		// Account 1 approves account 2 for NFT 1688		assert_ok!(TemplateModule::approve(689			origin1.clone(),690			account(2),691			CollectionId(1),692			TokenId(1),693			1694		));695		assert_eq!(696			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),697			account(2)698		);699700		// Account 2 transfers NFT 1 from account 1 to account 3701		assert_ok!(TemplateModule::transfer_from(702			origin2,703			account(1),704			account(3),705			CollectionId(1),706			TokenId(1),707			1708		));709		assert!(710			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()711		);712	});713}714715#[test]716fn refungible_approve_and_transfer_from() {717	new_test_ext().execute_with(|| {718		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));719720		let origin1 = Origin::signed(1);721		let origin2 = Origin::signed(2);722723		// Create RFT 1 in 1023 pieces for account 1724		let data = default_re_fungible_data();725		create_test_item(collection_id, &data.into());726727		assert_eq!(728			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),729			1730		);731		assert_eq!(732			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),733			1023734		);735		assert_eq!(736			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),737			true738		);739740		// Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list741		assert_ok!(TemplateModule::set_mint_permission(742			origin1.clone(),743			CollectionId(1),744			true745		));746		assert_ok!(TemplateModule::set_public_access_mode(747			origin1.clone(),748			CollectionId(1),749			AccessMode::AllowList750		));751		assert_ok!(TemplateModule::add_to_allow_list(752			origin1.clone(),753			CollectionId(1),754			account(1)755		));756		assert_ok!(TemplateModule::add_to_allow_list(757			origin1.clone(),758			CollectionId(1),759			account(2)760		));761		assert_ok!(TemplateModule::add_to_allow_list(762			origin1.clone(),763			CollectionId(1),764			account(3)765		));766767		// Account 1 approves account 2 for 1023 pieces of RFT 1768		assert_ok!(TemplateModule::approve(769			origin1,770			account(2),771			CollectionId(1),772			TokenId(1),773			1023774		));775		assert_eq!(776			<pallet_refungible::Allowance<Test>>::get((777				CollectionId(1),778				TokenId(1),779				account(1),780				account(2)781			)),782			1023783		);784785		// Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3786		assert_ok!(TemplateModule::transfer_from(787			origin2,788			account(1),789			account(3),790			CollectionId(1),791			TokenId(1),792			100793		));794		assert_eq!(795			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),796			1797		);798		assert_eq!(799			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),800			1801		);802		assert_eq!(803			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),804			923805		);806		assert_eq!(807			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),808			100809		);810		assert_eq!(811			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),812			true813		);814		assert_eq!(815			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),816			true817		);818		assert_eq!(819			<pallet_refungible::Allowance<Test>>::get((820				CollectionId(1),821				TokenId(1),822				account(1),823				account(2)824			)),825			923826		);827	});828}829830#[test]831fn fungible_approve_and_transfer_from() {832	new_test_ext().execute_with(|| {833		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));834835		let data = default_fungible_data();836		create_test_item(collection_id, &data.into());837838		let origin1 = Origin::signed(1);839		let origin2 = Origin::signed(2);840841		assert_ok!(TemplateModule::set_mint_permission(842			origin1.clone(),843			CollectionId(1),844			true845		));846		assert_ok!(TemplateModule::set_public_access_mode(847			origin1.clone(),848			CollectionId(1),849			AccessMode::AllowList850		));851		assert_ok!(TemplateModule::add_to_allow_list(852			origin1.clone(),853			CollectionId(1),854			account(1)855		));856		assert_ok!(TemplateModule::add_to_allow_list(857			origin1.clone(),858			CollectionId(1),859			account(2)860		));861		assert_ok!(TemplateModule::add_to_allow_list(862			origin1.clone(),863			CollectionId(1),864			account(3)865		));866867		// do approve868		assert_ok!(TemplateModule::approve(869			origin1.clone(),870			account(2),871			CollectionId(1),872			TokenId(0),873			5874		));875		assert_eq!(876			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),877			5878		);879		assert_ok!(TemplateModule::approve(880			origin1,881			account(3),882			CollectionId(1),883			TokenId(0),884			5885		));886		assert_eq!(887			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),888			5889		);890		assert_eq!(891			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),892			5893		);894895		assert_ok!(TemplateModule::transfer_from(896			origin2.clone(),897			account(1),898			account(3),899			CollectionId(1),900			TokenId(0),901			4902		));903904		assert_eq!(905			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),906			1907		);908909		assert_noop!(910			TemplateModule::transfer_from(911				origin2,912				account(1),913				account(3),914				CollectionId(1),915				TokenId(0),916				4917			)918			.map_err(|e| e.error),919			CommonError::<Test>::TokenValueNotEnough920		);921	});922}923924#[test]925fn change_collection_owner() {926	new_test_ext().execute_with(|| {927		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));928929		let origin1 = Origin::signed(1);930		assert_ok!(TemplateModule::change_collection_owner(931			origin1,932			collection_id,933			2934		));935		assert_eq!(936			<pallet_common::CollectionById<Test>>::get(collection_id)937				.unwrap()938				.owner,939			2940		);941	});942}943944#[test]945fn destroy_collection() {946	new_test_ext().execute_with(|| {947		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));948949		let origin1 = Origin::signed(1);950		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));951	});952}953954#[test]955fn burn_nft_item() {956	new_test_ext().execute_with(|| {957		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));958959		let origin1 = Origin::signed(1);960961		let data = default_nft_data();962		create_test_item(collection_id, &data.into());963964		// check balance (collection with id = 1, user id = 1)965		assert_eq!(966			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),967			1968		);969970		// burn item971		assert_ok!(TemplateModule::burn_item(972			origin1.clone(),973			collection_id,974			TokenId(1),975			1976		));977		assert_eq!(978			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),979			0980		);981	});982}983984#[test]985fn burn_same_nft_item_twice() {986	new_test_ext().execute_with(|| {987		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));988989		let origin1 = Origin::signed(1);990991		let data = default_nft_data();992		create_test_item(collection_id, &data.into());993994		// check balance (collection with id = 1, user id = 1)995		assert_eq!(996			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),997			1998		);9991000		// burn item1001		assert_ok!(TemplateModule::burn_item(1002			origin1.clone(),1003			collection_id,1004			TokenId(1),1005			11006		));10071008		// burn item again1009		assert_noop!(1010			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1011			CommonError::<Test>::TokenNotFound1012		);10131014		assert_eq!(1015			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1016			01017		);1018	});1019}10201021#[test]1022fn burn_fungible_item() {1023	new_test_ext().execute_with(|| {1024		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10251026		let origin1 = Origin::signed(1);1027		assert_ok!(TemplateModule::add_collection_admin(1028			origin1.clone(),1029			collection_id,1030			account(2)1031		));10321033		let data = default_fungible_data();1034		create_test_item(collection_id, &data.into());10351036		// check balance (collection with id = 1, user id = 1)1037		assert_eq!(1038			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1039			51040		);10411042		// burn item1043		assert_ok!(TemplateModule::burn_item(1044			origin1.clone(),1045			CollectionId(1),1046			TokenId(0),1047			51048		));1049		assert_noop!(1050			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1051			CommonError::<Test>::TokenValueTooLow1052		);10531054		assert_eq!(1055			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1056			01057		);1058	});1059}10601061#[test]1062fn burn_fungible_item_with_token_id() {1063	new_test_ext().execute_with(|| {1064		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10651066		let origin1 = Origin::signed(1);1067		assert_ok!(TemplateModule::add_collection_admin(1068			origin1.clone(),1069			collection_id,1070			account(2)1071		));10721073		let data = default_fungible_data();1074		create_test_item(collection_id, &data.into());10751076		// check balance (collection with id = 1, user id = 1)1077		assert_eq!(1078			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1079			51080		);10811082		// Try to burn item using Token ID1083		assert_noop!(1084			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1085			<pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1086		);1087	});1088}1089#[test]1090fn burn_refungible_item() {1091	new_test_ext().execute_with(|| {1092		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1093		let origin1 = Origin::signed(1);10941095		assert_ok!(TemplateModule::set_mint_permission(1096			origin1.clone(),1097			collection_id,1098			true1099		));1100		assert_ok!(TemplateModule::set_public_access_mode(1101			origin1.clone(),1102			collection_id,1103			AccessMode::AllowList1104		));1105		assert_ok!(TemplateModule::add_to_allow_list(1106			origin1.clone(),1107			collection_id,1108			account(1)1109		));11101111		assert_ok!(TemplateModule::add_collection_admin(1112			origin1.clone(),1113			collection_id,1114			account(2)1115		));11161117		let data = default_re_fungible_data();1118		create_test_item(collection_id, &data.into());11191120		// check balance (collection with id = 1, user id = 2)1121		assert_eq!(1122			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1123			11124		);1125		assert_eq!(1126			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1127			10231128		);11291130		// burn item1131		assert_ok!(TemplateModule::burn_item(1132			origin1.clone(),1133			collection_id,1134			TokenId(1),1135			10231136		));1137		assert_noop!(1138			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1139				.map_err(|e| e.error),1140			CommonError::<Test>::TokenValueTooLow1141		);11421143		assert_eq!(1144			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1145			01146		);1147	});1148}11491150#[test]1151fn add_collection_admin() {1152	new_test_ext().execute_with(|| {1153		let collection1_id =1154			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1155		let origin1 = Origin::signed(1);11561157		// Add collection admins1158		assert_ok!(TemplateModule::add_collection_admin(1159			origin1.clone(),1160			collection1_id,1161			account(2)1162		));1163		assert_ok!(TemplateModule::add_collection_admin(1164			origin1,1165			collection1_id,1166			account(3)1167		));11681169		// Owner is not an admin by default1170		assert_eq!(1171			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1172			false1173		);1174		assert!(<pallet_common::IsAdmin<Test>>::get((1175			CollectionId(1),1176			account(2)1177		)));1178		assert!(<pallet_common::IsAdmin<Test>>::get((1179			CollectionId(1),1180			account(3)1181		)));1182	});1183}11841185#[test]1186fn remove_collection_admin() {1187	new_test_ext().execute_with(|| {1188		let collection1_id =1189			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1190		let origin1 = Origin::signed(1);1191		let origin2 = Origin::signed(2);11921193		// Add collection admins 2 and 31194		assert_ok!(TemplateModule::add_collection_admin(1195			origin1.clone(),1196			collection1_id,1197			account(2)1198		));1199		assert_ok!(TemplateModule::add_collection_admin(1200			origin1,1201			collection1_id,1202			account(3)1203		));12041205		assert!(<pallet_common::IsAdmin<Test>>::get((1206			CollectionId(1),1207			account(2)1208		)));1209		assert!(<pallet_common::IsAdmin<Test>>::get((1210			CollectionId(1),1211			account(3)1212		)));12131214		// remove admin 31215		assert_ok!(TemplateModule::remove_collection_admin(1216			origin2,1217			CollectionId(1),1218			account(3)1219		));12201221		// 2 is still admin, 3 is not an admin anymore1222		assert!(<pallet_common::IsAdmin<Test>>::get((1223			CollectionId(1),1224			account(2)1225		)));1226		assert_eq!(1227			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1228			false1229		);1230	});1231}12321233#[test]1234fn balance_of() {1235	new_test_ext().execute_with(|| {1236		let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1237		let fungible_collection_id =1238			create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1239		let re_fungible_collection_id =1240			create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12411242		// check balance before1243		assert_eq!(1244			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1245			01246		);1247		assert_eq!(1248			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1249			01250		);1251		assert_eq!(1252			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1253			01254		);12551256		let nft_data = default_nft_data();1257		create_test_item(nft_collection_id, &nft_data.into());12581259		let fungible_data = default_fungible_data();1260		create_test_item(fungible_collection_id, &fungible_data.into());12611262		let re_fungible_data = default_re_fungible_data();1263		create_test_item(re_fungible_collection_id, &re_fungible_data.into());12641265		// check balance (collection with id = 1, user id = 1)1266		assert_eq!(1267			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1268			11269		);1270		assert_eq!(1271			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1272			51273		);1274		assert_eq!(1275			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1276			11277		);12781279		assert_eq!(1280			<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1281			true1282		);1283		assert_eq!(1284			<pallet_refungible::Owned<Test>>::get((1285				re_fungible_collection_id,1286				account(1),1287				TokenId(1)1288			)),1289			true1290		);1291	});1292}12931294#[test]1295fn approve() {1296	new_test_ext().execute_with(|| {1297		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));12981299		let data = default_nft_data();1300		create_test_item(collection_id, &data.into());13011302		let origin1 = Origin::signed(1);13031304		// approve1305		assert_ok!(TemplateModule::approve(1306			origin1,1307			account(2),1308			CollectionId(1),1309			TokenId(1),1310			11311		));1312		assert_eq!(1313			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1314			account(2)1315		);1316	});1317}13181319#[test]1320fn transfer_from() {1321	new_test_ext().execute_with(|| {1322		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1323		let origin1 = Origin::signed(1);1324		let origin2 = Origin::signed(2);13251326		let data = default_nft_data();1327		create_test_item(collection_id, &data.into());13281329		// approve1330		assert_ok!(TemplateModule::approve(1331			origin1.clone(),1332			account(2),1333			CollectionId(1),1334			TokenId(1),1335			11336		));1337		assert_eq!(1338			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1339			account(2)1340		);13411342		assert_ok!(TemplateModule::set_mint_permission(1343			origin1.clone(),1344			CollectionId(1),1345			true1346		));1347		assert_ok!(TemplateModule::set_public_access_mode(1348			origin1.clone(),1349			CollectionId(1),1350			AccessMode::AllowList1351		));1352		assert_ok!(TemplateModule::add_to_allow_list(1353			origin1.clone(),1354			CollectionId(1),1355			account(1)1356		));1357		assert_ok!(TemplateModule::add_to_allow_list(1358			origin1.clone(),1359			CollectionId(1),1360			account(2)1361		));1362		assert_ok!(TemplateModule::add_to_allow_list(1363			origin1,1364			CollectionId(1),1365			account(3)1366		));13671368		assert_ok!(TemplateModule::transfer_from(1369			origin2,1370			account(1),1371			account(2),1372			CollectionId(1),1373			TokenId(1),1374			11375		));13761377		// after transfer1378		assert_eq!(1379			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1380			01381		);1382		assert_eq!(1383			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1384			11385		);1386	});1387}13881389// #endregion13901391// Coverage tests region1392// #region13931394#[test]1395fn owner_can_add_address_to_allow_list() {1396	new_test_ext().execute_with(|| {1397		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13981399		let origin1 = Origin::signed(1);1400		assert_ok!(TemplateModule::add_to_allow_list(1401			origin1,1402			collection_id,1403			account(2)1404		));1405		assert!(<pallet_common::Allowlist<Test>>::get((1406			collection_id,1407			account(2)1408		)));1409	});1410}14111412#[test]1413fn admin_can_add_address_to_allow_list() {1414	new_test_ext().execute_with(|| {1415		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1416		let origin1 = Origin::signed(1);1417		let origin2 = Origin::signed(2);14181419		assert_ok!(TemplateModule::add_collection_admin(1420			origin1,1421			collection_id,1422			account(2)1423		));1424		assert_ok!(TemplateModule::add_to_allow_list(1425			origin2,1426			collection_id,1427			account(3)1428		));1429		assert!(<pallet_common::Allowlist<Test>>::get((1430			collection_id,1431			account(3)1432		)));1433	});1434}14351436#[test]1437fn nonprivileged_user_cannot_add_address_to_allow_list() {1438	new_test_ext().execute_with(|| {1439		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14401441		let origin2 = Origin::signed(2);1442		assert_noop!(1443			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1444			CommonError::<Test>::NoPermission1445		);1446	});1447}14481449#[test]1450fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1451	new_test_ext().execute_with(|| {1452		let origin1 = Origin::signed(1);14531454		assert_noop!(1455			TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1456			CommonError::<Test>::CollectionNotFound1457		);1458	});1459}14601461#[test]1462fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1463	new_test_ext().execute_with(|| {1464		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14651466		let origin1 = Origin::signed(1);1467		assert_ok!(TemplateModule::destroy_collection(1468			origin1.clone(),1469			collection_id1470		));1471		assert_noop!(1472			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1473			CommonError::<Test>::CollectionNotFound1474		);1475	});1476}14771478// If address is already added to allow list, nothing happens1479#[test]1480fn address_is_already_added_to_allow_list() {1481	new_test_ext().execute_with(|| {1482		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1483		let origin1 = Origin::signed(1);14841485		assert_ok!(TemplateModule::add_to_allow_list(1486			origin1.clone(),1487			collection_id,1488			account(2)1489		));1490		assert_ok!(TemplateModule::add_to_allow_list(1491			origin1,1492			collection_id,1493			account(2)1494		));1495		assert!(<pallet_common::Allowlist<Test>>::get((1496			collection_id,1497			account(2)1498		)));1499	});1500}15011502#[test]1503fn owner_can_remove_address_from_allow_list() {1504	new_test_ext().execute_with(|| {1505		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15061507		let origin1 = Origin::signed(1);1508		assert_ok!(TemplateModule::add_to_allow_list(1509			origin1.clone(),1510			collection_id,1511			account(2)1512		));1513		assert_ok!(TemplateModule::remove_from_allow_list(1514			origin1,1515			collection_id,1516			account(2)1517		));1518		assert_eq!(1519			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1520			false1521		);1522	});1523}15241525#[test]1526fn admin_can_remove_address_from_allow_list() {1527	new_test_ext().execute_with(|| {1528		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1529		let origin1 = Origin::signed(1);1530		let origin2 = Origin::signed(2);15311532		// Owner adds admin1533		assert_ok!(TemplateModule::add_collection_admin(1534			origin1.clone(),1535			collection_id,1536			account(2)1537		));15381539		// Owner adds address 3 to allow list1540		assert_ok!(TemplateModule::add_to_allow_list(1541			origin1,1542			collection_id,1543			account(3)1544		));15451546		// Admin removes address 3 from allow list1547		assert_ok!(TemplateModule::remove_from_allow_list(1548			origin2,1549			collection_id,1550			account(3)1551		));1552		assert_eq!(1553			<pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1554			false1555		);1556	});1557}15581559#[test]1560fn nonprivileged_user_cannot_remove_address_from_allow_list() {1561	new_test_ext().execute_with(|| {1562		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1563		let origin1 = Origin::signed(1);1564		let origin2 = Origin::signed(2);15651566		assert_ok!(TemplateModule::add_to_allow_list(1567			origin1,1568			collection_id,1569			account(2)1570		));1571		assert_noop!(1572			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1573			CommonError::<Test>::NoPermission1574		);1575		assert!(<pallet_common::Allowlist<Test>>::get((1576			collection_id,1577			account(2)1578		)));1579	});1580}15811582#[test]1583fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1584	new_test_ext().execute_with(|| {1585		let origin1 = Origin::signed(1);15861587		assert_noop!(1588			TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1589			CommonError::<Test>::CollectionNotFound1590		);1591	});1592}15931594#[test]1595fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1596	new_test_ext().execute_with(|| {1597		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1598		let origin1 = Origin::signed(1);1599		let origin2 = Origin::signed(2);16001601		// Add account 2 to allow list1602		assert_ok!(TemplateModule::add_to_allow_list(1603			origin1.clone(),1604			collection_id,1605			account(2)1606		));16071608		// Account 2 is in collection allow-list1609		assert!(<pallet_common::Allowlist<Test>>::get((1610			collection_id,1611			account(2)1612		)));16131614		// Destroy collection1615		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16161617		// Attempt to remove account 2 from collection allow-list => error1618		assert_noop!(1619			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1620			CommonError::<Test>::CollectionNotFound1621		);16221623		// Account 2 is not found in collection allow-list anyway1624		assert_eq!(1625			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1626			false1627		);1628	});1629}16301631// If address is already removed from allow list, nothing happens1632#[test]1633fn address_is_already_removed_from_allow_list() {1634	new_test_ext().execute_with(|| {1635		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1636		let origin1 = Origin::signed(1);16371638		assert_ok!(TemplateModule::add_to_allow_list(1639			origin1.clone(),1640			collection_id,1641			account(2)1642		));1643		assert_ok!(TemplateModule::remove_from_allow_list(1644			origin1.clone(),1645			collection_id,1646			account(2)1647		));1648		assert_eq!(1649			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1650			false1651		);1652		assert_ok!(TemplateModule::remove_from_allow_list(1653			origin1,1654			collection_id,1655			account(2)1656		));1657		assert_eq!(1658			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1659			false1660		);1661	});1662}16631664// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1665#[test]1666fn allow_list_test_1() {1667	new_test_ext().execute_with(|| {1668		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));16691670		let origin1 = Origin::signed(1);16711672		let data = default_nft_data();1673		create_test_item(collection_id, &data.into());16741675		assert_ok!(TemplateModule::set_public_access_mode(1676			origin1.clone(),1677			collection_id,1678			AccessMode::AllowList1679		));1680		assert_ok!(TemplateModule::add_to_allow_list(1681			origin1.clone(),1682			collection_id,1683			account(2)1684		));16851686		assert_noop!(1687			TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1688				.map_err(|e| e.error),1689			CommonError::<Test>::AddressNotInAllowlist1690		);1691	});1692}16931694#[test]1695fn allow_list_test_2() {1696	new_test_ext().execute_with(|| {1697		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1698		let origin1 = Origin::signed(1);16991700		let data = default_nft_data();1701		create_test_item(collection_id, &data.into());17021703		assert_ok!(TemplateModule::set_public_access_mode(1704			origin1.clone(),1705			collection_id,1706			AccessMode::AllowList1707		));1708		assert_ok!(TemplateModule::add_to_allow_list(1709			origin1.clone(),1710			collection_id,1711			account(1)1712		));1713		assert_ok!(TemplateModule::add_to_allow_list(1714			origin1.clone(),1715			collection_id,1716			account(2)1717		));17181719		// do approve1720		assert_ok!(TemplateModule::approve(1721			origin1.clone(),1722			account(1),1723			collection_id,1724			TokenId(1),1725			11726		));1727		assert_eq!(1728			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1729			account(1)1730		);17311732		assert_ok!(TemplateModule::remove_from_allow_list(1733			origin1.clone(),1734			collection_id,1735			account(1)1736		));17371738		assert_noop!(1739			TemplateModule::transfer_from(1740				origin1,1741				account(1),1742				account(3),1743				CollectionId(1),1744				TokenId(1),1745				11746			)1747			.map_err(|e| e.error),1748			CommonError::<Test>::AddressNotInAllowlist1749		);1750	});1751}17521753// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1754#[test]1755fn allow_list_test_3() {1756	new_test_ext().execute_with(|| {1757		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17581759		let origin1 = Origin::signed(1);17601761		let data = default_nft_data();1762		create_test_item(collection_id, &data.into());17631764		assert_ok!(TemplateModule::set_public_access_mode(1765			origin1.clone(),1766			collection_id,1767			AccessMode::AllowList1768		));1769		assert_ok!(TemplateModule::add_to_allow_list(1770			origin1.clone(),1771			collection_id,1772			account(1)1773		));17741775		assert_noop!(1776			TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1777				.map_err(|e| e.error),1778			CommonError::<Test>::AddressNotInAllowlist1779		);1780	});1781}17821783#[test]1784fn allow_list_test_4() {1785	new_test_ext().execute_with(|| {1786		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17871788		let origin1 = Origin::signed(1);17891790		let data = default_nft_data();1791		create_test_item(collection_id, &data.into());17921793		assert_ok!(TemplateModule::set_public_access_mode(1794			origin1.clone(),1795			collection_id,1796			AccessMode::AllowList1797		));1798		assert_ok!(TemplateModule::add_to_allow_list(1799			origin1.clone(),1800			collection_id,1801			account(1)1802		));1803		assert_ok!(TemplateModule::add_to_allow_list(1804			origin1.clone(),1805			collection_id,1806			account(2)1807		));18081809		// do approve1810		assert_ok!(TemplateModule::approve(1811			origin1.clone(),1812			account(1),1813			collection_id,1814			TokenId(1),1815			11816		));1817		assert_eq!(1818			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1819			account(1)1820		);18211822		assert_ok!(TemplateModule::remove_from_allow_list(1823			origin1.clone(),1824			collection_id,1825			account(2)1826		));18271828		assert_noop!(1829			TemplateModule::transfer_from(1830				origin1,1831				account(1),1832				account(3),1833				collection_id,1834				TokenId(1),1835				11836			)1837			.map_err(|e| e.error),1838			CommonError::<Test>::AddressNotInAllowlist1839		);1840	});1841}18421843// If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)1844#[test]1845fn allow_list_test_5() {1846	new_test_ext().execute_with(|| {1847		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18481849		let origin1 = Origin::signed(1);18501851		let data = default_nft_data();1852		create_test_item(collection_id, &data.into());18531854		assert_ok!(TemplateModule::set_public_access_mode(1855			origin1.clone(),1856			collection_id,1857			AccessMode::AllowList1858		));1859		assert_noop!(1860			TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1861				.map_err(|e| e.error),1862			CommonError::<Test>::AddressNotInAllowlist1863		);1864	});1865}18661867// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1868#[test]1869fn allow_list_test_6() {1870	new_test_ext().execute_with(|| {1871		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18721873		let origin1 = Origin::signed(1);18741875		let data = default_nft_data();1876		create_test_item(collection_id, &data.into());18771878		assert_ok!(TemplateModule::set_public_access_mode(1879			origin1.clone(),1880			collection_id,1881			AccessMode::AllowList1882		));18831884		// do approve1885		assert_noop!(1886			TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1887				.map_err(|e| e.error),1888			CommonError::<Test>::AddressNotInAllowlist1889		);1890	});1891}18921893// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1894//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1895#[test]1896fn allow_list_test_7() {1897	new_test_ext().execute_with(|| {1898		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18991900		let data = default_nft_data();1901		create_test_item(collection_id, &data.into());19021903		let origin1 = Origin::signed(1);19041905		assert_ok!(TemplateModule::set_public_access_mode(1906			origin1.clone(),1907			collection_id,1908			AccessMode::AllowList1909		));1910		assert_ok!(TemplateModule::add_to_allow_list(1911			origin1.clone(),1912			collection_id,1913			account(1)1914		));1915		assert_ok!(TemplateModule::add_to_allow_list(1916			origin1.clone(),1917			collection_id,1918			account(2)1919		));19201921		assert_ok!(TemplateModule::transfer(1922			origin1,1923			account(2),1924			CollectionId(1),1925			TokenId(1),1926			11927		));1928	});1929}19301931#[test]1932fn allow_list_test_8() {1933	new_test_ext().execute_with(|| {1934		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19351936		// Create NFT for account 11937		let data = default_nft_data();1938		create_test_item(collection_id, &data.into());19391940		let origin1 = Origin::signed(1);19411942		// Toggle Allow List mode and add accounts 1 and 21943		assert_ok!(TemplateModule::set_public_access_mode(1944			origin1.clone(),1945			collection_id,1946			AccessMode::AllowList1947		));1948		assert_ok!(TemplateModule::add_to_allow_list(1949			origin1.clone(),1950			collection_id,1951			account(1)1952		));1953		assert_ok!(TemplateModule::add_to_allow_list(1954			origin1.clone(),1955			collection_id,1956			account(2)1957		));19581959		// Sself-approve account 1 for NFT 11960		assert_ok!(TemplateModule::approve(1961			origin1.clone(),1962			account(1),1963			CollectionId(1),1964			TokenId(1),1965			11966		));1967		assert_eq!(1968			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1969			account(1)1970		);19711972		// Transfer from 1 to 21973		assert_ok!(TemplateModule::transfer_from(1974			origin1,1975			account(1),1976			account(2),1977			CollectionId(1),1978			TokenId(1),1979			11980		));1981	});1982}19831984// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.1985#[test]1986fn allow_list_test_9() {1987	new_test_ext().execute_with(|| {1988		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1989		let origin1 = Origin::signed(1);19901991		assert_ok!(TemplateModule::set_public_access_mode(1992			origin1.clone(),1993			collection_id,1994			AccessMode::AllowList1995		));1996		assert_ok!(TemplateModule::set_mint_permission(1997			origin1,1998			collection_id,1999			false2000		));20012002		let data = default_nft_data();2003		create_test_item(collection_id, &data.into());2004	});2005}20062007// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2008#[test]2009fn allow_list_test_10() {2010	new_test_ext().execute_with(|| {2011		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20122013		let origin1 = Origin::signed(1);2014		let origin2 = Origin::signed(2);20152016		assert_ok!(TemplateModule::set_public_access_mode(2017			origin1.clone(),2018			collection_id,2019			AccessMode::AllowList2020		));2021		assert_ok!(TemplateModule::set_mint_permission(2022			origin1.clone(),2023			collection_id,2024			false2025		));20262027		assert_ok!(TemplateModule::add_collection_admin(2028			origin1,2029			collection_id,2030			account(2)2031		));20322033		assert_ok!(TemplateModule::create_item(2034			origin2,2035			collection_id,2036			account(2),2037			default_nft_data().into()2038		));2039	});2040}20412042// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.2043#[test]2044fn allow_list_test_11() {2045	new_test_ext().execute_with(|| {2046		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20472048		let origin1 = Origin::signed(1);2049		let origin2 = Origin::signed(2);20502051		assert_ok!(TemplateModule::set_public_access_mode(2052			origin1.clone(),2053			collection_id,2054			AccessMode::AllowList2055		));2056		assert_ok!(TemplateModule::set_mint_permission(2057			origin1.clone(),2058			collection_id,2059			false2060		));2061		assert_ok!(TemplateModule::add_to_allow_list(2062			origin1,2063			collection_id,2064			account(2)2065		));20662067		assert_noop!(2068			TemplateModule::create_item(2069				origin2,2070				CollectionId(1),2071				account(2),2072				default_nft_data().into()2073			)2074			.map_err(|e| e.error),2075			CommonError::<Test>::PublicMintingNotAllowed2076		);2077	});2078}20792080// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.2081#[test]2082fn allow_list_test_12() {2083	new_test_ext().execute_with(|| {2084		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20852086		let origin1 = Origin::signed(1);2087		let origin2 = Origin::signed(2);20882089		assert_ok!(TemplateModule::set_public_access_mode(2090			origin1.clone(),2091			collection_id,2092			AccessMode::AllowList2093		));2094		assert_ok!(TemplateModule::set_mint_permission(2095			origin1,2096			collection_id,2097			false2098		));20992100		assert_noop!(2101			TemplateModule::create_item(2102				origin2,2103				CollectionId(1),2104				account(2),2105				default_nft_data().into()2106			)2107			.map_err(|e| e.error),2108			CommonError::<Test>::PublicMintingNotAllowed2109		);2110	});2111}21122113// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2114#[test]2115fn allow_list_test_13() {2116	new_test_ext().execute_with(|| {2117		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21182119		let origin1 = Origin::signed(1);21202121		assert_ok!(TemplateModule::set_public_access_mode(2122			origin1.clone(),2123			collection_id,2124			AccessMode::AllowList2125		));2126		assert_ok!(TemplateModule::set_mint_permission(2127			origin1,2128			collection_id,2129			true2130		));21312132		let data = default_nft_data();2133		create_test_item(collection_id, &data.into());2134	});2135}21362137// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2138#[test]2139fn allow_list_test_14() {2140	new_test_ext().execute_with(|| {2141		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21422143		let origin1 = Origin::signed(1);2144		let origin2 = Origin::signed(2);21452146		assert_ok!(TemplateModule::set_public_access_mode(2147			origin1.clone(),2148			collection_id,2149			AccessMode::AllowList2150		));2151		assert_ok!(TemplateModule::set_mint_permission(2152			origin1.clone(),2153			collection_id,2154			true2155		));21562157		assert_ok!(TemplateModule::add_collection_admin(2158			origin1,2159			collection_id,2160			account(2)2161		));21622163		assert_ok!(TemplateModule::create_item(2164			origin2,2165			collection_id,2166			account(2),2167			default_nft_data().into()2168		));2169	});2170}21712172// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.2173#[test]2174fn allow_list_test_15() {2175	new_test_ext().execute_with(|| {2176		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21772178		let origin1 = Origin::signed(1);2179		let origin2 = Origin::signed(2);21802181		assert_ok!(TemplateModule::set_public_access_mode(2182			origin1.clone(),2183			collection_id,2184			AccessMode::AllowList2185		));2186		assert_ok!(TemplateModule::set_mint_permission(2187			origin1,2188			collection_id,2189			true2190		));21912192		assert_noop!(2193			TemplateModule::create_item(2194				origin2,2195				collection_id,2196				account(2),2197				default_nft_data().into()2198			)2199			.map_err(|e| e.error),2200			CommonError::<Test>::AddressNotInAllowlist2201		);2202	});2203}22042205// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.2206#[test]2207fn allow_list_test_16() {2208	new_test_ext().execute_with(|| {2209		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22102211		let origin1 = Origin::signed(1);2212		let origin2 = Origin::signed(2);22132214		assert_ok!(TemplateModule::set_public_access_mode(2215			origin1.clone(),2216			collection_id,2217			AccessMode::AllowList2218		));2219		assert_ok!(TemplateModule::set_mint_permission(2220			origin1.clone(),2221			collection_id,2222			true2223		));2224		assert_ok!(TemplateModule::add_to_allow_list(2225			origin1,2226			collection_id,2227			account(2)2228		));22292230		assert_ok!(TemplateModule::create_item(2231			origin2,2232			collection_id,2233			account(2),2234			default_nft_data().into()2235		));2236	});2237}22382239// Total number of collections. Positive test2240#[test]2241fn total_number_collections_bound() {2242	new_test_ext().execute_with(|| {2243		create_test_collection(&CollectionMode::NFT, CollectionId(1));2244	});2245}22462247#[test]2248fn create_max_collections() {2249	new_test_ext().execute_with(|| {2250		for i in 1..=COLLECTION_NUMBER_LIMIT {2251			create_test_collection(&CollectionMode::NFT, CollectionId(i));2252		}2253	});2254}22552256// Total number of collections. Negative test2257#[test]2258fn total_number_collections_bound_neg() {2259	new_test_ext().execute_with(|| {2260		let origin1 = Origin::signed(1);22612262		for i in 1..=COLLECTION_NUMBER_LIMIT {2263			create_test_collection(&CollectionMode::NFT, CollectionId(i));2264		}22652266		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2267		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2268		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();22692270		// 11-th collection in chain. Expects error2271		assert_noop!(2272			TemplateModule::create_collection(2273				origin1,2274				col_name1,2275				col_desc1,2276				token_prefix1,2277				CollectionMode::NFT2278			),2279			CommonError::<Test>::TotalCollectionsLimitExceeded2280		);2281	});2282}22832284// Owned tokens by a single address. Positive test2285#[test]2286fn owned_tokens_bound() {2287	new_test_ext().execute_with(|| {2288		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22892290		let data = default_nft_data();2291		create_test_item(collection_id, &data.clone().into());2292		create_test_item(collection_id, &data.into());2293	});2294}22952296// Owned tokens by a single address. Negotive test2297#[test]2298fn owned_tokens_bound_neg() {2299	new_test_ext().execute_with(|| {2300		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23012302		let origin1 = Origin::signed(1);23032304		for _ in 1..=MAX_TOKEN_OWNERSHIP {2305			let data = default_nft_data();2306			create_test_item(collection_id, &data.clone().into());2307		}23082309		let data = default_nft_data();2310		assert_noop!(2311			TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2312				.map_err(|e| e.error),2313			CommonError::<Test>::AccountTokenLimitExceeded2314		);2315	});2316}23172318// Number of collection admins. Positive test2319#[test]2320fn collection_admins_bound() {2321	new_test_ext().execute_with(|| {2322		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23232324		let origin1 = Origin::signed(1);23252326		assert_ok!(TemplateModule::add_collection_admin(2327			origin1.clone(),2328			collection_id,2329			account(2)2330		));2331		assert_ok!(TemplateModule::add_collection_admin(2332			origin1,2333			collection_id,2334			account(3)2335		));2336	});2337}23382339// Number of collection admins. Negotive test2340#[test]2341fn collection_admins_bound_neg() {2342	new_test_ext().execute_with(|| {2343		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23442345		let origin1 = Origin::signed(1);23462347		for i in 0..COLLECTION_ADMINS_LIMIT {2348			assert_ok!(TemplateModule::add_collection_admin(2349				origin1.clone(),2350				collection_id,2351				account((2 + i).into())2352			));2353		}2354		assert_noop!(2355			TemplateModule::add_collection_admin(2356				origin1,2357				collection_id,2358				account((3 + COLLECTION_ADMINS_LIMIT).into())2359			),2360			CommonError::<Test>::CollectionAdminCountExceeded2361		);2362	});2363}2364// #endregion23652366#[test]2367fn set_const_on_chain_schema() {2368	new_test_ext().execute_with(|| {2369		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23702371		let origin1 = Origin::signed(1);2372		assert_ok!(TemplateModule::set_const_on_chain_schema(2373			origin1,2374			collection_id,2375			b"test const on chain schema".to_vec()2376		));23772378		assert_eq!(2379			<pallet_common::CollectionById<Test>>::get(collection_id)2380				.unwrap()2381				.const_on_chain_schema,2382			b"test const on chain schema".to_vec()2383		);2384		assert_eq!(2385			<pallet_common::CollectionById<Test>>::get(collection_id)2386				.unwrap()2387				.variable_on_chain_schema,2388			b"".to_vec()2389		);2390	});2391}23922393#[test]2394fn set_variable_on_chain_schema() {2395	new_test_ext().execute_with(|| {2396		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23972398		let origin1 = Origin::signed(1);2399		assert_ok!(TemplateModule::set_variable_on_chain_schema(2400			origin1,2401			collection_id,2402			b"test variable on chain schema".to_vec()2403		));24042405		assert_eq!(2406			<pallet_common::CollectionById<Test>>::get(collection_id)2407				.unwrap()2408				.const_on_chain_schema,2409			b"".to_vec()2410		);2411		assert_eq!(2412			<pallet_common::CollectionById<Test>>::get(collection_id)2413				.unwrap()2414				.variable_on_chain_schema,2415			b"test variable on chain schema".to_vec()2416		);2417	});2418}24192420#[test]2421fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2422	new_test_ext().execute_with(|| {2423		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24242425		let origin1 = Origin::signed(1);24262427		let data = default_nft_data();2428		create_test_item(CollectionId(1), &data.into());24292430		let variable_data = b"test data".to_vec();2431		assert_ok!(TemplateModule::set_variable_meta_data(2432			origin1,2433			collection_id,2434			TokenId(1),2435			variable_data.clone()2436		));24372438		assert_eq!(2439			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2440				.unwrap()2441				.variable_data,2442			variable_data2443		);2444	});2445}24462447#[test]2448fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2449	new_test_ext().execute_with(|| {2450		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));24512452		let origin1 = Origin::signed(1);24532454		let data = default_re_fungible_data();2455		create_test_item(collection_id, &data.into());24562457		let variable_data = b"test data".to_vec();2458		assert_ok!(TemplateModule::set_variable_meta_data(2459			origin1,2460			collection_id,2461			TokenId(1),2462			variable_data.clone()2463		));24642465		assert_eq!(2466			<pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2467			variable_data2468		);2469	});2470}24712472#[test]2473fn set_variable_meta_data_on_fungible_token_fails() {2474	new_test_ext().execute_with(|| {2475		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));24762477		let origin1 = Origin::signed(1);24782479		let data = default_fungible_data();2480		create_test_item(collection_id, &data.into());24812482		let variable_data = b"test data".to_vec();2483		assert_noop!(2484			TemplateModule::set_variable_meta_data(2485				origin1,2486				collection_id,2487				TokenId(0),2488				variable_data2489			)2490			.map_err(|e| e.error),2491			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2492		);2493	});2494}24952496#[test]2497fn set_variable_meta_data_on_nft_token_fails_for_big_data() {2498	new_test_ext().execute_with(|| {2499		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25002501		let origin1 = Origin::signed(1);25022503		let data = default_nft_data();2504		create_test_item(collection_id, &data.into());25052506		let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2507		assert_noop!(2508			TemplateModule::set_variable_meta_data(2509				origin1,2510				collection_id,2511				TokenId(1),2512				variable_data2513			)2514			.map_err(|e| e.error),2515			CommonError::<Test>::TokenVariableDataLimitExceeded2516		);2517	});2518}25192520#[test]2521fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {2522	new_test_ext().execute_with(|| {2523		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));25242525		let origin1 = Origin::signed(1);25262527		let data = default_re_fungible_data();2528		create_test_item(collection_id, &data.into());25292530		let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2531		assert_noop!(2532			TemplateModule::set_variable_meta_data(2533				origin1,2534				collection_id,2535				TokenId(1),2536				variable_data2537			)2538			.map_err(|e| e.error),2539			CommonError::<Test>::TokenVariableDataLimitExceeded2540		);2541	});2542}25432544#[test]2545fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2546	new_test_ext().execute_with(|| {2547		//default_limits();25482549		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25502551		let origin1 = Origin::signed(1);25522553		let data = default_nft_data();2554		create_test_item(collection_id, &data.into());25552556		assert_ok!(TemplateModule::set_meta_update_permission_flag(2557			origin1.clone(),2558			collection_id,2559			MetaUpdatePermission::ItemOwner,2560		));25612562		let variable_data = b"ten chars.".to_vec();2563		assert_ok!(TemplateModule::set_variable_meta_data(2564			origin1,2565			collection_id,2566			TokenId(1),2567			variable_data.clone()2568		));25692570		assert_eq!(2571			<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2572				.unwrap()2573				.variable_data,2574			variable_data2575		);2576	});2577}25782579#[test]2580fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {2581	new_test_ext().execute_with(|| {2582		let collection_id =2583			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));25842585		let origin1 = Origin::signed(1);25862587		assert_ok!(TemplateModule::set_mint_permission(2588			origin1.clone(),2589			collection_id,2590			true2591		));2592		assert_ok!(TemplateModule::add_to_allow_list(2593			origin1.clone(),2594			collection_id,2595			account(1)2596		));25972598		let data = default_nft_data();2599		create_test_item(collection_id, &data.into());26002601		assert_ok!(TemplateModule::set_meta_update_permission_flag(2602			origin1.clone(),2603			collection_id,2604			MetaUpdatePermission::ItemOwner,2605		));26062607		let variable_data = b"1234567890123".to_vec();2608		assert_noop!(2609			TemplateModule::set_variable_meta_data(2610				origin1,2611				collection_id,2612				TokenId(1),2613				variable_data.clone()2614			)2615			.map_err(|e| e.error),2616			CommonError::<Test>::TokenVariableDataLimitExceeded2617		);2618	})2619}26202621#[test]2622fn collection_transfer_flag_works() {2623	new_test_ext().execute_with(|| {2624		let origin1 = Origin::signed(1);26252626		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2627		assert_ok!(TemplateModule::set_transfers_enabled_flag(2628			origin1,2629			collection_id,2630			true2631		));26322633		let data = default_nft_data();2634		create_test_item(collection_id, &data.into());2635		assert_eq!(2636			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2637			12638		);2639		assert_eq!(2640			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2641			true2642		);26432644		let origin1 = Origin::signed(1);26452646		// default scenario2647		assert_ok!(TemplateModule::transfer(2648			origin1,2649			account(2),2650			collection_id,2651			TokenId(1),2652			12653		));2654		assert_eq!(2655			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2656			false2657		);2658		assert_eq!(2659			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2660			true2661		);2662		assert_eq!(2663			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2664			02665		);2666		assert_eq!(2667			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2668			12669		);2670	});2671}26722673#[test]2674fn set_variable_meta_data_on_nft_with_admin_flag() {2675	new_test_ext().execute_with(|| {2676		// default_limits();26772678		let collection_id =2679			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26802681		let origin1 = Origin::signed(1);2682		let origin2 = Origin::signed(2);26832684		assert_ok!(TemplateModule::set_mint_permission(2685			origin2.clone(),2686			collection_id,2687			true2688		));2689		assert_ok!(TemplateModule::add_to_allow_list(2690			origin2.clone(),2691			collection_id,2692			account(1)2693		));26942695		assert_ok!(TemplateModule::add_collection_admin(2696			origin2.clone(),2697			collection_id,2698			account(1)2699		));27002701		let data = default_nft_data();2702		create_test_item(collection_id, &data.into());27032704		assert_ok!(TemplateModule::set_meta_update_permission_flag(2705			origin2.clone(),2706			collection_id,2707			MetaUpdatePermission::Admin,2708		));27092710		let variable_data = b"test.".to_vec();2711		assert_ok!(TemplateModule::set_variable_meta_data(2712			origin1,2713			collection_id,2714			TokenId(1),2715			variable_data.clone()2716		));27172718		assert_eq!(2719			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2720				.unwrap()2721				.variable_data,2722			variable_data2723		);2724	});2725}27262727#[test]2728fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2729	new_test_ext().execute_with(|| {2730		// default_limits();27312732		let collection_id =2733			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27342735		let origin1 = Origin::signed(1);2736		let origin2 = Origin::signed(2);27372738		assert_ok!(TemplateModule::set_mint_permission(2739			origin2.clone(),2740			collection_id,2741			true2742		));2743		assert_ok!(TemplateModule::add_to_allow_list(2744			origin2.clone(),2745			collection_id,2746			account(1)2747		));27482749		let data = default_nft_data();2750		create_test_item(collection_id, &data.into());27512752		assert_ok!(TemplateModule::set_meta_update_permission_flag(2753			origin2.clone(),2754			collection_id,2755			MetaUpdatePermission::Admin,2756		));27572758		let variable_data = b"test.".to_vec();2759		assert_noop!(2760			TemplateModule::set_variable_meta_data(2761				origin1,2762				collection_id,2763				TokenId(1),2764				variable_data.clone()2765			)2766			.map_err(|e| e.error),2767			CommonError::<Test>::NoPermission2768		);2769	});2770}27712772#[test]2773fn set_variable_meta_flag_after_freeze() {2774	new_test_ext().execute_with(|| {2775		// default_limits();27762777		let collection_id =2778			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27792780		let origin2 = Origin::signed(2);27812782		assert_ok!(TemplateModule::set_meta_update_permission_flag(2783			origin2.clone(),2784			collection_id,2785			MetaUpdatePermission::None,2786		));2787		assert_noop!(2788			TemplateModule::set_meta_update_permission_flag(2789				origin2.clone(),2790				collection_id,2791				MetaUpdatePermission::Admin2792			),2793			CommonError::<Test>::MetadataFlagFrozen2794		);2795	});2796}27972798#[test]2799fn set_variable_meta_data_on_nft_with_none_flag_neg() {2800	new_test_ext().execute_with(|| {2801		// default_limits();28022803		let collection_id =2804			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2805		let origin1 = Origin::signed(1);28062807		let data = default_nft_data();2808		create_test_item(collection_id, &data.into());28092810		assert_ok!(TemplateModule::set_meta_update_permission_flag(2811			origin1.clone(),2812			collection_id,2813			MetaUpdatePermission::None,2814		));28152816		let variable_data = b"test.".to_vec();2817		assert_noop!(2818			TemplateModule::set_variable_meta_data(2819				origin1.clone(),2820				collection_id,2821				TokenId(1),2822				variable_data.clone()2823			)2824			.map_err(|e| e.error),2825			CommonError::<Test>::NoPermission2826		);2827	});2828}28292830#[test]2831fn collection_transfer_flag_works_neg() {2832	new_test_ext().execute_with(|| {2833		let origin1 = Origin::signed(1);28342835		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2836		assert_ok!(TemplateModule::set_transfers_enabled_flag(2837			origin1,2838			collection_id,2839			false2840		));28412842		let data = default_nft_data();2843		create_test_item(collection_id, &data.into());2844		assert_eq!(2845			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2846			12847		);2848		assert_eq!(2849			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2850			true2851		);28522853		let origin1 = Origin::signed(1);28542855		// default scenario2856		assert_noop!(2857			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2858				.map_err(|e| e.error),2859			CommonError::<Test>::TransferNotAllowed2860		);2861		assert_eq!(2862			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2863			12864		);2865		assert_eq!(2866			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2867			02868		);2869		assert_eq!(2870			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2871			true2872		);2873		assert_eq!(2874			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2875			false2876		);2877	});2878}
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -29,10 +29,14 @@
 pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;
 pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;
 pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
-pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;
 
+pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {
+	10_000_000
+} else {
+	10
+};
 pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
-	100000
+	100_000
 } else {
 	10
 };
@@ -44,7 +48,7 @@
 pub const COLLECTION_ADMINS_LIMIT: u32 = 5;
 pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;
 pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
-	1000000
+	1_000_000
 } else {
 	10
 };