git.delta.rocks / unique-network / refs/commits / a1bffc717b20

difftreelog

Fix unit test building

Greg Zaitsev2021-11-23parent: #76d8b56.patch.diff
in: master

8 files changed

modifiedCargo.lockdiffbeforeafterboth
5097 "frame-system-rpc-runtime-api",5097 "frame-system-rpc-runtime-api",
5098 "hex-literal",5098 "hex-literal",
5099 "nft-data-structs",5099 "nft-data-structs",
5100 "orml-vesting",
5100 "pallet-aura",5101 "pallet-aura",
5101 "pallet-balances",5102 "pallet-balances",
5102 "pallet-common",5103 "pallet-common",
5120 "pallet-transaction-payment-rpc-runtime-api",5121 "pallet-transaction-payment-rpc-runtime-api",
5121 "pallet-treasury",5122 "pallet-treasury",
5122 "pallet-unq-scheduler",5123 "pallet-unq-scheduler",
5123 "pallet-vesting",
5124 "pallet-xcm",5124 "pallet-xcm",
5125 "parachain-info",5125 "parachain-info",
5126 "parity-scale-codec",5126 "parity-scale-codec",
5307 "num-traits",5307 "num-traits",
5308]5308]
5309
5310[[package]]
5311name = "orml-vesting"
5312version = "0.4.1-dev"
5313source = "git+https://github.com/UniqueNetwork/open-runtime-module-library#d69f226e332ae29b7b33d53d2f06f309d2986ea0"
5314dependencies = [
5315 "frame-support",
5316 "frame-system",
5317 "parity-scale-codec",
5318 "scale-info",
5319 "serde",
5320 "sp-io",
5321 "sp-runtime",
5322 "sp-std",
5323]
53095324
5310[[package]]5325[[package]]
5311name = "owning_ref"5326name = "owning_ref"
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
273 TotalCollectionsLimitExceeded,273 TotalCollectionsLimitExceeded,
274 /// variable_data exceeded data limit.274 /// variable_data exceeded data limit.
275 TokenVariableDataLimitExceeded,275 TokenVariableDataLimitExceeded,
276 /// Exceeded max admin amount276 /// Exceeded max admin count
277 CollectionAdminAmountExceeded,277 CollectionAdminCountExceeded,
278278
279 /// Collection settings not allowing items transferring279 /// Collection settings not allowing items transferring
280 TransferNotAllowed,280 TransferNotAllowed,
479 if admin {479 if admin {
480 let amount = amount480 let amount = amount
481 .checked_add(1)481 .checked_add(1)
482 .ok_or(<Error<T>>::CollectionAdminAmountExceeded)?;482 .ok_or(<Error<T>>::CollectionAdminCountExceeded)?;
483 ensure!(483 ensure!(
484 amount <= Self::collection_admins_limit(),484 amount <= Self::collection_admins_limit(),
485 <Error<T>>::CollectionAdminAmountExceeded,485 <Error<T>>::CollectionAdminCountExceeded,
486 );486 );
487487
488 // =========488 // =========
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
182 _token: TokenId,182 _token: TokenId,
183 _data: Vec<u8>,183 _data: Vec<u8>,
184 ) -> DispatchResultWithPostInfo {184 ) -> DispatchResultWithPostInfo {
185 fail!(<Error<T>>::FungibleItemsHaveData)185 fail!(<Error<T>>::FungibleItemsDontHaveData)
186 }186 }
187187
188 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {188 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
35 /// Not default id passed as TokenId argument35 /// Not default id passed as TokenId argument
36 FungibleItemsHaveNoId,36 FungibleItemsHaveNoId,
37 /// Tried to set data for fungible item37 /// Tried to set data for fungible item
38 FungibleItemsHaveData,38 FungibleItemsDontHaveData,
39 }39 }
4040
41 #[pallet::config]41 #[pallet::config]
44 }44 }
4545
46 #[pallet::pallet]46 #[pallet::pallet]
47 #[pallet::generate_store(pub(super) trait Store)]47 #[pallet::generate_store(pub trait Store)]
48 pub struct Pallet<T>(_);48 pub struct Pallet<T>(_);
4949
50 #[pallet::storage]50 #[pallet::storage]
51 pub(super) type TotalSupply<T: Config> =51 pub type TotalSupply<T: Config> =
52 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;52 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;
5353
54 #[pallet::storage]54 #[pallet::storage]
55 pub(super) type Balance<T: Config> = StorageNMap<55 pub type Balance<T: Config> = StorageNMap<
56 Key = (56 Key = (
57 Key<Twox64Concat, CollectionId>,57 Key<Twox64Concat, CollectionId>,
58 Key<Blake2_128Concat, T::CrossAccountId>,58 Key<Blake2_128Concat, T::CrossAccountId>,
62 >;62 >;
6363
64 #[pallet::storage]64 #[pallet::storage]
65 pub(super) type Allowance<T: Config> = StorageNMap<65 pub type Allowance<T: Config> = StorageNMap<
66 Key = (66 Key = (
67 Key<Twox64Concat, CollectionId>,67 Key<Twox64Concat, CollectionId>,
68 Key<Blake2_128, T::CrossAccountId>,68 Key<Blake2_128, T::CrossAccountId>,
modifiedpallets/nft/src/mock.rsdiffbeforeafterboth
124#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]124#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]
125pub struct TestCrossAccountId(u64, sp_core::H160);125pub struct TestCrossAccountId(u64, sp_core::H160);
126impl CrossAccountId<u64> for TestCrossAccountId {126impl CrossAccountId<u64> for TestCrossAccountId {
127 fn as_sub(&self) -> &u64 {
128 &self.0
129 }
130 fn as_eth(&self) -> &sp_core::H160 {
131 &self.1
132 }
127 fn from_sub(sub: u64) -> Self {133 fn from_sub(sub: u64) -> Self {
128 let mut eth = [0; 20];134 let mut eth = [0; 20];
129 eth[12..20].copy_from_slice(&sub.to_be_bytes());135 eth[12..20].copy_from_slice(&sub.to_be_bytes());
130 Self(sub, sp_core::H160(eth))136 Self(sub, sp_core::H160(eth))
131 }137 }
132 fn as_sub(&self) -> &u64 {
133 &self.0
134 }
135 fn from_eth(eth: sp_core::H160) -> Self {138 fn from_eth(eth: sp_core::H160) -> Self {
136 let mut sub_raw = [0; 8];139 let mut sub_raw = [0; 8];
137 sub_raw.copy_from_slice(&eth.0[0..8]);140 sub_raw.copy_from_slice(&eth.0[0..8]);
138 let sub = u64::from_be_bytes(sub_raw);141 let sub = u64::from_be_bytes(sub_raw);
139 Self(sub, eth)142 Self(sub, eth)
140 }143 }
141 fn as_eth(&self) -> &sp_core::H160 {144 fn conv_eq(&self, other: &Self) -> bool {
142 &self.1145 self.as_sub() == other.as_sub()
143 }146 }
144}147}
148
149impl Default for TestCrossAccountId {
150 fn default() -> Self {
151 Self::from_sub(0)
152 }
153}
154
145155
146pub struct TestEtheremTransactionSender;156pub struct TestEtheremTransactionSender;
157 type EthereumTransactionSender = TestEtheremTransactionSender;167 type EthereumTransactionSender = TestEtheremTransactionSender;
158}168}
169
170impl pallet_common::Config for Test {
171 type Event = ();
172 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;
173 type EvmAddressMapping = TestEvmAddressMapping;
174 type CrossAccountId = TestCrossAccountId;
175
176 type Currency = Balances;
177 type CollectionCreationPrice = CollectionCreationPrice;
178 type TreasuryAccountId = TreasuryAccountId;
179}
180
181impl pallet_fungible::Config for Test {
182 type WeightInfo = ();
183}
184impl pallet_refungible::Config for Test {
185 type WeightInfo = ();
186}
187impl pallet_nonfungible::Config for Test {
188 type WeightInfo = ();
189}
159190
160impl pallet_template::Config for Test {191impl pallet_template::Config for Test {
161 type WeightInfo = ();192 type WeightInfo = ();
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
1// Tests to be written here1// Tests to be written here
2use super::*;2use super::*;
3use crate::mock::*;3use crate::mock::*;
4use crate::{AccessMode, CollectionMode, 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};
11
9use frame_support::{assert_noop, assert_ok};12use frame_support::{assert_noop, assert_ok};
10use sp_std::convert::TryInto;13use sp_std::convert::TryInto;
1114
49 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_name
56 );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_description
61 );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_prefix
65 );68 );
66 id69 id
91fn 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));
9598
96 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::Unique
100 ));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::Unique
131#[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));
135138
136 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());
141
138 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));
150154
151 let origin1 = Origin::signed(1);155 let origin1 = Origin::signed(1);
152156
153 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()];
154158
155 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_data
160 .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));
177181
178 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));
192196
193 let origin1 = Origin::signed(1);197 let origin1 = Origin::signed(1);
194198
200204
201 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_data
206 .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));
225229
226 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());
228232
229 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}
232236
235// new_test_ext().execute_with(|| {239// new_test_ext().execute_with(|| {
236// default_limits();240// default_limits();
237241
238// create_test_collection(&CollectionMode::Fungible(3), 1);242// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
239243
240// let origin1 = Origin::signed(1);244// let origin1 = Origin::signed(1);
241245
259#[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));
263267
264 let origin1 = Origin::signed(1);268 let origin1 = Origin::signed(1);
265 let origin2 = Origin::signed(2);269 let origin2 = Origin::signed(2);
266270
267 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());
269273
270 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);
272275
273 // change owner scenario276 // change owner scenario
274 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);
278279
279 // split item scenario280 // split item scenario
280 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 3
286 ));287 ));
287 assert_eq!(TemplateModule::balance_count(1, 2), 2);
288 assert_eq!(TemplateModule::balance_count(1, 3), 3);
289288
290 // split item and new owner has account scenario289 // split item and new owner has account scenario
291 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}
298295
299#[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));
303300
304 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());
306303
307 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);
318316
319 // change owner scenario317 // change owner scenario
320 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));318 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1023));
321319
322 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);
328326
329 // split item scenario327 // split item scenario
330 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 500
336 ));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);
348346
349 // split item and new owner has account scenario347 // split item and new owner has account scenario
350 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}
364362
365#[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));
369367
370 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);
374372
373
375 let origin1 = Origin::signed(1);374 let origin1 = Origin::signed(1);
376 // default scenario375 // default scenario
377 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}
385383
386#[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));
390388
391 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());
393391
394 let origin1 = Origin::signed(1);392 let origin1 = Origin::signed(1);
395 let origin2 = Origin::signed(2);393 let origin2 = Origin::signed(2);
396394
397 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);
399397
400 // neg transfer398 // neg transfer
401 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>::NoPermission
404 );402 );
405403
406 // do approve404 // do approve
407 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);
410407
411 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 1
418 ));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}
422419
423#[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));
427424
428 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());
433430
434 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);
440437
441 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 true
445 ));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::AllowList
450 ));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 ));
466463
467 // do approve464 // do approve
468 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 5
474 ));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));
478475
479 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 1
486 ));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}
490487
491#[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));
495492
496 let origin1 = Origin::signed(1);493 let origin1 = Origin::signed(1);
497 let origin2 = Origin::signed(2);494 let origin2 = Origin::signed(2);
498495
499 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());
501498
502 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);
504501
505 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 true
509 ));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::AllowList
514 ));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 ));
530527
531 // do approve528 // do approve
532 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);
534531
535 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 100
542 ));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);
547
548 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}
551547
552#[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));
556552
557 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());
559555
560 let origin1 = Origin::signed(1);556 let origin1 = Origin::signed(1);
561 let origin2 = Origin::signed(2);557 let origin2 = Origin::signed(2);
562558
563 assert_eq!(TemplateModule::balance_count(1, 1), 5);
564
565 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 true
569 ));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::AllowList
574 ));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 ));
590584
591 // do approve585 // do approve
592 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 5
598 ));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);
603597
604 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 4
611 ));605 ));
612 assert_eq!(TemplateModule::balance_count(1, 1), 1);
613 assert_eq!(TemplateModule::balance_count(1, 3), 4);
614606
615 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);607 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 1);
616608
617 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>::NoPermission
620 );612 );
621 });613 });
622}614}
623615
624#[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));
628620
629 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 2
634 ));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 2
638 );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));
646638
647 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));
656648
657 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());
666658
667 // 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);
669661
670 // burn item662 // burn item
671 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 1
676 ));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>::TokenNotFound
680 );672 );
681673
682 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}
685677
686#[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));
690682
691 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());
700692
701 // 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);
703695
704 // burn item696 // burn item
705 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>::TokenValueNotEnough
709 );701 );
710702
711 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}
714706
715#[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);
720712
721 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 ));
736728
737 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 ));
742734
743 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());
745737
746 // 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);
748741
749 // burn item742 // burn item
750 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>::TokenNotFound
754 );747 );
755748
756 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}
759752
760#[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));
766759
767 let origin1 = Origin::signed(1);760 let origin1 = Origin::signed(1);
768761
778 account(3)771 account(3)
779 ));772 ));
780773
781 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}
785779
786#[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));
792786
793 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 ));
807801
808 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))));
810804
811 // remove admin805 // remove admin
812 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}
820815
821#[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));
827822
828 // check balance before823 // check balance before
829 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 0
834 );
835827
836 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());
844836
845 // 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),841
850 1023
851 );
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 5
861 );
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}
871846
872#[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));
876851
877 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());
879854
880 let origin1 = Origin::signed(1);855 let origin1 = Origin::signed(1);
881856
882 // approve857 // approve
883 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}
887862
888#[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);
894869
899 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 1
905 ));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));
907882
908 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 true
912 ));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::AllowList
917 ));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)));
929904
930 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 1
937 ));912 ));
938913
939 // after transfer914 // after transfer
940 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}
944919
950#[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));
954929
955 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}
964939
965#[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);
971946
979 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}
985960
986#[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));
990965
991 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>::NoPermission
995 );970 );
996 });971 });
997}972}
1002 let origin1 = Origin::signed(1);977 let origin1 = Origin::signed(1);
1003978
1004 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>::CollectionNotFound
1007 );982 );
1008 });983 });
1009}984}
1010985
1011#[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));
1015990
1016 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>::CollectionNotFound
1024 );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);
10341009
1035 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}
10481023
1049#[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));
10531028
1054 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}
10681043
1069#[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);
10751050
1089 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}
10951070
1096#[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);
11021077
1107 ));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>::NoPermission
1111 );1086 );
1112 assert!(TemplateModule::allow_list(collection_id, 2));1087 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
1113 });1088 });
1114}1089}
11151090
1119 let origin1 = Origin::signed(1);1094 let origin1 = Origin::signed(1);
11201095
1121 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>::CollectionNotFound
1124 );1099 );
1125 });1100 });
1126}1101}
11271102
1128#[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);
11341109
1140 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>::CollectionNotFound
1144 );1119 );
1145 assert!(!TemplateModule::allow_list(collection_id, 2));1120 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
1146 });1121 });
1147}1122}
11481123
1149// If address is already removed from allow list, nothing happens1124// If address is already removed from allow list, nothing happens
1150#[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);
11551130
1156 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}
11741149
1175// 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));
11801155
1181 let origin1 = Origin::signed(1);1156 let origin1 = Origin::signed(1);
11821157
1195 ));1170 ));
11961171
1197 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>::AddressNotInAllowlist
1200 );1175 );
1201 });1176 });
1202}1177}
12031178
1204#[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);
12091184
1210 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 ));
12281203
1229 // do approve1204 // do approve
1230 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 1
1236 ));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));
12381213
1239 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 ));
12441219
1245 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>::AddressNotInAllowlist
1248 );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));
12571232
1258 let origin1 = Origin::signed(1);1233 let origin1 = Origin::signed(1);
12591234
1267 ));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 ));
12731248
1274 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>::AddressNotInAllowlist
1277 );1252 );
1278 });1253 });
1279}1254}
12801255
1281#[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));
12851260
1286 let origin1 = Origin::signed(1);1261 let origin1 = Origin::signed(1);
12871262
1308 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 1
1314 ));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));
13161291
1317 assert_ok!(TemplateModule::remove_from_allow_list(1292 assert_ok!(TemplateModule::remove_from_allow_list(
1318 origin1.clone(),1293 origin1.clone(),
1321 ));1296 ));
13221297
1323 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>::AddressNotInAllowlist
1326 );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));
13351310
1336 let origin1 = Origin::signed(1);1311 let origin1 = Origin::signed(1);
13371312
1344 AccessMode::AllowList1319 AccessMode::AllowList
1345 ));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>::AddressNotInAllowlist
1349 );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));
13581333
1359 let origin1 = Origin::signed(1);1334 let origin1 = Origin::signed(1);
13601335
13691344
1370 // do approve1345 // do approve
1371 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>::AddressNotInAllowlist
1374 );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));
13841359
1385 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 ));
14051380
1406 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}
14091384
1410#[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));
14141389
1415 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 5
1443 ));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));
14451420
1446 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 1
1453 ));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);
14631438
1464 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));
14851460
1486 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));
15201495
1521 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 ));
15391514
1540 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>::PublicMintingNotAllowed
1543 );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));
15521527
1553 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 ));
15661541
1567 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>::PublicMintingNotAllowed
1570 );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));
15791554
1580 let origin1 = Origin::signed(1);1555 let origin1 = Origin::signed(1);
15811556
1599#[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));
16031578
1604 let origin1 = Origin::signed(1);1579 let origin1 = Origin::signed(1);
1605 let origin2 = Origin::signed(2);1580 let origin2 = Origin::signed(2);
16231598
1624 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));
16381613
1639 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 ));
16521627
1653 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>::AddressNotInAllowlist
1656 );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));
16651640
1666 let origin1 = Origin::signed(1);1641 let origin1 = Origin::signed(1);
1667 let origin2 = Origin::signed(2);1642 let origin2 = Origin::signed(2);
16841659
1685 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}
17011676
1706 let origin1 = Origin::signed(1);1681 let origin1 = Origin::signed(1);
17071682
1708 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 }
17111686
1712 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::NFT
1724 ),1699 ),
1725 Error::<Test>::TotalCollectionsLimitExceeded1700 CommonError::<Test>::TotalCollectionsLimitExceeded
1726 );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));
17351710
1736 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));
17471722
1748 let origin1 = Origin::signed(1);1723 let origin1 = Origin::signed(1);
17491724
1750 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 }
17541729
1755 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>::AccountTokenLimitExceeded
1759 );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));
17681743
1769 let origin1 = Origin::signed(1);1744 let origin1 = Origin::signed(1);
17701745
1785#[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));
17891764
1790 let origin1 = Origin::signed(1);1765 let origin1 = Origin::signed(1);
17911766
1792 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>::CollectionAdminCountExceeded
1806 );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));
18151790
1816 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 ));
18221797
1823 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));
18421817
1843 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 ));
18491824
1850 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));
18691844
1870 let origin1 = Origin::signed(1);1845 let origin1 = Origin::signed(1);
18711846
1872 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());
18741849
1875 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 ));
18821857
1883 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_data
1892#[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));
18961871
1897 let origin1 = Origin::signed(1);1872 let origin1 = Origin::signed(1);
18981873
1899 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());
19011876
1902 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 ));
19091884
1910 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_data
1915 );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));
19231897
1924 let origin1 = Origin::signed(1);1898 let origin1 = Origin::signed(1);
19251899
1926 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());
19281902
1929 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>>::FungibleItemsDontHaveData
1933 );1907 );
1934 });1908 });
1935}1909}
19361910
1937#[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));
19411915
1942 let origin1 = Origin::signed(1);1916 let origin1 = Origin::signed(1);
19431917
1944 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());
19461920
1947 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>::TokenVariableDataLimitExceeded
1951 );1925 );
1952 });1926 });
1953}1927}
19541928
1955#[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));
19591933
1960 let origin1 = Origin::signed(1);1934 let origin1 = Origin::signed(1);
19611935
1962 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());
19641938
1965 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>::TokenVariableDataLimitExceeded
1969 );1943 );
1970 });1944 });
1971}1945}
1975 new_test_ext().execute_with(|| {1949 new_test_ext().execute_with(|| {
1976 //default_limits();1950 //default_limits();
19771951
1978 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1952 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
19791953
1980 let origin1 = Origin::signed(1);1954 let origin1 = Origin::signed(1);
19811955
1982 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());
19841958
1985 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 ));
19981972
1999 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_data
2008#[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));
20121986
2013 let origin1 = Origin::signed(1);1987 let origin1 = Origin::signed(1);
20141988
2024 ));1998 ));
20251999
2026 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());
20282002
2029 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>::TokenVariableDataLimitExceeded
2044 );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);
20522026
2053 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));
20552029
2056 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);
20602034
2061 let origin1 = Origin::signed(1);2035 let origin1 = Origin::signed(1);
20622036
2063 // default scenario2037 // default scenario
2064 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);
2068
2069 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}
20722045
2075 new_test_ext().execute_with(|| {2048 new_test_ext().execute_with(|| {
2076 // default_limits();2049 // default_limits();
20772050
2078 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));
20792052
2080 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 ));
20992072
2100 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());
21022075
2103 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 ));
21162089
2117 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_data
2128 new_test_ext().execute_with(|| {2101 new_test_ext().execute_with(|| {
2129 // default_limits();2102 // default_limits();
21302103
2131 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));
21322105
2133 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 ));
21462119
2147 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());
21492122
2150 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>::NoPermission
2165 );2138 );
2166 });2139 });
2167}2140}
2171 new_test_ext().execute_with(|| {2144 new_test_ext().execute_with(|| {
2172 // default_limits();2145 // default_limits();
21732146
2174 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));
21752148
2176 let origin2 = Origin::signed(2);2149 let origin2 = Origin::signed(2);
21772150
2186 collection_id,2159 collection_id,
2187 MetaUpdatePermission::Admin2160 MetaUpdatePermission::Admin
2188 ),2161 ),
2189 Error::<Test>::MetadataFlagFrozen2162 CommonError::<Test>::MetadataFlagFrozen
2190 );2163 );
2191 });2164 });
2192}2165}
2196 new_test_ext().execute_with(|| {2169 new_test_ext().execute_with(|| {
2197 // default_limits();2170 // default_limits();
21982171
2199 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);
22012174
2202 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());
22042177
2205 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>::NoPermission
2220 );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);
22282201
2229 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, false
2232 ));2205 ));
22332206
2234 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);
22382211
2239 let origin1 = Origin::signed(1);2212 let origin1 = Origin::signed(1);
22402213
2241 // default scenario2214 // default scenario
2242 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>::TransferNotAllowed
2245 );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);
2249
2250 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}
22532225
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
58 }58 }
5959
60 #[pallet::pallet]60 #[pallet::pallet]
61 #[pallet::generate_store(pub(super) trait Store)]61 #[pallet::generate_store(pub trait Store)]
62 pub struct Pallet<T>(_);62 pub struct Pallet<T>(_);
6363
64 #[pallet::storage]64 #[pallet::storage]
65 pub(super) type TokensMinted<T: Config> =65 pub type TokensMinted<T: Config> =
66 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;66 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
67 #[pallet::storage]67 #[pallet::storage]
68 pub(super) type TokensBurnt<T: Config> =68 pub type TokensBurnt<T: Config> =
69 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;69 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
7070
71 #[pallet::storage]71 #[pallet::storage]
72 pub(super) type TokenData<T: Config> = StorageNMap<72 pub type TokenData<T: Config> = StorageNMap<
73 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),73 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
74 Value = ItemData<T>,74 Value = ItemData<T>,
75 QueryKind = OptionQuery,75 QueryKind = OptionQuery,
76 >;76 >;
7777
78 /// Used to enumerate tokens owned by account78 /// Used to enumerate tokens owned by account
79 #[pallet::storage]79 #[pallet::storage]
80 pub(super) type Owned<T: Config> = StorageNMap<80 pub type Owned<T: Config> = StorageNMap<
81 Key = (81 Key = (
82 Key<Twox64Concat, CollectionId>,82 Key<Twox64Concat, CollectionId>,
83 Key<Blake2_128Concat, T::CrossAccountId>,83 Key<Blake2_128Concat, T::CrossAccountId>,
88 >;88 >;
8989
90 #[pallet::storage]90 #[pallet::storage]
91 pub(super) type AccountBalance<T: Config> = StorageNMap<91 pub type AccountBalance<T: Config> = StorageNMap<
92 Key = (92 Key = (
93 Key<Twox64Concat, CollectionId>,93 Key<Twox64Concat, CollectionId>,
94 Key<Blake2_128Concat, T::CrossAccountId>,94 Key<Blake2_128Concat, T::CrossAccountId>,
98 >;98 >;
9999
100 #[pallet::storage]100 #[pallet::storage]
101 pub(super) type Allowance<T: Config> = StorageNMap<101 pub type Allowance<T: Config> = StorageNMap<
102 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),102 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
103 Value = T::CrossAccountId,103 Value = T::CrossAccountId,
104 QueryKind = OptionQuery,104 QueryKind = OptionQuery,
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
54 }54 }
5555
56 #[pallet::pallet]56 #[pallet::pallet]
57 #[pallet::generate_store(pub(super) trait Store)]57 #[pallet::generate_store(pub trait Store)]
58 pub struct Pallet<T>(_);58 pub struct Pallet<T>(_);
5959
60 #[pallet::storage]60 #[pallet::storage]
61 pub(super) type TokensMinted<T: Config> =61 pub type TokensMinted<T: Config> =
62 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;62 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
63 #[pallet::storage]63 #[pallet::storage]
64 pub(super) type TokensBurnt<T: Config> =64 pub type TokensBurnt<T: Config> =
65 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;65 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
6666
67 #[pallet::storage]67 #[pallet::storage]
68 pub(super) type TokenData<T: Config> = StorageNMap<68 pub type TokenData<T: Config> = StorageNMap<
69 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),69 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
70 Value = ItemData,70 Value = ItemData,
71 QueryKind = ValueQuery,71 QueryKind = ValueQuery,
72 >;72 >;
7373
74 #[pallet::storage]74 #[pallet::storage]
75 pub(super) type TotalSupply<T: Config> = StorageNMap<75 pub type TotalSupply<T: Config> = StorageNMap<
76 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),76 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
77 Value = u128,77 Value = u128,
78 QueryKind = ValueQuery,78 QueryKind = ValueQuery,
79 >;79 >;
8080
81 /// Used to enumerate tokens owned by account81 /// Used to enumerate tokens owned by account
82 #[pallet::storage]82 #[pallet::storage]
83 pub(super) type Owned<T: Config> = StorageNMap<83 pub type Owned<T: Config> = StorageNMap<
84 Key = (84 Key = (
85 Key<Twox64Concat, CollectionId>,85 Key<Twox64Concat, CollectionId>,
86 Key<Blake2_128Concat, T::CrossAccountId>,86 Key<Blake2_128Concat, T::CrossAccountId>,
91 >;91 >;
9292
93 #[pallet::storage]93 #[pallet::storage]
94 pub(super) type AccountBalance<T: Config> = StorageNMap<94 pub type AccountBalance<T: Config> = StorageNMap<
95 Key = (95 Key = (
96 Key<Twox64Concat, CollectionId>,96 Key<Twox64Concat, CollectionId>,
97 // Owner97 // Owner
102 >;102 >;
103103
104 #[pallet::storage]104 #[pallet::storage]
105 pub(super) type Balance<T: Config> = StorageNMap<105 pub type Balance<T: Config> = StorageNMap<
106 Key = (106 Key = (
107 Key<Twox64Concat, CollectionId>,107 Key<Twox64Concat, CollectionId>,
108 Key<Twox64Concat, TokenId>,108 Key<Twox64Concat, TokenId>,
114 >;114 >;
115115
116 #[pallet::storage]116 #[pallet::storage]
117 pub(super) type Allowance<T: Config> = StorageNMap<117 pub type Allowance<T: Config> = StorageNMap<
118 Key = (118 Key = (
119 Key<Twox64Concat, CollectionId>,119 Key<Twox64Concat, CollectionId>,
120 Key<Twox64Concat, TokenId>,120 Key<Twox64Concat, TokenId>,