Explorar o código

Update tests in the storage module

- Remove old tests.rs file
- Introduce a new tests module
- Move mock and all tests into the tests module
Shamil Gadelshin %!s(int64=4) %!d(string=hai) anos
pai
achega
c5029f80d6

+ 2 - 93
runtime-modules/storage/src/data_directory.rs

@@ -155,14 +155,14 @@ decl_module! {
         }
 
         // The LiaisonJudgement can be updated, but only by the liaison.
-        fn accept_content(origin, content_id: T::ContentId) {
+        pub(crate) fn accept_content(origin, content_id: T::ContentId) {
             let who = ensure_signed(origin)?;
             Self::update_content_judgement(&who, content_id, LiaisonJudgement::Accepted)?;
             <KnownContentIds<T>>::mutate(|ids| ids.push(content_id));
             Self::deposit_event(RawEvent::ContentAccepted(content_id, who));
         }
 
-        fn reject_content(origin, content_id: T::ContentId) {
+        pub(crate) fn reject_content(origin, content_id: T::ContentId) {
             let who = ensure_signed(origin)?;
             Self::update_content_judgement(&who, content_id, LiaisonJudgement::Rejected)?;
             Self::deposit_event(RawEvent::ContentRejected(content_id, who));
@@ -233,94 +233,3 @@ impl<T: Trait> Module<T> {
         Ok(())
     }
 }
-
-#[cfg(test)]
-mod tests {
-    use crate::mock::*;
-
-    #[test]
-    fn succeed_adding_content() {
-        with_default_mock_builder(|| {
-            let sender = 1 as u64;
-            // Register a content with 1234 bytes of type 1, which should be recognized.
-            let res = TestDataDirectory::add_content(
-                Origin::signed(sender),
-                1,
-                1234,
-                0,
-                vec![1, 3, 3, 7],
-            );
-            assert!(res.is_ok());
-        });
-    }
-
-    #[test]
-    fn accept_content_as_liaison() {
-        with_default_mock_builder(|| {
-            let sender = 1 as u64;
-            let res = TestDataDirectory::add_content(
-                Origin::signed(sender),
-                1,
-                1234,
-                0,
-                vec![1, 2, 3, 4],
-            );
-            assert!(res.is_ok());
-
-            // An appropriate event should have been fired.
-            let (content_id, creator) = match System::events().last().unwrap().event {
-                MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
-                    content_id,
-                    creator,
-                )) => (content_id, creator),
-                _ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
-            };
-            assert_ne!(creator, 0xdeadbeefu64);
-            assert_eq!(creator, sender);
-
-            // Accepting content should not work with some random origin
-            let res = TestDataDirectory::accept_content(Origin::signed(1), content_id);
-            assert!(res.is_err());
-
-            // However, with the liaison as origin it should.
-            let res =
-                TestDataDirectory::accept_content(Origin::signed(TEST_MOCK_LIAISON), content_id);
-            assert!(res.is_ok());
-        });
-    }
-
-    #[test]
-    fn reject_content_as_liaison() {
-        with_default_mock_builder(|| {
-            let sender = 1 as u64;
-            let res = TestDataDirectory::add_content(
-                Origin::signed(sender),
-                1,
-                1234,
-                0,
-                vec![1, 2, 3, 4],
-            );
-            assert!(res.is_ok());
-
-            // An appropriate event should have been fired.
-            let (content_id, creator) = match System::events().last().unwrap().event {
-                MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
-                    content_id,
-                    creator,
-                )) => (content_id, creator),
-                _ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
-            };
-            assert_ne!(creator, 0xdeadbeefu64);
-            assert_eq!(creator, sender);
-
-            // Rejecting content should not work with some random origin
-            let res = TestDataDirectory::reject_content(Origin::signed(1), content_id);
-            assert!(res.is_err());
-
-            // However, with the liaison as origin it should.
-            let res =
-                TestDataDirectory::reject_content(Origin::signed(TEST_MOCK_LIAISON), content_id);
-            assert!(res.is_ok());
-        });
-    }
-}

