git.delta.rocks / unique-network / refs/commits / 455ab69b4262

difftreelog

Fix all unit test execution

Greg Zaitsev2021-11-24parent: #a1bffc7.patch.diff
in: master

6 files changed

modifiedpallets/inflation/src/lib.rsdiffbeforeafterboth
--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -46,7 +46,8 @@
 pub type BalanceOf<T> =
 	<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
 
-pub const YEAR: u32 = 5_259_600;
+// pub const YEAR: u32 = 5_259_600; // 6-second block 
+pub const YEAR: u32 = 2_629_800; // 12-second block 
 pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;
 pub const START_INFLATION_PERCENT: u32 = 10;
 pub const END_INFLATION_PERCENT: u32 = 4;
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -18,7 +18,7 @@
 type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
 type Block = frame_system::mocking::MockBlock<Test>;
 
-const YEAR: u64 = 5_259_600;
+const YEAR: u64 = 2_629_800;
 
 parameter_types! {
 	pub const ExistentialDeposit: u64 = 1;
@@ -112,8 +112,8 @@
 		// first inflation deposit should be equal to BlockInflation
 		Inflation::on_initialize(1);
 
-		// SBP M2 review: Verify expected block inflation for year 1
-		assert_eq!(Inflation::block_inflation(), 1901);
+		// Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = 3803
+		assert_eq!(Inflation::block_inflation(), 3803);
 		assert_eq!(
 			Balances::free_balance(1234) - initial_issuance,
 			Inflation::block_inflation()
@@ -158,26 +158,21 @@
 		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 		Inflation::on_initialize(1);
-		let block_inflation_year_0 = Inflation::block_inflation();
 
-		// SBP M2 review: go through all the block inflations for year 1,
+		// Go through all the block inflations for year 1,
 		// total issuance will be updated accordingly
 		for block in (100..YEAR).step_by(100) {
 			Inflation::on_initialize(block);
 		}
 		assert_eq!(
-			initial_issuance + (1901 * (YEAR / 100)),
+			initial_issuance + (3803 * (YEAR / 100)),
 			<Balances as Currency<_>>::total_issuance()
 		);
 
 		Inflation::on_initialize(YEAR);
 		let block_inflation_year_1 = Inflation::block_inflation();
-		// SBP M2 review: Verify expected block inflation for year 2
-		assert_eq!(block_inflation_year_1, 1952);
-
-		// SBP M2 review: this is actually not true
-		// Assert that year 1 inflation is less than year 0
-		// assert!(block_inflation_year_0 > block_inflation_year_1);
+		// Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR = 3904
+		assert_eq!(block_inflation_year_1, 3904);
 	});
 }
 
modifiedpallets/nft/src/mock.rsdiffbeforeafterboth
--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -27,6 +27,10 @@
 		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
 		TemplateModule: pallet_template::{Pallet, Call, Storage},
 		Balances: pallet_balances::{Pallet, Call, Storage},
+		Common: pallet_common::{Pallet, Storage, Event<T>},
+		Fungible: pallet_fungible::{Pallet, Storage},
+		Refungible: pallet_refungible::{Pallet, Storage},
+		Nonfungible: pallet_nonfungible::{Pallet, Storage},
 	}
 );
 
@@ -151,7 +155,6 @@
 		Self::from_sub(0)
 	}
 }
-
 
 pub struct TestEtheremTransactionSender;
 impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
