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
#[frame_support::pallet(dev_mode)]
pub mod pallet {
	use cfg_traits::liquidity_pools::{MessageProcessor, OutboundMessageHandler};
	use frame_support::pallet_prelude::*;
	use mock_builder::{execute_call, register_call, CallHandler};
	use orml_traits::GetByKey;

	#[pallet::config]
	pub trait Config: frame_system::Config {
		type Message;
		type Destination;
	}

	#[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_process(
			f: impl Fn(T::Message) -> (DispatchResult, Weight) + 'static,
		) -> CallHandler {
			register_call!(f)
		}

		pub fn mock_max_processing_weight(f: impl Fn(&T::Message) -> Weight + 'static) {
			register_call!(f);
		}

		pub fn mock_get(f: impl Fn(&T::Destination) -> Option<[u8; 20]> + 'static) {
			register_call!(f);
		}

		pub fn mock_handle(
			f: impl Fn(T::AccountId, T::Destination, T::Message) -> DispatchResult + 'static,
		) {
			register_call!(move |(sender, destination, msg)| f(sender, destination, msg));
		}
	}

	impl<T: Config> MessageProcessor for Pallet<T> {
		type Message = T::Message;

		fn process(msg: Self::Message) -> (DispatchResult, Weight) {
			execute_call!(msg)
		}

		fn max_processing_weight(msg: &Self::Message) -> Weight {
			execute_call!(msg)
		}
	}

	impl<T: Config> GetByKey<T::Destination, Option<[u8; 20]>> for Pallet<T> {
		fn get(a: &T::Destination) -> Option<[u8; 20]> {
			execute_call!(a)
		}
	}

	impl<T: Config> OutboundMessageHandler for Pallet<T> {
		type Destination = T::Destination;
		type Message = T::Message;
		type Sender = T::AccountId;

		fn handle(
			sender: Self::Sender,
			destination: Self::Destination,
			msg: Self::Message,
		) -> DispatchResult {
			execute_call!((sender, destination, msg))
		}
	}
}