From b8397eda2143c66b566511fd364d5abbb8682cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Tue, 21 May 2024 11:17:34 +0200 Subject: [PATCH 1/3] Fix for HAL-06 - removed unnecessary code. --- dao/src/voting_contracts/simple_voter.rs | 15 +---------- resources/simple_voter_contract_schema.json | 30 ++++++++++----------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/dao/src/voting_contracts/simple_voter.rs b/dao/src/voting_contracts/simple_voter.rs index 715310e0..0b1f0d50 100644 --- a/dao/src/voting_contracts/simple_voter.rs +++ b/dao/src/voting_contracts/simple_voter.rs @@ -51,6 +51,7 @@ impl SimpleVoterContract { ) -> Option; pub fn get_voter(&self, voting_id: VotingId, voting_type: VotingType, at: u32) -> Option
; pub fn cancel_finished_voting(&mut self, voting_id: VotingId); + pub fn finish_voting(&mut self, voting_id: VotingId, voting_type: VotingType) -> VotingSummary; } to self.access_control { @@ -98,20 +99,6 @@ impl SimpleVoterContract { SimpleVotingCreated::new(document_hash, info).emit(); } - pub fn finish_voting(&mut self, voting_id: VotingId, voting_type: VotingType) -> VotingSummary { - let voting_summary = self.voting_engine.finish_voting(voting_id, voting_type); - - if let VotingType::Formal = voting_summary.voting_type() { - self.simple_votings.set( - &voting_id, - self.simple_votings - .get(&voting_id) - .unwrap_or_revert_with(Error::VariableValueNotSet), - ); - } - voting_summary - } - pub fn get_document_hash(&self, voting_id: VotingId) -> Option { self.simple_votings.get(&voting_id) } diff --git a/resources/simple_voter_contract_schema.json b/resources/simple_voter_contract_schema.json index d2e0688d..73239fad 100644 --- a/resources/simple_voter_contract_schema.json +++ b/resources/simple_voter_contract_schema.json @@ -35,21 +35,6 @@ ], "return_ty": "Unit" }, - { - "name": "finish_voting", - "is_mutable": true, - "args": [ - { - "name": "voting_id", - "ty": "U32" - }, - { - "name": "voting_type", - "ty": "U32" - } - ], - "return_ty": "Any" - }, { "name": "get_document_hash", "is_mutable": false, @@ -178,6 +163,21 @@ ], "return_ty": "Unit" }, + { + "name": "finish_voting", + "is_mutable": true, + "args": [ + { + "name": "voting_id", + "ty": "U32" + }, + { + "name": "voting_type", + "ty": "U32" + } + ], + "return_ty": "Any" + }, { "name": "propose_new_owner", "is_mutable": true, From 1525a4e7fab77670ed8b3b7e13c7e1103f3a8263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Tue, 21 May 2024 11:50:15 +0200 Subject: [PATCH 2/3] Fix for HAL-04. Now it is impossible to submit job proof when Grace period has started. --- dao/src/bid_escrow/job.rs | 4 ++-- dao/src/utils/errors.rs | 2 +- dao/tests/steps/bid_escrow.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dao/src/bid_escrow/job.rs b/dao/src/bid_escrow/job.rs index c810773d..01576968 100644 --- a/dao/src/bid_escrow/job.rs +++ b/dao/src/bid_escrow/job.rs @@ -226,8 +226,8 @@ impl Job { revert(Error::OnlyWorkerCanSubmitProof); } - if self.finish_time() + self.grace_period() < request.block_time { - revert(Error::JobProofSubmittedAfterGracePeriod); + if self.finish_time() < request.block_time { + revert(Error::JobProofSubmittedAfterFinishTime); } self.job_proof = Some(request.proof); diff --git a/dao/src/utils/errors.rs b/dao/src/utils/errors.rs index 31aa0f80..0778673e 100644 --- a/dao/src/utils/errors.rs +++ b/dao/src/utils/errors.rs @@ -114,7 +114,7 @@ execution_error! { BidAlreadyPicked => 4038, BidCanceled => 4039, BidRejected => 4040, - JobProofSubmittedAfterGracePeriod => 4041, + JobProofSubmittedAfterFinishTime => 4041, // Reputation Token Errors. CannotStakeTwice => 4500, diff --git a/dao/tests/steps/bid_escrow.rs b/dao/tests/steps/bid_escrow.rs index 9e355e68..bbc3de02 100644 --- a/dao/tests/steps/bid_escrow.rs +++ b/dao/tests/steps/bid_escrow.rs @@ -268,7 +268,7 @@ fn bid_pick_failed(w: &mut DaoWorld, job_poster: Account, worker: Account) { 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, || { + test_env::assert_exception(Error::JobProofSubmittedAfterFinishTime, || { w.bid_escrow .submit_job_proof(job_id, DocumentHash::from("Job Proof")); }); From 37e0b4c9e360e63f1308f3f22c544f95154e694a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Tue, 21 May 2024 13:47:05 +0200 Subject: [PATCH 3/3] Fix lints. --- dao/src/voting_contracts/simple_voter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dao/src/voting_contracts/simple_voter.rs b/dao/src/voting_contracts/simple_voter.rs index 0b1f0d50..ed7bd0e1 100644 --- a/dao/src/voting_contracts/simple_voter.rs +++ b/dao/src/voting_contracts/simple_voter.rs @@ -1,14 +1,14 @@ use odra::{ contract_env::caller, types::{event::OdraEvent, Address, Balance, BlockTime}, - Event, Mapping, UnwrapOrRevert, + Event, Mapping, }; use crate::voting_contracts::SlashedVotings; use crate::{ configuration::ConfigurationBuilder, modules::{refs::ContractRefs, AccessControl}, - utils::{types::DocumentHash, Error}, + utils::types::DocumentHash, voting::{ ballot::{Ballot, Choice}, types::VotingId,