difftreelog
Fix unit test building
in: master
8 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5097,6 +5097,7 @@
"frame-system-rpc-runtime-api",
"hex-literal",
"nft-data-structs",
+ "orml-vesting",
"pallet-aura",
"pallet-balances",
"pallet-common",
@@ -5120,7 +5121,6 @@
"pallet-transaction-payment-rpc-runtime-api",
"pallet-treasury",
"pallet-unq-scheduler",
- "pallet-vesting",
"pallet-xcm",
"parachain-info",
"parity-scale-codec",
@@ -5308,6 +5308,21 @@
]
[[package]]
+name = "orml-vesting"
+version = "0.4.1-dev"
+source = "git+https://github.com/UniqueNetwork/open-runtime-module-library#d69f226e332ae29b7b33d53d2f06f309d2986ea0"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "parity-scale-codec",
+ "scale-info",
+ "serde",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
name = "owning_ref"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -273,8 +273,8 @@
TotalCollectionsLimitExceeded,
/// variable_data exceeded data limit.
TokenVariableDataLimitExceeded,
- /// Exceeded max admin amount
- CollectionAdminAmountExceeded,
+ /// Exceeded max admin count
+ CollectionAdminCountExceeded,
/// Collection settings not allowing items transferring
TransferNotAllowed,
@@ -479,10 +479,10 @@
if admin {
let amount = amount
.checked_add(1)
- .ok_or(<Error<T>>::CollectionAdminAmountExceeded)?;
+ .ok_or(<Error<T>>::CollectionAdminCountExceeded)?;
ensure!(
amount <= Self::collection_admins_limit(),
- <Error<T>>::CollectionAdminAmountExceeded,
+ <Error<T>>::CollectionAdminCountExceeded,
);
// =========
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -182,7 +182,7 @@
_token: TokenId,
_data: Vec<u8>,
) -> DispatchResultWithPostInfo {
- fail!(<Error<T>>::FungibleItemsHaveData)
+ fail!(<Error<T>>::FungibleItemsDontHaveData)
}
fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -35,7 +35,7 @@
/// Not default id passed as TokenId argument
FungibleItemsHaveNoId,
/// Tried to set data for fungible item
- FungibleItemsHaveData,
+ FungibleItemsDontHaveData,
}
#[pallet::config]
@@ -44,15 +44,15 @@
}
#[pallet::pallet]
- #[pallet::generate_store(pub(super) trait Store)]
+ #[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
- pub(super) type TotalSupply<T: Config> =
+ pub type TotalSupply<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type Balance<T: Config> = StorageNMap<
+ pub type Balance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -62,7 +62,7 @@
>;
#[pallet::storage]
- pub(super) type Allowance<T: Config> = StorageNMap<
+ pub type Allowance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128, T::CrossAccountId>,
pallets/nft/src/mock.rsdiffbeforeafterboth--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -124,25 +124,35 @@
#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]
pub struct TestCrossAccountId(u64, sp_core::H160);
impl CrossAccountId<u64> for TestCrossAccountId {
+ fn as_sub(&self) -> &u64 {
+ &self.0
+ }
+ fn as_eth(&self) -> &sp_core::H160 {
+ &self.1
+ }
fn from_sub(sub: u64) -> Self {
let mut eth = [0; 20];
eth[12..20].copy_from_slice(&sub.to_be_bytes());
Self(sub, sp_core::H160(eth))
}
- fn as_sub(&self) -> &u64 {
- &self.0
- }
fn from_eth(eth: sp_core::H160) -> Self {
let mut sub_raw = [0; 8];
sub_raw.copy_from_slice(ð.0[0..8]);
let sub = u64::from_be_bytes(sub_raw);
Self(sub, eth)
}
- fn as_eth(&self) -> &sp_core::H160 {
- &self.1
+ fn conv_eq(&self, other: &Self) -> bool {
+ self.as_sub() == other.as_sub()
+ }
+}
+
+impl Default for TestCrossAccountId {
+ fn default() -> Self {
+ Self::from_sub(0)
}
}
+
pub struct TestEtheremTransactionSender;
impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {
fn submit_logs_transaction(
@@ -157,6 +167,27 @@
type EthereumTransactionSender = TestEtheremTransactionSender;
}
+impl pallet_common::Config for Test {
+ type Event = ();
+ type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;
+ type EvmAddressMapping = TestEvmAddressMapping;
+ type CrossAccountId = TestCrossAccountId;
+
+ type Currency = Balances;
+ type CollectionCreationPrice = CollectionCreationPrice;
+ type TreasuryAccountId = TreasuryAccountId;
+}
+
+impl pallet_fungible::Config for Test {
+ type WeightInfo = ();
+}
+impl pallet_refungible::Config for Test {
+ type WeightInfo = ();
+}
+impl pallet_nonfungible::Config for Test {
+ type WeightInfo = ();
+}
+
impl pallet_template::Config for Test {
type WeightInfo = ();
}
pallets/nft/src/tests.rsdiffbeforeafterboth1// Tests to be written here1// Tests to be written here2use super::*;2use super::*;3use crate::mock::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode, CreateItemData};4use crate::{AccessMode, CollectionMode};5use nft_data_structs::{5use nft_data_structs::{6 CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,6 COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, CreateFungibleData, 7 CreateNftData, CreateReFungibleData, ExistenceRequirement, MAX_COLLECTION_DESCRIPTION_LENGTH, 7 MAX_DECIMAL_POINTS,8 MAX_COLLECTION_NAME_LENGTH, MAX_DECIMAL_POINTS, MAX_TOKEN_PREFIX_LENGTH, COLLECTION_ADMINS_LIMIT, 9 MetaUpdatePermission, Pays, PostDispatchInfo, TokenId, Weight, WithdrawReasons,8};10};119use frame_support::{assert_noop, assert_ok};12use frame_support::{assert_noop, assert_ok};10use sp_std::convert::TryInto;13use sp_std::convert::TryInto;111449 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();52 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();50 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();53 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();51 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();54 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();52 assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);55 assert_eq!(<pallet_common::CollectionById<Test>>::get(id).unwrap().owner, owner);53 assert_eq!(56 assert_eq!(54 TemplateModule::collection_id(id).unwrap().name,57 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,55 saved_col_name58 saved_col_name56 );59 );57 assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);60 assert_eq!(<pallet_common::CollectionById<Test>>::get(id).unwrap().mode, *mode);58 assert_eq!(61 assert_eq!(59 TemplateModule::collection_id(id).unwrap().description,62 <pallet_common::CollectionById<Test>>::get(id).unwrap().description,60 saved_description63 saved_description61 );64 );62 assert_eq!(65 assert_eq!(63 TemplateModule::collection_id(id).unwrap().token_prefix,66 <pallet_common::CollectionById<Test>>::get(id).unwrap().token_prefix,64 saved_prefix67 saved_prefix65 );68 );66 id69 id91fn set_version_schema() {94fn set_version_schema() {92 new_test_ext().execute_with(|| {95 new_test_ext().execute_with(|| {93 let origin1 = Origin::signed(1);96 let origin1 = Origin::signed(1);94 let collection_id = create_test_collection(&CollectionMode::NFT, 1);97 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));959896 assert_ok!(TemplateModule::set_schema_version(99 assert_ok!(TemplateModule::set_schema_version(97 origin1,100 origin1,98 collection_id,101 collection_id,99 SchemaVersion::Unique102 SchemaVersion::Unique100 ));103 ));101 assert_eq!(104 assert_eq!(102 TemplateModule::collection_id(collection_id)105 <pallet_common::CollectionById<Test>>::get(collection_id)103 .unwrap()106 .unwrap()104 .schema_version,107 .schema_version,105 SchemaVersion::Unique108 SchemaVersion::Unique131#[test]134#[test]132fn create_nft_item() {135fn create_nft_item() {133 new_test_ext().execute_with(|| {136 new_test_ext().execute_with(|| {134 let collection_id = create_test_collection(&CollectionMode::NFT, 1);137 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));135138136 let data = default_nft_data();139 let data = default_nft_data();137 create_test_item(collection_id, &data.clone().into());140 create_test_item(collection_id, &data.clone().into());141138 let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();142 let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();139 assert_eq!(item.const_data, data.const_data.into_inner());143 assert_eq!(item.const_data, data.const_data.into_inner());140 assert_eq!(item.variable_data, data.variable_data.into_inner());144 assert_eq!(item.variable_data, data.variable_data.into_inner());141 });145 });146#[test]150#[test]147fn create_nft_multiple_items() {151fn create_nft_multiple_items() {148 new_test_ext().execute_with(|| {152 new_test_ext().execute_with(|| {149 create_test_collection(&CollectionMode::NFT, 1);153 create_test_collection(&CollectionMode::NFT, CollectionId(1));150154151 let origin1 = Origin::signed(1);155 let origin1 = Origin::signed(1);152156153 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];157 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];154158155 assert_ok!(TemplateModule::create_multiple_items(159 assert_ok!(TemplateModule::create_multiple_items(156 origin1,160 origin1,157 1,161 CollectionId(1),158 account(1),162 account(1),159 items_data163 items_data160 .clone()164 .clone()163 .collect()167 .collect()164 ));168 ));165 for (index, data) in items_data.into_iter().enumerate() {169 for (index, data) in items_data.into_iter().enumerate() {166 let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap();170 let item = <pallet_nonfungible::TokenData<Test>>::get((CollectionId(1), TokenId((index + 1) as u32))).unwrap();167 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());171 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());168 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());172 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());169 }173 }173#[test]177#[test]174fn create_refungible_item() {178fn create_refungible_item() {175 new_test_ext().execute_with(|| {179 new_test_ext().execute_with(|| {176 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);180 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));177181178 let data = default_re_fungible_data();182 let data = default_re_fungible_data();179 create_test_item(collection_id, &data.clone().into());183 create_test_item(collection_id, &data.clone().into());180 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();184 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));181 let balance = TemplateModule::balance(collection_id, 1, account(1));185 let balance = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));182 assert_eq!(item.const_data, data.const_data.into_inner());186 assert_eq!(item.const_data, data.const_data.into_inner());183 assert_eq!(item.variable_data, data.variable_data.into_inner());187 assert_eq!(item.variable_data, data.variable_data.into_inner());184 assert_eq!(balance, 1023);188 assert_eq!(balance, 1023);188#[test]192#[test]189fn create_multiple_refungible_items() {193fn create_multiple_refungible_items() {190 new_test_ext().execute_with(|| {194 new_test_ext().execute_with(|| {191 create_test_collection(&CollectionMode::ReFungible, 1);195 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));192196193 let origin1 = Origin::signed(1);197 let origin1 = Origin::signed(1);194198200204201 assert_ok!(TemplateModule::create_multiple_items(205 assert_ok!(TemplateModule::create_multiple_items(202 origin1,206 origin1,203 1,207 CollectionId(1),204 account(1),208 account(1),205 items_data209 items_data206 .clone()210 .clone()209 .collect()213 .collect()210 ));214 ));211 for (index, data) in items_data.into_iter().enumerate() {215 for (index, data) in items_data.into_iter().enumerate() {212 let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();216 let item = <pallet_nonfungible::TokenData<Test>>::get((CollectionId(1), TokenId((index + 1) as u32))).unwrap();213 let balance = TemplateModule::balance(1, 1, account(1));217 let balance = <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));214 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());218 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());215 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());219 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());216 assert_eq!(balance, 1023);220 assert_eq!(balance, 1023);221#[test]225#[test]222fn create_fungible_item() {226fn create_fungible_item() {223 new_test_ext().execute_with(|| {227 new_test_ext().execute_with(|| {224 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);228 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));225229226 let data = default_fungible_data();230 let data = default_fungible_data();227 create_test_item(collection_id, &data.into());231 create_test_item(collection_id, &data.into());228232229 assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);233 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);230 });234 });231}235}232236235// new_test_ext().execute_with(|| {239// new_test_ext().execute_with(|| {236// default_limits();240// default_limits();237241238// create_test_collection(&CollectionMode::Fungible(3), 1);242// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));239243240// let origin1 = Origin::signed(1);244// let origin1 = Origin::signed(1);241245259#[test]263#[test]260fn transfer_fungible_item() {264fn transfer_fungible_item() {261 new_test_ext().execute_with(|| {265 new_test_ext().execute_with(|| {262 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);266 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));263267264 let origin1 = Origin::signed(1);268 let origin1 = Origin::signed(1);265 let origin2 = Origin::signed(2);269 let origin2 = Origin::signed(2);266270267 let data = default_fungible_data();271 let data = default_fungible_data();268 create_test_item(collection_id, &data.into());272 create_test_item(collection_id, &data.into());269273270 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);274 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 5);271 assert_eq!(TemplateModule::balance_count(1, 1), 5);272275273 // change owner scenario276 // change owner scenario274 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 5));277 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 5));275 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);278 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 0);276 assert_eq!(TemplateModule::balance_count(1, 1), 0);277 assert_eq!(TemplateModule::balance_count(1, 2), 5);278279279 // split item scenario280 // split item scenario280 assert_ok!(TemplateModule::transfer(281 assert_ok!(TemplateModule::transfer(281 origin2.clone(),282 origin2.clone(),282 account(3),283 account(3),283 1,284 CollectionId(1),284 1,285 TokenId(1),285 3286 3286 ));287 ));287 assert_eq!(TemplateModule::balance_count(1, 2), 2);288 assert_eq!(TemplateModule::balance_count(1, 3), 3);289288290 // split item and new owner has account scenario289 // split item and new owner has account scenario291 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 1));290 assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 1));292 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);291 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))), 1);293 assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);294 assert_eq!(TemplateModule::balance_count(1, 2), 1);295 assert_eq!(TemplateModule::balance_count(1, 3), 4);292 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))), 4);296 });293 });297}294}298295299#[test]296#[test]300fn transfer_refungible_item() {297fn transfer_refungible_item() {301 new_test_ext().execute_with(|| {298 new_test_ext().execute_with(|| {302 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);299 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));303300304 let data = default_re_fungible_data();301 let data = default_re_fungible_data();305 create_test_item(collection_id, &data.clone().into());302 create_test_item(collection_id, &data.clone().into());306303307 let origin1 = Origin::signed(1);304 let origin1 = Origin::signed(1);308 let origin2 = Origin::signed(2);305 let origin2 = Origin::signed(2);309 {306 {310 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();307 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));311 let balance = TemplateModule::balance(collection_id, 1, account(1));308 let balance = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));312 assert_eq!(item.const_data, data.const_data.into_inner());309 assert_eq!(item.const_data, data.const_data.into_inner());313 assert_eq!(item.variable_data, data.variable_data.into_inner());310 assert_eq!(item.variable_data, data.variable_data.into_inner());314 assert_eq!(balance, 1023);311 assert_eq!(balance, 1023);315 }312 }316 assert_eq!(TemplateModule::balance_count(1, 1), 1023);313 314 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);317 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);315 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);318316319 // change owner scenario317 // change owner scenario320 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));318 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1023));321319322 let balance2 = TemplateModule::balance(collection_id, 1, account(2));320 let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));323 assert_eq!(balance2, 1023);321 assert_eq!(balance2, 1023);324 assert_eq!(TemplateModule::balance_count(1, 1), 0);322 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);325 assert_eq!(TemplateModule::balance_count(1, 2), 1023);323 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1023);326 // assert_eq!(TemplateModule::address_tokens(1, 1), []);324 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);327 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);325 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);328326329 // split item scenario327 // split item scenario330 assert_ok!(TemplateModule::transfer(328 assert_ok!(TemplateModule::transfer(331 origin2.clone(),329 origin2.clone(),332 account(3),330 account(3),333 1,331 CollectionId(1),334 1,332 TokenId(1),335 500333 500336 ));334 ));337 {335 {338 let item = TemplateModule::refungible_item_id(1, 1).unwrap();336 let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId(1)));339 let balance2 = TemplateModule::balance(collection_id, 1, account(2));337 let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));340 let balance3 = TemplateModule::balance(collection_id, 1, account(3));338 let balance3 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3)));341 assert_eq!(balance2, 523);339 assert_eq!(balance2, 523);342 assert_eq!(balance3, 500);340 assert_eq!(balance3, 500);343 }341 }344 assert_eq!(TemplateModule::balance_count(1, 2), 523);342 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 523);345 assert_eq!(TemplateModule::balance_count(1, 3), 500);343 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 500);346 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);344 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);347 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);345 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);348346349 // split item and new owner has account scenario347 // split item and new owner has account scenario350 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));348 assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 200));351 {349 {352 let item = TemplateModule::refungible_item_id(1, 1).unwrap();350 let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId(1)));353 let balance2 = TemplateModule::balance(collection_id, 1, account(2));351 let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));354 let balance3 = TemplateModule::balance(collection_id, 1, account(3));352 let balance3 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3)));355 assert_eq!(balance2, 323);353 assert_eq!(balance2, 323);356 assert_eq!(balance3, 700);354 assert_eq!(balance3, 700);357 }355 }358 assert_eq!(TemplateModule::balance_count(1, 2), 323);356 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 323);359 assert_eq!(TemplateModule::balance_count(1, 3), 700);357 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 700);360 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);358 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);361 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);359 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);362 });360 });363}361}364362365#[test]363#[test]366fn transfer_nft_item() {364fn transfer_nft_item() {367 new_test_ext().execute_with(|| {365 new_test_ext().execute_with(|| {368 let collection_id = create_test_collection(&CollectionMode::NFT, 1);366 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));369367370 let data = default_nft_data();368 let data = default_nft_data();371 create_test_item(collection_id, &data.into());369 create_test_item(collection_id, &data.into());372 assert_eq!(TemplateModule::balance_count(1, 1), 1);370 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);373 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);371 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);374372373375 let origin1 = Origin::signed(1);374 let origin1 = Origin::signed(1);376 // default scenario375 // default scenario377 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));376 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1000));378 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));377 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);379 assert_eq!(TemplateModule::balance_count(1, 1), 0);380 assert_eq!(TemplateModule::balance_count(1, 2), 1);378 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);381 // assert_eq!(TemplateModule::address_tokens(1, 1), []);379 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);382 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);380 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);383 });381 });384}382}385383386#[test]384#[test]387fn nft_approve_and_transfer_from() {385fn nft_approve_and_transfer_from() {388 new_test_ext().execute_with(|| {386 new_test_ext().execute_with(|| {389 let collection_id = create_test_collection(&CollectionMode::NFT, 1);387 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));390388391 let data = default_nft_data();389 let data = default_nft_data();392 create_test_item(collection_id, &data.into());390 create_test_item(collection_id, &data.into());393391394 let origin1 = Origin::signed(1);392 let origin1 = Origin::signed(1);395 let origin2 = Origin::signed(2);393 let origin2 = Origin::signed(2);396394397 assert_eq!(TemplateModule::balance_count(1, 1), 1);395 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);398 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);396 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);399397400 // neg transfer398 // neg transfer401 assert_noop!(399 assert_noop!(402 TemplateModule::transfer_from(origin2.clone(), account(1), account(2), 1, 1, 1),400 TemplateModule::transfer_from(origin2.clone(), account(1), account(2), CollectionId(1), TokenId(1), 1),403 Error::<Test>::NoPermission401 CommonError::<Test>::NoPermission404 );402 );405403406 // do approve404 // do approve407 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 5));405 assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 5));408 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);406 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));409 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);410407411 assert_ok!(TemplateModule::transfer_from(408 assert_ok!(TemplateModule::transfer_from(412 origin2,409 origin2,413 account(1),410 account(1),414 account(3),411 account(3),415 1,412 CollectionId(1),416 1,413 TokenId(1),417 1414 1418 ));415 ));419 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);416 assert!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none());420 });417 });421}418}422419423#[test]420#[test]424fn nft_approve_and_transfer_from_allow_list() {421fn nft_approve_and_transfer_from_allow_list() {425 new_test_ext().execute_with(|| {422 new_test_ext().execute_with(|| {426 let collection_id = create_test_collection(&CollectionMode::NFT, 1);423 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));427424428 let origin1 = Origin::signed(1);425 let origin1 = Origin::signed(1);429 let origin2 = Origin::signed(2);426 let origin2 = Origin::signed(2);432 create_test_item(collection_id, &data.clone().into());429 create_test_item(collection_id, &data.clone().into());433430434 assert_eq!(431 assert_eq!(435 &TemplateModule::nft_item_id(1, 1).unwrap().const_data,432 &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1))).unwrap().const_data,436 &data.const_data.into_inner()433 &data.const_data.into_inner()437 );434 );438 assert_eq!(TemplateModule::balance_count(1, 1), 1);435 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);439 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);436 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);440437441 assert_ok!(TemplateModule::set_mint_permission(438 assert_ok!(TemplateModule::set_mint_permission(442 origin1.clone(),439 origin1.clone(),443 1,440 CollectionId(1),444 true441 true445 ));442 ));446 assert_ok!(TemplateModule::set_public_access_mode(443 assert_ok!(TemplateModule::set_public_access_mode(447 origin1.clone(),444 origin1.clone(),448 1,445 CollectionId(1),449 AccessMode::AllowList446 AccessMode::AllowList450 ));447 ));451 assert_ok!(TemplateModule::add_to_allow_list(448 assert_ok!(TemplateModule::add_to_allow_list(452 origin1.clone(),449 origin1.clone(),453 1,450 CollectionId(1),454 account(1)451 account(1)455 ));452 ));456 assert_ok!(TemplateModule::add_to_allow_list(453 assert_ok!(TemplateModule::add_to_allow_list(457 origin1.clone(),454 origin1.clone(),458 1,455 CollectionId(1),459 account(2)456 account(2)460 ));457 ));461 assert_ok!(TemplateModule::add_to_allow_list(458 assert_ok!(TemplateModule::add_to_allow_list(462 origin1.clone(),459 origin1.clone(),463 1,460 CollectionId(1),464 account(3)461 account(3)465 ));462 ));466463467 // do approve464 // do approve468 assert_ok!(TemplateModule::approve(465 assert_ok!(TemplateModule::approve(469 origin1.clone(),466 origin1.clone(),470 account(2),467 account(2),471 1,468 CollectionId(1),472 1,469 TokenId(1),473 5470 5474 ));471 ));475 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);472 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));476 assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));473 assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(1), 5));477 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);474 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(3));478475479 assert_ok!(TemplateModule::transfer_from(476 assert_ok!(TemplateModule::transfer_from(480 origin2,477 origin2,481 account(1),478 account(1),482 account(3),479 account(3),483 1,480 CollectionId(1),484 1,481 TokenId(1),485 1482 1486 ));483 ));487 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);484 assert!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none());488 });485 });489}486}490487491#[test]488#[test]492fn refungible_approve_and_transfer_from() {489fn refungible_approve_and_transfer_from() {493 new_test_ext().execute_with(|| {490 new_test_ext().execute_with(|| {494 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);491 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));495492496 let origin1 = Origin::signed(1);493 let origin1 = Origin::signed(1);497 let origin2 = Origin::signed(2);494 let origin2 = Origin::signed(2);498495499 let data = default_re_fungible_data();496 let data = default_re_fungible_data();500 create_test_item(collection_id, &data.into());497 create_test_item(collection_id, &data.into());501498502 assert_eq!(TemplateModule::balance_count(1, 1), 1023);499 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);503 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);500 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);504501505 assert_ok!(TemplateModule::set_mint_permission(502 assert_ok!(TemplateModule::set_mint_permission(506 origin1.clone(),503 origin1.clone(),507 1,504 CollectionId(1),508 true505 true509 ));506 ));510 assert_ok!(TemplateModule::set_public_access_mode(507 assert_ok!(TemplateModule::set_public_access_mode(511 origin1.clone(),508 origin1.clone(),512 1,509 CollectionId(1),513 AccessMode::AllowList510 AccessMode::AllowList514 ));511 ));515 assert_ok!(TemplateModule::add_to_allow_list(512 assert_ok!(TemplateModule::add_to_allow_list(516 origin1.clone(),513 origin1.clone(),517 1,514 CollectionId(1),518 account(1)515 account(1)519 ));516 ));520 assert_ok!(TemplateModule::add_to_allow_list(517 assert_ok!(TemplateModule::add_to_allow_list(521 origin1.clone(),518 origin1.clone(),522 1,519 CollectionId(1),523 account(2)520 account(2)524 ));521 ));525 assert_ok!(TemplateModule::add_to_allow_list(522 assert_ok!(TemplateModule::add_to_allow_list(526 origin1.clone(),523 origin1.clone(),527 1,524 CollectionId(1),528 account(3)525 account(3)529 ));526 ));530527531 // do approve528 // do approve532 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1023));529 assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1023));533 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);530 assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 1023);534531535 assert_ok!(TemplateModule::transfer_from(532 assert_ok!(TemplateModule::transfer_from(536 origin2,533 origin2,537 account(1),534 account(1),538 account(3),535 account(3),539 1,536 CollectionId(1),540 1,537 TokenId(1),541 100538 100542 ));539 ));543 assert_eq!(TemplateModule::balance_count(1, 1), 923);540 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 923);544 assert_eq!(TemplateModule::balance_count(1, 3), 100);541 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 100);545 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);542 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);546 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);543 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(3))), true);547548 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 923);544 assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 923);549 });545 });550}546}551547552#[test]548#[test]553fn fungible_approve_and_transfer_from() {549fn fungible_approve_and_transfer_from() {554 new_test_ext().execute_with(|| {550 new_test_ext().execute_with(|| {555 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);551 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));556552557 let data = default_fungible_data();553 let data = default_fungible_data();558 create_test_item(collection_id, &data.into());554 create_test_item(collection_id, &data.into());559555560 let origin1 = Origin::signed(1);556 let origin1 = Origin::signed(1);561 let origin2 = Origin::signed(2);557 let origin2 = Origin::signed(2);562558563 assert_eq!(TemplateModule::balance_count(1, 1), 5);564565 assert_ok!(TemplateModule::set_mint_permission(559 assert_ok!(TemplateModule::set_mint_permission(566 origin1.clone(),560 origin1.clone(),567 1,561 CollectionId(1),568 true562 true569 ));563 ));570 assert_ok!(TemplateModule::set_public_access_mode(564 assert_ok!(TemplateModule::set_public_access_mode(571 origin1.clone(),565 origin1.clone(),572 1,566 CollectionId(1),573 AccessMode::AllowList567 AccessMode::AllowList574 ));568 ));575 assert_ok!(TemplateModule::add_to_allow_list(569 assert_ok!(TemplateModule::add_to_allow_list(576 origin1.clone(),570 origin1.clone(),577 1,571 CollectionId(1),578 account(1)572 account(1)579 ));573 ));580 assert_ok!(TemplateModule::add_to_allow_list(574 assert_ok!(TemplateModule::add_to_allow_list(581 origin1.clone(),575 origin1.clone(),582 1,576 CollectionId(1),583 account(2)577 account(2)584 ));578 ));585 assert_ok!(TemplateModule::add_to_allow_list(579 assert_ok!(TemplateModule::add_to_allow_list(586 origin1.clone(),580 origin1.clone(),587 1,581 CollectionId(1),588 account(3)582 account(3)589 ));583 ));590584591 // do approve585 // do approve592 assert_ok!(TemplateModule::approve(586 assert_ok!(TemplateModule::approve(593 origin1.clone(),587 origin1.clone(),594 account(2),588 account(2),595 1,589 CollectionId(1),596 1,590 TokenId(1),597 5591 5598 ));592 ));599 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);593 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);600 assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));594 assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(1), 5));601 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);595 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);602 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);596 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))), 5);603597604 assert_ok!(TemplateModule::transfer_from(598 assert_ok!(TemplateModule::transfer_from(605 origin2.clone(),599 origin2.clone(),606 account(1),600 account(1),607 account(3),601 account(3),608 1,602 CollectionId(1),609 1,603 TokenId(1),610 4604 4611 ));605 ));612 assert_eq!(TemplateModule::balance_count(1, 1), 1);613 assert_eq!(TemplateModule::balance_count(1, 3), 4);614606615 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);607 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 1);616608617 assert_noop!(609 assert_noop!(618 TemplateModule::transfer_from(origin2, account(1), account(3), 1, 1, 4),610 TemplateModule::transfer_from(origin2, account(1), account(3), CollectionId(1), TokenId(1), 4),619 Error::<Test>::NoPermission611 CommonError::<Test>::NoPermission620 );612 );621 });613 });622}614}623615624#[test]616#[test]625fn change_collection_owner() {617fn change_collection_owner() {626 new_test_ext().execute_with(|| {618 new_test_ext().execute_with(|| {627 let collection_id = create_test_collection(&CollectionMode::NFT, 1);619 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));628620629 let origin1 = Origin::signed(1);621 let origin1 = Origin::signed(1);630 assert_ok!(TemplateModule::change_collection_owner(622 assert_ok!(TemplateModule::change_collection_owner(633 2625 2634 ));626 ));635 assert_eq!(627 assert_eq!(636 TemplateModule::collection_id(collection_id).unwrap().owner,628 <pallet_common::CollectionById<Test>>::get(collection_id).unwrap().owner,637 2629 2638 );630 );639 });631 });642#[test]634#[test]643fn destroy_collection() {635fn destroy_collection() {644 new_test_ext().execute_with(|| {636 new_test_ext().execute_with(|| {645 let collection_id = create_test_collection(&CollectionMode::NFT, 1);637 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));646638647 let origin1 = Origin::signed(1);639 let origin1 = Origin::signed(1);648 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));640 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));652#[test]644#[test]653fn burn_nft_item() {645fn burn_nft_item() {654 new_test_ext().execute_with(|| {646 new_test_ext().execute_with(|| {655 let collection_id = create_test_collection(&CollectionMode::NFT, 1);647 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));656648657 let origin1 = Origin::signed(1);649 let origin1 = Origin::signed(1);658 assert_ok!(TemplateModule::add_collection_admin(650 assert_ok!(TemplateModule::add_collection_admin(665 create_test_item(collection_id, &data.into());657 create_test_item(collection_id, &data.into());666658667 // check balance (collection with id = 1, user id = 1)659 // check balance (collection with id = 1, user id = 1)668 assert_eq!(TemplateModule::balance_count(1, 1), 1);660 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);669661670 // burn item662 // burn item671 assert_ok!(TemplateModule::burn_item(663 assert_ok!(TemplateModule::burn_item(672 origin1.clone(),664 origin1.clone(),673 collection_id,665 collection_id,674 1,666 TokenId(1),675 1667 1676 ));668 ));677 assert_noop!(669 assert_noop!(678 TemplateModule::burn_item(origin1, collection_id, 1, 1),670 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1),679 Error::<Test>::TokenNotFound671 CommonError::<Test>::TokenNotFound680 );672 );681673682 assert_eq!(TemplateModule::balance_count(1, 1), 0);674 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);683 });675 });684}676}685677686#[test]678#[test]687fn burn_fungible_item() {679fn burn_fungible_item() {688 new_test_ext().execute_with(|| {680 new_test_ext().execute_with(|| {689 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);681 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));690682691 let origin1 = Origin::signed(1);683 let origin1 = Origin::signed(1);692 assert_ok!(TemplateModule::add_collection_admin(684 assert_ok!(TemplateModule::add_collection_admin(699 create_test_item(collection_id, &data.into());691 create_test_item(collection_id, &data.into());700692701 // check balance (collection with id = 1, user id = 1)693 // check balance (collection with id = 1, user id = 1)702 assert_eq!(TemplateModule::balance_count(1, 1), 5);694 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);703695704 // burn item696 // burn item705 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));697 assert_ok!(TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 5));706 assert_noop!(698 assert_noop!(707 TemplateModule::burn_item(origin1, 1, 1, 5),699 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5),708 Error::<Test>::TokenValueNotEnough700 CommonError::<Test>::TokenValueNotEnough709 );701 );710702711 assert_eq!(TemplateModule::balance_count(1, 1), 0);703 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 0);712 });704 });713}705}714706715#[test]707#[test]716fn burn_refungible_item() {708fn burn_refungible_item() {717 new_test_ext().execute_with(|| {709 new_test_ext().execute_with(|| {718 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);710 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));719 let origin1 = Origin::signed(1);711 let origin1 = Origin::signed(1);720712721 assert_ok!(TemplateModule::set_mint_permission(713 assert_ok!(TemplateModule::set_mint_permission(730 ));722 ));731 assert_ok!(TemplateModule::add_to_allow_list(723 assert_ok!(TemplateModule::add_to_allow_list(732 origin1.clone(),724 origin1.clone(),733 1,725 collection_id,734 account(1)726 account(1)735 ));727 ));736728737 assert_ok!(TemplateModule::add_collection_admin(729 assert_ok!(TemplateModule::add_collection_admin(738 origin1.clone(),730 origin1.clone(),739 1,731 collection_id,740 account(2)732 account(2)741 ));733 ));742734743 let data = default_re_fungible_data();735 let data = default_re_fungible_data();744 create_test_item(collection_id, &data.into());736 create_test_item(collection_id, &data.into());745737746 // check balance (collection with id = 1, user id = 2)738 // check balance (collection with id = 1, user id = 2)747 assert_eq!(TemplateModule::balance_count(1, 1), 1023);739 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);740 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);748741749 // burn item742 // burn item750 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));743 assert_ok!(TemplateModule::burn_item(origin1.clone(), collection_id, TokenId(1), 1023));751 assert_noop!(744 assert_noop!(752 TemplateModule::burn_item(origin1, 1, 1, 1023),745 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023),753 Error::<Test>::TokenNotFound746 CommonError::<Test>::TokenNotFound754 );747 );755748756 assert_eq!(TemplateModule::balance_count(1, 1), 0);749 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 0);757 });750 });758}751}759752760#[test]753#[test]761fn add_collection_admin() {754fn add_collection_admin() {762 new_test_ext().execute_with(|| {755 new_test_ext().execute_with(|| {763 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);756 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));764 create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);757 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(2));765 create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);758 create_test_collection_for_owner(&CollectionMode::NFT, 3, CollectionId(3));766759767 let origin1 = Origin::signed(1);760 let origin1 = Origin::signed(1);768761778 account(3)771 account(3)779 ));772 ));780773781 assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)),);774 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))));775 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));782 assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)),);776 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));783 });777 });784}778}785779786#[test]780#[test]787fn remove_collection_admin() {781fn remove_collection_admin() {788 new_test_ext().execute_with(|| {782 new_test_ext().execute_with(|| {789 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);783 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));790 create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);784 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(2));791 create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);785 create_test_collection_for_owner(&CollectionMode::NFT, 3, CollectionId(3));792786793 let origin1 = Origin::signed(1);787 let origin1 = Origin::signed(1);794 let origin2 = Origin::signed(2);788 let origin2 = Origin::signed(2);805 account(3)799 account(3)806 ));800 ));807801808 assert!(TemplateModule::admin_list_collection(1).contains(&account(2)),);802 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));809 assert!(TemplateModule::admin_list_collection(1).contains(&account(3)),);803 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));810804811 // remove admin805 // remove admin812 assert_ok!(TemplateModule::remove_collection_admin(806 assert_ok!(TemplateModule::remove_collection_admin(813 origin2,807 origin2,814 1,808 CollectionId(1),815 account(3)809 account(3)816 ));810 ));817 assert!(!TemplateModule::admin_list_collection(1).contains(&account(3)),);811 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));812 assert_eq!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))), false);818 });813 });819}814}820815821#[test]816#[test]822fn balance_of() {817fn balance_of() {823 new_test_ext().execute_with(|| {818 new_test_ext().execute_with(|| {824 let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);819 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));825 let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);820 let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));826 let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);821 let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(3));827822828 // check balance before823 // check balance before829 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);824 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))), 0);830 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);825 assert_eq!(<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))), 0);831 assert_eq!(826 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))), 0);832 TemplateModule::balance_count(re_fungible_collection_id, 1),833 0834 );835827836 let nft_data = default_nft_data();828 let nft_data = default_nft_data();837 create_test_item(nft_collection_id, &nft_data.into());829 create_test_item(nft_collection_id, &nft_data.into());843 create_test_item(re_fungible_collection_id, &re_fungible_data.into());835 create_test_item(re_fungible_collection_id, &re_fungible_data.into());844836845 // check balance (collection with id = 1, user id = 1)837 // check balance (collection with id = 1, user id = 1)846 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);838 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))), 1);847 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);839 assert_eq!(<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))), 5);848 assert_eq!(840 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))), 1023);849 TemplateModule::balance_count(re_fungible_collection_id, 1),841850 1023851 );852 assert_eq!(842 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);853 TemplateModule::nft_item_id(nft_collection_id, 1)854 .unwrap()855 .owner,856 account(1)857 );858 assert_eq!(859 TemplateModule::fungible_item_id(fungible_collection_id, 1).value,860 5861 );862 assert_eq!(843 assert_eq!(<pallet_refungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);863 TemplateModule::refungible_item_id(re_fungible_collection_id, 1)864 .unwrap()865 .owner[0]866 .owner,867 account(1)868 );869 });844 });870}845}871846872#[test]847#[test]873fn approve() {848fn approve() {874 new_test_ext().execute_with(|| {849 new_test_ext().execute_with(|| {875 let collection_id = create_test_collection(&CollectionMode::NFT, 1);850 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));876851877 let data = default_nft_data();852 let data = default_nft_data();878 create_test_item(collection_id, &data.into());853 create_test_item(collection_id, &data.into());879854880 let origin1 = Origin::signed(1);855 let origin1 = Origin::signed(1);881856882 // approve857 // approve883 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1));858 assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1));884 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);859 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));885 });860 });886}861}887862888#[test]863#[test]889fn transfer_from() {864fn transfer_from() {890 new_test_ext().execute_with(|| {865 new_test_ext().execute_with(|| {891 let collection_id = create_test_collection(&CollectionMode::NFT, 1);866 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));892 let origin1 = Origin::signed(1);867 let origin1 = Origin::signed(1);893 let origin2 = Origin::signed(2);868 let origin2 = Origin::signed(2);894869899 assert_ok!(TemplateModule::approve(874 assert_ok!(TemplateModule::approve(900 origin1.clone(),875 origin1.clone(),901 account(2),876 account(2),902 1,877 CollectionId(1),903 1,878 TokenId(1),904 1879 1905 ));880 ));906 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);881 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));907882908 assert_ok!(TemplateModule::set_mint_permission(883 assert_ok!(TemplateModule::set_mint_permission(909 origin1.clone(),884 origin1.clone(),910 1,885 CollectionId(1),911 true886 true912 ));887 ));913 assert_ok!(TemplateModule::set_public_access_mode(888 assert_ok!(TemplateModule::set_public_access_mode(914 origin1.clone(),889 origin1.clone(),915 1,890 CollectionId(1),916 AccessMode::AllowList891 AccessMode::AllowList917 ));892 ));918 assert_ok!(TemplateModule::add_to_allow_list(893 assert_ok!(TemplateModule::add_to_allow_list(919 origin1.clone(),894 origin1.clone(),920 1,895 CollectionId(1),921 account(1)896 account(1)922 ));897 ));923 assert_ok!(TemplateModule::add_to_allow_list(898 assert_ok!(TemplateModule::add_to_allow_list(924 origin1.clone(),899 origin1.clone(),925 1,900 CollectionId(1),926 account(2)901 account(2)927 ));902 ));928 assert_ok!(TemplateModule::add_to_allow_list(origin1, 1, account(3)));903 assert_ok!(TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(3)));929904930 assert_ok!(TemplateModule::transfer_from(905 assert_ok!(TemplateModule::transfer_from(931 origin2,906 origin2,932 account(1),907 account(1),933 account(2),908 account(2),934 1,909 CollectionId(1),935 1,910 TokenId(1),936 1911 1937 ));912 ));938913939 // after transfer914 // after transfer940 assert_eq!(TemplateModule::balance_count(1, 1), 0);915 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))), 0);941 assert_eq!(TemplateModule::balance_count(1, 2), 1);916 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))), 1);942 });917 });943}918}944919950#[test]925#[test]951fn owner_can_add_address_to_allow_list() {926fn owner_can_add_address_to_allow_list() {952 new_test_ext().execute_with(|| {927 new_test_ext().execute_with(|| {953 let collection_id = create_test_collection(&CollectionMode::NFT, 1);928 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));954929955 let origin1 = Origin::signed(1);930 let origin1 = Origin::signed(1);956 assert_ok!(TemplateModule::add_to_allow_list(931 assert_ok!(TemplateModule::add_to_allow_list(957 origin1,932 origin1,958 collection_id,933 collection_id,959 account(2)934 account(2)960 ));935 ));961 assert!(TemplateModule::allow_list(collection_id, 2));936 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));962 });937 });963}938}964939965#[test]940#[test]966fn admin_can_add_address_to_allow_list() {941fn admin_can_add_address_to_allow_list() {967 new_test_ext().execute_with(|| {942 new_test_ext().execute_with(|| {968 let collection_id = create_test_collection(&CollectionMode::NFT, 1);943 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));969 let origin1 = Origin::signed(1);944 let origin1 = Origin::signed(1);970 let origin2 = Origin::signed(2);945 let origin2 = Origin::signed(2);971946979 collection_id,954 collection_id,980 account(3)955 account(3)981 ));956 ));982 assert!(TemplateModule::allow_list(collection_id, 3));957 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(3))));983 });958 });984}959}985960986#[test]961#[test]987fn nonprivileged_user_cannot_add_address_to_allow_list() {962fn nonprivileged_user_cannot_add_address_to_allow_list() {988 new_test_ext().execute_with(|| {963 new_test_ext().execute_with(|| {989 let collection_id = create_test_collection(&CollectionMode::NFT, 1);964 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));990965991 let origin2 = Origin::signed(2);966 let origin2 = Origin::signed(2);992 assert_noop!(967 assert_noop!(993 TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),968 TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),994 Error::<Test>::NoPermission969 CommonError::<Test>::NoPermission995 );970 );996 });971 });997}972}1002 let origin1 = Origin::signed(1);977 let origin1 = Origin::signed(1);10039781004 assert_noop!(979 assert_noop!(1005 TemplateModule::add_to_allow_list(origin1, 1, account(2)),980 TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1006 Error::<Test>::CollectionNotFound981 CommonError::<Test>::CollectionNotFound1007 );982 );1008 });983 });1009}984}10109851011#[test]986#[test]1012fn nobody_can_add_address_to_allow_list_of_deleted_collection() {987fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1013 new_test_ext().execute_with(|| {988 new_test_ext().execute_with(|| {1014 let collection_id = create_test_collection(&CollectionMode::NFT, 1);989 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10159901016 let origin1 = Origin::signed(1);991 let origin1 = Origin::signed(1);1017 assert_ok!(TemplateModule::destroy_collection(992 assert_ok!(TemplateModule::destroy_collection(1020 ));995 ));1021 assert_noop!(996 assert_noop!(1022 TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),997 TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1023 Error::<Test>::CollectionNotFound998 CommonError::<Test>::CollectionNotFound1024 );999 );1025 });1000 });1026}1001}1029#[test]1004#[test]1030fn address_is_already_added_to_allow_list() {1005fn address_is_already_added_to_allow_list() {1031 new_test_ext().execute_with(|| {1006 new_test_ext().execute_with(|| {1032 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1007 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1033 let origin1 = Origin::signed(1);1008 let origin1 = Origin::signed(1);103410091035 assert_ok!(TemplateModule::add_to_allow_list(1010 assert_ok!(TemplateModule::add_to_allow_list(1042 collection_id,1017 collection_id,1043 account(2)1018 account(2)1044 ));1019 ));1045 assert!(TemplateModule::allow_list(collection_id, 2));1020 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1046 });1021 });1047}1022}104810231049#[test]1024#[test]1050fn owner_can_remove_address_from_allow_list() {1025fn owner_can_remove_address_from_allow_list() {1051 new_test_ext().execute_with(|| {1026 new_test_ext().execute_with(|| {1052 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1027 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));105310281054 let origin1 = Origin::signed(1);1029 let origin1 = Origin::signed(1);1055 assert_ok!(TemplateModule::add_to_allow_list(1030 assert_ok!(TemplateModule::add_to_allow_list(1062 collection_id,1037 collection_id,1063 account(2)1038 account(2)1064 ));1039 ));1065 assert!(!TemplateModule::allow_list(collection_id, 2));1040 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1066 });1041 });1067}1042}106810431069#[test]1044#[test]1070fn admin_can_remove_address_from_allow_list() {1045fn admin_can_remove_address_from_allow_list() {1071 new_test_ext().execute_with(|| {1046 new_test_ext().execute_with(|| {1072 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1047 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1073 let origin1 = Origin::signed(1);1048 let origin1 = Origin::signed(1);1074 let origin2 = Origin::signed(2);1049 let origin2 = Origin::signed(2);107510501089 collection_id,1064 collection_id,1090 account(3)1065 account(3)1091 ));1066 ));1092 assert!(!TemplateModule::allow_list(collection_id, 3));1067 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(3))));1093 });1068 });1094}1069}109510701096#[test]1071#[test]1097fn nonprivileged_user_cannot_remove_address_from_allow_list() {1072fn nonprivileged_user_cannot_remove_address_from_allow_list() {1098 new_test_ext().execute_with(|| {1073 new_test_ext().execute_with(|| {1099 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1074 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1100 let origin1 = Origin::signed(1);1075 let origin1 = Origin::signed(1);1101 let origin2 = Origin::signed(2);1076 let origin2 = Origin::signed(2);110210771107 ));1082 ));1108 assert_noop!(1083 assert_noop!(1109 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1084 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1110 Error::<Test>::NoPermission1085 CommonError::<Test>::NoPermission1111 );1086 );1112 assert!(TemplateModule::allow_list(collection_id, 2));1087 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1113 });1088 });1114}1089}111510901119 let origin1 = Origin::signed(1);1094 let origin1 = Origin::signed(1);112010951121 assert_noop!(1096 assert_noop!(1122 TemplateModule::remove_from_allow_list(origin1, 1, account(2)),1097 TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1123 Error::<Test>::CollectionNotFound1098 CommonError::<Test>::CollectionNotFound1124 );1099 );1125 });1100 });1126}1101}112711021128#[test]1103#[test]1129fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1104fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1130 new_test_ext().execute_with(|| {1105 new_test_ext().execute_with(|| {1131 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1106 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1132 let origin1 = Origin::signed(1);1107 let origin1 = Origin::signed(1);1133 let origin2 = Origin::signed(2);1108 let origin2 = Origin::signed(2);113411091140 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1115 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1141 assert_noop!(1116 assert_noop!(1142 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1117 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1143 Error::<Test>::CollectionNotFound1118 CommonError::<Test>::CollectionNotFound1144 );1119 );1145 assert!(!TemplateModule::allow_list(collection_id, 2));1120 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1146 });1121 });1147}1122}114811231149// If address is already removed from allow list, nothing happens1124// If address is already removed from allow list, nothing happens1150#[test]1125#[test]1151fn address_is_already_removed_from_allow_list() {1126fn address_is_already_removed_from_allow_list() {1152 new_test_ext().execute_with(|| {1127 new_test_ext().execute_with(|| {1153 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1128 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1154 let origin1 = Origin::signed(1);1129 let origin1 = Origin::signed(1);115511301156 assert_ok!(TemplateModule::add_to_allow_list(1131 assert_ok!(TemplateModule::add_to_allow_list(1168 collection_id,1143 collection_id,1169 account(2)1144 account(2)1170 ));1145 ));1171 assert!(!TemplateModule::allow_list(collection_id, 2));1146 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1172 });1147 });1173}1148}117411491175// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1150// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1176#[test]1151#[test]1177fn allow_list_test_1() {1152fn allow_list_test_1() {1178 new_test_ext().execute_with(|| {1153 new_test_ext().execute_with(|| {1179 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1154 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));118011551181 let origin1 = Origin::signed(1);1156 let origin1 = Origin::signed(1);118211571195 ));1170 ));119611711197 assert_noop!(1172 assert_noop!(1198 TemplateModule::transfer(origin1, account(3), 1, 1, 1),1173 TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1),1199 Error::<Test>::AddresNotInAllowList1174 CommonError::<Test>::AddressNotInAllowlist1200 );1175 );1201 });1176 });1202}1177}120311781204#[test]1179#[test]1205fn allow_list_test_2() {1180fn allow_list_test_2() {1206 new_test_ext().execute_with(|| {1181 new_test_ext().execute_with(|| {1207 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1182 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1208 let origin1 = Origin::signed(1);1183 let origin1 = Origin::signed(1);120911841210 let data = default_nft_data();1185 let data = default_nft_data();1217 ));1192 ));1218 assert_ok!(TemplateModule::add_to_allow_list(1193 assert_ok!(TemplateModule::add_to_allow_list(1219 origin1.clone(),1194 origin1.clone(),1220 1,1195 collection_id,1221 account(1)1196 account(1)1222 ));1197 ));1223 assert_ok!(TemplateModule::add_to_allow_list(1198 assert_ok!(TemplateModule::add_to_allow_list(1224 origin1.clone(),1199 origin1.clone(),1225 1,1200 collection_id,1226 account(2)1201 account(2)1227 ));1202 ));122812031229 // do approve1204 // do approve1230 assert_ok!(TemplateModule::approve(1205 assert_ok!(TemplateModule::approve(1231 origin1.clone(),1206 origin1.clone(),1232 account(1),1207 account(1),1233 1,1208 collection_id,1234 1,1209 TokenId(1),1235 11210 11236 ));1211 ));1237 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);1212 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));123812131239 assert_ok!(TemplateModule::remove_from_allow_list(1214 assert_ok!(TemplateModule::remove_from_allow_list(1240 origin1.clone(),1215 origin1.clone(),1241 1,1216 collection_id,1242 account(1)1217 account(1)1243 ));1218 ));124412191245 assert_noop!(1220 assert_noop!(1246 TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1221 TemplateModule::transfer_from(origin1, account(1), account(3), CollectionId(1), TokenId(1), 1),1247 Error::<Test>::AddresNotInAllowList1222 CommonError::<Test>::AddressNotInAllowlist1248 );1223 );1249 });1224 });1250}1225}1253#[test]1228#[test]1254fn allow_list_test_3() {1229fn allow_list_test_3() {1255 new_test_ext().execute_with(|| {1230 new_test_ext().execute_with(|| {1256 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1231 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));125712321258 let origin1 = Origin::signed(1);1233 let origin1 = Origin::signed(1);125912341267 ));1242 ));1268 assert_ok!(TemplateModule::add_to_allow_list(1243 assert_ok!(TemplateModule::add_to_allow_list(1269 origin1.clone(),1244 origin1.clone(),1270 1,1245 collection_id,1271 account(1)1246 account(1)1272 ));1247 ));127312481274 assert_noop!(1249 assert_noop!(1275 TemplateModule::transfer(origin1, account(3), 1, 1, 1),1250 TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1),1276 Error::<Test>::AddresNotInAllowList1251 CommonError::<Test>::AddressNotInAllowlist1277 );1252 );1278 });1253 });1279}1254}128012551281#[test]1256#[test]1282fn allow_list_test_4() {1257fn allow_list_test_4() {1283 new_test_ext().execute_with(|| {1258 new_test_ext().execute_with(|| {1284 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1259 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));128512601286 let origin1 = Origin::signed(1);1261 let origin1 = Origin::signed(1);128712621308 assert_ok!(TemplateModule::approve(1283 assert_ok!(TemplateModule::approve(1309 origin1.clone(),1284 origin1.clone(),1310 account(1),1285 account(1),1311 1,1286 collection_id,1312 1,1287 TokenId(1),1313 11288 11314 ));1289 ));1315 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);1290 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));131612911317 assert_ok!(TemplateModule::remove_from_allow_list(1292 assert_ok!(TemplateModule::remove_from_allow_list(1318 origin1.clone(),1293 origin1.clone(),1321 ));1296 ));132212971323 assert_noop!(1298 assert_noop!(1324 TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1299 TemplateModule::transfer_from(origin1, account(1), account(3), collection_id, TokenId(1), 1),1325 Error::<Test>::AddresNotInAllowList1300 CommonError::<Test>::AddressNotInAllowlist1326 );1301 );1327 });1302 });1328}1303}1331#[test]1306#[test]1332fn allow_list_test_5() {1307fn allow_list_test_5() {1333 new_test_ext().execute_with(|| {1308 new_test_ext().execute_with(|| {1334 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1309 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));133513101336 let origin1 = Origin::signed(1);1311 let origin1 = Origin::signed(1);133713121344 AccessMode::AllowList1319 AccessMode::AllowList1345 ));1320 ));1346 assert_noop!(1321 assert_noop!(1347 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1322 TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 5),1348 Error::<Test>::AddresNotInAllowList1323 CommonError::<Test>::AddressNotInAllowlist1349 );1324 );1350 });1325 });1351}1326}1354#[test]1329#[test]1355fn allow_list_test_6() {1330fn allow_list_test_6() {1356 new_test_ext().execute_with(|| {1331 new_test_ext().execute_with(|| {1357 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1332 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));135813331359 let origin1 = Origin::signed(1);1334 let origin1 = Origin::signed(1);13601335136913441370 // do approve1345 // do approve1371 assert_noop!(1346 assert_noop!(1372 TemplateModule::approve(origin1, account(1), 1, 1, 5),1347 TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 5),1373 Error::<Test>::AddresNotInAllowList1348 CommonError::<Test>::AddressNotInAllowlist1374 );1349 );1375 });1350 });1376}1351}1380#[test]1355#[test]1381fn allow_list_test_7() {1356fn allow_list_test_7() {1382 new_test_ext().execute_with(|| {1357 new_test_ext().execute_with(|| {1383 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1358 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));138413591385 let data = default_nft_data();1360 let data = default_nft_data();1386 create_test_item(collection_id, &data.into());1361 create_test_item(collection_id, &data.into());1403 account(2)1378 account(2)1404 ));1379 ));140513801406 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1));1381 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1));1407 });1382 });1408}1383}140913841410#[test]1385#[test]1411fn allow_list_test_8() {1386fn allow_list_test_8() {1412 new_test_ext().execute_with(|| {1387 new_test_ext().execute_with(|| {1413 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1388 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));141413891415 let data = default_nft_data();1390 let data = default_nft_data();1416 create_test_item(collection_id, &data.into());1391 create_test_item(collection_id, &data.into());1437 assert_ok!(TemplateModule::approve(1412 assert_ok!(TemplateModule::approve(1438 origin1.clone(),1413 origin1.clone(),1439 account(1),1414 account(1),1440 1,1415 CollectionId(1), 1441 1,1416 TokenId(1),1442 51417 51443 ));1418 ));1444 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);1419 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));144514201446 assert_ok!(TemplateModule::transfer_from(1421 assert_ok!(TemplateModule::transfer_from(1447 origin1,1422 origin1,1448 account(1),1423 account(1),1449 account(2),1424 account(2),1450 1,1425 CollectionId(1), 1451 1,1426 TokenId(1),1452 11427 11453 ));1428 ));1454 });1429 });1458#[test]1433#[test]1459fn allow_list_test_9() {1434fn allow_list_test_9() {1460 new_test_ext().execute_with(|| {1435 new_test_ext().execute_with(|| {1461 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1436 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1462 let origin1 = Origin::signed(1);1437 let origin1 = Origin::signed(1);146314381464 assert_ok!(TemplateModule::set_public_access_mode(1439 assert_ok!(TemplateModule::set_public_access_mode(1481#[test]1456#[test]1482fn allow_list_test_10() {1457fn allow_list_test_10() {1483 new_test_ext().execute_with(|| {1458 new_test_ext().execute_with(|| {1484 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1459 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));148514601486 let origin1 = Origin::signed(1);1461 let origin1 = Origin::signed(1);1487 let origin2 = Origin::signed(2);1462 let origin2 = Origin::signed(2);1516#[test]1491#[test]1517fn allow_list_test_11() {1492fn allow_list_test_11() {1518 new_test_ext().execute_with(|| {1493 new_test_ext().execute_with(|| {1519 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1494 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));152014951521 let origin1 = Origin::signed(1);1496 let origin1 = Origin::signed(1);1522 let origin2 = Origin::signed(2);1497 let origin2 = Origin::signed(2);1538 ));1513 ));153915141540 assert_noop!(1515 assert_noop!(1541 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1516 TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()),1542 Error::<Test>::PublicMintingNotAllowed1517 CommonError::<Test>::PublicMintingNotAllowed1543 );1518 );1544 });1519 });1545}1520}1548#[test]1523#[test]1549fn allow_list_test_12() {1524fn allow_list_test_12() {1550 new_test_ext().execute_with(|| {1525 new_test_ext().execute_with(|| {1551 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1526 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));155215271553 let origin1 = Origin::signed(1);1528 let origin1 = Origin::signed(1);1554 let origin2 = Origin::signed(2);1529 let origin2 = Origin::signed(2);1565 ));1540 ));156615411567 assert_noop!(1542 assert_noop!(1568 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1543 TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()),1569 Error::<Test>::PublicMintingNotAllowed1544 CommonError::<Test>::PublicMintingNotAllowed1570 );1545 );1571 });1546 });1572}1547}1575#[test]1550#[test]1576fn allow_list_test_13() {1551fn allow_list_test_13() {1577 new_test_ext().execute_with(|| {1552 new_test_ext().execute_with(|| {1578 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1553 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));157915541580 let origin1 = Origin::signed(1);1555 let origin1 = Origin::signed(1);158115561599#[test]1574#[test]1600fn allow_list_test_14() {1575fn allow_list_test_14() {1601 new_test_ext().execute_with(|| {1576 new_test_ext().execute_with(|| {1602 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1577 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));160315781604 let origin1 = Origin::signed(1);1579 let origin1 = Origin::signed(1);1605 let origin2 = Origin::signed(2);1580 let origin2 = Origin::signed(2);162315981624 assert_ok!(TemplateModule::create_item(1599 assert_ok!(TemplateModule::create_item(1625 origin2,1600 origin2,1626 1,1601 collection_id,1627 account(2),1602 account(2),1628 default_nft_data().into()1603 default_nft_data().into()1629 ));1604 ));1634#[test]1609#[test]1635fn allow_list_test_15() {1610fn allow_list_test_15() {1636 new_test_ext().execute_with(|| {1611 new_test_ext().execute_with(|| {1637 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1612 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));163816131639 let origin1 = Origin::signed(1);1614 let origin1 = Origin::signed(1);1640 let origin2 = Origin::signed(2);1615 let origin2 = Origin::signed(2);1651 ));1626 ));165216271653 assert_noop!(1628 assert_noop!(1654 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),1629 TemplateModule::create_item(origin2, collection_id, account(2), default_nft_data().into()),1655 Error::<Test>::AddresNotInAllowList1630 CommonError::<Test>::AddressNotInAllowlist1656 );1631 );1657 });1632 });1658}1633}1661#[test]1636#[test]1662fn allow_list_test_16() {1637fn allow_list_test_16() {1663 new_test_ext().execute_with(|| {1638 new_test_ext().execute_with(|| {1664 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1639 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));166516401666 let origin1 = Origin::signed(1);1641 let origin1 = Origin::signed(1);1667 let origin2 = Origin::signed(2);1642 let origin2 = Origin::signed(2);168416591685 assert_ok!(TemplateModule::create_item(1660 assert_ok!(TemplateModule::create_item(1686 origin2,1661 origin2,1687 1,1662 collection_id,1688 account(2),1663 account(2),1689 default_nft_data().into()1664 default_nft_data().into()1690 ));1665 ));1695#[test]1670#[test]1696fn total_number_collections_bound() {1671fn total_number_collections_bound() {1697 new_test_ext().execute_with(|| {1672 new_test_ext().execute_with(|| {1698 create_test_collection(&CollectionMode::NFT, 1);1673 create_test_collection(&CollectionMode::NFT, CollectionId(1));1699 });1674 });1700}1675}170116761706 let origin1 = Origin::signed(1);1681 let origin1 = Origin::signed(1);170716821708 for i in 0..COLLECTION_NUMBER_LIMIT {1683 for i in 0..COLLECTION_NUMBER_LIMIT {1709 create_test_collection(&CollectionMode::NFT, i + 1);1684 create_test_collection(&CollectionMode::NFT, CollectionId(i + 1));1710 }1685 }171116861712 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1687 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1722 token_prefix1,1697 token_prefix1,1723 CollectionMode::NFT1698 CollectionMode::NFT1724 ),1699 ),1725 Error::<Test>::TotalCollectionsLimitExceeded1700 CommonError::<Test>::TotalCollectionsLimitExceeded1726 );1701 );1727 });1702 });1728}1703}1731#[test]1706#[test]1732fn owned_tokens_bound() {1707fn owned_tokens_bound() {1733 new_test_ext().execute_with(|| {1708 new_test_ext().execute_with(|| {1734 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1709 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));173517101736 let data = default_nft_data();1711 let data = default_nft_data();1737 create_test_item(collection_id, &data.clone().into());1712 create_test_item(collection_id, &data.clone().into());1743#[test]1718#[test]1744fn owned_tokens_bound_neg() {1719fn owned_tokens_bound_neg() {1745 new_test_ext().execute_with(|| {1720 new_test_ext().execute_with(|| {1746 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1721 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));174717221748 let origin1 = Origin::signed(1);1723 let origin1 = Origin::signed(1);174917241750 for _ in 0..ACCOUNT_TOKEN_OWNERSHIP_LIMIT {1725 for _ in 0..MAX_TOKEN_OWNERSHIP {1751 let data = default_nft_data();1726 let data = default_nft_data();1752 create_test_item(collection_id, &data.clone().into());1727 create_test_item(collection_id, &data.clone().into());1753 }1728 }175417291755 let data = default_nft_data();1730 let data = default_nft_data();1756 assert_noop!(1731 assert_noop!(1757 TemplateModule::create_item(origin1, 1, account(1), data.into()),1732 TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into()),1758 Error::<Test>::AccountTokenLimitExceeded1733 CommonError::<Test>::AccountTokenLimitExceeded1759 );1734 );1760 });1735 });1761}1736}1764#[test]1739#[test]1765fn collection_admins_bound() {1740fn collection_admins_bound() {1766 new_test_ext().execute_with(|| {1741 new_test_ext().execute_with(|| {1767 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1742 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));176817431769 let origin1 = Origin::signed(1);1744 let origin1 = Origin::signed(1);177017451785#[test]1760#[test]1786fn collection_admins_bound_neg() {1761fn collection_admins_bound_neg() {1787 new_test_ext().execute_with(|| {1762 new_test_ext().execute_with(|| {1788 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1763 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));178917641790 let origin1 = Origin::signed(1);1765 let origin1 = Origin::signed(1);179117661792 for i in 0..COLLECTION_ADMINS_LIMIT {1767 for i in 0..COLLECTION_ADMINS_LIMIT {1793 assert_ok!(TemplateModule::add_collection_admin(1768 assert_ok!(TemplateModule::add_collection_admin(1794 origin1.clone(),1769 origin1.clone(),1795 collection_id,1770 collection_id,1796 account(2 + i)1771 account((2 + i).into())1797 ));1772 ));1798 }1773 }1799 assert_noop!(1774 assert_noop!(1800 TemplateModule::add_collection_admin(1775 TemplateModule::add_collection_admin(1801 origin1,1776 origin1,1802 collection_id,1777 collection_id,1803 account(3 + COLLECTION_ADMINS_LIMIT)1778 account((3 + COLLECTION_ADMINS_LIMIT).into())1804 ),1779 ),1805 Error::<Test>::CollectionAdminsLimitExceeded1780 CommonError::<Test>::CollectionAdminCountExceeded1806 );1781 );1807 });1782 });1808}1783}1811#[test]1786#[test]1812fn set_const_on_chain_schema() {1787fn set_const_on_chain_schema() {1813 new_test_ext().execute_with(|| {1788 new_test_ext().execute_with(|| {1814 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1789 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));181517901816 let origin1 = Origin::signed(1);1791 let origin1 = Origin::signed(1);1817 assert_ok!(TemplateModule::set_const_on_chain_schema(1792 assert_ok!(TemplateModule::set_const_on_chain_schema(1821 ));1796 ));182217971823 assert_eq!(1798 assert_eq!(1824 TemplateModule::collection_id(collection_id)1799 <pallet_common::CollectionById<Test>>::get(collection_id)1825 .unwrap()1800 .unwrap()1826 .const_on_chain_schema,1801 .const_on_chain_schema,1827 b"test const on chain schema".to_vec()1802 b"test const on chain schema".to_vec()1828 );1803 );1829 assert_eq!(1804 assert_eq!(1830 TemplateModule::collection_id(collection_id)1805 <pallet_common::CollectionById<Test>>::get(collection_id)1831 .unwrap()1806 .unwrap()1832 .variable_on_chain_schema,1807 .variable_on_chain_schema,1833 b"".to_vec()1808 b"".to_vec()1838#[test]1813#[test]1839fn set_variable_on_chain_schema() {1814fn set_variable_on_chain_schema() {1840 new_test_ext().execute_with(|| {1815 new_test_ext().execute_with(|| {1841 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1816 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));184218171843 let origin1 = Origin::signed(1);1818 let origin1 = Origin::signed(1);1844 assert_ok!(TemplateModule::set_variable_on_chain_schema(1819 assert_ok!(TemplateModule::set_variable_on_chain_schema(1848 ));1823 ));184918241850 assert_eq!(1825 assert_eq!(1851 TemplateModule::collection_id(collection_id)1826 <pallet_common::CollectionById<Test>>::get(collection_id)1852 .unwrap()1827 .unwrap()1853 .const_on_chain_schema,1828 .const_on_chain_schema,1854 b"".to_vec()1829 b"".to_vec()1855 );1830 );1856 assert_eq!(1831 assert_eq!(1857 TemplateModule::collection_id(collection_id)1832 <pallet_common::CollectionById<Test>>::get(collection_id)1858 .unwrap()1833 .unwrap()1859 .variable_on_chain_schema,1834 .variable_on_chain_schema,1860 b"test variable on chain schema".to_vec()1835 b"test variable on chain schema".to_vec()1865#[test]1840#[test]1866fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1841fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1867 new_test_ext().execute_with(|| {1842 new_test_ext().execute_with(|| {1868 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1843 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));186918441870 let origin1 = Origin::signed(1);1845 let origin1 = Origin::signed(1);187118461872 let data = default_nft_data();1847 let data = default_nft_data();1873 create_test_item(1, &data.into());1848 create_test_item(CollectionId(1), &data.into());187418491875 let variable_data = b"test data".to_vec();1850 let variable_data = b"test data".to_vec();1876 assert_ok!(TemplateModule::set_variable_meta_data(1851 assert_ok!(TemplateModule::set_variable_meta_data(1877 origin1,1852 origin1,1878 collection_id,1853 collection_id,1879 1,1854 TokenId(1),1880 variable_data.clone()1855 variable_data.clone()1881 ));1856 ));188218571883 assert_eq!(1858 assert_eq!(1884 TemplateModule::nft_item_id(collection_id, 1)1859 <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))1885 .unwrap()1860 .unwrap()1886 .variable_data,1861 .variable_data,1887 variable_data1862 variable_data1892#[test]1867#[test]1893fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1868fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1894 new_test_ext().execute_with(|| {1869 new_test_ext().execute_with(|| {1895 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);1870 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));189618711897 let origin1 = Origin::signed(1);1872 let origin1 = Origin::signed(1);189818731899 let data = default_re_fungible_data();1874 let data = default_re_fungible_data();1900 create_test_item(1, &data.into());1875 create_test_item(collection_id, &data.into());190118761902 let variable_data = b"test data".to_vec();1877 let variable_data = b"test data".to_vec();1903 assert_ok!(TemplateModule::set_variable_meta_data(1878 assert_ok!(TemplateModule::set_variable_meta_data(1904 origin1,1879 origin1,1905 collection_id,1880 collection_id,1906 1,1881 TokenId(1),1907 variable_data.clone()1882 variable_data.clone()1908 ));1883 ));190918841910 assert_eq!(1885 assert_eq!(1911 TemplateModule::refungible_item_id(collection_id, 1)1886 <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)))1912 .unwrap()1913 .variable_data,1887 .variable_data,1914 variable_data1888 variable_data1915 );1889 );1919#[test]1893#[test]1920fn set_variable_meta_data_on_fungible_token_fails() {1894fn set_variable_meta_data_on_fungible_token_fails() {1921 new_test_ext().execute_with(|| {1895 new_test_ext().execute_with(|| {1922 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);1896 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));192318971924 let origin1 = Origin::signed(1);1898 let origin1 = Origin::signed(1);192518991926 let data = default_fungible_data();1900 let data = default_fungible_data();1927 create_test_item(1, &data.into());1901 create_test_item(collection_id, &data.into());192819021929 let variable_data = b"test data".to_vec();1903 let variable_data = b"test data".to_vec();1930 assert_noop!(1904 assert_noop!(1931 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),1905 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),1932 Error::<Test>::CantStoreMetadataInFungibleTokens1906 <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData1933 );1907 );1934 });1908 });1935}1909}193619101937#[test]1911#[test]1938fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1912fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1939 new_test_ext().execute_with(|| {1913 new_test_ext().execute_with(|| {1940 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1914 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));194119151942 let origin1 = Origin::signed(1);1916 let origin1 = Origin::signed(1);194319171944 let data = default_nft_data();1918 let data = default_nft_data();1945 create_test_item(1, &data.into());1919 create_test_item(collection_id, &data.into());194619201947 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1921 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1948 assert_noop!(1922 assert_noop!(1949 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),1923 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),1950 Error::<Test>::TokenVariableDataLimitExceeded1924 CommonError::<Test>::TokenVariableDataLimitExceeded1951 );1925 );1952 });1926 });1953}1927}195419281955#[test]1929#[test]1956fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {1930fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {1957 new_test_ext().execute_with(|| {1931 new_test_ext().execute_with(|| {1958 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);1932 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));195919331960 let origin1 = Origin::signed(1);1934 let origin1 = Origin::signed(1);196119351962 let data = default_re_fungible_data();1936 let data = default_re_fungible_data();1963 create_test_item(1, &data.into());1937 create_test_item(collection_id, &data.into());196419381965 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1939 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1966 assert_noop!(1940 assert_noop!(1967 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),1941 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),1968 Error::<Test>::TokenVariableDataLimitExceeded1942 CommonError::<Test>::TokenVariableDataLimitExceeded1969 );1943 );1970 });1944 });1971}1945}1975 new_test_ext().execute_with(|| {1949 new_test_ext().execute_with(|| {1976 //default_limits();1950 //default_limits();197719511978 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1952 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));197919531980 let origin1 = Origin::signed(1);1954 let origin1 = Origin::signed(1);198119551982 let data = default_nft_data();1956 let data = default_nft_data();1983 create_test_item(1, &data.into());1957 create_test_item(collection_id, &data.into());198419581985 assert_ok!(TemplateModule::set_meta_update_permission_flag(1959 assert_ok!(TemplateModule::set_meta_update_permission_flag(1986 origin1.clone(),1960 origin1.clone(),1992 assert_ok!(TemplateModule::set_variable_meta_data(1966 assert_ok!(TemplateModule::set_variable_meta_data(1993 origin1,1967 origin1,1994 collection_id,1968 collection_id,1995 1,1969 TokenId(1),1996 variable_data.clone()1970 variable_data.clone()1997 ));1971 ));199819721999 assert_eq!(1973 assert_eq!(2000 TemplateModule::nft_item_id(collection_id, 1)1974 <pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2001 .unwrap()1975 .unwrap()2002 .variable_data,1976 .variable_data,2003 variable_data1977 variable_data2008#[test]1982#[test]2009fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {1983fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {2010 new_test_ext().execute_with(|| {1984 new_test_ext().execute_with(|| {2011 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);1985 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));201219862013 let origin1 = Origin::signed(1);1987 let origin1 = Origin::signed(1);201419882024 ));1998 ));202519992026 let data = default_nft_data();2000 let data = default_nft_data();2027 create_test_item(1, &data.into());2001 create_test_item(collection_id, &data.into());202820022029 assert_ok!(TemplateModule::set_meta_update_permission_flag(2003 assert_ok!(TemplateModule::set_meta_update_permission_flag(2030 origin1.clone(),2004 origin1.clone(),2037 TemplateModule::set_variable_meta_data(2011 TemplateModule::set_variable_meta_data(2038 origin1,2012 origin1,2039 collection_id,2013 collection_id,2040 1,2014 TokenId(1),2041 variable_data.clone()2015 variable_data.clone()2042 ),2016 ),2043 Error::<Test>::TokenVariableDataLimitExceeded2017 CommonError::<Test>::TokenVariableDataLimitExceeded2044 );2018 );2045 })2019 })2046}2020}2050 new_test_ext().execute_with(|| {2024 new_test_ext().execute_with(|| {2051 let origin1 = Origin::signed(1);2025 let origin1 = Origin::signed(1);205220262053 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2027 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2054 assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));2028 assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, collection_id, true));205520292056 let data = default_nft_data();2030 let data = default_nft_data();2057 create_test_item(collection_id, &data.into());2031 create_test_item(collection_id, &data.into());2058 assert_eq!(TemplateModule::balance_count(1, 1), 1);2032 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);2059 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2033 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);206020342061 let origin1 = Origin::signed(1);2035 let origin1 = Origin::signed(1);206220362063 // default scenario2037 // default scenario2064 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));2038 assert_ok!(TemplateModule::transfer(origin1, account(2), collection_id, TokenId(1), 1000));2065 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));2039 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);2066 assert_eq!(TemplateModule::balance_count(1, 1), 0);2040 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);2067 assert_eq!(TemplateModule::balance_count(1, 2), 1);2041 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);20682069 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);2042 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);2070 });2043 });2071}2044}207220452075 new_test_ext().execute_with(|| {2048 new_test_ext().execute_with(|| {2076 // default_limits();2049 // default_limits();207720502078 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2051 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));207920522080 let origin1 = Origin::signed(1);2053 let origin1 = Origin::signed(1);2081 let origin2 = Origin::signed(2);2054 let origin2 = Origin::signed(2);2098 ));2071 ));209920722100 let data = default_nft_data();2073 let data = default_nft_data();2101 create_test_item(1, &data.into());2074 create_test_item(collection_id, &data.into());210220752103 assert_ok!(TemplateModule::set_meta_update_permission_flag(2076 assert_ok!(TemplateModule::set_meta_update_permission_flag(2104 origin2.clone(),2077 origin2.clone(),2110 assert_ok!(TemplateModule::set_variable_meta_data(2083 assert_ok!(TemplateModule::set_variable_meta_data(2111 origin1,2084 origin1,2112 collection_id,2085 collection_id,2113 1,2086 TokenId(1),2114 variable_data.clone()2087 variable_data.clone()2115 ));2088 ));211620892117 assert_eq!(2090 assert_eq!(2118 TemplateModule::nft_item_id(collection_id, 1)2091 <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2119 .unwrap()2092 .unwrap()2120 .variable_data,2093 .variable_data,2121 variable_data2094 variable_data2128 new_test_ext().execute_with(|| {2101 new_test_ext().execute_with(|| {2129 // default_limits();2102 // default_limits();213021032131 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2104 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));213221052133 let origin1 = Origin::signed(1);2106 let origin1 = Origin::signed(1);2134 let origin2 = Origin::signed(2);2107 let origin2 = Origin::signed(2);2145 ));2118 ));214621192147 let data = default_nft_data();2120 let data = default_nft_data();2148 create_test_item(1, &data.into());2121 create_test_item(collection_id, &data.into());214921222150 assert_ok!(TemplateModule::set_meta_update_permission_flag(2123 assert_ok!(TemplateModule::set_meta_update_permission_flag(2151 origin2.clone(),2124 origin2.clone(),2158 TemplateModule::set_variable_meta_data(2131 TemplateModule::set_variable_meta_data(2159 origin1,2132 origin1,2160 collection_id,2133 collection_id,2161 1,2134 TokenId(1),2162 variable_data.clone()2135 variable_data.clone()2163 ),2136 ),2164 Error::<Test>::NoPermission2137 CommonError::<Test>::NoPermission2165 );2138 );2166 });2139 });2167}2140}2171 new_test_ext().execute_with(|| {2144 new_test_ext().execute_with(|| {2172 // default_limits();2145 // default_limits();217321462174 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2147 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));217521482176 let origin2 = Origin::signed(2);2149 let origin2 = Origin::signed(2);217721502186 collection_id,2159 collection_id,2187 MetaUpdatePermission::Admin2160 MetaUpdatePermission::Admin2188 ),2161 ),2189 Error::<Test>::MetadataFlagFrozen2162 CommonError::<Test>::MetadataFlagFrozen2190 );2163 );2191 });2164 });2192}2165}2196 new_test_ext().execute_with(|| {2169 new_test_ext().execute_with(|| {2197 // default_limits();2170 // default_limits();219821712199 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);2172 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2200 let origin1 = Origin::signed(1);2173 let origin1 = Origin::signed(1);220121742202 let data = default_nft_data();2175 let data = default_nft_data();2203 create_test_item(1, &data.into());2176 create_test_item(collection_id, &data.into());220421772205 assert_ok!(TemplateModule::set_meta_update_permission_flag(2178 assert_ok!(TemplateModule::set_meta_update_permission_flag(2206 origin1.clone(),2179 origin1.clone(),2213 TemplateModule::set_variable_meta_data(2186 TemplateModule::set_variable_meta_data(2214 origin1.clone(),2187 origin1.clone(),2215 collection_id,2188 collection_id,2216 1,2189 TokenId(1),2217 variable_data.clone()2190 variable_data.clone()2218 ),2191 ),2219 Error::<Test>::MetadataUpdateDenied2192 CommonError::<Test>::NoPermission2220 );2193 );2221 });2194 });2222}2195}2226 new_test_ext().execute_with(|| {2199 new_test_ext().execute_with(|| {2227 let origin1 = Origin::signed(1);2200 let origin1 = Origin::signed(1);222822012229 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2202 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2230 assert_ok!(TemplateModule::set_transfers_enabled_flag(2203 assert_ok!(TemplateModule::set_transfers_enabled_flag(2231 origin1, 1, false2204 origin1, collection_id, false2232 ));2205 ));223322062234 let data = default_nft_data();2207 let data = default_nft_data();2235 create_test_item(collection_id, &data.into());2208 create_test_item(collection_id, &data.into());2236 assert_eq!(TemplateModule::balance_count(1, 1), 1);2209 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);2237 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2210 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);223822112239 let origin1 = Origin::signed(1);2212 let origin1 = Origin::signed(1);224022132241 // default scenario2214 // default scenario2242 assert_noop!(2215 assert_noop!(2243 TemplateModule::transfer(origin1, account(2), 1, 1, 1000),2216 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1000),2244 Error::<Test>::TransferNotAllowed2217 CommonError::<Test>::TransferNotAllowed2245 );2218 );2246 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));2219 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);2247 assert_eq!(TemplateModule::balance_count(1, 1), 1);2220 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 0);2248 assert_eq!(TemplateModule::balance_count(1, 2), 0);2221 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);22492250 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2222 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), false);2251 });2223 });2252}2224}22532225pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -58,18 +58,18 @@
}
#[pallet::pallet]
- #[pallet::generate_store(pub(super) trait Store)]
+ #[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
- pub(super) type TokensMinted<T: Config> =
+ pub type TokensMinted<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type TokensBurnt<T: Config> =
+ pub type TokensBurnt<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type TokenData<T: Config> = StorageNMap<
+ pub type TokenData<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = ItemData<T>,
QueryKind = OptionQuery,
@@ -77,7 +77,7 @@
/// Used to enumerate tokens owned by account
#[pallet::storage]
- pub(super) type Owned<T: Config> = StorageNMap<
+ pub type Owned<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -88,7 +88,7 @@
>;
#[pallet::storage]
- pub(super) type AccountBalance<T: Config> = StorageNMap<
+ pub type AccountBalance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -98,7 +98,7 @@
>;
#[pallet::storage]
- pub(super) type Allowance<T: Config> = StorageNMap<
+ pub type Allowance<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = T::CrossAccountId,
QueryKind = OptionQuery,
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -54,25 +54,25 @@
}
#[pallet::pallet]
- #[pallet::generate_store(pub(super) trait Store)]
+ #[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
- pub(super) type TokensMinted<T: Config> =
+ pub type TokensMinted<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type TokensBurnt<T: Config> =
+ pub type TokensBurnt<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type TokenData<T: Config> = StorageNMap<
+ pub type TokenData<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = ItemData,
QueryKind = ValueQuery,
>;
#[pallet::storage]
- pub(super) type TotalSupply<T: Config> = StorageNMap<
+ pub type TotalSupply<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = u128,
QueryKind = ValueQuery,
@@ -80,7 +80,7 @@
/// Used to enumerate tokens owned by account
#[pallet::storage]
- pub(super) type Owned<T: Config> = StorageNMap<
+ pub type Owned<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -91,7 +91,7 @@
>;
#[pallet::storage]
- pub(super) type AccountBalance<T: Config> = StorageNMap<
+ pub type AccountBalance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
// Owner
@@ -102,7 +102,7 @@
>;
#[pallet::storage]
- pub(super) type Balance<T: Config> = StorageNMap<
+ pub type Balance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Twox64Concat, TokenId>,
@@ -114,7 +114,7 @@
>;
#[pallet::storage]
- pub(super) type Allowance<T: Config> = StorageNMap<
+ pub type Allowance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Twox64Concat, TokenId>,