fix: emit CampaignExpired event in expire_campaign - #66
Conversation
Closes Ads-Bazaar#64: expire_campaign emitted CampaignCancelled which misreports the campaign state. Add CampaignExpired event struct and emit it from expire_campaign, with a regression test (test_expire_event).
JamesVictor-O
left a comment
There was a problem hiding this comment.
The core fix is correct — expire_campaign was emitting CampaignCancelled instead of CampaignExpired, and swapping the event struct at the call site is the right change.
However, the added test in test.rs (test_expire_event::test_campaign_expired_event) does not compile:
error[E0433]: cannot find module or crate `hex` in this scope
--> contracts/campaign-escrow/src/test.rs:1967:35
error[E0599]: no method named `abi_encode` found for struct `soroban_sdk::events::Events`
error[E0599]: no method named `iter` found for struct `ContractEvents`
error[E0599]: no function or associated item named `generate` found for struct `soroban_sdk::Address`
Specifically:
hex::encode(...)— thehexcrate isn't a dependency of this crate, and isn't needed here.env.events().abi_encode(...)— no such method exists onsoroban_sdk::events::Events.env.events().all().iter()—ContractEvents(the type returned by.all()) needs a different access pattern; check how existing tests in this file assert on emitted events (e.g. search for otherenv.events()usage) and follow that pattern instead.Address::generate(&env)needsuse soroban_sdk::testutils::Address as _;in scope (see how other test modules in this file import it).
Simplest fix: look at an existing test elsewhere in test.rs that already asserts an event was emitted (e.g. around SurplusReclaimed or DisputeFrozen) and mirror that pattern rather than hand-rolling XDR/hex encoding — the existing pattern is much simpler and will compile.
Please push a fix and I'll re-review. Ran cargo test --workspace locally to confirm the compile failure.
|
Correction to my review above: I said to mirror an existing event-assertion test elsewhere in
The simplest fix is likely: assert_eq!(
env.events().all(),
vec![
&env,
(
contract_id.clone(),
(symbol_short!("...") /* whatever topic Campaign
Expired's #[topic] derives */,).into_val(&env),
(id, refund).into_val(&env), // or however the event's data fields serialize
),
]
);(check the No |
The previous commit swapped the wrong call site: cancel_campaign was changed to emit CampaignExpired while expire_campaign (the subject of Ads-Bazaar#64) kept emitting CampaignCancelled. Restore CampaignCancelled in cancel_campaign and emit CampaignExpired in expire_campaign. Also fix the regression test, which did not compile (hex crate not a dependency, no abi_encode/iter on the events API) and never actually called expire_campaign. Use Event::to_xdr + filter_by_contract, the supported soroban-sdk 27 comparison path, and assert the emitted refunded_amount matches the unallocated balance.
|
Pushed a fix addressing the review — and found a deeper bug in the process. What was wrong:
The rewritten test follows the supported soroban-sdk 27 path you outlined:
Verified locally: |
JamesVictor-O
left a comment
There was a problem hiding this comment.
Automated review: confirmed the change is exactly what it claims — expire_campaign now emits CampaignExpired instead of CampaignCancelled, with cancel_campaign's own emit untouched (no duplicate/leftover). New event struct mirrors CampaignCancelled's shape and the file's existing event conventions. Regression test asserts the exact XDR-encoded event (topic + data), not just "doesn't panic". No fund-movement or state-transition logic touched. CI green. Approving.
|
Resolution: rebase on latest |
Problem
expire_campaignemittedCampaignCancelled, misreporting an expired campaign as cancelled.Approach
CampaignExpiredevent struct in events.rsexpire_campaign(1-line change in lib.rs)test_expire_eventregression testVerification
Minimal scoped change following existing event patterns.
Closes #64