Browse Source

Merge branch 'olympia' into giza-olympia-post-merge

Leszek Wiesner 3 years ago
parent
commit
d01abfc8c1

+ 26 - 11
runtime-modules/bounty/src/benchmarking.rs

@@ -673,6 +673,7 @@ benchmarks! {
         let funding_amount: BalanceOf<T> = 10000000u32.into();
         let oracle = BountyActor::Council;
         let entrant_stake: BalanceOf<T> = T::MinWorkEntrantStake::get();
+        let rationale = b"text".to_vec();
 
         let params = BountyCreationParameters::<T> {
             work_period,
@@ -709,7 +710,12 @@ benchmarks! {
 
         run_to_block::<T>((work_period + One::one()).into());
 
-    }: submit_oracle_judgment(RawOrigin::Root, oracle.clone(), bounty_id, judgment.clone())
+    }: submit_oracle_judgment(
+        RawOrigin::Root,
+        oracle.clone(),
+        bounty_id,
+        judgment.clone(),
+        rationale.clone())
     verify {
         for entry_id in entry_ids {
             let entry = Bounty::<T>::entries(entry_id);
@@ -724,7 +730,7 @@ benchmarks! {
             );
         }
         assert_last_event::<T>(
-            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment).into()
+            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment, rationale).into()
         );
     }
 
@@ -736,6 +742,7 @@ benchmarks! {
         let funding_amount: BalanceOf<T> = 100u32.into();
         let oracle = BountyActor::Council;
         let entrant_stake: BalanceOf<T> = T::MinWorkEntrantStake::get();
+        let rationale = b"text".to_vec();
 
         let params = BountyCreationParameters::<T> {
             work_period,
@@ -761,13 +768,18 @@ benchmarks! {
 
         run_to_block::<T>((work_period + One::one()).into());
 
-    }: submit_oracle_judgment(RawOrigin::Root, oracle.clone(), bounty_id, judgment.clone())
+    }: submit_oracle_judgment(
+        RawOrigin::Root,
+        oracle.clone(),
+        bounty_id,
+        judgment.clone(),
+        rationale.clone())
     verify {
         for entry_id in entry_ids {
             assert!(!<Entries<T>>::contains_key(entry_id));
         }
         assert_last_event::<T>(
-            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment).into()
+            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment, rationale).into()
         );
     }
 
@@ -781,6 +793,7 @@ benchmarks! {
         let (oracle_account_id, oracle_member_id) = member_funded_account::<T>("oracle", 1);
         let oracle = BountyActor::Member(oracle_member_id);
         let entrant_stake: BalanceOf<T> = T::MinWorkEntrantStake::get();
+        let rationale = b"text".to_vec();
 
         let params = BountyCreationParameters::<T> {
             work_period,
@@ -821,8 +834,8 @@ benchmarks! {
         RawOrigin::Signed(oracle_account_id),
         oracle.clone(),
         bounty_id,
-        judgment.clone()
-    )
+        judgment.clone(),
+        rationale.clone())
     verify {
         for entry_id in entry_ids {
             let entry = Bounty::<T>::entries(entry_id);
@@ -837,7 +850,7 @@ benchmarks! {
             );
         }
         assert_last_event::<T>(
-            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment).into()
+            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment, rationale).into()
         );
     }
 
@@ -851,6 +864,7 @@ benchmarks! {
         let (oracle_account_id, oracle_member_id) = member_funded_account::<T>("oracle", 1);
         let oracle = BountyActor::Member(oracle_member_id);
         let entrant_stake: BalanceOf<T> = T::MinWorkEntrantStake::get();
+        let rationale = b"text".to_vec();
 
         let params = BountyCreationParameters::<T> {
             work_period,
@@ -880,14 +894,14 @@ benchmarks! {
         RawOrigin::Signed(oracle_account_id),
         oracle.clone(),
         bounty_id,
-        judgment.clone()
-    )
+        judgment.clone(),
+        rationale.clone())
     verify {
         for entry_id in entry_ids {
             assert!(!<Entries<T>>::contains_key(entry_id));
         }
         assert_last_event::<T>(
-            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment).into()
+            Event::<T>::OracleJudgmentSubmitted(bounty_id, oracle, judgment, rationale).into()
         );
     }
 
@@ -947,7 +961,8 @@ benchmarks! {
             RawOrigin::Signed(oracle_account_id).into(),
             oracle.clone(),
             bounty_id,
-            judgment.clone()
+            judgment.clone(),
+            Vec::new(),
         ).unwrap();
 
     }: _ (RawOrigin::Signed(work_account_id), work_member_id, bounty_id, entry_id)

+ 10 - 3
runtime-modules/bounty/src/lib.rs

