Skip to content

Commit

Permalink
add check for allocation smaller than decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed May 2, 2024
1 parent 13c0fec commit e514af9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
33 changes: 33 additions & 0 deletions pallets/funding/src/tests/1_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <TestRuntime as Config>::PriceProvider::calculate_decimals_aware_price(
PriceOf::<TestRuntime>::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::<TestRuntime>::create_project(
RuntimeOrigin::signed(ISSUER_1),
jwt.clone(),
project_metadata.clone()
),
Error::<TestRuntime>::BadMetadata(MetadataError::AllocationSizeError)
);
});
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion pallets/funding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit e514af9

Please sign in to comment.