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

difftreelog

CORE-296 Add error "NotSufficientFounds" and test it.

Trubnikov Sergey2022-02-28parent: #7f8cc7f.patch.diff
in: master

3 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -318,6 +318,9 @@
 		AddressIsZero,
 		/// Target collection doesn't supports this operation
 		UnsupportedOperation,
+
+		/// Not sufficient founds to perform action
+		NotSufficientFounds,
 	}
 
 	#[pallet::storage]
@@ -470,7 +473,7 @@
 				WithdrawReasons::TRANSFER,
 				ExistenceRequirement::KeepAlive,
 			)
-			.map_err(|_| Error::<T>::NoPermission)?;
+			.map_err(|_| Error::<T>::NotSufficientFounds)?;
 		}
 
 		<CreatedCollectionCount<T>>::put(created_count);
modifiedpallets/unique/src/mock.rsdiffbeforeafterboth
--- a/pallets/unique/src/mock.rs
+++ b/pallets/unique/src/mock.rs
@@ -108,7 +108,7 @@
 }
 
 parameter_types! {
-	pub const CollectionCreationPrice: u32 = 0;
+	pub const CollectionCreationPrice: u32 = 100;
 	pub TreasuryAccountId: u64 = 1234;
 	pub EthereumChainId: u32 = 1111;
 }
modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
7 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,7 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,
8 TokenId, MAX_TOKEN_OWNERSHIP,8 TokenId, MAX_TOKEN_OWNERSHIP,
9};9};
10use frame_support::{assert_noop, assert_ok};10use frame_support::{assert_noop, assert_ok, assert_err};
11use sp_std::convert::TryInto;11use sp_std::convert::TryInto;
12use pallet_balances;
13
14fn add_balance(user: u64, value: u64) {
15 const RICH_USER: u64 = 999;
16 assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), RICH_USER, value, 0));
17 assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(Origin::root(), RICH_USER, user, value));
18}
1219
13fn default_nft_data() -> CreateNftData {20fn default_nft_data() -> CreateNftData {
14 CreateNftData {21 CreateNftData {
34 owner: u64,41 owner: u64,
35 id: CollectionId,42 id: CollectionId,
36) -> CollectionId {43) -> CollectionId {
44 add_balance(owner, CollectionCreationPrice::get() as u64 + 1);
45
37 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();46 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
38 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();47 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
120 });129 });
121}130}
131
132#[test]
133fn check_not_sufficient_founds() {
134 new_test_ext().execute_with(|| {
135 let acc: u64 = 1;
136 <pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();
137
138 let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
139 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
140 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
141
142 let data: CreateCollectionData<<Test as system::Config>::AccountId> = CreateCollectionData {
143 name: name.try_into().unwrap(),
144 description: description.try_into().unwrap(),
145 token_prefix: token_prefix.try_into().unwrap(),
146 mode: CollectionMode::NFT,
147 ..Default::default()
148 };
149
150 let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);
151 assert_err!(result, <CommonError<Test>>::NotSufficientFounds);
152 });
153}
122154
123#[test]155#[test]
124fn create_fungible_collection_fails_with_large_decimal_numbers() {156fn create_fungible_collection_fails_with_large_decimal_numbers() {