Fix 85#192
Open
Hydrax117 wants to merge 3 commits into
Open
Conversation
|
@Hydrax117 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.
Pull Request — Issue #85
Title
feat(progress): implement get_progress_history with 50-entry gas capCloses
Closes #85
Summary
The README documents
get_progress_history(player_id)as a first-class query function, but the contract only exposedget_history_entry(player_id, index), forcing callers to loop manually. This PR implements the missing function, adds a 50-entry gas cap, and covers both the happy path and the empty-history edge case with unit tests.Changes
contracts/progress/src/lib.rsProduction code
Import — added
Vecto thesoroban_sdkimport:New query function — added after
get_history_entryin the Queries section:Tests
test_get_progress_history_three_entries— advances through all three tiers and asserts all 3 entries are returned with correctold_level,new_level, andmilestone_refat each position:test_get_progress_history_empty— queries a player that has never hadadvance_levelcalled and asserts an empty Vec is returned:Acceptance Criteria
1..=limitwherelimit = count.min(50)HistoryCounterabsent →count = 0→ loop skipped → empty Vec returnedtest_get_progress_history_three_entriescheckslen == 3and all fields at each indexDesign Notes
const MAX_ENTRIES: u32 = 50is applied viacount.min(MAX_ENTRIES)before the loop, so the number of storage reads is bounded regardless of how many timesadvance_levelhas been called.1, 2, 3, …byadvance_leveland collected in that order, so the returned Vec is naturally chronological.HistoryCounterandHistoryEntrykeys; no schema changes required.if let Some— defensive guard inside the loop handles any theoretical gap in the index sequence without panicking, though under normal operation all indices1..=countwill be present.soroban_sdk::Vecis used (notstd::vec::Vec) because Soroban contracts compile to WASM and must use the SDK's host-managed collection types.How to Verify
Expected output:
Checklist
cargo test --workspacecargo clippy --workspace -- -D warningscargo fmt --all -- --check