-
Notifications
You must be signed in to change notification settings - Fork 87
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
feat: Implement Dynamic Daily Reset for DailyPlayerStat #268
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
onchain/src/contracts/dewordle.cairo
Outdated
let current_timestamp = get_block_timestamp(); | ||
let last_attempt_timestamp = daily_stat.last_attempt_timestamp; | ||
|
||
if last_attempt_timestamp < self.end_of_day_timestamp.read() - SECONDS_IN_A_DAY { | ||
daily_stat = | ||
DailyPlayerStat { | ||
player: caller, | ||
attempt_remaining: 6, | ||
has_won: false, | ||
won_at_attempt: 0, | ||
last_attempt_timestamp: current_timestamp, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to the top of the submit_guess
function, also you're not updating the daily player stat when it's a new day.
onchain/tests/test_dewordle.cairo
Outdated
#[test] | ||
fn test_get_player_daily_stat_new_player() { | ||
let contract_address = deploy_contract(); | ||
let dewordle = IDeWordleDispatcher { contract_address }; | ||
|
||
// Get stats for a player that hasn't played yet | ||
let random_player = starknet::contract_address_const::<0x456>(); | ||
let daily_stat = dewordle.get_player_daily_stat(random_player); | ||
|
||
// Verify default values | ||
assert(daily_stat.player == random_player, 'Wrong player address'); | ||
assert(daily_stat.attempt_remaining == 6, 'Should have 6 attempts'); | ||
assert(!daily_stat.has_won, 'has_won should be false'); | ||
assert(daily_stat.won_at_attempt == 0, 'won_at_attempt should be 0'); | ||
assert(daily_stat.last_attempt_timestamp == 0, 'Timestap should be 0'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this too
onchain/src/contracts/dewordle.cairo
Outdated
}; | ||
self.daily_player_stat.write(caller, new_daily_stat); | ||
Option::None | ||
return Option::None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Option::None; | |
Option::None |
Pull Request
Description
This PR introduces a mechanism to track each player's last attempt timestamp using last_attempt_timestamp inside the DailyPlayerStat struct. This ensures that player stats reset dynamically on their first attempt of a new day. The submit_guess function now checks if last_attempt_timestamp is from a previous day—if so, it resets DailyPlayerStat; otherwise, it proceeds normally. Additionally, last_attempt_timestamp updates on every guess submission. Unit tests have been added to verify correct behavior.
Related Issue
Closes #234
Type of Change
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to not work as expected)Update your CONTRIBUTING.md to reference the template
Documentation update
Code refactoring
Performance improvement
Test update
Build/CI pipeline change
Other (please describe):
Checklist
I have read the CONTRIBUTING document.
My code follows the code style of this project.
I have commented my code, particularly in hard-to-understand areas.
I have made corresponding changes to the documentation.
My changes generate no new warnings.
I have added tests that prove my fix is effective or that my feature works.
New and existing unit tests pass locally with my changes.
Any dependent changes have been merged and published in downstream modules.
Screenshots/Recordings
Additional Context
Testing Instructions
Run "scarb test" while in the onchain directory