Skip to content

fix(contract): nutrition/behavior validation and paged weight history (#299, #300, #301, #302) - #355

Merged
iam-mercy merged 1 commit into
iam-mercy:mainfrom
Crypto-Oracle001:fix/issues-299-300-301-302-validation-pagination
Oct 20, 2026
Merged

iam-mercy merged 1 commit into
iam-mercy:mainfrom
Crypto-Oracle001:fix/issues-299-300-301-302-validation-pagination

Conversation

@Crypto-Oracle001

Copy link
Copy Markdown
Contributor

Summary

#299: add_weight_entry weight bounds

  • Rejects weight == 0 or weight > 500_000 g with InvalidInput. Valid entries are stored with a timestamp and emit WeightRecorded. The existing tests cover zero weight, unrealistic weight and the event.

#300: log_feeding servings and plan existence

  • Rejects servings == 0 and any plan_id that does not exist or does not belong to the pet.
  • Added test_log_feeding_rejects_nonexistent_plan.

#301: Paginated weight history

  • New get_weight_history_paged(pet_id, offset, limit) reads only the requested slice from storage.
  • limit is capped at 50. A limit of 0, an offset past the end, or an unknown pet returns an empty page.
  • Added test_get_weight_history_paged.

#302: add_behavior_record bounds

  • Severity must be between 1 and 5. Descriptions longer than 500 bytes are rejected with InvalidInput.
  • Emits a BehaviorRecorded event on success.
  • Added tests in test_behavior.rs for severity 0 and 10, an oversized description, and a max-length description that persists and emits the event.

Closes #299
Closes #300
Closes #301
Closes #302

…ght history

Issue iam-mercy#299 - add_weight_entry weight bounds
- add_weight_entry rejects weight == 0 or weight > MAX_PET_WEIGHT_GRAMS
  (500_000 g) with ContractError::InvalidInput; valid entries are stored
  with a timestamp and emit WeightRecorded. Covered by the existing
  zero/unrealistic-weight and event tests.

Issue iam-mercy#300 - log_feeding servings and plan existence
- log_feeding rejects servings == 0 and plan_ids that do not exist or do
  not belong to the pet. Adds test_log_feeding_rejects_nonexistent_plan
  alongside the existing zero-servings test.

Issue iam-mercy#301 - paginated weight history
- Add get_weight_history_paged(pet_id, offset, limit) that reads only the
  requested slice from storage (no full-history load).
- limit is capped at MAX_WEIGHT_HISTORY_PAGE_SIZE (50); limit 0, an
  offset past the end, or an unknown pet return an empty page.
- Adds test_get_weight_history_paged covering offset/limit paging, the
  50-entry cap and boundary cases.

Issue iam-mercy#302 - add_behavior_record bounds
- Keep severity bounded to 1..=5 and reject descriptions longer than
  MAX_BEHAVIOR_DESCRIPTION_LEN (500 bytes) with InvalidInput.
- Emit a BehaviorRecorded event (BehaviorRecordedEvent) on success.
- Fix the outdated doc comment (severity was documented as 0-10).
- Adds tests in test_behavior.rs for severity 0 and 10 rejection,
  oversized description rejection, and a max-length description that
  persists and emits an event.

Closes iam-mercy#299
Closes iam-mercy#300
Closes iam-mercy#301
Closes iam-mercy#302
@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@Crypto-Oracle001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@iam-mercy
iam-mercy merged commit c98a3fd into iam-mercy:main Oct 20, 2026
0 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants