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
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 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() {