fix(tools): reject non-positive and overflow amounts in CampaignTotal…#52
Conversation
|
Good defensive check on the increment path — catching negatives and overflow is exactly what we need for #50. Heads up though: flipping 's return type from to is a public API break for downstream callers. Could you either add a non-breaking alongside (leaving 's signature as-is), or handle the validation internally while keeping the current signature? Once that's done this is good to go. |
|
Hey @cybermax4200 👋 — the validation tightening for #50 (rejecting non-positive / overflow amounts in |
Everything is now green, can you merge please |
|
Can I work on this? I've contributed to similar full-stack projects and can handle this quickly. |
Problem
CampaignTotals::increment accepted any i128, including negative values and zero. A caller passing a negative amount would silently subtract from the running
total — driving (campaign_id, asset) balances negative with no error. This creates a semantic mismatch with the on-chain storage_increment_total_raised, which
panics on delta <= 0, and corrupts off-chain analytics dashboards that treat these totals as "amount raised".
Overflow was also silent: a sufficiently large amount would wrap, producing a nonsense total.
Changes
Tests
Three new cases added alongside the existing six:
All 9 unit tests pass.
Closes #50