Conversation
|
One more detail that might save you time, since it narrows the search to a single merge.
So the bad conflict resolution came in on #1386's branch and landed on main with it, which is why Worth a look at how that merge was resolved before more branches pile on top: the two hunks that went wrong are exactly the two this PR repairs (the missing |
a0cf64c to
303e57c
Compare
|
rebased onto main - mergeable again |
303e57c to
9574841
Compare
|
Rebased onto the current |
9574841 to
afa1c5e
Compare
|
Rebased onto current Files that needed resolution:
Verification,
Intent of #1348 is unchanged. |
…blocked the build
Nine tests for `donate` boundaries: the minimum amount, a zero amount, a
nonexistent pool, a closed pool, a cancelled pool, `u128::MAX` recorded exactly,
the rejection past MAX, and the pool total and donor count moving together.
Two of the cases the issue lists cannot pass against the code as it is, so they
come with the smallest change that makes them true:
- `donate` accepted a zero contribution and still counted the caller as a donor,
because the donor-count branch runs before any amount check. It now rejects
zero with `InvalidAmount` — the same message `donate_with_token` uses for the
same case — and a second test confirms the rejected call leaves no donor
behind.
- `donate` built the pool total with a bare `+`. `u128::MAX` is recorded fine,
but the contribution after it panicked deep in the arithmetic with nothing
tying the message to the contract. It now uses `checked_add` and reports
"Collected amount overflow", matching the token path.
`main` does not compile, so none of this could run. Verified on a clean checkout
with these changes stashed:
error: this file contains an unclosed delimiter
--> contracts/hello-world/src/lib.rs:1572:40
error[E0592]: duplicate definitions with name `get_all_campaigns`
`is_closed` lost its closing brace in a merge, which nested the rest of the impl
inside it, and `get_all_campaigns` was defined twice with two different
implementations — one checks storage before pushing an id, the other pushes every
id up to the count. The brace is restored and the storage-checking version is
kept, since the other one assumes ids are contiguous.
One pre-existing test asserted 200M where the contract says 300M + 200M = 500M,
and then compared 800M against the 500M goal. Its expectations now match
`collected` being a single running total. Whether donations in different tokens
should be tracked separately is exactly what Web3Novalabs#1349 asks, so that is not decided
here.
Unrelated but worth a follow-up: 24 test files exist under src/, and only 11 are
declared in lib.rs, so the rest never run — including
test_issue_1063_donor_count.rs, whose header documents a double-increment in the
donor count that the current code does not do.
cargo test --lib: 173 passed, 0 failed (before: the crate did not compile).
afa1c5e to
08c644c
Compare
|
Correction to my resolution note above. My first pass kept the union of At head 08c644c: |
|
Closing this: the issue is assigned to @manasehstephen131-ops in Drips ( |
Closes #1348
What this adds
Nine tests for
donateboundary amounts, in a newtest_issue_1348_donate_boundary_amounts.rsregistered inlib.rs:PoolNotFound(Setup GitHub CI/CD Pipeline #1)PoolIsClosed(Define Core Data Structures for Donation Pools #4)InvalidPoolState(Create Landing Page UI #2)u128::MAXis recorded exactlyu128::MAXis rejected by the checked addTwo cases could not pass, so they come with the smallest change that makes them true
The issue asks for "zero-amount donation is rejected" and "u128 near-max amount handled without overflow". Neither held:
donatehad no amount check at all, and the donor-count branch runs before anything else, so a zero contribution succeeded and marked the caller as a donor of the pool. It now rejects zero withInvalidAmount, the same messagedonate_with_tokenuses for the same case.collectedwas built with a bare+.u128::MAXitself is recorded fine; the contribution after it panicked deep in the arithmetic with no message tying it to the contract. It now useschecked_addand reportsCollected amount overflow, matching whatdonate_with_tokenalready does.Both are three lines and mirror the sibling function, so
donateanddonate_with_tokennow reject the same inputs the same way. If you would rather keepdonatepermissive and have the tests document the current behaviour instead, that is a two-line revert — say the word.maindoes not compile, so the tests could not run at allVerified on a clean checkout with these changes stashed:
is_closedlost its closing brace in a merge, which nested the entire rest of the impl inside it (that is also whyclose_poolandis_closedended up unindented).get_all_campaignsexists twice with two different implementations: one checksstorage().has(&id)before pushing, the other pushes every id up to the count. The storage-checking version is kept — the other assumes ids are contiguous.Those two edits are what let
cargo test --librun at all. Same story as the missing brace: happy to split them out if you prefer a separate PR.One pre-existing test asserted the wrong total
test_campaign_lifecycle::test_campaign_token_donations_lifecycleasserted 200M after a 300M + 200M sequence, then compared 800M against the 500M goal. Its expectations now match the contract:collectedis a single running total across donations regardless of token. Whether donations in different tokens should be tracked separately is exactly what #1349 asks, so I have not decided that here.Worth a separate issue: 14 test files never run
src/contains 26test*.rsfiles andlib.rsdeclares 12 modules. The other 14 are dead code as far as CI is concerned —test_numeric_overflow,test_issue_1067_refund_deadline,test_token_transfer_errors,test_auth_bypass, and others.test_issue_1063_donor_count.rsis a good example of why this matters: its header documents a double increment in the donor count with tests asserting it, while the currentdonateincrements once — nobody noticed because the file never runs. I did not touch them; declaring them all would probably surface a pile of failures at once.Verification
Before these fixes the same command stopped at "could not compile
hello-world".