Skip to content

Commit

Permalink
accept only ct decimals from 4 to 20
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed May 2, 2024
1 parent f69f6f3 commit 7f7e83c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pallets/funding/src/tests/1_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,44 @@ mod create_project_extrinsic {
);
});
}

#[test]
fn unaccepted_ct_decimals() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let mut project_metadata = default_project_metadata(ISSUER_1);

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(),
);

let mut fail_with_decimals = |decimals: u8| {
project_metadata.token_information.decimals = decimals;

inst.execute(|| {
assert_noop!(
Pallet::<TestRuntime>::create_project(
RuntimeOrigin::signed(ISSUER_1),
jwt.clone(),
project_metadata.clone()
),
Error::<TestRuntime>::BadMetadata(MetadataError::BadDecimals)
);
});
};

// less than 5 should fail
for i in 0..=4 {
fail_with_decimals(i);
}
// more than 20 should fail
for i in 21..30 {
fail_with_decimals(i);
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions pallets/funding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ pub mod storage_types {
if target_funding < (1000u64 * 10u64.pow(USD_DECIMALS.into())).into() {
return Err(MetadataError::FundingTargetTooLow);
}

if self.token_information.decimals < 5 || self.token_information.decimals > 20 {
return Err(MetadataError::BadDecimals);
}
Ok(())
}
}
Expand Down Expand Up @@ -758,6 +762,8 @@ pub mod inner_types {
FundingTargetTooLow,
/// The project's metadata hash is not provided while starting the evaluation round.
CidNotProvided,
/// The ct decimals specified for the CT is outside the 4 to 20 range.
BadDecimals,
}

/// Errors related to the project's migration process.
Expand Down

0 comments on commit 7f7e83c

Please sign in to comment.