3use crate::mock::*;3use crate::mock::*;
4use crate::{AccessMode, CollectionMode};4use crate::{AccessMode, CollectionMode};
5use nft_data_structs::{5use nft_data_structs::{
6 COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, CreateFungibleData, 6 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData,
7 CreateNftData, CreateReFungibleData, ExistenceRequirement, MAX_COLLECTION_DESCRIPTION_LENGTH, 7 CreateNftData, CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT,
8 MAX_COLLECTION_NAME_LENGTH, MAX_DECIMAL_POINTS, MAX_TOKEN_PREFIX_LENGTH, COLLECTION_ADMINS_LIMIT,
9 MetaUpdatePermission, Pays, PostDispatchInfo, TokenId, Weight, WithdrawReasons,8 MetaUpdatePermission, TokenId,
10};9};
1110
12use frame_support::{assert_noop, assert_ok};11use frame_support::{assert_noop, assert_ok};
213 .collect()212 .collect()
214 ));213 ));
215 for (index, data) in items_data.into_iter().enumerate() {214 for (index, data) in items_data.into_iter().enumerate() {
216 let item = <pallet_nonfungible::TokenData<Test>>::get((CollectionId(1), TokenId((index + 1) as u32))).unwrap();215 let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId((index + 1) as u32)));
217 let balance = <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));216 let balance = <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));
218 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());217 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
219 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());218 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
274 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 5);273 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 5);
275274
276 // change owner scenario275 // change owner scenario
277 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 5));276 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(0), 5));
278 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 0);277 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 0);
279278
280 // split item scenario279 // split item scenario
281 assert_ok!(TemplateModule::transfer(280 assert_ok!(TemplateModule::transfer(
282 origin2.clone(),281 origin2.clone(),
283 account(3),282 account(3),
284 CollectionId(1),283 CollectionId(1),
285 TokenId(1),284 TokenId(0),
286 3285 3
287 ));286 ));
288287
289 // split item and new owner has account scenario288 // split item and new owner has account scenario
290 assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 1));289 assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(0), 1));
291 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))), 1);290 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))), 1);
292 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))), 4);291 assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))), 4);
293 });292 });
298 new_test_ext().execute_with(|| {297 new_test_ext().execute_with(|| {
299 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));298 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
300299
300 // Create RFT 1 in 1023 pieces for account 1
301 let data = default_re_fungible_data();301 let data = default_re_fungible_data();
302 create_test_item(collection_id, &data.clone().into());302 create_test_item(collection_id, &data.clone().into());
303 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
304 assert_eq!(item.const_data, data.const_data.into_inner());
305 assert_eq!(item.variable_data, data.variable_data.into_inner());
306 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
307 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);
308 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
303309
310 // Account 1 transfers all 1023 pieces of RFT 1 to account 2
304 let origin1 = Origin::signed(1);311 let origin1 = Origin::signed(1);
305 let origin2 = Origin::signed(2);312 let origin2 = Origin::signed(2);
306 {
307 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
308 let balance = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));
309 assert_eq!(item.const_data, data.const_data.into_inner());
310 assert_eq!(item.variable_data, data.variable_data.into_inner());
311 assert_eq!(balance, 1023);
312 }
313
314 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);
315 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
316
317 // change owner scenario
318 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1023));313 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1023));
319
320 let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));314 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))), 1023);
321 assert_eq!(balance2, 1023);
322 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);315 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
323 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1023);316 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
324 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);317 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
325 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);318 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
326319
327 // split item scenario320 // Account 2 transfers 500 pieces of RFT 1 to account 3
328 assert_ok!(TemplateModule::transfer(321 assert_ok!(TemplateModule::transfer(
329 origin2.clone(),322 origin2.clone(),
330 account(3),323 account(3),
331 CollectionId(1),324 CollectionId(1),
332 TokenId(1),325 TokenId(1),
333 500326 500
334 ));327 ));
335 {328 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))), 523);
336 let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId(1)));
337 let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));
338 let balance3 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3)));329 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))), 500);
339 assert_eq!(balance2, 523);
340 assert_eq!(balance3, 500);
341 }330 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
342 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 523);
343 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 500);331 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 1);
344 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);332 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
345 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);333 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);
346334
347 // split item and new owner has account scenario335 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance
348 assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 200));336 assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 200));
349 {337 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))), 323);
350 let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId(1)));
351 let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));
352 let balance3 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3)));338 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))), 700);
353 assert_eq!(balance2, 323);
354 assert_eq!(balance3, 700);
355 }339 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
356 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 323);
357 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 700);340 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 1);
358 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);341 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
359 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);342 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);
360 });343 });
373356
374 let origin1 = Origin::signed(1);357 let origin1 = Origin::signed(1);
375 // default scenario358 // default scenario
376 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1000));359 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1));
377 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);360 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
378 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);361 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
379 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);362 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
382}365}
383366
384#[test]367#[test]
368fn transfer_nft_item_wrong_value() {
369 new_test_ext().execute_with(|| {
370 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
371
372 let data = default_nft_data();
373 create_test_item(collection_id, &data.into());
374 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
375 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
376
377 let origin1 = Origin::signed(1);
378
379 assert_noop!(
380 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2).map_err(|e| e.error),
381 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount
382 );
383 });
384}
385
386#[test]
387fn transfer_nft_item_zero_value() {
388 new_test_ext().execute_with(|| {
389 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
390
391 let data = default_nft_data();
392 create_test_item(collection_id, &data.into());
393 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
394 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
395
396 let origin1 = Origin::signed(1);
397
398 // Transferring 0 amount works on NFT...
399 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 0));
400 // ... and results in no transfer
401 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
402 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
403 });
404}
405
406#[test]
385fn nft_approve_and_transfer_from() {407fn nft_approve_and_transfer_from() {
386 new_test_ext().execute_with(|| {408 new_test_ext().execute_with(|| {
387 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));409 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
395 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);417 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
396 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);418 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
397419
398 // neg transfer420 // neg transfer_from
399 assert_noop!(421 assert_noop!(
400 TemplateModule::transfer_from(origin2.clone(), account(1), account(2), CollectionId(1), TokenId(1), 1),422 TemplateModule::transfer_from(origin2.clone(), account(1), account(2), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
401 CommonError::<Test>::NoPermission423 CommonError::<Test>::TokenValueNotEnough
402 );424 );
403425
404 // do approve426 // do approve
405 assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 5));427 assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1));
406 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));428 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));
407429
408 assert_ok!(TemplateModule::transfer_from(430 assert_ok!(TemplateModule::transfer_from(
425 let origin1 = Origin::signed(1);447 let origin1 = Origin::signed(1);
426 let origin2 = Origin::signed(2);448 let origin2 = Origin::signed(2);
427449
450 // Create NFT 1 for account 1
428 let data = default_nft_data();451 let data = default_nft_data();
429 create_test_item(collection_id, &data.clone().into());452 create_test_item(collection_id, &data.clone().into());
430
431 assert_eq!(453 assert_eq!(
432 &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1))).unwrap().const_data,454 &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1))).unwrap().const_data,
433 &data.const_data.into_inner()455 &data.const_data.into_inner()
434 );456 );
435 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);457 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
436 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);458 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
437459
460 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list
438 assert_ok!(TemplateModule::set_mint_permission(461 assert_ok!(TemplateModule::set_mint_permission(
439 origin1.clone(),462 origin1.clone(),
440 CollectionId(1),463 CollectionId(1),
461 account(3)484 account(3)
462 ));485 ));
463486
464 // do approve487 // Account 1 approves account 2 for NFT 1
465 assert_ok!(TemplateModule::approve(488 assert_ok!(TemplateModule::approve(
466 origin1.clone(),489 origin1.clone(),
467 account(2),490 account(2),
468 CollectionId(1),491 CollectionId(1),
469 TokenId(1),492 TokenId(1),
470 5493 1
471 ));494 ));
472 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));495 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));
473 assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(1), 5));
474 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(3));
475496
497 // Account 2 transfers NFT 1 from account 1 to account 3
476 assert_ok!(TemplateModule::transfer_from(498 assert_ok!(TemplateModule::transfer_from(
477 origin2,499 origin2,
478 account(1),500 account(1),
493 let origin1 = Origin::signed(1);515 let origin1 = Origin::signed(1);
494 let origin2 = Origin::signed(2);516 let origin2 = Origin::signed(2);
495517
518 // Create RFT 1 in 1023 pieces for account 1
496 let data = default_re_fungible_data();519 let data = default_re_fungible_data();
497 create_test_item(collection_id, &data.into());520 create_test_item(collection_id, &data.into());
498521
499 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);522 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
523 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);
500 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);524 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
501525
526 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list
502 assert_ok!(TemplateModule::set_mint_permission(527 assert_ok!(TemplateModule::set_mint_permission(
503 origin1.clone(),528 origin1.clone(),
504 CollectionId(1),529 CollectionId(1),
525 account(3)550 account(3)
526 ));551 ));
527552
528 // do approve553 // Account 1 approves account 2 for 1023 pieces of RFT 1
529 assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1023));554 assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1023));
530 assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 1023);555 assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 1023);
531556
557 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3
532 assert_ok!(TemplateModule::transfer_from(558 assert_ok!(TemplateModule::transfer_from(
533 origin2,559 origin2,
534 account(1),560 account(1),
537 TokenId(1),563 TokenId(1),
538 100564 100
539 ));565 ));
540 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 923);566 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
541 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 100);567 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 1);
568 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 923);
569 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))), 100);
542 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);570 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
543 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(3))), true);571 assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
544 assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 923);572 assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 923);
545 });573 });
546}574}
587 origin1.clone(),615 origin1.clone(),
588 account(2),616 account(2),
589 CollectionId(1),617 CollectionId(1),
590 TokenId(1),618 TokenId(0),
591 5619 5
592 ));620 ));
593 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);621 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);
594 assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(1), 5));622 assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(0), 5));
595 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);623 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);
596 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))), 5);624 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))), 5);
597625
600 account(1),628 account(1),
601 account(3),629 account(3),
602 CollectionId(1),630 CollectionId(1),
603 TokenId(1),631 TokenId(0),
604 4632 4
605 ));633 ));
606634
607 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 1);635 assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 1);
608636
609 assert_noop!(637 assert_noop!(
610 TemplateModule::transfer_from(origin2, account(1), account(3), CollectionId(1), TokenId(1), 4),638 TemplateModule::transfer_from(origin2, account(1), account(3), CollectionId(1), TokenId(0), 4).map_err(|e| e.error),
611 CommonError::<Test>::NoPermission639 CommonError::<Test>::TokenValueNotEnough
612 );640 );
613 });641 });
614}642}
647 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));675 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
648676
649 let origin1 = Origin::signed(1);677 let origin1 = Origin::signed(1);
678
679 let data = default_nft_data();
680 create_test_item(collection_id, &data.into());
681
682 // check balance (collection with id = 1, user id = 1)
683 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
684
685 // burn item
650 assert_ok!(TemplateModule::add_collection_admin(686 assert_ok!(TemplateModule::burn_item(
651 origin1.clone(),687 origin1.clone(),
652 collection_id,688 collection_id,
653 account(2)689 TokenId(1),
690 1
654 ));691 ));
692 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
693 });
694}
655695
696#[test]
697fn burn_same_nft_item_twice() {
698 new_test_ext().execute_with(|| {
699 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
700
701 let origin1 = Origin::signed(1);
702
656 let data = default_nft_data();703 let data = default_nft_data();
657 create_test_item(collection_id, &data.into());704 create_test_item(collection_id, &data.into());
658705
659 // check balance (collection with id = 1, user id = 1)706 // check balance (collection with id = 1, user id = 1)
660 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);707 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
661708
662 // burn item709 // burn item
663 assert_ok!(TemplateModule::burn_item(710 assert_ok!(TemplateModule::burn_item(
666 TokenId(1),713 TokenId(1),
667 1714 1
668 ));715 ));
716
717 // burn item again
669 assert_noop!(718 assert_noop!(
670 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1),719 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),
671 CommonError::<Test>::TokenNotFound720 CommonError::<Test>::TokenNotFound
672 );721 );
673722
674 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);723 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
675 });724 });
676}725}
677726
694 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);743 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);
695744
696 // burn item745 // burn item
697 assert_ok!(TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 5));746 assert_ok!(TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(0), 5));
698 assert_noop!(747 assert_noop!(
699 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5),748 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),
700 CommonError::<Test>::TokenValueNotEnough749 CommonError::<Test>::TokenValueTooLow
701 );750 );
702751
703 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 0);752 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 0);
704 });753 });
705}754}
706755
707#[test]756#[test]
757fn burn_fungible_item_with_token_id() {
758 new_test_ext().execute_with(|| {
759 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
760
761 let origin1 = Origin::signed(1);
762 assert_ok!(TemplateModule::add_collection_admin(
763 origin1.clone(),
764 collection_id,
765 account(2)
766 ));
767
768 let data = default_fungible_data();
769 create_test_item(collection_id, &data.into());
770
771 // check balance (collection with id = 1, user id = 1)
772 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);
773
774 // Try to burn item using Token ID
775 assert_noop!(
776 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),
777 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId
778 );
779 });
780}
781#[test]
708fn burn_refungible_item() {782fn burn_refungible_item() {
709 new_test_ext().execute_with(|| {783 new_test_ext().execute_with(|| {
710 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));784 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
736 create_test_item(collection_id, &data.into());810 create_test_item(collection_id, &data.into());
737811
738 // check balance (collection with id = 1, user id = 2)812 // check balance (collection with id = 1, user id = 2)
739 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);813 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
740 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);814 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);
741815
742 // burn item816 // burn item
743 assert_ok!(TemplateModule::burn_item(origin1.clone(), collection_id, TokenId(1), 1023));817 assert_ok!(TemplateModule::burn_item(origin1.clone(), collection_id, TokenId(1), 1023));
744 assert_noop!(818 assert_noop!(
745 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023),819 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error),
746 CommonError::<Test>::TokenNotFound820 CommonError::<Test>::TokenValueTooLow
747 );821 );
748822
749 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 0);823 assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 0);
754fn add_collection_admin() {828fn add_collection_admin() {
755 new_test_ext().execute_with(|| {829 new_test_ext().execute_with(|| {
756 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));830 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
757 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(2));
758 create_test_collection_for_owner(&CollectionMode::NFT, 3, CollectionId(3));
759
760 let origin1 = Origin::signed(1);831 let origin1 = Origin::signed(1);
761832
762 // collection admin833 // Add collection admins
763 assert_ok!(TemplateModule::add_collection_admin(834 assert_ok!(TemplateModule::add_collection_admin(
764 origin1.clone(),835 origin1.clone(),
765 collection1_id,836 collection1_id,
771 account(3)842 account(3)
772 ));843 ));
773844
774 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))));845 // Owner is not an admin by default
846 assert_eq!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))), false);
775 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));847 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));
776 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));848 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));
777 });849 });
781fn remove_collection_admin() {853fn remove_collection_admin() {
782 new_test_ext().execute_with(|| {854 new_test_ext().execute_with(|| {
783 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));855 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
784 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(2));
785 create_test_collection_for_owner(&CollectionMode::NFT, 3, CollectionId(3));
786
787 let origin1 = Origin::signed(1);856 let origin1 = Origin::signed(1);
788 let origin2 = Origin::signed(2);857 let origin2 = Origin::signed(2);
789858
790 // collection admin859 // Add collection admins 2 and 3
791 assert_ok!(TemplateModule::add_collection_admin(860 assert_ok!(TemplateModule::add_collection_admin(
792 origin1.clone(),861 origin1.clone(),
793 collection1_id,862 collection1_id,
802 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));871 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));
803 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));872 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));
804873
805 // remove admin874 // remove admin 3
806 assert_ok!(TemplateModule::remove_collection_admin(875 assert_ok!(TemplateModule::remove_collection_admin(
807 origin2,876 origin2,
808 CollectionId(1),877 CollectionId(1),
809 account(3)878 account(3)
810 ));879 ));
880
811 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));881 // 2 is still admin, 3 is not an admin anymore
882 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));
812 assert_eq!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))), false);883 assert_eq!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))), false);
813 });884 });
814}885}
815886
837 // check balance (collection with id = 1, user id = 1)908 // check balance (collection with id = 1, user id = 1)
838 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))), 1);909 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))), 1);
839 assert_eq!(<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))), 5);910 assert_eq!(<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))), 5);
840 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))), 1023);911 assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))), 1);
841912
842 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);913 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);
843 assert_eq!(<pallet_refungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);914 assert_eq!(<pallet_refungible::Owned<Test>>::get((re_fungible_collection_id, account(1), TokenId(1))), true);
844 });915 });
845}916}
846917
1037 collection_id,1108 collection_id,
1038 account(2)1109 account(2)
1039 ));1110 ));
1040 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1111 assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);
1041 });1112 });
1042}1113}
10431114
1048 let origin1 = Origin::signed(1);1119 let origin1 = Origin::signed(1);
1049 let origin2 = Origin::signed(2);1120 let origin2 = Origin::signed(2);
10501121
1122 // Owner adds admin
1051 assert_ok!(TemplateModule::add_collection_admin(1123 assert_ok!(TemplateModule::add_collection_admin(
1052 origin1.clone(),1124 origin1.clone(),
1053 collection_id,1125 collection_id,
1054 account(2)1126 account(2)
1055 ));1127 ));
10561128
1129 // Owner adds address 3 to allow list
1057 assert_ok!(TemplateModule::add_to_allow_list(1130 assert_ok!(TemplateModule::add_to_allow_list(
1058 origin1,1131 origin1,
1059 collection_id,1132 collection_id,
1060 account(3)1133 account(3)
1061 ));1134 ));
1135
1136 // Admin removes address 3 from allow list
1062 assert_ok!(TemplateModule::remove_from_allow_list(1137 assert_ok!(TemplateModule::remove_from_allow_list(
1063 origin2,1138 origin2,
1064 collection_id,1139 collection_id,
1065 account(3)1140 account(3)
1066 ));1141 ));
1067 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(3))));1142 assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(3))), false);
1068 });1143 });
1069}1144}
10701145
1107 let origin1 = Origin::signed(1);1182 let origin1 = Origin::signed(1);
1108 let origin2 = Origin::signed(2);1183 let origin2 = Origin::signed(2);
11091184
1185 // Add account 2 to allow list
1110 assert_ok!(TemplateModule::add_to_allow_list(1186 assert_ok!(TemplateModule::add_to_allow_list(
1111 origin1.clone(),1187 origin1.clone(),
1112 collection_id,1188 collection_id,
1113 account(2)1189 account(2)
1114 ));1190 ));
1191
1192 // Account 2 is in collection allow-list
1193 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
1194
1195 // Destroy collection
1115 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1196 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
1197
1198 // Attempt to remove account 2 from collection allow-list => error
1116 assert_noop!(1199 assert_noop!(
1117 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1200 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
1118 CommonError::<Test>::CollectionNotFound1201 CommonError::<Test>::CollectionNotFound
1119 );1202 );
1203
1120 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1204 // Account 2 is not found in collection allow-list anyway
1205 assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);
1121 });1206 });
1122}1207}
11231208
1138 collection_id,1223 collection_id,
1139 account(2)1224 account(2)
1140 ));1225 ));
1226 assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);
1141 assert_ok!(TemplateModule::remove_from_allow_list(1227 assert_ok!(TemplateModule::remove_from_allow_list(
1142 origin1,1228 origin1,
1143 collection_id,1229 collection_id,
1144 account(2)1230 account(2)
1145 ));1231 ));
1146 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1232 assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);
1147 });1233 });
1148}1234}
11491235
1170 ));1256 ));
11711257
1172 assert_noop!(1258 assert_noop!(
1173 TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1),1259 TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
1174 CommonError::<Test>::AddressNotInAllowlist1260 CommonError::<Test>::AddressNotInAllowlist
1175 );1261 );
1176 });1262 });
1218 ));1304 ));
12191305
1220 assert_noop!(1306 assert_noop!(
1221 TemplateModule::transfer_from(origin1, account(1), account(3), CollectionId(1), TokenId(1), 1),1307 TemplateModule::transfer_from(origin1, account(1), account(3), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
1222 CommonError::<Test>::AddressNotInAllowlist1308 CommonError::<Test>::AddressNotInAllowlist
1223 );1309 );
1224 });1310 });
1247 ));1333 ));
12481334
1249 assert_noop!(1335 assert_noop!(
1250 TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1),1336 TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1).map_err(|e| e.error),
1251 CommonError::<Test>::AddressNotInAllowlist1337 CommonError::<Test>::AddressNotInAllowlist
1252 );1338 );
1253 });1339 });
1296 ));1382 ));
12971383
1298 assert_noop!(1384 assert_noop!(
1299 TemplateModule::transfer_from(origin1, account(1), account(3), collection_id, TokenId(1), 1),1385 TemplateModule::transfer_from(origin1, account(1), account(3), collection_id, TokenId(1), 1).map_err(|e| e.error),
1300 CommonError::<Test>::AddressNotInAllowlist1386 CommonError::<Test>::AddressNotInAllowlist
1301 );1387 );
1302 });1388 });
1319 AccessMode::AllowList1405 AccessMode::AllowList
1320 ));1406 ));
1321 assert_noop!(1407 assert_noop!(
1322 TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 5),1408 TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
1323 CommonError::<Test>::AddressNotInAllowlist1409 CommonError::<Test>::AddressNotInAllowlist
1324 );1410 );
1325 });1411 });
13441430
1345 // do approve1431 // do approve
1346 assert_noop!(1432 assert_noop!(
1347 TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 5),1433 TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
1348 CommonError::<Test>::AddressNotInAllowlist1434 CommonError::<Test>::AddressNotInAllowlist
1349 );1435 );
1350 });1436 });
1387 new_test_ext().execute_with(|| {1473 new_test_ext().execute_with(|| {
1388 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1474 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
13891475
1476 // Create NFT for account 1
1390 let data = default_nft_data();1477 let data = default_nft_data();
1391 create_test_item(collection_id, &data.into());1478 create_test_item(collection_id, &data.into());
13921479
1393 let origin1 = Origin::signed(1);1480 let origin1 = Origin::signed(1);
13941481
1482 // Toggle Allow List mode and add accounts 1 and 2
1395 assert_ok!(TemplateModule::set_public_access_mode(1483 assert_ok!(TemplateModule::set_public_access_mode(
1396 origin1.clone(),1484 origin1.clone(),
1397 collection_id,1485 collection_id,
1408 account(2)1496 account(2)
1409 ));1497 ));
14101498
1411 // do approve1499 // Sself-approve account 1 for NFT 1
1412 assert_ok!(TemplateModule::approve(1500 assert_ok!(TemplateModule::approve(
1413 origin1.clone(),1501 origin1.clone(),
1414 account(1),1502 account(1),
1415 CollectionId(1), 1503 CollectionId(1),
1416 TokenId(1),1504 TokenId(1),
1417 51505 1
1418 ));1506 ));
1419 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));1507 assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));
14201508
1509 // Transfer from 1 to 2
1421 assert_ok!(TemplateModule::transfer_from(1510 assert_ok!(TemplateModule::transfer_from(
1422 origin1,1511 origin1,
1423 account(1),1512 account(1),
1513 ));1602 ));
15141603
1515 assert_noop!(1604 assert_noop!(
1516 TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()),1605 TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()).map_err(|e| e.error),
1517 CommonError::<Test>::PublicMintingNotAllowed1606 CommonError::<Test>::PublicMintingNotAllowed
1518 );1607 );
1519 });1608 });
1540 ));1629 ));
15411630
1542 assert_noop!(1631 assert_noop!(
1543 TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()),1632 TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()).map_err(|e| e.error),
1544 CommonError::<Test>::PublicMintingNotAllowed1633 CommonError::<Test>::PublicMintingNotAllowed
1545 );1634 );
1546 });1635 });
1626 ));1715 ));
16271716
1628 assert_noop!(1717 assert_noop!(
1629 TemplateModule::create_item(origin2, collection_id, account(2), default_nft_data().into()),1718 TemplateModule::create_item(origin2, collection_id, account(2), default_nft_data().into()).map_err(|e| e.error),
1630 CommonError::<Test>::AddressNotInAllowlist1719 CommonError::<Test>::AddressNotInAllowlist
1631 );1720 );
1632 });1721 });
1674 });1763 });
1675}1764}
16761765
1677// Total number of collections. Negotive test
1678#[test]1766#[test]
1767fn create_max_collections() {
1768 new_test_ext().execute_with(|| {
1769 for i in 1..=COLLECTION_NUMBER_LIMIT {
1770 create_test_collection(&CollectionMode::NFT, CollectionId(i));
1771 }
1772 });
1773}
1774
1775// Total number of collections. Negative test
1776#[test]
1679fn total_number_collections_bound_neg() {1777fn total_number_collections_bound_neg() {
1680 new_test_ext().execute_with(|| {1778 new_test_ext().execute_with(|| {
1681 let origin1 = Origin::signed(1);1779 let origin1 = Origin::signed(1);
16821780
1683 for i in 0..COLLECTION_NUMBER_LIMIT {1781 for i in 1..=COLLECTION_NUMBER_LIMIT {
1684 create_test_collection(&CollectionMode::NFT, CollectionId(i + 1));1782 create_test_collection(&CollectionMode::NFT, CollectionId(i));
1685 }1783 }
16861784
1687 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1785 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
17221820
1723 let origin1 = Origin::signed(1);1821 let origin1 = Origin::signed(1);
17241822
1725 for _ in 0..MAX_TOKEN_OWNERSHIP {1823 for _ in 1..=MAX_TOKEN_OWNERSHIP {
1726 let data = default_nft_data();1824 let data = default_nft_data();
1727 create_test_item(collection_id, &data.clone().into());1825 create_test_item(collection_id, &data.clone().into());
1728 }1826 }
17291827
1730 let data = default_nft_data();1828 let data = default_nft_data();
1731 assert_noop!(1829 assert_noop!(
1732 TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into()),1830 TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into()).map_err(|e| e.error),
1733 CommonError::<Test>::AccountTokenLimitExceeded1831 CommonError::<Test>::AccountTokenLimitExceeded
1734 );1832 );
1735 });1833 });
19022000
1903 let variable_data = b"test data".to_vec();2001 let variable_data = b"test data".to_vec();
1904 assert_noop!(2002 assert_noop!(
1905 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),2003 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(0), variable_data).map_err(|e| e.error),
1906 <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2004 <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData
1907 );2005 );
1908 });2006 });
1909}2007}
19102008
1911#[test]2009#[test]
2010fn set_variable_meta_data_on_fungible_token_with_token_id_fails() {
2011 new_test_ext().execute_with(|| {
2012 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
2013
2014 let origin1 = Origin::signed(1);
2015
2016 let data = default_fungible_data();
2017 create_test_item(collection_id, &data.into());
2018
2019 let variable_data = b"test data".to_vec();
2020 assert_noop!(
2021 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data).map_err(|e| e.error),
2022 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId
2023 );
2024 });
2025}
2026
2027#[test]
1912fn set_variable_meta_data_on_nft_token_fails_for_big_data() {2028fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
1913 new_test_ext().execute_with(|| {2029 new_test_ext().execute_with(|| {
1914 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2030 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
19202036
1921 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2037 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
1922 assert_noop!(2038 assert_noop!(
1923 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),2039 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data).map_err(|e| e.error),
1924 CommonError::<Test>::TokenVariableDataLimitExceeded2040 CommonError::<Test>::TokenVariableDataLimitExceeded
1925 );2041 );
1926 });2042 });
19382054
1939 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2055 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
1940 assert_noop!(2056 assert_noop!(
1941 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),2057 TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data).map_err(|e| e.error),
1942 CommonError::<Test>::TokenVariableDataLimitExceeded2058 CommonError::<Test>::TokenVariableDataLimitExceeded
1943 );2059 );
1944 });2060 });
2013 collection_id,2129 collection_id,
2014 TokenId(1),2130 TokenId(1),
2015 variable_data.clone()2131 variable_data.clone()
2016 ),2132 ).map_err(|e| e.error),
2017 CommonError::<Test>::TokenVariableDataLimitExceeded2133 CommonError::<Test>::TokenVariableDataLimitExceeded
2018 );2134 );
2019 })2135 })
2035 let origin1 = Origin::signed(1);2151 let origin1 = Origin::signed(1);
20362152
2037 // default scenario2153 // default scenario
2038 assert_ok!(TemplateModule::transfer(origin1, account(2), collection_id, TokenId(1), 1000));2154 assert_ok!(TemplateModule::transfer(origin1, account(2), collection_id, TokenId(1), 1));
2039 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);2155 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
2040 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);2156 assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
2041 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);2157 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
2133 collection_id,2249 collection_id,
2134 TokenId(1),2250 TokenId(1),
2135 variable_data.clone()2251 variable_data.clone()
2136 ),2252 ).map_err(|e| e.error),
2137 CommonError::<Test>::NoPermission2253 CommonError::<Test>::NoPermission
2138 );2254 );
2139 });2255 });
2188 collection_id,2304 collection_id,
2189 TokenId(1),2305 TokenId(1),
2190 variable_data.clone()2306 variable_data.clone()
2191 ),2307 ).map_err(|e| e.error),
2192 CommonError::<Test>::NoPermission2308 CommonError::<Test>::NoPermission
2193 );2309 );
2194 });2310 });
22132329
2214 // default scenario2330 // default scenario
2215 assert_noop!(2331 assert_noop!(
2216 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1000),2332 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
2217 CommonError::<Test>::TransferNotAllowed2333 CommonError::<Test>::TransferNotAllowed
2218 );2334 );
2219 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);2335 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -795,8 +795,8 @@
 	use super::*;
 
 	use frame_support::{
-		Hashable, assert_err, assert_noop, assert_ok, ord_parameter_types, parameter_types,
-		traits::{Contains, OnFinalize, OnInitialize},
+		ord_parameter_types, parameter_types,
+		traits::Contains,
 		weights::constants::RocksDbWeight,
 	};
 	use sp_core::H256;
