From e514af936b5d2d915f684abfb6764930df52c9a2 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Wed, 1 May 2024 15:23:02 +0200 Subject: [PATCH] add check for allocation smaller than decimals --- pallets/funding/src/tests/1_application.rs | 33 ++++++++++++++++++++++ pallets/funding/src/types.rs | 4 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pallets/funding/src/tests/1_application.rs b/pallets/funding/src/tests/1_application.rs index c779d9cd2..9e163f6c8 100644 --- a/pallets/funding/src/tests/1_application.rs +++ b/pallets/funding/src/tests/1_application.rs @@ -595,6 +595,39 @@ mod create_project_extrinsic { fail_with_decimals(i); } } + + #[test] + fn allocation_smaller_than_decimals() { + let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); + let mut project_metadata = default_project_metadata(ISSUER_1); + project_metadata.total_allocation_size = 2_000_000; + project_metadata.token_information.decimals = 8; + project_metadata.minimum_price = ::PriceProvider::calculate_decimals_aware_price( + PriceOf::::from_float(100_000.0f64), + USD_DECIMALS, + project_metadata.token_information.decimals, + ) + .unwrap(); + + inst.mint_plmc_to(default_plmc_balances()); + let jwt = get_mock_jwt_with_cid( + ISSUER_1, + InvestorType::Institutional, + generate_did_from_account(ISSUER_1), + project_metadata.clone().policy_ipfs_cid.unwrap(), + ); + + inst.execute(|| { + assert_noop!( + Pallet::::create_project( + RuntimeOrigin::signed(ISSUER_1), + jwt.clone(), + project_metadata.clone() + ), + Error::::BadMetadata(MetadataError::AllocationSizeError) + ); + }); + } } } diff --git a/pallets/funding/src/types.rs b/pallets/funding/src/types.rs index 193f7b22d..2aff7d4d3 100644 --- a/pallets/funding/src/types.rs +++ b/pallets/funding/src/types.rs @@ -225,7 +225,9 @@ pub mod storage_types { return Err(MetadataError::AllocationSizeError); } - if self.total_allocation_size <= 0u64.into() { + if self.total_allocation_size <= 0u64.into() || + self.total_allocation_size < 10u64.pow(self.token_information.decimals as u32).into() + { return Err(MetadataError::AllocationSizeError); }