+ 0 - 84
runtime-modules/storage/src/data_object_storage_registry.rs

@@ -199,87 +199,3 @@ impl<T: Trait> Module<T> {
         Ok(())
     }
 }
-
-#[cfg(test)]
-mod tests {
-    use crate::mock::*;
-
-    #[test]
-    fn initial_state() {
-        with_default_mock_builder(|| {
-            assert_eq!(
-                TestDataObjectStorageRegistry::first_relationship_id(),
-                TEST_FIRST_RELATIONSHIP_ID
-            );
-        });
-    }
-
-    #[test]
-    fn test_add_relationship() {
-        with_default_mock_builder(|| {
-            // The content needs to exist - in our mock, that's with the content ID TEST_MOCK_EXISTING_CID
-            let res = TestDataObjectStorageRegistry::add_relationship(
-                Origin::signed(TEST_MOCK_LIAISON),
-                TEST_MOCK_EXISTING_CID,
-            );
-            assert!(res.is_ok());
-        });
-    }
-
-    #[test]
-    fn test_fail_adding_relationship_with_bad_content() {
-        with_default_mock_builder(|| {
-            let res = TestDataObjectStorageRegistry::add_relationship(Origin::signed(1), 24);
-            assert!(res.is_err());
-        });
-    }
-
-    #[test]
-    fn test_toggle_ready() {
-        with_default_mock_builder(|| {
-            // Create a DOSR
-            let res = TestDataObjectStorageRegistry::add_relationship(
-                Origin::signed(TEST_MOCK_LIAISON),
-                TEST_MOCK_EXISTING_CID,
-            );
-            assert!(res.is_ok());
-
-            // Grab DOSR ID from event
-            let dosr_id = match System::events().last().unwrap().event {
-                MetaEvent::data_object_storage_registry(
-                    data_object_storage_registry::RawEvent::DataObjectStorageRelationshipAdded(
-                        dosr_id,
-                        _content_id,
-                        _account_id,
-                    ),
-                ) => dosr_id,
-                _ => 0xdeadbeefu64, // invalid value, unlikely to match
-            };
-            assert_ne!(dosr_id, 0xdeadbeefu64);
-
-            // Toggling from a different account should fail
-            let res =
-                TestDataObjectStorageRegistry::set_relationship_ready(Origin::signed(2), dosr_id);
-            assert!(res.is_err());
-
-            // Toggling with the wrong ID should fail.
-            let res = TestDataObjectStorageRegistry::set_relationship_ready(
-                Origin::signed(TEST_MOCK_LIAISON),
-                dosr_id + 1,
-            );
-            assert!(res.is_err());
-
-            // Toggling with the correct ID and origin should succeed
-            let res = TestDataObjectStorageRegistry::set_relationship_ready(
-                Origin::signed(TEST_MOCK_LIAISON),
-                dosr_id,
-            );
-            assert!(res.is_ok());
-            assert_eq!(System::events().last().unwrap().event,
-                MetaEvent::data_object_storage_registry(data_object_storage_registry::RawEvent::DataObjectStorageRelationshipReadyUpdated(
-                    dosr_id,
-                    true,
-                )));
-        });
-    }
-}

+ 0 - 162
runtime-modules/storage/src/data_object_type_registry.rs

@@ -157,165 +157,3 @@ impl<T: Trait> Module<T> {
         Self::data_object_types(&id).ok_or(MSG_DO_TYPE_NOT_FOUND)
     }
 }
