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

difftreelog

Merge pull request #299 from UniqueNetwork/feature/CORE-296

kozyrevdev2022-03-01parents: #64ceec5 #f313147.patch.diff
in: master
CORE-296 Add error "NotSufficientFounds" and test it.

3 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
319 /// Target collection doesn't supports this operation319 /// Target collection doesn't supports this operation
320 UnsupportedOperation,320 UnsupportedOperation,
321
322 /// Not sufficient founds to perform action
323 NotSufficientFounds,
321 }324 }
322325
323 #[pallet::storage]326 #[pallet::storage]
470 WithdrawReasons::TRANSFER,473 WithdrawReasons::TRANSFER,
471 ExistenceRequirement::KeepAlive,474 ExistenceRequirement::KeepAlive,
472 )475 )
473 .map_err(|_| Error::<T>::NoPermission)?;476 .map_err(|_| Error::<T>::NotSufficientFounds)?;
474 }477 }
475478
476 <CreatedCollectionCount<T>>::put(created_count);479 <CreatedCollectionCount<T>>::put(created_count);
modifiedpallets/unique/src/mock.rsdiffbeforeafterboth
108}108}
109109
110parameter_types! {110parameter_types! {
111 pub const CollectionCreationPrice: u32 = 0;111 pub const CollectionCreationPrice: u32 = 100;
112 pub TreasuryAccountId: u64 = 1234;112 pub TreasuryAccountId: u64 = 1234;
113 pub EthereumChainId: u32 = 1111;113 pub EthereumChainId: u32 = 1111;
114}114}
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 DONOR_USER: u64 = 999;
16 assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(
17 Origin::root(),
18 DONOR_USER,
19 value,
20 0
21 ));
22 assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(
23 Origin::root(),
24 DONOR_USER,
25 user,
26 value
27 ));
28}
1229
13fn default_nft_data() -> CreateNftData {30fn default_nft_data() -> CreateNftData {
14 CreateNftData {31 CreateNftData {
34 owner: u64,51 owner: u64,
35 id: CollectionId,52 id: CollectionId,
36) -> CollectionId {53) -> CollectionId {
54 add_balance(owner, CollectionCreationPrice::get() as u64 + 1);
55
37 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();56 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>>();57 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
120 });139 });
121}140}
141
142#[test]
143fn check_not_sufficient_founds() {
144 new_test_ext().execute_with(|| {
145 let acc: u64 = 1;
146 <pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();
147
148 let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
149 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
150 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
151
152 let data: CreateCollectionData<<Test as system::Config>::AccountId> =
153 CreateCollectionData {
154 name: name.try_into().unwrap(),
155 description: description.try_into().unwrap(),
156 token_prefix: token_prefix.try_into().unwrap(),
157 mode: CollectionMode::NFT,
158 ..Default::default()
159 };
160
161 let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);
162 assert_err!(result, <CommonError<Test>>::NotSufficientFounds);
163 });
164}
122165
123#[test]166#[test]
124fn create_fungible_collection_fails_with_large_decimal_numbers() {167fn create_fungible_collection_fails_with_large_decimal_numbers() {