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
11 changes: 3 additions & 8 deletions contracts/events/src/bounty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn apply(
admin::require_not_paused(env)?;

let event = storage::get_event(env, bounty_id).ok_or(Error::EventNotFound)?;
require_active_bounty(env, &event)?;
require_active_bounty(&event)?;

applicant.require_auth();
idempotency::require_unseen(env, &applicant, &op_id)?;
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn withdraw_application(
admin::require_not_paused(env)?;

let event = storage::get_event(env, bounty_id).ok_or(Error::EventNotFound)?;
require_active_bounty(env, &event)?;
require_active_bounty(&event)?;

applicant.require_auth();
idempotency::require_unseen(env, &applicant, &op_id)?;
Expand All @@ -85,17 +85,12 @@ pub fn withdraw_application(
// ============================================================
// HELPERS
// ============================================================
fn require_active_bounty(env: &Env, event: &EventRecord) -> Result<(), Error> {
fn require_active_bounty(event: &EventRecord) -> Result<(), Error> {
if !matches!(event.pillar, Pillar::Bounty) {
return Err(Error::InvalidPillar);
}
if !matches!(event.status, EventStatus::Active) {
return Err(Error::EventNotActive);
}
if let Some(deadline) = event.deadline {
if deadline <= env.ledger().timestamp() {
return Err(Error::DeadlinePassed);
}
}
Ok(())
}
4 changes: 0 additions & 4 deletions contracts/events/src/crowdfunding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ pub fn validate_create(_env: &Env, record: &EventRecord, _owner: &Address) -> Re
_ => return Err(Error::InvalidReleaseKind),
}

if record.deadline.is_none() {
return Err(Error::DeadlineRequired);
}

if record.winner_distribution.len() != 1 {
return Err(Error::InvalidDistribution);
}
Expand Down
5 changes: 2 additions & 3 deletions contracts/events/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ pub enum Error {
InvalidReleaseKind = 33,
InvalidDistribution = 34,
InvalidBudget = 35,
DeadlineRequired = 36,
DeadlinePassed = 37,
DeadlineMustBeFuture = 38,
// 36-38 retired: deadline enforcement removed (submission windows are an
// off-chain/backend concern; the contract no longer gates on deadline).
TitleTooLong = 39,

ApplicantAlreadyApplied = 40,
Expand Down
16 changes: 0 additions & 16 deletions contracts/events/src/event_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ pub fn create_event(env: &Env, params: CreateEventParams, op_id: BytesN<32>) ->
return Err(Error::DistributionMismatch);
}

if let Some(deadline) = params.deadline {
if deadline <= env.ledger().timestamp() {
return Err(Error::DeadlineMustBeFuture);
}
}

if let Some(bps) = params.fee_bps_override {
if bps > MAX_FEE_BPS {
return Err(Error::InvalidFeeBps);
Expand Down Expand Up @@ -544,11 +538,6 @@ pub fn submit(
if matches!(event.pillar, Pillar::Crowdfunding) {
return Err(Error::InvalidPillar);
}
if let Some(deadline) = event.deadline {
if deadline <= env.ledger().timestamp() {
return Err(Error::DeadlinePassed);
}
}

applicant.require_auth();
idempotency::require_unseen(env, &applicant, &op_id)?;
Expand Down Expand Up @@ -612,11 +601,6 @@ pub fn withdraw_submission(
if !matches!(event.status, EventStatus::Active) {
return Err(Error::EventNotActive);
}
if let Some(deadline) = event.deadline {
if deadline <= env.ledger().timestamp() {
return Err(Error::DeadlinePassed);
}
}

applicant.require_auth();
idempotency::require_unseen(env, &applicant, &op_id)?;
Expand Down
3 changes: 0 additions & 3 deletions contracts/events/src/hackathon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ pub fn validate_create(_env: &Env, record: &EventRecord, _owner: &Address) -> Re
if !matches!(record.release_kind, ReleaseKind::Single) {
return Err(Error::InvalidReleaseKind);
}
if record.deadline.is_none() {
return Err(Error::DeadlineRequired);
}
Ok(())
}
18 changes: 0 additions & 18 deletions contracts/events/src/tests/bounty_pillar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,6 @@ fn apply_on_completed_event_reverts() {
assert_eq!(err, Error::EventNotActive);
}

#[test]
fn apply_after_deadline_reverts() {
let ctx = setup();
let deadline = ctx.env.ledger().timestamp() + 100;
let bounty_id = create_bounty_with_deadline(&ctx, deadline);

ctx.env.ledger().with_mut(|li| {
li.timestamp = deadline;
});

let op_id = BytesN::random(&ctx.env);
let err = expect_op_err(
ctx.events
.try_apply_to_bounty(&bounty_id, &ctx.applicant, &op_id),
);
assert_eq!(err, Error::DeadlinePassed);
}

#[test]
fn apply_when_paused_reverts() {
let ctx = setup();
Expand Down
21 changes: 0 additions & 21 deletions contracts/events/src/tests/crowdfunding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,6 @@ fn create_rejects_single_release_kind() {
assert!(res.is_err(), "single release must be rejected");
}

#[test]
fn create_rejects_missing_deadline() {
let ctx = setup();
let params = CreateEventParams {
pillar: Pillar::Crowdfunding,
owner: ctx.builder.clone(),
token: ctx.token_addr.clone(),
total_budget: FUNDING_GOAL,
release_kind: ReleaseKind::Multi(3),
content_uri: String::from_str(&ctx.env, "uri"),
title: String::from_str(&ctx.env, "Bad CF"),
deadline: None,
winner_distribution: single_dist_100_at_1(&ctx.env),
fee_bps_override: None,
manager: None,
};
let op = BytesN::random(&ctx.env);
let res = ctx.events.try_create_event(&params, &op);
assert!(res.is_err());
}

#[test]
fn create_rejects_distribution_with_multiple_positions() {
let ctx = setup();
Expand Down
57 changes: 0 additions & 57 deletions contracts/events/src/tests/hackathon_pillar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,48 +172,6 @@ fn create_rejects_multi_release_kind() {
assert!(res.is_err(), "hackathon must use Single release");
}

#[test]
fn create_rejects_missing_deadline() {
let ctx = setup();
let params = CreateEventParams {
pillar: Pillar::Hackathon,
owner: ctx.owner.clone(),
token: ctx.token_addr.clone(),
total_budget: TOTAL_BUDGET,
release_kind: ReleaseKind::Single,
content_uri: String::from_str(&ctx.env, "uri"),
title: String::from_str(&ctx.env, "Hackathon"),
deadline: None,
winner_distribution: single_winner_dist(&ctx.env),
fee_bps_override: None,
manager: None,
};
let op = BytesN::random(&ctx.env);
let res = ctx.events.try_create_event(&params, &op);
assert!(res.is_err(), "hackathon requires a submission deadline");
}

#[test]
fn create_rejects_past_deadline() {
let ctx = setup();
let params = CreateEventParams {
pillar: Pillar::Hackathon,
owner: ctx.owner.clone(),
token: ctx.token_addr.clone(),
total_budget: TOTAL_BUDGET,
release_kind: ReleaseKind::Single,
content_uri: String::from_str(&ctx.env, "uri"),
title: String::from_str(&ctx.env, "Hackathon"),
deadline: Some(ctx.env.ledger().timestamp()),
winner_distribution: single_winner_dist(&ctx.env),
fee_bps_override: None,
manager: None,
};
let op = BytesN::random(&ctx.env);
let res = ctx.events.try_create_event(&params, &op);
assert!(res.is_err(), "deadline must be in the future");
}

// ============================================================
// submit (open submission model)
// ============================================================
Expand Down Expand Up @@ -252,21 +210,6 @@ fn resubmit_keeps_original_timestamp_and_updates_uri() {
assert_eq!(second.submitted_at, first_time);
}

#[test]
fn submit_after_deadline_reverts() {
let ctx = setup();
let id = create_hackathon(&ctx);

ctx.env.ledger().with_mut(|li| {
li.timestamp += 2 * 86_400;
});

let uri = String::from_str(&ctx.env, "ipfs://Qm.../late.json");
let op = BytesN::random(&ctx.env);
let res = ctx.events.try_submit(&id, &ctx.applicant, &uri, &op);
assert!(res.is_err(), "submission after the deadline must revert");
}

#[test]
fn submit_replayed_op_reverts() {
let ctx = setup();
Expand Down
Loading