Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify identifier length validation #960

Merged
merged 9 commits into from
Nov 13, 2023
Merged

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented Nov 10, 2023

Firstly, remove asserts from the validate_identifier_length and
validate_prefix_length functions. Instead, let the regular checks
handle cases where min and max constraints don’t allow for a valid
prefix to exist.

Secondly, ensure minimum length constraints is at least one. This
makes sure that the validation functions will check for empty
identifiers and prefixes. This makes empty identifier check in
validate_channel_identifier as well as IdentifierError::Empty variant
unnecessary so get rid of those too.

Lastly, collapse all checks in validate_prefix_length into a single
call to validate_identifier_length with correctly adjusted min and max
constraints.

Closes: #961


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

Firstly, remove asserts from the validate_identifier_length and
validate_prefix_length functions.  Instead, let the regular checks
handle cases where min and max constraints don’t allow for a valid
prefix to exist.

Secondly, ensure minimum length constraints is at least one.  This
makes sure that the validation functions will check for empty
identifiers and prefixes.  This makes empty identifier check in
validate_channel_identifier as well as Error::Empty variant
unnecessary so get rid of those too.

Lastly, collapse all checks in validate_prefix_length into a single
call to validate_identifier_length with correctly adjusted min and max
constraints.

Issue: cosmos#959
Copy link

codecov bot commented Nov 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (318c284) 66.38% compared to head (7883612) 66.33%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #960      +/-   ##
==========================================
- Coverage   66.38%   66.33%   -0.06%     
==========================================
  Files         161      161              
  Lines       15767    15743      -24     
==========================================
- Hits        10467    10443      -24     
  Misses       5300     5300              
Files Coverage Δ
...tes/ibc/src/core/ics24_host/identifier/validate.rs 98.76% <100.00%> (-0.29%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mina86 mina86 marked this pull request as ready for review November 11, 2023 09:04
@mina86
Copy link
Contributor Author

mina86 commented Nov 11, 2023

@rnbguy, I guess it’s ready for review if you like it then.

Copy link
Collaborator

@rnbguy rnbguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @mina86 ! Requested a few changes.

@mina86 mina86 requested a review from rnbguy November 13, 2023 15:34
Copy link
Collaborator

@rnbguy rnbguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mina86 🎉
I reverted the deletion of IdentifierError::Empty as #942 can cover it.

@rnbguy rnbguy merged commit fe6b5b0 into cosmos:main Nov 13, 2023
12 checks passed
@mina86 mina86 deleted the d branch November 13, 2023 18:49
Farhad-Shabani pushed a commit that referenced this pull request Sep 9, 2024
* refactor: simplify identifier length validation

Firstly, remove asserts from the validate_identifier_length and
validate_prefix_length functions.  Instead, let the regular checks
handle cases where min and max constraints don’t allow for a valid
prefix to exist.

Secondly, ensure minimum length constraints is at least one.  This
makes sure that the validation functions will check for empty
identifiers and prefixes.  This makes empty identifier check in
validate_channel_identifier as well as Error::Empty variant
unnecessary so get rid of those too.

Lastly, collapse all checks in validate_prefix_length into a single
call to validate_identifier_length with correctly adjusted min and max
constraints.

Issue: #959

* log

* Update 960-simplify-length-validation.md

Signed-off-by: Michal Nazarewicz <[email protected]>

* tests

* Update and rename 960-simplify-length-validation.md to 961-simplify-length-validation.md

Signed-off-by: Michal Nazarewicz <[email protected]>

* update changelog entry

* revert error variant deletion

* refactor id validation tests

* use numeral consistently

---------

Signed-off-by: Michal Nazarewicz <[email protected]>
Co-authored-by: Ranadeep Biswas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor identifier length validation in ics24 implementation
2 participants