Browse Source

update tests and renamed moderators

ignazio 3 years ago
parent
commit
7ae0761e7f

+ 9 - 8
runtime-modules/content/src/lib.rs

@@ -302,7 +302,7 @@ pub struct ChannelRecord<MemberId: Ord, CuratorGroupId, AccountId, Balance> {
     /// collaborator set
     collaborators: BTreeSet<MemberId>,
     /// moderator set
-    moderator_set: BTreeSet<MemberId>,
+    moderators: BTreeSet<MemberId>,
     /// Cumulative cashout
     cumulative_payout_earned: Balance,
 }
@@ -353,7 +353,7 @@ pub struct ChannelCreationParametersRecord<StorageAssets, AccountId, MemberId: O
     /// initial collaborator set
     collaborators: BTreeSet<MemberId>,
     /// initial moderator set
-    moderator_set: BTreeSet<MemberId>,
+    moderators: BTreeSet<MemberId>,
 }
 
 type ChannelCreationParameters<T> = ChannelCreationParametersRecord<
@@ -972,7 +972,8 @@ decl_module! {
             // next channel id
             let channel_id = NextChannelId::<T>::get();
 
-            // ensure collaborator member ids are valid
+            // ensure collaborator & moderator member ids are valid
+            Self::validate_member_set(&params.moderators)?;
             Self::validate_member_set(&params.collaborators)?;
 
             let upload_params = params.assets.as_ref().map(|assets| {
@@ -1039,7 +1040,7 @@ decl_module! {
                 is_censored: false,
                 reward_account: params.reward_account.clone(),
                 collaborators: params.collaborators.clone(),
-                moderator_set: params.moderator_set.clone(),
+                moderators: params.moderators.clone(),
                 cumulative_payout_earned: BalanceOf::<T>::zero(),
             };
 
@@ -1920,7 +1921,7 @@ decl_module! {
         fn update_moderator_set(
             origin,
             actor: ContentActor<T::CuratorGroupId, T::CuratorId, T::MemberId>,
-            new_moderator_set: BTreeSet<T::MemberId>,
+            new_moderators: BTreeSet<T::MemberId>,
             channel_id: T::ChannelId
         ) {
             // ensure (origin, actor) is channel owner
@@ -1933,18 +1934,18 @@ decl_module! {
                 &actor,
             )?;
 
-            Self::validate_member_set(&new_moderator_set)?;
+            Self::validate_member_set(&new_moderators)?;
 
             //
             // == MUTATION_SAFE ==
             //
 
-            <ChannelById<T>>::mutate(channel_id, |x| x.moderator_set = new_moderator_set.clone());
+            <ChannelById<T>>::mutate(channel_id, |x| x.moderators = new_moderators.clone());
 
             Self::deposit_event(
                 RawEvent::ModeratorSetUpdated(
                     channel_id,
-                    new_moderator_set
+                    new_moderators
                 ));
         }
 

+ 2 - 2
runtime-modules/content/src/permissions/mod.rs

@@ -356,8 +356,8 @@ pub fn ensure_actor_authorized_to_remove_comment<T: Trait>(
         .map(|_| CleanupActor::ChannelOwner);
     let actor_is_author =
         ensure_actor_is_comment_author::<T>(actor, &post.author).map(|_| CleanupActor::PostAuthor);
-    let actor_is_moderator = ensure_actor_is_moderator::<T>(actor, &channel.moderator_set)
-        .map(|_| CleanupActor::Moderator);
+    let actor_is_moderator =
+        ensure_actor_is_moderator::<T>(actor, &channel.moderators).map(|_| CleanupActor::Moderator);
 
     actor_is_author.or(actor_is_owner).or(actor_is_moderator)
 }

+ 14 - 2
runtime-modules/content/src/tests/channels.rs

@@ -21,7 +21,7 @@ fn channel_censoring() {
                 meta: None,
                 reward_account: None,
                 collaborators: BTreeSet::new(),
-                moderator_set: BTreeSet::new(),
+                moderators: BTreeSet::new(),
             }
         ));
 
@@ -99,7 +99,7 @@ fn channel_censoring() {
                 meta: None,
                 reward_account: None,
                 collaborators: BTreeSet::new(),
-                moderator_set: BTreeSet::new(),
+                moderators: BTreeSet::new(),
             }
         ));
 
@@ -1493,3 +1493,15 @@ fn unsuccessful_channel_deletion_with_invalid_bag_size() {
             .call_and_assert(Err(Error::<Test>::InvalidBagSizeSpecified.into()));
     })
 }
+
+#[test]
+fn unsuccessful_channel_creation_with_invalid_moderator_set() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+        CreateChannelFixture::default()
+            .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
+            .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
+            .with_moderators(vec![DEFAULT_MODERATOR_ID + 100].into_iter().collect())
+            .call_and_assert(Err(Error::<Test>::InvalidMemberProvided.into()));
+    })
+}

