From 4432b75ac8b1b4756eae1f0b522ed1d69768e613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Mon, 6 May 2024 15:07:50 +0200 Subject: [PATCH] Fix for HAL-04 issue. Now jobs after grace period cannot be submitted using submit_job endpoint. --- dao/src/bid_escrow/job.rs | 5 ++++ dao/src/bid_escrow/job_engine.rs | 1 + dao/src/utils/errors.rs | 1 + .../hal-02-pick_canceled_bid.feature | 2 +- ...l-04-submitting-job-after-deadline.feature | 24 +++++++++++++++++++ dao/tests/steps/bid_escrow.rs | 10 ++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 dao/tests/features/bid_escrow/hal-04-submitting-job-after-deadline.feature diff --git a/dao/src/bid_escrow/job.rs b/dao/src/bid_escrow/job.rs index b81cdb3a..e747ee95 100644 --- a/dao/src/bid_escrow/job.rs +++ b/dao/src/bid_escrow/job.rs @@ -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`. @@ -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; } diff --git a/dao/src/bid_escrow/job_engine.rs b/dao/src/bid_escrow/job_engine.rs index 6fccd98e..13ff5eb4 100644 --- a/dao/src/bid_escrow/job_engine.rs +++ b/dao/src/bid_escrow/job_engine.rs @@ -64,6 +64,7 @@ impl JobEngine { job.submit_proof(SubmitJobProofRequest { proof, caller: worker, + block_time: get_block_time(), }); JobSubmitted::new(&job).emit(); diff --git a/dao/src/utils/errors.rs b/dao/src/utils/errors.rs index bdd28332..9129b1e2 100644 --- a/dao/src/utils/errors.rs +++ b/dao/src/utils/errors.rs @@ -112,6 +112,7 @@ execution_error! { BidAlreadyPicked => 4038, BidCanceled => 4039, BidRejected => 4040, + JobProofSubmittedAfterGracePeriod => 4041, // Reputation Token Errors. CannotStakeTwice => 4500, diff --git a/dao/tests/features/bid_escrow/hal-02-pick_canceled_bid.feature b/dao/tests/features/bid_escrow/hal-02-pick_canceled_bid.feature index edefe85a..197ca6e4 100644 --- a/dao/tests/features/bid_escrow/hal-02-pick_canceled_bid.feature +++ b/dao/tests/features/bid_escrow/hal-02-pick_canceled_bid.feature @@ -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 | diff --git a/dao/tests/features/bid_escrow/hal-04-submitting-job-after-deadline.feature b/dao/tests/features/bid_escrow/hal-04-submitting-job-after-deadline.feature new file mode 100644 index 00000000..fbc5694b --- /dev/null +++ b/dao/tests/features/bid_escrow/hal-04-submitting-job-after-deadline.feature @@ -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 \ No newline at end of file diff --git a/dao/tests/steps/bid_escrow.rs b/dao/tests/steps/bid_escrow.rs index 3fd1511e..9e355e68 100644 --- a/dao/tests/steps/bid_escrow.rs +++ b/dao/tests/steps/bid_escrow.rs @@ -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")); + }); +}