Browse Source

Ok(()) into is_ok()

ignazio 3 years ago
parent
commit
ebd7802921
1 changed files with 53 additions and 55 deletions
  1. 53 55
      runtime-modules/content/src/tests/fixtures.rs

+ 53 - 55
runtime-modules/content/src/tests/fixtures.rs

@@ -90,67 +90,65 @@ impl CreateChannelFixture {
 
         let balance_post = Balances::usable_balance(self.sender);
 
-        match actual_result {
-            Ok(()) => {
-                // ensure channel is on chain
-                assert_ok!(Content::ensure_channel_exists(&channel_id));
-
-                // channel counter increased
-                assert_eq!(
-                    Content::next_channel_id(),
-                    channel_id.saturating_add(One::one())
-                );
-
-                // dynamic bag for channel is created
-                assert_ok!(Storage::<Test>::ensure_bag_exists(&channel_bag_id));
-
-                // event correctly deposited
-                let owner = Content::actor_to_channel_owner(&self.actor).unwrap();
-                assert_eq!(
-                    System::events().last().unwrap().event,
-                    MetaEvent::content(RawEvent::ChannelCreated(
-                        self.actor.clone(),
-                        channel_id,
-                        ChannelRecord {
-                            owner: owner,
-                            is_censored: false,
-                            reward_account: self.params.reward_account.clone(),
-                            collaborators: self.params.collaborators.clone(),
-                            num_videos: Zero::zero(),
-                        },
-                        self.params.clone(),
-                    ))
-                );
-
-                if let Some(assets) = self.params.assets.as_ref() {
-                    // balance accounting is correct
-                    let bag_deletion_prize = BalanceOf::<Test>::zero();
-                    let objects_deletion_prize = assets.object_creation_list.iter().fold(
-                        BalanceOf::<Test>::zero(),
-                        |acc, _| {
+        if actual_result.is_ok() {
+            // ensure channel is on chain
+            assert_ok!(Content::ensure_channel_exists(&channel_id));
+
+            // channel counter increased
+            assert_eq!(
+                Content::next_channel_id(),
+                channel_id.saturating_add(One::one())
+            );
+
+            // dynamic bag for channel is created
+            assert_ok!(Storage::<Test>::ensure_bag_exists(&channel_bag_id));
+
+            // event correctly deposited
+            let owner = Content::actor_to_channel_owner(&self.actor).unwrap();
+            assert_eq!(
+                System::events().last().unwrap().event,
+                MetaEvent::content(RawEvent::ChannelCreated(
+                    self.actor.clone(),
+                    channel_id,
+                    ChannelRecord {
+                        owner: owner,
+                        is_censored: false,
+                        reward_account: self.params.reward_account.clone(),
+                        collaborators: self.params.collaborators.clone(),
+                        num_videos: Zero::zero(),
+                    },
+                    self.params.clone(),
+                ))
+            );
+
+            if let Some(assets) = self.params.assets.as_ref() {
+                // balance accounting is correct
+                let bag_deletion_prize = BalanceOf::<Test>::zero();
+                let objects_deletion_prize =
+                    assets
+                        .object_creation_list
+                        .iter()
+                        .fold(BalanceOf::<Test>::zero(), |acc, _| {
                             acc.saturating_add(
                                 <Test as storage::Trait>::DataObjectDeletionPrize::get(),
                             )
-                        },
-                    );
+                        });
 
-                    assert_eq!(
-                        balance_pre.saturating_sub(balance_post),
-                        bag_deletion_prize.saturating_add(objects_deletion_prize),
-                    );
+                assert_eq!(
+                    balance_pre.saturating_sub(balance_post),
+                    bag_deletion_prize.saturating_add(objects_deletion_prize),
+                );
 
-                    assert!((beg_obj_id..end_obj_id).all(|id| {
-                        storage::DataObjectsById::<Test>::contains_key(&channel_bag_id, id)
-                    }));
-                }
-            }
-            Err(_) => {
-                assert_eq!(balance_post, balance_pre);
-                assert_eq!(beg_obj_id, end_obj_id);
-                assert!(!storage::Bags::<Test>::contains_key(&channel_bag_id));
-                assert!(!ChannelById::<Test>::contains_key(&channel_id));
-                assert_eq!(NextChannelId::<Test>::get(), channel_id);
+                assert!((beg_obj_id..end_obj_id).all(|id| {
+                    storage::DataObjectsById::<Test>::contains_key(&channel_bag_id, id)
+                }));
             }
+        } else {
+            assert_eq!(balance_post, balance_pre);
+            assert_eq!(beg_obj_id, end_obj_id);
+            assert!(!storage::Bags::<Test>::contains_key(&channel_bag_id));
+            assert!(!ChannelById::<Test>::contains_key(&channel_id));
+            assert_eq!(NextChannelId::<Test>::get(), channel_id);
         }
     }
 }