Repository navigation
fix(contract): nutrition/behavior validation and paged weight history (#299, #300, #301, #302) - #355
Merged
iam-mercy merged 1 commit intoOct 20, 2026
Conversation
…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
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#299:
add_weight_entryweight boundsweight == 0orweight > 500_000g withInvalidInput. Valid entries are stored with a timestamp and emitWeightRecorded. The existing tests cover zero weight, unrealistic weight and the event.#300:
log_feedingservings and plan existenceservings == 0and anyplan_idthat does not exist or does not belong to the pet.test_log_feeding_rejects_nonexistent_plan.#301: Paginated weight history
get_weight_history_paged(pet_id, offset, limit)reads only the requested slice from storage.limitis capped at 50. A limit of 0, an offset past the end, or an unknown pet returns an empty page.test_get_weight_history_paged.#302:
add_behavior_recordboundsInvalidInput.BehaviorRecordedevent on success.test_behavior.rsfor 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