Переглянути джерело

Merge pull request #3279 from shamil-gadelshin/olympia-create-thread-check

Olympia. Runtime: fix create_thread bug - check the category existence.
Mokhtar Naamani 3 роки тому
батько
коміт
8bb0a84bc8
2 змінених файлів з 28 додано та 0 видалено
  1. 2 0
      runtime-modules/forum/src/lib.rs
  2. 26 0
      runtime-modules/forum/src/tests.rs

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

@@ -2219,6 +2219,8 @@ impl<T: Trait> Module<T> {
         // Check that account is forum member
         Self::ensure_is_forum_user(account_id, &forum_user_id)?;
 
+        Self::ensure_category_exists(category_id)?;
+
         let category = Self::ensure_category_is_mutable(category_id)?;
 
         // The balance for creation of thread is the base cost plus the cost of a single post

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

@@ -1049,6 +1049,32 @@ fn edit_thread_metadata() {
     });
 }
 
+#[test]
+fn create_thread_fails_on_non_existing_category() {
+    let forum_lead = FORUM_LEAD_ORIGIN_ID;
+    let initial_balance = 10_000_000;
+
+    with_test_externalities(|| {
+        balances::Module::<Runtime>::make_free_balance_be(&forum_lead, initial_balance);
+
+        assert_eq!(
+            balances::Module::<Runtime>::free_balance(&forum_lead),
+            initial_balance
+        );
+        let invalid_category_id = 100;
+        create_thread_mock(
+            FORUM_LEAD_ORIGIN,
+            FORUM_LEAD_ORIGIN_ID,
+            FORUM_LEAD_ORIGIN_ID,
+            invalid_category_id,
+            good_thread_metadata(),
+            good_thread_text(),
+            None,
+            Err(Error::<Runtime>::CategoryDoesNotExist.into()),
+        );
+    });
+}
+
 /*
  ** update_category
  */