Browse Source

unsuccessful dyn bag creation with dynamic and param bag differing

ignazio 3 years ago
parent
commit
f14e24b74b
2 changed files with 16 additions and 2 deletions
  1. 3 2
      runtime-modules/storage/src/lib.rs
  2. 13 0
      runtime-modules/storage/src/tests/mod.rs

+ 3 - 2
runtime-modules/storage/src/lib.rs

@@ -2852,14 +2852,15 @@ impl<T: Trait> Module<T> {
         let bag_change = upload_params
             .as_ref()
             .map(|params| {
-                // ensure coherent account ids for prize
+                // ensure coherent account ids & bag ids
                 if let Some(deletion_prize) = deletion_prize {
                     ensure!(
                         params.deletion_prize_source_account_id == deletion_prize.account_id,
                         Error::<T>::AccountsNotCoherent,
                     );
-                    ensure!(bag_id == params.bag_id, Error::<T>::BagsNotCoherent,);
                 }
+                ensure!(bag_id == params.bag_id, Error::<T>::BagsNotCoherent);
+
                 Self::validate_bag_change(params)
             })
             .transpose()?;

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

@@ -5262,6 +5262,19 @@ fn unsuccessful_dyn_bag_creation_with_buckets_having_insufficient_size_available
     })
 }
 
+#[test]
+fn unsuccessful_dyn_bag_creation_with_dynamic_and_param_bag_differing() {
+    build_test_externalities().execute_with(|| {
+        run_to_block(1);
+
+        create_storage_buckets(DEFAULT_STORAGE_BUCKETS_NUMBER);
+        increase_account_balance(&DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
+
+        CreateDynamicBagWithObjectsFixture::default()
+            .with_params_bag_id(DynamicBagId::<Test>::Channel(0u64).into())
+            .call_and_assert(Err(Error::<Test>::BagsNotCoherent.into()));
+    })
+}
 #[test]
 fn successful_dyn_bag_creation_with_upload_and_no_deletion_prize() {
     build_test_externalities().execute_with(|| {