difftreelog
Merge pull request #974 from UniqueNetwork/fix/evm-coder-leftovers
in: master
25 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -528,7 +528,7 @@
|r: sc_service::Result<
up_data_structs::TokenDataVersion1<CrossAccountId>,
sp_runtime::DispatchError,
- >| r.and_then(|value| Ok(value.into())),
+ >| r.map(|value| value.into()),
)
.or_else(|_| {
Ok(api
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -297,7 +297,7 @@
default_runtime,
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
- vec![
+ [
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
@@ -371,7 +371,7 @@
default_runtime,
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
- vec![
+ [
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -63,7 +63,7 @@
}
let bytes = id.to_string();
let len = data.len();
- data[len - bytes.len()..].copy_from_slice(&bytes.as_bytes());
+ data[len - bytes.len()..].copy_from_slice(bytes.as_bytes());
data
}
pub fn property_value() -> PropertyValue {
@@ -80,7 +80,7 @@
cast: impl FnOnce(CollectionHandle<T>) -> R,
) -> Result<R, DispatchError> {
let imbalance = <T as Config>::Currency::deposit(
- &owner.as_sub(),
+ owner.as_sub(),
T::CollectionCreationPrice::get(),
Precision::Exact,
)?;
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -2420,7 +2420,8 @@
}
}
-#[cfg(feature = "tests")]
+#[cfg(any(feature = "tests", test))]
+#[allow(missing_docs)]
pub mod tests {
use crate::{DispatchResult, DispatchError, LazyValue, Config};
@@ -2456,7 +2457,7 @@
}
#[rustfmt::skip]
- pub const table: [TestCase; 16] = [
+ pub const TABLE: [TestCase; 16] = [
// ┌╴collection_admin
// │ ┌╴is_collection_admin
// │ │ ┌╴token_owner
pallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-coder-substrate/src/lib.rs
+++ b/pallets/evm-coder-substrate/src/lib.rs
@@ -286,7 +286,14 @@
{
let call = C::parse_full(input)?;
if call.is_none() {
- return Err("unrecognized selector".into());
+ let selector = if input.len() >= 4 {
+ let mut selector = [0; 4];
+ selector.copy_from_slice(&input[..4]);
+ u32::from_be_bytes(selector)
+ } else {
+ 0
+ };
+ return Err(format!("unrecognized selector: 0x{selector:0>8x}").into());
}
let call = call.unwrap();
@@ -329,7 +336,7 @@
ERC165Call(ERC165Call, PhantomData<fn() -> T>),
OtherCall(ERC165Call),
- #[weight(Weight::from_ref_time(a + b))]
+ #[weight(Weight::from_parts(a + b, 0))]
Example {
a: u64,
b: u64,
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -53,7 +53,7 @@
let data = (0..b).map(|i| {
bench_init!(to: cross_sub(i););
(to, 200)
- }).collect::<BTreeMap<_, _>>().try_into().unwrap();
+ }).collect::<BTreeMap<_, _>>();
}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
burn_item {
pallets/identity/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/identity/src/benchmarking.rs
+++ b/pallets/identity/src/benchmarking.rs
@@ -35,6 +35,7 @@
//! Identity pallet benchmarking.
#![cfg(feature = "runtime-benchmarks")]
+#![allow(clippy::no_effect)]
use super::*;
pallets/identity/src/tests.rsdiffbeforeafterboth--- a/pallets/identity/src/tests.rs
+++ b/pallets/identity/src/tests.rs
@@ -67,7 +67,7 @@
parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
- frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
+ frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_parts(1024, 0));
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
pallets/identity/src/types.rsdiffbeforeafterboth--- a/pallets/identity/src/types.rs
+++ b/pallets/identity/src/types.rs
@@ -481,7 +481,7 @@
let mut registry = scale_info::Registry::new();
let type_id = registry.register_type(&scale_info::meta_type::<Data>());
let registry: scale_info::PortableRegistry = registry.into();
- let type_info = registry.resolve(type_id.id()).unwrap();
+ let type_info = registry.resolve(type_id.id).unwrap();
let check_type_info = |data: &Data| {
let variant_name = match data {
@@ -492,20 +492,20 @@
Data::ShaThree256(_) => "ShaThree256".to_string(),
Data::Raw(bytes) => format!("Raw{}", bytes.len()),
};
- if let scale_info::TypeDef::Variant(variant) = type_info.type_def() {
+ if let scale_info::TypeDef::Variant(variant) = &type_info.type_def {
let variant = variant
- .variants()
+ .variants
.iter()
- .find(|v| v.name() == &variant_name)
+ .find(|v| v.name == variant_name)
.expect(&format!("Expected to find variant {}", variant_name));
let field_arr_len = variant
- .fields()
+ .fields
.first()
- .and_then(|f| registry.resolve(f.ty().id()))
+ .and_then(|f| registry.resolve(f.ty.id))
.map(|ty| {
- if let scale_info::TypeDef::Array(arr) = ty.type_def() {
- arr.len()
+ if let scale_info::TypeDef::Array(arr) = &ty.type_def {
+ arr.len
} else {
panic!("Should be an array type")
}
@@ -513,7 +513,7 @@
.unwrap_or(0);
let encoded = data.encode();
- assert_eq!(encoded[0], variant.index());
+ assert_eq!(encoded[0], variant.index);
assert_eq!(encoded.len() as u32 - 1, field_arr_len);
} else {
panic!("Should be a variant type")
pallets/inflation/src/tests.rsdiffbeforeafterboth--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -78,7 +78,7 @@
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
- frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024));
+ frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0));
pub const SS58Prefix: u8 = 42;
}
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -43,12 +43,12 @@
owner: T::CrossAccountId,
) -> Result<TokenId, DispatchError> {
<Pallet<T>>::create_item(
- &collection,
+ collection,
sender,
create_max_item_data::<T>(owner),
&Unlimited,
)?;
- Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
+ Ok(TokenId(<TokensMinted<T>>::get(collection.id)))
}
fn create_collection<T: Config>(
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -51,8 +51,8 @@
users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,
) -> Result<TokenId, DispatchError> {
let data: CreateItemData<T> = create_max_item_data::<T>(users);
- <Pallet<T>>::create_item(&collection, sender, data, &Unlimited)?;
- Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
+ <Pallet<T>>::create_item(collection, sender, data, &Unlimited)?;
+ Ok(TokenId(<TokensMinted<T>>::get(collection.id)))
}
fn create_collection<T: Config>(
@@ -104,7 +104,7 @@
let data = vec![create_max_item_data::<T>((0..b).map(|u| {
bench_init!(to: cross_sub(u););
(to, 200)
- }))].try_into().unwrap();
+ }))];
}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
// Other user left, token data is kept
pallets/scheduler-v2/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/benchmarking.rs
+++ b/pallets/scheduler-v2/src/benchmarking.rs
@@ -83,11 +83,11 @@
///
/// # Arguments
/// * `periodic` - makes the task periodic.
-/// Sets the task's period and repetition count to `100`.
+/// Sets the task's period and repetition count to `100`.
/// * `named` - gives a name to the task: `u32_to_name(0)`.
/// * `signed` - determines the origin of the task.
-/// If true, it will have the Signed origin. Otherwise it will have the Root origin.
-/// See [`make_origin`] for details.
+/// If true, it will have the Signed origin. Otherwise it will have the Root origin.
+/// See [`make_origin`] for details.
/// * maybe_lookup_len - sets optional lookup length. It is used to benchmark task fetching from the `Preimages` store.
/// * priority - the task's priority.
fn make_task<T: Config>(
@@ -155,12 +155,10 @@
}
if maybe_lookup_len.is_some() {
len += 1;
+ } else if len > 0 {
+ len -= 1;
} else {
- if len > 0 {
- len -= 1;
- } else {
- break c;
- }
+ break c;
}
}
}
pallets/scheduler-v2/src/mock.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/mock.rs
+++ b/pallets/scheduler-v2/src/mock.rs
@@ -33,6 +33,7 @@
// limitations under the License.
//! # Scheduler test environment.
+#![allow(deprecated)]
use super::*;
@@ -229,6 +230,10 @@
r => Err(O::from(r)),
})
}
+ #[cfg(feature = "runtime-benchmarks")]
+ fn try_successful_origin() -> Result<O, ()> {
+ Ok(O::from(RawOrigin::Root))
+ }
}
pub struct Executor;
pallets/scheduler-v2/src/tests.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/tests.rs
+++ b/pallets/scheduler-v2/src/tests.rs
@@ -33,6 +33,7 @@
// limitations under the License.
//! # Scheduler tests.
+#![allow(deprecated)]
use super::*;
use crate::mock::{
pallets/structure/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/structure/src/benchmarking.rs
+++ b/pallets/structure/src/benchmarking.rs
@@ -19,8 +19,7 @@
use frame_benchmarking::{benchmarks, account};
use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
use up_data_structs::{
- CreateCollectionData, CollectionMode, CreateItemData, CollectionFlags, CreateNftData,
- budget::Unlimited,
+ CreateCollectionData, CollectionMode, CreateItemData, CreateNftData, budget::Unlimited,
};
use pallet_common::Config as CommonConfig;
use pallet_evm::account::CrossAccountId;
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -24,8 +24,7 @@
weights::CommonWeights,
RelayChainBlockNumberProvider,
},
- Runtime, RuntimeEvent, RuntimeCall, RUNTIME_NAME, TOKEN_SYMBOL, DECIMALS,
- Balances,
+ Runtime, RuntimeEvent, RuntimeCall, RUNTIME_NAME, TOKEN_SYMBOL, DECIMALS, Balances,
};
use frame_support::traits::{ConstU32, ConstU64, Currency};
use up_common::{
runtime/common/ethereum/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring.rs
+++ b/runtime/common/ethereum/sponsoring.rs
@@ -161,7 +161,8 @@
}
}
CollectionMode::ReFungible => {
- let call = <UniqueRefungibleCall<T>>::parse_full(&call_context.input).ok()??;
+ let call =
+ <UniqueRefungibleCall<T>>::parse_full(&call_context.input).ok()??;
refungible::call_sponsor(call, collection, who).map(|()| sponsor)
}
CollectionMode::Fungible(_) => {
runtime/common/tests/mod.rsdiffbeforeafterboth--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -16,7 +16,6 @@
use sp_runtime::{BuildStorage, Storage};
use sp_core::{Public, Pair};
-use sp_std::vec;
use up_common::types::AuraId;
use crate::{Runtime, GenesisConfig, ParachainInfoConfig, RuntimeEvent, System};
@@ -76,7 +75,7 @@
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
- let accounts = vec!["Alice", "Bob"];
+ let accounts = ["Alice", "Bob"];
let keys = accounts
.iter()
.map(|&acc| {
@@ -104,7 +103,7 @@
..GenesisConfig::default()
};
- cfg.build_storage().unwrap().into()
+ cfg.build_storage().unwrap()
}
#[cfg(not(feature = "collator-selection"))]
runtime/common/tests/xcm.rsdiffbeforeafterboth--- a/runtime/common/tests/xcm.rs
+++ b/runtime/common/tests/xcm.rs
@@ -26,7 +26,7 @@
const ALICE: AccountId = AccountId::new([0u8; 32]);
const BOB: AccountId = AccountId::new([1u8; 32]);
-const INITIAL_BALANCE: u128 = 1000000000000000000_0000; // 1000 UNQ
+const INITIAL_BALANCE: u128 = 10_000_000_000_000_000_000_000; // 10_000 UNQ
#[test]
pub fn xcm_transact_is_forbidden() {
runtime/tests/Cargo.tomldiffbeforeafterboth--- a/runtime/tests/Cargo.toml
+++ b/runtime/tests/Cargo.toml
@@ -5,7 +5,6 @@
[features]
default = ['refungible']
-tests = ['pallet-common/tests']
refungible = []
@@ -44,3 +43,6 @@
evm-coder = { workspace = true }
up-sponsorship = { workspace = true }
xcm = { workspace = true }
+
+[dev-dependencies]
+pallet-common = { workspace = true, features = ["tests"] }
runtime/tests/src/tests.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Tests to be written here18use crate::{Test, TestCrossAccountId, CollectionCreationPrice, RuntimeOrigin, Unique, new_test_ext};19use up_data_structs::{20 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,21 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, TokenId,22 MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionMode, AccessMode, CollectionPermissions,23 PropertyKeyPermission, PropertyPermission, Property, CollectionPropertiesVec,24 CollectionPropertiesPermissionsVec,25};26use frame_support::{assert_noop, assert_ok, assert_err};27use sp_std::convert::TryInto;28use pallet_evm::account::CrossAccountId;29use pallet_common::Error as CommonError;30use pallet_unique::Error as UniqueError;3132fn add_balance(user: u64, value: u64) {33 const DONOR_USER: u64 = 999;34 assert_ok!(<pallet_balances::Pallet<Test>>::force_set_balance(35 RuntimeOrigin::root(),36 DONOR_USER,37 value,38 ));39 assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(40 RuntimeOrigin::root(),41 DONOR_USER,42 user,43 value44 ));45}4647fn default_nft_data() -> CreateNftData {48 CreateNftData {49 properties: vec![Property {50 key: b"test-prop".to_vec().try_into().unwrap(),51 value: b"test-nft-prop".to_vec().try_into().unwrap(),52 }]53 .try_into()54 .unwrap(),55 }56}5758fn default_fungible_data() -> CreateFungibleData {59 CreateFungibleData { value: 5 }60}6162fn default_re_fungible_data() -> CreateReFungibleData {63 CreateReFungibleData {64 pieces: 1023,65 properties: vec![Property {66 key: b"test-prop".to_vec().try_into().unwrap(),67 value: b"test-nft-prop".to_vec().try_into().unwrap(),68 }]69 .try_into()70 .unwrap(),71 }72}7374fn create_test_collection_for_owner(75 mode: &CollectionMode,76 owner: u64,77 id: CollectionId,78) -> CollectionId {79 add_balance(owner, CollectionCreationPrice::get() as u64 + 1);8081 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();82 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();83 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();84 let token_property_permissions: CollectionPropertiesPermissionsVec =85 vec![PropertyKeyPermission {86 key: b"test-prop".to_vec().try_into().unwrap(),87 permission: PropertyPermission {88 mutable: true,89 collection_admin: false,90 token_owner: true,91 },92 }]93 .try_into()94 .unwrap();95 let properties: CollectionPropertiesVec = vec![Property {96 key: b"test-collection-prop".to_vec().try_into().unwrap(),97 value: b"test-collection-value".to_vec().try_into().unwrap(),98 }]99 .try_into()100 .unwrap();101102 let data: CreateCollectionData<u64> = CreateCollectionData {103 name: col_name1.try_into().unwrap(),104 description: col_desc1.try_into().unwrap(),105 token_prefix: token_prefix1.try_into().unwrap(),106 mode: mode.clone(),107 token_property_permissions: token_property_permissions.clone(),108 properties: properties.clone(),109 ..Default::default()110 };111112 let origin1 = RuntimeOrigin::signed(owner);113 assert_ok!(Unique::create_collection_ex(origin1, data));114115 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();116 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();117 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();118 assert_eq!(119 <pallet_common::CollectionById<Test>>::get(id)120 .unwrap()121 .owner,122 owner123 );124 assert_eq!(125 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,126 saved_col_name127 );128 assert_eq!(129 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,130 *mode131 );132 assert_eq!(133 <pallet_common::CollectionById<Test>>::get(id)134 .unwrap()135 .description,136 saved_description137 );138 assert_eq!(139 <pallet_common::CollectionById<Test>>::get(id)140 .unwrap()141 .token_prefix,142 saved_prefix143 );144 assert_eq!(145 get_collection_property_permissions(id).as_slice(),146 token_property_permissions.as_slice()147 );148 assert_eq!(149 get_collection_properties(id).as_slice(),150 properties.as_slice()151 );152 id153}154155fn get_collection_property_permissions(collection_id: CollectionId) -> Vec<PropertyKeyPermission> {156 <pallet_common::Pallet<Test>>::property_permissions(collection_id)157 .into_iter()158 .map(|(key, permission)| PropertyKeyPermission { key, permission })159 .collect()160}161162fn get_collection_properties(collection_id: CollectionId) -> Vec<Property> {163 <pallet_common::Pallet<Test>>::collection_properties(collection_id)164 .into_iter()165 .map(|(key, value)| Property { key, value })166 .collect()167}168169fn get_token_properties(collection_id: CollectionId, token_id: TokenId) -> Vec<Property> {170 <pallet_nonfungible::Pallet<Test>>::token_properties((collection_id, token_id))171 .into_iter()172 .map(|(key, value)| Property { key, value })173 .collect()174}175176fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {177 create_test_collection_for_owner(&mode, 1, id)178}179180fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {181 let origin1 = RuntimeOrigin::signed(1);182 assert_ok!(Unique::create_item(183 origin1,184 collection_id,185 account(1),186 data.clone()187 ));188}189190fn account(sub: u64) -> TestCrossAccountId {191 TestCrossAccountId::from_sub(sub)192}193194// Use cases tests region195// #region196197#[test]198fn check_not_sufficient_founds() {199 new_test_ext().execute_with(|| {200 let acc: u64 = 1;201 <pallet_balances::Pallet<Test>>::force_set_balance(RuntimeOrigin::root(), acc, 0).unwrap();202203 let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();204 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();205 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();206207 let data: CreateCollectionData<<Test as frame_system::Config>::AccountId> =208 CreateCollectionData {209 name: name.try_into().unwrap(),210 description: description.try_into().unwrap(),211 token_prefix: token_prefix.try_into().unwrap(),212 mode: CollectionMode::NFT,213 ..Default::default()214 };215216 let result = Unique::create_collection_ex(RuntimeOrigin::signed(acc), data);217 assert_err!(result, <CommonError<Test>>::NotSufficientFounds);218 });219}220221#[test]222fn create_fungible_collection_fails_with_large_decimal_numbers() {223 new_test_ext().execute_with(|| {224 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();225 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();226 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();227228 let data: CreateCollectionData<u64> = CreateCollectionData {229 name: col_name1.try_into().unwrap(),230 description: col_desc1.try_into().unwrap(),231 token_prefix: token_prefix1.try_into().unwrap(),232 mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),233 ..Default::default()234 };235236 let origin1 = RuntimeOrigin::signed(1);237 assert_noop!(238 Unique::create_collection_ex(origin1, data),239 UniqueError::<Test>::CollectionDecimalPointLimitExceeded240 );241 });242}243244#[test]245fn create_nft_item() {246 new_test_ext().execute_with(|| {247 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));248249 let data = default_nft_data();250 create_test_item(collection_id, &data.clone().into());251252 assert_eq!(253 get_token_properties(collection_id, TokenId(1)).as_slice(),254 data.properties.as_slice(),255 );256 });257}258259// Use cases tests region260// #region261#[test]262fn create_nft_multiple_items() {263 new_test_ext().execute_with(|| {264 create_test_collection(&CollectionMode::NFT, CollectionId(1));265266 let origin1 = RuntimeOrigin::signed(1);267268 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];269270 assert_ok!(Unique::create_multiple_items(271 origin1,272 CollectionId(1),273 account(1),274 items_data275 .clone()276 .into_iter()277 .map(|d| { d.into() })278 .collect()279 ));280 for (index, data) in items_data.into_iter().enumerate() {281 assert_eq!(282 get_token_properties(CollectionId(1), TokenId(index as u32 + 1)).as_slice(),283 data.properties.as_slice()284 );285 }286 });287}288289#[test]290fn create_refungible_item() {291 new_test_ext().execute_with(|| {292 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));293294 let data = default_re_fungible_data();295 create_test_item(collection_id, &data.clone().into());296 let balance =297 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));298 assert_eq!(balance, 1023);299 });300}301302#[test]303fn create_multiple_refungible_items() {304 new_test_ext().execute_with(|| {305 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));306307 let origin1 = RuntimeOrigin::signed(1);308309 let items_data = vec![310 default_re_fungible_data(),311 default_re_fungible_data(),312 default_re_fungible_data(),313 ];314315 assert_ok!(Unique::create_multiple_items(316 origin1,317 CollectionId(1),318 account(1),319 items_data320 .clone()321 .into_iter()322 .map(|d| { d.into() })323 .collect()324 ));325 for (index, _data) in items_data.into_iter().enumerate() {326 let balance = <pallet_refungible::Balance<Test>>::get((327 CollectionId(1),328 TokenId((index + 1) as u32),329 account(1),330 ));331 assert_eq!(balance, 1023);332 }333 });334}335336#[test]337fn create_fungible_item() {338 new_test_ext().execute_with(|| {339 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));340341 let data = default_fungible_data();342 create_test_item(collection_id, &data.into());343344 assert_eq!(345 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),346 5347 );348 });349}350351//#[test]352// fn create_multiple_fungible_items() {353// new_test_ext().execute_with(|| {354// default_limits();355356// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));357358// let origin1 = RuntimeOrigin::signed(1);359360// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];361362// assert_ok!(Unique::create_multiple_items(363// origin1.clone(),364// 1,365// 1,366// items_data.clone().into_iter().map(|d| { d.into() }).collect()367// ));368369// for (index, _) in items_data.iter().enumerate() {370// assert_eq!(Unique::fungible_item_id(1, (index + 1) as TokenId).value, 5);371// }372// assert_eq!(Unique::balance_count(1, 1), 3000);373// assert_eq!(Unique::address_tokens(1, 1), [1, 2, 3]);374// });375// }376377#[test]378fn transfer_fungible_item() {379 new_test_ext().execute_with(|| {380 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));381382 let origin1 = RuntimeOrigin::signed(1);383 let origin2 = RuntimeOrigin::signed(2);384385 let data = default_fungible_data();386 create_test_item(collection_id, &data.into());387388 assert_eq!(389 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),390 5391 );392393 // change owner scenario394 assert_ok!(Unique::transfer(395 origin1,396 account(2),397 CollectionId(1),398 TokenId(0),399 5400 ));401 assert_eq!(402 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),403 0404 );405406 // split item scenario407 assert_ok!(Unique::transfer(408 origin2.clone(),409 account(3),410 CollectionId(1),411 TokenId(0),412 3413 ));414415 // split item and new owner has account scenario416 assert_ok!(Unique::transfer(417 origin2,418 account(3),419 CollectionId(1),420 TokenId(0),421 1422 ));423 assert_eq!(424 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),425 1426 );427 assert_eq!(428 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),429 4430 );431 });432}433434#[test]435fn transfer_refungible_item() {436 new_test_ext().execute_with(|| {437 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));438439 // Create RFT 1 in 1023 pieces for account 1440 let data = default_re_fungible_data();441 create_test_item(collection_id, &data.clone().into());442 assert_eq!(443 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),444 1445 );446 assert_eq!(447 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),448 1023449 );450 assert_eq!(451 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),452 true453 );454455 // Account 1 transfers all 1023 pieces of RFT 1 to account 2456 let origin1 = RuntimeOrigin::signed(1);457 let origin2 = RuntimeOrigin::signed(2);458 assert_ok!(Unique::transfer(459 origin1,460 account(2),461 CollectionId(1),462 TokenId(1),463 1023464 ));465 assert_eq!(466 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),467 1023468 );469 assert_eq!(470 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),471 0472 );473 assert_eq!(474 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),475 1476 );477 assert_eq!(478 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),479 false480 );481 assert_eq!(482 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),483 true484 );485486 // Account 2 transfers 500 pieces of RFT 1 to account 3487 assert_ok!(Unique::transfer(488 origin2.clone(),489 account(3),490 CollectionId(1),491 TokenId(1),492 500493 ));494 assert_eq!(495 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),496 523497 );498 assert_eq!(499 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),500 500501 );502 assert_eq!(503 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),504 1505 );506 assert_eq!(507 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),508 1509 );510 assert_eq!(511 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),512 true513 );514 assert_eq!(515 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),516 true517 );518519 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance520 assert_ok!(Unique::transfer(521 origin2,522 account(3),523 CollectionId(1),524 TokenId(1),525 200526 ));527 assert_eq!(528 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),529 323530 );531 assert_eq!(532 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),533 700534 );535 assert_eq!(536 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),537 1538 );539 assert_eq!(540 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),541 1542 );543 assert_eq!(544 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),545 true546 );547 assert_eq!(548 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),549 true550 );551 });552}553554#[test]555fn transfer_nft_item() {556 new_test_ext().execute_with(|| {557 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));558559 let data = default_nft_data();560 create_test_item(collection_id, &data.into());561 assert_eq!(562 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),563 1564 );565 assert_eq!(566 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),567 true568 );569570 let origin1 = RuntimeOrigin::signed(1);571 // default scenario572 assert_ok!(Unique::transfer(573 origin1,574 account(2),575 CollectionId(1),576 TokenId(1),577 1578 ));579 assert_eq!(580 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),581 0582 );583 assert_eq!(584 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),585 1586 );587 assert_eq!(588 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),589 false590 );591 assert_eq!(592 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),593 true594 );595 });596}597598#[test]599fn transfer_nft_item_wrong_value() {600 new_test_ext().execute_with(|| {601 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));602603 let data = default_nft_data();604 create_test_item(collection_id, &data.into());605 assert_eq!(606 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),607 1608 );609 assert_eq!(610 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),611 true612 );613614 let origin1 = RuntimeOrigin::signed(1);615616 assert_noop!(617 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)618 .map_err(|e| e.error),619 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount620 );621 });622}623624#[test]625fn transfer_nft_item_zero_value() {626 new_test_ext().execute_with(|| {627 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));628629 let data = default_nft_data();630 create_test_item(collection_id, &data.into());631 assert_eq!(632 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),633 1634 );635 assert_eq!(636 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),637 true638 );639640 let origin1 = RuntimeOrigin::signed(1);641642 // Transferring 0 amount works on NFT...643 assert_ok!(Unique::transfer(644 origin1,645 account(2),646 CollectionId(1),647 TokenId(1),648 0649 ));650 // ... and results in no transfer651 assert_eq!(652 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),653 1654 );655 assert_eq!(656 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),657 true658 );659 });660}661662#[test]663fn nft_approve_and_transfer_from() {664 new_test_ext().execute_with(|| {665 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));666667 let data = default_nft_data();668 create_test_item(collection_id, &data.into());669670 let origin1 = RuntimeOrigin::signed(1);671 let origin2 = RuntimeOrigin::signed(2);672673 assert_eq!(674 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),675 1676 );677 assert_eq!(678 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),679 true680 );681682 // neg transfer_from683 assert_noop!(684 Unique::transfer_from(685 origin2.clone(),686 account(1),687 account(2),688 CollectionId(1),689 TokenId(1),690 1691 )692 .map_err(|e| e.error),693 CommonError::<Test>::ApprovedValueTooLow694 );695696 // do approve697 assert_ok!(Unique::approve(698 origin1,699 account(2),700 CollectionId(1),701 TokenId(1),702 1703 ));704 assert_eq!(705 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),706 account(2)707 );708709 assert_ok!(Unique::transfer_from(710 origin2,711 account(1),712 account(3),713 CollectionId(1),714 TokenId(1),715 1716 ));717 assert!(718 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()719 );720 });721}722723#[test]724fn nft_approve_and_transfer_from_allow_list() {725 new_test_ext().execute_with(|| {726 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));727728 let origin1 = RuntimeOrigin::signed(1);729 let origin2 = RuntimeOrigin::signed(2);730731 // Create NFT 1 for account 1732 let data = default_nft_data();733 create_test_item(collection_id, &data.clone().into());734 assert_eq!(735 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),736 1737 );738 assert_eq!(739 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),740 true741 );742743 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list744 assert_ok!(Unique::set_collection_permissions(745 origin1.clone(),746 CollectionId(1),747 CollectionPermissions {748 mint_mode: Some(true),749 access: Some(AccessMode::AllowList),750 nesting: None,751 }752 ));753 assert_ok!(Unique::add_to_allow_list(754 origin1.clone(),755 CollectionId(1),756 account(1)757 ));758 assert_ok!(Unique::add_to_allow_list(759 origin1.clone(),760 CollectionId(1),761 account(2)762 ));763 assert_ok!(Unique::add_to_allow_list(764 origin1.clone(),765 CollectionId(1),766 account(3)767 ));768769 // Account 1 approves account 2 for NFT 1770 assert_ok!(Unique::approve(771 origin1.clone(),772 account(2),773 CollectionId(1),774 TokenId(1),775 1776 ));777 assert_eq!(778 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),779 account(2)780 );781782 // Account 2 transfers NFT 1 from account 1 to account 3783 assert_ok!(Unique::transfer_from(784 origin2,785 account(1),786 account(3),787 CollectionId(1),788 TokenId(1),789 1790 ));791 assert!(792 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()793 );794 });795}796797#[test]798fn refungible_approve_and_transfer_from() {799 new_test_ext().execute_with(|| {800 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));801802 let origin1 = RuntimeOrigin::signed(1);803 let origin2 = RuntimeOrigin::signed(2);804805 // Create RFT 1 in 1023 pieces for account 1806 let data = default_re_fungible_data();807 create_test_item(collection_id, &data.into());808809 assert_eq!(810 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),811 1812 );813 assert_eq!(814 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),815 1023816 );817 assert_eq!(818 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),819 true820 );821822 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list823 assert_ok!(Unique::set_collection_permissions(824 origin1.clone(),825 CollectionId(1),826 CollectionPermissions {827 mint_mode: Some(true),828 access: Some(AccessMode::AllowList),829 nesting: None,830 }831 ));832 assert_ok!(Unique::add_to_allow_list(833 origin1.clone(),834 CollectionId(1),835 account(1)836 ));837 assert_ok!(Unique::add_to_allow_list(838 origin1.clone(),839 CollectionId(1),840 account(2)841 ));842 assert_ok!(Unique::add_to_allow_list(843 origin1.clone(),844 CollectionId(1),845 account(3)846 ));847848 // Account 1 approves account 2 for 1023 pieces of RFT 1849 assert_ok!(Unique::approve(850 origin1,851 account(2),852 CollectionId(1),853 TokenId(1),854 1023855 ));856 assert_eq!(857 <pallet_refungible::Allowance<Test>>::get((858 CollectionId(1),859 TokenId(1),860 account(1),861 account(2)862 )),863 1023864 );865866 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3867 assert_ok!(Unique::transfer_from(868 origin2,869 account(1),870 account(3),871 CollectionId(1),872 TokenId(1),873 100874 ));875 assert_eq!(876 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),877 1878 );879 assert_eq!(880 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),881 1882 );883 assert_eq!(884 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),885 923886 );887 assert_eq!(888 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),889 100890 );891 assert_eq!(892 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),893 true894 );895 assert_eq!(896 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),897 true898 );899 assert_eq!(900 <pallet_refungible::Allowance<Test>>::get((901 CollectionId(1),902 TokenId(1),903 account(1),904 account(2)905 )),906 923907 );908 });909}910911#[test]912fn fungible_approve_and_transfer_from() {913 new_test_ext().execute_with(|| {914 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));915916 let data = default_fungible_data();917 create_test_item(collection_id, &data.into());918919 let origin1 = RuntimeOrigin::signed(1);920 let origin2 = RuntimeOrigin::signed(2);921922 assert_ok!(Unique::set_collection_permissions(923 origin1.clone(),924 CollectionId(1),925 CollectionPermissions {926 mint_mode: Some(true),927 access: Some(AccessMode::AllowList),928 nesting: None,929 }930 ));931 assert_ok!(Unique::add_to_allow_list(932 origin1.clone(),933 CollectionId(1),934 account(1)935 ));936 assert_ok!(Unique::add_to_allow_list(937 origin1.clone(),938 CollectionId(1),939 account(2)940 ));941 assert_ok!(Unique::add_to_allow_list(942 origin1.clone(),943 CollectionId(1),944 account(3)945 ));946947 // do approve948 assert_ok!(Unique::approve(949 origin1.clone(),950 account(2),951 CollectionId(1),952 TokenId(0),953 5954 ));955 assert_eq!(956 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),957 5958 );959 assert_ok!(Unique::approve(960 origin1,961 account(3),962 CollectionId(1),963 TokenId(0),964 5965 ));966 assert_eq!(967 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),968 5969 );970 assert_eq!(971 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),972 5973 );974975 assert_ok!(Unique::transfer_from(976 origin2.clone(),977 account(1),978 account(3),979 CollectionId(1),980 TokenId(0),981 4982 ));983984 assert_eq!(985 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),986 1987 );988989 assert_noop!(990 Unique::transfer_from(991 origin2,992 account(1),993 account(3),994 CollectionId(1),995 TokenId(0),996 4997 )998 .map_err(|e| e.error),999 CommonError::<Test>::ApprovedValueTooLow1000 );1001 });1002}10031004#[test]1005fn change_collection_owner() {1006 new_test_ext().execute_with(|| {1007 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10081009 let origin1 = RuntimeOrigin::signed(1);1010 assert_ok!(Unique::change_collection_owner(origin1, collection_id, 2));1011 assert_eq!(1012 <pallet_common::CollectionById<Test>>::get(collection_id)1013 .unwrap()1014 .owner,1015 21016 );1017 });1018}10191020#[test]1021fn destroy_collection() {1022 new_test_ext().execute_with(|| {1023 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10241025 let origin1 = RuntimeOrigin::signed(1);1026 assert_ok!(Unique::destroy_collection(origin1, collection_id));1027 });1028}10291030#[test]1031fn burn_nft_item() {1032 new_test_ext().execute_with(|| {1033 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10341035 let origin1 = RuntimeOrigin::signed(1);10361037 let data = default_nft_data();1038 create_test_item(collection_id, &data.into());10391040 // check balance (collection with id = 1, user id = 1)1041 assert_eq!(1042 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1043 11044 );10451046 // burn item1047 assert_ok!(Unique::burn_item(1048 origin1.clone(),1049 collection_id,1050 TokenId(1),1051 11052 ));1053 assert_eq!(1054 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1055 01056 );1057 });1058}10591060#[test]1061fn burn_same_nft_item_twice() {1062 new_test_ext().execute_with(|| {1063 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10641065 let origin1 = RuntimeOrigin::signed(1);10661067 let data = default_nft_data();1068 create_test_item(collection_id, &data.into());10691070 // check balance (collection with id = 1, user id = 1)1071 assert_eq!(1072 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1073 11074 );10751076 // burn item1077 assert_ok!(Unique::burn_item(1078 origin1.clone(),1079 collection_id,1080 TokenId(1),1081 11082 ));10831084 // burn item again1085 assert_noop!(1086 Unique::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1087 CommonError::<Test>::TokenNotFound1088 );10891090 assert_eq!(1091 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1092 01093 );1094 });1095}10961097#[test]1098fn burn_fungible_item() {1099 new_test_ext().execute_with(|| {1100 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11011102 let origin1 = RuntimeOrigin::signed(1);1103 assert_ok!(Unique::add_collection_admin(1104 origin1.clone(),1105 collection_id,1106 account(2)1107 ));11081109 let data = default_fungible_data();1110 create_test_item(collection_id, &data.into());11111112 // check balance (collection with id = 1, user id = 1)1113 assert_eq!(1114 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1115 51116 );11171118 // burn item1119 assert_ok!(Unique::burn_item(1120 origin1.clone(),1121 CollectionId(1),1122 TokenId(0),1123 51124 ));1125 assert_noop!(1126 Unique::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1127 CommonError::<Test>::TokenValueTooLow1128 );11291130 assert_eq!(1131 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1132 01133 );1134 });1135}11361137#[test]1138fn burn_fungible_item_with_token_id() {1139 new_test_ext().execute_with(|| {1140 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11411142 let origin1 = RuntimeOrigin::signed(1);1143 assert_ok!(Unique::add_collection_admin(1144 origin1.clone(),1145 collection_id,1146 account(2)1147 ));11481149 let data = default_fungible_data();1150 create_test_item(collection_id, &data.into());11511152 // check balance (collection with id = 1, user id = 1)1153 assert_eq!(1154 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1155 51156 );11571158 // Try to burn item using Token ID1159 assert_noop!(1160 Unique::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1161 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1162 );1163 });1164}1165#[test]1166fn burn_refungible_item() {1167 new_test_ext().execute_with(|| {1168 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1169 let origin1 = RuntimeOrigin::signed(1);11701171 assert_ok!(Unique::set_collection_permissions(1172 origin1.clone(),1173 collection_id,1174 CollectionPermissions {1175 mint_mode: Some(true),1176 access: Some(AccessMode::AllowList),1177 nesting: None,1178 }1179 ));1180 assert_ok!(Unique::add_to_allow_list(1181 origin1.clone(),1182 collection_id,1183 account(1)1184 ));11851186 assert_ok!(Unique::add_collection_admin(1187 origin1.clone(),1188 collection_id,1189 account(2)1190 ));11911192 let data = default_re_fungible_data();1193 create_test_item(collection_id, &data.into());11941195 // check balance (collection with id = 1, user id = 2)1196 assert_eq!(1197 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1198 11199 );1200 assert_eq!(1201 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1202 10231203 );12041205 // burn item1206 assert_ok!(Unique::burn_item(1207 origin1.clone(),1208 collection_id,1209 TokenId(1),1210 10231211 ));1212 assert_noop!(1213 Unique::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error),1214 CommonError::<Test>::TokenValueTooLow1215 );12161217 assert_eq!(1218 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1219 01220 );1221 });1222}12231224#[test]1225fn add_collection_admin() {1226 new_test_ext().execute_with(|| {1227 let collection1_id =1228 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1229 let origin1 = RuntimeOrigin::signed(1);12301231 // Add collection admins1232 assert_ok!(Unique::add_collection_admin(1233 origin1.clone(),1234 collection1_id,1235 account(2)1236 ));1237 assert_ok!(Unique::add_collection_admin(1238 origin1,1239 collection1_id,1240 account(3)1241 ));12421243 // Owner is not an admin by default1244 assert_eq!(1245 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1246 false1247 );1248 assert!(<pallet_common::IsAdmin<Test>>::get((1249 CollectionId(1),1250 account(2)1251 )));1252 assert!(<pallet_common::IsAdmin<Test>>::get((1253 CollectionId(1),1254 account(3)1255 )));1256 });1257}12581259#[test]1260fn remove_collection_admin() {1261 new_test_ext().execute_with(|| {1262 let collection1_id =1263 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1264 let origin1 = RuntimeOrigin::signed(1);12651266 // Add collection admins 2 and 31267 assert_ok!(Unique::add_collection_admin(1268 origin1.clone(),1269 collection1_id,1270 account(2)1271 ));1272 assert_ok!(Unique::add_collection_admin(1273 origin1.clone(),1274 collection1_id,1275 account(3)1276 ));12771278 assert!(<pallet_common::IsAdmin<Test>>::get((1279 CollectionId(1),1280 account(2)1281 )));1282 assert!(<pallet_common::IsAdmin<Test>>::get((1283 CollectionId(1),1284 account(3)1285 )));12861287 // remove admin 31288 assert_ok!(Unique::remove_collection_admin(1289 origin1,1290 CollectionId(1),1291 account(3)1292 ));12931294 // 2 is still admin, 3 is not an admin anymore1295 assert!(<pallet_common::IsAdmin<Test>>::get((1296 CollectionId(1),1297 account(2)1298 )));1299 assert_eq!(1300 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1301 false1302 );1303 });1304}13051306#[test]1307fn balance_of() {1308 new_test_ext().execute_with(|| {1309 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1310 let fungible_collection_id =1311 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1312 let re_fungible_collection_id =1313 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));13141315 // check balance before1316 assert_eq!(1317 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1318 01319 );1320 assert_eq!(1321 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1322 01323 );1324 assert_eq!(1325 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1326 01327 );13281329 let nft_data = default_nft_data();1330 create_test_item(nft_collection_id, &nft_data.into());13311332 let fungible_data = default_fungible_data();1333 create_test_item(fungible_collection_id, &fungible_data.into());13341335 let re_fungible_data = default_re_fungible_data();1336 create_test_item(re_fungible_collection_id, &re_fungible_data.into());13371338 // check balance (collection with id = 1, user id = 1)1339 assert_eq!(1340 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1341 11342 );1343 assert_eq!(1344 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1345 51346 );1347 assert_eq!(1348 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1349 11350 );13511352 assert_eq!(1353 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1354 true1355 );1356 assert_eq!(1357 <pallet_refungible::Owned<Test>>::get((1358 re_fungible_collection_id,1359 account(1),1360 TokenId(1)1361 )),1362 true1363 );1364 });1365}13661367#[test]1368fn approve() {1369 new_test_ext().execute_with(|| {1370 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13711372 let data = default_nft_data();1373 create_test_item(collection_id, &data.into());13741375 let origin1 = RuntimeOrigin::signed(1);13761377 // approve1378 assert_ok!(Unique::approve(1379 origin1,1380 account(2),1381 CollectionId(1),1382 TokenId(1),1383 11384 ));1385 assert_eq!(1386 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1387 account(2)1388 );1389 });1390}13911392#[test]1393fn transfer_from() {1394 new_test_ext().execute_with(|| {1395 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1396 let origin1 = RuntimeOrigin::signed(1);1397 let origin2 = RuntimeOrigin::signed(2);13981399 let data = default_nft_data();1400 create_test_item(collection_id, &data.into());14011402 // approve1403 assert_ok!(Unique::approve(1404 origin1.clone(),1405 account(2),1406 CollectionId(1),1407 TokenId(1),1408 11409 ));1410 assert_eq!(1411 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1412 account(2)1413 );14141415 assert_ok!(Unique::set_collection_permissions(1416 origin1.clone(),1417 CollectionId(1),1418 CollectionPermissions {1419 mint_mode: Some(true),1420 access: Some(AccessMode::AllowList),1421 nesting: None,1422 }1423 ));1424 assert_ok!(Unique::add_to_allow_list(1425 origin1.clone(),1426 CollectionId(1),1427 account(1)1428 ));1429 assert_ok!(Unique::add_to_allow_list(1430 origin1.clone(),1431 CollectionId(1),1432 account(2)1433 ));1434 assert_ok!(Unique::add_to_allow_list(1435 origin1,1436 CollectionId(1),1437 account(3)1438 ));14391440 assert_ok!(Unique::transfer_from(1441 origin2,1442 account(1),1443 account(2),1444 CollectionId(1),1445 TokenId(1),1446 11447 ));14481449 // after transfer1450 assert_eq!(1451 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1452 01453 );1454 assert_eq!(1455 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1456 11457 );1458 });1459}14601461// #endregion14621463// Coverage tests region1464// #region14651466#[test]1467fn owner_can_add_address_to_allow_list() {1468 new_test_ext().execute_with(|| {1469 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14701471 let origin1 = RuntimeOrigin::signed(1);1472 assert_ok!(Unique::add_to_allow_list(1473 origin1,1474 collection_id,1475 account(2)1476 ));1477 assert!(<pallet_common::Allowlist<Test>>::get((1478 collection_id,1479 account(2)1480 )));1481 });1482}14831484#[test]1485fn admin_can_add_address_to_allow_list() {1486 new_test_ext().execute_with(|| {1487 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1488 let origin1 = RuntimeOrigin::signed(1);1489 let origin2 = RuntimeOrigin::signed(2);14901491 assert_ok!(Unique::add_collection_admin(1492 origin1,1493 collection_id,1494 account(2)1495 ));1496 assert_ok!(Unique::add_to_allow_list(1497 origin2,1498 collection_id,1499 account(3)1500 ));1501 assert!(<pallet_common::Allowlist<Test>>::get((1502 collection_id,1503 account(3)1504 )));1505 });1506}15071508#[test]1509fn nonprivileged_user_cannot_add_address_to_allow_list() {1510 new_test_ext().execute_with(|| {1511 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15121513 let origin2 = RuntimeOrigin::signed(2);1514 assert_noop!(1515 Unique::add_to_allow_list(origin2, collection_id, account(3)),1516 CommonError::<Test>::NoPermission1517 );1518 });1519}15201521#[test]1522fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1523 new_test_ext().execute_with(|| {1524 let origin1 = RuntimeOrigin::signed(1);15251526 assert_noop!(1527 Unique::add_to_allow_list(origin1, CollectionId(1), account(2)),1528 CommonError::<Test>::CollectionNotFound1529 );1530 });1531}15321533#[test]1534fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1535 new_test_ext().execute_with(|| {1536 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15371538 let origin1 = RuntimeOrigin::signed(1);1539 assert_ok!(Unique::destroy_collection(origin1.clone(), collection_id));1540 assert_noop!(1541 Unique::add_to_allow_list(origin1, collection_id, account(2)),1542 CommonError::<Test>::CollectionNotFound1543 );1544 });1545}15461547// If address is already added to allow list, nothing happens1548#[test]1549fn address_is_already_added_to_allow_list() {1550 new_test_ext().execute_with(|| {1551 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1552 let origin1 = RuntimeOrigin::signed(1);15531554 assert_ok!(Unique::add_to_allow_list(1555 origin1.clone(),1556 collection_id,1557 account(2)1558 ));1559 assert_ok!(Unique::add_to_allow_list(1560 origin1,1561 collection_id,1562 account(2)1563 ));1564 assert!(<pallet_common::Allowlist<Test>>::get((1565 collection_id,1566 account(2)1567 )));1568 });1569}15701571#[test]1572fn owner_can_remove_address_from_allow_list() {1573 new_test_ext().execute_with(|| {1574 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15751576 let origin1 = RuntimeOrigin::signed(1);1577 assert_ok!(Unique::add_to_allow_list(1578 origin1.clone(),1579 collection_id,1580 account(2)1581 ));1582 assert_ok!(Unique::remove_from_allow_list(1583 origin1,1584 collection_id,1585 account(2)1586 ));1587 assert_eq!(1588 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1589 false1590 );1591 });1592}15931594#[test]1595fn admin_can_remove_address_from_allow_list() {1596 new_test_ext().execute_with(|| {1597 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1598 let origin1 = RuntimeOrigin::signed(1);1599 let origin2 = RuntimeOrigin::signed(2);16001601 // Owner adds admin1602 assert_ok!(Unique::add_collection_admin(1603 origin1.clone(),1604 collection_id,1605 account(2)1606 ));16071608 // Owner adds address 3 to allow list1609 assert_ok!(Unique::add_to_allow_list(1610 origin1,1611 collection_id,1612 account(3)1613 ));16141615 // Admin removes address 3 from allow list1616 assert_ok!(Unique::remove_from_allow_list(1617 origin2,1618 collection_id,1619 account(3)1620 ));1621 assert_eq!(1622 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1623 false1624 );1625 });1626}16271628#[test]1629fn nonprivileged_user_cannot_remove_address_from_allow_list() {1630 new_test_ext().execute_with(|| {1631 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1632 let origin1 = RuntimeOrigin::signed(1);1633 let origin2 = RuntimeOrigin::signed(2);16341635 assert_ok!(Unique::add_to_allow_list(1636 origin1,1637 collection_id,1638 account(2)1639 ));1640 assert_noop!(1641 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1642 CommonError::<Test>::NoPermission1643 );1644 assert!(<pallet_common::Allowlist<Test>>::get((1645 collection_id,1646 account(2)1647 )));1648 });1649}16501651#[test]1652fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1653 new_test_ext().execute_with(|| {1654 let origin1 = RuntimeOrigin::signed(1);16551656 assert_noop!(1657 Unique::remove_from_allow_list(origin1, CollectionId(1), account(2)),1658 CommonError::<Test>::CollectionNotFound1659 );1660 });1661}16621663#[test]1664fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1665 new_test_ext().execute_with(|| {1666 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1667 let origin1 = RuntimeOrigin::signed(1);1668 let origin2 = RuntimeOrigin::signed(2);16691670 // Add account 2 to allow list1671 assert_ok!(Unique::add_to_allow_list(1672 origin1.clone(),1673 collection_id,1674 account(2)1675 ));16761677 // Account 2 is in collection allow-list1678 assert!(<pallet_common::Allowlist<Test>>::get((1679 collection_id,1680 account(2)1681 )));16821683 // Destroy collection1684 assert_ok!(Unique::destroy_collection(origin1, collection_id));16851686 // Attempt to remove account 2 from collection allow-list => error1687 assert_noop!(1688 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1689 CommonError::<Test>::CollectionNotFound1690 );16911692 // Account 2 is not found in collection allow-list anyway1693 assert_eq!(1694 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1695 false1696 );1697 });1698}16991700// If address is already removed from allow list, nothing happens1701#[test]1702fn address_is_already_removed_from_allow_list() {1703 new_test_ext().execute_with(|| {1704 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1705 let origin1 = RuntimeOrigin::signed(1);17061707 assert_ok!(Unique::add_to_allow_list(1708 origin1.clone(),1709 collection_id,1710 account(2)1711 ));1712 assert_ok!(Unique::remove_from_allow_list(1713 origin1.clone(),1714 collection_id,1715 account(2)1716 ));1717 assert_eq!(1718 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1719 false1720 );1721 assert_ok!(Unique::remove_from_allow_list(1722 origin1,1723 collection_id,1724 account(2)1725 ));1726 assert_eq!(1727 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1728 false1729 );1730 });1731}17321733// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1734#[test]1735fn allow_list_test_1() {1736 new_test_ext().execute_with(|| {1737 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17381739 let origin1 = RuntimeOrigin::signed(1);1740 assert_ok!(Unique::add_collection_admin(1741 origin1.clone(),1742 collection_id,1743 account(1)1744 ));17451746 let data = default_nft_data();1747 create_test_item(collection_id, &data.into());17481749 assert_ok!(Unique::set_collection_permissions(1750 origin1.clone(),1751 collection_id,1752 CollectionPermissions {1753 mint_mode: None,1754 access: Some(AccessMode::AllowList),1755 nesting: None,1756 }1757 ));1758 assert_ok!(Unique::add_to_allow_list(1759 origin1.clone(),1760 collection_id,1761 account(2)1762 ));17631764 assert_noop!(1765 Unique::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1766 .map_err(|e| e.error),1767 CommonError::<Test>::AddressNotInAllowlist1768 );1769 });1770}17711772#[test]1773fn allow_list_test_2() {1774 new_test_ext().execute_with(|| {1775 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1776 let origin1 = RuntimeOrigin::signed(1);17771778 let data = default_nft_data();1779 create_test_item(collection_id, &data.into());17801781 assert_ok!(Unique::set_collection_permissions(1782 origin1.clone(),1783 collection_id,1784 CollectionPermissions {1785 mint_mode: None,1786 access: Some(AccessMode::AllowList),1787 nesting: None,1788 }1789 ));1790 assert_ok!(Unique::add_to_allow_list(1791 origin1.clone(),1792 collection_id,1793 account(1)1794 ));1795 assert_ok!(Unique::add_to_allow_list(1796 origin1.clone(),1797 collection_id,1798 account(2)1799 ));18001801 // do approve1802 assert_ok!(Unique::approve(1803 origin1.clone(),1804 account(1),1805 collection_id,1806 TokenId(1),1807 11808 ));1809 assert_eq!(1810 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1811 account(1)1812 );18131814 assert_ok!(Unique::remove_from_allow_list(1815 origin1.clone(),1816 collection_id,1817 account(1)1818 ));18191820 assert_noop!(1821 Unique::transfer_from(1822 origin1,1823 account(1),1824 account(3),1825 CollectionId(1),1826 TokenId(1),1827 11828 )1829 .map_err(|e| e.error),1830 CommonError::<Test>::AddressNotInAllowlist1831 );1832 });1833}18341835// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1836#[test]1837fn allow_list_test_3() {1838 new_test_ext().execute_with(|| {1839 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18401841 let origin1 = RuntimeOrigin::signed(1);18421843 let data = default_nft_data();1844 create_test_item(collection_id, &data.into());18451846 assert_ok!(Unique::set_collection_permissions(1847 origin1.clone(),1848 collection_id,1849 CollectionPermissions {1850 mint_mode: None,1851 access: Some(AccessMode::AllowList),1852 nesting: None,1853 }1854 ));1855 assert_ok!(Unique::add_to_allow_list(1856 origin1.clone(),1857 collection_id,1858 account(1)1859 ));18601861 assert_noop!(1862 Unique::transfer(origin1, account(3), collection_id, TokenId(1), 1)1863 .map_err(|e| e.error),1864 CommonError::<Test>::AddressNotInAllowlist1865 );1866 });1867}18681869#[test]1870fn allow_list_test_4() {1871 new_test_ext().execute_with(|| {1872 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18731874 let origin1 = RuntimeOrigin::signed(1);18751876 let data = default_nft_data();1877 create_test_item(collection_id, &data.into());18781879 assert_ok!(Unique::set_collection_permissions(1880 origin1.clone(),1881 collection_id,1882 CollectionPermissions {1883 mint_mode: None,1884 access: Some(AccessMode::AllowList),1885 nesting: None,1886 }1887 ));1888 assert_ok!(Unique::add_to_allow_list(1889 origin1.clone(),1890 collection_id,1891 account(1)1892 ));1893 assert_ok!(Unique::add_to_allow_list(1894 origin1.clone(),1895 collection_id,1896 account(2)1897 ));18981899 // do approve1900 assert_ok!(Unique::approve(1901 origin1.clone(),1902 account(1),1903 collection_id,1904 TokenId(1),1905 11906 ));1907 assert_eq!(1908 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1909 account(1)1910 );19111912 assert_ok!(Unique::remove_from_allow_list(1913 origin1.clone(),1914 collection_id,1915 account(2)1916 ));19171918 assert_noop!(1919 Unique::transfer_from(1920 origin1,1921 account(1),1922 account(3),1923 collection_id,1924 TokenId(1),1925 11926 )1927 .map_err(|e| e.error),1928 CommonError::<Test>::AddressNotInAllowlist1929 );1930 });1931}19321933// If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)1934#[test]1935fn allow_list_test_5() {1936 new_test_ext().execute_with(|| {1937 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19381939 let origin1 = RuntimeOrigin::signed(1);19401941 let data = default_nft_data();1942 create_test_item(collection_id, &data.into());19431944 assert_ok!(Unique::set_collection_permissions(1945 origin1.clone(),1946 collection_id,1947 CollectionPermissions {1948 mint_mode: None,1949 access: Some(AccessMode::AllowList),1950 nesting: None,1951 }1952 ));1953 assert_noop!(1954 Unique::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),1955 CommonError::<Test>::AddressNotInAllowlist1956 );1957 });1958}19591960// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1961#[test]1962fn allow_list_test_6() {1963 new_test_ext().execute_with(|| {1964 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19651966 let origin1 = RuntimeOrigin::signed(1);19671968 let data = default_nft_data();1969 create_test_item(collection_id, &data.into());19701971 assert_ok!(Unique::set_collection_permissions(1972 origin1.clone(),1973 collection_id,1974 CollectionPermissions {1975 mint_mode: None,1976 access: Some(AccessMode::AllowList),1977 nesting: None,1978 }1979 ));19801981 // do approve1982 assert_noop!(1983 Unique::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1984 .map_err(|e| e.error),1985 CommonError::<Test>::AddressNotInAllowlist1986 );1987 });1988}19891990// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1991// tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1992#[test]1993fn allow_list_test_7() {1994 new_test_ext().execute_with(|| {1995 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19961997 let data = default_nft_data();1998 create_test_item(collection_id, &data.into());19992000 let origin1 = RuntimeOrigin::signed(1);20012002 assert_ok!(Unique::set_collection_permissions(2003 origin1.clone(),2004 collection_id,2005 CollectionPermissions {2006 mint_mode: None,2007 access: Some(AccessMode::AllowList),2008 nesting: None,2009 }2010 ));2011 assert_ok!(Unique::add_to_allow_list(2012 origin1.clone(),2013 collection_id,2014 account(1)2015 ));2016 assert_ok!(Unique::add_to_allow_list(2017 origin1.clone(),2018 collection_id,2019 account(2)2020 ));20212022 assert_ok!(Unique::transfer(2023 origin1,2024 account(2),2025 CollectionId(1),2026 TokenId(1),2027 12028 ));2029 });2030}20312032#[test]2033fn allow_list_test_8() {2034 new_test_ext().execute_with(|| {2035 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20362037 // Create NFT for account 12038 let data = default_nft_data();2039 create_test_item(collection_id, &data.into());20402041 let origin1 = RuntimeOrigin::signed(1);20422043 // Toggle Allow List mode and add accounts 1 and 22044 assert_ok!(Unique::set_collection_permissions(2045 origin1.clone(),2046 collection_id,2047 CollectionPermissions {2048 mint_mode: None,2049 access: Some(AccessMode::AllowList),2050 nesting: None,2051 }2052 ));2053 assert_ok!(Unique::add_to_allow_list(2054 origin1.clone(),2055 collection_id,2056 account(1)2057 ));2058 assert_ok!(Unique::add_to_allow_list(2059 origin1.clone(),2060 collection_id,2061 account(2)2062 ));20632064 // Sself-approve account 1 for NFT 12065 assert_ok!(Unique::approve(2066 origin1.clone(),2067 account(1),2068 CollectionId(1),2069 TokenId(1),2070 12071 ));2072 assert_eq!(2073 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2074 account(1)2075 );20762077 // Transfer from 1 to 22078 assert_ok!(Unique::transfer_from(2079 origin1,2080 account(1),2081 account(2),2082 CollectionId(1),2083 TokenId(1),2084 12085 ));2086 });2087}20882089// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2090#[test]2091fn allow_list_test_9() {2092 new_test_ext().execute_with(|| {2093 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2094 let origin1 = RuntimeOrigin::signed(1);20952096 assert_ok!(Unique::set_collection_permissions(2097 origin1.clone(),2098 collection_id,2099 CollectionPermissions {2100 mint_mode: Some(false),2101 access: Some(AccessMode::AllowList),2102 nesting: None,2103 }2104 ));21052106 let data = default_nft_data();2107 create_test_item(collection_id, &data.into());2108 });2109}21102111// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2112#[test]2113fn allow_list_test_10() {2114 new_test_ext().execute_with(|| {2115 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21162117 let origin1 = RuntimeOrigin::signed(1);2118 let origin2 = RuntimeOrigin::signed(2);21192120 assert_ok!(Unique::set_collection_permissions(2121 origin1.clone(),2122 collection_id,2123 CollectionPermissions {2124 mint_mode: Some(false),2125 access: Some(AccessMode::AllowList),2126 nesting: None,2127 }2128 ));21292130 assert_ok!(Unique::add_collection_admin(2131 origin1,2132 collection_id,2133 account(2)2134 ));21352136 assert_ok!(Unique::create_item(2137 origin2,2138 collection_id,2139 account(2),2140 default_nft_data().into()2141 ));2142 });2143}21442145// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.2146#[test]2147fn allow_list_test_11() {2148 new_test_ext().execute_with(|| {2149 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21502151 let origin1 = RuntimeOrigin::signed(1);2152 let origin2 = RuntimeOrigin::signed(2);21532154 assert_ok!(Unique::set_collection_permissions(2155 origin1.clone(),2156 collection_id,2157 CollectionPermissions {2158 mint_mode: Some(false),2159 access: Some(AccessMode::AllowList),2160 nesting: None,2161 }2162 ));2163 assert_ok!(Unique::add_to_allow_list(2164 origin1,2165 collection_id,2166 account(2)2167 ));21682169 assert_noop!(2170 Unique::create_item(2171 origin2,2172 CollectionId(1),2173 account(2),2174 default_nft_data().into()2175 )2176 .map_err(|e| e.error),2177 CommonError::<Test>::PublicMintingNotAllowed2178 );2179 });2180}21812182// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.2183#[test]2184fn allow_list_test_12() {2185 new_test_ext().execute_with(|| {2186 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21872188 let origin1 = RuntimeOrigin::signed(1);2189 let origin2 = RuntimeOrigin::signed(2);21902191 assert_ok!(Unique::set_collection_permissions(2192 origin1.clone(),2193 collection_id,2194 CollectionPermissions {2195 mint_mode: Some(false),2196 access: Some(AccessMode::AllowList),2197 nesting: None,2198 }2199 ));22002201 assert_noop!(2202 Unique::create_item(2203 origin2,2204 CollectionId(1),2205 account(2),2206 default_nft_data().into()2207 )2208 .map_err(|e| e.error),2209 CommonError::<Test>::PublicMintingNotAllowed2210 );2211 });2212}22132214// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2215#[test]2216fn allow_list_test_13() {2217 new_test_ext().execute_with(|| {2218 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22192220 let origin1 = RuntimeOrigin::signed(1);22212222 assert_ok!(Unique::set_collection_permissions(2223 origin1.clone(),2224 collection_id,2225 CollectionPermissions {2226 mint_mode: Some(true),2227 access: Some(AccessMode::AllowList),2228 nesting: None,2229 }2230 ));22312232 let data = default_nft_data();2233 create_test_item(collection_id, &data.into());2234 });2235}22362237// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2238#[test]2239fn allow_list_test_14() {2240 new_test_ext().execute_with(|| {2241 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22422243 let origin1 = RuntimeOrigin::signed(1);2244 let origin2 = RuntimeOrigin::signed(2);22452246 assert_ok!(Unique::set_collection_permissions(2247 origin1.clone(),2248 collection_id,2249 CollectionPermissions {2250 mint_mode: Some(true),2251 access: Some(AccessMode::AllowList),2252 nesting: None,2253 }2254 ));22552256 assert_ok!(Unique::add_collection_admin(2257 origin1,2258 collection_id,2259 account(2)2260 ));22612262 assert_ok!(Unique::create_item(2263 origin2,2264 collection_id,2265 account(2),2266 default_nft_data().into()2267 ));2268 });2269}22702271// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.2272#[test]2273fn allow_list_test_15() {2274 new_test_ext().execute_with(|| {2275 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22762277 let origin1 = RuntimeOrigin::signed(1);2278 let origin2 = RuntimeOrigin::signed(2);22792280 assert_ok!(Unique::set_collection_permissions(2281 origin1.clone(),2282 collection_id,2283 CollectionPermissions {2284 mint_mode: Some(true),2285 access: Some(AccessMode::AllowList),2286 nesting: None,2287 }2288 ));22892290 assert_noop!(2291 Unique::create_item(2292 origin2,2293 collection_id,2294 account(2),2295 default_nft_data().into()2296 )2297 .map_err(|e| e.error),2298 CommonError::<Test>::AddressNotInAllowlist2299 );2300 });2301}23022303// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.2304#[test]2305fn allow_list_test_16() {2306 new_test_ext().execute_with(|| {2307 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23082309 let origin1 = RuntimeOrigin::signed(1);2310 let origin2 = RuntimeOrigin::signed(2);23112312 assert_ok!(Unique::set_collection_permissions(2313 origin1.clone(),2314 collection_id,2315 CollectionPermissions {2316 mint_mode: Some(true),2317 access: Some(AccessMode::AllowList),2318 nesting: None,2319 }2320 ));2321 assert_ok!(Unique::add_to_allow_list(2322 origin1,2323 collection_id,2324 account(2)2325 ));23262327 assert_ok!(Unique::create_item(2328 origin2,2329 collection_id,2330 account(2),2331 default_nft_data().into()2332 ));2333 });2334}23352336// Total number of collections. Positive test2337#[test]2338fn total_number_collections_bound() {2339 new_test_ext().execute_with(|| {2340 create_test_collection(&CollectionMode::NFT, CollectionId(1));2341 });2342}23432344#[test]2345fn create_max_collections() {2346 new_test_ext().execute_with(|| {2347 for i in 1..COLLECTION_NUMBER_LIMIT {2348 create_test_collection(&CollectionMode::NFT, CollectionId(i));2349 }2350 });2351}23522353// Total number of collections. Negative test2354#[test]2355fn total_number_collections_bound_neg() {2356 new_test_ext().execute_with(|| {2357 let origin1 = RuntimeOrigin::signed(1);23582359 for i in 1..=COLLECTION_NUMBER_LIMIT {2360 create_test_collection(&CollectionMode::NFT, CollectionId(i));2361 }23622363 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2364 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2365 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23662367 let data: CreateCollectionData<u64> = CreateCollectionData {2368 name: col_name1.try_into().unwrap(),2369 description: col_desc1.try_into().unwrap(),2370 token_prefix: token_prefix1.try_into().unwrap(),2371 mode: CollectionMode::NFT,2372 ..Default::default()2373 };23742375 // 11-th collection in chain. Expects error2376 assert_noop!(2377 Unique::create_collection_ex(origin1, data),2378 CommonError::<Test>::TotalCollectionsLimitExceeded2379 );2380 });2381}23822383// Owned tokens by a single address. Positive test2384#[test]2385fn owned_tokens_bound() {2386 new_test_ext().execute_with(|| {2387 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23882389 let data = default_nft_data();2390 create_test_item(collection_id, &data.clone().into());2391 create_test_item(collection_id, &data.into());2392 });2393}23942395// Owned tokens by a single address. Negotive test2396#[test]2397fn owned_tokens_bound_neg() {2398 new_test_ext().execute_with(|| {2399 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24002401 let origin1 = RuntimeOrigin::signed(1);24022403 for _ in 1..=MAX_TOKEN_OWNERSHIP {2404 let data = default_nft_data();2405 create_test_item(collection_id, &data.clone().into());2406 }24072408 let data = default_nft_data();2409 assert_noop!(2410 Unique::create_item(origin1, CollectionId(1), account(1), data.into())2411 .map_err(|e| e.error),2412 CommonError::<Test>::AccountTokenLimitExceeded2413 );2414 });2415}24162417// Number of collection admins. Positive test2418#[test]2419fn collection_admins_bound() {2420 new_test_ext().execute_with(|| {2421 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24222423 let origin1 = RuntimeOrigin::signed(1);24242425 assert_ok!(Unique::add_collection_admin(2426 origin1.clone(),2427 collection_id,2428 account(2)2429 ));2430 assert_ok!(Unique::add_collection_admin(2431 origin1,2432 collection_id,2433 account(3)2434 ));2435 });2436}24372438// Number of collection admins. Negotive test2439#[test]2440fn collection_admins_bound_neg() {2441 new_test_ext().execute_with(|| {2442 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24432444 let origin1 = RuntimeOrigin::signed(1);24452446 for i in 0..COLLECTION_ADMINS_LIMIT {2447 assert_ok!(Unique::add_collection_admin(2448 origin1.clone(),2449 collection_id,2450 account((2 + i).into())2451 ));2452 }2453 assert_noop!(2454 Unique::add_collection_admin(2455 origin1,2456 collection_id,2457 account((3 + COLLECTION_ADMINS_LIMIT).into())2458 ),2459 CommonError::<Test>::CollectionAdminCountExceeded2460 );2461 });2462}2463// #endregion24642465#[test]2466fn collection_transfer_flag_works() {2467 new_test_ext().execute_with(|| {2468 let origin1 = RuntimeOrigin::signed(1);24692470 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2471 assert_ok!(Unique::set_transfers_enabled_flag(2472 origin1,2473 collection_id,2474 true2475 ));24762477 let data = default_nft_data();2478 create_test_item(collection_id, &data.into());2479 assert_eq!(2480 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2481 12482 );2483 assert_eq!(2484 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2485 true2486 );24872488 let origin1 = RuntimeOrigin::signed(1);24892490 // default scenario2491 assert_ok!(Unique::transfer(2492 origin1,2493 account(2),2494 collection_id,2495 TokenId(1),2496 12497 ));2498 assert_eq!(2499 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2500 false2501 );2502 assert_eq!(2503 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2504 true2505 );2506 assert_eq!(2507 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2508 02509 );2510 assert_eq!(2511 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2512 12513 );2514 });2515}25162517#[test]2518fn collection_transfer_flag_works_neg() {2519 new_test_ext().execute_with(|| {2520 let origin1 = RuntimeOrigin::signed(1);25212522 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2523 assert_ok!(Unique::set_transfers_enabled_flag(2524 origin1,2525 collection_id,2526 false2527 ));25282529 let data = default_nft_data();2530 create_test_item(collection_id, &data.into());2531 assert_eq!(2532 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2533 12534 );2535 assert_eq!(2536 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2537 true2538 );25392540 let origin1 = RuntimeOrigin::signed(1);25412542 // default scenario2543 assert_noop!(2544 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2545 .map_err(|e| e.error),2546 CommonError::<Test>::TransferNotAllowed2547 );2548 assert_eq!(2549 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2550 12551 );2552 assert_eq!(2553 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2554 02555 );2556 assert_eq!(2557 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2558 true2559 );2560 assert_eq!(2561 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2562 false2563 );2564 });2565}25662567#[test]2568fn collection_sponsoring() {2569 new_test_ext().execute_with(|| {2570 // default_limits();2571 let user1 = 1_u64;2572 let user2 = 777_u64;2573 let origin1 = RuntimeOrigin::signed(user1);2574 let origin2 = RuntimeOrigin::signed(user2);2575 let account2 = account(user2);25762577 let collection_id =2578 create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));2579 assert_ok!(Unique::set_collection_sponsor(2580 origin1.clone(),2581 collection_id,2582 user12583 ));2584 assert_ok!(Unique::confirm_sponsorship(origin1.clone(), collection_id));25852586 // Expect error while have no permissions2587 assert!(Unique::create_item(2588 origin2.clone(),2589 collection_id,2590 account2.clone(),2591 default_nft_data().into()2592 )2593 .is_err());25942595 assert_ok!(Unique::set_collection_permissions(2596 origin1.clone(),2597 collection_id,2598 CollectionPermissions {2599 mint_mode: Some(true),2600 access: Some(AccessMode::AllowList),2601 nesting: None,2602 }2603 ));2604 assert_ok!(Unique::add_to_allow_list(2605 origin1.clone(),2606 collection_id,2607 account2.clone()2608 ));26092610 assert_ok!(Unique::create_item(2611 origin2,2612 collection_id,2613 account2,2614 default_nft_data().into()2615 ));2616 });2617}26182619mod check_token_permissions {2620 use super::*;2621 use frame_support::once_cell::sync::Lazy;2622 use pallet_common::LazyValue;2623 use sp_runtime::DispatchError;26242625 fn test<FTE: FnOnce() -> bool>(2626 i: usize,2627 test_case: &pallet_common::tests::TestCase,2628 check_token_existence: &mut LazyValue<bool, FTE>,2629 ) {2630 let collection_admin = test_case.collection_admin;2631 let mut is_collection_admin = LazyValue::new(|| test_case.is_collection_admin);2632 let token_owner = test_case.token_owner;2633 let mut is_token_owner = LazyValue::new(|| Ok(test_case.is_token_owner));2634 let is_no_permission = test_case.no_permission;26352636 let result = pallet_common::tests::check_token_permissions::<Test, _, _, FTE>(2637 collection_admin,2638 token_owner,2639 &mut is_collection_admin,2640 &mut is_token_owner,2641 check_token_existence,2642 );26432644 if is_no_permission {2645 assert!(2646 result.is_err(),2647 "{i}: {test_case:?}, token_exist: {}",2648 check_token_existence.value()2649 );2650 assert_err!(result, pallet_common::Error::<Test>::NoPermission,);2651 } else if check_token_existence.has_value() && !check_token_existence.value() {2652 assert!(2653 result.is_err(),2654 "{i}: {test_case:?}, token_exist: {}",2655 check_token_existence.value()2656 );2657 assert_err!(result, pallet_common::Error::<Test>::TokenNotFound,);2658 }2659 }26602661 #[test]2662 fn no_permission_only() {2663 new_test_ext().execute_with(|| {2664 let mut check_token_existence = LazyValue::new(|| true);2665 for (i, row) in pallet_common::tests::table.iter().enumerate() {2666 test(i, row, &mut check_token_existence);2667 }2668 });2669 }26702671 #[test]2672 fn no_permission_and_token_not_found() {2673 new_test_ext().execute_with(|| {2674 for (i, row) in pallet_common::tests::table.iter().enumerate() {2675 // This is inside the loop to keep track of whether the lambda was called2676 let mut check_token_existence = LazyValue::new(|| false);2677 test(i, row, &mut check_token_existence);2678 }2679 });2680 }2681}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Tests to be written here18use crate::{Test, TestCrossAccountId, CollectionCreationPrice, RuntimeOrigin, Unique, new_test_ext};19use up_data_structs::{20 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,21 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, TokenId,22 MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionMode, AccessMode, CollectionPermissions,23 PropertyKeyPermission, PropertyPermission, Property, CollectionPropertiesVec,24 CollectionPropertiesPermissionsVec,25};26use frame_support::{assert_noop, assert_ok, assert_err};27use sp_std::convert::TryInto;28use pallet_evm::account::CrossAccountId;29use pallet_common::Error as CommonError;30use pallet_unique::Error as UniqueError;3132fn add_balance(user: u64, value: u64) {33 const DONOR_USER: u64 = 999;34 assert_ok!(<pallet_balances::Pallet<Test>>::force_set_balance(35 RuntimeOrigin::root(),36 DONOR_USER,37 value,38 ));39 assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(40 RuntimeOrigin::root(),41 DONOR_USER,42 user,43 value44 ));45}4647fn default_nft_data() -> CreateNftData {48 CreateNftData {49 properties: vec![Property {50 key: b"test-prop".to_vec().try_into().unwrap(),51 value: b"test-nft-prop".to_vec().try_into().unwrap(),52 }]53 .try_into()54 .unwrap(),55 }56}5758fn default_fungible_data() -> CreateFungibleData {59 CreateFungibleData { value: 5 }60}6162fn default_re_fungible_data() -> CreateReFungibleData {63 CreateReFungibleData {64 pieces: 1023,65 properties: vec![Property {66 key: b"test-prop".to_vec().try_into().unwrap(),67 value: b"test-nft-prop".to_vec().try_into().unwrap(),68 }]69 .try_into()70 .unwrap(),71 }72}7374fn create_test_collection_for_owner(75 mode: &CollectionMode,76 owner: u64,77 id: CollectionId,78) -> CollectionId {79 add_balance(owner, CollectionCreationPrice::get() as u64 + 1);8081 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();82 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();83 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();84 let token_property_permissions: CollectionPropertiesPermissionsVec =85 vec![PropertyKeyPermission {86 key: b"test-prop".to_vec().try_into().unwrap(),87 permission: PropertyPermission {88 mutable: true,89 collection_admin: false,90 token_owner: true,91 },92 }]93 .try_into()94 .unwrap();95 let properties: CollectionPropertiesVec = vec![Property {96 key: b"test-collection-prop".to_vec().try_into().unwrap(),97 value: b"test-collection-value".to_vec().try_into().unwrap(),98 }]99 .try_into()100 .unwrap();101102 let data = CreateCollectionData {103 name: col_name1.try_into().unwrap(),104 description: col_desc1.try_into().unwrap(),105 token_prefix: token_prefix1.try_into().unwrap(),106 mode: mode.clone(),107 token_property_permissions: token_property_permissions.clone(),108 properties: properties.clone(),109 ..Default::default()110 };111112 let origin1 = RuntimeOrigin::signed(owner);113 assert_ok!(Unique::create_collection_ex(origin1, data));114115 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();116 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();117 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();118 assert_eq!(119 <pallet_common::CollectionById<Test>>::get(id)120 .unwrap()121 .owner,122 owner123 );124 assert_eq!(125 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,126 saved_col_name127 );128 assert_eq!(129 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,130 *mode131 );132 assert_eq!(133 <pallet_common::CollectionById<Test>>::get(id)134 .unwrap()135 .description,136 saved_description137 );138 assert_eq!(139 <pallet_common::CollectionById<Test>>::get(id)140 .unwrap()141 .token_prefix,142 saved_prefix143 );144 assert_eq!(145 get_collection_property_permissions(id).as_slice(),146 token_property_permissions.as_slice()147 );148 assert_eq!(149 get_collection_properties(id).as_slice(),150 properties.as_slice()151 );152 id153}154155fn get_collection_property_permissions(collection_id: CollectionId) -> Vec<PropertyKeyPermission> {156 <pallet_common::Pallet<Test>>::property_permissions(collection_id)157 .into_iter()158 .map(|(key, permission)| PropertyKeyPermission { key, permission })159 .collect()160}161162fn get_collection_properties(collection_id: CollectionId) -> Vec<Property> {163 <pallet_common::Pallet<Test>>::collection_properties(collection_id)164 .into_iter()165 .map(|(key, value)| Property { key, value })166 .collect()167}168169fn get_token_properties(collection_id: CollectionId, token_id: TokenId) -> Vec<Property> {170 <pallet_nonfungible::Pallet<Test>>::token_properties((collection_id, token_id))171 .into_iter()172 .map(|(key, value)| Property { key, value })173 .collect()174}175176fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {177 create_test_collection_for_owner(&mode, 1, id)178}179180fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {181 let origin1 = RuntimeOrigin::signed(1);182 assert_ok!(Unique::create_item(183 origin1,184 collection_id,185 account(1),186 data.clone()187 ));188}189190fn account(sub: u64) -> TestCrossAccountId {191 TestCrossAccountId::from_sub(sub)192}193194// Use cases tests region195// #region196197#[test]198fn check_not_sufficient_founds() {199 new_test_ext().execute_with(|| {200 let acc: u64 = 1;201 <pallet_balances::Pallet<Test>>::force_set_balance(RuntimeOrigin::root(), acc, 0).unwrap();202203 let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();204 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();205 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();206207 let data = CreateCollectionData {208 name: name.try_into().unwrap(),209 description: description.try_into().unwrap(),210 token_prefix: token_prefix.try_into().unwrap(),211 mode: CollectionMode::NFT,212 ..Default::default()213 };214215 let result = Unique::create_collection_ex(RuntimeOrigin::signed(acc), data);216 assert_err!(result, <CommonError<Test>>::NotSufficientFounds);217 });218}219220#[test]221fn create_fungible_collection_fails_with_large_decimal_numbers() {222 new_test_ext().execute_with(|| {223 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();224 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();225 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();226227 let data = CreateCollectionData {228 name: col_name1.try_into().unwrap(),229 description: col_desc1.try_into().unwrap(),230 token_prefix: token_prefix1.try_into().unwrap(),231 mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),232 ..Default::default()233 };234235 let origin1 = RuntimeOrigin::signed(1);236 assert_noop!(237 Unique::create_collection_ex(origin1, data),238 UniqueError::<Test>::CollectionDecimalPointLimitExceeded239 );240 });241}242243#[test]244fn create_nft_item() {245 new_test_ext().execute_with(|| {246 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));247248 let data = default_nft_data();249 create_test_item(collection_id, &data.clone().into());250251 assert_eq!(252 get_token_properties(collection_id, TokenId(1)).as_slice(),253 data.properties.as_slice(),254 );255 });256}257258// Use cases tests region259// #region260#[test]261fn create_nft_multiple_items() {262 new_test_ext().execute_with(|| {263 create_test_collection(&CollectionMode::NFT, CollectionId(1));264265 let origin1 = RuntimeOrigin::signed(1);266267 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];268269 assert_ok!(Unique::create_multiple_items(270 origin1,271 CollectionId(1),272 account(1),273 items_data274 .clone()275 .into_iter()276 .map(|d| { d.into() })277 .collect()278 ));279 for (index, data) in items_data.into_iter().enumerate() {280 assert_eq!(281 get_token_properties(CollectionId(1), TokenId(index as u32 + 1)).as_slice(),282 data.properties.as_slice()283 );284 }285 });286}287288#[test]289fn create_refungible_item() {290 new_test_ext().execute_with(|| {291 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));292293 let data = default_re_fungible_data();294 create_test_item(collection_id, &data.clone().into());295 let balance =296 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));297 assert_eq!(balance, 1023);298 });299}300301#[test]302fn create_multiple_refungible_items() {303 new_test_ext().execute_with(|| {304 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));305306 let origin1 = RuntimeOrigin::signed(1);307308 let items_data = vec![309 default_re_fungible_data(),310 default_re_fungible_data(),311 default_re_fungible_data(),312 ];313314 assert_ok!(Unique::create_multiple_items(315 origin1,316 CollectionId(1),317 account(1),318 items_data319 .clone()320 .into_iter()321 .map(|d| { d.into() })322 .collect()323 ));324 for (index, _data) in items_data.into_iter().enumerate() {325 let balance = <pallet_refungible::Balance<Test>>::get((326 CollectionId(1),327 TokenId((index + 1) as u32),328 account(1),329 ));330 assert_eq!(balance, 1023);331 }332 });333}334335#[test]336fn create_fungible_item() {337 new_test_ext().execute_with(|| {338 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));339340 let data = default_fungible_data();341 create_test_item(collection_id, &data.into());342343 assert_eq!(344 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),345 5346 );347 });348}349350//#[test]351// fn create_multiple_fungible_items() {352// new_test_ext().execute_with(|| {353// default_limits();354355// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));356357// let origin1 = RuntimeOrigin::signed(1);358359// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];360361// assert_ok!(Unique::create_multiple_items(362// origin1.clone(),363// 1,364// 1,365// items_data.clone().into_iter().map(|d| { d.into() }).collect()366// ));367368// for (index, _) in items_data.iter().enumerate() {369// assert_eq!(Unique::fungible_item_id(1, (index + 1) as TokenId).value, 5);370// }371// assert_eq!(Unique::balance_count(1, 1), 3000);372// assert_eq!(Unique::address_tokens(1, 1), [1, 2, 3]);373// });374// }375376#[test]377fn transfer_fungible_item() {378 new_test_ext().execute_with(|| {379 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));380381 let origin1 = RuntimeOrigin::signed(1);382 let origin2 = RuntimeOrigin::signed(2);383384 let data = default_fungible_data();385 create_test_item(collection_id, &data.into());386387 assert_eq!(388 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),389 5390 );391392 // change owner scenario393 assert_ok!(Unique::transfer(394 origin1,395 account(2),396 CollectionId(1),397 TokenId(0),398 5399 ));400 assert_eq!(401 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),402 0403 );404405 // split item scenario406 assert_ok!(Unique::transfer(407 origin2.clone(),408 account(3),409 CollectionId(1),410 TokenId(0),411 3412 ));413414 // split item and new owner has account scenario415 assert_ok!(Unique::transfer(416 origin2,417 account(3),418 CollectionId(1),419 TokenId(0),420 1421 ));422 assert_eq!(423 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),424 1425 );426 assert_eq!(427 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),428 4429 );430 });431}432433#[test]434fn transfer_refungible_item() {435 new_test_ext().execute_with(|| {436 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));437438 // Create RFT 1 in 1023 pieces for account 1439 let data = default_re_fungible_data();440 create_test_item(collection_id, &data.clone().into());441 assert_eq!(442 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),443 1444 );445 assert_eq!(446 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),447 1023448 );449 assert_eq!(450 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),451 true452 );453454 // Account 1 transfers all 1023 pieces of RFT 1 to account 2455 let origin1 = RuntimeOrigin::signed(1);456 let origin2 = RuntimeOrigin::signed(2);457 assert_ok!(Unique::transfer(458 origin1,459 account(2),460 CollectionId(1),461 TokenId(1),462 1023463 ));464 assert_eq!(465 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),466 1023467 );468 assert_eq!(469 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),470 0471 );472 assert_eq!(473 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),474 1475 );476 assert_eq!(477 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),478 false479 );480 assert_eq!(481 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),482 true483 );484485 // Account 2 transfers 500 pieces of RFT 1 to account 3486 assert_ok!(Unique::transfer(487 origin2.clone(),488 account(3),489 CollectionId(1),490 TokenId(1),491 500492 ));493 assert_eq!(494 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),495 523496 );497 assert_eq!(498 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),499 500500 );501 assert_eq!(502 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),503 1504 );505 assert_eq!(506 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),507 1508 );509 assert_eq!(510 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),511 true512 );513 assert_eq!(514 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),515 true516 );517518 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance519 assert_ok!(Unique::transfer(520 origin2,521 account(3),522 CollectionId(1),523 TokenId(1),524 200525 ));526 assert_eq!(527 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),528 323529 );530 assert_eq!(531 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),532 700533 );534 assert_eq!(535 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),536 1537 );538 assert_eq!(539 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),540 1541 );542 assert_eq!(543 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),544 true545 );546 assert_eq!(547 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),548 true549 );550 });551}552553#[test]554fn transfer_nft_item() {555 new_test_ext().execute_with(|| {556 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));557558 let data = default_nft_data();559 create_test_item(collection_id, &data.into());560 assert_eq!(561 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),562 1563 );564 assert_eq!(565 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),566 true567 );568569 let origin1 = RuntimeOrigin::signed(1);570 // default scenario571 assert_ok!(Unique::transfer(572 origin1,573 account(2),574 CollectionId(1),575 TokenId(1),576 1577 ));578 assert_eq!(579 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),580 0581 );582 assert_eq!(583 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),584 1585 );586 assert_eq!(587 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),588 false589 );590 assert_eq!(591 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),592 true593 );594 });595}596597#[test]598fn transfer_nft_item_wrong_value() {599 new_test_ext().execute_with(|| {600 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));601602 let data = default_nft_data();603 create_test_item(collection_id, &data.into());604 assert_eq!(605 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),606 1607 );608 assert_eq!(609 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),610 true611 );612613 let origin1 = RuntimeOrigin::signed(1);614615 assert_noop!(616 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)617 .map_err(|e| e.error),618 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount619 );620 });621}622623#[test]624fn transfer_nft_item_zero_value() {625 new_test_ext().execute_with(|| {626 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));627628 let data = default_nft_data();629 create_test_item(collection_id, &data.into());630 assert_eq!(631 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),632 1633 );634 assert_eq!(635 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),636 true637 );638639 let origin1 = RuntimeOrigin::signed(1);640641 // Transferring 0 amount works on NFT...642 assert_ok!(Unique::transfer(643 origin1,644 account(2),645 CollectionId(1),646 TokenId(1),647 0648 ));649 // ... and results in no transfer650 assert_eq!(651 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),652 1653 );654 assert_eq!(655 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),656 true657 );658 });659}660661#[test]662fn nft_approve_and_transfer_from() {663 new_test_ext().execute_with(|| {664 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));665666 let data = default_nft_data();667 create_test_item(collection_id, &data.into());668669 let origin1 = RuntimeOrigin::signed(1);670 let origin2 = RuntimeOrigin::signed(2);671672 assert_eq!(673 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),674 1675 );676 assert_eq!(677 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),678 true679 );680681 // neg transfer_from682 assert_noop!(683 Unique::transfer_from(684 origin2.clone(),685 account(1),686 account(2),687 CollectionId(1),688 TokenId(1),689 1690 )691 .map_err(|e| e.error),692 CommonError::<Test>::ApprovedValueTooLow693 );694695 // do approve696 assert_ok!(Unique::approve(697 origin1,698 account(2),699 CollectionId(1),700 TokenId(1),701 1702 ));703 assert_eq!(704 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),705 account(2)706 );707708 assert_ok!(Unique::transfer_from(709 origin2,710 account(1),711 account(3),712 CollectionId(1),713 TokenId(1),714 1715 ));716 assert!(717 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()718 );719 });720}721722#[test]723fn nft_approve_and_transfer_from_allow_list() {724 new_test_ext().execute_with(|| {725 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));726727 let origin1 = RuntimeOrigin::signed(1);728 let origin2 = RuntimeOrigin::signed(2);729730 // Create NFT 1 for account 1731 let data = default_nft_data();732 create_test_item(collection_id, &data.clone().into());733 assert_eq!(734 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),735 1736 );737 assert_eq!(738 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),739 true740 );741742 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list743 assert_ok!(Unique::set_collection_permissions(744 origin1.clone(),745 CollectionId(1),746 CollectionPermissions {747 mint_mode: Some(true),748 access: Some(AccessMode::AllowList),749 nesting: None,750 }751 ));752 assert_ok!(Unique::add_to_allow_list(753 origin1.clone(),754 CollectionId(1),755 account(1)756 ));757 assert_ok!(Unique::add_to_allow_list(758 origin1.clone(),759 CollectionId(1),760 account(2)761 ));762 assert_ok!(Unique::add_to_allow_list(763 origin1.clone(),764 CollectionId(1),765 account(3)766 ));767768 // Account 1 approves account 2 for NFT 1769 assert_ok!(Unique::approve(770 origin1.clone(),771 account(2),772 CollectionId(1),773 TokenId(1),774 1775 ));776 assert_eq!(777 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),778 account(2)779 );780781 // Account 2 transfers NFT 1 from account 1 to account 3782 assert_ok!(Unique::transfer_from(783 origin2,784 account(1),785 account(3),786 CollectionId(1),787 TokenId(1),788 1789 ));790 assert!(791 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()792 );793 });794}795796#[test]797fn refungible_approve_and_transfer_from() {798 new_test_ext().execute_with(|| {799 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));800801 let origin1 = RuntimeOrigin::signed(1);802 let origin2 = RuntimeOrigin::signed(2);803804 // Create RFT 1 in 1023 pieces for account 1805 let data = default_re_fungible_data();806 create_test_item(collection_id, &data.into());807808 assert_eq!(809 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),810 1811 );812 assert_eq!(813 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),814 1023815 );816 assert_eq!(817 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),818 true819 );820821 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list822 assert_ok!(Unique::set_collection_permissions(823 origin1.clone(),824 CollectionId(1),825 CollectionPermissions {826 mint_mode: Some(true),827 access: Some(AccessMode::AllowList),828 nesting: None,829 }830 ));831 assert_ok!(Unique::add_to_allow_list(832 origin1.clone(),833 CollectionId(1),834 account(1)835 ));836 assert_ok!(Unique::add_to_allow_list(837 origin1.clone(),838 CollectionId(1),839 account(2)840 ));841 assert_ok!(Unique::add_to_allow_list(842 origin1.clone(),843 CollectionId(1),844 account(3)845 ));846847 // Account 1 approves account 2 for 1023 pieces of RFT 1848 assert_ok!(Unique::approve(849 origin1,850 account(2),851 CollectionId(1),852 TokenId(1),853 1023854 ));855 assert_eq!(856 <pallet_refungible::Allowance<Test>>::get((857 CollectionId(1),858 TokenId(1),859 account(1),860 account(2)861 )),862 1023863 );864865 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3866 assert_ok!(Unique::transfer_from(867 origin2,868 account(1),869 account(3),870 CollectionId(1),871 TokenId(1),872 100873 ));874 assert_eq!(875 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),876 1877 );878 assert_eq!(879 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),880 1881 );882 assert_eq!(883 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),884 923885 );886 assert_eq!(887 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),888 100889 );890 assert_eq!(891 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),892 true893 );894 assert_eq!(895 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),896 true897 );898 assert_eq!(899 <pallet_refungible::Allowance<Test>>::get((900 CollectionId(1),901 TokenId(1),902 account(1),903 account(2)904 )),905 923906 );907 });908}909910#[test]911fn fungible_approve_and_transfer_from() {912 new_test_ext().execute_with(|| {913 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));914915 let data = default_fungible_data();916 create_test_item(collection_id, &data.into());917918 let origin1 = RuntimeOrigin::signed(1);919 let origin2 = RuntimeOrigin::signed(2);920921 assert_ok!(Unique::set_collection_permissions(922 origin1.clone(),923 CollectionId(1),924 CollectionPermissions {925 mint_mode: Some(true),926 access: Some(AccessMode::AllowList),927 nesting: None,928 }929 ));930 assert_ok!(Unique::add_to_allow_list(931 origin1.clone(),932 CollectionId(1),933 account(1)934 ));935 assert_ok!(Unique::add_to_allow_list(936 origin1.clone(),937 CollectionId(1),938 account(2)939 ));940 assert_ok!(Unique::add_to_allow_list(941 origin1.clone(),942 CollectionId(1),943 account(3)944 ));945946 // do approve947 assert_ok!(Unique::approve(948 origin1.clone(),949 account(2),950 CollectionId(1),951 TokenId(0),952 5953 ));954 assert_eq!(955 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),956 5957 );958 assert_ok!(Unique::approve(959 origin1,960 account(3),961 CollectionId(1),962 TokenId(0),963 5964 ));965 assert_eq!(966 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),967 5968 );969 assert_eq!(970 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),971 5972 );973974 assert_ok!(Unique::transfer_from(975 origin2.clone(),976 account(1),977 account(3),978 CollectionId(1),979 TokenId(0),980 4981 ));982983 assert_eq!(984 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),985 1986 );987988 assert_noop!(989 Unique::transfer_from(990 origin2,991 account(1),992 account(3),993 CollectionId(1),994 TokenId(0),995 4996 )997 .map_err(|e| e.error),998 CommonError::<Test>::ApprovedValueTooLow999 );1000 });1001}10021003#[test]1004fn change_collection_owner() {1005 new_test_ext().execute_with(|| {1006 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10071008 let origin1 = RuntimeOrigin::signed(1);1009 assert_ok!(Unique::change_collection_owner(origin1, collection_id, 2));1010 assert_eq!(1011 <pallet_common::CollectionById<Test>>::get(collection_id)1012 .unwrap()1013 .owner,1014 21015 );1016 });1017}10181019#[test]1020fn destroy_collection() {1021 new_test_ext().execute_with(|| {1022 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10231024 let origin1 = RuntimeOrigin::signed(1);1025 assert_ok!(Unique::destroy_collection(origin1, collection_id));1026 });1027}10281029#[test]1030fn burn_nft_item() {1031 new_test_ext().execute_with(|| {1032 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10331034 let origin1 = RuntimeOrigin::signed(1);10351036 let data = default_nft_data();1037 create_test_item(collection_id, &data.into());10381039 // check balance (collection with id = 1, user id = 1)1040 assert_eq!(1041 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1042 11043 );10441045 // burn item1046 assert_ok!(Unique::burn_item(1047 origin1.clone(),1048 collection_id,1049 TokenId(1),1050 11051 ));1052 assert_eq!(1053 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1054 01055 );1056 });1057}10581059#[test]1060fn burn_same_nft_item_twice() {1061 new_test_ext().execute_with(|| {1062 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10631064 let origin1 = RuntimeOrigin::signed(1);10651066 let data = default_nft_data();1067 create_test_item(collection_id, &data.into());10681069 // check balance (collection with id = 1, user id = 1)1070 assert_eq!(1071 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1072 11073 );10741075 // burn item1076 assert_ok!(Unique::burn_item(1077 origin1.clone(),1078 collection_id,1079 TokenId(1),1080 11081 ));10821083 // burn item again1084 assert_noop!(1085 Unique::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1086 CommonError::<Test>::TokenNotFound1087 );10881089 assert_eq!(1090 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1091 01092 );1093 });1094}10951096#[test]1097fn burn_fungible_item() {1098 new_test_ext().execute_with(|| {1099 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11001101 let origin1 = RuntimeOrigin::signed(1);1102 assert_ok!(Unique::add_collection_admin(1103 origin1.clone(),1104 collection_id,1105 account(2)1106 ));11071108 let data = default_fungible_data();1109 create_test_item(collection_id, &data.into());11101111 // check balance (collection with id = 1, user id = 1)1112 assert_eq!(1113 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1114 51115 );11161117 // burn item1118 assert_ok!(Unique::burn_item(1119 origin1.clone(),1120 CollectionId(1),1121 TokenId(0),1122 51123 ));1124 assert_noop!(1125 Unique::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1126 CommonError::<Test>::TokenValueTooLow1127 );11281129 assert_eq!(1130 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1131 01132 );1133 });1134}11351136#[test]1137fn burn_fungible_item_with_token_id() {1138 new_test_ext().execute_with(|| {1139 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11401141 let origin1 = RuntimeOrigin::signed(1);1142 assert_ok!(Unique::add_collection_admin(1143 origin1.clone(),1144 collection_id,1145 account(2)1146 ));11471148 let data = default_fungible_data();1149 create_test_item(collection_id, &data.into());11501151 // check balance (collection with id = 1, user id = 1)1152 assert_eq!(1153 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1154 51155 );11561157 // Try to burn item using Token ID1158 assert_noop!(1159 Unique::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1160 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1161 );1162 });1163}1164#[test]1165fn burn_refungible_item() {1166 new_test_ext().execute_with(|| {1167 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1168 let origin1 = RuntimeOrigin::signed(1);11691170 assert_ok!(Unique::set_collection_permissions(1171 origin1.clone(),1172 collection_id,1173 CollectionPermissions {1174 mint_mode: Some(true),1175 access: Some(AccessMode::AllowList),1176 nesting: None,1177 }1178 ));1179 assert_ok!(Unique::add_to_allow_list(1180 origin1.clone(),1181 collection_id,1182 account(1)1183 ));11841185 assert_ok!(Unique::add_collection_admin(1186 origin1.clone(),1187 collection_id,1188 account(2)1189 ));11901191 let data = default_re_fungible_data();1192 create_test_item(collection_id, &data.into());11931194 // check balance (collection with id = 1, user id = 2)1195 assert_eq!(1196 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1197 11198 );1199 assert_eq!(1200 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1201 10231202 );12031204 // burn item1205 assert_ok!(Unique::burn_item(1206 origin1.clone(),1207 collection_id,1208 TokenId(1),1209 10231210 ));1211 assert_noop!(1212 Unique::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error),1213 CommonError::<Test>::TokenValueTooLow1214 );12151216 assert_eq!(1217 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1218 01219 );1220 });1221}12221223#[test]1224fn add_collection_admin() {1225 new_test_ext().execute_with(|| {1226 let collection1_id =1227 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1228 let origin1 = RuntimeOrigin::signed(1);12291230 // Add collection admins1231 assert_ok!(Unique::add_collection_admin(1232 origin1.clone(),1233 collection1_id,1234 account(2)1235 ));1236 assert_ok!(Unique::add_collection_admin(1237 origin1,1238 collection1_id,1239 account(3)1240 ));12411242 // Owner is not an admin by default1243 assert_eq!(1244 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1245 false1246 );1247 assert!(<pallet_common::IsAdmin<Test>>::get((1248 CollectionId(1),1249 account(2)1250 )));1251 assert!(<pallet_common::IsAdmin<Test>>::get((1252 CollectionId(1),1253 account(3)1254 )));1255 });1256}12571258#[test]1259fn remove_collection_admin() {1260 new_test_ext().execute_with(|| {1261 let collection1_id =1262 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1263 let origin1 = RuntimeOrigin::signed(1);12641265 // Add collection admins 2 and 31266 assert_ok!(Unique::add_collection_admin(1267 origin1.clone(),1268 collection1_id,1269 account(2)1270 ));1271 assert_ok!(Unique::add_collection_admin(1272 origin1.clone(),1273 collection1_id,1274 account(3)1275 ));12761277 assert!(<pallet_common::IsAdmin<Test>>::get((1278 CollectionId(1),1279 account(2)1280 )));1281 assert!(<pallet_common::IsAdmin<Test>>::get((1282 CollectionId(1),1283 account(3)1284 )));12851286 // remove admin 31287 assert_ok!(Unique::remove_collection_admin(1288 origin1,1289 CollectionId(1),1290 account(3)1291 ));12921293 // 2 is still admin, 3 is not an admin anymore1294 assert!(<pallet_common::IsAdmin<Test>>::get((1295 CollectionId(1),1296 account(2)1297 )));1298 assert_eq!(1299 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1300 false1301 );1302 });1303}13041305#[test]1306fn balance_of() {1307 new_test_ext().execute_with(|| {1308 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1309 let fungible_collection_id =1310 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1311 let re_fungible_collection_id =1312 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));13131314 // check balance before1315 assert_eq!(1316 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1317 01318 );1319 assert_eq!(1320 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1321 01322 );1323 assert_eq!(1324 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1325 01326 );13271328 let nft_data = default_nft_data();1329 create_test_item(nft_collection_id, &nft_data.into());13301331 let fungible_data = default_fungible_data();1332 create_test_item(fungible_collection_id, &fungible_data.into());13331334 let re_fungible_data = default_re_fungible_data();1335 create_test_item(re_fungible_collection_id, &re_fungible_data.into());13361337 // check balance (collection with id = 1, user id = 1)1338 assert_eq!(1339 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1340 11341 );1342 assert_eq!(1343 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1344 51345 );1346 assert_eq!(1347 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1348 11349 );13501351 assert_eq!(1352 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1353 true1354 );1355 assert_eq!(1356 <pallet_refungible::Owned<Test>>::get((1357 re_fungible_collection_id,1358 account(1),1359 TokenId(1)1360 )),1361 true1362 );1363 });1364}13651366#[test]1367fn approve() {1368 new_test_ext().execute_with(|| {1369 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13701371 let data = default_nft_data();1372 create_test_item(collection_id, &data.into());13731374 let origin1 = RuntimeOrigin::signed(1);13751376 // approve1377 assert_ok!(Unique::approve(1378 origin1,1379 account(2),1380 CollectionId(1),1381 TokenId(1),1382 11383 ));1384 assert_eq!(1385 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1386 account(2)1387 );1388 });1389}13901391#[test]1392fn transfer_from() {1393 new_test_ext().execute_with(|| {1394 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1395 let origin1 = RuntimeOrigin::signed(1);1396 let origin2 = RuntimeOrigin::signed(2);13971398 let data = default_nft_data();1399 create_test_item(collection_id, &data.into());14001401 // approve1402 assert_ok!(Unique::approve(1403 origin1.clone(),1404 account(2),1405 CollectionId(1),1406 TokenId(1),1407 11408 ));1409 assert_eq!(1410 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1411 account(2)1412 );14131414 assert_ok!(Unique::set_collection_permissions(1415 origin1.clone(),1416 CollectionId(1),1417 CollectionPermissions {1418 mint_mode: Some(true),1419 access: Some(AccessMode::AllowList),1420 nesting: None,1421 }1422 ));1423 assert_ok!(Unique::add_to_allow_list(1424 origin1.clone(),1425 CollectionId(1),1426 account(1)1427 ));1428 assert_ok!(Unique::add_to_allow_list(1429 origin1.clone(),1430 CollectionId(1),1431 account(2)1432 ));1433 assert_ok!(Unique::add_to_allow_list(1434 origin1,1435 CollectionId(1),1436 account(3)1437 ));14381439 assert_ok!(Unique::transfer_from(1440 origin2,1441 account(1),1442 account(2),1443 CollectionId(1),1444 TokenId(1),1445 11446 ));14471448 // after transfer1449 assert_eq!(1450 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1451 01452 );1453 assert_eq!(1454 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1455 11456 );1457 });1458}14591460// #endregion14611462// Coverage tests region1463// #region14641465#[test]1466fn owner_can_add_address_to_allow_list() {1467 new_test_ext().execute_with(|| {1468 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14691470 let origin1 = RuntimeOrigin::signed(1);1471 assert_ok!(Unique::add_to_allow_list(1472 origin1,1473 collection_id,1474 account(2)1475 ));1476 assert!(<pallet_common::Allowlist<Test>>::get((1477 collection_id,1478 account(2)1479 )));1480 });1481}14821483#[test]1484fn admin_can_add_address_to_allow_list() {1485 new_test_ext().execute_with(|| {1486 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1487 let origin1 = RuntimeOrigin::signed(1);1488 let origin2 = RuntimeOrigin::signed(2);14891490 assert_ok!(Unique::add_collection_admin(1491 origin1,1492 collection_id,1493 account(2)1494 ));1495 assert_ok!(Unique::add_to_allow_list(1496 origin2,1497 collection_id,1498 account(3)1499 ));1500 assert!(<pallet_common::Allowlist<Test>>::get((1501 collection_id,1502 account(3)1503 )));1504 });1505}15061507#[test]1508fn nonprivileged_user_cannot_add_address_to_allow_list() {1509 new_test_ext().execute_with(|| {1510 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15111512 let origin2 = RuntimeOrigin::signed(2);1513 assert_noop!(1514 Unique::add_to_allow_list(origin2, collection_id, account(3)),1515 CommonError::<Test>::NoPermission1516 );1517 });1518}15191520#[test]1521fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1522 new_test_ext().execute_with(|| {1523 let origin1 = RuntimeOrigin::signed(1);15241525 assert_noop!(1526 Unique::add_to_allow_list(origin1, CollectionId(1), account(2)),1527 CommonError::<Test>::CollectionNotFound1528 );1529 });1530}15311532#[test]1533fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1534 new_test_ext().execute_with(|| {1535 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15361537 let origin1 = RuntimeOrigin::signed(1);1538 assert_ok!(Unique::destroy_collection(origin1.clone(), collection_id));1539 assert_noop!(1540 Unique::add_to_allow_list(origin1, collection_id, account(2)),1541 CommonError::<Test>::CollectionNotFound1542 );1543 });1544}15451546// If address is already added to allow list, nothing happens1547#[test]1548fn address_is_already_added_to_allow_list() {1549 new_test_ext().execute_with(|| {1550 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1551 let origin1 = RuntimeOrigin::signed(1);15521553 assert_ok!(Unique::add_to_allow_list(1554 origin1.clone(),1555 collection_id,1556 account(2)1557 ));1558 assert_ok!(Unique::add_to_allow_list(1559 origin1,1560 collection_id,1561 account(2)1562 ));1563 assert!(<pallet_common::Allowlist<Test>>::get((1564 collection_id,1565 account(2)1566 )));1567 });1568}15691570#[test]1571fn owner_can_remove_address_from_allow_list() {1572 new_test_ext().execute_with(|| {1573 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15741575 let origin1 = RuntimeOrigin::signed(1);1576 assert_ok!(Unique::add_to_allow_list(1577 origin1.clone(),1578 collection_id,1579 account(2)1580 ));1581 assert_ok!(Unique::remove_from_allow_list(1582 origin1,1583 collection_id,1584 account(2)1585 ));1586 assert_eq!(1587 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1588 false1589 );1590 });1591}15921593#[test]1594fn admin_can_remove_address_from_allow_list() {1595 new_test_ext().execute_with(|| {1596 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1597 let origin1 = RuntimeOrigin::signed(1);1598 let origin2 = RuntimeOrigin::signed(2);15991600 // Owner adds admin1601 assert_ok!(Unique::add_collection_admin(1602 origin1.clone(),1603 collection_id,1604 account(2)1605 ));16061607 // Owner adds address 3 to allow list1608 assert_ok!(Unique::add_to_allow_list(1609 origin1,1610 collection_id,1611 account(3)1612 ));16131614 // Admin removes address 3 from allow list1615 assert_ok!(Unique::remove_from_allow_list(1616 origin2,1617 collection_id,1618 account(3)1619 ));1620 assert_eq!(1621 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1622 false1623 );1624 });1625}16261627#[test]1628fn nonprivileged_user_cannot_remove_address_from_allow_list() {1629 new_test_ext().execute_with(|| {1630 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1631 let origin1 = RuntimeOrigin::signed(1);1632 let origin2 = RuntimeOrigin::signed(2);16331634 assert_ok!(Unique::add_to_allow_list(1635 origin1,1636 collection_id,1637 account(2)1638 ));1639 assert_noop!(1640 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1641 CommonError::<Test>::NoPermission1642 );1643 assert!(<pallet_common::Allowlist<Test>>::get((1644 collection_id,1645 account(2)1646 )));1647 });1648}16491650#[test]1651fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1652 new_test_ext().execute_with(|| {1653 let origin1 = RuntimeOrigin::signed(1);16541655 assert_noop!(1656 Unique::remove_from_allow_list(origin1, CollectionId(1), account(2)),1657 CommonError::<Test>::CollectionNotFound1658 );1659 });1660}16611662#[test]1663fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1664 new_test_ext().execute_with(|| {1665 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1666 let origin1 = RuntimeOrigin::signed(1);1667 let origin2 = RuntimeOrigin::signed(2);16681669 // Add account 2 to allow list1670 assert_ok!(Unique::add_to_allow_list(1671 origin1.clone(),1672 collection_id,1673 account(2)1674 ));16751676 // Account 2 is in collection allow-list1677 assert!(<pallet_common::Allowlist<Test>>::get((1678 collection_id,1679 account(2)1680 )));16811682 // Destroy collection1683 assert_ok!(Unique::destroy_collection(origin1, collection_id));16841685 // Attempt to remove account 2 from collection allow-list => error1686 assert_noop!(1687 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1688 CommonError::<Test>::CollectionNotFound1689 );16901691 // Account 2 is not found in collection allow-list anyway1692 assert_eq!(1693 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1694 false1695 );1696 });1697}16981699// If address is already removed from allow list, nothing happens1700#[test]1701fn address_is_already_removed_from_allow_list() {1702 new_test_ext().execute_with(|| {1703 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1704 let origin1 = RuntimeOrigin::signed(1);17051706 assert_ok!(Unique::add_to_allow_list(1707 origin1.clone(),1708 collection_id,1709 account(2)1710 ));1711 assert_ok!(Unique::remove_from_allow_list(1712 origin1.clone(),1713 collection_id,1714 account(2)1715 ));1716 assert_eq!(1717 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1718 false1719 );1720 assert_ok!(Unique::remove_from_allow_list(1721 origin1,1722 collection_id,1723 account(2)1724 ));1725 assert_eq!(1726 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1727 false1728 );1729 });1730}17311732// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1733#[test]1734fn allow_list_test_1() {1735 new_test_ext().execute_with(|| {1736 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17371738 let origin1 = RuntimeOrigin::signed(1);1739 assert_ok!(Unique::add_collection_admin(1740 origin1.clone(),1741 collection_id,1742 account(1)1743 ));17441745 let data = default_nft_data();1746 create_test_item(collection_id, &data.into());17471748 assert_ok!(Unique::set_collection_permissions(1749 origin1.clone(),1750 collection_id,1751 CollectionPermissions {1752 mint_mode: None,1753 access: Some(AccessMode::AllowList),1754 nesting: None,1755 }1756 ));1757 assert_ok!(Unique::add_to_allow_list(1758 origin1.clone(),1759 collection_id,1760 account(2)1761 ));17621763 assert_noop!(1764 Unique::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1765 .map_err(|e| e.error),1766 CommonError::<Test>::AddressNotInAllowlist1767 );1768 });1769}17701771#[test]1772fn allow_list_test_2() {1773 new_test_ext().execute_with(|| {1774 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1775 let origin1 = RuntimeOrigin::signed(1);17761777 let data = default_nft_data();1778 create_test_item(collection_id, &data.into());17791780 assert_ok!(Unique::set_collection_permissions(1781 origin1.clone(),1782 collection_id,1783 CollectionPermissions {1784 mint_mode: None,1785 access: Some(AccessMode::AllowList),1786 nesting: None,1787 }1788 ));1789 assert_ok!(Unique::add_to_allow_list(1790 origin1.clone(),1791 collection_id,1792 account(1)1793 ));1794 assert_ok!(Unique::add_to_allow_list(1795 origin1.clone(),1796 collection_id,1797 account(2)1798 ));17991800 // do approve1801 assert_ok!(Unique::approve(1802 origin1.clone(),1803 account(1),1804 collection_id,1805 TokenId(1),1806 11807 ));1808 assert_eq!(1809 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1810 account(1)1811 );18121813 assert_ok!(Unique::remove_from_allow_list(1814 origin1.clone(),1815 collection_id,1816 account(1)1817 ));18181819 assert_noop!(1820 Unique::transfer_from(1821 origin1,1822 account(1),1823 account(3),1824 CollectionId(1),1825 TokenId(1),1826 11827 )1828 .map_err(|e| e.error),1829 CommonError::<Test>::AddressNotInAllowlist1830 );1831 });1832}18331834// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1835#[test]1836fn allow_list_test_3() {1837 new_test_ext().execute_with(|| {1838 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18391840 let origin1 = RuntimeOrigin::signed(1);18411842 let data = default_nft_data();1843 create_test_item(collection_id, &data.into());18441845 assert_ok!(Unique::set_collection_permissions(1846 origin1.clone(),1847 collection_id,1848 CollectionPermissions {1849 mint_mode: None,1850 access: Some(AccessMode::AllowList),1851 nesting: None,1852 }1853 ));1854 assert_ok!(Unique::add_to_allow_list(1855 origin1.clone(),1856 collection_id,1857 account(1)1858 ));18591860 assert_noop!(1861 Unique::transfer(origin1, account(3), collection_id, TokenId(1), 1)1862 .map_err(|e| e.error),1863 CommonError::<Test>::AddressNotInAllowlist1864 );1865 });1866}18671868#[test]1869fn allow_list_test_4() {1870 new_test_ext().execute_with(|| {1871 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18721873 let origin1 = RuntimeOrigin::signed(1);18741875 let data = default_nft_data();1876 create_test_item(collection_id, &data.into());18771878 assert_ok!(Unique::set_collection_permissions(1879 origin1.clone(),1880 collection_id,1881 CollectionPermissions {1882 mint_mode: None,1883 access: Some(AccessMode::AllowList),1884 nesting: None,1885 }1886 ));1887 assert_ok!(Unique::add_to_allow_list(1888 origin1.clone(),1889 collection_id,1890 account(1)1891 ));1892 assert_ok!(Unique::add_to_allow_list(1893 origin1.clone(),1894 collection_id,1895 account(2)1896 ));18971898 // do approve1899 assert_ok!(Unique::approve(1900 origin1.clone(),1901 account(1),1902 collection_id,1903 TokenId(1),1904 11905 ));1906 assert_eq!(1907 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1908 account(1)1909 );19101911 assert_ok!(Unique::remove_from_allow_list(1912 origin1.clone(),1913 collection_id,1914 account(2)1915 ));19161917 assert_noop!(1918 Unique::transfer_from(1919 origin1,1920 account(1),1921 account(3),1922 collection_id,1923 TokenId(1),1924 11925 )1926 .map_err(|e| e.error),1927 CommonError::<Test>::AddressNotInAllowlist1928 );1929 });1930}19311932// If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)1933#[test]1934fn allow_list_test_5() {1935 new_test_ext().execute_with(|| {1936 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19371938 let origin1 = RuntimeOrigin::signed(1);19391940 let data = default_nft_data();1941 create_test_item(collection_id, &data.into());19421943 assert_ok!(Unique::set_collection_permissions(1944 origin1.clone(),1945 collection_id,1946 CollectionPermissions {1947 mint_mode: None,1948 access: Some(AccessMode::AllowList),1949 nesting: None,1950 }1951 ));1952 assert_noop!(1953 Unique::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),1954 CommonError::<Test>::AddressNotInAllowlist1955 );1956 });1957}19581959// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1960#[test]1961fn allow_list_test_6() {1962 new_test_ext().execute_with(|| {1963 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19641965 let origin1 = RuntimeOrigin::signed(1);19661967 let data = default_nft_data();1968 create_test_item(collection_id, &data.into());19691970 assert_ok!(Unique::set_collection_permissions(1971 origin1.clone(),1972 collection_id,1973 CollectionPermissions {1974 mint_mode: None,1975 access: Some(AccessMode::AllowList),1976 nesting: None,1977 }1978 ));19791980 // do approve1981 assert_noop!(1982 Unique::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1983 .map_err(|e| e.error),1984 CommonError::<Test>::AddressNotInAllowlist1985 );1986 });1987}19881989// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1990// tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1991#[test]1992fn allow_list_test_7() {1993 new_test_ext().execute_with(|| {1994 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19951996 let data = default_nft_data();1997 create_test_item(collection_id, &data.into());19981999 let origin1 = RuntimeOrigin::signed(1);20002001 assert_ok!(Unique::set_collection_permissions(2002 origin1.clone(),2003 collection_id,2004 CollectionPermissions {2005 mint_mode: None,2006 access: Some(AccessMode::AllowList),2007 nesting: None,2008 }2009 ));2010 assert_ok!(Unique::add_to_allow_list(2011 origin1.clone(),2012 collection_id,2013 account(1)2014 ));2015 assert_ok!(Unique::add_to_allow_list(2016 origin1.clone(),2017 collection_id,2018 account(2)2019 ));20202021 assert_ok!(Unique::transfer(2022 origin1,2023 account(2),2024 CollectionId(1),2025 TokenId(1),2026 12027 ));2028 });2029}20302031#[test]2032fn allow_list_test_8() {2033 new_test_ext().execute_with(|| {2034 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20352036 // Create NFT for account 12037 let data = default_nft_data();2038 create_test_item(collection_id, &data.into());20392040 let origin1 = RuntimeOrigin::signed(1);20412042 // Toggle Allow List mode and add accounts 1 and 22043 assert_ok!(Unique::set_collection_permissions(2044 origin1.clone(),2045 collection_id,2046 CollectionPermissions {2047 mint_mode: None,2048 access: Some(AccessMode::AllowList),2049 nesting: None,2050 }2051 ));2052 assert_ok!(Unique::add_to_allow_list(2053 origin1.clone(),2054 collection_id,2055 account(1)2056 ));2057 assert_ok!(Unique::add_to_allow_list(2058 origin1.clone(),2059 collection_id,2060 account(2)2061 ));20622063 // Sself-approve account 1 for NFT 12064 assert_ok!(Unique::approve(2065 origin1.clone(),2066 account(1),2067 CollectionId(1),2068 TokenId(1),2069 12070 ));2071 assert_eq!(2072 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2073 account(1)2074 );20752076 // Transfer from 1 to 22077 assert_ok!(Unique::transfer_from(2078 origin1,2079 account(1),2080 account(2),2081 CollectionId(1),2082 TokenId(1),2083 12084 ));2085 });2086}20872088// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2089#[test]2090fn allow_list_test_9() {2091 new_test_ext().execute_with(|| {2092 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2093 let origin1 = RuntimeOrigin::signed(1);20942095 assert_ok!(Unique::set_collection_permissions(2096 origin1.clone(),2097 collection_id,2098 CollectionPermissions {2099 mint_mode: Some(false),2100 access: Some(AccessMode::AllowList),2101 nesting: None,2102 }2103 ));21042105 let data = default_nft_data();2106 create_test_item(collection_id, &data.into());2107 });2108}21092110// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2111#[test]2112fn allow_list_test_10() {2113 new_test_ext().execute_with(|| {2114 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21152116 let origin1 = RuntimeOrigin::signed(1);2117 let origin2 = RuntimeOrigin::signed(2);21182119 assert_ok!(Unique::set_collection_permissions(2120 origin1.clone(),2121 collection_id,2122 CollectionPermissions {2123 mint_mode: Some(false),2124 access: Some(AccessMode::AllowList),2125 nesting: None,2126 }2127 ));21282129 assert_ok!(Unique::add_collection_admin(2130 origin1,2131 collection_id,2132 account(2)2133 ));21342135 assert_ok!(Unique::create_item(2136 origin2,2137 collection_id,2138 account(2),2139 default_nft_data().into()2140 ));2141 });2142}21432144// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.2145#[test]2146fn allow_list_test_11() {2147 new_test_ext().execute_with(|| {2148 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21492150 let origin1 = RuntimeOrigin::signed(1);2151 let origin2 = RuntimeOrigin::signed(2);21522153 assert_ok!(Unique::set_collection_permissions(2154 origin1.clone(),2155 collection_id,2156 CollectionPermissions {2157 mint_mode: Some(false),2158 access: Some(AccessMode::AllowList),2159 nesting: None,2160 }2161 ));2162 assert_ok!(Unique::add_to_allow_list(2163 origin1,2164 collection_id,2165 account(2)2166 ));21672168 assert_noop!(2169 Unique::create_item(2170 origin2,2171 CollectionId(1),2172 account(2),2173 default_nft_data().into()2174 )2175 .map_err(|e| e.error),2176 CommonError::<Test>::PublicMintingNotAllowed2177 );2178 });2179}21802181// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.2182#[test]2183fn allow_list_test_12() {2184 new_test_ext().execute_with(|| {2185 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21862187 let origin1 = RuntimeOrigin::signed(1);2188 let origin2 = RuntimeOrigin::signed(2);21892190 assert_ok!(Unique::set_collection_permissions(2191 origin1.clone(),2192 collection_id,2193 CollectionPermissions {2194 mint_mode: Some(false),2195 access: Some(AccessMode::AllowList),2196 nesting: None,2197 }2198 ));21992200 assert_noop!(2201 Unique::create_item(2202 origin2,2203 CollectionId(1),2204 account(2),2205 default_nft_data().into()2206 )2207 .map_err(|e| e.error),2208 CommonError::<Test>::PublicMintingNotAllowed2209 );2210 });2211}22122213// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2214#[test]2215fn allow_list_test_13() {2216 new_test_ext().execute_with(|| {2217 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22182219 let origin1 = RuntimeOrigin::signed(1);22202221 assert_ok!(Unique::set_collection_permissions(2222 origin1.clone(),2223 collection_id,2224 CollectionPermissions {2225 mint_mode: Some(true),2226 access: Some(AccessMode::AllowList),2227 nesting: None,2228 }2229 ));22302231 let data = default_nft_data();2232 create_test_item(collection_id, &data.into());2233 });2234}22352236// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2237#[test]2238fn allow_list_test_14() {2239 new_test_ext().execute_with(|| {2240 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22412242 let origin1 = RuntimeOrigin::signed(1);2243 let origin2 = RuntimeOrigin::signed(2);22442245 assert_ok!(Unique::set_collection_permissions(2246 origin1.clone(),2247 collection_id,2248 CollectionPermissions {2249 mint_mode: Some(true),2250 access: Some(AccessMode::AllowList),2251 nesting: None,2252 }2253 ));22542255 assert_ok!(Unique::add_collection_admin(2256 origin1,2257 collection_id,2258 account(2)2259 ));22602261 assert_ok!(Unique::create_item(2262 origin2,2263 collection_id,2264 account(2),2265 default_nft_data().into()2266 ));2267 });2268}22692270// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.2271#[test]2272fn allow_list_test_15() {2273 new_test_ext().execute_with(|| {2274 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22752276 let origin1 = RuntimeOrigin::signed(1);2277 let origin2 = RuntimeOrigin::signed(2);22782279 assert_ok!(Unique::set_collection_permissions(2280 origin1.clone(),2281 collection_id,2282 CollectionPermissions {2283 mint_mode: Some(true),2284 access: Some(AccessMode::AllowList),2285 nesting: None,2286 }2287 ));22882289 assert_noop!(2290 Unique::create_item(2291 origin2,2292 collection_id,2293 account(2),2294 default_nft_data().into()2295 )2296 .map_err(|e| e.error),2297 CommonError::<Test>::AddressNotInAllowlist2298 );2299 });2300}23012302// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.2303#[test]2304fn allow_list_test_16() {2305 new_test_ext().execute_with(|| {2306 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23072308 let origin1 = RuntimeOrigin::signed(1);2309 let origin2 = RuntimeOrigin::signed(2);23102311 assert_ok!(Unique::set_collection_permissions(2312 origin1.clone(),2313 collection_id,2314 CollectionPermissions {2315 mint_mode: Some(true),2316 access: Some(AccessMode::AllowList),2317 nesting: None,2318 }2319 ));2320 assert_ok!(Unique::add_to_allow_list(2321 origin1,2322 collection_id,2323 account(2)2324 ));23252326 assert_ok!(Unique::create_item(2327 origin2,2328 collection_id,2329 account(2),2330 default_nft_data().into()2331 ));2332 });2333}23342335// Total number of collections. Positive test2336#[test]2337fn total_number_collections_bound() {2338 new_test_ext().execute_with(|| {2339 create_test_collection(&CollectionMode::NFT, CollectionId(1));2340 });2341}23422343#[test]2344fn create_max_collections() {2345 new_test_ext().execute_with(|| {2346 for i in 1..COLLECTION_NUMBER_LIMIT {2347 create_test_collection(&CollectionMode::NFT, CollectionId(i));2348 }2349 });2350}23512352// Total number of collections. Negative test2353#[test]2354fn total_number_collections_bound_neg() {2355 new_test_ext().execute_with(|| {2356 let origin1 = RuntimeOrigin::signed(1);23572358 for i in 1..=COLLECTION_NUMBER_LIMIT {2359 create_test_collection(&CollectionMode::NFT, CollectionId(i));2360 }23612362 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2363 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2364 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23652366 let data = CreateCollectionData {2367 name: col_name1.try_into().unwrap(),2368 description: col_desc1.try_into().unwrap(),2369 token_prefix: token_prefix1.try_into().unwrap(),2370 mode: CollectionMode::NFT,2371 ..Default::default()2372 };23732374 // 11-th collection in chain. Expects error2375 assert_noop!(2376 Unique::create_collection_ex(origin1, data),2377 CommonError::<Test>::TotalCollectionsLimitExceeded2378 );2379 });2380}23812382// Owned tokens by a single address. Positive test2383#[test]2384fn owned_tokens_bound() {2385 new_test_ext().execute_with(|| {2386 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23872388 let data = default_nft_data();2389 create_test_item(collection_id, &data.clone().into());2390 create_test_item(collection_id, &data.into());2391 });2392}23932394// Owned tokens by a single address. Negotive test2395#[test]2396fn owned_tokens_bound_neg() {2397 new_test_ext().execute_with(|| {2398 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23992400 let origin1 = RuntimeOrigin::signed(1);24012402 for _ in 1..=MAX_TOKEN_OWNERSHIP {2403 let data = default_nft_data();2404 create_test_item(collection_id, &data.clone().into());2405 }24062407 let data = default_nft_data();2408 assert_noop!(2409 Unique::create_item(origin1, CollectionId(1), account(1), data.into())2410 .map_err(|e| e.error),2411 CommonError::<Test>::AccountTokenLimitExceeded2412 );2413 });2414}24152416// Number of collection admins. Positive test2417#[test]2418fn collection_admins_bound() {2419 new_test_ext().execute_with(|| {2420 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24212422 let origin1 = RuntimeOrigin::signed(1);24232424 assert_ok!(Unique::add_collection_admin(2425 origin1.clone(),2426 collection_id,2427 account(2)2428 ));2429 assert_ok!(Unique::add_collection_admin(2430 origin1,2431 collection_id,2432 account(3)2433 ));2434 });2435}24362437// Number of collection admins. Negotive test2438#[test]2439fn collection_admins_bound_neg() {2440 new_test_ext().execute_with(|| {2441 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24422443 let origin1 = RuntimeOrigin::signed(1);24442445 for i in 0..COLLECTION_ADMINS_LIMIT {2446 assert_ok!(Unique::add_collection_admin(2447 origin1.clone(),2448 collection_id,2449 account((2 + i).into())2450 ));2451 }2452 assert_noop!(2453 Unique::add_collection_admin(2454 origin1,2455 collection_id,2456 account((3 + COLLECTION_ADMINS_LIMIT).into())2457 ),2458 CommonError::<Test>::CollectionAdminCountExceeded2459 );2460 });2461}2462// #endregion24632464#[test]2465fn collection_transfer_flag_works() {2466 new_test_ext().execute_with(|| {2467 let origin1 = RuntimeOrigin::signed(1);24682469 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2470 assert_ok!(Unique::set_transfers_enabled_flag(2471 origin1,2472 collection_id,2473 true2474 ));24752476 let data = default_nft_data();2477 create_test_item(collection_id, &data.into());2478 assert_eq!(2479 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2480 12481 );2482 assert_eq!(2483 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2484 true2485 );24862487 let origin1 = RuntimeOrigin::signed(1);24882489 // default scenario2490 assert_ok!(Unique::transfer(2491 origin1,2492 account(2),2493 collection_id,2494 TokenId(1),2495 12496 ));2497 assert_eq!(2498 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2499 false2500 );2501 assert_eq!(2502 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2503 true2504 );2505 assert_eq!(2506 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2507 02508 );2509 assert_eq!(2510 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2511 12512 );2513 });2514}25152516#[test]2517fn collection_transfer_flag_works_neg() {2518 new_test_ext().execute_with(|| {2519 let origin1 = RuntimeOrigin::signed(1);25202521 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2522 assert_ok!(Unique::set_transfers_enabled_flag(2523 origin1,2524 collection_id,2525 false2526 ));25272528 let data = default_nft_data();2529 create_test_item(collection_id, &data.into());2530 assert_eq!(2531 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2532 12533 );2534 assert_eq!(2535 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2536 true2537 );25382539 let origin1 = RuntimeOrigin::signed(1);25402541 // default scenario2542 assert_noop!(2543 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2544 .map_err(|e| e.error),2545 CommonError::<Test>::TransferNotAllowed2546 );2547 assert_eq!(2548 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2549 12550 );2551 assert_eq!(2552 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2553 02554 );2555 assert_eq!(2556 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2557 true2558 );2559 assert_eq!(2560 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2561 false2562 );2563 });2564}25652566#[test]2567fn collection_sponsoring() {2568 new_test_ext().execute_with(|| {2569 // default_limits();2570 let user1 = 1_u64;2571 let user2 = 777_u64;2572 let origin1 = RuntimeOrigin::signed(user1);2573 let origin2 = RuntimeOrigin::signed(user2);2574 let account2 = account(user2);25752576 let collection_id =2577 create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));2578 assert_ok!(Unique::set_collection_sponsor(2579 origin1.clone(),2580 collection_id,2581 user12582 ));2583 assert_ok!(Unique::confirm_sponsorship(origin1.clone(), collection_id));25842585 // Expect error while have no permissions2586 assert!(Unique::create_item(2587 origin2.clone(),2588 collection_id,2589 account2.clone(),2590 default_nft_data().into()2591 )2592 .is_err());25932594 assert_ok!(Unique::set_collection_permissions(2595 origin1.clone(),2596 collection_id,2597 CollectionPermissions {2598 mint_mode: Some(true),2599 access: Some(AccessMode::AllowList),2600 nesting: None,2601 }2602 ));2603 assert_ok!(Unique::add_to_allow_list(2604 origin1.clone(),2605 collection_id,2606 account2.clone()2607 ));26082609 assert_ok!(Unique::create_item(2610 origin2,2611 collection_id,2612 account2,2613 default_nft_data().into()2614 ));2615 });2616}26172618mod check_token_permissions {2619 use super::*;2620 use pallet_common::LazyValue;26212622 fn test<FTE: FnOnce() -> bool>(2623 i: usize,2624 test_case: &pallet_common::tests::TestCase,2625 check_token_existence: &mut LazyValue<bool, FTE>,2626 ) {2627 let collection_admin = test_case.collection_admin;2628 let mut is_collection_admin = LazyValue::new(|| test_case.is_collection_admin);2629 let token_owner = test_case.token_owner;2630 let mut is_token_owner = LazyValue::new(|| Ok(test_case.is_token_owner));2631 let is_no_permission = test_case.no_permission;26322633 let result = pallet_common::tests::check_token_permissions::<Test, _, _, FTE>(2634 collection_admin,2635 token_owner,2636 &mut is_collection_admin,2637 &mut is_token_owner,2638 check_token_existence,2639 );26402641 if is_no_permission {2642 assert!(2643 result.is_err(),2644 "{i}: {test_case:?}, token_exist: {}",2645 check_token_existence.value()2646 );2647 assert_err!(result, pallet_common::Error::<Test>::NoPermission,);2648 } else if check_token_existence.has_value() && !check_token_existence.value() {2649 assert!(2650 result.is_err(),2651 "{i}: {test_case:?}, token_exist: {}",2652 check_token_existence.value()2653 );2654 assert_err!(result, pallet_common::Error::<Test>::TokenNotFound,);2655 }2656 }26572658 #[test]2659 fn no_permission_only() {2660 new_test_ext().execute_with(|| {2661 let mut check_token_existence = LazyValue::new(|| true);2662 for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {2663 test(i, row, &mut check_token_existence);2664 }2665 });2666 }26672668 #[test]2669 fn no_permission_and_token_not_found() {2670 new_test_ext().execute_with(|| {2671 for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {2672 // This is inside the loop to keep track of whether the lambda was called2673 let mut check_token_existence = LazyValue::new(|| false);2674 test(i, row, &mut check_token_existence);2675 }2676 });2677 }2678}tests/src/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -106,15 +106,17 @@
flags: [CollectionFlag.Erc721metadata],
}, 'nft');
- await mintCollectionHelper(helper, alice, {
+ // User can not set Foreign flag itself
+
+ await expect(mintCollectionHelper(helper, alice, {
name: 'name', description: 'descr', tokenPrefix: 'COL',
flags: [CollectionFlag.Foreign],
- }, 'nft');
+ }, 'nft')).to.be.rejectedWith(/common.NoPermission/);
- await mintCollectionHelper(helper, alice, {
+ await expect(mintCollectionHelper(helper, alice, {
name: 'name', description: 'descr', tokenPrefix: 'COL',
flags: [CollectionFlag.Erc721metadata, CollectionFlag.Foreign],
- }, 'nft');
+ }, 'nft')).to.be.rejectedWith(/common.NoPermission/);
});
itSub('Create new collection with extra fields', async ({helper}) => {
tests/src/eth/collectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionLimits.test.ts
+++ b/tests/src/eth/collectionLimits.test.ts
@@ -106,7 +106,7 @@
// Cannot disable limits
await expect(collectionEvm.methods
- .setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: false, value: 200}})
+ .setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: false, value: 0}})
.call()).to.be.rejectedWith('user can\'t disable limits');
await expect(collectionEvm.methods
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -41,7 +41,7 @@
for(const arg of args) {
if(typeof arg !== 'string')
continue;
- const skippedWarnings = ['1000:: Normal connection closure', 'Not decorating unknown runtime apis:', 'RPC methods not decorated:', 'Not decorating runtime apis'];
+ const skippedWarnings = ['1000:: Normal connection closure', 'Not decorating unknown runtime apis:', 'RPC methods not decorated:', 'Not decorating runtime apis', 'Bad input data provided to validate_transaction', 'account balance too low', '1006:: Abnormal Closure'];
const needToSkip = skippedWarnings.reduce((a, b) => a || arg.includes(b), false);
if(needToSkip || arg === 'Normal connection closure')
return;