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
--- 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
--- a/pallets/unique/src/tests.rs
+++ b/pallets/unique/src/tests.rs
@@ -7,9 +7,26 @@
 	CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,
 	TokenId, MAX_TOKEN_OWNERSHIP,
 };
-use frame_support::{assert_noop, assert_ok};
+use frame_support::{assert_noop, assert_ok, assert_err};
 use sp_std::convert::TryInto;
+use pallet_balances;
 
+fn add_balance(user: u64, value: u64) {
+	const DONOR_USER: u64 = 999;
+	assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(
+		Origin::root(),
+		DONOR_USER,
+		value,
+		0
+	));
+	assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(
+		Origin::root(),
+		DONOR_USER,
+		user,
+		value
+	));
+}
+
 fn default_nft_data() -> CreateNftData {
 	CreateNftData {
 		const_data: vec![1, 2, 3].try_into().unwrap(),
@@ -34,6 +51,8 @@
 	owner: u64,
 	id: CollectionId,
 ) -> CollectionId {
+	add_balance(owner, CollectionCreationPrice::get() as u64 + 1);
+
 	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
 	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
 	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
@@ -121,6 +140,30 @@
 }
 
 #[test]
+fn check_not_sufficient_founds() {
+	new_test_ext().execute_with(|| {
+		let acc: u64 = 1;
+		<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();
+
+		let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+		let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+		let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
+
+		let data: CreateCollectionData<<Test as system::Config>::AccountId> =
+			CreateCollectionData {
+				name: name.try_into().unwrap(),
+				description: description.try_into().unwrap(),
+				token_prefix: token_prefix.try_into().unwrap(),
+				mode: CollectionMode::NFT,
+				..Default::default()
+			};
+
+		let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);
+		assert_err!(result, <CommonError<Test>>::NotSufficientFounds);
+	});
+}
+
+#[test]
 fn create_fungible_collection_fails_with_large_decimal_numbers() {
 	new_test_ext().execute_with(|| {
 		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();