Browse Source

changing crate::Errors now is signalled at compile time

ignazio 3 years ago
parent
commit
09f58c963d
1 changed files with 18 additions and 28 deletions
  1. 18 28
      runtime-modules/content/src/tests/fixtures.rs

+ 18 - 28
runtime-modules/content/src/tests/fixtures.rs

@@ -3,7 +3,6 @@ use super::mock::*;
 use crate::*;
 use frame_support::assert_ok;
 use frame_support::traits::Currency;
-use sp_runtime::DispatchError;
 
 // constants used
 pub const VOUCHER_OBJECTS_NUMBER_LIMIT: u64 = 40;
@@ -440,7 +439,7 @@ impl UpdateChannelFixture {
                 assert_eq!(balance_pre, balance_post);
                 assert_eq!(beg_obj_id, end_obj_id);
 
-                if into_str(err) != "DataObjectDoesntExist" {
+                if err != storage::Error::<Test>::DataObjectDoesntExist.into() {
                     assert!(self.params.assets_to_remove.iter().all(|id| {
                         storage::DataObjectsById::<Test>::contains_key(&bag_id_for_channel, id)
                     }))
@@ -579,7 +578,7 @@ impl UpdateVideoFixture {
                 assert_eq!(balance_pre, balance_post);
                 assert_eq!(beg_obj_id, end_obj_id);
 
-                if into_str(err) != "DataObjectDoesntExist" {
+                if err != storage::Error::<Test>::DataObjectDoesntExist.into() {
                     assert!(self.params.assets_to_remove.iter().all(|id| {
                         storage::DataObjectsById::<Test>::contains_key(&bag_id_for_channel, id)
                     }));
@@ -673,7 +672,7 @@ impl DeleteChannelFixture {
 
             Err(err) => {
                 assert_eq!(balance_pre, balance_post);
-                if into_str(err) != "ChannelDoesNotExist" {
+                if err != Error::<Test>::ChannelDoesNotExist.into() {
                     assert!(ChannelById::<Test>::contains_key(&self.channel_id));
                     assert!(channel_objects_ids.iter().all(|id| {
                         storage::DataObjectsById::<Test>::contains_key(&bag_id_for_channel, id)
@@ -763,25 +762,21 @@ impl DeleteVideoFixture {
             Err(err) => {
                 assert_eq!(balance_pre, balance_post);
 
-                match into_str(err) {
-                    "DataObjectDoesntExist" => {
-                        let video_post = <VideoById<Test>>::get(&self.video_id);
-                        assert_eq!(video_pre, video_post);
-                        assert!(VideoById::<Test>::contains_key(&self.video_id));
-                    }
-                    "VideoDoesNotExist" => {
-                        assert!(self.assets_to_remove.iter().all(|id| {
-                            storage::DataObjectsById::<Test>::contains_key(&channel_bag_id, id)
-                        }));
-                    }
-                    _ => {
-                        let video_post = <VideoById<Test>>::get(&self.video_id);
-                        assert_eq!(video_pre, video_post);
-                        assert!(VideoById::<Test>::contains_key(&self.video_id));
-                        assert!(self.assets_to_remove.iter().all(|id| {
-                            storage::DataObjectsById::<Test>::contains_key(&channel_bag_id, id)
-                        }));
-                    }
+                if err == storage::Error::<Test>::DataObjectDoesntExist.into() {
+                    let video_post = <VideoById<Test>>::get(&self.video_id);
+                    assert_eq!(video_pre, video_post);
+                    assert!(VideoById::<Test>::contains_key(&self.video_id));
+                } else if err == Error::<Test>::VideoDoesNotExist.into() {
+                    assert!(self.assets_to_remove.iter().all(|id| {
+                        storage::DataObjectsById::<Test>::contains_key(&channel_bag_id, id)
+                    }));
+                } else {
+                    let video_post = <VideoById<Test>>::get(&self.video_id);
+                    assert_eq!(video_pre, video_post);
+                    assert!(VideoById::<Test>::contains_key(&self.video_id));
+                    assert!(self.assets_to_remove.iter().all(|id| {
+                        storage::DataObjectsById::<Test>::contains_key(&channel_bag_id, id)
+                    }));
                 }
             }
         }
@@ -894,8 +889,3 @@ pub fn create_default_curator_owned_channel_with_video() {
         .with_channel_id(NextChannelId::<Test>::get() - 1)
         .call_and_assert(Ok(()));
 }
-
-// wrapper to silence compiler error
-fn into_str(err: DispatchError) -> &'static str {
-    err.into()
-}