Skip to content

Commit

Permalink
Fix for HAL-04 issue.
Browse files Browse the repository at this point in the history
Now jobs after grace period cannot be submitted using submit_job
endpoint.
  • Loading branch information
kubaplas committed May 6, 2024
1 parent 96b5465 commit 4432b75
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dao/src/bid_escrow/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct ReclaimJobRequest {
pub struct SubmitJobProofRequest {
pub proof: DocumentHash,
pub caller: Address,
pub block_time: BlockTime,
}

/// Serializable representation of a `Job`.
Expand Down Expand Up @@ -229,6 +230,10 @@ impl Job {
revert(Error::OnlyWorkerCanSubmitProof);
}

if self.finish_time() + self.grace_period() < request.block_time {
revert(Error::JobProofSubmittedAfterGracePeriod);
}

self.job_proof = Some(request.proof);
self.status = JobStatus::Submitted;
}
Expand Down
1 change: 1 addition & 0 deletions dao/src/bid_escrow/job_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl JobEngine {
job.submit_proof(SubmitJobProofRequest {
proof,
caller: worker,
block_time: get_block_time(),
});

JobSubmitted::new(&job).emit();
Expand Down
1 change: 1 addition & 0 deletions dao/src/utils/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ execution_error! {
BidAlreadyPicked => 4038,
BidCanceled => 4039,
BidRejected => 4040,
JobProofSubmittedAfterGracePeriod => 4041,

// Reputation Token Errors.
CannotStakeTwice => 4500,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Pick a canceled bid
JobPoster cannot pick a bid that has already been cancelled.
This is a presentation of HAL-02 issue fix.
This is a presentation of HAL-02 issue fix.
Background:
Given accounts
| account | CSPR balance | REP balance | REP stake | is_kyced | is_va |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: Out of time submission
The internal worker submits the job proof several days after the deadline.
This is a presentation of HAL-04 issue fix.
Background:
Given following balances
| account | CSPR balance | REP balance | REP stake | is_kyced | is_va |
| BidEscrow | 1000 | 0 | 0 | false | false |
| MultisigWallet | 0 | 0 | 0 | false | false |
| JobPoster | 1000 | 0 | 0 | true | false |
| InternalWorker | 0 | 1000 | 0 | true | true |
| ExternalWorker | 500 | 0 | 0 | true | false |
| VA1 | 0 | 1000 | 0 | true | true |
| VA2 | 0 | 1000 | 0 | true | true |
And following configuration
| key | value |
| TimeBetweenInformalAndFormalVoting | 0 |
| VotingStartAfterJobSubmission | 0 |
When JobPoster posted a JobOffer with expected timeframe of 14 days, maximum budget of 1000 CSPR and 400 CSPR DOS Fee
And InternalWorker posted the Bid for JobOffer 0 with proposed timeframe of 7 days and 500 CSPR price and 100 REP stake
And 8 days passed
And ExternalWorker posted the Bid for JobOffer 0 with proposed timeframe of 7 days and 500 CSPR price and 100 CSPR stake with onboarding
And JobPoster picked the Bid of InternalWorker
And 130 days passed
Then InternalWorker fails to submit the JobProof of Job 0
10 changes: 10 additions & 0 deletions dao/tests/steps/bid_escrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,13 @@ fn cannot_submit_job_proof_second_time(w: &mut DaoWorld, worker: Account, job_id
fn bid_pick_failed(w: &mut DaoWorld, job_poster: Account, worker: Account) {
w.pick_bid_failed(job_poster, worker);
}

#[then(expr = "{account} fails submit the JobProof of outdated Job {int}")]
fn submit_outdated_job_proof(w: &mut DaoWorld, worker: Account, job_id: JobId) {
let worker = w.get_address(&worker);
test_env::set_caller(worker);
test_env::assert_exception(Error::JobProofSubmittedAfterGracePeriod, || {
w.bid_escrow
.submit_job_proof(job_id, DocumentHash::from("Job Proof"));
});
}

0 comments on commit 4432b75

Please sign in to comment.