Browse Source

added reward minting

ignazio 3 years ago
parent
commit
edc75ae3ac
2 changed files with 18 additions and 8 deletions
  1. 6 3
      runtime-modules/content/src/lib.rs
  2. 12 5
      runtime-modules/content/src/tests/fixtures.rs

+ 6 - 3
runtime-modules/content/src/lib.rs

@@ -120,6 +120,11 @@ pub trait ModuleAccount<T: balances::Trait> {
     fn usable_balance() -> BalanceOf<T> {
         <Balances<T>>::usable_balance(&Self::module_account_id())
     }
+
+    /// Mints the reward into the destination account provided
+    fn transfer_reward(dest_account_id: &T::AccountId, amount: BalanceOf<T>) {
+        let _ = <Balances<T> as Currency<T::AccountId>>::deposit_creating(dest_account_id, amount);
+    }
 }
 
 /// Implementation of the ModuleAccountHandler.
@@ -1988,7 +1993,7 @@ decl_module! {
             // == MUTATION SAFE ==
             //
 
-            Self::transfer_reward(cashout, &channel.reward_account.unwrap());
+            ContentTreasury::<T>::transfer_reward( &channel.reward_account.unwrap(), cashout);
             ChannelById::<T>::mutate(
                 &item.channel_id,
                 |channel| channel.cumulative_payout_earned =
@@ -2226,8 +2231,6 @@ impl<T: Trait> Module<T> {
         max(storage_price, cleanup_cost)
     }
 
-    fn transfer_reward(_reward: BalanceOf<T>, _address: &<T as frame_system::Trait>::AccountId) {}
-
     // If we are trying to delete a video post we need witness verification
     fn ensure_witness_verification(
         witness: Option<<T as frame_system::Trait>::Hash>,

+ 12 - 5
runtime-modules/content/src/tests/fixtures.rs

@@ -1300,7 +1300,9 @@ impl ClaimChannelRewardFixture {
 
     pub fn call_and_assert(&self, expected_result: DispatchResult) {
         let origin = Origin::signed(self.sender.clone());
-        let _balance_pre = Balances::<Test>::usable_balance(self.sender);
+        let balance_pre = Balances::<Test>::usable_balance(self.sender);
+        let payout_earned_pre =
+            Content::channel_by_id(self.item.channel_id).cumulative_payout_earned;
 
         let actual_result = Content::claim_channel_reward(
             origin,
@@ -1308,17 +1310,19 @@ impl ClaimChannelRewardFixture {
             build_merkle_path_helper(&self.payments, 1),
             self.item.clone(),
         );
-        let _balance_post = Balances::<Test>::usable_balance(self.sender);
-        let cumulative_payout_earned =
+        let balance_post = Balances::<Test>::usable_balance(self.sender);
+        let payout_earned_post =
             Content::channel_by_id(self.item.channel_id).cumulative_payout_earned;
         assert_eq!(actual_result, expected_result);
 
         if actual_result.is_ok() {
             assert_eq!(
-                cumulative_payout_earned,
-                self.item.cumulative_payout_claimed
+                balance_post.saturating_sub(balance_pre),
+                payout_earned_post.saturating_sub(payout_earned_pre)
             );
 
+            assert_eq!(payout_earned_post, self.item.cumulative_payout_claimed);
+
             assert_eq!(
                 System::events().last().unwrap().event,
                 MetaEvent::content(RawEvent::ChannelRewardUpdated(
@@ -1326,6 +1330,9 @@ impl ClaimChannelRewardFixture {
                     self.item.channel_id
                 ))
             );
+        } else {
+            assert_eq!(balance_post, balance_pre);
+            assert_eq!(payout_earned_post, payout_earned_pre);
         }
     }
 }