-
-#[cfg(test)]
-mod tests {
-    //use super::*;
-    use crate::mock::*;
-
-    use system::{self, EventRecord, Phase};
-
-    #[test]
-    fn initial_state() {
-        with_default_mock_builder(|| {
-            assert_eq!(
-                TestDataObjectTypeRegistry::first_data_object_type_id(),
-                TEST_FIRST_DATA_OBJECT_TYPE_ID
-            );
-        });
-    }
-
-    #[test]
-    fn succeed_register() {
-        with_default_mock_builder(|| {
-            let data: TestDataObjectType = TestDataObjectType {
-                description: "foo".as_bytes().to_vec(),
-                active: false,
-            };
-            let res = TestDataObjectTypeRegistry::register_data_object_type(
-                system::RawOrigin::Root.into(),
-                data,
-            );
-            assert!(res.is_ok());
-        });
-    }
-
-    #[test]
-    fn update_existing() {
-        with_default_mock_builder(|| {
-            // First register a type
-            let data: TestDataObjectType = TestDataObjectType {
-                description: "foo".as_bytes().to_vec(),
-                active: false,
-            };
-            let id_res = TestDataObjectTypeRegistry::register_data_object_type(
-                system::RawOrigin::Root.into(),
-                data,
-            );
-            assert!(id_res.is_ok());
-
-            let dot_id = match System::events().last().unwrap().event {
-                MetaEvent::data_object_type_registry(
-                    data_object_type_registry::RawEvent::DataObjectTypeRegistered(dot_id),
-                ) => dot_id,
-                _ => 0xdeadbeefu64, // unlikely value
-            };
-            assert_ne!(dot_id, 0xdeadbeefu64);
-
-            // Now update it with new data - we need the ID to be the same as in
-            // returned by the previous call. First, though, try and fail with a bad ID
-            let updated1: TestDataObjectType = TestDataObjectType {
-                description: "bar".as_bytes().to_vec(),
-                active: false,
-            };
-            let res = TestDataObjectTypeRegistry::update_data_object_type(
-                system::RawOrigin::Root.into(),
-                dot_id + 1,
-                updated1,
-            );
-            assert!(res.is_err());
-
-            // Finally with an existing ID, it should work.
-            let updated3: TestDataObjectType = TestDataObjectType {
-                description: "bar".as_bytes().to_vec(),
-                active: false,
-            };
-            let res = TestDataObjectTypeRegistry::update_data_object_type(
-                system::RawOrigin::Root.into(),
-                dot_id,
-                updated3,
-            );
-            assert!(res.is_ok());
-            assert_eq!(
-                *System::events().last().unwrap(),
-                EventRecord {
-                    phase: Phase::ApplyExtrinsic(0),
-                    event: MetaEvent::data_object_type_registry(
-                        data_object_type_registry::RawEvent::DataObjectTypeUpdated(dot_id)
-                    ),
-                    topics: vec![],
-                }
-            );
-        });
-    }
-
-    #[test]
-    fn activate_existing() {
-        with_default_mock_builder(|| {
-            // First register a type
-            let data: TestDataObjectType = TestDataObjectType {
-                description: "foo".as_bytes().to_vec(),
-                active: false,
-            };
-            let id_res = TestDataObjectTypeRegistry::register_data_object_type(
-                system::RawOrigin::Root.into(),
-                data,
-            );
-            assert!(id_res.is_ok());
-            assert_eq!(
-                *System::events().last().unwrap(),
-                EventRecord {
-                    phase: Phase::ApplyExtrinsic(0),
-                    event: MetaEvent::data_object_type_registry(
-                        data_object_type_registry::RawEvent::DataObjectTypeRegistered(
-                            TEST_FIRST_DATA_OBJECT_TYPE_ID
-                        )
-                    ),
-                    topics: vec![],
-                }
-            );
-
-            // Retrieve, and ensure it's not active.
-            let data =
-                TestDataObjectTypeRegistry::data_object_types(TEST_FIRST_DATA_OBJECT_TYPE_ID);
-            assert!(data.is_some());
-            assert!(!data.unwrap().active);
-
-            // Now activate the data object type
-            let res = TestDataObjectTypeRegistry::activate_data_object_type(
-                system::RawOrigin::Root.into(),
-                TEST_FIRST_DATA_OBJECT_TYPE_ID,
-            );
-            assert!(res.is_ok());
-            assert_eq!(
-                *System::events().last().unwrap(),
-                EventRecord {
-                    phase: Phase::ApplyExtrinsic(0),
-                    event: MetaEvent::data_object_type_registry(
-                        data_object_type_registry::RawEvent::DataObjectTypeUpdated(
-                            TEST_FIRST_DATA_OBJECT_TYPE_ID
-                        )
-                    ),
-                    topics: vec![],
-                }
-            );
-
-            // Ensure that the item is actually activated.
-            let data =
-                TestDataObjectTypeRegistry::data_object_types(TEST_FIRST_DATA_OBJECT_TYPE_ID);
-            assert!(data.is_some());
-            assert!(data.unwrap().active);
-
-            // Deactivate again.
-            let res = TestDataObjectTypeRegistry::deactivate_data_object_type(
-                system::RawOrigin::Root.into(),
-                TEST_FIRST_DATA_OBJECT_TYPE_ID,
-            );
-            assert!(res.is_ok());
-            let data =
-                TestDataObjectTypeRegistry::data_object_types(TEST_FIRST_DATA_OBJECT_TYPE_ID);
-            assert!(data.is_some());
-            assert!(!data.unwrap().active);
-        });
-    }
-}

