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
1// Tests to be written here1// Tests to be written here
2use super::*;2use super::*;
3use crate::mock::*;3use crate::mock::*;
4use crate::{AccessMode, CollectionMode, Ownership, CreateItemData};4use crate::{AccessMode, CollectionMode};
5use up_data_structs::{5use up_data_structs::{
6 CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,6 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,
7 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,
7 MAX_DECIMAL_POINTS,8 TokenId,
8};9};
9use frame_support::{assert_noop, assert_ok};10use frame_support::{assert_noop, assert_ok};
10use sp_std::convert::TryInto;11use sp_std::convert::TryInto;
49 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();50 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_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
51 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();52 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
52 assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);
53 assert_eq!(53 assert_eq!(
54 TemplateModule::collection_id(id).unwrap().name,54 <pallet_common::CollectionById<Test>>::get(id)
55 .unwrap()
56 .owner,
57 owner
58 );
59 assert_eq!(
60 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,
55 saved_col_name61 saved_col_name
56 );62 );
57 assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);
58 assert_eq!(63 assert_eq!(
59 TemplateModule::collection_id(id).unwrap().description,64 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,
65 *mode
66 );
67 assert_eq!(
68 <pallet_common::CollectionById<Test>>::get(id)
69 .unwrap()
70 .description,
60 saved_description71 saved_description
61 );72 );
62 assert_eq!(73 assert_eq!(
63 TemplateModule::collection_id(id).unwrap().token_prefix,74 <pallet_common::CollectionById<Test>>::get(id)
75 .unwrap()
76 .token_prefix,
64 saved_prefix77 saved_prefix
65 );78 );
66 id79 id
91fn set_version_schema() {104fn set_version_schema() {
92 new_test_ext().execute_with(|| {105 new_test_ext().execute_with(|| {
93 let origin1 = Origin::signed(1);106 let origin1 = Origin::signed(1);
94 let collection_id = create_test_collection(&CollectionMode::NFT, 1);107 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
95108
96 assert_ok!(TemplateModule::set_schema_version(109 assert_ok!(TemplateModule::set_schema_version(
97 origin1,110 origin1,
98 collection_id,111 collection_id,
99 SchemaVersion::Unique112 SchemaVersion::Unique
100 ));113 ));
101 assert_eq!(114 assert_eq!(
102 TemplateModule::collection_id(collection_id)115 <pallet_common::CollectionById<Test>>::get(collection_id)
103 .unwrap()116 .unwrap()
104 .schema_version,117 .schema_version,
105 SchemaVersion::Unique118 SchemaVersion::Unique
131#[test]144#[test]
132fn create_nft_item() {145fn create_nft_item() {
133 new_test_ext().execute_with(|| {146 new_test_ext().execute_with(|| {
134 let collection_id = create_test_collection(&CollectionMode::NFT, 1);147 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
135148
136 let data = default_nft_data();149 let data = default_nft_data();
137 create_test_item(collection_id, &data.clone().into());150 create_test_item(collection_id, &data.clone().into());
151
138 let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();152 let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();
139 assert_eq!(item.const_data, data.const_data.into_inner());153 assert_eq!(item.const_data, data.const_data.into_inner());
140 assert_eq!(item.variable_data, data.variable_data.into_inner());154 assert_eq!(item.variable_data, data.variable_data.into_inner());
141 });155 });
146#[test]160#[test]
147fn create_nft_multiple_items() {161fn create_nft_multiple_items() {
148 new_test_ext().execute_with(|| {162 new_test_ext().execute_with(|| {
149 create_test_collection(&CollectionMode::NFT, 1);163 create_test_collection(&CollectionMode::NFT, CollectionId(1));
150164
151 let origin1 = Origin::signed(1);165 let origin1 = Origin::signed(1);
152166
153 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];167 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];
154168
155 assert_ok!(TemplateModule::create_multiple_items(169 assert_ok!(TemplateModule::create_multiple_items(
156 origin1,170 origin1,
157 1,171 CollectionId(1),
158 account(1),172 account(1),
159 items_data173 items_data
160 .clone()174 .clone()
163 .collect()177 .collect()
164 ));178 ));
165 for (index, data) in items_data.into_iter().enumerate() {179 for (index, data) in items_data.into_iter().enumerate() {
166 let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap();180 let item = <pallet_nonfungible::TokenData<Test>>::get((
181 CollectionId(1),
182 TokenId((index + 1) as u32),
183 ))
184 .unwrap();
167 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());185 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());186 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
169 }187 }
173#[test]191#[test]
174fn create_refungible_item() {192fn create_refungible_item() {
175 new_test_ext().execute_with(|| {193 new_test_ext().execute_with(|| {
176 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);194 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
177195
178 let data = default_re_fungible_data();196 let data = default_re_fungible_data();
179 create_test_item(collection_id, &data.clone().into());197 create_test_item(collection_id, &data.clone().into());
180 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();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)));
181 assert_eq!(item.const_data, data.const_data.into_inner());201 assert_eq!(item.const_data, data.const_data.into_inner());
182 assert_eq!(item.variable_data, data.variable_data.into_inner());202 assert_eq!(item.variable_data, data.variable_data.into_inner());
183 assert_eq!(203 assert_eq!(balance, 1023);
184 item.owner[0],
185 Ownership {
186 owner: account(1),
187 fraction: 1023
188 }
189 );
190 });204 });
191}205}
192206
193#[test]207#[test]
194fn create_multiple_refungible_items() {208fn create_multiple_refungible_items() {
195 new_test_ext().execute_with(|| {209 new_test_ext().execute_with(|| {
196 create_test_collection(&CollectionMode::ReFungible, 1);210 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
197211
198 let origin1 = Origin::signed(1);212 let origin1 = Origin::signed(1);
199213
205219
206 assert_ok!(TemplateModule::create_multiple_items(220 assert_ok!(TemplateModule::create_multiple_items(
207 origin1,221 origin1,
208 1,222 CollectionId(1),
209 account(1),223 account(1),
210 items_data224 items_data
211 .clone()225 .clone()
214 .collect()228 .collect()
215 ));229 ));
216 for (index, data) in items_data.into_iter().enumerate() {230 for (index, data) in items_data.into_iter().enumerate() {
217 let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();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)));
218 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());237 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());238 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
220 assert_eq!(239 assert_eq!(balance, 1023);
221 item.owner[0],
222 Ownership {
223 owner: account(1),
224 fraction: 1023
225 }
226 );
227 }240 }
228 });241 });
229}242}
230243
231#[test]244#[test]
232fn create_fungible_item() {245fn create_fungible_item() {
233 new_test_ext().execute_with(|| {246 new_test_ext().execute_with(|| {
234 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);247 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
235248
236 let data = default_fungible_data();249 let data = default_fungible_data();
237 create_test_item(collection_id, &data.into());250 create_test_item(collection_id, &data.into());
238251
239 assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);252 assert_eq!(
253 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
254 5
255 );
240 });256 });
241}257}
242258
245// new_test_ext().execute_with(|| {261// new_test_ext().execute_with(|| {
246// default_limits();262// default_limits();
247263
248// create_test_collection(&CollectionMode::Fungible(3), 1);264// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
249265
250// let origin1 = Origin::signed(1);266// let origin1 = Origin::signed(1);
251267
269#[test]285#[test]
270fn transfer_fungible_item() {286fn transfer_fungible_item() {
271 new_test_ext().execute_with(|| {287 new_test_ext().execute_with(|| {
272 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);288 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
273289
274 let origin1 = Origin::signed(1);290 let origin1 = Origin::signed(1);
275 let origin2 = Origin::signed(2);291 let origin2 = Origin::signed(2);
276292
277 let data = default_fungible_data();293 let data = default_fungible_data();
278 create_test_item(collection_id, &data.into());294 create_test_item(collection_id, &data.into());
279295
280 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);296 assert_eq!(
281 assert_eq!(TemplateModule::balance_count(1, 1), 5);297 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),
298 5
299 );
282300
283 // change owner scenario301 // change owner scenario
284 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 5));302 assert_ok!(TemplateModule::transfer(
303 origin1,
304 account(2),
305 CollectionId(1),
306 TokenId(0),
307 5
308 ));
285 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);309 assert_eq!(
310 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),
286 assert_eq!(TemplateModule::balance_count(1, 1), 0);311 0
287 assert_eq!(TemplateModule::balance_count(1, 2), 5);312 );
288313
289 // split item scenario314 // split item scenario
290 assert_ok!(TemplateModule::transfer(315 assert_ok!(TemplateModule::transfer(
291 origin2.clone(),316 origin2.clone(),
292 account(3),317 account(3),
293 1,318 CollectionId(1),
294 1,319 TokenId(0),
295 3320 3
296 ));321 ));
297 assert_eq!(TemplateModule::balance_count(1, 2), 2);
298 assert_eq!(TemplateModule::balance_count(1, 3), 3);
299322
300 // split item and new owner has account scenario323 // split item and new owner has account scenario
301 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 1));324 assert_ok!(TemplateModule::transfer(
325 origin2,
326 account(3),
302 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);327 CollectionId(1),
303 assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);328 TokenId(0),
329 1
330 ));
304 assert_eq!(TemplateModule::balance_count(1, 2), 1);331 assert_eq!(
332 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),
333 1
334 );
305 assert_eq!(TemplateModule::balance_count(1, 3), 4);335 assert_eq!(
336 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),
337 4
338 );
306 });339 });
307}340}
308341
309#[test]342#[test]
310fn transfer_refungible_item() {343fn transfer_refungible_item() {
311 new_test_ext().execute_with(|| {344 new_test_ext().execute_with(|| {
312 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);345 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
313346
347 // Create RFT 1 in 1023 pieces for account 1
314 let data = default_re_fungible_data();348 let data = default_re_fungible_data();
315 create_test_item(collection_id, &data.clone().into());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 1
356 );
357 assert_eq!(
358 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
359 1023
360 );
361 assert_eq!(
362 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
363 true
364 );
316365
366 // Account 1 transfers all 1023 pieces of RFT 1 to account 2
317 let origin1 = Origin::signed(1);367 let origin1 = Origin::signed(1);
318 let origin2 = Origin::signed(2);368 let origin2 = Origin::signed(2);
319 {369 assert_ok!(TemplateModule::transfer(
320 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();
321 assert_eq!(item.const_data, data.const_data.into_inner());370 origin1,
322 assert_eq!(item.variable_data, data.variable_data.into_inner());371 account(2),
323 assert_eq!(
324 item.owner[0],
325 Ownership {372 CollectionId(1),
326 owner: account(1),
327 fraction: 1023373 TokenId(1),
328 }
329 );
330 }
331 assert_eq!(TemplateModule::balance_count(1, 1), 1023);
332 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);374 1023
333
334 // change owner scenario
335 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));375 ));
336 assert_eq!(376 assert_eq!(
337 TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],377 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
338 Ownership {
339 owner: account(2),
340 fraction: 1023378 1023
341 }
342 );379 );
343 assert_eq!(TemplateModule::balance_count(1, 1), 0);380 assert_eq!(
381 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
382 0
383 );
344 assert_eq!(TemplateModule::balance_count(1, 2), 1023);384 assert_eq!(
385 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
386 1
387 );
345 // assert_eq!(TemplateModule::address_tokens(1, 1), []);388 assert_eq!(
389 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
390 false
391 );
346 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);392 assert_eq!(
393 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
394 true
395 );
347396
348 // split item scenario397 // Account 2 transfers 500 pieces of RFT 1 to account 3
349 assert_ok!(TemplateModule::transfer(398 assert_ok!(TemplateModule::transfer(
350 origin2.clone(),399 origin2.clone(),
351 account(3),400 account(3),
352 1,401 CollectionId(1),
353 1,402 TokenId(1),
354 500403 500
355 ));404 ));
356 {405 assert_eq!(
357 let item = TemplateModule::refungible_item_id(1, 1).unwrap();406 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
358 assert_eq!(
359 item.owner[0],
360 Ownership {
361 owner: account(2),
362 fraction: 523407 523
363 }408 );
364 );
365 assert_eq!(409 assert_eq!(
366 item.owner[1],410 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
367 Ownership {
368 owner: account(3),
369 fraction: 500411 500
370 }412 );
371 );
372 }413 assert_eq!(
373 assert_eq!(TemplateModule::balance_count(1, 2), 523);414 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
415 1
416 );
374 assert_eq!(TemplateModule::balance_count(1, 3), 500);417 assert_eq!(
418 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
419 1
420 );
375 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);421 assert_eq!(
422 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
423 true
424 );
376 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);425 assert_eq!(
426 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),
427 true
428 );
377429
378 // split item and new owner has account scenario430 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance
379 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));431 assert_ok!(TemplateModule::transfer(
432 origin2,
433 account(3),
380 {434 CollectionId(1),
381 let item = TemplateModule::refungible_item_id(1, 1).unwrap();
382 assert_eq!(435 TokenId(1),
383 item.owner[0],436 200
384 Ownership {437 ));
438 assert_eq!(
385 owner: account(2),439 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
386 fraction: 323440 323
387 }441 );
388 );
389 assert_eq!(442 assert_eq!(
390 item.owner[1],443 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
391 Ownership {
392 owner: account(3),
393 fraction: 700444 700
394 }445 );
395 );
396 }446 assert_eq!(
397 assert_eq!(TemplateModule::balance_count(1, 2), 323);447 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
448 1
449 );
398 assert_eq!(TemplateModule::balance_count(1, 3), 700);450 assert_eq!(
451 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
452 1
453 );
399 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);454 assert_eq!(
455 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
456 true
457 );
400 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);458 assert_eq!(
459 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),
460 true
461 );
401 });462 });
402}463}
403464
404#[test]465#[test]
405fn transfer_nft_item() {466fn transfer_nft_item() {
406 new_test_ext().execute_with(|| {467 new_test_ext().execute_with(|| {
407 let collection_id = create_test_collection(&CollectionMode::NFT, 1);468 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
408469
409 let data = default_nft_data();470 let data = default_nft_data();
410 create_test_item(collection_id, &data.into());471 create_test_item(collection_id, &data.into());
411 assert_eq!(TemplateModule::balance_count(1, 1), 1);472 assert_eq!(
473 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
474 1
475 );
412 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);476 assert_eq!(
477 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
478 true
479 );
413480
414 let origin1 = Origin::signed(1);481 let origin1 = Origin::signed(1);
415 // default scenario482 // default scenario
416 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));483 assert_ok!(TemplateModule::transfer(
484 origin1,
485 account(2),
486 CollectionId(1),
487 TokenId(1),
488 1
489 ));
417 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));490 assert_eq!(
491 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
418 assert_eq!(TemplateModule::balance_count(1, 1), 0);492 0
493 );
419 assert_eq!(TemplateModule::balance_count(1, 2), 1);494 assert_eq!(
495 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
496 1
497 );
420 // assert_eq!(TemplateModule::address_tokens(1, 1), []);498 assert_eq!(
499 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
500 false
501 );
421 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);502 assert_eq!(
503 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
504 true
505 );
422 });506 });
423}507}
424508
425#[test]509#[test]
510fn transfer_nft_item_wrong_value() {
511 new_test_ext().execute_with(|| {
512 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
513
514 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 1
519 );
520 assert_eq!(
521 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
522 true
523 );
524
525 let origin1 = Origin::signed(1);
526
527 assert_noop!(
528 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)
529 .map_err(|e| e.error),
530 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount
531 );
532 });
533}
534
535#[test]
536fn transfer_nft_item_zero_value() {
537 new_test_ext().execute_with(|| {
538 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
539
540 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 1
545 );
546 assert_eq!(
547 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
548 true
549 );
550
551 let origin1 = Origin::signed(1);
552
553 // Transferring 0 amount works on NFT...
554 assert_ok!(TemplateModule::transfer(
555 origin1,
556 account(2),
557 CollectionId(1),
558 TokenId(1),
559 0
560 ));
561 // ... and results in no transfer
562 assert_eq!(
563 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
564 1
565 );
566 assert_eq!(
567 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
568 true
569 );
570 });
571}
572
573#[test]
426fn nft_approve_and_transfer_from() {574fn nft_approve_and_transfer_from() {
427 new_test_ext().execute_with(|| {575 new_test_ext().execute_with(|| {
428 let collection_id = create_test_collection(&CollectionMode::NFT, 1);576 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
429577
430 let data = default_nft_data();578 let data = default_nft_data();
431 create_test_item(collection_id, &data.into());579 create_test_item(collection_id, &data.into());
432580
433 let origin1 = Origin::signed(1);581 let origin1 = Origin::signed(1);
434 let origin2 = Origin::signed(2);582 let origin2 = Origin::signed(2);
435583
436 assert_eq!(TemplateModule::balance_count(1, 1), 1);584 assert_eq!(
585 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
586 1
587 );
437 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);588 assert_eq!(
589 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
590 true
591 );
438592
439 // neg transfer593 // neg transfer_from
440 assert_noop!(594 assert_noop!(
441 TemplateModule::transfer_from(origin2.clone(), account(1), account(2), 1, 1, 1),595 TemplateModule::transfer_from(
596 origin2.clone(),
597 account(1),
598 account(2),
599 CollectionId(1),
600 TokenId(1),
601 1
602 )
603 .map_err(|e| e.error),
442 Error::<Test>::NoPermission604 CommonError::<Test>::TokenValueNotEnough
443 );605 );
444606
445 // do approve607 // do approve
446 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 5));608 assert_ok!(TemplateModule::approve(
609 origin1,
610 account(2),
611 CollectionId(1),
612 TokenId(1),
613 1
614 ));
447 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);615 assert_eq!(
616 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
448 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);617 account(2)
618 );
449619
450 assert_ok!(TemplateModule::transfer_from(620 assert_ok!(TemplateModule::transfer_from(
451 origin2,621 origin2,
452 account(1),622 account(1),
453 account(3),623 account(3),
454 1,624 CollectionId(1),
455 1,625 TokenId(1),
456 1626 1
457 ));627 ));
458 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);628 assert!(
629 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()
630 );
459 });631 });
460}632}
461633
462#[test]634#[test]
463fn nft_approve_and_transfer_from_allow_list() {635fn nft_approve_and_transfer_from_allow_list() {
464 new_test_ext().execute_with(|| {636 new_test_ext().execute_with(|| {
465 let collection_id = create_test_collection(&CollectionMode::NFT, 1);637 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
466638
467 let origin1 = Origin::signed(1);639 let origin1 = Origin::signed(1);
468 let origin2 = Origin::signed(2);640 let origin2 = Origin::signed(2);
469641
642 // Create NFT 1 for account 1
470 let data = default_nft_data();643 let data = default_nft_data();
471 create_test_item(collection_id, &data.clone().into());644 create_test_item(collection_id, &data.clone().into());
472
473 assert_eq!(645 assert_eq!(
474 &TemplateModule::nft_item_id(1, 1).unwrap().const_data,646 &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))
647 .unwrap()
648 .const_data,
475 &data.const_data.into_inner()649 &data.const_data.into_inner()
476 );650 );
477 assert_eq!(TemplateModule::balance_count(1, 1), 1);651 assert_eq!(
652 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
653 1
654 );
478 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);655 assert_eq!(
656 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
657 true
658 );
479659
660 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list
480 assert_ok!(TemplateModule::set_mint_permission(661 assert_ok!(TemplateModule::set_mint_permission(
481 origin1.clone(),662 origin1.clone(),
482 1,663 CollectionId(1),
483 true664 true
484 ));665 ));
485 assert_ok!(TemplateModule::set_public_access_mode(666 assert_ok!(TemplateModule::set_public_access_mode(
486 origin1.clone(),667 origin1.clone(),
487 1,668 CollectionId(1),
488 AccessMode::AllowList669 AccessMode::AllowList
489 ));670 ));
490 assert_ok!(TemplateModule::add_to_allow_list(671 assert_ok!(TemplateModule::add_to_allow_list(
491 origin1.clone(),672 origin1.clone(),
492 1,673 CollectionId(1),
493 account(1)674 account(1)
494 ));675 ));
495 assert_ok!(TemplateModule::add_to_allow_list(676 assert_ok!(TemplateModule::add_to_allow_list(
496 origin1.clone(),677 origin1.clone(),
497 1,678 CollectionId(1),
498 account(2)679 account(2)
499 ));680 ));
500 assert_ok!(TemplateModule::add_to_allow_list(681 assert_ok!(TemplateModule::add_to_allow_list(
501 origin1.clone(),682 origin1.clone(),
502 1,683 CollectionId(1),
503 account(3)684 account(3)
504 ));685 ));
505686
506 // do approve687 // Account 1 approves account 2 for NFT 1
507 assert_ok!(TemplateModule::approve(688 assert_ok!(TemplateModule::approve(
508 origin1.clone(),689 origin1.clone(),
509 account(2),690 account(2),
510 1,691 CollectionId(1),
511 1,692 TokenId(1),
512 5693 1
513 ));694 ));
514 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);695 assert_eq!(
696 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
515 assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));697 account(2)
516 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);698 );
517699
700 // Account 2 transfers NFT 1 from account 1 to account 3
518 assert_ok!(TemplateModule::transfer_from(701 assert_ok!(TemplateModule::transfer_from(
519 origin2,702 origin2,
520 account(1),703 account(1),
521 account(3),704 account(3),
522 1,705 CollectionId(1),
523 1,706 TokenId(1),
524 1707 1
525 ));708 ));
526 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);709 assert!(
710 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()
711 );
527 });712 });
528}713}
529714
530#[test]715#[test]
531fn refungible_approve_and_transfer_from() {716fn refungible_approve_and_transfer_from() {
532 new_test_ext().execute_with(|| {717 new_test_ext().execute_with(|| {
533 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);718 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
534719
535 let origin1 = Origin::signed(1);720 let origin1 = Origin::signed(1);
536 let origin2 = Origin::signed(2);721 let origin2 = Origin::signed(2);
537722
723 // Create RFT 1 in 1023 pieces for account 1
538 let data = default_re_fungible_data();724 let data = default_re_fungible_data();
539 create_test_item(collection_id, &data.into());725 create_test_item(collection_id, &data.into());
540726
541 assert_eq!(TemplateModule::balance_count(1, 1), 1023);727 assert_eq!(
728 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
729 1
730 );
731 assert_eq!(
732 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
733 1023
734 );
542 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);735 assert_eq!(
736 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
737 true
738 );
543739
740 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list
544 assert_ok!(TemplateModule::set_mint_permission(741 assert_ok!(TemplateModule::set_mint_permission(
545 origin1.clone(),742 origin1.clone(),
546 1,743 CollectionId(1),
547 true744 true
548 ));745 ));
549 assert_ok!(TemplateModule::set_public_access_mode(746 assert_ok!(TemplateModule::set_public_access_mode(
550 origin1.clone(),747 origin1.clone(),
551 1,748 CollectionId(1),
552 AccessMode::AllowList749 AccessMode::AllowList
553 ));750 ));
554 assert_ok!(TemplateModule::add_to_allow_list(751 assert_ok!(TemplateModule::add_to_allow_list(
555 origin1.clone(),752 origin1.clone(),
556 1,753 CollectionId(1),
557 account(1)754 account(1)
558 ));755 ));
559 assert_ok!(TemplateModule::add_to_allow_list(756 assert_ok!(TemplateModule::add_to_allow_list(
560 origin1.clone(),757 origin1.clone(),
561 1,758 CollectionId(1),
562 account(2)759 account(2)
563 ));760 ));
564 assert_ok!(TemplateModule::add_to_allow_list(761 assert_ok!(TemplateModule::add_to_allow_list(
565 origin1.clone(),762 origin1.clone(),
566 1,763 CollectionId(1),
567 account(3)764 account(3)
568 ));765 ));
569766
570 // do approve767 // Account 1 approves account 2 for 1023 pieces of RFT 1
571 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1023));768 assert_ok!(TemplateModule::approve(
769 origin1,
770 account(2),
771 CollectionId(1),
772 TokenId(1),
773 1023
774 ));
572 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);775 assert_eq!(
776 <pallet_refungible::Allowance<Test>>::get((
777 CollectionId(1),
778 TokenId(1),
779 account(1),
780 account(2)
781 )),
782 1023
783 );
573784
785 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3
574 assert_ok!(TemplateModule::transfer_from(786 assert_ok!(TemplateModule::transfer_from(
575 origin2,787 origin2,
576 account(1),788 account(1),
577 account(3),789 account(3),
578 1,790 CollectionId(1),
579 1,791 TokenId(1),
580 100792 100
581 ));793 ));
582 assert_eq!(TemplateModule::balance_count(1, 1), 923);794 assert_eq!(
795 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
796 1
797 );
798 assert_eq!(
799 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
800 1
801 );
802 assert_eq!(
803 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
804 923
805 );
583 assert_eq!(TemplateModule::balance_count(1, 3), 100);806 assert_eq!(
807 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
808 100
809 );
584 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);810 assert_eq!(
811 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
812 true
813 );
585 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);814 assert_eq!(
586815 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
816 true
587 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 923);817 );
818 assert_eq!(
819 <pallet_refungible::Allowance<Test>>::get((
820 CollectionId(1),
821 TokenId(1),
822 account(1),
823 account(2)
824 )),
825 923
826 );
588 });827 });
589}828}
590829
591#[test]830#[test]
592fn fungible_approve_and_transfer_from() {831fn fungible_approve_and_transfer_from() {
593 new_test_ext().execute_with(|| {832 new_test_ext().execute_with(|| {
594 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);833 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
595834
596 let data = default_fungible_data();835 let data = default_fungible_data();
597 create_test_item(collection_id, &data.into());836 create_test_item(collection_id, &data.into());
598837
599 let origin1 = Origin::signed(1);838 let origin1 = Origin::signed(1);
600 let origin2 = Origin::signed(2);839 let origin2 = Origin::signed(2);
601840
602 assert_eq!(TemplateModule::balance_count(1, 1), 5);
603
604 assert_ok!(TemplateModule::set_mint_permission(841 assert_ok!(TemplateModule::set_mint_permission(
605 origin1.clone(),842 origin1.clone(),
606 1,843 CollectionId(1),
607 true844 true
608 ));845 ));
609 assert_ok!(TemplateModule::set_public_access_mode(846 assert_ok!(TemplateModule::set_public_access_mode(
610 origin1.clone(),847 origin1.clone(),
611 1,848 CollectionId(1),
612 AccessMode::AllowList849 AccessMode::AllowList
613 ));850 ));
614 assert_ok!(TemplateModule::add_to_allow_list(851 assert_ok!(TemplateModule::add_to_allow_list(
615 origin1.clone(),852 origin1.clone(),
616 1,853 CollectionId(1),
617 account(1)854 account(1)
618 ));855 ));
619 assert_ok!(TemplateModule::add_to_allow_list(856 assert_ok!(TemplateModule::add_to_allow_list(
620 origin1.clone(),857 origin1.clone(),
621 1,858 CollectionId(1),
622 account(2)859 account(2)
623 ));860 ));
624 assert_ok!(TemplateModule::add_to_allow_list(861 assert_ok!(TemplateModule::add_to_allow_list(
625 origin1.clone(),862 origin1.clone(),
626 1,863 CollectionId(1),
627 account(3)864 account(3)
628 ));865 ));
629866
630 // do approve867 // do approve
631 assert_ok!(TemplateModule::approve(868 assert_ok!(TemplateModule::approve(
632 origin1.clone(),869 origin1.clone(),
633 account(2),870 account(2),
634 1,871 CollectionId(1),
635 1,872 TokenId(0),
636 5873 5
637 ));874 ));
638 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);875 assert_eq!(
876 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
877 5
878 );
639 assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));879 assert_ok!(TemplateModule::approve(
880 origin1,
881 account(3),
882 CollectionId(1),
883 TokenId(0),
884 5
885 ));
640 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);886 assert_eq!(
887 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
888 5
889 );
641 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);890 assert_eq!(
891 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),
892 5
893 );
642894
643 assert_ok!(TemplateModule::transfer_from(895 assert_ok!(TemplateModule::transfer_from(
644 origin2.clone(),896 origin2.clone(),
645 account(1),897 account(1),
646 account(3),898 account(3),
647 1,899 CollectionId(1),
648 1,900 TokenId(0),
649 4901 4
650 ));902 ));
651 assert_eq!(TemplateModule::balance_count(1, 1), 1);
652 assert_eq!(TemplateModule::balance_count(1, 3), 4);
653903
654 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);904 assert_eq!(
905 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
906 1
907 );
655908
656 assert_noop!(909 assert_noop!(
657 TemplateModule::transfer_from(origin2, account(1), account(3), 1, 1, 4),910 TemplateModule::transfer_from(
911 origin2,
912 account(1),
913 account(3),
914 CollectionId(1),
915 TokenId(0),
916 4
917 )
918 .map_err(|e| e.error),
658 Error::<Test>::NoPermission919 CommonError::<Test>::TokenValueNotEnough
659 );920 );
660 });921 });
661}922}
662923
663#[test]924#[test]
664fn change_collection_owner() {925fn change_collection_owner() {
665 new_test_ext().execute_with(|| {926 new_test_ext().execute_with(|| {
666 let collection_id = create_test_collection(&CollectionMode::NFT, 1);927 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
667928
668 let origin1 = Origin::signed(1);929 let origin1 = Origin::signed(1);
669 assert_ok!(TemplateModule::change_collection_owner(930 assert_ok!(TemplateModule::change_collection_owner(
672 2933 2
673 ));934 ));
674 assert_eq!(935 assert_eq!(
675 TemplateModule::collection_id(collection_id).unwrap().owner,936 <pallet_common::CollectionById<Test>>::get(collection_id)
937 .unwrap()
938 .owner,
676 2939 2
677 );940 );
678 });941 });
681#[test]944#[test]
682fn destroy_collection() {945fn destroy_collection() {
683 new_test_ext().execute_with(|| {946 new_test_ext().execute_with(|| {
684 let collection_id = create_test_collection(&CollectionMode::NFT, 1);947 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
685948
686 let origin1 = Origin::signed(1);949 let origin1 = Origin::signed(1);
687 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));950 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
691#[test]954#[test]
692fn burn_nft_item() {955fn burn_nft_item() {
693 new_test_ext().execute_with(|| {956 new_test_ext().execute_with(|| {
694 let collection_id = create_test_collection(&CollectionMode::NFT, 1);957 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
695958
696 let origin1 = Origin::signed(1);959 let origin1 = Origin::signed(1);
960
961 let data = default_nft_data();
962 create_test_item(collection_id, &data.into());
963
964 // check balance (collection with id = 1, user id = 1)
965 assert_eq!(
966 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
967 1
968 );
969
970 // burn item
697 assert_ok!(TemplateModule::add_collection_admin(971 assert_ok!(TemplateModule::burn_item(
698 origin1.clone(),972 origin1.clone(),
699 collection_id,973 collection_id,
700 account(2)974 TokenId(1),
975 1
701 ));976 ));
977 assert_eq!(
978 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
979 0
980 );
981 });
982}
702983
984#[test]
985fn burn_same_nft_item_twice() {
986 new_test_ext().execute_with(|| {
987 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
988
989 let origin1 = Origin::signed(1);
990
703 let data = default_nft_data();991 let data = default_nft_data();
704 create_test_item(collection_id, &data.into());992 create_test_item(collection_id, &data.into());
705993
706 // check balance (collection with id = 1, user id = 1)994 // check balance (collection with id = 1, user id = 1)
707 assert_eq!(TemplateModule::balance_count(1, 1), 1);995 assert_eq!(
996 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
997 1
998 );
708999
709 // burn item1000 // burn item
710 assert_ok!(TemplateModule::burn_item(1001 assert_ok!(TemplateModule::burn_item(
711 origin1.clone(),1002 origin1.clone(),
712 collection_id,1003 collection_id,
713 1,1004 TokenId(1),
714 11005 1
715 ));1006 ));
1007
1008 // burn item again
716 assert_noop!(1009 assert_noop!(
717 TemplateModule::burn_item(origin1, collection_id, 1, 1),1010 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),
718 Error::<Test>::TokenNotFound1011 CommonError::<Test>::TokenNotFound
719 );1012 );
7201013
721 assert_eq!(TemplateModule::balance_count(1, 1), 0);1014 assert_eq!(
1015 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
1016 0
1017 );
722 });1018 });
723}1019}
7241020
725#[test]1021#[test]
726fn burn_fungible_item() {1022fn burn_fungible_item() {
727 new_test_ext().execute_with(|| {1023 new_test_ext().execute_with(|| {
728 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);1024 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
7291025
730 let origin1 = Origin::signed(1);1026 let origin1 = Origin::signed(1);
731 assert_ok!(TemplateModule::add_collection_admin(1027 assert_ok!(TemplateModule::add_collection_admin(
738 create_test_item(collection_id, &data.into());1034 create_test_item(collection_id, &data.into());
7391035
740 // check balance (collection with id = 1, user id = 1)1036 // check balance (collection with id = 1, user id = 1)
741 assert_eq!(TemplateModule::balance_count(1, 1), 5);1037 assert_eq!(
1038 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
1039 5
1040 );
7421041
743 // burn item1042 // burn item
744 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));1043 assert_ok!(TemplateModule::burn_item(
1044 origin1.clone(),
1045 CollectionId(1),
1046 TokenId(0),
1047 5
1048 ));
745 assert_noop!(1049 assert_noop!(
746 TemplateModule::burn_item(origin1, 1, 1, 5),1050 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),
747 Error::<Test>::TokenValueNotEnough1051 CommonError::<Test>::TokenValueTooLow
748 );1052 );
7491053
750 assert_eq!(TemplateModule::balance_count(1, 1), 0);1054 assert_eq!(
1055 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
1056 0
1057 );
751 });1058 });
752}1059}
7531060
754#[test]1061#[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));
1065
1066 let origin1 = Origin::signed(1);
1067 assert_ok!(TemplateModule::add_collection_admin(
1068 origin1.clone(),
1069 collection_id,
1070 account(2)
1071 ));
1072
1073 let data = default_fungible_data();
1074 create_test_item(collection_id, &data.into());
1075
1076 // check balance (collection with id = 1, user id = 1)
1077 assert_eq!(
1078 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
1079 5
1080 );
1081
1082 // Try to burn item using Token ID
1083 assert_noop!(
1084 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),
1085 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId
1086 );
1087 });
1088}
1089#[test]
755fn burn_refungible_item() {1090fn burn_refungible_item() {
756 new_test_ext().execute_with(|| {1091 new_test_ext().execute_with(|| {
757 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);1092 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
758 let origin1 = Origin::signed(1);1093 let origin1 = Origin::signed(1);
7591094
760 assert_ok!(TemplateModule::set_mint_permission(1095 assert_ok!(TemplateModule::set_mint_permission(
769 ));1104 ));
770 assert_ok!(TemplateModule::add_to_allow_list(1105 assert_ok!(TemplateModule::add_to_allow_list(
771 origin1.clone(),1106 origin1.clone(),
772 1,1107 collection_id,
773 account(1)1108 account(1)
774 ));1109 ));
7751110
776 assert_ok!(TemplateModule::add_collection_admin(1111 assert_ok!(TemplateModule::add_collection_admin(
777 origin1.clone(),1112 origin1.clone(),
778 1,1113 collection_id,
779 account(2)1114 account(2)
780 ));1115 ));
7811116
782 let data = default_re_fungible_data();1117 let data = default_re_fungible_data();
783 create_test_item(collection_id, &data.into());1118 create_test_item(collection_id, &data.into());
7841119
785 // check balance (collection with id = 1, user id = 2)1120 // check balance (collection with id = 1, user id = 2)
786 assert_eq!(TemplateModule::balance_count(1, 1), 1023);1121 assert_eq!(
1122 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
1123 1
1124 );
1125 assert_eq!(
1126 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
1127 1023
1128 );
7871129
788 // burn item1130 // burn item
789 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));1131 assert_ok!(TemplateModule::burn_item(
1132 origin1.clone(),
1133 collection_id,
1134 TokenId(1),
1135 1023
1136 ));
790 assert_noop!(1137 assert_noop!(
791 TemplateModule::burn_item(origin1, 1, 1, 1023),1138 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)
1139 .map_err(|e| e.error),
792 Error::<Test>::TokenNotFound1140 CommonError::<Test>::TokenValueTooLow
793 );1141 );
7941142
795 assert_eq!(TemplateModule::balance_count(1, 1), 0);1143 assert_eq!(
1144 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
1145 0
1146 );
796 });1147 });
797}1148}
7981149
799#[test]1150#[test]
800fn add_collection_admin() {1151fn add_collection_admin() {
801 new_test_ext().execute_with(|| {1152 new_test_ext().execute_with(|| {
802 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);1153 let collection1_id =
803 create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);1154 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
804 create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);
805
806 let origin1 = Origin::signed(1);1155 let origin1 = Origin::signed(1);
8071156
808 // collection admin1157 // Add collection admins
809 assert_ok!(TemplateModule::add_collection_admin(1158 assert_ok!(TemplateModule::add_collection_admin(
810 origin1.clone(),1159 origin1.clone(),
811 collection1_id,1160 collection1_id,
817 account(3)1166 account(3)
818 ));1167 ));
8191168
820 assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)),);1169 // Owner is not an admin by default
1170 assert_eq!(
1171 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),
1172 false
1173 );
1174 assert!(<pallet_common::IsAdmin<Test>>::get((
1175 CollectionId(1),
1176 account(2)
1177 )));
821 assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)),);1178 assert!(<pallet_common::IsAdmin<Test>>::get((
1179 CollectionId(1),
1180 account(3)
1181 )));
822 });1182 });
823}1183}
8241184
825#[test]1185#[test]
826fn remove_collection_admin() {1186fn remove_collection_admin() {
827 new_test_ext().execute_with(|| {1187 new_test_ext().execute_with(|| {
828 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);1188 let collection1_id =
829 create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);1189 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
830 create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);
831
832 let origin1 = Origin::signed(1);1190 let origin1 = Origin::signed(1);
833 let origin2 = Origin::signed(2);1191 let origin2 = Origin::signed(2);
8341192
835 // collection admin1193 // Add collection admins 2 and 3
836 assert_ok!(TemplateModule::add_collection_admin(1194 assert_ok!(TemplateModule::add_collection_admin(
837 origin1.clone(),1195 origin1.clone(),
838 collection1_id,1196 collection1_id,
844 account(3)1202 account(3)
845 ));1203 ));
8461204
847 assert!(TemplateModule::admin_list_collection(1).contains(&account(2)),);1205 assert!(<pallet_common::IsAdmin<Test>>::get((
1206 CollectionId(1),
1207 account(2)
1208 )));
848 assert!(TemplateModule::admin_list_collection(1).contains(&account(3)),);1209 assert!(<pallet_common::IsAdmin<Test>>::get((
1210 CollectionId(1),
1211 account(3)
1212 )));
8491213
850 // remove admin1214 // remove admin 3
851 assert_ok!(TemplateModule::remove_collection_admin(1215 assert_ok!(TemplateModule::remove_collection_admin(
852 origin2,1216 origin2,
853 1,1217 CollectionId(1),
854 account(3)1218 account(3)
855 ));1219 ));
1220
856 assert!(!TemplateModule::admin_list_collection(1).contains(&account(3)),);1221 // 2 is still admin, 3 is not an admin anymore
1222 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 false
1229 );
857 });1230 });
858}1231}
8591232
860#[test]1233#[test]
861fn balance_of() {1234fn balance_of() {
862 new_test_ext().execute_with(|| {1235 new_test_ext().execute_with(|| {
863 let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);1236 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
864 let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);1237 let fungible_collection_id =
1238 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));
865 let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);1239 let re_fungible_collection_id =
1240 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));
8661241
867 // check balance before1242 // check balance before
868 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);
869 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);
870 assert_eq!(1243 assert_eq!(
871 TemplateModule::balance_count(re_fungible_collection_id, 1),1244 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),
872 01245 0
873 );1246 );
1247 assert_eq!(
1248 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),
1249 0
1250 );
1251 assert_eq!(
1252 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),
1253 0
1254 );
8741255
875 let nft_data = default_nft_data();1256 let nft_data = default_nft_data();
876 create_test_item(nft_collection_id, &nft_data.into());1257 create_test_item(nft_collection_id, &nft_data.into());
882 create_test_item(re_fungible_collection_id, &re_fungible_data.into());1263 create_test_item(re_fungible_collection_id, &re_fungible_data.into());
8831264
884 // check balance (collection with id = 1, user id = 1)1265 // 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!(1266 assert_eq!(
888 TemplateModule::balance_count(re_fungible_collection_id, 1),1267 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),
889 10231268 1
890 );1269 );
891 assert_eq!(1270 assert_eq!(
892 TemplateModule::nft_item_id(nft_collection_id, 1)1271 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),
893 .unwrap()
894 .owner,
895 account(1)1272 5
896 );1273 );
897 assert_eq!(1274 assert_eq!(
898 TemplateModule::fungible_item_id(fungible_collection_id, 1).value,1275 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),
899 51276 1
900 );1277 );
1278
901 assert_eq!(1279 assert_eq!(
902 TemplateModule::refungible_item_id(re_fungible_collection_id, 1)1280 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),
903 .unwrap()
904 .owner[0]
905 .owner,
906 account(1)1281 true
907 );1282 );
1283 assert_eq!(
1284 <pallet_refungible::Owned<Test>>::get((
1285 re_fungible_collection_id,
1286 account(1),
1287 TokenId(1)
1288 )),
1289 true
1290 );
908 });1291 });
909}1292}
9101293
911#[test]1294#[test]
912fn approve() {1295fn approve() {
913 new_test_ext().execute_with(|| {1296 new_test_ext().execute_with(|| {
914 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1297 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
9151298
916 let data = default_nft_data();1299 let data = default_nft_data();
917 create_test_item(collection_id, &data.into());1300 create_test_item(collection_id, &data.into());
9181301
919 let origin1 = Origin::signed(1);1302 let origin1 = Origin::signed(1);
9201303
921 // approve1304 // approve
922 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1));1305 assert_ok!(TemplateModule::approve(
1306 origin1,
1307 account(2),
1308 CollectionId(1),
1309 TokenId(1),
1310 1
1311 ));
923 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);1312 assert_eq!(
1313 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1314 account(2)
1315 );
924 });1316 });
925}1317}
9261318
927#[test]1319#[test]
928fn transfer_from() {1320fn transfer_from() {
929 new_test_ext().execute_with(|| {1321 new_test_ext().execute_with(|| {
930 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1322 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
931 let origin1 = Origin::signed(1);1323 let origin1 = Origin::signed(1);
932 let origin2 = Origin::signed(2);1324 let origin2 = Origin::signed(2);
9331325
938 assert_ok!(TemplateModule::approve(1330 assert_ok!(TemplateModule::approve(
939 origin1.clone(),1331 origin1.clone(),
940 account(2),1332 account(2),
941 1,1333 CollectionId(1),
942 1,1334 TokenId(1),
943 11335 1
944 ));1336 ));
945 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);1337 assert_eq!(
1338 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1339 account(2)
1340 );
9461341
947 assert_ok!(TemplateModule::set_mint_permission(1342 assert_ok!(TemplateModule::set_mint_permission(
948 origin1.clone(),1343 origin1.clone(),
949 1,1344 CollectionId(1),
950 true1345 true
951 ));1346 ));
952 assert_ok!(TemplateModule::set_public_access_mode(1347 assert_ok!(TemplateModule::set_public_access_mode(
953 origin1.clone(),1348 origin1.clone(),
954 1,1349 CollectionId(1),
955 AccessMode::AllowList1350 AccessMode::AllowList
956 ));1351 ));
957 assert_ok!(TemplateModule::add_to_allow_list(1352 assert_ok!(TemplateModule::add_to_allow_list(
958 origin1.clone(),1353 origin1.clone(),
959 1,1354 CollectionId(1),
960 account(1)1355 account(1)
961 ));1356 ));
962 assert_ok!(TemplateModule::add_to_allow_list(1357 assert_ok!(TemplateModule::add_to_allow_list(
963 origin1.clone(),1358 origin1.clone(),
964 1,1359 CollectionId(1),
965 account(2)1360 account(2)
966 ));1361 ));
967 assert_ok!(TemplateModule::add_to_allow_list(origin1, 1, account(3)));1362 assert_ok!(TemplateModule::add_to_allow_list(
1363 origin1,
1364 CollectionId(1),
1365 account(3)
1366 ));
9681367
969 assert_ok!(TemplateModule::transfer_from(1368 assert_ok!(TemplateModule::transfer_from(
970 origin2,1369 origin2,
971 account(1),1370 account(1),
972 account(2),1371 account(2),
973 1,1372 CollectionId(1),
974 1,1373 TokenId(1),
975 11374 1
976 ));1375 ));
9771376
978 // after transfer1377 // after transfer
979 assert_eq!(TemplateModule::balance_count(1, 1), 0);1378 assert_eq!(
1379 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),
1380 0
1381 );
980 assert_eq!(TemplateModule::balance_count(1, 2), 1);1382 assert_eq!(
1383 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),
1384 1
1385 );
981 });1386 });
982}1387}
9831388
989#[test]1394#[test]
990fn owner_can_add_address_to_allow_list() {1395fn owner_can_add_address_to_allow_list() {
991 new_test_ext().execute_with(|| {1396 new_test_ext().execute_with(|| {
992 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1397 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
9931398
994 let origin1 = Origin::signed(1);1399 let origin1 = Origin::signed(1);
995 assert_ok!(TemplateModule::add_to_allow_list(1400 assert_ok!(TemplateModule::add_to_allow_list(
996 origin1,1401 origin1,
997 collection_id,1402 collection_id,
998 account(2)1403 account(2)
999 ));1404 ));
1000 assert!(TemplateModule::allow_list(collection_id, 2));1405 assert!(<pallet_common::Allowlist<Test>>::get((
1406 collection_id,
1407 account(2)
1408 )));
1001 });1409 });
1002}1410}
10031411
1004#[test]1412#[test]
1005fn admin_can_add_address_to_allow_list() {1413fn admin_can_add_address_to_allow_list() {
1006 new_test_ext().execute_with(|| {1414 new_test_ext().execute_with(|| {
1007 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1415 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1008 let origin1 = Origin::signed(1);1416 let origin1 = Origin::signed(1);
1009 let origin2 = Origin::signed(2);1417 let origin2 = Origin::signed(2);
10101418
1018 collection_id,1426 collection_id,
1019 account(3)1427 account(3)
1020 ));1428 ));
1021 assert!(TemplateModule::allow_list(collection_id, 3));1429 assert!(<pallet_common::Allowlist<Test>>::get((
1430 collection_id,
1431 account(3)
1432 )));
1022 });1433 });
1023}1434}
10241435
1025#[test]1436#[test]
1026fn nonprivileged_user_cannot_add_address_to_allow_list() {1437fn nonprivileged_user_cannot_add_address_to_allow_list() {
1027 new_test_ext().execute_with(|| {1438 new_test_ext().execute_with(|| {
1028 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1439 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
10291440
1030 let origin2 = Origin::signed(2);1441 let origin2 = Origin::signed(2);
1031 assert_noop!(1442 assert_noop!(
1032 TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1443 TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),
1033 Error::<Test>::NoPermission1444 CommonError::<Test>::NoPermission
1034 );1445 );
1035 });1446 });
1036}1447}
1041 let origin1 = Origin::signed(1);1452 let origin1 = Origin::signed(1);
10421453
1043 assert_noop!(1454 assert_noop!(
1044 TemplateModule::add_to_allow_list(origin1, 1, account(2)),1455 TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),
1045 Error::<Test>::CollectionNotFound1456 CommonError::<Test>::CollectionNotFound
1046 );1457 );
1047 });1458 });
1048}1459}
10491460
1050#[test]1461#[test]
1051fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1462fn nobody_can_add_address_to_allow_list_of_deleted_collection() {
1052 new_test_ext().execute_with(|| {1463 new_test_ext().execute_with(|| {
1053 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1464 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
10541465
1055 let origin1 = Origin::signed(1);1466 let origin1 = Origin::signed(1);
1056 assert_ok!(TemplateModule::destroy_collection(1467 assert_ok!(TemplateModule::destroy_collection(
1059 ));1470 ));
1060 assert_noop!(1471 assert_noop!(
1061 TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1472 TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),
1062 Error::<Test>::CollectionNotFound1473 CommonError::<Test>::CollectionNotFound
1063 );1474 );
1064 });1475 });
1065}1476}
1068#[test]1479#[test]
1069fn address_is_already_added_to_allow_list() {1480fn address_is_already_added_to_allow_list() {
1070 new_test_ext().execute_with(|| {1481 new_test_ext().execute_with(|| {
1071 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1482 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1072 let origin1 = Origin::signed(1);1483 let origin1 = Origin::signed(1);
10731484
1074 assert_ok!(TemplateModule::add_to_allow_list(1485 assert_ok!(TemplateModule::add_to_allow_list(
1081 collection_id,1492 collection_id,
1082 account(2)1493 account(2)
1083 ));1494 ));
1084 assert!(TemplateModule::allow_list(collection_id, 2));1495 assert!(<pallet_common::Allowlist<Test>>::get((
1496 collection_id,
1497 account(2)
1498 )));
1085 });1499 });
1086}1500}
10871501
1088#[test]1502#[test]
1089fn owner_can_remove_address_from_allow_list() {1503fn owner_can_remove_address_from_allow_list() {
1090 new_test_ext().execute_with(|| {1504 new_test_ext().execute_with(|| {
1091 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1505 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
10921506
1093 let origin1 = Origin::signed(1);1507 let origin1 = Origin::signed(1);
1094 assert_ok!(TemplateModule::add_to_allow_list(1508 assert_ok!(TemplateModule::add_to_allow_list(
1101 collection_id,1515 collection_id,
1102 account(2)1516 account(2)
1103 ));1517 ));
1104 assert!(!TemplateModule::allow_list(collection_id, 2));1518 assert_eq!(
1519 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
1520 false
1521 );
1105 });1522 });
1106}1523}
11071524
1108#[test]1525#[test]
1109fn admin_can_remove_address_from_allow_list() {1526fn admin_can_remove_address_from_allow_list() {
1110 new_test_ext().execute_with(|| {1527 new_test_ext().execute_with(|| {
1111 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1528 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1112 let origin1 = Origin::signed(1);1529 let origin1 = Origin::signed(1);
1113 let origin2 = Origin::signed(2);1530 let origin2 = Origin::signed(2);
11141531
1532 // Owner adds admin
1115 assert_ok!(TemplateModule::add_collection_admin(1533 assert_ok!(TemplateModule::add_collection_admin(
1116 origin1.clone(),1534 origin1.clone(),
1117 collection_id,1535 collection_id,
1118 account(2)1536 account(2)
1119 ));1537 ));
11201538
1539 // Owner adds address 3 to allow list
1121 assert_ok!(TemplateModule::add_to_allow_list(1540 assert_ok!(TemplateModule::add_to_allow_list(
1122 origin1,1541 origin1,
1123 collection_id,1542 collection_id,
1124 account(3)1543 account(3)
1125 ));1544 ));
1545
1546 // Admin removes address 3 from allow list
1126 assert_ok!(TemplateModule::remove_from_allow_list(1547 assert_ok!(TemplateModule::remove_from_allow_list(
1127 origin2,1548 origin2,
1128 collection_id,1549 collection_id,
1129 account(3)1550 account(3)
1130 ));1551 ));
1131 assert!(!TemplateModule::allow_list(collection_id, 3));1552 assert_eq!(
1553 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),
1554 false
1555 );
1132 });1556 });
1133}1557}
11341558
1135#[test]1559#[test]
1136fn nonprivileged_user_cannot_remove_address_from_allow_list() {1560fn nonprivileged_user_cannot_remove_address_from_allow_list() {
1137 new_test_ext().execute_with(|| {1561 new_test_ext().execute_with(|| {
1138 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1562 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1139 let origin1 = Origin::signed(1);1563 let origin1 = Origin::signed(1);
1140 let origin2 = Origin::signed(2);1564 let origin2 = Origin::signed(2);
11411565
1146 ));1570 ));
1147 assert_noop!(1571 assert_noop!(
1148 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1572 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
1149 Error::<Test>::NoPermission1573 CommonError::<Test>::NoPermission
1150 );1574 );
1151 assert!(TemplateModule::allow_list(collection_id, 2));1575 assert!(<pallet_common::Allowlist<Test>>::get((
1576 collection_id,
1577 account(2)
1578 )));
1152 });1579 });
1153}1580}
11541581
1158 let origin1 = Origin::signed(1);1585 let origin1 = Origin::signed(1);
11591586
1160 assert_noop!(1587 assert_noop!(
1161 TemplateModule::remove_from_allow_list(origin1, 1, account(2)),1588 TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),
1162 Error::<Test>::CollectionNotFound1589 CommonError::<Test>::CollectionNotFound
1163 );1590 );
1164 });1591 });
1165}1592}
11661593
1167#[test]1594#[test]
1168fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1595fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {
1169 new_test_ext().execute_with(|| {1596 new_test_ext().execute_with(|| {
1170 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1597 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1171 let origin1 = Origin::signed(1);1598 let origin1 = Origin::signed(1);
1172 let origin2 = Origin::signed(2);1599 let origin2 = Origin::signed(2);
11731600
1601 // Add account 2 to allow list
1174 assert_ok!(TemplateModule::add_to_allow_list(1602 assert_ok!(TemplateModule::add_to_allow_list(
1175 origin1.clone(),1603 origin1.clone(),
1176 collection_id,1604 collection_id,
1177 account(2)1605 account(2)
1178 ));1606 ));
1607
1608 // Account 2 is in collection allow-list
1609 assert!(<pallet_common::Allowlist<Test>>::get((
1610 collection_id,
1611 account(2)
1612 )));
1613
1614 // Destroy collection
1179 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1615 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
1616
1617 // Attempt to remove account 2 from collection allow-list => error
1180 assert_noop!(1618 assert_noop!(
1181 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1619 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
1182 Error::<Test>::CollectionNotFound1620 CommonError::<Test>::CollectionNotFound
1183 );1621 );
1622
1184 assert!(!TemplateModule::allow_list(collection_id, 2));1623 // Account 2 is not found in collection allow-list anyway
1624 assert_eq!(
1625 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
1626 false
1627 );
1185 });1628 });
1186}1629}
11871630
1188// If address is already removed from allow list, nothing happens1631// If address is already removed from allow list, nothing happens
1189#[test]1632#[test]
1190fn address_is_already_removed_from_allow_list() {1633fn address_is_already_removed_from_allow_list() {
1191 new_test_ext().execute_with(|| {1634 new_test_ext().execute_with(|| {
1192 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1635 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1193 let origin1 = Origin::signed(1);1636 let origin1 = Origin::signed(1);
11941637
1195 assert_ok!(TemplateModule::add_to_allow_list(1638 assert_ok!(TemplateModule::add_to_allow_list(
1202 collection_id,1645 collection_id,
1203 account(2)1646 account(2)
1204 ));1647 ));
1648 assert_eq!(
1649 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
1650 false
1651 );
1205 assert_ok!(TemplateModule::remove_from_allow_list(1652 assert_ok!(TemplateModule::remove_from_allow_list(
1206 origin1,1653 origin1,
1207 collection_id,1654 collection_id,
1208 account(2)1655 account(2)
1209 ));1656 ));
1210 assert!(!TemplateModule::allow_list(collection_id, 2));1657 assert_eq!(
1658 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
1659 false
1660 );
1211 });1661 });
1212}1662}
12131663
1214// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1664// 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]1665#[test]
1216fn allow_list_test_1() {1666fn allow_list_test_1() {
1217 new_test_ext().execute_with(|| {1667 new_test_ext().execute_with(|| {
1218 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1668 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
12191669
1220 let origin1 = Origin::signed(1);1670 let origin1 = Origin::signed(1);
12211671
1234 ));1684 ));
12351685
1236 assert_noop!(1686 assert_noop!(
1237 TemplateModule::transfer(origin1, account(3), 1, 1, 1),1687 TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)
1688 .map_err(|e| e.error),
1238 Error::<Test>::AddresNotInAllowList1689 CommonError::<Test>::AddressNotInAllowlist
1239 );1690 );
1240 });1691 });
1241}1692}
12421693
1243#[test]1694#[test]
1244fn allow_list_test_2() {1695fn allow_list_test_2() {
1245 new_test_ext().execute_with(|| {1696 new_test_ext().execute_with(|| {
1246 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1697 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1247 let origin1 = Origin::signed(1);1698 let origin1 = Origin::signed(1);
12481699
1249 let data = default_nft_data();1700 let data = default_nft_data();
1256 ));1707 ));
1257 assert_ok!(TemplateModule::add_to_allow_list(1708 assert_ok!(TemplateModule::add_to_allow_list(
1258 origin1.clone(),1709 origin1.clone(),
1259 1,1710 collection_id,
1260 account(1)1711 account(1)
1261 ));1712 ));
1262 assert_ok!(TemplateModule::add_to_allow_list(1713 assert_ok!(TemplateModule::add_to_allow_list(
1263 origin1.clone(),1714 origin1.clone(),
1264 1,1715 collection_id,
1265 account(2)1716 account(2)
1266 ));1717 ));
12671718
1268 // do approve1719 // do approve
1269 assert_ok!(TemplateModule::approve(1720 assert_ok!(TemplateModule::approve(
1270 origin1.clone(),1721 origin1.clone(),
1271 account(1),1722 account(1),
1272 1,1723 collection_id,
1273 1,1724 TokenId(1),
1274 11725 1
1275 ));1726 ));
1276 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);1727 assert_eq!(
1728 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1729 account(1)
1730 );
12771731
1278 assert_ok!(TemplateModule::remove_from_allow_list(1732 assert_ok!(TemplateModule::remove_from_allow_list(
1279 origin1.clone(),1733 origin1.clone(),
1280 1,1734 collection_id,
1281 account(1)1735 account(1)
1282 ));1736 ));
12831737
1284 assert_noop!(1738 assert_noop!(
1285 TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1739 TemplateModule::transfer_from(
1740 origin1,
1741 account(1),
1742 account(3),
1743 CollectionId(1),
1744 TokenId(1),
1745 1
1746 )
1747 .map_err(|e| e.error),
1286 Error::<Test>::AddresNotInAllowList1748 CommonError::<Test>::AddressNotInAllowlist
1287 );1749 );
1288 });1750 });
1289}1751}
1292#[test]1754#[test]
1293fn allow_list_test_3() {1755fn allow_list_test_3() {
1294 new_test_ext().execute_with(|| {1756 new_test_ext().execute_with(|| {
1295 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1757 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
12961758
1297 let origin1 = Origin::signed(1);1759 let origin1 = Origin::signed(1);
12981760
1306 ));1768 ));
1307 assert_ok!(TemplateModule::add_to_allow_list(1769 assert_ok!(TemplateModule::add_to_allow_list(
1308 origin1.clone(),1770 origin1.clone(),
1309 1,1771 collection_id,
1310 account(1)1772 account(1)
1311 ));1773 ));
13121774
1313 assert_noop!(1775 assert_noop!(
1314 TemplateModule::transfer(origin1, account(3), 1, 1, 1),1776 TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)
1777 .map_err(|e| e.error),
1315 Error::<Test>::AddresNotInAllowList1778 CommonError::<Test>::AddressNotInAllowlist
1316 );1779 );
1317 });1780 });
1318}1781}
13191782
1320#[test]1783#[test]
1321fn allow_list_test_4() {1784fn allow_list_test_4() {
1322 new_test_ext().execute_with(|| {1785 new_test_ext().execute_with(|| {
1323 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1786 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
13241787
1325 let origin1 = Origin::signed(1);1788 let origin1 = Origin::signed(1);
13261789
1347 assert_ok!(TemplateModule::approve(1810 assert_ok!(TemplateModule::approve(
1348 origin1.clone(),1811 origin1.clone(),
1349 account(1),1812 account(1),
1350 1,1813 collection_id,
1351 1,1814 TokenId(1),
1352 11815 1
1353 ));1816 ));
1354 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);1817 assert_eq!(
1818 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1819 account(1)
1820 );
13551821
1356 assert_ok!(TemplateModule::remove_from_allow_list(1822 assert_ok!(TemplateModule::remove_from_allow_list(
1357 origin1.clone(),1823 origin1.clone(),
1360 ));1826 ));
13611827
1362 assert_noop!(1828 assert_noop!(
1363 TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1829 TemplateModule::transfer_from(
1830 origin1,
1831 account(1),
1832 account(3),
1833 collection_id,
1834 TokenId(1),
1835 1
1836 )
1837 .map_err(|e| e.error),
1364 Error::<Test>::AddresNotInAllowList1838 CommonError::<Test>::AddressNotInAllowlist
1365 );1839 );
1366 });1840 });
1367}1841}
1370#[test]1844#[test]
1371fn allow_list_test_5() {1845fn allow_list_test_5() {
1372 new_test_ext().execute_with(|| {1846 new_test_ext().execute_with(|| {
1373 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1847 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
13741848
1375 let origin1 = Origin::signed(1);1849 let origin1 = Origin::signed(1);
13761850
1383 AccessMode::AllowList1857 AccessMode::AllowList
1384 ));1858 ));
1385 assert_noop!(1859 assert_noop!(
1386 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1860 TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)
1861 .map_err(|e| e.error),
1387 Error::<Test>::AddresNotInAllowList1862 CommonError::<Test>::AddressNotInAllowlist
1388 );1863 );
1389 });1864 });
1390}1865}
1393#[test]1868#[test]
1394fn allow_list_test_6() {1869fn allow_list_test_6() {
1395 new_test_ext().execute_with(|| {1870 new_test_ext().execute_with(|| {
1396 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1871 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
13971872
1398 let origin1 = Origin::signed(1);1873 let origin1 = Origin::signed(1);
13991874
14081883
1409 // do approve1884 // do approve
1410 assert_noop!(1885 assert_noop!(
1411 TemplateModule::approve(origin1, account(1), 1, 1, 5),1886 TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)
1887 .map_err(|e| e.error),
1412 Error::<Test>::AddresNotInAllowList1888 CommonError::<Test>::AddressNotInAllowlist
1413 );1889 );
1414 });1890 });
1415}1891}
1419#[test]1895#[test]
1420fn allow_list_test_7() {1896fn allow_list_test_7() {
1421 new_test_ext().execute_with(|| {1897 new_test_ext().execute_with(|| {
1422 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1898 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
14231899
1424 let data = default_nft_data();1900 let data = default_nft_data();
1425 create_test_item(collection_id, &data.into());1901 create_test_item(collection_id, &data.into());
1442 account(2)1918 account(2)
1443 ));1919 ));
14441920
1445 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1));1921 assert_ok!(TemplateModule::transfer(
1922 origin1,
1923 account(2),
1924 CollectionId(1),
1925 TokenId(1),
1926 1
1927 ));
1446 });1928 });
1447}1929}
14481930
1449#[test]1931#[test]
1450fn allow_list_test_8() {1932fn allow_list_test_8() {
1451 new_test_ext().execute_with(|| {1933 new_test_ext().execute_with(|| {
1452 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1934 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
14531935
1936 // Create NFT for account 1
1454 let data = default_nft_data();1937 let data = default_nft_data();
1455 create_test_item(collection_id, &data.into());1938 create_test_item(collection_id, &data.into());
14561939
1457 let origin1 = Origin::signed(1);1940 let origin1 = Origin::signed(1);
14581941
1942 // Toggle Allow List mode and add accounts 1 and 2
1459 assert_ok!(TemplateModule::set_public_access_mode(1943 assert_ok!(TemplateModule::set_public_access_mode(
1460 origin1.clone(),1944 origin1.clone(),
1461 collection_id,1945 collection_id,
1472 account(2)1956 account(2)
1473 ));1957 ));
14741958
1475 // do approve1959 // Sself-approve account 1 for NFT 1
1476 assert_ok!(TemplateModule::approve(1960 assert_ok!(TemplateModule::approve(
1477 origin1.clone(),1961 origin1.clone(),
1478 account(1),1962 account(1),
1479 1,1963 CollectionId(1),
1480 1,1964 TokenId(1),
1481 51965 1
1482 ));1966 ));
1483 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);1967 assert_eq!(
1968 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1969 account(1)
1970 );
14841971
1972 // Transfer from 1 to 2
1485 assert_ok!(TemplateModule::transfer_from(1973 assert_ok!(TemplateModule::transfer_from(
1486 origin1,1974 origin1,
1487 account(1),1975 account(1),
1488 account(2),1976 account(2),
1489 1,1977 CollectionId(1),
1490 1,1978 TokenId(1),
1491 11979 1
1492 ));1980 ));
1493 });1981 });
1497#[test]1985#[test]
1498fn allow_list_test_9() {1986fn allow_list_test_9() {
1499 new_test_ext().execute_with(|| {1987 new_test_ext().execute_with(|| {
1500 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1988 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1501 let origin1 = Origin::signed(1);1989 let origin1 = Origin::signed(1);
15021990
1503 assert_ok!(TemplateModule::set_public_access_mode(1991 assert_ok!(TemplateModule::set_public_access_mode(
1520#[test]2008#[test]
1521fn allow_list_test_10() {2009fn allow_list_test_10() {
1522 new_test_ext().execute_with(|| {2010 new_test_ext().execute_with(|| {
1523 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2011 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
15242012
1525 let origin1 = Origin::signed(1);2013 let origin1 = Origin::signed(1);
1526 let origin2 = Origin::signed(2);2014 let origin2 = Origin::signed(2);
1555#[test]2043#[test]
1556fn allow_list_test_11() {2044fn allow_list_test_11() {
1557 new_test_ext().execute_with(|| {2045 new_test_ext().execute_with(|| {
1558 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2046 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
15592047
1560 let origin1 = Origin::signed(1);2048 let origin1 = Origin::signed(1);
1561 let origin2 = Origin::signed(2);2049 let origin2 = Origin::signed(2);
1577 ));2065 ));
15782066
1579 assert_noop!(2067 assert_noop!(
1580 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),2068 TemplateModule::create_item(
2069 origin2,
2070 CollectionId(1),
2071 account(2),
2072 default_nft_data().into()
2073 )
2074 .map_err(|e| e.error),
1581 Error::<Test>::PublicMintingNotAllowed2075 CommonError::<Test>::PublicMintingNotAllowed
1582 );2076 );
1583 });2077 });
1584}2078}
1587#[test]2081#[test]
1588fn allow_list_test_12() {2082fn allow_list_test_12() {
1589 new_test_ext().execute_with(|| {2083 new_test_ext().execute_with(|| {
1590 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2084 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
15912085
1592 let origin1 = Origin::signed(1);2086 let origin1 = Origin::signed(1);
1593 let origin2 = Origin::signed(2);2087 let origin2 = Origin::signed(2);
1604 ));2098 ));
16052099
1606 assert_noop!(2100 assert_noop!(
1607 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),2101 TemplateModule::create_item(
2102 origin2,
2103 CollectionId(1),
2104 account(2),
2105 default_nft_data().into()
2106 )
2107 .map_err(|e| e.error),
1608 Error::<Test>::PublicMintingNotAllowed2108 CommonError::<Test>::PublicMintingNotAllowed
1609 );2109 );
1610 });2110 });
1611}2111}
1614#[test]2114#[test]
1615fn allow_list_test_13() {2115fn allow_list_test_13() {
1616 new_test_ext().execute_with(|| {2116 new_test_ext().execute_with(|| {
1617 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2117 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
16182118
1619 let origin1 = Origin::signed(1);2119 let origin1 = Origin::signed(1);
16202120
1638#[test]2138#[test]
1639fn allow_list_test_14() {2139fn allow_list_test_14() {
1640 new_test_ext().execute_with(|| {2140 new_test_ext().execute_with(|| {
1641 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2141 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
16422142
1643 let origin1 = Origin::signed(1);2143 let origin1 = Origin::signed(1);
1644 let origin2 = Origin::signed(2);2144 let origin2 = Origin::signed(2);
16622162
1663 assert_ok!(TemplateModule::create_item(2163 assert_ok!(TemplateModule::create_item(
1664 origin2,2164 origin2,
1665 1,2165 collection_id,
1666 account(2),2166 account(2),
1667 default_nft_data().into()2167 default_nft_data().into()
1668 ));2168 ));
1673#[test]2173#[test]
1674fn allow_list_test_15() {2174fn allow_list_test_15() {
1675 new_test_ext().execute_with(|| {2175 new_test_ext().execute_with(|| {
1676 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2176 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
16772177
1678 let origin1 = Origin::signed(1);2178 let origin1 = Origin::signed(1);
1679 let origin2 = Origin::signed(2);2179 let origin2 = Origin::signed(2);
1690 ));2190 ));
16912191
1692 assert_noop!(2192 assert_noop!(
1693 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),2193 TemplateModule::create_item(
2194 origin2,
2195 collection_id,
2196 account(2),
2197 default_nft_data().into()
2198 )
2199 .map_err(|e| e.error),
1694 Error::<Test>::AddresNotInAllowList2200 CommonError::<Test>::AddressNotInAllowlist
1695 );2201 );
1696 });2202 });
1697}2203}
1700#[test]2206#[test]
1701fn allow_list_test_16() {2207fn allow_list_test_16() {
1702 new_test_ext().execute_with(|| {2208 new_test_ext().execute_with(|| {
1703 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2209 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
17042210
1705 let origin1 = Origin::signed(1);2211 let origin1 = Origin::signed(1);
1706 let origin2 = Origin::signed(2);2212 let origin2 = Origin::signed(2);
17232229
1724 assert_ok!(TemplateModule::create_item(2230 assert_ok!(TemplateModule::create_item(
1725 origin2,2231 origin2,
1726 1,2232 collection_id,
1727 account(2),2233 account(2),
1728 default_nft_data().into()2234 default_nft_data().into()
1729 ));2235 ));
1734#[test]2240#[test]
1735fn total_number_collections_bound() {2241fn total_number_collections_bound() {
1736 new_test_ext().execute_with(|| {2242 new_test_ext().execute_with(|| {
1737 create_test_collection(&CollectionMode::NFT, 1);2243 create_test_collection(&CollectionMode::NFT, CollectionId(1));
1738 });2244 });
1739}2245}
17402246
1741// Total number of collections. Negotive test
1742#[test]2247#[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}
2255
2256// Total number of collections. Negative test
2257#[test]
1743fn total_number_collections_bound_neg() {2258fn total_number_collections_bound_neg() {
1744 new_test_ext().execute_with(|| {2259 new_test_ext().execute_with(|| {
1745 let origin1 = Origin::signed(1);2260 let origin1 = Origin::signed(1);
17462261
1747 for i in 0..COLLECTION_NUMBER_LIMIT {2262 for i in 1..=COLLECTION_NUMBER_LIMIT {
1748 create_test_collection(&CollectionMode::NFT, i + 1);2263 create_test_collection(&CollectionMode::NFT, CollectionId(i));
1749 }2264 }
17502265
1751 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2266 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
1761 token_prefix1,2276 token_prefix1,
1762 CollectionMode::NFT2277 CollectionMode::NFT
1763 ),2278 ),
1764 Error::<Test>::TotalCollectionsLimitExceeded2279 CommonError::<Test>::TotalCollectionsLimitExceeded
1765 );2280 );
1766 });2281 });
1767}2282}
1770#[test]2285#[test]
1771fn owned_tokens_bound() {2286fn owned_tokens_bound() {
1772 new_test_ext().execute_with(|| {2287 new_test_ext().execute_with(|| {
1773 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2288 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
17742289
1775 let data = default_nft_data();2290 let data = default_nft_data();
1776 create_test_item(collection_id, &data.clone().into());2291 create_test_item(collection_id, &data.clone().into());
1782#[test]2297#[test]
1783fn owned_tokens_bound_neg() {2298fn owned_tokens_bound_neg() {
1784 new_test_ext().execute_with(|| {2299 new_test_ext().execute_with(|| {
1785 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2300 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
17862301
1787 let origin1 = Origin::signed(1);2302 let origin1 = Origin::signed(1);
17882303
1789 for _ in 0..ACCOUNT_TOKEN_OWNERSHIP_LIMIT {2304 for _ in 1..=MAX_TOKEN_OWNERSHIP {
1790 let data = default_nft_data();2305 let data = default_nft_data();
1791 create_test_item(collection_id, &data.clone().into());2306 create_test_item(collection_id, &data.clone().into());
1792 }2307 }
17932308
1794 let data = default_nft_data();2309 let data = default_nft_data();
1795 assert_noop!(2310 assert_noop!(
1796 TemplateModule::create_item(origin1, 1, account(1), data.into()),2311 TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())
2312 .map_err(|e| e.error),
1797 Error::<Test>::AccountTokenLimitExceeded2313 CommonError::<Test>::AccountTokenLimitExceeded
1798 );2314 );
1799 });2315 });
1800}2316}
1803#[test]2319#[test]
1804fn collection_admins_bound() {2320fn collection_admins_bound() {
1805 new_test_ext().execute_with(|| {2321 new_test_ext().execute_with(|| {
1806 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2322 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
18072323
1808 let origin1 = Origin::signed(1);2324 let origin1 = Origin::signed(1);
18092325
1824#[test]2340#[test]
1825fn collection_admins_bound_neg() {2341fn collection_admins_bound_neg() {
1826 new_test_ext().execute_with(|| {2342 new_test_ext().execute_with(|| {
1827 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2343 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
18282344
1829 let origin1 = Origin::signed(1);2345 let origin1 = Origin::signed(1);
18302346
1831 for i in 0..COLLECTION_ADMINS_LIMIT {2347 for i in 0..COLLECTION_ADMINS_LIMIT {
1832 assert_ok!(TemplateModule::add_collection_admin(2348 assert_ok!(TemplateModule::add_collection_admin(
1833 origin1.clone(),2349 origin1.clone(),
1834 collection_id,2350 collection_id,
1835 account(2 + i)2351 account((2 + i).into())
1836 ));2352 ));
1837 }2353 }
1838 assert_noop!(2354 assert_noop!(
1839 TemplateModule::add_collection_admin(2355 TemplateModule::add_collection_admin(
1840 origin1,2356 origin1,
1841 collection_id,2357 collection_id,
1842 account(3 + COLLECTION_ADMINS_LIMIT)2358 account((3 + COLLECTION_ADMINS_LIMIT).into())
1843 ),2359 ),
1844 Error::<Test>::CollectionAdminsLimitExceeded2360 CommonError::<Test>::CollectionAdminCountExceeded
1845 );2361 );
1846 });2362 });
1847}2363}
1850#[test]2366#[test]
1851fn set_const_on_chain_schema() {2367fn set_const_on_chain_schema() {
1852 new_test_ext().execute_with(|| {2368 new_test_ext().execute_with(|| {
1853 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2369 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
18542370
1855 let origin1 = Origin::signed(1);2371 let origin1 = Origin::signed(1);
1856 assert_ok!(TemplateModule::set_const_on_chain_schema(2372 assert_ok!(TemplateModule::set_const_on_chain_schema(
1860 ));2376 ));
18612377
1862 assert_eq!(2378 assert_eq!(
1863 TemplateModule::collection_id(collection_id)2379 <pallet_common::CollectionById<Test>>::get(collection_id)
1864 .unwrap()2380 .unwrap()
1865 .const_on_chain_schema,2381 .const_on_chain_schema,
1866 b"test const on chain schema".to_vec()2382 b"test const on chain schema".to_vec()
1867 );2383 );
1868 assert_eq!(2384 assert_eq!(
1869 TemplateModule::collection_id(collection_id)2385 <pallet_common::CollectionById<Test>>::get(collection_id)
1870 .unwrap()2386 .unwrap()
1871 .variable_on_chain_schema,2387 .variable_on_chain_schema,
1872 b"".to_vec()2388 b"".to_vec()
1877#[test]2393#[test]
1878fn set_variable_on_chain_schema() {2394fn set_variable_on_chain_schema() {
1879 new_test_ext().execute_with(|| {2395 new_test_ext().execute_with(|| {
1880 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2396 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
18812397
1882 let origin1 = Origin::signed(1);2398 let origin1 = Origin::signed(1);
1883 assert_ok!(TemplateModule::set_variable_on_chain_schema(2399 assert_ok!(TemplateModule::set_variable_on_chain_schema(
1887 ));2403 ));
18882404
1889 assert_eq!(2405 assert_eq!(
1890 TemplateModule::collection_id(collection_id)2406 <pallet_common::CollectionById<Test>>::get(collection_id)
1891 .unwrap()2407 .unwrap()
1892 .const_on_chain_schema,2408 .const_on_chain_schema,
1893 b"".to_vec()2409 b"".to_vec()
1894 );2410 );
1895 assert_eq!(2411 assert_eq!(
1896 TemplateModule::collection_id(collection_id)2412 <pallet_common::CollectionById<Test>>::get(collection_id)
1897 .unwrap()2413 .unwrap()
1898 .variable_on_chain_schema,2414 .variable_on_chain_schema,
1899 b"test variable on chain schema".to_vec()2415 b"test variable on chain schema".to_vec()
1904#[test]2420#[test]
1905fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2421fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {
1906 new_test_ext().execute_with(|| {2422 new_test_ext().execute_with(|| {
1907 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2423 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
19082424
1909 let origin1 = Origin::signed(1);2425 let origin1 = Origin::signed(1);
19102426
1911 let data = default_nft_data();2427 let data = default_nft_data();
1912 create_test_item(1, &data.into());2428 create_test_item(CollectionId(1), &data.into());
19132429
1914 let variable_data = b"test data".to_vec();2430 let variable_data = b"test data".to_vec();
1915 assert_ok!(TemplateModule::set_variable_meta_data(2431 assert_ok!(TemplateModule::set_variable_meta_data(
1916 origin1,2432 origin1,
1917 collection_id,2433 collection_id,
1918 1,2434 TokenId(1),
1919 variable_data.clone()2435 variable_data.clone()
1920 ));2436 ));
19212437
1922 assert_eq!(2438 assert_eq!(
1923 TemplateModule::nft_item_id(collection_id, 1)2439 <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))
1924 .unwrap()2440 .unwrap()
1925 .variable_data,2441 .variable_data,
1926 variable_data2442 variable_data
1931#[test]2447#[test]
1932fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2448fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {
1933 new_test_ext().execute_with(|| {2449 new_test_ext().execute_with(|| {
1934 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);2450 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
19352451
1936 let origin1 = Origin::signed(1);2452 let origin1 = Origin::signed(1);
19372453
1938 let data = default_re_fungible_data();2454 let data = default_re_fungible_data();
1939 create_test_item(1, &data.into());2455 create_test_item(collection_id, &data.into());
19402456
1941 let variable_data = b"test data".to_vec();2457 let variable_data = b"test data".to_vec();
1942 assert_ok!(TemplateModule::set_variable_meta_data(2458 assert_ok!(TemplateModule::set_variable_meta_data(
1943 origin1,2459 origin1,
1944 collection_id,2460 collection_id,
1945 1,2461 TokenId(1),
1946 variable_data.clone()2462 variable_data.clone()
1947 ));2463 ));
19482464
1949 assert_eq!(2465 assert_eq!(
1950 TemplateModule::refungible_item_id(collection_id, 1)2466 <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,
1951 .unwrap()
1952 .variable_data,
1953 variable_data2467 variable_data
1954 );2468 );
1955 });2469 });
1958#[test]2472#[test]
1959fn set_variable_meta_data_on_fungible_token_fails() {2473fn set_variable_meta_data_on_fungible_token_fails() {
1960 new_test_ext().execute_with(|| {2474 new_test_ext().execute_with(|| {
1961 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);2475 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
19622476
1963 let origin1 = Origin::signed(1);2477 let origin1 = Origin::signed(1);
19642478
1965 let data = default_fungible_data();2479 let data = default_fungible_data();
1966 create_test_item(1, &data.into());2480 create_test_item(collection_id, &data.into());
19672481
1968 let variable_data = b"test data".to_vec();2482 let variable_data = b"test data".to_vec();
1969 assert_noop!(2483 assert_noop!(
1970 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),2484 TemplateModule::set_variable_meta_data(
2485 origin1,
2486 collection_id,
2487 TokenId(0),
2488 variable_data
2489 )
2490 .map_err(|e| e.error),
1971 Error::<Test>::CantStoreMetadataInFungibleTokens2491 <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData
1972 );2492 );
1973 });2493 });
1974}2494}
19752495
1976#[test]2496#[test]
1977fn set_variable_meta_data_on_nft_token_fails_for_big_data() {2497fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
1978 new_test_ext().execute_with(|| {2498 new_test_ext().execute_with(|| {
1979 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2499 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
19802500
1981 let origin1 = Origin::signed(1);2501 let origin1 = Origin::signed(1);
19822502
1983 let data = default_nft_data();2503 let data = default_nft_data();
1984 create_test_item(1, &data.into());2504 create_test_item(collection_id, &data.into());
19852505
1986 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2506 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
1987 assert_noop!(2507 assert_noop!(
1988 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),2508 TemplateModule::set_variable_meta_data(
2509 origin1,
2510 collection_id,
2511 TokenId(1),
2512 variable_data
2513 )
2514 .map_err(|e| e.error),
1989 Error::<Test>::TokenVariableDataLimitExceeded2515 CommonError::<Test>::TokenVariableDataLimitExceeded
1990 );2516 );
1991 });2517 });
1992}2518}
19932519
1994#[test]2520#[test]
1995fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {2521fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {
1996 new_test_ext().execute_with(|| {2522 new_test_ext().execute_with(|| {
1997 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);2523 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
19982524
1999 let origin1 = Origin::signed(1);2525 let origin1 = Origin::signed(1);
20002526
2001 let data = default_re_fungible_data();2527 let data = default_re_fungible_data();
2002 create_test_item(1, &data.into());2528 create_test_item(collection_id, &data.into());
20032529
2004 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2530 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
2005 assert_noop!(2531 assert_noop!(
2006 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),2532 TemplateModule::set_variable_meta_data(
2533 origin1,
2534 collection_id,
2535 TokenId(1),
2536 variable_data
2537 )
2538 .map_err(|e| e.error),
2007 Error::<Test>::TokenVariableDataLimitExceeded2539 CommonError::<Test>::TokenVariableDataLimitExceeded
2008 );2540 );
2009 });2541 });
2010}2542}
2014 new_test_ext().execute_with(|| {2546 new_test_ext().execute_with(|| {
2015 //default_limits();2547 //default_limits();
20162548
2017 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2549 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
20182550
2019 let origin1 = Origin::signed(1);2551 let origin1 = Origin::signed(1);
20202552
2021 let data = default_nft_data();2553 let data = default_nft_data();
2022 create_test_item(1, &data.into());2554 create_test_item(collection_id, &data.into());
20232555
2024 assert_ok!(TemplateModule::set_meta_update_permission_flag(2556 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2025 origin1.clone(),2557 origin1.clone(),
2031 assert_ok!(TemplateModule::set_variable_meta_data(2563 assert_ok!(TemplateModule::set_variable_meta_data(
2032 origin1,2564 origin1,
2033 collection_id,2565 collection_id,
2034 1,2566 TokenId(1),
2035 variable_data.clone()2567 variable_data.clone()
2036 ));2568 ));
20372569
2038 assert_eq!(2570 assert_eq!(
2039 TemplateModule::nft_item_id(collection_id, 1)2571 <pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))
2040 .unwrap()2572 .unwrap()
2041 .variable_data,2573 .variable_data,
2042 variable_data2574 variable_data
2047#[test]2579#[test]
2048fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {2580fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {
2049 new_test_ext().execute_with(|| {2581 new_test_ext().execute_with(|| {
2050 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);2582 let collection_id =
2583 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
20512584
2052 let origin1 = Origin::signed(1);2585 let origin1 = Origin::signed(1);
20532586
2063 ));2596 ));
20642597
2065 let data = default_nft_data();2598 let data = default_nft_data();
2066 create_test_item(1, &data.into());2599 create_test_item(collection_id, &data.into());
20672600
2068 assert_ok!(TemplateModule::set_meta_update_permission_flag(2601 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2069 origin1.clone(),2602 origin1.clone(),
2076 TemplateModule::set_variable_meta_data(2609 TemplateModule::set_variable_meta_data(
2077 origin1,2610 origin1,
2078 collection_id,2611 collection_id,
2079 1,2612 TokenId(1),
2080 variable_data.clone()2613 variable_data.clone()
2081 ),2614 )
2615 .map_err(|e| e.error),
2082 Error::<Test>::TokenVariableDataLimitExceeded2616 CommonError::<Test>::TokenVariableDataLimitExceeded
2083 );2617 );
2084 })2618 })
2085}2619}
2089 new_test_ext().execute_with(|| {2623 new_test_ext().execute_with(|| {
2090 let origin1 = Origin::signed(1);2624 let origin1 = Origin::signed(1);
20912625
2092 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2626 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
2093 assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));2627 assert_ok!(TemplateModule::set_transfers_enabled_flag(
2628 origin1,
2629 collection_id,
2630 true
2631 ));
20942632
2095 let data = default_nft_data();2633 let data = default_nft_data();
2096 create_test_item(collection_id, &data.into());2634 create_test_item(collection_id, &data.into());
2097 assert_eq!(TemplateModule::balance_count(1, 1), 1);2635 assert_eq!(
2636 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
2637 1
2638 );
2098 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2639 assert_eq!(
2640 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
2641 true
2642 );
20992643
2100 let origin1 = Origin::signed(1);2644 let origin1 = Origin::signed(1);
21012645
2102 // default scenario2646 // default scenario
2103 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));2647 assert_ok!(TemplateModule::transfer(
2648 origin1,
2649 account(2),
2650 collection_id,
2651 TokenId(1),
2652 1
2653 ));
2104 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));2654 assert_eq!(
2655 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
2656 false
2657 );
2105 assert_eq!(TemplateModule::balance_count(1, 1), 0);2658 assert_eq!(
2659 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
2660 true
2661 );
2106 assert_eq!(TemplateModule::balance_count(1, 2), 1);2662 assert_eq!(
21072663 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
2664 0
2665 );
2108 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);2666 assert_eq!(
2667 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
2668 1
2669 );
2109 });2670 });
2110}2671}
21112672
2114 new_test_ext().execute_with(|| {2675 new_test_ext().execute_with(|| {
2115 // default_limits();2676 // default_limits();
21162677
2117 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2678 let collection_id =
2679 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
21182680
2119 let origin1 = Origin::signed(1);2681 let origin1 = Origin::signed(1);
2120 let origin2 = Origin::signed(2);2682 let origin2 = Origin::signed(2);
2137 ));2699 ));
21382700
2139 let data = default_nft_data();2701 let data = default_nft_data();
2140 create_test_item(1, &data.into());2702 create_test_item(collection_id, &data.into());
21412703
2142 assert_ok!(TemplateModule::set_meta_update_permission_flag(2704 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2143 origin2.clone(),2705 origin2.clone(),
2149 assert_ok!(TemplateModule::set_variable_meta_data(2711 assert_ok!(TemplateModule::set_variable_meta_data(
2150 origin1,2712 origin1,
2151 collection_id,2713 collection_id,
2152 1,2714 TokenId(1),
2153 variable_data.clone()2715 variable_data.clone()
2154 ));2716 ));
21552717
2156 assert_eq!(2718 assert_eq!(
2157 TemplateModule::nft_item_id(collection_id, 1)2719 <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))
2158 .unwrap()2720 .unwrap()
2159 .variable_data,2721 .variable_data,
2160 variable_data2722 variable_data
2167 new_test_ext().execute_with(|| {2729 new_test_ext().execute_with(|| {
2168 // default_limits();2730 // default_limits();
21692731
2170 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2732 let collection_id =
2733 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
21712734
2172 let origin1 = Origin::signed(1);2735 let origin1 = Origin::signed(1);
2173 let origin2 = Origin::signed(2);2736 let origin2 = Origin::signed(2);
2184 ));2747 ));
21852748
2186 let data = default_nft_data();2749 let data = default_nft_data();
2187 create_test_item(1, &data.into());2750 create_test_item(collection_id, &data.into());
21882751
2189 assert_ok!(TemplateModule::set_meta_update_permission_flag(2752 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2190 origin2.clone(),2753 origin2.clone(),
2197 TemplateModule::set_variable_meta_data(2760 TemplateModule::set_variable_meta_data(
2198 origin1,2761 origin1,
2199 collection_id,2762 collection_id,
2200 1,2763 TokenId(1),
2201 variable_data.clone()2764 variable_data.clone()
2202 ),2765 )
2766 .map_err(|e| e.error),
2203 Error::<Test>::NoPermission2767 CommonError::<Test>::NoPermission
2204 );2768 );
2205 });2769 });
2206}2770}
2210 new_test_ext().execute_with(|| {2774 new_test_ext().execute_with(|| {
2211 // default_limits();2775 // default_limits();
22122776
2213 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2777 let collection_id =
2778 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
22142779
2215 let origin2 = Origin::signed(2);2780 let origin2 = Origin::signed(2);
22162781
2225 collection_id,2790 collection_id,
2226 MetaUpdatePermission::Admin2791 MetaUpdatePermission::Admin
2227 ),2792 ),
2228 Error::<Test>::MetadataFlagFrozen2793 CommonError::<Test>::MetadataFlagFrozen
2229 );2794 );
2230 });2795 });
2231}2796}
2235 new_test_ext().execute_with(|| {2800 new_test_ext().execute_with(|| {
2236 // default_limits();2801 // default_limits();
22372802
2238 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);2803 let collection_id =
2804 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
2239 let origin1 = Origin::signed(1);2805 let origin1 = Origin::signed(1);
22402806
2241 let data = default_nft_data();2807 let data = default_nft_data();
2242 create_test_item(1, &data.into());2808 create_test_item(collection_id, &data.into());
22432809
2244 assert_ok!(TemplateModule::set_meta_update_permission_flag(2810 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2245 origin1.clone(),2811 origin1.clone(),
2252 TemplateModule::set_variable_meta_data(2818 TemplateModule::set_variable_meta_data(
2253 origin1.clone(),2819 origin1.clone(),
2254 collection_id,2820 collection_id,
2255 1,2821 TokenId(1),
2256 variable_data.clone()2822 variable_data.clone()
2257 ),2823 )
2824 .map_err(|e| e.error),
2258 Error::<Test>::MetadataUpdateDenied2825 CommonError::<Test>::NoPermission
2259 );2826 );
2260 });2827 });
2261}2828}
2265 new_test_ext().execute_with(|| {2832 new_test_ext().execute_with(|| {
2266 let origin1 = Origin::signed(1);2833 let origin1 = Origin::signed(1);
22672834
2268 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2835 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
2269 assert_ok!(TemplateModule::set_transfers_enabled_flag(2836 assert_ok!(TemplateModule::set_transfers_enabled_flag(
2270 origin1, 1, false2837 origin1,
2838 collection_id,
2839 false
2271 ));2840 ));
22722841
2273 let data = default_nft_data();2842 let data = default_nft_data();
2274 create_test_item(collection_id, &data.into());2843 create_test_item(collection_id, &data.into());
2275 assert_eq!(TemplateModule::balance_count(1, 1), 1);2844 assert_eq!(
2845 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
2846 1
2847 );
2276 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2848 assert_eq!(
2849 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
2850 true
2851 );
22772852
2278 let origin1 = Origin::signed(1);2853 let origin1 = Origin::signed(1);
22792854
2280 // default scenario2855 // default scenario
2281 assert_noop!(2856 assert_noop!(
2282 TemplateModule::transfer(origin1, account(2), 1, 1, 1000),2857 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)
2858 .map_err(|e| e.error),
2283 Error::<Test>::TransferNotAllowed2859 CommonError::<Test>::TransferNotAllowed
2284 );2860 );
2285 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));2861 assert_eq!(
2862 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
2863 1
2864 );
2286 assert_eq!(TemplateModule::balance_count(1, 1), 1);2865 assert_eq!(
2866 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
2867 0
2868 );
2287 assert_eq!(TemplateModule::balance_count(1, 2), 0);2869 assert_eq!(
22882870 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
2871 true
2289 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2872 );
2873 assert_eq!(
2874 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
2875 false
2876 );
2290 });2877 });
2291}2878}
22922879
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
 };