Browse Source

Storage: add add_content_uploading_blocked test case

iorveth 4 years ago
parent
commit
b924ff42a2

+ 29 - 1
runtime-modules/storage/src/tests/data_directory.rs

@@ -1,5 +1,6 @@
 #![cfg(test)]
 
+use crate::data_directory::Error;
 use common::storage::StorageObjectOwner;
 use frame_support::dispatch::DispatchError;
 use system::RawOrigin;
@@ -46,13 +47,40 @@ fn add_content_fails_with_invalid_origin() {
             ipfs_content_id: vec![1, 2, 3, 4],
         };
 
-        // Register a content with 1234 bytes of type 1, which should be recognized.
+        // Make an attempt to register a content with 1234 bytes of type 1, which should be recognized.
         let res =
             TestDataDirectory::add_content(RawOrigin::Root.into(), owner, vec![content_parameters]);
         assert_eq!(res, Err(DispatchError::Other("Bad origin")));
     });
 }
 
+#[test]
+fn add_content_uploading_blocked() {
+    ExtBuilder::default()
+        .uploading_blocked_status(true)
+        .build()
+        .execute_with(|| {
+            let sender = 1u64;
+
+            let owner = StorageObjectOwner::Member(1u64);
+
+            let content_parameters = ContentParameters {
+                content_id: 1,
+                type_id: 1234,
+                size: 0,
+                ipfs_content_id: vec![1, 2, 3, 4],
+            };
+
+            // Make an attempt to register a content, when uploading is blocked.
+            let res = TestDataDirectory::add_content(
+                Origin::signed(sender),
+                owner,
+                vec![content_parameters],
+            );
+            assert_eq!(res, Err(Error::<Test>::ContentUploadingBlocked.into()));
+        });
+}
+
 #[test]
 fn accept_and_reject_content_fail_with_invalid_storage_provider() {
     with_default_mock_builder(|| {

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

@@ -244,6 +244,7 @@ pub struct ExtBuilder {
     first_content_id: u64,
     first_relationship_id: u64,
     first_metadata_id: u64,
+    uploading_blocked: bool,
 }
 
 impl Default for ExtBuilder {
@@ -256,6 +257,7 @@ impl Default for ExtBuilder {
             first_content_id: 2,
             first_relationship_id: 3,
             first_metadata_id: 4,
+            uploading_blocked: false,
         }
     }
 }
@@ -281,6 +283,11 @@ impl ExtBuilder {
         self
     }
 
+    pub fn uploading_blocked_status(mut self, uploading_blocked: bool) -> Self {
+        self.uploading_blocked = uploading_blocked;
+        self
+    }
+
     pub fn build(self) -> sp_io::TestExternalities {
         let mut t = system::GenesisConfig::default()
             .build_storage::<Test>()
@@ -292,7 +299,7 @@ impl ExtBuilder {
             global_quota: self.global_quota,
             data_object_by_content_id: vec![],
             quotas: vec![],
-            uploading_blocked: false,
+            uploading_blocked: self.uploading_blocked,
         }
         .assimilate_storage(&mut t)
         .unwrap();