+ 1 - 1
runtime-modules/storage/src/lib.rs

@@ -6,4 +6,4 @@ pub mod data_object_storage_registry;
 pub mod data_object_type_registry;
 pub mod traits;
 
-mod mock;
+mod tests;

+ 0 - 206
runtime-modules/storage/src/tests.rs

@@ -1,206 +0,0 @@
-#![cfg(test)]
-
-use super::mock::*;
-use super::*;
-
-use runtime_io::with_externalities;
-use system::{self, EventRecord, Phase};
-
-#[test]
-fn initial_state() {
-    const DEFAULT_FIRST_ID: u64 = 1000;
-
-    with_externalities(
-        &mut ExtBuilder::default()
-            .first_data_object_type_id(DEFAULT_FIRST_ID)
-            .build(),
-        || {
-            assert_eq!(
-                TestDataObjectTypeRegistry::first_data_object_type_id(),
-                DEFAULT_FIRST_ID
-            );
-        },
-    );
-}
-
-#[test]
-fn fail_register_without_root() {
-    const DEFAULT_FIRST_ID: u64 = 1000;
-
-    with_externalities(
-        &mut ExtBuilder::default()
-            .first_data_object_type_id(DEFAULT_FIRST_ID)
-            .build(),
-        || {
-            let data: TestDataObjectType = TestDataObjectType {
-                id: None,
-                description: "foo".as_bytes().to_vec(),
-                active: false,
-            };
-            let res =
-                TestDataObjectTypeRegistry::register_data_object_type(Origin::signed(1), data);
-            assert!(res.is_err());
-        },
-    );
-}
-
-#[test]
-fn succeed_register_as_root() {
-    const DEFAULT_FIRST_ID: u64 = 1000;
-
-    with_externalities(
-        &mut ExtBuilder::default()
-            .first_data_object_type_id(DEFAULT_FIRST_ID)
-            .build(),
-        || {
-            let data: TestDataObjectType = TestDataObjectType {
-                id: None,
-                description: "foo".as_bytes().to_vec(),
-                active: false,
-            };
-            let res = TestDataObjectTypeRegistry::register_data_object_type(Origin::ROOT, data);
-            assert!(res.is_ok());
-        },
-    );
-}
-
-#[test]
-fn update_existing() {
-    const DEFAULT_FIRST_ID: u64 = 1000;
-
-    with_externalities(
-        &mut ExtBuilder::default()
-            .first_data_object_type_id(DEFAULT_FIRST_ID)
-            .build(),
-        || {
-            // First register a type
-            let data: TestDataObjectType = TestDataObjectType {
-                id: None,
-                description: "foo".as_bytes().to_vec(),
-                active: false,
-            };
-            let id_res = TestDataObjectTypeRegistry::register_data_object_type(Origin::ROOT, data);
-            assert!(id_res.is_ok());
-            assert_eq!(
-                *System::events().last().unwrap(),
-                EventRecord {
-                    phase: Phase::ApplyExtrinsic(0),
-                    event: MetaEvent::data_object_type_registry(
-                        data_object_type_registry::RawEvent::DataObjectTypeRegistered(
-                            DEFAULT_FIRST_ID
-                        )
-                    ),
-                }
-            );
-
-            // Now update it with new data - we need the ID to be the same as in
-            // returned by the previous call. First, though, try and fail without
-            let updated1: TestDataObjectType = TestDataObjectType {
-                id: None,
-                description: "bar".as_bytes().to_vec(),
-                active: false,
-            };
-            let res = TestDataObjectTypeRegistry::update_data_object_type(Origin::ROOT, updated1);
-            assert!(res.is_err());
-
-            // Now try with a bad ID
-            let updated2: TestDataObjectType = TestDataObjectType {
-                id: Some(DEFAULT_FIRST_ID + 1),
-                description: "bar".as_bytes().to_vec(),
-                active: false,
-            };
-            let res = TestDataObjectTypeRegistry::update_data_object_type(Origin::ROOT, updated2);
-            assert!(res.is_err());
-
-            // Finally with an existing ID, it should work.
-            let updated3: TestDataObjectType = TestDataObjectType {
-                id: Some(DEFAULT_FIRST_ID),
-                description: "bar".as_bytes().to_vec(),
-                active: false,
-            };
-            let res = TestDataObjectTypeRegistry::update_data_object_type(Origin::ROOT, updated3);
-            assert!(res.is_ok());
-            assert_eq!(
-                *System::events().last().unwrap(),
-                EventRecord {
-                    phase: Phase::ApplyExtrinsic(0),
-                    event: MetaEvent::data_object_type_registry(
-                        data_object_type_registry::RawEvent::DataObjectTypeUpdated(
-                            DEFAULT_FIRST_ID
-                        )
-                    ),
-                }
-            );
-        },
-    );
-}
-
-#[test]
-fn activate_existing() {
-    const DEFAULT_FIRST_ID: u64 = 1000;
-
-    with_externalities(
-        &mut ExtBuilder::default()
-            .first_data_object_type_id(DEFAULT_FIRST_ID)
-            .build(),
-        || {
-            // First register a type
-            let data: TestDataObjectType = TestDataObjectType {
-                id: None,
-                description: "foo".as_bytes().to_vec(),
-                active: false,
-            };
-            let id_res = TestDataObjectTypeRegistry::register_data_object_type(Origin::ROOT, data);
-            assert!(id_res.is_ok());
-            assert_eq!(
-                *System::events().last().unwrap(),
-                EventRecord {
-                    phase: Phase::ApplyExtrinsic(0),
-                    event: MetaEvent::data_object_type_registry(
-                        data_object_type_registry::RawEvent::DataObjectTypeRegistered(
-                            DEFAULT_FIRST_ID
-                        )
-                    ),
-                }
-            );
-
-            // Retrieve, and ensure it's not active.
-            let data = TestDataObjectTypeRegistry::data_object_type(DEFAULT_FIRST_ID);
-            assert!(data.is_some());
-            assert!(!data.unwrap().active);
-
-            // Now activate the data object type
-            let res = TestDataObjectTypeRegistry::activate_data_object_type(
-                Origin::ROOT,
-                DEFAULT_FIRST_ID,
-            );
-            assert!(res.is_ok());
-            assert_eq!(
-                *System::events().last().unwrap(),
-                EventRecord {
-                    phase: Phase::ApplyExtrinsic(0),
-                    event: MetaEvent::data_object_type_registry(
-                        data_object_type_registry::RawEvent::DataObjectTypeUpdated(
-                            DEFAULT_FIRST_ID
-                        )
-                    ),
-                }
-            );
-
-            // Ensure that the item is actually activated.
-            let data = TestDataObjectTypeRegistry::data_object_type(DEFAULT_FIRST_ID);
-            assert!(data.is_some());
-            assert!(data.unwrap().active);
-
-            // Deactivate again.
-            let res = TestDataObjectTypeRegistry::deactivate_data_object_type(
-                Origin::ROOT,
-                DEFAULT_FIRST_ID,
-            );
-            assert!(res.is_ok());
-            let data = TestDataObjectTypeRegistry::data_object_type(DEFAULT_FIRST_ID);
-            assert!(data.is_some());
-            assert!(!data.unwrap().active);
-        },
-    );
-}

