Skip to content
Open
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
1 change: 1 addition & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ portable history of paid work.
| 3 | `NotOpen` | the bounty is already paid or refunded |
| 4 | `NotAssigned` | `release` called before `assign` |
| 5 | `AlreadyFunded` | the issue already has an open bounty |
| 6 | `SelfAssign` | `assign` targets the funding maintainer |

## Build and test

Expand Down
4 changes: 4 additions & 0 deletions contracts/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub enum Error {
NotOpen = 3,
NotAssigned = 4,
AlreadyFunded = 5,
SelfAssign = 6,
}

#[contracttype]
Expand Down Expand Up @@ -175,6 +176,9 @@ impl Escrow {
pub fn assign(env: Env, id: u64, assignee: Option<Address>) -> Result<(), Error> {
let mut bounty = Self::open_bounty(&env, id)?;
bounty.maintainer.require_auth();
if assignee.as_ref() == Some(&bounty.maintainer) {
return Err(Error::SelfAssign);
}
bounty.assignee = assignee.clone();
Self::save(&env, id, &bounty);
Assigned { id, assignee }.publish(&env);
Expand Down
22 changes: 22 additions & 0 deletions contracts/escrow/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ fn release_requires_an_assignee() {
assert_eq!(s.escrow.try_release(&id, &pr), Err(Ok(Error::NotAssigned)));
}

#[test]
fn maintainer_cannot_assign_bounty_to_themselves() {
let s = setup();
let id = s.escrow.fund(&s.maintainer, &s.repo, &842, &900);

assert_eq!(
s.escrow.try_assign(&id, &Some(s.maintainer.clone())),
Err(Ok(Error::SelfAssign))
);
assert_eq!(s.escrow.get(&id).assignee, None);
}

#[test]
fn maintainer_can_clear_an_assignee() {
let s = setup();
let id = s.escrow.fund(&s.maintainer, &s.repo, &842, &900);
s.escrow.assign(&id, &Some(s.contributor.clone()));
s.escrow.assign(&id, &None);

assert_eq!(s.escrow.get(&id).assignee, None);
}

#[test]
fn closed_bounties_cannot_be_paid_twice() {
let s = setup();
Expand Down
Loading