Просмотр исходного кода

runtime: Drop the obsolete ‘recurring rewards’ pallet.

Shamil Gadelshin 4 лет назад
Родитель
Сommit
4e8f9611e6

+ 0 - 17
Cargo.lock

@@ -4003,11 +4003,9 @@ dependencies = [
  "pallet-common",
  "pallet-council",
  "pallet-membership",
- "pallet-recurring-reward",
  "pallet-referendum",
  "pallet-staking-handler",
  "pallet-timestamp",
- "pallet-token-mint",
  "parity-scale-codec",
  "serde",
  "sp-arithmetic",
@@ -4030,21 +4028,6 @@ dependencies = [
  "sp-std",
 ]
 
-[[package]]
-name = "pallet-recurring-reward"
-version = "3.1.0"
-dependencies = [
- "frame-support",
- "frame-system",
- "pallet-balances",
- "pallet-token-mint",
- "parity-scale-codec",
- "sp-arithmetic",
- "sp-core",
- "sp-io",
- "sp-runtime",
-]
-
 [[package]]
 name = "pallet-referendum"
 version = "1.0.0"

+ 0 - 1
Cargo.toml

@@ -9,7 +9,6 @@ members = [
 	"runtime-modules/forum",
 	"runtime-modules/membership",
 	"runtime-modules/memo",
-	"runtime-modules/recurring-reward",
 	"runtime-modules/referendum",
 	"runtime-modules/service-discovery",
 	"runtime-modules/storage",

+ 0 - 4
runtime-modules/proposals/engine/Cargo.toml

@@ -19,8 +19,6 @@ staking-handler = { package = 'pallet-staking-handler', default-features = false
 
 # Benchmark dependencies.
 frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca', optional = true}
-recurringrewards = { package = 'pallet-recurring-reward', default-features = false, path = '../../recurring-reward', optional = true}
-minting = { package = 'pallet-token-mint', default-features = false, path = '../../token-minting', optional = true}
 membership = { package = 'pallet-membership', default-features = false, path = '../../membership', optional = true}
 council = { package = 'pallet-council', default-features = false, path = '../../council', optional = true}
 referendum = { package = 'pallet-referendum', default-features = false, path = '../../referendum', optional = true}
@@ -36,8 +34,6 @@ referendum = { package = 'pallet-referendum', default-features = false, path = '
 default = ['std']
 runtime-benchmarks = [
     'frame-benchmarking',
-    'recurringrewards',
-    'minting',
     'membership',
     'council',
     'referendum',

+ 0 - 29
runtime-modules/recurring-reward/Cargo.toml

@@ -1,29 +0,0 @@
-[package]
-name = 'pallet-recurring-reward'
-version = '3.1.0'
-authors = ['Joystream contributors']
-edition = '2018'
-
-[dependencies]
-codec = { package = 'parity-scale-codec', version = '1.3.4', default-features = false, features = ['derive'] }
-sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-frame-system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-minting = { package = 'pallet-token-mint', default-features = false, path = '../token-minting'}
-
-[dev-dependencies]
-sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
-
-[features]
-default = ['std']
-std = [
-	'codec/std',
-	'sp-arithmetic/std',
-	'sp-runtime/std',
-	'frame-support/std',
-	'frame-system/std',
-	'minting/std',
-]

+ 0 - 406
runtime-modules/recurring-reward/src/lib.rs

@@ -1,406 +0,0 @@
-// Clippy linter warning. TODO: remove after the Constaninople release
-#![allow(clippy::type_complexity)]
-// disable it because of possible frontend API break
-
-// Clippy linter warning. TODO: refactor the Option<Option<>>
-#![allow(clippy::option_option)] // disable it because of possible API break
-
-// Ensure we're `no_std` when compiling for Wasm.
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use codec::{Codec, Decode, Encode};
-use frame_support::storage::IterableStorageMap;
-use frame_support::{decl_module, decl_storage, ensure, Parameter};
-use sp_arithmetic::traits::{BaseArithmetic, One, Zero};
-use sp_runtime::traits::{MaybeSerialize, Member};
-
-use minting::BalanceOf;
-
-mod mock;
-mod tests;
-
-pub trait Trait: frame_system::Trait + minting::Trait {
-    type PayoutStatusHandler: PayoutStatusHandler<Self>;
-
-    /// Type of identifier for recipients.
-    type RecipientId: Parameter
-        + Member
-        + BaseArithmetic
-        + Codec
-        + Default
-        + Copy
-        + MaybeSerialize
-        + PartialEq;
-
-    /// Type for identifier for relationship representing that a recipient recieves recurring reward from a token mint
-    type RewardRelationshipId: Parameter
-        + Member
-        + BaseArithmetic
-        + Codec
-        + Default
-        + Copy
-        + MaybeSerialize
-        + PartialEq;
-}
-
-/// Handler for aftermath of a payout attempt
-pub trait PayoutStatusHandler<T: Trait> {
-    fn payout_succeeded(
-        id: T::RewardRelationshipId,
-        destination_account: &T::AccountId,
-        amount: BalanceOf<T>,
-    );
-
-    fn payout_failed(
-        id: T::RewardRelationshipId,
-        destination_account: &T::AccountId,
-        amount: BalanceOf<T>,
-    );
-}
-
-/// Makes `()` empty tuple, a PayoutStatusHandler that does nothing.
-impl<T: Trait> PayoutStatusHandler<T> for () {
-    fn payout_succeeded(
-        _id: T::RewardRelationshipId,
-        _destination_account: &T::AccountId,
-        _amount: BalanceOf<T>,
-    ) {
-    }
-
-    fn payout_failed(
-        _id: T::RewardRelationshipId,
-        _destination_account: &T::AccountId,
-        _amount: BalanceOf<T>,
-    ) {
-    }
-}
-
-/// A recipient of recurring rewards
-#[derive(Encode, Decode, Copy, Clone, Debug, Default)]
-pub struct Recipient<Balance> {
-    // stats
-    /// Total payout received by this recipient
-    total_reward_received: Balance,
-
-    /// Total payout missed for this recipient
-    total_reward_missed: Balance,
-}
-
-#[derive(Encode, Decode, Copy, Clone, Debug, Default)]
-pub struct RewardRelationship<AccountId, Balance, BlockNumber, MintId, RecipientId> {
-    /// Identifier for receiver
-    recipient: RecipientId,
-
-    /// Identifier for reward source
-    mint_id: MintId,
-
-    /// Destination account for reward
-    pub account: AccountId,
-
-    /// The payout amount at the next payout
-    pub amount_per_payout: Balance,
-
-    /// When set, identifies block when next payout should be processed,
-    /// otherwise there is no pending payout
-    next_payment_at_block: Option<BlockNumber>,
-
-    /// When set, will be the basis for automatically setting next payment,
-    /// otherwise any upcoming payout will be a one off.
-    payout_interval: Option<BlockNumber>,
-
-    // stats
-    /// Total payout received in this relationship
-    total_reward_received: Balance,
-
-    /// Total payout failed in this relationship
-    total_reward_missed: Balance,
-}
-
-impl<AccountId: Clone, Balance: Clone, BlockNumber: Clone, MintId: Clone, RecipientId: Clone>
-    RewardRelationship<AccountId, Balance, BlockNumber, MintId, RecipientId>
-{
-    /// Verifies whether relationship is active
-    pub fn is_active(&self) -> bool {
-        self.next_payment_at_block.is_some()
-    }
-
-    /// Make clone which is activated.
-    pub fn clone_activated(&self, start_at: &BlockNumber) -> Self {
-        Self {
-            next_payment_at_block: Some((*start_at).clone()),
-            ..((*self).clone())
-        }
-    }
-
-    /// Make clone which is deactivated
-    pub fn clone_deactivated(&self) -> Self {
-        Self {
-            next_payment_at_block: None,
-            ..((*self).clone())
-        }
-    }
-}
-
-decl_storage! {
-    trait Store for Module<T: Trait> as RecurringReward {
-        Recipients get(fn recipients): map hasher(blake2_128_concat)
-            T::RecipientId => Recipient<BalanceOf<T>>;
-
-        RecipientsCreated get(fn recipients_created): T::RecipientId;
-
-        pub RewardRelationships get(fn reward_relationships): map hasher(blake2_128_concat)
-            T::RewardRelationshipId => RewardRelationship<T::AccountId, BalanceOf<T>, T::BlockNumber, T::MintId, T::RecipientId>;
-
-        RewardRelationshipsCreated get(fn reward_relationships_created): T::RewardRelationshipId;
-    }
-}
-
-decl_module! {
-    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
-
-        fn on_finalize(now: T::BlockNumber) {
-            Self::do_payouts(now);
-        }
-    }
-}
-
-#[derive(Eq, PartialEq, Debug)]
-pub enum RewardsError {
-    RecipientNotFound,
-    RewardSourceNotFound,
-    NextPaymentNotInFuture,
-    RewardRelationshipNotFound,
-}
-
-impl<T: Trait> Module<T> {
-    /// Adds a new Recipient and returns new recipient identifier.
-    pub fn add_recipient() -> T::RecipientId {
-        let next_id = Self::recipients_created();
-        <RecipientsCreated<T>>::put(next_id + One::one());
-        <Recipients<T>>::insert(&next_id, Recipient::default());
-        next_id
-    }
-
-    /// Adds a new RewardRelationship, for a given source mint, recipient, account.
-    pub fn add_reward_relationship(
-        mint_id: T::MintId,
-        recipient: T::RecipientId,
-        account: T::AccountId,
-        amount_per_payout: BalanceOf<T>,
-        next_payment_at_block: T::BlockNumber,
-        payout_interval: Option<T::BlockNumber>,
-    ) -> Result<T::RewardRelationshipId, RewardsError> {
-        ensure!(
-            <minting::Module<T>>::mint_exists(mint_id),
-            RewardsError::RewardSourceNotFound
-        );
-        ensure!(
-            <Recipients<T>>::contains_key(recipient),
-            RewardsError::RecipientNotFound
-        );
-        ensure!(
-            next_payment_at_block > <frame_system::Module<T>>::block_number(),
-            RewardsError::NextPaymentNotInFuture
-        );
-
-        let relationship_id = Self::reward_relationships_created();
-        <RewardRelationshipsCreated<T>>::put(relationship_id + One::one());
-        <RewardRelationships<T>>::insert(
-            relationship_id,
-            RewardRelationship {
-                mint_id,
-                recipient,
-                account,
-                amount_per_payout,
-                next_payment_at_block: Some(next_payment_at_block),
-                payout_interval,
-                total_reward_received: Zero::zero(),
-                total_reward_missed: Zero::zero(),
-            },
-        );
-        Ok(relationship_id)
-    }
-
-    /// Removes a relationship from RewardRelashionships and its recipient.
-    pub fn remove_reward_relationship(id: T::RewardRelationshipId) {
-        if <RewardRelationships<T>>::contains_key(&id) {
-            <Recipients<T>>::remove(<RewardRelationships<T>>::take(&id).recipient);
-        }
-    }
-
-    /// Will attempt to activat a deactivated reward relationship.
-    pub fn try_to_activate_relationship(
-        id: T::RewardRelationshipId,
-        next_payment_at_block: T::BlockNumber,
-    ) -> Result<bool, ()> {
-        // Ensure relationship exists
-        let reward_relationship = Self::ensure_reward_relationship_exists(&id)?;
-
-        let activated = if reward_relationship.is_active() {
-            // Was not activated
-            false
-        } else {
-            // Update as activated
-            let activated_relationship =
-                reward_relationship.clone_activated(&next_payment_at_block);
-
-            RewardRelationships::<T>::insert(id, activated_relationship);
-
-            // We activated
-            true
-        };
-
-        Ok(activated)
-    }
-
-    /// Will attempt to deactivat a activated reward relationship.
-    pub fn try_to_deactivate_relationship(id: T::RewardRelationshipId) -> Result<bool, ()> {
-        // Ensure relationship exists
-        let reward_relationship = Self::ensure_reward_relationship_exists(&id)?;
-
-        let deactivated = if reward_relationship.is_active() {
-            let deactivated_relationship = reward_relationship.clone_deactivated();
-
-            RewardRelationships::<T>::insert(id, deactivated_relationship);
-
-            // Was deactivated
-            true
-        } else {
-            // Was not deactivated
-            false
-        };
-
-        Ok(deactivated)
-    }
-
-    // For reward relationship found with given identifier, new values can be set for
-    // account, payout, block number when next payout will be made and the new interval after
-    // the next scheduled payout. All values are optional, but updating values are combined in this
-    // single method to ensure atomic updates.
-    pub fn set_reward_relationship(
-        id: T::RewardRelationshipId,
-        new_account: Option<T::AccountId>,
-        new_payout: Option<BalanceOf<T>>,
-        new_next_payment_at: Option<Option<T::BlockNumber>>,
-        new_payout_interval: Option<Option<T::BlockNumber>>,
-    ) -> Result<(), RewardsError> {
-        ensure!(
-            <RewardRelationships<T>>::contains_key(&id),
-            RewardsError::RewardRelationshipNotFound
-        );
-
-        let mut relationship = Self::reward_relationships(&id);
-
-        if let Some(account) = new_account {
-            relationship.account = account;
-        }
-        if let Some(payout) = new_payout {
-            relationship.amount_per_payout = payout;
-        }
-        if let Some(next_payout_at_block) = new_next_payment_at {
-            if let Some(blocknumber) = next_payout_at_block {
-                ensure!(
-                    blocknumber > <frame_system::Module<T>>::block_number(),
-                    RewardsError::NextPaymentNotInFuture
-                );
-            }
-            relationship.next_payment_at_block = next_payout_at_block;
-        }
-        if let Some(payout_interval) = new_payout_interval {
-            relationship.payout_interval = payout_interval;
-        }
-
-        <RewardRelationships<T>>::insert(&id, relationship);
-        Ok(())
-    }
-
-    /*
-    For all relationships where next_payment_at_block is set and matches current block height,
-    a call to pay_reward is made for the suitable amount, recipient and source.
-    The next_payment_in_block is updated based on payout_interval.
-    If the call succeeds, total_reward_received is incremented on both
-    recipient and dependency with amount_per_payout, and a call to T::PayoutStatusHandler is made.
-    Otherwise, analogous steps for failure.
-    */
-    fn do_payouts(now: T::BlockNumber) {
-        for (relationship_id, ref mut relationship) in <RewardRelationships<T>>::iter() {
-            assert!(<Recipients<T>>::contains_key(&relationship.recipient));
-
-            let mut recipient = Self::recipients(relationship.recipient);
-
-            if let Some(next_payment_at_block) = relationship.next_payment_at_block {
-                if next_payment_at_block != now {
-                    continue;
-                }
-
-                // Add the missed payout and try to pay those in addition to scheduled payout?
-                // let payout = relationship.total_reward_missed + relationship.amount_per_payout;
-                let payout = relationship.amount_per_payout;
-
-                // try to make payment
-                if <minting::Module<T>>::transfer_tokens(
-                    relationship.mint_id,
-                    payout,
-                    &relationship.account,
-                )
-                .is_err()
-                {
-                    // add only newly scheduled payout to total missed payout
-                    relationship.total_reward_missed += relationship.amount_per_payout;
-
-                    // update recipient stats
-                    recipient.total_reward_missed += relationship.amount_per_payout;
-
-                    T::PayoutStatusHandler::payout_failed(
-                        relationship_id,
-                        &relationship.account,
-                        payout,
-                    );
-                } else {
-                    // update payout received stats
-                    relationship.total_reward_received += payout;
-                    recipient.total_reward_received += payout;
-
-                    // update missed payout stats
-                    // if relationship.total_reward_missed != Zero::zero() {
-                    //     // update recipient stats
-                    //     recipient.total_reward_missed -= relationship.total_reward_missed;
-
-                    //     // clear missed reward on relationship
-                    //     relationship.total_reward_missed = Zero::zero();
-                    // }
-                    T::PayoutStatusHandler::payout_succeeded(
-                        relationship_id,
-                        &relationship.account,
-                        payout,
-                    );
-                }
-
-                // update next payout blocknumber at interval if set
-                if let Some(payout_interval) = relationship.payout_interval {
-                    relationship.next_payment_at_block = Some(now + payout_interval);
-                } else {
-                    relationship.next_payment_at_block = None;
-                }
-
-                <Recipients<T>>::insert(relationship.recipient, recipient);
-                <RewardRelationships<T>>::insert(relationship_id, relationship);
-            }
-        }
-    }
-}
-
-impl<T: Trait> Module<T> {
-    fn ensure_reward_relationship_exists(
-        id: &T::RewardRelationshipId,
-    ) -> Result<
-        RewardRelationship<T::AccountId, BalanceOf<T>, T::BlockNumber, T::MintId, T::RecipientId>,
-        (),
-    > {
-        ensure!(RewardRelationships::<T>::contains_key(id), ());
-
-        let relationship = RewardRelationships::<T>::get(id);
-
-        Ok(relationship)
-    }
-}

+ 0 - 99
runtime-modules/recurring-reward/src/mock/mod.rs

@@ -1,99 +0,0 @@
-#![cfg(test)]
-
-use crate::{Module, Trait};
-
-use balances;
-use frame_support::{impl_outer_origin, parameter_types};
-use minting;
-use sp_core::H256;
-use sp_runtime::{
-    testing::Header,
-    traits::{BlakeTwo256, IdentityLookup},
-    Perbill,
-};
-
-mod status_handler;
-pub use status_handler::MockStatusHandler;
-
-impl_outer_origin! {
-    pub enum Origin for Test {}
-}
-
-// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
-#[derive(Clone, PartialEq, Eq, Debug)]
-pub struct Test;
-parameter_types! {
-    pub const BlockHashCount: u64 = 250;
-    pub const MaximumBlockWeight: u32 = 1024;
-    pub const MaximumBlockLength: u32 = 2 * 1024;
-    pub const AvailableBlockRatio: Perbill = Perbill::one();
-    pub const MinimumPeriod: u64 = 5;
-}
-
-impl frame_system::Trait for Test {
-    type BaseCallFilter = ();
-    type Origin = Origin;
-    type Call = ();
-    type Index = u64;
-    type BlockNumber = u64;
-    type Hash = H256;
-    type Hashing = BlakeTwo256;
-    type AccountId = u64;
-    type Lookup = IdentityLookup<Self::AccountId>;
-    type Header = Header;
-    type Event = ();
-    type BlockHashCount = BlockHashCount;
-    type MaximumBlockWeight = MaximumBlockWeight;
-    type DbWeight = ();
-    type BlockExecutionWeight = ();
-    type ExtrinsicBaseWeight = ();
-    type MaximumExtrinsicWeight = ();
-    type MaximumBlockLength = MaximumBlockLength;
-    type AvailableBlockRatio = AvailableBlockRatio;
-    type Version = ();
-    type PalletInfo = ();
-    type AccountData = balances::AccountData<u64>;
-    type OnNewAccount = ();
-    type OnKilledAccount = ();
-    type SystemWeightInfo = ();
-}
-
-parameter_types! {
-    pub const ExistentialDeposit: u32 = 0;
-}
-
-impl balances::Trait for Test {
-    type Balance = u64;
-    type DustRemoval = ();
-    type Event = ();
-    type ExistentialDeposit = ExistentialDeposit;
-    type AccountStore = System;
-    type WeightInfo = ();
-    type MaxLocks = ();
-}
-
-impl Trait for Test {
-    type PayoutStatusHandler = MockStatusHandler;
-    type RecipientId = u64;
-    type RewardRelationshipId = u64;
-}
-
-impl minting::Trait for Test {
-    type Currency = Balances;
-    type MintId = u64;
-}
-
-pub fn build_test_externalities() -> sp_io::TestExternalities {
-    MockStatusHandler::reset();
-
-    let t = frame_system::GenesisConfig::default()
-        .build_storage::<Test>()
-        .unwrap();
-
-    t.into()
-}
-
-pub type System = frame_system::Module<Test>;
-pub type Balances = balances::Module<Test>;
-pub type Rewards = Module<Test>;
-pub type Minting = minting::Module<Test>;

+ 0 - 64
runtime-modules/recurring-reward/src/mock/status_handler.rs

@@ -1,64 +0,0 @@
-#![cfg(test)]
-
-use super::Test;
-use crate::{PayoutStatusHandler, Trait};
-use std::cell::RefCell;
-
-struct StatusHandlerState<T: Trait> {
-    successes: Vec<T::RewardRelationshipId>,
-    failures: Vec<T::RewardRelationshipId>,
-}
-
-impl<T: Trait> StatusHandlerState<T> {
-    pub fn reset(&mut self) {
-        self.successes = vec![];
-        self.failures = vec![];
-    }
-}
-
-impl<T: Trait> Default for StatusHandlerState<T> {
-    fn default() -> Self {
-        Self {
-            successes: vec![],
-            failures: vec![],
-        }
-    }
-}
-
-thread_local!(static STATUS_HANDLER_STATE: RefCell<StatusHandlerState<Test>> = RefCell::new(Default::default()));
-
-pub struct MockStatusHandler {}
-impl MockStatusHandler {
-    pub fn reset() {
-        STATUS_HANDLER_STATE.with(|cell| {
-            cell.borrow_mut().reset();
-        });
-    }
-    pub fn successes() -> usize {
-        let mut value = 0;
-        STATUS_HANDLER_STATE.with(|cell| {
-            value = cell.borrow_mut().successes.len();
-        });
-        value
-    }
-    pub fn failures() -> usize {
-        let mut value = 0;
-        STATUS_HANDLER_STATE.with(|cell| {
-            value = cell.borrow_mut().failures.len();
-        });
-        value
-    }
-}
-impl PayoutStatusHandler<Test> for MockStatusHandler {
-    fn payout_succeeded(id: u64, _destination_account: &u64, _amount: u64) {
-        STATUS_HANDLER_STATE.with(|cell| {
-            cell.borrow_mut().successes.push(id);
-        });
-    }
-
-    fn payout_failed(id: u64, _destination_account: &u64, _amount: u64) {
-        STATUS_HANDLER_STATE.with(|cell| {
-            cell.borrow_mut().failures.push(id);
-        });
-    }
-}

+ 0 - 259
runtime-modules/recurring-reward/src/tests.rs

@@ -1,259 +0,0 @@
-#![cfg(test)]
-
-use super::*;
-use crate::mock::*;
-use frame_support::traits::Currency;
-
-fn create_new_mint_with_capacity(capacity: u64) -> u64 {
-    let mint_id = Minting::add_mint(capacity, None).ok().unwrap();
-    assert!(Minting::mint_exists(mint_id));
-    assert_eq!(Minting::get_mint_capacity(mint_id).ok().unwrap(), capacity);
-    mint_id
-}
-
-#[test]
-fn adding_recipients() {
-    build_test_externalities().execute_with(|| {
-        let next_id = Rewards::recipients_created();
-        assert!(!<Recipients<Test>>::contains_key(&next_id));
-        let recipient_id = Rewards::add_recipient();
-        assert!(<Recipients<Test>>::contains_key(&next_id));
-        assert_eq!(recipient_id, next_id);
-        assert_eq!(Rewards::recipients_created(), next_id + 1);
-    });
-}
-
-#[test]
-fn adding_relationships() {
-    build_test_externalities().execute_with(|| {
-        let recipient_account: u64 = 1;
-        let mint_id = create_new_mint_with_capacity(1000000);
-        let recipient_id = Rewards::add_recipient();
-        let interval: u64 = 600;
-        let next_payment_at: u64 = 2222;
-        let payout = 100;
-
-        let next_relationship_id = Rewards::reward_relationships_created();
-        let relationship = Rewards::add_reward_relationship(
-            mint_id,
-            recipient_id,
-            recipient_account,
-            payout,
-            next_payment_at,
-            Some(interval),
-        );
-        assert!(relationship.is_ok());
-        let relationship_id = relationship.ok().unwrap();
-        assert_eq!(relationship_id, next_relationship_id);
-        assert_eq!(
-            Rewards::reward_relationships_created(),
-            next_relationship_id + 1
-        );
-        assert!(<RewardRelationships<Test>>::contains_key(&relationship_id));
-        let relationship = Rewards::reward_relationships(&relationship_id);
-        assert_eq!(relationship.next_payment_at_block, Some(next_payment_at));
-        assert_eq!(relationship.amount_per_payout, payout);
-        assert_eq!(relationship.mint_id, mint_id);
-        assert_eq!(relationship.account, recipient_account);
-        assert_eq!(relationship.payout_interval, Some(interval));
-
-        // mint doesn't exist
-        assert_eq!(
-            Rewards::add_reward_relationship(
-                111,
-                recipient_id,
-                recipient_account,
-                100,
-                next_payment_at,
-                None,
-            )
-            .expect_err("should fail if mint doesn't exist"),
-            RewardsError::RewardSourceNotFound
-        );
-    });
-}
-
-#[test]
-fn one_off_payout() {
-    build_test_externalities().execute_with(|| {
-        System::set_block_number(10000);
-        let recipient_account: u64 = 1;
-        let _ = Balances::deposit_creating(&recipient_account, 400);
-        let mint_id = create_new_mint_with_capacity(1000000);
-        let recipient_id = Rewards::add_recipient();
-        let payout: u64 = 1000;
-        let next_payout_at: u64 = 12222;
-        let relationship = Rewards::add_reward_relationship(
-            mint_id,
-            recipient_id,
-            recipient_account,
-            payout,
-            next_payout_at,
-            None,
-        );
-        assert!(relationship.is_ok());
-        let relationship_id = relationship.ok().unwrap();
-
-        let relationship = Rewards::reward_relationships(&relationship_id);
-        assert_eq!(relationship.next_payment_at_block, Some(next_payout_at));
-
-        let starting_balance = Balances::free_balance(&recipient_account);
-
-        // try to catch 'off by one' bugs
-        Rewards::do_payouts(next_payout_at - 1);
-        assert_eq!(Balances::free_balance(&recipient_account), starting_balance);
-        Rewards::do_payouts(next_payout_at + 1);
-        assert_eq!(Balances::free_balance(&recipient_account), starting_balance);
-
-        assert_eq!(MockStatusHandler::successes(), 0);
-
-        Rewards::do_payouts(next_payout_at);
-        assert_eq!(
-            Balances::free_balance(&recipient_account),
-            starting_balance + payout
-        );
-        assert_eq!(MockStatusHandler::successes(), 1);
-
-        let relationship = Rewards::reward_relationships(&relationship_id);
-        assert_eq!(relationship.total_reward_received, payout);
-        assert_eq!(relationship.next_payment_at_block, None);
-
-        let recipient = Rewards::recipients(&recipient_id);
-        assert_eq!(recipient.total_reward_received, payout);
-    });
-}
-
-#[test]
-fn recurring_payout() {
-    build_test_externalities().execute_with(|| {
-        System::set_block_number(10000);
-        let recipient_account: u64 = 1;
-        let _ = Balances::deposit_creating(&recipient_account, 400);
-        let mint_id = create_new_mint_with_capacity(1000000);
-        let recipient_id = Rewards::add_recipient();
-        let payout: u64 = 1000;
-        let next_payout_at: u64 = 12222;
-        let interval: u64 = 600;
-        let relationship = Rewards::add_reward_relationship(
-            mint_id,
-            recipient_id,
-            recipient_account,
-            payout,
-            next_payout_at,
-            Some(interval),
-        );
-        assert!(relationship.is_ok());
-        let relationship_id = relationship.ok().unwrap();
-
-        let relationship = Rewards::reward_relationships(&relationship_id);
-        assert_eq!(relationship.next_payment_at_block, Some(next_payout_at));
-
-        let starting_balance = Balances::free_balance(&recipient_account);
-
-        let number_of_payouts = 3;
-        for i in 0..number_of_payouts {
-            Rewards::do_payouts(next_payout_at + interval * i);
-        }
-        assert_eq!(MockStatusHandler::successes(), number_of_payouts as usize);
-
-        assert_eq!(
-            Balances::free_balance(&recipient_account),
-            starting_balance + payout * number_of_payouts
-        );
-
-        let relationship = Rewards::reward_relationships(&relationship_id);
-        assert_eq!(
-            relationship.total_reward_received,
-            payout * number_of_payouts
-        );
-
-        let recipient = Rewards::recipients(&recipient_id);
-        assert_eq!(recipient.total_reward_received, payout * number_of_payouts);
-    });
-}
-
-#[test]
-fn track_missed_payouts() {
-    build_test_externalities().execute_with(|| {
-        System::set_block_number(10000);
-        let recipient_account: u64 = 1;
-        let _ = Balances::deposit_creating(&recipient_account, 400);
-        let mint_id = create_new_mint_with_capacity(0);
-        let recipient_id = Rewards::add_recipient();
-        let payout: u64 = 1000;
-        let next_payout_at: u64 = 12222;
-        let relationship = Rewards::add_reward_relationship(
-            mint_id,
-            recipient_id,
-            recipient_account,
-            payout,
-            next_payout_at,
-            None,
-        );
-        assert!(relationship.is_ok());
-        let relationship_id = relationship.ok().unwrap();
-
-        let relationship = Rewards::reward_relationships(&relationship_id);
-        assert_eq!(relationship.next_payment_at_block, Some(next_payout_at));
-
-        let starting_balance = Balances::free_balance(&recipient_account);
-
-        Rewards::do_payouts(next_payout_at);
-        assert_eq!(Balances::free_balance(&recipient_account), starting_balance);
-
-        assert_eq!(MockStatusHandler::failures(), 1);
-
-        let relationship = Rewards::reward_relationships(&relationship_id);
-        assert_eq!(relationship.total_reward_received, 0);
-        assert_eq!(relationship.total_reward_missed, payout);
-
-        let recipient = Rewards::recipients(&recipient_id);
-        assert_eq!(recipient.total_reward_received, 0);
-        assert_eq!(recipient.total_reward_missed, payout);
-    });
-}
-
-#[test]
-fn activate_and_deactivate_relationship() {
-    build_test_externalities().execute_with(|| {
-        System::set_block_number(10000);
-        let recipient_account: u64 = 1;
-        let _ = Balances::deposit_creating(&recipient_account, 400);
-        let mint_id = create_new_mint_with_capacity(0);
-        let recipient_id = Rewards::add_recipient();
-        let payout: u64 = 1000;
-        let next_payout_at: u64 = 12222;
-
-        // Add relationship
-        let relationship_id = Rewards::add_reward_relationship(
-            mint_id,
-            recipient_id,
-            recipient_account,
-            payout,
-            next_payout_at,
-            None,
-        )
-        .unwrap();
-
-        // The relationship starts out active
-        assert!(Rewards::reward_relationships(&relationship_id).is_active());
-
-        // We are able to deactivate relationship
-        assert!(Rewards::try_to_deactivate_relationship(relationship_id).unwrap());
-
-        // The relationship is no longer active
-        assert!(!Rewards::reward_relationships(&relationship_id).is_active());
-
-        // We cannot deactivate an already deactivated relationship
-        assert!(!Rewards::try_to_deactivate_relationship(relationship_id).unwrap());
-
-        // We are able to activate relationship
-        assert!(Rewards::try_to_activate_relationship(relationship_id, next_payout_at).unwrap());
-
-        // The relationship is now not active
-        assert!(Rewards::reward_relationships(&relationship_id).is_active());
-
-        // We cannot activate an already active relationship
-        assert!(!Rewards::try_to_activate_relationship(relationship_id, next_payout_at).unwrap());
-    });
-}