+ 72 - 0
runtime-modules/storage/src/tests/data_directory.rs

@@ -0,0 +1,72 @@
+#![cfg(test)]
+
+use super::mock::*;
+
+#[test]
+fn succeed_adding_content() {
+    with_default_mock_builder(|| {
+        let sender = 1 as u64;
+        // Register a content with 1234 bytes of type 1, which should be recognized.
+        let res =
+            TestDataDirectory::add_content(Origin::signed(sender), 1, 1234, 0, vec![1, 3, 3, 7]);
+        assert!(res.is_ok());
+    });
+}
+
+#[test]
+fn accept_content_as_liaison() {
+    with_default_mock_builder(|| {
+        let sender = 1 as u64;
+        let res =
+            TestDataDirectory::add_content(Origin::signed(sender), 1, 1234, 0, vec![1, 2, 3, 4]);
+        assert!(res.is_ok());
+
+        // An appropriate event should have been fired.
+        let (content_id, creator) = match System::events().last().unwrap().event {
+            MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
+                content_id,
+                creator,
+            )) => (content_id, creator),
+            _ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
+        };
+        assert_ne!(creator, 0xdeadbeefu64);
+        assert_eq!(creator, sender);
+
+        // Accepting content should not work with some random origin
+        let res = TestDataDirectory::accept_content(Origin::signed(1), content_id);
+        assert!(res.is_err());
+
+        // However, with the liaison as origin it should.
+        let res = TestDataDirectory::accept_content(Origin::signed(TEST_MOCK_LIAISON), content_id);
+        assert!(res.is_ok());
+    });
+}
+
+#[test]
+fn reject_content_as_liaison() {
+    with_default_mock_builder(|| {
+        let sender = 1 as u64;
+        let res =
+            TestDataDirectory::add_content(Origin::signed(sender), 1, 1234, 0, vec![1, 2, 3, 4]);
+        assert!(res.is_ok());
+
+        // An appropriate event should have been fired.
+        let (content_id, creator) = match System::events().last().unwrap().event {
+            MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
+                content_id,
+                creator,
+            )) => (content_id, creator),
+            _ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
+        };
+        assert_ne!(creator, 0xdeadbeefu64);
+        assert_eq!(creator, sender);
+
+        // Rejecting content should not work with some random origin
+        let res = TestDataDirectory::reject_content(Origin::signed(1), content_id);
+        assert!(res.is_err());
+
+        // However, with the liaison as origin it should.
+        let res = TestDataDirectory::reject_content(Origin::signed(TEST_MOCK_LIAISON), content_id);
+        assert!(res.is_ok());
+    });
+}

