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
#[frame_support::pallet(dev_mode)]
pub mod pallet {
	use cfg_traits::investments::{Investment, InvestmentCollector};
	use frame_support::pallet_prelude::*;
	use mock_builder::{execute_call, register_call};

	#[pallet::config]
	pub trait Config: frame_system::Config {
		type Amount;
		type TrancheAmount;
		type CurrencyId;
		type InvestmentId;
	}

	#[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_update_investment(
			f: impl Fn(&T::AccountId, T::InvestmentId, T::Amount) -> DispatchResult + 'static,
		) {
			register_call!(move |(a, b, c)| f(a, b, c));
		}

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

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

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

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

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

	impl<T: Config> Investment<T::AccountId> for Pallet<T> {
		type Amount = T::Amount;
		type CurrencyId = T::CurrencyId;
		type Error = DispatchError;
		type InvestmentId = T::InvestmentId;
		type TrancheAmount = T::TrancheAmount;

		fn update_investment(
			a: &T::AccountId,
			b: Self::InvestmentId,
			c: Self::Amount,
		) -> DispatchResult {
			execute_call!((a, b, c))
		}

		fn investment(
			a: &T::AccountId,
			b: Self::InvestmentId,
		) -> Result<Self::Amount, Self::Error> {
			execute_call!((a, b))
		}

		fn update_redemption(
			a: &T::AccountId,
			b: Self::InvestmentId,
			c: Self::TrancheAmount,
		) -> DispatchResult {
			execute_call!((a, b, c))
		}

		fn redemption(
			a: &T::AccountId,
			b: Self::InvestmentId,
		) -> Result<Self::TrancheAmount, Self::Error> {
			execute_call!((a, b))
		}
	}

	impl<T: Config> InvestmentCollector<T::AccountId> for Pallet<T> {
		type Error = DispatchError;
		type InvestmentId = T::InvestmentId;
		type Result = ();

		fn collect_investment(
			a: T::AccountId,
			b: Self::InvestmentId,
		) -> Result<Self::Result, Self::Error> {
			execute_call!((a, b))
		}

		fn collect_redemption(
			a: T::AccountId,
			b: Self::InvestmentId,
		) -> Result<Self::Result, Self::Error> {
			execute_call!((a, b))
		}
	}
}