Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions contracts/campaign-escrow/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ pub struct CampaignCancelled {
pub refunded_amount: i128,
}

#[contractevent]
#[derive(Clone, Debug)]
pub struct CampaignExpired {
#[topic]
pub campaign_id: CampaignId,
pub refunded_amount: i128,
}

#[contractevent]
#[derive(Clone, Debug)]
pub struct SurplusReclaimed {
Expand Down
2 changes: 1 addition & 1 deletion contracts/campaign-escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl CampaignEscrowContract {
campaign.escrow_balance = campaign.committed_payouts;
campaign.status = CampaignStatus::Cancelled;
storage::set_campaign(&env, &campaign);
events::CampaignCancelled {
events::CampaignExpired {
campaign_id,
refunded_amount: refund,
}
Expand Down
43 changes: 43 additions & 0 deletions contracts/campaign-escrow/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,3 +1928,46 @@ mod test_freeze_for_dispute {
assert_eq!(result, Err(Ok(Error::SubmissionNotPayable)));
}
}

mod test_expire_event {
use super::test_helpers::*;
use soroban_sdk::testutils::{Address as _, Events as _};
use soroban_sdk::{Address, Event as _};

#[test]
fn test_campaign_expired_event() {
let (env, contract_id) = setup_env();
let (client, _admin, _dispute, business, token) = bootstrap(&env, &contract_id, 50);

let budget: i128 = 10_000_000;
let id = create_funded_campaign(&env, &client, &business, &token, budget, 5);

let c1 = Address::generate(&env);
let c2 = Address::generate(&env);
// Two creators are selected (committing 1_000_000 each)
for c in [&c1, &c2] {
client.apply_to_campaign(c, &id, &soroban_sdk::String::from_str(&env, "pitch"));
client.approve_creator(&business, &id, c, &1_000_000);
}

// Advance past the content deadline.
advance_time(&env, 604_800 + 10);

// Expire the campaign — this is what emits the CampaignExpired event.
client.expire_campaign(&business, &id);

// Verify CampaignExpired was emitted with the unallocated refund
// (budget minus the 2M committed to the approved creators).
let events = env.events().all().filter_by_contract(&contract_id);
assert_eq!(
events.events().last(),
Some(
&crate::events::CampaignExpired {
campaign_id: id,
refunded_amount: budget - 2 * 1_000_000,
}
.to_xdr(&env, &contract_id)
)
);
}
}
Loading