fix(core): preserve null gold in DonateGoldExecution constructor (#4092) - #4892
fix(core): preserve null gold in DonateGoldExecution constructor (#4092)#4892berkelmali wants to merge 1 commit into
Conversation
Walkthrough
ChangesGold donation flow
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/Donate.test.ts (1)
141-143: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMake the test cover deferred calculation timing.
Line 143 constructs
DonateGoldExecutionafter the donor balance is set. A regression that calculates the default amount in the constructor would pass this test. Construct the execution before changing the donor balance, then enqueue it after the change. Assert against the post-change balance to verify thatinit()uses the current gold.Proposed test adjustment
- donor.addGold(9000n); + const donation = new DonateGoldExecution(donor, rInfo.id, null); + donor.addGold(9000n); const goldBefore = donor.gold(), recBefore = recipient.gold(); - game.addExecution(new DonateGoldExecution(donor, rInfo.id, null)); + game.addExecution(donation);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/Donate.test.ts` around lines 141 - 143, Update the test around DonateGoldExecution to construct the execution before the donor balance is changed, then add gold and enqueue the existing execution afterward. Assert the recipient and donor balances using the post-change gold amount, verifying that DonateGoldExecution.init() calculates the default donation at execution time rather than construction time.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/Donate.test.ts`:
- Around line 141-143: Update the test around DonateGoldExecution to construct
the execution before the donor balance is changed, then add gold and enqueue the
existing execution afterward. Assert the recipient and donor balances using the
post-change gold amount, verifying that DonateGoldExecution.init() calculates
the default donation at execution time rather than construction time.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2e19fdee-c874-4f9f-af6b-915d61c993c3
📒 Files selected for processing (2)
src/core/execution/DonateGoldExecution.tstests/Donate.test.ts
PR 1:
fix(core): preserve null gold in DonateGoldExecution constructorResolves #4092
Description:
In
DonateGoldExecution.ts, the constructor previously initializedthis.gold = toInt(goldNum ?? 0). Whennullwas explicitly passed asgoldNum(intended to trigger a default donation of 1/3 of the sender's gold), the nullish coalescing operator?? 0immediately convertednullto0, settingthis.goldto0n.Consequently, in
init(), the linethis.gold ??= this.sender.gold() / 3n;failed to trigger because0nis neithernullnorundefined. As a result, callingDonateGoldExecutionwithnullcaused the player to donate0gold instead of 1/3 of their current gold balance.This PR fixes the constructor to preserve
nullwhengoldNumisnull:This allows
init()to correctly evaluatethis.gold ??= this.sender.gold() / 3nand donate 1/3 of the sender's gold.Please complete the following:
tests/Donate.test.ts)Please put your Discord username so you can be contacted if a bug or regression is found:
barfires