@@ -571,7 +571,8 @@ decl_event! {
         /// - bounty ID
         /// - oracle
         /// - judgment data
-        OracleJudgmentSubmitted(BountyId, BountyActor<MemberId>, OracleJudgment),
+        /// - rationale
+        OracleJudgmentSubmitted(BountyId, BountyActor<MemberId>, OracleJudgment, Vec<u8>),
 
         /// Work entry was slashed.
         /// Params:
@@ -1123,7 +1124,8 @@ decl_module! {
             origin,
             oracle: BountyActor<MemberId<T>>,
             bounty_id: T::BountyId,
-            judgment: OracleJudgment<T::EntryId, BalanceOf<T>>
+            judgment: OracleJudgment<T::EntryId, BalanceOf<T>>,
+            rationale: Vec<u8>,
         ) {
             let bounty_oracle_manager = BountyActorManager::<T>::ensure_bounty_actor_manager(
                 origin,
@@ -1180,7 +1182,12 @@ decl_module! {
             }
 
             // Fire a judgment event.
-            Self::deposit_event(RawEvent::OracleJudgmentSubmitted(bounty_id, oracle, judgment));
+            Self::deposit_event(RawEvent::OracleJudgmentSubmitted(
+                bounty_id,
+                oracle,
+                judgment,
+                rationale,
+            ));
         }
 
         /// Withdraw work entrant funds.

+ 7 - 0
runtime-modules/bounty/src/tests/fixtures.rs

@@ -700,6 +700,7 @@ pub struct SubmitJudgmentFixture {
     bounty_id: u64,
     oracle: BountyActor<u64>,
     judgment: OracleJudgmentOf<Test>,
+    rationale: Vec<u8>,
 }
 
 impl SubmitJudgmentFixture {
@@ -709,6 +710,7 @@ impl SubmitJudgmentFixture {
             bounty_id: 1,
             oracle: BountyActor::Council,
             judgment: Default::default(),
+            rationale: Default::default(),
         }
     }
 
@@ -731,6 +733,10 @@ impl SubmitJudgmentFixture {
         Self { judgment, ..self }
     }
 
+    pub fn with_rationale(self, rationale: Vec<u8>) -> Self {
+        Self { rationale, ..self }
+    }
+
     pub fn call_and_assert(&self, expected_result: DispatchResult) {
         let old_bounty = Bounty::bounties(self.bounty_id);
         let actual_result = Bounty::submit_oracle_judgment(
@@ -738,6 +744,7 @@ impl SubmitJudgmentFixture {
             self.oracle.clone(),
             self.bounty_id,
             self.judgment.clone(),
+            self.rationale.clone(),
         );
 
         assert_eq!(actual_result, expected_result);

+ 6 - 0
runtime-modules/bounty/src/tests/mod.rs

@@ -2453,6 +2453,7 @@ fn submit_judgment_by_council_succeeded_with_complex_judgment() {
         let entrant_stake = 37;
         let working_period = 10;
         let judging_period = 10;
+        let rationale = b"text".to_vec();
 
         set_council_budget(initial_balance);
 
@@ -2560,6 +2561,7 @@ fn submit_judgment_by_council_succeeded_with_complex_judgment() {
         SubmitJudgmentFixture::default()
             .with_bounty_id(bounty_id)
             .with_judgment(judgment.clone())
+            .with_rationale(rationale.clone())
             .call_and_assert(Ok(()));
 
         assert_eq!(
@@ -2578,6 +2580,7 @@ fn submit_judgment_by_council_succeeded_with_complex_judgment() {
             bounty_id,
             BountyActor::Council,
             judgment,
+            rationale,
         ));
     });
 }
@@ -2760,6 +2763,7 @@ fn submit_judgment_by_member_succeeded() {
         let judging_period = 10;
         let oracle_member_id = 1;
         let oracle_account_id = 1;
+        let rationale = b"text".to_vec();
 
         set_council_budget(initial_balance);
 
@@ -2818,12 +2822,14 @@ fn submit_judgment_by_member_succeeded() {
             .with_origin(RawOrigin::Signed(oracle_account_id))
             .with_oracle_member_id(oracle_member_id)
             .with_judgment(judgment.clone())
+            .with_rationale(rationale.clone())
             .call_and_assert(Ok(()));
 
         EventFixture::assert_last_crate_event(RawEvent::OracleJudgmentSubmitted(
             bounty_id,
             BountyActor::Member(oracle_member_id),
             judgment,
+            rationale,
         ));
     });
 }

+ 8 - 2
runtime-modules/forum/src/benchmarking.rs

@@ -1152,7 +1152,10 @@ benchmarks! {
         assert_eq!(Module::<T>::category_by_id(new_category_id), new_category);
 
         assert!(!<ThreadById<T>>::contains_key(category_id, thread_id));
-        assert_eq!(Module::<T>::thread_by_id(new_category_id, thread_id), thread);
+        assert_eq!(
+            Module::<T>::thread_by_id(new_category_id, thread_id),
+            Thread { category_id: new_category_id, ..thread}
+        );
 
         assert_last_event::<T>(
             RawEvent::ThreadMoved(
@@ -1226,7 +1229,10 @@ benchmarks! {
         assert_eq!(Module::<T>::category_by_id(new_category_id), new_category);
 
         assert!(!<ThreadById<T>>::contains_key(category_id, thread_id));
-        assert_eq!(Module::<T>::thread_by_id(new_category_id, thread_id), thread);
+        assert_eq!(
+            Module::<T>::thread_by_id(new_category_id, thread_id),
+            Thread { category_id: new_category_id, ..thread}
+        );
 
         assert_last_event::<T>(
             RawEvent::ThreadMoved(

+ 13 - 2
runtime-modules/forum/src/lib.rs

@@ -1102,7 +1102,13 @@ decl_module! {
         ).max(WeightInfoForum::<T>::move_thread_to_category_moderator(
             T::MaxCategoryDepth::get() as u32,
         ))]
-        fn move_thread_to_category(origin, actor: PrivilegedActor<T>, category_id: T::CategoryId, thread_id: T::ThreadId, new_category_id: T::CategoryId) -> DispatchResult {
+        fn move_thread_to_category(
+            origin,
+            actor: PrivilegedActor<T>,
+            category_id: T::CategoryId,
+            thread_id: T::ThreadId,
+            new_category_id: T::CategoryId
+        ) -> DispatchResult {
             // Ensure data migration is done
             Self::ensure_data_migration_done()?;
 
@@ -1115,8 +1121,13 @@ decl_module! {
             // == MUTATION SAFE ==
             //
 
+            let updated_thread = Thread {
+                category_id: new_category_id,
+                ..thread
+            };
+
             <ThreadById<T>>::remove(thread.category_id, thread_id);
-            <ThreadById<T>>::insert(new_category_id, thread_id, thread.clone());
+            <ThreadById<T>>::insert(new_category_id, thread_id, updated_thread);
             <CategoryById<T>>::mutate(thread.category_id, |category| category.num_direct_threads -= 1);
             <CategoryById<T>>::mutate(new_category_id, |category| category.num_direct_threads += 1);
 

+ 120 - 0
runtime-modules/forum/src/tests.rs

@@ -1350,6 +1350,126 @@ fn move_thread_moderator_permissions() {
     });
 }
 
+#[test]
+fn category_updated_successfully_on_thread_moving() {
+    let moderator = FORUM_MODERATOR_ORIGIN_ID;
+    let moderator_origin = FORUM_MODERATOR_ORIGIN;
+
+    let forum_lead = FORUM_LEAD_ORIGIN_ID;
+    let origin = OriginType::Signed(forum_lead);
+    let initial_balance = 10_000_000;
+    with_test_externalities(|| {
+        balances::Module::<Runtime>::make_free_balance_be(&forum_lead, initial_balance);
+
+        let category_id_1 = create_category_mock(
+            origin.clone(),
+            None,
+            good_category_title(),
+            good_category_description(),
+            Ok(()),
+        );
+        let category_id_2 = create_category_mock(
+            origin.clone(),
+            None,
+            good_category_title(),
+            good_category_description(),
+            Ok(()),
+        );
+
+        // sanity check
+        assert_ne!(category_id_1, category_id_2);
+
+        let thread_id = create_thread_mock(
+            origin.clone(),
+            forum_lead,
+            forum_lead,
+            category_id_1,
+            good_thread_metadata(),
+            good_thread_text(),
+            None,
+            Ok(()),
+        );
+
+        // set incomplete permissions for first user (only category 1)
+        update_category_membership_of_moderator_mock(
+            moderator_origin.clone(),
+            moderator,
+            category_id_1,
+            true,
+            Ok(()),
+        );
+
+        // give the rest of necessary permissions to the first moderator
+        update_category_membership_of_moderator_mock(
+            moderator_origin.clone(),
+            moderator,
+            category_id_2,
+            true,
+            Ok(()),
+        );
+
+        // check counters of threads in category
+        assert_eq!(
+            <CategoryById<Runtime>>::get(category_id_1).num_direct_threads,
+            1,
+        );
+        assert_eq!(
+            <CategoryById<Runtime>>::get(category_id_2).num_direct_threads,
+            0,
+        );
+
+        // move in one direction
+        move_thread_mock(
+            moderator_origin.clone(),
+            moderator,
+            category_id_1,
+            thread_id,
+            category_id_2,
+            Ok(()),
+        );
+
+        assert_eq!(
+            TestForumModule::thread_by_id(category_id_2, thread_id).category_id,
+            category_id_2
+        );
+
+        // check counters of threads in category
+        assert_eq!(
+            <CategoryById<Runtime>>::get(category_id_1).num_direct_threads,
+            0,
+        );
+        assert_eq!(
+            <CategoryById<Runtime>>::get(category_id_2).num_direct_threads,
+            1,
+        );
+
+        // move in opposite direction
+        move_thread_mock(
+            moderator_origin.clone(),
+            moderator,
+            category_id_2,
+            thread_id,
+            category_id_1,
+            Ok(()),
+        );
+
+        // check counters of threads in category
+        assert_eq!(
+            <CategoryById<Runtime>>::get(category_id_1).num_direct_threads,
+            1,
+        );
+        assert_eq!(
+            <CategoryById<Runtime>>::get(category_id_2).num_direct_threads,
+            0,
+        );
+
+        assert_eq!(
+            TestForumModule::thread_by_id(category_id_1, thread_id).category_id,
+            category_id_1
+        );
+    });
+}
+
 #[test]
 // test if error is thrown when origin and destination category is the same
 fn move_thread_invalid_move() {