+ 84 - 0
runtime-modules/storage/src/tests/data_object_storage_registry.rs

@@ -0,0 +1,84 @@
+#![cfg(test)]
+
+use super::mock::*;
+
+#[test]
+fn initial_state() {
+    with_default_mock_builder(|| {
+        assert_eq!(
+            TestDataObjectStorageRegistry::first_relationship_id(),
+            TEST_FIRST_RELATIONSHIP_ID
+        );
+    });
+}
+
+#[test]
+fn test_add_relationship() {
+    with_default_mock_builder(|| {
+        // The content needs to exist - in our mock, that's with the content ID TEST_MOCK_EXISTING_CID
+        let res = TestDataObjectStorageRegistry::add_relationship(
+            Origin::signed(TEST_MOCK_LIAISON),
+            TEST_MOCK_EXISTING_CID,
+        );
+        assert!(res.is_ok());
+    });
+}
+
+#[test]
+fn test_fail_adding_relationship_with_bad_content() {
+    with_default_mock_builder(|| {
+        let res = TestDataObjectStorageRegistry::add_relationship(Origin::signed(1), 24);
+        assert!(res.is_err());
+    });
+}
+
+#[test]
+fn test_toggle_ready() {
+    with_default_mock_builder(|| {
+        // Create a DOSR
+        let res = TestDataObjectStorageRegistry::add_relationship(
+            Origin::signed(TEST_MOCK_LIAISON),
+            TEST_MOCK_EXISTING_CID,
+        );
+        assert!(res.is_ok());
+
+        // Grab DOSR ID from event
+        let dosr_id = match System::events().last().unwrap().event {
+            MetaEvent::data_object_storage_registry(
+                data_object_storage_registry::RawEvent::DataObjectStorageRelationshipAdded(
+                    dosr_id,
+                    _content_id,
+                    _account_id,
+                ),
+            ) => dosr_id,
+            _ => 0xdeadbeefu64, // invalid value, unlikely to match
+        };
+        assert_ne!(dosr_id, 0xdeadbeefu64);
+
+        // Toggling from a different account should fail
+        let res = TestDataObjectStorageRegistry::set_relationship_ready(Origin::signed(2), dosr_id);
+        assert!(res.is_err());
+
+        // Toggling with the wrong ID should fail.
+        let res = TestDataObjectStorageRegistry::set_relationship_ready(
+            Origin::signed(TEST_MOCK_LIAISON),
+            dosr_id + 1,
+        );
+        assert!(res.is_err());
+
+        // Toggling with the correct ID and origin should succeed
+        let res = TestDataObjectStorageRegistry::set_relationship_ready(
+            Origin::signed(TEST_MOCK_LIAISON),
+            dosr_id,
+        );
+        assert!(res.is_ok());
+        assert_eq!(
+            System::events().last().unwrap().event,
+            MetaEvent::data_object_storage_registry(
+                data_object_storage_registry::RawEvent::DataObjectStorageRelationshipReadyUpdated(
+                    dosr_id, true,
+                )
+            )
+        );
+    });
+}

