From cbc95b83059b3c71452720419be87dfc8e5a58c4 Mon Sep 17 00:00:00 2001 From: kozyrevdev <73348153+kozyrevdev@users.noreply.github.com> Date: Tue, 01 Mar 2022 08:02:00 +0000 Subject: [PATCH] Merge pull request #299 from UniqueNetwork/feature/CORE-296 CORE-296 Add error "NotSufficientFounds" and test it. --- --- 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::::NoPermission)?; + .map_err(|_| Error::::NotSufficientFounds)?; } >::put(created_count); --- 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; } --- 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!(>::set_balance( + Origin::root(), + DONOR_USER, + value, + 0 + )); + assert_ok!(>::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 = "Test1\0".encode_utf16().collect::>(); let col_desc1: Vec = "TestDescription1\0".encode_utf16().collect::>(); let token_prefix1: Vec = 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; + >::set_balance(Origin::root(), acc, 0, 0).unwrap(); + + let name: Vec = "Test1\0".encode_utf16().collect::>(); + let description: Vec = "TestDescription1\0".encode_utf16().collect::>(); + let token_prefix: Vec = b"token_prefix1\0".to_vec(); + + let data: CreateCollectionData<::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, >::NotSufficientFounds); + }); +} + +#[test] fn create_fungible_collection_fails_with_large_decimal_numbers() { new_test_ext().execute_with(|| { let col_name1: Vec = "Test1\0".encode_utf16().collect::>(); -- gitstuff