Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/campaign_transfer_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use soroban_sdk::token::StellarAssetClient as TokenAdminClient;
use soroban_sdk::{testutils::Address as _, Address, Env, String};

fn setup_env<'a>() -> (Env, Address, Address, ProofOfHeartClient<'a>) {
Expand Down Expand Up @@ -90,17 +91,22 @@ fn campaign_transfer_cancel_then_reinitiate_succeeds() {
}

#[test]
fn original_creator_cannot_contribute_after_campaign_transfer() {
fn original_creator_can_contribute_after_campaign_transfer() {
let (env, _admin, creator, client) = setup_env();
let new_creator = Address::generate(&env);
let campaign_id = create_campaign(&env, &client, &creator, "Transfer contribution guard");

let token_admin = TokenAdminClient::new(&env, &client.get_token());
token_admin.mint(&creator, &100);

client.verify_campaign(&campaign_id);
client.initiate_campaign_transfer(&campaign_id, &new_creator);
client.accept_campaign_transfer(&campaign_id);

// After transfer, the original creator is a regular community member and
// must be allowed to contribute.
let res = client.try_contribute(&campaign_id, &creator, &100);
assert_eq!(res.unwrap_err().unwrap(), Error::NotAuthorized);
assert!(res.is_ok());
}

#[test]
Expand Down
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl ProofOfHeart {
}

require_active_campaign(&campaign)?;
if contributor == campaign.creator || contributor == campaign.first_creator {
if contributor == campaign.creator {
return Err(Error::NotAuthorized);
}
if env.ledger().timestamp() > campaign.deadline {
Expand Down Expand Up @@ -527,7 +527,7 @@ impl ProofOfHeart {
set_total_raised_global(
&env,
total_raised
.checked_sub(campaign.amount_raised)
.checked_sub(campaign.amount_raised - reserve_amount)
.ok_or(Error::Overflow)?,
);

Expand Down Expand Up @@ -571,6 +571,14 @@ impl ProofOfHeart {
reserve.released = true;
set_campaign_reserve(&env, campaign_id, &reserve);

let total_raised = get_total_raised_global(&env);
set_total_raised_global(
&env,
total_raised
.checked_sub(reserve.amount)
.ok_or(Error::Overflow)?,
);

env.events().publish(
("reserve_released", campaign_id, campaign.creator),
reserve.amount,
Expand All @@ -587,6 +595,7 @@ impl ProofOfHeart {
reserve_bps: u32,
) -> Result<(), Error> {
assert_admin(&env, &admin)?;
Self::require_not_paused(&env)?;
if reserve_bps > 10000 || delay_days > 365 {
return Err(Error::ValidationFailed);
}
Expand Down Expand Up @@ -665,6 +674,7 @@ impl ProofOfHeart {
description: String,
) -> Result<(), Error> {
let mut campaign = get_creator_campaign(&env, campaign_id)?;
Self::require_not_paused(&env)?;

if campaign.amount_raised > 0 {
return Err(Error::ValidationFailed);
Expand Down Expand Up @@ -717,6 +727,7 @@ impl ProofOfHeart {
description: String,
) -> Result<(), Error> {
let mut campaign = get_creator_campaign(&env, campaign_id)?;
Self::require_not_paused(&env)?;

require_active_campaign(&campaign)?;
if description.len() < CAMPAIGN_DESCRIPTION_MIN_LEN
Expand Down
Loading