1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#[frame_support::pallet(dev_mode)]
pub mod pallet {
	use cfg_traits::rewards::{AccountRewards, CurrencyGroupChange, GroupRewards};
	use frame_support::pallet_prelude::*;
	use mock_builder::{execute_call, register_call};

	#[pallet::config]
	pub trait Config: frame_system::Config {
		type Balance;
		type GroupId;
		type CurrencyId;
	}

	#[pallet::pallet]
	pub struct Pallet<T>(_);

	#[pallet::storage]
	type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>;

	impl<T: Config> Pallet<T> {
		pub fn mock_is_ready(f: impl Fn(T::GroupId) -> bool + 'static) {
			register_call!(f);
		}

		pub fn mock_reward_group(
			f: impl Fn(T::GroupId, T::Balance) -> Result<T::Balance, DispatchError> + 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}

		pub fn mock_group_stake(f: impl Fn(T::GroupId) -> T::Balance + 'static) {
			register_call!(f);
		}

		pub fn mock_deposit_stake(
			f: impl Fn(T::CurrencyId, &T::AccountId, T::Balance) -> DispatchResult + 'static,
		) {
			register_call!(move |(a, b, c)| f(a, b, c));
		}

		pub fn mock_withdraw_stake(
			f: impl Fn(T::CurrencyId, &T::AccountId, T::Balance) -> DispatchResult + 'static,
		) {
			register_call!(move |(a, b, c)| f(a, b, c));
		}

		pub fn mock_compute_reward(
			f: impl Fn(T::CurrencyId, &T::AccountId) -> Result<T::Balance, DispatchError> + 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}

		pub fn mock_claim_reward(
			f: impl Fn(T::CurrencyId, &T::AccountId) -> Result<T::Balance, DispatchError> + 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}

		pub fn mock_account_stake(
			f: impl Fn(T::CurrencyId, &T::AccountId) -> T::Balance + 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}

		pub fn mock_attach_currency(
			f: impl Fn(T::CurrencyId, T::GroupId) -> DispatchResult + 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}

		pub fn mock_currency_group(f: impl Fn(T::CurrencyId) -> Option<T::GroupId> + 'static) {
			register_call!(f);
		}
	}

	impl<T: Config> GroupRewards for Pallet<T> {
		type Balance = T::Balance;
		type GroupId = T::GroupId;

		fn is_ready(a: T::GroupId) -> bool {
			execute_call!(a)
		}

		fn reward_group(a: T::GroupId, b: T::Balance) -> Result<T::Balance, DispatchError> {
			execute_call!((a, b))
		}

		fn group_stake(a: T::GroupId) -> T::Balance {
			execute_call!(a)
		}
	}

	impl<T: Config> AccountRewards<T::AccountId> for Pallet<T> {
		type Balance = T::Balance;
		type CurrencyId = T::CurrencyId;

		fn deposit_stake(a: T::CurrencyId, b: &T::AccountId, c: T::Balance) -> DispatchResult {
			execute_call!((a, b, c))
		}

		fn withdraw_stake(a: T::CurrencyId, b: &T::AccountId, c: T::Balance) -> DispatchResult {
			execute_call!((a, b, c))
		}

		fn compute_reward(a: T::CurrencyId, b: &T::AccountId) -> Result<T::Balance, DispatchError> {
			execute_call!((a, b))
		}

		fn claim_reward(a: T::CurrencyId, b: &T::AccountId) -> Result<T::Balance, DispatchError> {
			execute_call!((a, b))
		}

		fn account_stake(a: T::CurrencyId, b: &T::AccountId) -> T::Balance {
			execute_call!((a, b))
		}
	}

	impl<T: Config> CurrencyGroupChange for Pallet<T> {
		type CurrencyId = T::CurrencyId;
		type GroupId = T::GroupId;

		fn attach_currency(a: T::CurrencyId, b: T::GroupId) -> DispatchResult {
			execute_call!((a, b))
		}

		fn currency_group(a: T::CurrencyId) -> Option<T::GroupId> {
			execute_call!(a)
		}
	}
}