+ 12 - 12
runtime-modules/content/src/tests/fixtures.rs

@@ -23,7 +23,7 @@ impl CreateChannelFixture {
                 meta: None,
                 reward_account: None,
                 collaborators: BTreeSet::new(),
-                moderator_set: BTreeSet::new(),
+                moderators: BTreeSet::new(),
             },
         }
     }
@@ -56,10 +56,10 @@ impl CreateChannelFixture {
         }
     }
 
-    pub fn with_moderators(self, moderator_set: BTreeSet<MemberId>) -> Self {
+    pub fn with_moderators(self, moderators: BTreeSet<MemberId>) -> Self {
         Self {
             params: ChannelCreationParameters::<Test> {
-                moderator_set: moderator_set,
+                moderators,
                 ..self.params
             },
             ..self
@@ -115,7 +115,7 @@ impl CreateChannelFixture {
                         is_censored: false,
                         reward_account: self.params.reward_account.clone(),
                         collaborators: self.params.collaborators.clone(),
-                        moderator_set: self.params.moderator_set.clone(),
+                        moderators: self.params.moderators.clone(),
                         num_videos: Zero::zero(),
                         cumulative_payout_earned: Zero::zero(),
                     },
@@ -418,7 +418,7 @@ impl UpdateChannelFixture {
                                 .clone()
                                 .unwrap_or(channel_pre.collaborators),
                             num_videos: channel_pre.num_videos,
-                            moderator_set: channel_pre.moderator_set,
+                            moderators: channel_pre.moderators,
                             cumulative_payout_earned: BalanceOf::<Test>::zero(),
                         },
                         self.params.clone(),
@@ -1077,7 +1077,7 @@ impl DeleteVideoFixture {
 pub struct UpdateModeratorSetFixture {
     sender: AccountId,
     actor: ContentActor<CuratorGroupId, CuratorId, MemberId>,
-    new_moderator_set: BTreeSet<MemberId>,
+    new_moderators: BTreeSet<MemberId>,
     channel_id: ChannelId,
 }
 
@@ -1086,7 +1086,7 @@ impl UpdateModeratorSetFixture {
         Self {
             sender: DEFAULT_MEMBER_ACCOUNT_ID,
             actor: ContentActor::Member(DEFAULT_MEMBER_ID),
-            new_moderator_set: BTreeSet::new(),
+            new_moderators: BTreeSet::new(),
             channel_id: ChannelId::one(),
         }
     }
@@ -1099,9 +1099,9 @@ impl UpdateModeratorSetFixture {
         Self { actor, ..self }
     }
 
-    pub fn with_moderators(self, new_moderator_set: BTreeSet<MemberId>) -> Self {
+    pub fn with_moderators(self, new_moderators: BTreeSet<MemberId>) -> Self {
         Self {
-            new_moderator_set,
+            new_moderators,
             ..self
         }
     }
@@ -1117,7 +1117,7 @@ impl UpdateModeratorSetFixture {
         let actual_result = Content::update_moderator_set(
             origin,
             self.actor.clone(),
-            self.new_moderator_set.clone(),
+            self.new_moderators.clone(),
             self.channel_id.clone(),
         );
 
@@ -1130,10 +1130,10 @@ impl UpdateModeratorSetFixture {
                 System::events().last().unwrap().event,
                 MetaEvent::content(RawEvent::ModeratorSetUpdated(
                     self.channel_id,
-                    self.new_moderator_set.clone(),
+                    self.new_moderators.clone(),
                 ))
             );
-            assert_eq!(channel_post.moderator_set, self.new_moderator_set);
+            assert_eq!(channel_post.moderators, self.new_moderators);
         } else {
             assert_eq!(channel_pre, channel_post);
         }

+ 1 - 1
runtime-modules/content/src/tests/migration.rs

@@ -33,7 +33,7 @@ fn assert_video_and_channel_existrinsics_with(result: DispatchResult) {
                 meta: Some(vec![]),
                 reward_account: None,
                 collaborators: BTreeSet::new(),
-                moderator_set: BTreeSet::new(),
+                moderators: BTreeSet::new(),
             },
         ),
         result

+ 1 - 0
runtime-modules/content/src/tests/mock.rs

@@ -209,6 +209,7 @@ impl ContentActorAuthenticator for Test {
             DEFAULT_MEMBER_ID => true,
             UNAUTHORIZED_MEMBER_ID => true,
             COLLABORATOR_MEMBER_ID => true,
+            DEFAULT_MODERATOR_ID => true,
             UNAUTHORIZED_COLLABORATOR_MEMBER_ID => true,
             _ => false,
         }