@@ -806,7 +806,6 @@
 		traits::{BlakeTwo256, IdentityLookup},
 	};
 	use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};
-	use substrate_test_utils::assert_eq_uvec;
 	use crate as scheduler;
 
 	mod logger {
@@ -815,9 +814,6 @@
 
 		thread_local! {
 			static LOG: RefCell<Vec<(OriginCaller, u32)>> = RefCell::new(Vec::new());
-		}
-		pub fn log() -> Vec<(OriginCaller, u32)> {
-			LOG.with(|log| log.borrow().clone())
 		}
 		pub trait Config: system::Config {
 			type Event: From<Event> + Into<<Self as system::Config>::Event>;
@@ -928,24 +924,5 @@
 		type MaxScheduledPerBlock = MaxScheduledPerBlock;
 		type WeightInfo = ();
 		type SponsorshipHandler = ();
-	}
-
-	pub fn new_test_ext() -> sp_io::TestExternalities {
-		let t = system::GenesisConfig::default()
-			.build_storage::<Test>()
-			.unwrap();
-		t.into()
-	}
-
-	fn run_to_block(n: u64) {
-		while System::block_number() < n {
-			Scheduler::on_finalize(System::block_number());
-			System::set_block_number(System::block_number() + 1);
-			Scheduler::on_initialize(System::block_number());
-		}
-	}
-
-	fn root() -> OriginCaller {
-		system::RawOrigin::Root.into()
 	}
 }
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -29,10 +29,14 @@
 pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;
 pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;
 pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
-pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;
 
+pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {
+	10_000_000
+} else {
+	10
+};
 pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
-	100000
+	100_000
 } else {
 	10
 };
@@ -44,7 +48,7 @@
 pub const COLLECTION_ADMINS_LIMIT: u32 = 5;
 pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;
 pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
-	1000000
+	1_000_000
 } else {
 	10
 };