Преглед на файлове

Modify update_role_account extrinsic in the workin group module.

Shamil Gadelshin преди 4 години
родител
ревизия
3699dac0d4
променени са 2 файла, в които са добавени 47 реда и са изтрити 5 реда
  1. 17 4
      runtime-modules/working-group/src/lib.rs
  2. 30 1
      runtime-modules/working-group/src/tests/mod.rs

+ 17 - 4
runtime-modules/working-group/src/lib.rs

@@ -16,7 +16,7 @@
 //! - [begin_applicant_review](./struct.Module.html#method.begin_applicant_review) - Begin reviewing worker/lead applications.
 //! - [fill_opening](./struct.Module.html#method.fill_opening) - Fill opening for worker/lead.
 //! - [withdraw_application](./struct.Module.html#method.withdraw_application) - Withdraw the worker/lead application.
-//! - [terminate_application](./struct.Module.html#method.terminate_application) - Terminate the worker/lead application.
+//! - [terminate_application](./struct.Module.html#method.terminate_application) - Terminate the worker application.
 //! - [apply_on_opening](./struct.Module.html#method.apply_on_opening) - Apply on a worker/lead opening.
 //!
 //! ### Roles lifecycle
@@ -41,9 +41,10 @@
 // Do not delete! Cannot be uncommented by default, because of Parity decl_module! issue.
 //#![warn(missing_docs)]
 
-// TODO: leave role - unset lead on success when the leader is leaving.
-// TODO: check all that a leader can set only its own parameters as a worker.
-// TODO: coments
+// TODO: slash_stake for a leader
+// TODO: decrease_stake for a leader
+// TODO: increase_stake for a leader
+// TODO: comments
 
 #[cfg(test)]
 mod tests;
@@ -370,6 +371,18 @@ decl_module! {
                 worker.role_account = new_role_account_id.clone()
             });
 
+            // Update lead data if it is necessary.
+            let lead = <CurrentLead::<T, I>>::get();
+            if let Some(lead) = lead {
+                if lead.worker_id == worker_id {
+                    let new_lead = Lead{
+                        role_account_id: new_role_account_id.clone(),
+                        ..lead
+                    };
+                    <CurrentLead::<T, I>>::put(new_lead);
+                }
+            }
+
             // Trigger event
             Self::deposit_event(RawEvent::WorkerRoleAccountUpdated(worker_id, new_role_account_id));
         }

+ 30 - 1
runtime-modules/working-group/src/tests/mod.rs

@@ -3,7 +3,7 @@ mod hiring_workflow;
 mod mock;
 
 use crate::types::{OpeningPolicyCommitment, OpeningType, RewardPolicy};
-use crate::{Error, RawEvent};
+use crate::{Error, Lead, RawEvent};
 use common::constraints::InputValidationLengthConstraint;
 use mock::{
     build_test_externalities, Test, TestWorkingGroup, TestWorkingGroupInstance,
@@ -874,6 +874,35 @@ fn update_worker_role_account_succeeds() {
     });
 }
 
+#[test]
+fn update_worker_role_account_by_leader_succeeds() {
+    build_test_externalities().execute_with(|| {
+        let new_account_id = 10;
+        let worker_id = HireLeadFixture::default().hire_lead();
+
+        // Default ids.
+        let mut lead = Lead {
+            member_id: 1,
+            role_account_id: 1,
+            worker_id: 0,
+        };
+
+        assert_eq!(TestWorkingGroup::current_lead(), Some(lead));
+
+        let update_worker_account_fixture =
+            UpdateWorkerRoleAccountFixture::default_with_ids(worker_id, new_account_id);
+
+        update_worker_account_fixture.call_and_assert(Ok(()));
+
+        lead = Lead {
+            role_account_id: new_account_id,
+            ..lead
+        };
+
+        assert_eq!(TestWorkingGroup::current_lead(), Some(lead));
+    });
+}
+
 #[test]
 fn update_worker_role_account_fails_with_invalid_origin() {
     build_test_externalities().execute_with(|| {