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
#[frame_support::pallet(dev_mode)]
pub mod pallet {
	use frame_support::pallet_prelude::*;
	use mock_builder::{execute_call, register_call};
	use orml_traits::asset_registry::{AssetMetadata, Inspect, Mutate};
	use sp_std::fmt::Debug;
	use staging_xcm::{v4::Location, VersionedLocation};

	#[pallet::config]
	pub trait Config: frame_system::Config {
		type AssetId;
		type Balance: Clone + Debug + Eq + PartialEq;
		type CustomMetadata: Parameter + Member + TypeInfo;
		type StringLimit: Get<u32>;
	}

	#[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_asset_id(f: impl Fn(&Location) -> Option<T::AssetId> + 'static) {
			register_call!(f);
		}

		pub fn mock_metadata(
			f: impl Fn(
					&T::AssetId,
				) -> Option<AssetMetadata<T::Balance, T::CustomMetadata, T::StringLimit>>
				+ 'static,
		) {
			register_call!(f);
		}

		pub fn mock_metadata_by_location(
			f: impl Fn(
					&Location,
				) -> Option<AssetMetadata<T::Balance, T::CustomMetadata, T::StringLimit>>
				+ 'static,
		) {
			register_call!(f);
		}

		pub fn mock_location(
			f: impl Fn(&T::AssetId) -> Result<Option<Location>, DispatchError> + 'static,
		) {
			register_call!(f);
		}

		pub fn mock_register_asset(
			f: impl Fn(
					Option<T::AssetId>,
					AssetMetadata<T::Balance, T::CustomMetadata, T::StringLimit>,
				) -> DispatchResult
				+ 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}

		pub fn mock_update_asset(
			f: impl Fn(
					T::AssetId,
					Option<u32>,
					Option<BoundedVec<u8, T::StringLimit>>,
					Option<BoundedVec<u8, T::StringLimit>>,
					Option<T::Balance>,
					Option<Option<VersionedLocation>>,
					Option<T::CustomMetadata>,
				) -> DispatchResult
				+ 'static,
		) {
			register_call!(move |(a, b, c, d, e, g, h)| f(a, b, c, d, e, g, h));
		}
	}

	impl<T: Config> Inspect for Pallet<T> {
		type AssetId = T::AssetId;
		type Balance = T::Balance;
		type CustomMetadata = T::CustomMetadata;
		type StringLimit = T::StringLimit;

		fn asset_id(a: &Location) -> Option<Self::AssetId> {
			execute_call!(a)
		}

		fn metadata(
			a: &Self::AssetId,
		) -> Option<AssetMetadata<Self::Balance, Self::CustomMetadata, Self::StringLimit>> {
			execute_call!(a)
		}

		fn metadata_by_location(
			a: &Location,
		) -> Option<AssetMetadata<Self::Balance, Self::CustomMetadata, Self::StringLimit>> {
			execute_call!(a)
		}

		fn location(a: &Self::AssetId) -> Result<Option<Location>, DispatchError> {
			execute_call!(a)
		}
	}

	impl<T: Config> Mutate for Pallet<T> {
		fn register_asset(
			a: Option<Self::AssetId>,
			b: AssetMetadata<Self::Balance, Self::CustomMetadata, Self::StringLimit>,
		) -> DispatchResult {
			execute_call!((a, b))
		}

		fn update_asset(
			a: Self::AssetId,
			b: Option<u32>,
			c: Option<BoundedVec<u8, Self::StringLimit>>,
			d: Option<BoundedVec<u8, Self::StringLimit>>,
			e: Option<Self::Balance>,
			g: Option<Option<VersionedLocation>>,
			h: Option<Self::CustomMetadata>,
		) -> DispatchResult {
			execute_call!((a, b, c, d, e, g, h))
		}
	}
}