From 8a37f3ec9fdf371e4a1327fa64228e778b7de2ae Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Wed, 24 Nov 2021 15:04:31 +0000 Subject: [PATCH] Fix formatting --- --- a/pallets/inflation/src/lib.rs +++ b/pallets/inflation/src/lib.rs @@ -46,8 +46,8 @@ pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -// pub const YEAR: u32 = 5_259_600; // 6-second block -pub const YEAR: u32 = 2_629_800; // 12-second block +// 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; --- a/pallets/scheduler/src/lib.rs +++ b/pallets/scheduler/src/lib.rs @@ -738,9 +738,7 @@ use super::*; use frame_support::{ - ord_parameter_types, parameter_types, - traits::Contains, - weights::constants::RocksDbWeight, + ord_parameter_types, parameter_types, traits::Contains, weights::constants::RocksDbWeight, }; use sp_core::H256; use sp_runtime::{ --- a/pallets/unique/src/tests.rs +++ b/pallets/unique/src/tests.rs @@ -3,9 +3,9 @@ use crate::mock::*; use crate::{AccessMode, CollectionMode}; use up_data_structs::{ - COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, - CreateNftData, CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, - MetaUpdatePermission, TokenId, + COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData, + CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission, + TokenId, }; use frame_support::{assert_noop, assert_ok}; use sp_std::convert::TryInto; @@ -50,18 +50,30 @@ let saved_col_name: Vec = "Test1\0".encode_utf16().collect::>(); let saved_description: Vec = "TestDescription1\0".encode_utf16().collect::>(); let saved_prefix: Vec = b"token_prefix1\0".to_vec(); - assert_eq!(>::get(id).unwrap().owner, owner); assert_eq!( + >::get(id) + .unwrap() + .owner, + owner + ); + assert_eq!( >::get(id).unwrap().name, saved_col_name ); - assert_eq!(>::get(id).unwrap().mode, *mode); assert_eq!( - >::get(id).unwrap().description, + >::get(id).unwrap().mode, + *mode + ); + assert_eq!( + >::get(id) + .unwrap() + .description, saved_description ); assert_eq!( - >::get(id).unwrap().token_prefix, + >::get(id) + .unwrap() + .token_prefix, saved_prefix ); id @@ -165,7 +177,11 @@ .collect() )); for (index, data) in items_data.into_iter().enumerate() { - let item = >::get((CollectionId(1), TokenId((index + 1) as u32))).unwrap(); + let item = >::get(( + CollectionId(1), + TokenId((index + 1) as u32), + )) + .unwrap(); assert_eq!(item.const_data.to_vec(), data.const_data.into_inner()); assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner()); } @@ -180,7 +196,8 @@ let data = default_re_fungible_data(); create_test_item(collection_id, &data.clone().into()); let item = >::get((collection_id, TokenId(1))); - let balance = >::get((collection_id, TokenId(1), account(1))); + let balance = + >::get((collection_id, TokenId(1), account(1))); assert_eq!(item.const_data, data.const_data.into_inner()); assert_eq!(item.variable_data, data.variable_data.into_inner()); assert_eq!(balance, 1023); @@ -211,8 +228,12 @@ .collect() )); for (index, data) in items_data.into_iter().enumerate() { - let item = >::get((CollectionId(1), TokenId((index + 1) as u32))); - let balance = >::get((CollectionId(1), TokenId(1), account(1))); + let item = >::get(( + CollectionId(1), + TokenId((index + 1) as u32), + )); + let balance = + >::get((CollectionId(1), TokenId(1), account(1))); assert_eq!(item.const_data.to_vec(), data.const_data.into_inner()); assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner()); assert_eq!(balance, 1023); @@ -228,7 +249,10 @@ let data = default_fungible_data(); create_test_item(collection_id, &data.into()); - assert_eq!(>::get((collection_id, account(1))), 5); + assert_eq!( + >::get((collection_id, account(1))), + 5 + ); }); } @@ -269,11 +293,23 @@ let data = default_fungible_data(); create_test_item(collection_id, &data.into()); - assert_eq!(>::get((CollectionId(1), account(1))), 5); + assert_eq!( + >::get((CollectionId(1), account(1))), + 5 + ); // change owner scenario - assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(0), 5)); - assert_eq!(>::get((CollectionId(1), account(1))), 0); + assert_ok!(TemplateModule::transfer( + origin1, + account(2), + CollectionId(1), + TokenId(0), + 5 + )); + assert_eq!( + >::get((CollectionId(1), account(1))), + 0 + ); // split item scenario assert_ok!(TemplateModule::transfer( @@ -285,9 +321,21 @@ )); // split item and new owner has account scenario - assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(0), 1)); - assert_eq!(>::get((CollectionId(1), account(2))), 1); - assert_eq!(>::get((CollectionId(1), account(3))), 4); + assert_ok!(TemplateModule::transfer( + origin2, + account(3), + CollectionId(1), + TokenId(0), + 1 + )); + assert_eq!( + >::get((CollectionId(1), account(2))), + 1 + ); + assert_eq!( + >::get((CollectionId(1), account(3))), + 4 + ); }); } @@ -302,19 +350,49 @@ let item = >::get((collection_id, TokenId(1))); assert_eq!(item.const_data, data.const_data.into_inner()); assert_eq!(item.variable_data, data.variable_data.into_inner()); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, TokenId(1), account(1))), 1023); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, TokenId(1), account(1))), + 1023 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); // Account 1 transfers all 1023 pieces of RFT 1 to account 2 let origin1 = Origin::signed(1); let origin2 = Origin::signed(2); - assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1023)); - assert_eq!(>::get((collection_id, TokenId(1), account(2))), 1023); - assert_eq!(>::get((collection_id, account(1))), 0); - assert_eq!(>::get((collection_id, account(2))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), false); - assert_eq!(>::get((collection_id, account(2), TokenId(1))), true); + assert_ok!(TemplateModule::transfer( + origin1, + account(2), + CollectionId(1), + TokenId(1), + 1023 + )); + assert_eq!( + >::get((collection_id, TokenId(1), account(2))), + 1023 + ); + assert_eq!( + >::get((collection_id, account(1))), + 0 + ); + assert_eq!( + >::get((collection_id, account(2))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + false + ); + assert_eq!( + >::get((collection_id, account(2), TokenId(1))), + true + ); // Account 2 transfers 500 pieces of RFT 1 to account 3 assert_ok!(TemplateModule::transfer( @@ -324,21 +402,63 @@ TokenId(1), 500 )); - assert_eq!(>::get((collection_id, TokenId(1), account(2))), 523); - assert_eq!(>::get((collection_id, TokenId(1), account(3))), 500); - assert_eq!(>::get((collection_id, account(2))), 1); - assert_eq!(>::get((collection_id, account(3))), 1); - assert_eq!(>::get((collection_id, account(2), TokenId(1))), true); - assert_eq!(>::get((collection_id, account(3), TokenId(1))), true); + assert_eq!( + >::get((collection_id, TokenId(1), account(2))), + 523 + ); + assert_eq!( + >::get((collection_id, TokenId(1), account(3))), + 500 + ); + assert_eq!( + >::get((collection_id, account(2))), + 1 + ); + assert_eq!( + >::get((collection_id, account(3))), + 1 + ); + assert_eq!( + >::get((collection_id, account(2), TokenId(1))), + true + ); + assert_eq!( + >::get((collection_id, account(3), TokenId(1))), + true + ); // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance - assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 200)); - assert_eq!(>::get((collection_id, TokenId(1), account(2))), 323); - assert_eq!(>::get((collection_id, TokenId(1), account(3))), 700); - assert_eq!(>::get((collection_id, account(2))), 1); - assert_eq!(>::get((collection_id, account(3))), 1); - assert_eq!(>::get((collection_id, account(2), TokenId(1))), true); - assert_eq!(>::get((collection_id, account(3), TokenId(1))), true); + assert_ok!(TemplateModule::transfer( + origin2, + account(3), + CollectionId(1), + TokenId(1), + 200 + )); + assert_eq!( + >::get((collection_id, TokenId(1), account(2))), + 323 + ); + assert_eq!( + >::get((collection_id, TokenId(1), account(3))), + 700 + ); + assert_eq!( + >::get((collection_id, account(2))), + 1 + ); + assert_eq!( + >::get((collection_id, account(3))), + 1 + ); + assert_eq!( + >::get((collection_id, account(2), TokenId(1))), + true + ); + assert_eq!( + >::get((collection_id, account(3), TokenId(1))), + true + ); }); } @@ -349,17 +469,40 @@ let data = default_nft_data(); create_test_item(collection_id, &data.into()); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); - + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); let origin1 = Origin::signed(1); // default scenario - assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)); - assert_eq!(>::get((collection_id, account(1))), 0); - assert_eq!(>::get((collection_id, account(2))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), false); - assert_eq!(>::get((collection_id, account(2), TokenId(1))), true); + assert_ok!(TemplateModule::transfer( + origin1, + account(2), + CollectionId(1), + TokenId(1), + 1 + )); + assert_eq!( + >::get((collection_id, account(1))), + 0 + ); + assert_eq!( + >::get((collection_id, account(2))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + false + ); + assert_eq!( + >::get((collection_id, account(2), TokenId(1))), + true + ); }); } @@ -370,13 +513,20 @@ let data = default_nft_data(); create_test_item(collection_id, &data.into()); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); let origin1 = Origin::signed(1); assert_noop!( - TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2).map_err(|e| e.error), + TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2) + .map_err(|e| e.error), >::NonfungibleItemsHaveNoAmount ); }); @@ -389,16 +539,34 @@ let data = default_nft_data(); create_test_item(collection_id, &data.into()); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); let origin1 = Origin::signed(1); // Transferring 0 amount works on NFT... - assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 0)); + assert_ok!(TemplateModule::transfer( + origin1, + account(2), + CollectionId(1), + TokenId(1), + 0 + )); // ... and results in no transfer - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); }); } @@ -413,18 +581,41 @@ let origin1 = Origin::signed(1); let origin2 = Origin::signed(2); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); // neg transfer_from assert_noop!( - TemplateModule::transfer_from(origin2.clone(), account(1), account(2), CollectionId(1), TokenId(1), 1).map_err(|e| e.error), + TemplateModule::transfer_from( + origin2.clone(), + account(1), + account(2), + CollectionId(1), + TokenId(1), + 1 + ) + .map_err(|e| e.error), CommonError::::TokenValueNotEnough ); // do approve - assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1)); - assert_eq!(>::get((CollectionId(1), TokenId(1))).unwrap(), account(2)); + assert_ok!(TemplateModule::approve( + origin1, + account(2), + CollectionId(1), + TokenId(1), + 1 + )); + assert_eq!( + >::get((CollectionId(1), TokenId(1))).unwrap(), + account(2) + ); assert_ok!(TemplateModule::transfer_from( origin2, @@ -434,7 +625,9 @@ TokenId(1), 1 )); - assert!(>::get((CollectionId(1), TokenId(1))).is_none()); + assert!( + >::get((CollectionId(1), TokenId(1))).is_none() + ); }); } @@ -450,11 +643,19 @@ let data = default_nft_data(); create_test_item(collection_id, &data.clone().into()); assert_eq!( - &>::get((collection_id, TokenId(1))).unwrap().const_data, + &>::get((collection_id, TokenId(1))) + .unwrap() + .const_data, &data.const_data.into_inner() ); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list assert_ok!(TemplateModule::set_mint_permission( @@ -483,7 +684,7 @@ account(3) )); - // Account 1 approves account 2 for NFT 1 + // Account 1 approves account 2 for NFT 1 assert_ok!(TemplateModule::approve( origin1.clone(), account(2), @@ -491,7 +692,10 @@ TokenId(1), 1 )); - assert_eq!(>::get((CollectionId(1), TokenId(1))).unwrap(), account(2)); + assert_eq!( + >::get((CollectionId(1), TokenId(1))).unwrap(), + account(2) + ); // Account 2 transfers NFT 1 from account 1 to account 3 assert_ok!(TemplateModule::transfer_from( @@ -502,7 +706,9 @@ TokenId(1), 1 )); - assert!(>::get((CollectionId(1), TokenId(1))).is_none()); + assert!( + >::get((CollectionId(1), TokenId(1))).is_none() + ); }); } @@ -518,9 +724,18 @@ let data = default_re_fungible_data(); create_test_item(collection_id, &data.into()); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, TokenId(1), account(1))), 1023); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, TokenId(1), account(1))), + 1023 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list assert_ok!(TemplateModule::set_mint_permission( @@ -550,8 +765,22 @@ )); // Account 1 approves account 2 for 1023 pieces of RFT 1 - assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1023)); - assert_eq!(>::get((CollectionId(1), TokenId(1), account(1), account(2))), 1023); + assert_ok!(TemplateModule::approve( + origin1, + account(2), + CollectionId(1), + TokenId(1), + 1023 + )); + assert_eq!( + >::get(( + CollectionId(1), + TokenId(1), + account(1), + account(2) + )), + 1023 + ); // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3 assert_ok!(TemplateModule::transfer_from( @@ -562,13 +791,39 @@ TokenId(1), 100 )); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(3))), 1); - assert_eq!(>::get((collection_id, TokenId(1), account(1))), 923); - assert_eq!(>::get((collection_id, TokenId(1), account(3))), 100); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); - assert_eq!(>::get((CollectionId(1), TokenId(1), account(1), account(2))), 923); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(3))), + 1 + ); + assert_eq!( + >::get((collection_id, TokenId(1), account(1))), + 923 + ); + assert_eq!( + >::get((collection_id, TokenId(1), account(3))), + 100 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); + assert_eq!( + >::get(( + CollectionId(1), + TokenId(1), + account(1), + account(2) + )), + 923 + ); }); } @@ -617,10 +872,25 @@ TokenId(0), 5 )); - assert_eq!(>::get((CollectionId(1), account(1), account(2))), 5); - assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(0), 5)); - assert_eq!(>::get((CollectionId(1), account(1), account(2))), 5); - assert_eq!(>::get((CollectionId(1), account(1), account(3))), 5); + assert_eq!( + >::get((CollectionId(1), account(1), account(2))), + 5 + ); + assert_ok!(TemplateModule::approve( + origin1, + account(3), + CollectionId(1), + TokenId(0), + 5 + )); + assert_eq!( + >::get((CollectionId(1), account(1), account(2))), + 5 + ); + assert_eq!( + >::get((CollectionId(1), account(1), account(3))), + 5 + ); assert_ok!(TemplateModule::transfer_from( origin2.clone(), @@ -631,10 +901,21 @@ 4 )); - assert_eq!(>::get((CollectionId(1), account(1), account(2))), 1); + assert_eq!( + >::get((CollectionId(1), account(1), account(2))), + 1 + ); assert_noop!( - TemplateModule::transfer_from(origin2, account(1), account(3), CollectionId(1), TokenId(0), 4).map_err(|e| e.error), + TemplateModule::transfer_from( + origin2, + account(1), + account(3), + CollectionId(1), + TokenId(0), + 4 + ) + .map_err(|e| e.error), CommonError::::TokenValueNotEnough ); }); @@ -652,7 +933,9 @@ 2 )); assert_eq!( - >::get(collection_id).unwrap().owner, + >::get(collection_id) + .unwrap() + .owner, 2 ); }); @@ -679,7 +962,10 @@ create_test_item(collection_id, &data.into()); // check balance (collection with id = 1, user id = 1) - assert_eq!(>::get((collection_id, account(1))), 1); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); // burn item assert_ok!(TemplateModule::burn_item( @@ -688,7 +974,10 @@ TokenId(1), 1 )); - assert_eq!(>::get((collection_id, account(1))), 0); + assert_eq!( + >::get((collection_id, account(1))), + 0 + ); }); } @@ -703,7 +992,10 @@ create_test_item(collection_id, &data.into()); // check balance (collection with id = 1, user id = 1) - assert_eq!(>::get((collection_id, account(1))), 1); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); // burn item assert_ok!(TemplateModule::burn_item( @@ -712,14 +1004,17 @@ TokenId(1), 1 )); - + // burn item again assert_noop!( TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error), CommonError::::TokenNotFound ); - assert_eq!(>::get((collection_id, account(1))), 0); + assert_eq!( + >::get((collection_id, account(1))), + 0 + ); }); } @@ -739,16 +1034,27 @@ create_test_item(collection_id, &data.into()); // check balance (collection with id = 1, user id = 1) - assert_eq!(>::get((collection_id, account(1))), 5); + assert_eq!( + >::get((collection_id, account(1))), + 5 + ); // burn item - assert_ok!(TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(0), 5)); + assert_ok!(TemplateModule::burn_item( + origin1.clone(), + CollectionId(1), + TokenId(0), + 5 + )); assert_noop!( TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error), CommonError::::TokenValueTooLow ); - assert_eq!(>::get((collection_id, account(1))), 0); + assert_eq!( + >::get((collection_id, account(1))), + 0 + ); }); } @@ -768,7 +1074,10 @@ create_test_item(collection_id, &data.into()); // check balance (collection with id = 1, user id = 1) - assert_eq!(>::get((collection_id, account(1))), 5); + assert_eq!( + >::get((collection_id, account(1))), + 5 + ); // Try to burn item using Token ID assert_noop!( @@ -809,24 +1118,40 @@ create_test_item(collection_id, &data.into()); // check balance (collection with id = 1, user id = 2) - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, TokenId(1), account(1))), 1023); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, TokenId(1), account(1))), + 1023 + ); // burn item - assert_ok!(TemplateModule::burn_item(origin1.clone(), collection_id, TokenId(1), 1023)); + assert_ok!(TemplateModule::burn_item( + origin1.clone(), + collection_id, + TokenId(1), + 1023 + )); assert_noop!( - TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error), + TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023) + .map_err(|e| e.error), CommonError::::TokenValueTooLow ); - assert_eq!(>::get((collection_id, TokenId(1), account(1))), 0); + assert_eq!( + >::get((collection_id, TokenId(1), account(1))), + 0 + ); }); } #[test] fn add_collection_admin() { new_test_ext().execute_with(|| { - let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1)); + let collection1_id = + create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1)); let origin1 = Origin::signed(1); // Add collection admins @@ -842,16 +1167,26 @@ )); // Owner is not an admin by default - assert_eq!(>::get((CollectionId(1), account(1))), false); - assert!(>::get((CollectionId(1), account(2)))); - assert!(>::get((CollectionId(1), account(3)))); + assert_eq!( + >::get((CollectionId(1), account(1))), + false + ); + assert!(>::get(( + CollectionId(1), + account(2) + ))); + assert!(>::get(( + CollectionId(1), + account(3) + ))); }); } #[test] fn remove_collection_admin() { new_test_ext().execute_with(|| { - let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1)); + let collection1_id = + create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1)); let origin1 = Origin::signed(1); let origin2 = Origin::signed(2); @@ -867,8 +1202,14 @@ account(3) )); - assert!(>::get((CollectionId(1), account(2)))); - assert!(>::get((CollectionId(1), account(3)))); + assert!(>::get(( + CollectionId(1), + account(2) + ))); + assert!(>::get(( + CollectionId(1), + account(3) + ))); // remove admin 3 assert_ok!(TemplateModule::remove_collection_admin( @@ -878,8 +1219,14 @@ )); // 2 is still admin, 3 is not an admin anymore - assert!(>::get((CollectionId(1), account(2)))); - assert_eq!(>::get((CollectionId(1), account(3))), false); + assert!(>::get(( + CollectionId(1), + account(2) + ))); + assert_eq!( + >::get((CollectionId(1), account(3))), + false + ); }); } @@ -887,13 +1234,24 @@ fn balance_of() { new_test_ext().execute_with(|| { let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1)); - let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(2)); - let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(3)); + let fungible_collection_id = + create_test_collection(&CollectionMode::Fungible(3), CollectionId(2)); + let re_fungible_collection_id = + create_test_collection(&CollectionMode::ReFungible, CollectionId(3)); // check balance before - assert_eq!(>::get((nft_collection_id, account(1))), 0); - assert_eq!(>::get((fungible_collection_id, account(1))), 0); - assert_eq!(>::get((re_fungible_collection_id, account(1))), 0); + assert_eq!( + >::get((nft_collection_id, account(1))), + 0 + ); + assert_eq!( + >::get((fungible_collection_id, account(1))), + 0 + ); + assert_eq!( + >::get((re_fungible_collection_id, account(1))), + 0 + ); let nft_data = default_nft_data(); create_test_item(nft_collection_id, &nft_data.into()); @@ -905,12 +1263,31 @@ create_test_item(re_fungible_collection_id, &re_fungible_data.into()); // check balance (collection with id = 1, user id = 1) - assert_eq!(>::get((nft_collection_id, account(1))), 1); - assert_eq!(>::get((fungible_collection_id, account(1))), 5); - assert_eq!(>::get((re_fungible_collection_id, account(1))), 1); + assert_eq!( + >::get((nft_collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((fungible_collection_id, account(1))), + 5 + ); + assert_eq!( + >::get((re_fungible_collection_id, account(1))), + 1 + ); - assert_eq!(>::get((nft_collection_id, account(1), TokenId(1))), true); - assert_eq!(>::get((re_fungible_collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((nft_collection_id, account(1), TokenId(1))), + true + ); + assert_eq!( + >::get(( + re_fungible_collection_id, + account(1), + TokenId(1) + )), + true + ); }); } @@ -925,8 +1302,17 @@ let origin1 = Origin::signed(1); // approve - assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1)); - assert_eq!(>::get((CollectionId(1), TokenId(1))).unwrap(), account(2)); + assert_ok!(TemplateModule::approve( + origin1, + account(2), + CollectionId(1), + TokenId(1), + 1 + )); + assert_eq!( + >::get((CollectionId(1), TokenId(1))).unwrap(), + account(2) + ); }); } @@ -948,7 +1334,10 @@ TokenId(1), 1 )); - assert_eq!(>::get((CollectionId(1), TokenId(1))).unwrap(), account(2)); + assert_eq!( + >::get((CollectionId(1), TokenId(1))).unwrap(), + account(2) + ); assert_ok!(TemplateModule::set_mint_permission( origin1.clone(), @@ -970,7 +1359,11 @@ CollectionId(1), account(2) )); - assert_ok!(TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(3))); + assert_ok!(TemplateModule::add_to_allow_list( + origin1, + CollectionId(1), + account(3) + )); assert_ok!(TemplateModule::transfer_from( origin2, @@ -982,8 +1375,14 @@ )); // after transfer - assert_eq!(>::get((CollectionId(1), account(1))), 0); - assert_eq!(>::get((CollectionId(1), account(2))), 1); + assert_eq!( + >::get((CollectionId(1), account(1))), + 0 + ); + assert_eq!( + >::get((CollectionId(1), account(2))), + 1 + ); }); } @@ -1003,7 +1402,10 @@ collection_id, account(2) )); - assert!(>::get((collection_id, account(2)))); + assert!(>::get(( + collection_id, + account(2) + ))); }); } @@ -1024,7 +1426,10 @@ collection_id, account(3) )); - assert!(>::get((collection_id, account(3)))); + assert!(>::get(( + collection_id, + account(3) + ))); }); } @@ -1087,7 +1492,10 @@ collection_id, account(2) )); - assert!(>::get((collection_id, account(2)))); + assert!(>::get(( + collection_id, + account(2) + ))); }); } @@ -1107,7 +1515,10 @@ collection_id, account(2) )); - assert_eq!(>::get((collection_id, account(2))), false); + assert_eq!( + >::get((collection_id, account(2))), + false + ); }); } @@ -1138,7 +1549,10 @@ collection_id, account(3) )); - assert_eq!(>::get((collection_id, account(3))), false); + assert_eq!( + >::get((collection_id, account(3))), + false + ); }); } @@ -1158,7 +1572,10 @@ TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)), CommonError::::NoPermission ); - assert!(>::get((collection_id, account(2)))); + assert!(>::get(( + collection_id, + account(2) + ))); }); } @@ -1189,7 +1606,10 @@ )); // Account 2 is in collection allow-list - assert!(>::get((collection_id, account(2)))); + assert!(>::get(( + collection_id, + account(2) + ))); // Destroy collection assert_ok!(TemplateModule::destroy_collection(origin1, collection_id)); @@ -1201,7 +1621,10 @@ ); // Account 2 is not found in collection allow-list anyway - assert_eq!(>::get((collection_id, account(2))), false); + assert_eq!( + >::get((collection_id, account(2))), + false + ); }); } @@ -1222,13 +1645,19 @@ collection_id, account(2) )); - assert_eq!(>::get((collection_id, account(2))), false); + assert_eq!( + >::get((collection_id, account(2))), + false + ); assert_ok!(TemplateModule::remove_from_allow_list( origin1, collection_id, account(2) )); - assert_eq!(>::get((collection_id, account(2))), false); + assert_eq!( + >::get((collection_id, account(2))), + false + ); }); } @@ -1255,7 +1684,8 @@ )); assert_noop!( - TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1).map_err(|e| e.error), + TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1) + .map_err(|e| e.error), CommonError::::AddressNotInAllowlist ); }); @@ -1294,7 +1724,10 @@ TokenId(1), 1 )); - assert_eq!(>::get((CollectionId(1), TokenId(1))).unwrap(), account(1)); + assert_eq!( + >::get((CollectionId(1), TokenId(1))).unwrap(), + account(1) + ); assert_ok!(TemplateModule::remove_from_allow_list( origin1.clone(), @@ -1303,7 +1736,15 @@ )); assert_noop!( - TemplateModule::transfer_from(origin1, account(1), account(3), CollectionId(1), TokenId(1), 1).map_err(|e| e.error), + TemplateModule::transfer_from( + origin1, + account(1), + account(3), + CollectionId(1), + TokenId(1), + 1 + ) + .map_err(|e| e.error), CommonError::::AddressNotInAllowlist ); }); @@ -1332,7 +1773,8 @@ )); assert_noop!( - TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1).map_err(|e| e.error), + TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1) + .map_err(|e| e.error), CommonError::::AddressNotInAllowlist ); }); @@ -1372,7 +1814,10 @@ TokenId(1), 1 )); - assert_eq!(>::get((CollectionId(1), TokenId(1))).unwrap(), account(1)); + assert_eq!( + >::get((CollectionId(1), TokenId(1))).unwrap(), + account(1) + ); assert_ok!(TemplateModule::remove_from_allow_list( origin1.clone(), @@ -1381,7 +1826,15 @@ )); assert_noop!( - TemplateModule::transfer_from(origin1, account(1), account(3), collection_id, TokenId(1), 1).map_err(|e| e.error), + TemplateModule::transfer_from( + origin1, + account(1), + account(3), + collection_id, + TokenId(1), + 1 + ) + .map_err(|e| e.error), CommonError::::AddressNotInAllowlist ); }); @@ -1404,7 +1857,8 @@ AccessMode::AllowList )); assert_noop!( - TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error), + TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1) + .map_err(|e| e.error), CommonError::::AddressNotInAllowlist ); }); @@ -1429,7 +1883,8 @@ // do approve assert_noop!( - TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1).map_err(|e| e.error), + TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1) + .map_err(|e| e.error), CommonError::::AddressNotInAllowlist ); }); @@ -1463,7 +1918,13 @@ account(2) )); - assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)); + assert_ok!(TemplateModule::transfer( + origin1, + account(2), + CollectionId(1), + TokenId(1), + 1 + )); }); } @@ -1499,18 +1960,21 @@ assert_ok!(TemplateModule::approve( origin1.clone(), account(1), - CollectionId(1), + CollectionId(1), TokenId(1), 1 )); - assert_eq!(>::get((CollectionId(1), TokenId(1))).unwrap(), account(1)); + assert_eq!( + >::get((CollectionId(1), TokenId(1))).unwrap(), + account(1) + ); // Transfer from 1 to 2 assert_ok!(TemplateModule::transfer_from( origin1, account(1), account(2), - CollectionId(1), + CollectionId(1), TokenId(1), 1 )); @@ -1601,7 +2065,13 @@ )); assert_noop!( - TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()).map_err(|e| e.error), + TemplateModule::create_item( + origin2, + CollectionId(1), + account(2), + default_nft_data().into() + ) + .map_err(|e| e.error), CommonError::::PublicMintingNotAllowed ); }); @@ -1628,7 +2098,13 @@ )); assert_noop!( - TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()).map_err(|e| e.error), + TemplateModule::create_item( + origin2, + CollectionId(1), + account(2), + default_nft_data().into() + ) + .map_err(|e| e.error), CommonError::::PublicMintingNotAllowed ); }); @@ -1714,7 +2190,13 @@ )); assert_noop!( - TemplateModule::create_item(origin2, collection_id, account(2), default_nft_data().into()).map_err(|e| e.error), + TemplateModule::create_item( + origin2, + collection_id, + account(2), + default_nft_data().into() + ) + .map_err(|e| e.error), CommonError::::AddressNotInAllowlist ); }); @@ -1826,7 +2308,8 @@ let data = default_nft_data(); assert_noop!( - TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into()).map_err(|e| e.error), + TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into()) + .map_err(|e| e.error), CommonError::::AccountTokenLimitExceeded ); }); @@ -1980,8 +2463,7 @@ )); assert_eq!( - >::get((collection_id, TokenId(1))) - .variable_data, + >::get((collection_id, TokenId(1))).variable_data, variable_data ); }); @@ -1999,7 +2481,13 @@ let variable_data = b"test data".to_vec(); assert_noop!( - TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(0), variable_data).map_err(|e| e.error), + TemplateModule::set_variable_meta_data( + origin1, + collection_id, + TokenId(0), + variable_data + ) + .map_err(|e| e.error), >::FungibleItemsDontHaveData ); }); @@ -2017,7 +2505,13 @@ let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec(); assert_noop!( - TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data).map_err(|e| e.error), + TemplateModule::set_variable_meta_data( + origin1, + collection_id, + TokenId(1), + variable_data + ) + .map_err(|e| e.error), CommonError::::TokenVariableDataLimitExceeded ); }); @@ -2035,7 +2529,13 @@ let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec(); assert_noop!( - TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data).map_err(|e| e.error), + TemplateModule::set_variable_meta_data( + origin1, + collection_id, + TokenId(1), + variable_data + ) + .map_err(|e| e.error), CommonError::::TokenVariableDataLimitExceeded ); }); @@ -2079,7 +2579,8 @@ #[test] fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() { new_test_ext().execute_with(|| { - let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1)); + let collection_id = + create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1)); let origin1 = Origin::signed(1); @@ -2110,7 +2611,8 @@ collection_id, TokenId(1), variable_data.clone() - ).map_err(|e| e.error), + ) + .map_err(|e| e.error), CommonError::::TokenVariableDataLimitExceeded ); }) @@ -2122,21 +2624,49 @@ let origin1 = Origin::signed(1); let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1)); - assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, collection_id, true)); + assert_ok!(TemplateModule::set_transfers_enabled_flag( + origin1, + collection_id, + true + )); let data = default_nft_data(); create_test_item(collection_id, &data.into()); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); let origin1 = Origin::signed(1); // default scenario - assert_ok!(TemplateModule::transfer(origin1, account(2), collection_id, TokenId(1), 1)); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), false); - assert_eq!(>::get((collection_id, account(2), TokenId(1))), true); - assert_eq!(>::get((collection_id, account(1))), 0); - assert_eq!(>::get((collection_id, account(2))), 1); + assert_ok!(TemplateModule::transfer( + origin1, + account(2), + collection_id, + TokenId(1), + 1 + )); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + false + ); + assert_eq!( + >::get((collection_id, account(2), TokenId(1))), + true + ); + assert_eq!( + >::get((collection_id, account(1))), + 0 + ); + assert_eq!( + >::get((collection_id, account(2))), + 1 + ); }); } @@ -2145,7 +2675,8 @@ new_test_ext().execute_with(|| { // default_limits(); - let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1)); + let collection_id = + create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1)); let origin1 = Origin::signed(1); let origin2 = Origin::signed(2); @@ -2198,7 +2729,8 @@ new_test_ext().execute_with(|| { // default_limits(); - let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1)); + let collection_id = + create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1)); let origin1 = Origin::signed(1); let origin2 = Origin::signed(2); @@ -2230,7 +2762,8 @@ collection_id, TokenId(1), variable_data.clone() - ).map_err(|e| e.error), + ) + .map_err(|e| e.error), CommonError::::NoPermission ); }); @@ -2241,7 +2774,8 @@ new_test_ext().execute_with(|| { // default_limits(); - let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1)); + let collection_id = + create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1)); let origin2 = Origin::signed(2); @@ -2266,7 +2800,8 @@ new_test_ext().execute_with(|| { // default_limits(); - let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1)); + let collection_id = + create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1)); let origin1 = Origin::signed(1); let data = default_nft_data(); @@ -2285,7 +2820,8 @@ collection_id, TokenId(1), variable_data.clone() - ).map_err(|e| e.error), + ) + .map_err(|e| e.error), CommonError::::NoPermission ); }); @@ -2298,24 +2834,45 @@ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1)); assert_ok!(TemplateModule::set_transfers_enabled_flag( - origin1, collection_id, false + origin1, + collection_id, + false )); let data = default_nft_data(); create_test_item(collection_id, &data.into()); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); let origin1 = Origin::signed(1); // default scenario assert_noop!( - TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1).map_err(|e| e.error), + TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1) + .map_err(|e| e.error), CommonError::::TransferNotAllowed ); - assert_eq!(>::get((collection_id, account(1))), 1); - assert_eq!(>::get((collection_id, account(2))), 0); - assert_eq!(>::get((collection_id, account(1), TokenId(1))), true); - assert_eq!(>::get((collection_id, account(2), TokenId(1))), false); + assert_eq!( + >::get((collection_id, account(1))), + 1 + ); + assert_eq!( + >::get((collection_id, account(2))), + 0 + ); + assert_eq!( + >::get((collection_id, account(1), TokenId(1))), + true + ); + assert_eq!( + >::get((collection_id, account(2), TokenId(1))), + false + ); }); } -- gitstuff