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

fix edge cases in assert_before parsing #140

Merged
merged 1 commit into from
Feb 16, 2023
Merged

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented Feb 15, 2023

Specifically, assert_before a negative value is an automatic fail. assert_before a value exceeding the max is an automatic pass.

The two functions used to parse block height and timestamps (seconds) for the original ASSERT_HEIGHT_* and ASSERT_SECONDS_* has edge-case behavior tailored to those conditions. Those conditions requires the block height or timestamp to exceed the specified limit. If the limit is 0 or negative, the condition is always true. If the limit exceeds the max value however (uint32 and uint64 respectively), the conditions always fail.

Since the ASSERT_BEFORE_* conditions have the inverse semantics, the edge case behavior also need to be inverse. This patch introduces parse_positive_height() and parse_positive_seconds() with the inverse behavior for values outside the limits.

The bulk of this patch is to fix up the unit tests to explicitly cover these cases, both for the existing parse_height() and the new parse_positive_height() (as well as the "seconds" counterpart).

…a negative value is an automatic fail. assert_before a value exceeding the max is an automatic pass
Copy link
Contributor

@richardkiss richardkiss left a comment

Choose a reason for hiding this comment

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

Seems reasonable.

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.

2 participants