+ 156 - 0
runtime-modules/storage/src/tests/data_object_type_registry.rs

@@ -0,0 +1,156 @@
+#![cfg(test)]
+
+use super::mock::*;
+
+use system::{self, EventRecord, Phase};
+
+#[test]
+fn initial_state() {
+    with_default_mock_builder(|| {
+        assert_eq!(
+            TestDataObjectTypeRegistry::first_data_object_type_id(),
+            TEST_FIRST_DATA_OBJECT_TYPE_ID
+        );
+    });
+}
+
+#[test]
+fn succeed_register() {
+    with_default_mock_builder(|| {
+        let data: TestDataObjectType = TestDataObjectType {
+            description: "foo".as_bytes().to_vec(),
+            active: false,
+        };
+        let res = TestDataObjectTypeRegistry::register_data_object_type(
+            system::RawOrigin::Root.into(),
+            data,
+        );
+        assert!(res.is_ok());
+    });
+}
+
+#[test]
+fn update_existing() {
+    with_default_mock_builder(|| {
+        // First register a type
+        let data: TestDataObjectType = TestDataObjectType {
+            description: "foo".as_bytes().to_vec(),
+            active: false,
+        };
+        let id_res = TestDataObjectTypeRegistry::register_data_object_type(
+            system::RawOrigin::Root.into(),
+            data,
+        );
+        assert!(id_res.is_ok());
+
+        let dot_id = match System::events().last().unwrap().event {
+            MetaEvent::data_object_type_registry(
+                data_object_type_registry::RawEvent::DataObjectTypeRegistered(dot_id),
+            ) => dot_id,
+            _ => 0xdeadbeefu64, // unlikely value
+        };
+        assert_ne!(dot_id, 0xdeadbeefu64);
+
+        // Now update it with new data - we need the ID to be the same as in
+        // returned by the previous call. First, though, try and fail with a bad ID
+        let updated1: TestDataObjectType = TestDataObjectType {
+            description: "bar".as_bytes().to_vec(),
+            active: false,
+        };
+        let res = TestDataObjectTypeRegistry::update_data_object_type(
+            system::RawOrigin::Root.into(),
+            dot_id + 1,
+            updated1,
+        );
+        assert!(res.is_err());
+
+        // Finally with an existing ID, it should work.
+        let updated3: TestDataObjectType = TestDataObjectType {
+            description: "bar".as_bytes().to_vec(),
+            active: false,
+        };
+        let res = TestDataObjectTypeRegistry::update_data_object_type(
+            system::RawOrigin::Root.into(),
+            dot_id,
+            updated3,
+        );
+        assert!(res.is_ok());
+        assert_eq!(
+            *System::events().last().unwrap(),
+            EventRecord {
+                phase: Phase::ApplyExtrinsic(0),
+                event: MetaEvent::data_object_type_registry(
+                    data_object_type_registry::RawEvent::DataObjectTypeUpdated(dot_id)
+                ),
+                topics: vec![],
+            }
+        );
+    });
+}
+
+#[test]
+fn activate_existing() {
+    with_default_mock_builder(|| {
+        // First register a type
+        let data: TestDataObjectType = TestDataObjectType {
+            description: "foo".as_bytes().to_vec(),
+            active: false,
+        };
+        let id_res = TestDataObjectTypeRegistry::register_data_object_type(
+            system::RawOrigin::Root.into(),
+            data,
+        );
+        assert!(id_res.is_ok());
+        assert_eq!(
+            *System::events().last().unwrap(),
+            EventRecord {
+                phase: Phase::ApplyExtrinsic(0),
+                event: MetaEvent::data_object_type_registry(
+                    data_object_type_registry::RawEvent::DataObjectTypeRegistered(
+                        TEST_FIRST_DATA_OBJECT_TYPE_ID
+                    )
+                ),
+                topics: vec![],
+            }
+        );
+
+        // Retrieve, and ensure it's not active.
+        let data = TestDataObjectTypeRegistry::data_object_types(TEST_FIRST_DATA_OBJECT_TYPE_ID);
+        assert!(data.is_some());
+        assert!(!data.unwrap().active);
+
+        // Now activate the data object type
+        let res = TestDataObjectTypeRegistry::activate_data_object_type(
+            system::RawOrigin::Root.into(),
+            TEST_FIRST_DATA_OBJECT_TYPE_ID,
+        );
+        assert!(res.is_ok());
+        assert_eq!(
+            *System::events().last().unwrap(),
+            EventRecord {
+                phase: Phase::ApplyExtrinsic(0),
+                event: MetaEvent::data_object_type_registry(
+                    data_object_type_registry::RawEvent::DataObjectTypeUpdated(
+                        TEST_FIRST_DATA_OBJECT_TYPE_ID
+                    )
+                ),
+                topics: vec![],
+            }
+        );
+
+        // Ensure that the item is actually activated.
+        let data = TestDataObjectTypeRegistry::data_object_types(TEST_FIRST_DATA_OBJECT_TYPE_ID);
+        assert!(data.is_some());
+        assert!(data.unwrap().active);
+
+        // Deactivate again.
+        let res = TestDataObjectTypeRegistry::deactivate_data_object_type(
+            system::RawOrigin::Root.into(),
+            TEST_FIRST_DATA_OBJECT_TYPE_ID,
+        );
+        assert!(res.is_ok());
+        let data = TestDataObjectTypeRegistry::data_object_types(TEST_FIRST_DATA_OBJECT_TYPE_ID);
+        assert!(data.is_some());
+        assert!(!data.unwrap().active);
+    });
+}

+ 1 - 1
runtime-modules/storage/src/mock.rs → runtime-modules/storage/src/tests/mock.rs

@@ -1,7 +1,7 @@
 #![cfg(test)]
 
-pub use super::{data_directory, data_object_storage_registry, data_object_type_registry};
 use crate::traits;
+pub use crate::{data_directory, data_object_storage_registry, data_object_type_registry};
 pub use common::currency::GovernanceCurrency;
 use membership::members;
 use roles::actors;

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

@@ -0,0 +1,6 @@
+#![cfg(test)]
+
+mod data_directory;
+mod data_object_storage_registry;
+mod data_object_type_registry;
+mod mock;