difftreelog
Fix all unit test execution
in: master
6 files changed
pallets/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;
pallets/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);
});
}
pallets/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 {
pallets/nft/src/tests.rsdiffbeforeafterboth3use 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};111012use 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);275274276 // change owner scenario275 // change owner scenario277 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);279278280 // split item scenario279 // split item scenario281 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 3287 ));286 ));288287289 // split item and new owner has account scenario288 // split item and new owner has account scenario290 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));300299300 // Create RFT 1 in 1023 pieces for account 1301 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);303309310 // Account 1 transfers all 1023 pieces of RFT 1 to account 2304 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);316317 // change owner scenario318 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));319320 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);326319327 // split item scenario320 // Account 2 transfers 500 pieces of RFT 1 to account 3328 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 500334 ));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);346334347 // split item and new owner has account scenario335 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance348 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 });373356374 let origin1 = Origin::signed(1);357 let origin1 = Origin::signed(1);375 // default scenario358 // default scenario376 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}383366384#[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));371372 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);376377 let origin1 = Origin::signed(1);378379 assert_noop!(380 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2).map_err(|e| e.error),381 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount382 );383 });384}385386#[test]387fn transfer_nft_item_zero_value() {388 new_test_ext().execute_with(|| {389 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));390391 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);395396 let origin1 = Origin::signed(1);397398 // Transferring 0 amount works on NFT...399 assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 0));400 // ... and results in no transfer401 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}405406#[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);397419398 // neg transfer420 // neg transfer_from399 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>::TokenValueNotEnough402 );424 );403425404 // do approve426 // do approve405 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));407429408 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);427449450 // Create NFT 1 for account 1428 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());430431 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);437459460 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list438 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 ));463486464 // 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 1471 ));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));475496497 // Account 2 transfers NFT 1 from account 1 to account 3476 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);495517518 // Create RFT 1 in 1023 pieces for account 1496 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());498521499 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);501525526 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list502 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 ));527552528 // do approve553 // Account 1 approves account 2 for 1023 pieces of RFT 1529 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);531556557 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3532 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 100539 ));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 5592 ));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);597625600 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 4605 ));633 ));606634607 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);608636609 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>::TokenValueNotEnough612 );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));648676649 let origin1 = Origin::signed(1);677 let origin1 = Origin::signed(1);678679 let data = default_nft_data();680 create_test_item(collection_id, &data.into());681682 // check balance (collection with id = 1, user id = 1)683 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);684685 // burn item650 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 1654 ));691 ));692 assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);693 });694}655695696#[test]697fn burn_same_nft_item_twice() {698 new_test_ext().execute_with(|| {699 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));700701 let origin1 = Origin::signed(1);702656 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());658705659 // 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);661708662 // burn item709 // burn item663 assert_ok!(TemplateModule::burn_item(710 assert_ok!(TemplateModule::burn_item(666 TokenId(1),713 TokenId(1),667 1714 1668 ));715 ));716 717 // burn item again669 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>::TokenNotFound672 );721 );673722674 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}677726694 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);695744696 // burn item745 // burn item697 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>::TokenValueTooLow701 );750 );702751703 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}706755707#[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));760761 let origin1 = Origin::signed(1);762 assert_ok!(TemplateModule::add_collection_admin(763 origin1.clone(),764 collection_id,765 account(2)766 ));767768 let data = default_fungible_data();769 create_test_item(collection_id, &data.into());770771 // check balance (collection with id = 1, user id = 1)772 assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);773774 // Try to burn item using Token ID775 assert_noop!(776 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),777 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId778 );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());737811738 // 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);741815742 // burn item816 // burn item743 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>::TokenValueTooLow747 );821 );748822749 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));759760 let origin1 = Origin::signed(1);831 let origin1 = Origin::signed(1);761832762 // collection admin833 // Add collection admins763 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 ));773844774 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))));845 // Owner is not an admin by default846 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));786787 let origin1 = Origin::signed(1);856 let origin1 = Origin::signed(1);788 let origin2 = Origin::signed(2);857 let origin2 = Origin::signed(2);789858790 // collection admin859 // Add collection admins 2 and 3791 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))));804873805 // remove admin874 // remove admin 3806 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 ));880811 assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));881 // 2 is still admin, 3 is not an admin anymore882 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}815886837 // 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);841912842 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}8469171037 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}104311141048 let origin1 = Origin::signed(1);1119 let origin1 = Origin::signed(1);1049 let origin2 = Origin::signed(2);1120 let origin2 = Origin::signed(2);105011211122 // Owner adds admin1051 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 ));105611281129 // Owner adds address 3 to allow list1057 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 ));11351136 // Admin removes address 3 from allow list1062 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}107011451107 let origin1 = Origin::signed(1);1182 let origin1 = Origin::signed(1);1108 let origin2 = Origin::signed(2);1183 let origin2 = Origin::signed(2);110911841185 // Add account 2 to allow list1110 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 ));11911192 // Account 2 is in collection allow-list1193 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));11941195 // Destroy collection1115 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1196 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));11971198 // Attempt to remove account 2 from collection allow-list => error1116 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>::CollectionNotFound1119 );1202 );12031120 assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));1204 // Account 2 is not found in collection allow-list anyway1205 assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);1121 });1206 });1122}1207}112312081138 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}114912351170 ));1256 ));117112571172 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>::AddressNotInAllowlist1175 );1261 );1176 });1262 });1218 ));1304 ));121913051220 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>::AddressNotInAllowlist1223 );1309 );1224 });1310 });1247 ));1333 ));124813341249 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>::AddressNotInAllowlist1252 );1338 );1253 });1339 });1296 ));1382 ));129713831298 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>::AddressNotInAllowlist1301 );1387 );1302 });1388 });1319 AccessMode::AllowList1405 AccessMode::AllowList1320 ));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>::AddressNotInAllowlist1324 );1410 );1325 });1411 });134414301345 // do approve1431 // do approve1346 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>::AddressNotInAllowlist1349 );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));138914751476 // Create NFT for account 11390 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());139214791393 let origin1 = Origin::signed(1);1480 let origin1 = Origin::signed(1);139414811482 // Toggle Allow List mode and add accounts 1 and 21395 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 ));141014981411 // do approve1499 // Sself-approve account 1 for NFT 11412 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 11418 ));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));142015081509 // Transfer from 1 to 21421 assert_ok!(TemplateModule::transfer_from(1510 assert_ok!(TemplateModule::transfer_from(1422 origin1,1511 origin1,1423 account(1),1512 account(1),1513 ));1602 ));151416031515 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>::PublicMintingNotAllowed1518 );1607 );1519 });1608 });1540 ));1629 ));154116301542 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>::PublicMintingNotAllowed1545 );1634 );1546 });1635 });1626 ));1715 ));162717161628 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>::AddressNotInAllowlist1631 );1720 );1632 });1721 });1674 });1763 });1675}1764}167617651677// Total number of collections. Negotive test1678#[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}17741775// Total number of collections. Negative test1776#[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);168217801683 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 }168617841687 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>>();172218201723 let origin1 = Origin::signed(1);1821 let origin1 = Origin::signed(1);172418221725 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 }172918271730 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>::AccountTokenLimitExceeded1734 );1832 );1735 });1833 });190220001903 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>>::FungibleItemsDontHaveData1907 );2005 );1908 });2006 });1909}2007}191020081911#[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));20132014 let origin1 = Origin::signed(1);20152016 let data = default_fungible_data();2017 create_test_item(collection_id, &data.into());20182019 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>>::FungibleItemsHaveNoId2023 );2024 });2025}20262027#[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));192020361921 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>::TokenVariableDataLimitExceeded1925 );2041 );1926 });2042 });193820541939 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>::TokenVariableDataLimitExceeded1943 );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>::TokenVariableDataLimitExceeded2018 );2134 );2019 })2135 })2035 let origin1 = Origin::signed(1);2151 let origin1 = Origin::signed(1);203621522037 // default scenario2153 // default scenario2038 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>::NoPermission2138 );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>::NoPermission2193 );2309 );2194 });2310 });221323292214 // default scenario2330 // default scenario2215 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>::TransferNotAllowed2218 );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);pallets/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()
}
}
primitives/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
};