test(dpp): add StepDecreasingAmount and validate_update keyword/description error path tests#3125
Conversation
📝 WalkthroughWalkthroughThis PR adds comprehensive unit tests for two validation functions in rs-dpp, covering previously untested error branches. Tests are added for StepDecreasingAmount distribution validation (covering invalid parameter combinations) and validate_update_v0 keyword and description validation (covering invalid lengths, characters, and duplicates). Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
7ca3eb0 to
d94fa42
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
b25e974 to
dfeb089
Compare
dfeb089 to
15f4bdb
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs (1)
615-802: New keyword/description validation tests look correct and well-structured.All seven tests properly set up the fixture, bump the version, mutate the target field to an invalid value, and assert the expected error variant. The error paths exercised align with the validation logic at lines 270-323.
One minor observation: existing tests in this file (e.g., lines 386-391, 415-416) use
assert_matches!withifguards to verify error details (contract ID, keyword value, etc.), whereas these new tests only match the variant with a wildcard_. Adding guards would strengthen the assertions—for example, verifyinge.data_contract_id() == old_data_contract.id()on the keyword errors—but this is optional.,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs` around lines 615 - 802, Update the new tests to assert error details instead of using wildcards: for each test that currently matches e.g. ConsensusError::BasicError(BasicError::TooManyKeywordsError(_)) or BasicError::InvalidKeywordLengthError(_), change the pattern to bind the inner error (e.g. BasicError::TooManyKeywordsError(e)) and add an if guard that checks properties like e.data_contract_id() == old_data_contract.id() and, where relevant, e.keyword() or e.keyword_value() equals the invalid value used in the test; locate these changes in the tests named should_return_invalid_result_if_too_many_keywords, _if_keyword_too_short, _if_keyword_too_long, _if_keyword_has_invalid_chars, _if_duplicate_keywords, _if_description_too_short, and _if_description_too_long, and update the assert_matches! patterns to include the bound variable and guards to validate error details.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs`:
- Around line 615-802: Update the new tests to assert error details instead of
using wildcards: for each test that currently matches e.g.
ConsensusError::BasicError(BasicError::TooManyKeywordsError(_)) or
BasicError::InvalidKeywordLengthError(_), change the pattern to bind the inner
error (e.g. BasicError::TooManyKeywordsError(e)) and add an if guard that checks
properties like e.data_contract_id() == old_data_contract.id() and, where
relevant, e.keyword() or e.keyword_value() equals the invalid value used in the
test; locate these changes in the tests named
should_return_invalid_result_if_too_many_keywords, _if_keyword_too_short,
_if_keyword_too_long, _if_keyword_has_invalid_chars, _if_duplicate_keywords,
_if_description_too_short, and _if_description_too_long, and update the
assert_matches! patterns to include the bound variable and guards to validate
error details.
Issue Being Fixed
Tracker: thepastaclaw/tracker#14 (parent: #11)
Addresses findings C-13 and I-02 from the rs-dpp test quality audit.
What was done
C-13:
StepDecreasingAmountvalidation — 3 tests → 11 testsAdded 8 new error-path tests covering all previously untested branches:
test_step_decreasing_amount_invalid_zero_distribution_start— distribution_start_amount=0test_step_decreasing_amount_invalid_max_distribution_start— distribution_start_amount > MAX_DISTRIBUTION_PARAMtest_step_decreasing_amount_invalid_trailing_exceeds_start— trailing > start amounttest_step_decreasing_amount_invalid_max_interval_count_too_low— max_interval_count=1 (< 2)test_step_decreasing_amount_invalid_max_interval_count_too_high— max_interval_count=1025 (> 1024)test_step_decreasing_amount_invalid_zero_numerator— decrease_per_interval_numerator=0test_step_decreasing_amount_invalid_numerator_gte_denominator— numerator >= denominatortest_step_decreasing_amount_invalid_min_value_exceeds_start— min_value > distribution_start_amountI-02:
validate_updatekeyword/description validation — 0 tests → 7 testsAdded tests for all 5 keyword error paths plus 2 description error paths:
should_return_invalid_result_if_too_many_keywords— 51 keywords →TooManyKeywordsErrorshould_return_invalid_result_if_keyword_too_short— 2-char keyword →InvalidKeywordLengthErrorshould_return_invalid_result_if_keyword_too_long— 51-char keyword →InvalidKeywordLengthErrorshould_return_invalid_result_if_keyword_has_invalid_chars— whitespace in keyword →InvalidKeywordCharacterErrorshould_return_invalid_result_if_duplicate_keywords— same keyword twice →DuplicateKeywordsErrorshould_return_invalid_result_if_description_too_short— 2-char description →InvalidDescriptionLengthErrorshould_return_invalid_result_if_description_too_long— 101-char description →InvalidDescriptionLengthErrorAll tests compile and pass (56 targeted tests, 0 failures).
Summary by CodeRabbit
Validation
What was tested
Results
Environment
dashpay/platform