Browse Source

added tests with empty proof vector

ignazio 3 years ago
parent
commit
50546b8215

+ 11 - 6
runtime-modules/content/src/tests/fixtures.rs

@@ -6,6 +6,9 @@ use frame_support::traits::Currency;
 use sp_std::cmp::min;
 use sp_std::iter::{IntoIterator, Iterator};
 
+// Index which indentifies the item in the commitment set we want the proof for
+pub const DEFAULT_PROOF_INDEX: usize = 1;
+
 // fixtures
 pub struct CreateChannelFixture {
     sender: AccountId,
@@ -1310,12 +1313,14 @@ impl ClaimChannelRewardFixture {
         let payout_earned_pre =
             Content::channel_by_id(self.item.channel_id).cumulative_payout_earned;
 
-        let actual_result = Content::claim_channel_reward(
-            origin,
-            self.actor.clone(),
-            build_merkle_path_helper(&self.payments, 1),
-            self.item.clone(),
-        );
+        let proof = if self.payments.is_empty() {
+            vec![]
+        } else {
+            build_merkle_path_helper(&self.payments, DEFAULT_PROOF_INDEX)
+        };
+
+        let actual_result =
+            Content::claim_channel_reward(origin, self.actor.clone(), proof, self.item.clone());
         let balance_post = Balances::<Test>::usable_balance(self.sender);
         let payout_earned_post =
             Content::channel_by_id(self.item.channel_id).cumulative_payout_earned;

+ 21 - 0
runtime-modules/content/src/tests/merkle.rs

@@ -228,6 +228,27 @@ fn unsuccessful_reward_claim_with_invalid_claim() {
     })
 }
 
+#[test]
+fn unsuccessful_reward_claim_with_empty_proof() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_member_owned_channel_with_video();
+
+        let item = PullPayment::<Test> {
+            channel_id: ChannelId::one(),
+            cumulative_payout_claimed: BalanceOf::<Test>::from(DEFAULT_PAYOUT_CLAIMED + 1),
+            reason: Hashing::hash_of(&b"reason".to_vec()),
+        };
+        ClaimChannelRewardFixture::default()
+            .with_item(item)
+            .with_payments(vec![])
+            .call_and_assert(Err(Error::<Test>::PaymentProofVerificationFailed.into()))
+    })
+}
+
 #[test]
 fn successful_reward_claim_by_member() {
     with_default_mock_builder(|| {