1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonbeam is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
// We want to avoid including the rococo-runtime here.
18
// TODO: whenever a conclusion is taken from https://github.com/paritytech/substrate/issues/8158
19

            
20
use cumulus_primitives_core::{relay_chain::HrmpChannelId, ParaId};
21
use pallet_xcm_transactor::relay_indices::RelayChainIndices;
22
use parity_scale_codec::{Decode, Encode};
23
use sp_runtime::traits::{AccountIdLookup, StaticLookup};
24
use sp_runtime::AccountId32;
25
use sp_std::vec::Vec;
26

            
27
#[derive(Encode, Decode)]
28
pub enum RelayCall {
29
	#[codec(index = 6u8)]
30
	Stake(StakeCall),
31
	#[codec(index = 24u8)]
32
	// the index should match the position of the module in `construct_runtime!`
33
	Utility(UtilityCall),
34
	#[codec(index = 60u8)]
35
	// the index should match the position of the module in `construct_runtime!`
36
	Hrmp(HrmpCall),
37
}
38

            
39
#[derive(Encode, Decode)]
40
pub enum StakeCall {
41
	#[codec(index = 0u16)]
42
	// the index should match the position of the dispatchable in the target pallet
43
	Bond(
44
		#[codec(compact)] cumulus_primitives_core::relay_chain::Balance,
45
		pallet_staking::RewardDestination<AccountId32>,
46
	),
47
	#[codec(index = 1u16)]
48
	BondExtra(#[codec(compact)] cumulus_primitives_core::relay_chain::Balance),
49
	#[codec(index = 2u16)]
50
	Unbond(#[codec(compact)] cumulus_primitives_core::relay_chain::Balance),
51
	#[codec(index = 3u16)]
52
	WithdrawUnbonded(u32),
53
	#[codec(index = 4u16)]
54
	Validate(pallet_staking::ValidatorPrefs),
55
	#[codec(index = 5u16)]
56
	Nominate(Vec<<AccountIdLookup<AccountId32, ()> as StaticLookup>::Source>),
57
	#[codec(index = 6u16)]
58
	Chill,
59
	#[codec(index = 7u16)]
60
	SetPayee(pallet_staking::RewardDestination<AccountId32>),
61
	#[codec(index = 8u16)]
62
	SetController,
63
	#[codec(index = 19u16)]
64
	Rebond(#[codec(compact)] cumulus_primitives_core::relay_chain::Balance),
65
}
66

            
67
// Utility call encoding, needed for xcm transactor pallet
68
#[derive(Encode, Decode)]
69
pub enum UtilityCall {
70
	#[codec(index = 1u8)]
71
	AsDerivative(u16),
72
}
73

            
74
// HRMP call encoding, needed for xcm transactor pallet
75
#[derive(Encode, Decode)]
76
pub enum HrmpCall {
77
	#[codec(index = 0u8)]
78
	InitOpenChannel(ParaId, u32, u32),
79
	#[codec(index = 1u8)]
80
	AcceptOpenChannel(ParaId),
81
	#[codec(index = 2u8)]
82
	CloseChannel(HrmpChannelId),
83
	#[codec(index = 6u8)]
84
	CancelOpenRequest(HrmpChannelId, u32),
85
}
86

            
87
pub struct KusamaEncoder;
88

            
89
impl xcm_primitives::UtilityEncodeCall for KusamaEncoder {
90
	fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec<u8> {
91
		match call {
92
			xcm_primitives::UtilityAvailableCalls::AsDerivative(a, b) => {
93
				let mut call = RelayCall::Utility(UtilityCall::AsDerivative(a.clone())).encode();
94
				// If we encode directly we inject the call length,
95
				// so we just append the inner call after encoding the outer
96
				call.append(&mut b.clone());
97
				call
98
			}
99
		}
100
	}
101
}
102

            
103
impl xcm_primitives::HrmpEncodeCall for KusamaEncoder {
104
	fn hrmp_encode_call(
105
		call: xcm_primitives::HrmpAvailableCalls,
106
	) -> Result<Vec<u8>, xcm::latest::Error> {
107
		match call {
108
			xcm_primitives::HrmpAvailableCalls::InitOpenChannel(a, b, c) => Ok(RelayCall::Hrmp(
109
				HrmpCall::InitOpenChannel(a.clone(), b.clone(), c.clone()),
110
			)
111
			.encode()),
112
			xcm_primitives::HrmpAvailableCalls::AcceptOpenChannel(a) => {
113
				Ok(RelayCall::Hrmp(HrmpCall::AcceptOpenChannel(a.clone())).encode())
114
			}
115
			xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
116
				Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
117
			}
118
			xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
119
				Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode())
120
			}
121
		}
122
	}
123
}
124

            
125
impl xcm_primitives::StakeEncodeCall for KusamaEncoder {
126
	fn encode_call(call: xcm_primitives::AvailableStakeCalls) -> Vec<u8> {
127
		match call {
128
			xcm_primitives::AvailableStakeCalls::Bond(b, c) => {
129
				RelayCall::Stake(StakeCall::Bond(b, c)).encode()
130
			}
131

            
132
			xcm_primitives::AvailableStakeCalls::BondExtra(a) => {
133
				RelayCall::Stake(StakeCall::BondExtra(a)).encode()
134
			}
135

            
136
			xcm_primitives::AvailableStakeCalls::Unbond(a) => {
137
				RelayCall::Stake(StakeCall::Unbond(a)).encode()
138
			}
139

            
140
			xcm_primitives::AvailableStakeCalls::WithdrawUnbonded(a) => {
141
				RelayCall::Stake(StakeCall::WithdrawUnbonded(a)).encode()
142
			}
143

            
144
			xcm_primitives::AvailableStakeCalls::Validate(a) => {
145
				RelayCall::Stake(StakeCall::Validate(a)).encode()
146
			}
147

            
148
			xcm_primitives::AvailableStakeCalls::Chill => {
149
				RelayCall::Stake(StakeCall::Chill).encode()
150
			}
151

            
152
			xcm_primitives::AvailableStakeCalls::SetPayee(a) => {
153
				RelayCall::Stake(StakeCall::SetPayee(a.into())).encode()
154
			}
155

            
156
			xcm_primitives::AvailableStakeCalls::SetController => {
157
				RelayCall::Stake(StakeCall::SetController).encode()
158
			}
159

            
160
			xcm_primitives::AvailableStakeCalls::Rebond(a) => {
161
				RelayCall::Stake(StakeCall::Rebond(a.into())).encode()
162
			}
163

            
164
			xcm_primitives::AvailableStakeCalls::Nominate(a) => {
165
				let nominated: Vec<<AccountIdLookup<AccountId32, ()> as StaticLookup>::Source> =
166
					a.iter().map(|add| (*add).clone().into()).collect();
167

            
168
				RelayCall::Stake(StakeCall::Nominate(nominated)).encode()
169
			}
170
		}
171
	}
172
}
173

            
174
/// Kusama pallet and extrinsic indices
175
pub const KUSAMA_RELAY_INDICES: RelayChainIndices = RelayChainIndices {
176
	staking: 6u8,
177
	utility: 24u8,
178
	hrmp: 60u8,
179
	bond: 0u8,
180
	bond_extra: 1u8,
181
	unbond: 2u8,
182
	withdraw_unbonded: 3u8,
183
	validate: 4u8,
184
	nominate: 5u8,
185
	chill: 6u8,
186
	set_payee: 7u8,
187
	set_controller: 8u8,
188
	rebond: 19u8,
189
	as_derivative: 1u8,
190
	init_open_channel: 0u8,
191
	accept_open_channel: 1u8,
192
	close_channel: 2u8,
193
	cancel_open_request: 6u8,
194
};
195
//
196
// #[cfg(test)]
197
// mod tests {
198
// 	use super::*;
199
// 	use crate::kusama::KusamaEncoder;
200
// 	use frame_support::traits::PalletInfo;
201
// 	use sp_runtime::Perbill;
202
// 	use xcm_primitives::{StakeEncodeCall, UtilityEncodeCall};
203
//
204
// 	#[test]
205
// 	fn test_as_derivative() {
206
// 		let mut expected_encoded: Vec<u8> = Vec::new();
207
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
208
// 			kusama_runtime::Utility,
209
// 		>()
210
// 		.unwrap() as u8;
211
// 		expected_encoded.push(index);
212
//
213
// 		let mut expected = pallet_utility::Call::<kusama_runtime::Runtime>::as_derivative {
214
// 			index: 1,
215
// 			call: kusama_runtime::RuntimeCall::Staking(pallet_staking::Call::<
216
// 				kusama_runtime::Runtime,
217
// 			>::chill {})
218
// 			.into(),
219
// 		}
220
// 		.encode();
221
// 		expected_encoded.append(&mut expected);
222
//
223
// 		let call_bytes = <KusamaEncoder as StakeEncodeCall>::encode_call(
224
// 			xcm_primitives::AvailableStakeCalls::Chill,
225
// 		);
226
//
227
// 		expected_encoded.append(&mut expected);
228
//
229
// 		assert_eq!(
230
// 			xcm_primitives::UtilityEncodeCall::encode_call(
231
// 				KusamaEncoder,
232
// 				xcm_primitives::UtilityAvailableCalls::AsDerivative(1, call_bytes.clone())
233
// 			),
234
// 			expected_encoded.clone()
235
// 		);
236
//
237
// 		sp_io::TestExternalities::default().execute_with(|| {
238
// 			// Pallet-xcm-transactor default encoder returns same result
239
// 			// insert storage item as per migration to set the storage item
240
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
241
// 				KUSAMA_RELAY_INDICES,
242
// 			);
243
// 			assert_eq!(
244
// 				<pallet_xcm_transactor::Pallet::<
245
// 					moonriver_runtime::Runtime> as UtilityEncodeCall
246
// 				>::encode_call(
247
// 					pallet_xcm_transactor::Pallet(
248
// 						sp_std::marker::PhantomData::<moonriver_runtime::Runtime>::default()),
249
// 					xcm_primitives::UtilityAvailableCalls::AsDerivative(1, call_bytes)
250
// 				),
251
// 				expected_encoded
252
// 			);
253
// 		});
254
// 	}
255
//
256
// 	#[test]
257
// 	fn test_stake_bond() {
258
// 		let mut expected_encoded: Vec<u8> = Vec::new();
259
//
260
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
261
// 			kusama_runtime::Staking,
262
// 		>()
263
// 		.unwrap() as u8;
264
// 		expected_encoded.push(index);
265
//
266
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::bond {
267
// 			value: 100u32.into(),
268
// 			payee: pallet_staking::RewardDestination::Controller,
269
// 		}
270
// 		.encode();
271
// 		expected_encoded.append(&mut expected);
272
//
273
// 		assert_eq!(
274
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
275
// 				xcm_primitives::AvailableStakeCalls::Bond(
276
// 					100u32.into(),
277
// 					pallet_staking::RewardDestination::Controller
278
// 				)
279
// 			),
280
// 			expected_encoded.clone()
281
// 		);
282
// 		sp_io::TestExternalities::default().execute_with(|| {
283
// 			// Pallet-xcm-transactor default encoder returns same result
284
// 			// insert storage item as per migration to set the storage item
285
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
286
// 				KUSAMA_RELAY_INDICES,
287
// 			);
288
// 			assert_eq!(
289
// 				<pallet_xcm_transactor::Pallet::<
290
// 					moonriver_runtime::Runtime> as StakeEncodeCall
291
// 				>::encode_call(
292
// 					xcm_primitives::AvailableStakeCalls::Bond(
293
// 							100u32.into(),
294
// 						pallet_staking::RewardDestination::Controller
295
// 					)
296
// 				),
297
// 				expected_encoded
298
// 			);
299
// 		});
300
// 	}
301
// 	#[test]
302
// 	fn test_stake_bond_extra() {
303
// 		let mut expected_encoded: Vec<u8> = Vec::new();
304
//
305
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
306
// 			kusama_runtime::Staking,
307
// 		>()
308
// 		.unwrap() as u8;
309
// 		expected_encoded.push(index);
310
//
311
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::bond_extra {
312
// 			max_additional: 100u32.into(),
313
// 		}
314
// 		.encode();
315
// 		expected_encoded.append(&mut expected);
316
//
317
// 		assert_eq!(
318
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
319
// 				xcm_primitives::AvailableStakeCalls::BondExtra(100u32.into(),)
320
// 			),
321
// 			expected_encoded.clone()
322
// 		);
323
// 		sp_io::TestExternalities::default().execute_with(|| {
324
// 			// Pallet-xcm-transactor default encoder returns same result
325
// 			// insert storage item as per migration to set the storage item
326
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
327
// 				KUSAMA_RELAY_INDICES,
328
// 			);
329
// 			assert_eq!(
330
// 				<pallet_xcm_transactor::Pallet::<
331
// 					moonriver_runtime::Runtime> as StakeEncodeCall
332
// 				>::encode_call(
333
// 					xcm_primitives::AvailableStakeCalls::BondExtra(100u32.into(),)
334
// 				),
335
// 				expected_encoded
336
// 			);
337
// 		});
338
// 	}
339
// 	#[test]
340
// 	fn test_stake_unbond() {
341
// 		let mut expected_encoded: Vec<u8> = Vec::new();
342
//
343
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
344
// 			kusama_runtime::Staking,
345
// 		>()
346
// 		.unwrap() as u8;
347
// 		expected_encoded.push(index);
348
//
349
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::unbond {
350
// 			value: 100u32.into(),
351
// 		}
352
// 		.encode();
353
// 		expected_encoded.append(&mut expected);
354
//
355
// 		assert_eq!(
356
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
357
// 				xcm_primitives::AvailableStakeCalls::Unbond(100u32.into(),)
358
// 			),
359
// 			expected_encoded.clone()
360
// 		);
361
// 		sp_io::TestExternalities::default().execute_with(|| {
362
// 			// Pallet-xcm-transactor default encoder returns same result
363
// 			// insert storage item as per migration to set the storage item
364
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
365
// 				KUSAMA_RELAY_INDICES,
366
// 			);
367
// 			assert_eq!(
368
// 				<pallet_xcm_transactor::Pallet::<
369
// 					moonriver_runtime::Runtime> as StakeEncodeCall
370
// 				>::encode_call(
371
// 					xcm_primitives::AvailableStakeCalls::Unbond(100u32.into(),)
372
// 				),
373
// 				expected_encoded
374
// 			);
375
// 		});
376
// 	}
377
// 	#[test]
378
// 	fn test_stake_withdraw_unbonded() {
379
// 		let mut expected_encoded: Vec<u8> = Vec::new();
380
//
381
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
382
// 			kusama_runtime::Staking,
383
// 		>()
384
// 		.unwrap() as u8;
385
// 		expected_encoded.push(index);
386
//
387
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::withdraw_unbonded {
388
// 			num_slashing_spans: 100u32,
389
// 		}
390
// 		.encode();
391
// 		expected_encoded.append(&mut expected);
392
//
393
// 		assert_eq!(
394
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
395
// 				xcm_primitives::AvailableStakeCalls::WithdrawUnbonded(100u32,)
396
// 			),
397
// 			expected_encoded.clone()
398
// 		);
399
// 		sp_io::TestExternalities::default().execute_with(|| {
400
// 			// Pallet-xcm-transactor default encoder returns same result
401
// 			// insert storage item as per migration to set the storage item
402
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
403
// 				KUSAMA_RELAY_INDICES,
404
// 			);
405
// 			assert_eq!(
406
// 				<pallet_xcm_transactor::Pallet::<
407
// 					moonriver_runtime::Runtime> as StakeEncodeCall
408
// 				>::encode_call(
409
// 					xcm_primitives::AvailableStakeCalls::WithdrawUnbonded(100u32,)
410
// 				),
411
// 				expected_encoded
412
// 			);
413
// 		});
414
// 	}
415
// 	#[test]
416
// 	fn test_stake_validate() {
417
// 		let mut expected_encoded: Vec<u8> = Vec::new();
418
//
419
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
420
// 			kusama_runtime::Staking,
421
// 		>()
422
// 		.unwrap() as u8;
423
// 		expected_encoded.push(index);
424
//
425
// 		let validator_prefs = pallet_staking::ValidatorPrefs {
426
// 			commission: Perbill::from_percent(5),
427
// 			blocked: true,
428
// 		};
429
//
430
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::validate {
431
// 			prefs: validator_prefs.clone(),
432
// 		}
433
// 		.encode();
434
// 		expected_encoded.append(&mut expected);
435
//
436
// 		assert_eq!(
437
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
438
// 				xcm_primitives::AvailableStakeCalls::Validate(validator_prefs.clone())
439
// 			),
440
// 			expected_encoded
441
// 		);
442
// 		sp_io::TestExternalities::default().execute_with(|| {
443
// 			// Pallet-xcm-transactor default encoder returns same result
444
// 			// insert storage item as per migration to set the storage item
445
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
446
// 				KUSAMA_RELAY_INDICES,
447
// 			);
448
// 			assert_eq!(
449
// 				<pallet_xcm_transactor::Pallet::<
450
// 					moonriver_runtime::Runtime> as StakeEncodeCall
451
// 				>::encode_call(
452
// 					xcm_primitives::AvailableStakeCalls::Validate(validator_prefs)
453
// 				),
454
// 				expected_encoded
455
// 			);
456
// 		});
457
// 	}
458
// 	#[test]
459
// 	fn test_stake_nominate() {
460
// 		let mut expected_encoded: Vec<u8> = Vec::new();
461
// 		let relay_account: AccountId32 = [1u8; 32].into();
462
//
463
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
464
// 			kusama_runtime::Staking,
465
// 		>()
466
// 		.unwrap() as u8;
467
// 		expected_encoded.push(index);
468
//
469
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::nominate {
470
// 			targets: vec![relay_account.clone().into()],
471
// 		}
472
// 		.encode();
473
// 		expected_encoded.append(&mut expected);
474
//
475
// 		assert_eq!(
476
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
477
// 				xcm_primitives::AvailableStakeCalls::Nominate(vec![relay_account.clone().into()])
478
// 			),
479
// 			expected_encoded.clone()
480
// 		);
481
// 		sp_io::TestExternalities::default().execute_with(|| {
482
// 			// Pallet-xcm-transactor default encoder returns same result
483
// 			// insert storage item as per migration to set the storage item
484
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
485
// 				KUSAMA_RELAY_INDICES,
486
// 			);
487
// 			assert_eq!(
488
// 				<pallet_xcm_transactor::Pallet::<
489
// 					moonriver_runtime::Runtime> as StakeEncodeCall
490
// 				>::encode_call(
491
// 					xcm_primitives::AvailableStakeCalls::Nominate(vec![
492
// 						relay_account.into()
493
// 					])
494
// 				),
495
// 				expected_encoded
496
// 			);
497
// 		});
498
// 	}
499
// 	#[test]
500
// 	fn test_stake_chill() {
501
// 		let mut expected_encoded: Vec<u8> = Vec::new();
502
//
503
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
504
// 			kusama_runtime::Staking,
505
// 		>()
506
// 		.unwrap() as u8;
507
// 		expected_encoded.push(index);
508
//
509
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::chill {}.encode();
510
// 		expected_encoded.append(&mut expected);
511
//
512
// 		assert_eq!(
513
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
514
// 				xcm_primitives::AvailableStakeCalls::Chill
515
// 			),
516
// 			expected_encoded.clone()
517
// 		);
518
// 		sp_io::TestExternalities::default().execute_with(|| {
519
// 			// Pallet-xcm-transactor default encoder returns same result
520
// 			// insert storage item as per migration to set the storage item
521
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
522
// 				KUSAMA_RELAY_INDICES,
523
// 			);
524
// 			assert_eq!(
525
// 				<pallet_xcm_transactor::Pallet::<
526
// 					moonriver_runtime::Runtime> as StakeEncodeCall
527
// 				>::encode_call(
528
// 					xcm_primitives::AvailableStakeCalls::Chill
529
// 				),
530
// 				expected_encoded
531
// 			);
532
// 		});
533
// 	}
534
//
535
// 	#[test]
536
// 	fn test_set_payee() {
537
// 		let mut expected_encoded: Vec<u8> = Vec::new();
538
//
539
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
540
// 			kusama_runtime::Staking,
541
// 		>()
542
// 		.unwrap() as u8;
543
// 		expected_encoded.push(index);
544
//
545
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::set_payee {
546
// 			payee: pallet_staking::RewardDestination::Controller,
547
// 		}
548
// 		.encode();
549
// 		expected_encoded.append(&mut expected);
550
//
551
// 		assert_eq!(
552
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
553
// 				xcm_primitives::AvailableStakeCalls::SetPayee(
554
// 					pallet_staking::RewardDestination::Controller
555
// 				)
556
// 			),
557
// 			expected_encoded.clone()
558
// 		);
559
// 		sp_io::TestExternalities::default().execute_with(|| {
560
// 			// Pallet-xcm-transactor default encoder returns same result
561
// 			// insert storage item as per migration to set the storage item
562
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
563
// 				KUSAMA_RELAY_INDICES,
564
// 			);
565
// 			assert_eq!(
566
// 				<pallet_xcm_transactor::Pallet::<
567
// 					moonriver_runtime::Runtime> as StakeEncodeCall
568
// 				>::encode_call(
569
// 					xcm_primitives::AvailableStakeCalls::SetPayee(
570
// 						pallet_staking::RewardDestination::Controller
571
// 					)
572
// 				),
573
// 				expected_encoded
574
// 			);
575
// 		});
576
// 	}
577
//
578
// 	#[test]
579
// 	fn test_set_controller() {
580
// 		let mut expected_encoded: Vec<u8> = Vec::new();
581
//
582
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
583
// 			kusama_runtime::Staking,
584
// 		>()
585
// 		.unwrap() as u8;
586
// 		expected_encoded.push(index);
587
//
588
// 		let mut expected =
589
// 			pallet_staking::Call::<kusama_runtime::Runtime>::set_controller {}.encode();
590
// 		expected_encoded.append(&mut expected);
591
//
592
// 		assert_eq!(
593
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
594
// 				xcm_primitives::AvailableStakeCalls::SetController
595
// 			),
596
// 			expected_encoded.clone()
597
// 		);
598
// 		sp_io::TestExternalities::default().execute_with(|| {
599
// 			// Pallet-xcm-transactor default encoder returns same result
600
// 			// insert storage item as per migration to set the storage item
601
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
602
// 				KUSAMA_RELAY_INDICES,
603
// 			);
604
// 			assert_eq!(
605
// 					<pallet_xcm_transactor::Pallet::<
606
// 							moonriver_runtime::Runtime> as StakeEncodeCall
607
// 					>::encode_call(
608
// 							xcm_primitives::AvailableStakeCalls::SetController
609
// 					),
610
// 					expected_encoded
611
// 			);
612
// 		});
613
// 	}
614
// 	#[test]
615
// 	fn test_rebond() {
616
// 		let mut expected_encoded: Vec<u8> = Vec::new();
617
//
618
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
619
// 			kusama_runtime::Staking,
620
// 		>()
621
// 		.unwrap() as u8;
622
// 		expected_encoded.push(index);
623
//
624
// 		let mut expected = pallet_staking::Call::<kusama_runtime::Runtime>::rebond {
625
// 			value: 100u32.into(),
626
// 		}
627
// 		.encode();
628
// 		expected_encoded.append(&mut expected);
629
//
630
// 		assert_eq!(
631
// 			<KusamaEncoder as StakeEncodeCall>::encode_call(
632
// 				xcm_primitives::AvailableStakeCalls::Rebond(100u32.into())
633
// 			),
634
// 			expected_encoded.clone()
635
// 		);
636
// 		sp_io::TestExternalities::default().execute_with(|| {
637
// 			// Pallet-xcm-transactor default encoder returns same result
638
// 			// insert storage item as per migration to set the storage item
639
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
640
// 				KUSAMA_RELAY_INDICES,
641
// 			);
642
// 			assert_eq!(
643
// 				<pallet_xcm_transactor::Pallet::<
644
// 					moonriver_runtime::Runtime> as StakeEncodeCall
645
// 				>::encode_call(
646
// 					xcm_primitives::AvailableStakeCalls::Rebond(100u32.into())
647
// 				),
648
// 				expected_encoded
649
// 			);
650
// 		});
651
// 	}
652
//
653
// 	#[test]
654
// 	fn test_hrmp_init() {
655
// 		let mut expected_encoded: Vec<u8> = Vec::new();
656
//
657
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
658
// 			kusama_runtime::Hrmp,
659
// 		>()
660
// 		.unwrap() as u8;
661
// 		expected_encoded.push(index);
662
//
663
// 		let mut expected = polkadot_runtime_parachains::hrmp::Call::<
664
// 			kusama_runtime::Runtime
665
// 		>::hrmp_init_open_channel {
666
// 			recipient: 1000u32.into(),
667
// 			proposed_max_capacity: 100u32,
668
// 			proposed_max_message_size: 100u32,
669
// 		}
670
// 		.encode();
671
// 		expected_encoded.append(&mut expected);
672
//
673
// 		assert_eq!(
674
// 			<KusamaEncoder as xcm_primitives::HrmpEncodeCall>::hrmp_encode_call(
675
// 				xcm_primitives::HrmpAvailableCalls::InitOpenChannel(
676
// 					1000u32.into(),
677
// 					100u32.into(),
678
// 					100u32.into()
679
// 				)
680
// 			),
681
// 			Ok(expected_encoded.clone())
682
// 		);
683
// 		sp_io::TestExternalities::default().execute_with(|| {
684
// 			// Pallet-xcm-transactor default encoder returns same result
685
// 			// insert storage item as per migration to set the storage item
686
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
687
// 				KUSAMA_RELAY_INDICES,
688
// 			);
689
// 			assert_eq!(
690
// 				<pallet_xcm_transactor::Pallet::<
691
// 					moonriver_runtime::Runtime> as xcm_primitives::HrmpEncodeCall
692
// 				>::hrmp_encode_call(
693
// 					xcm_primitives::HrmpAvailableCalls::InitOpenChannel(
694
// 						1000u32.into(),
695
// 						100u32.into(),
696
// 						100u32.into()
697
// 					)
698
// 				),
699
// 				Ok(expected_encoded)
700
// 			);
701
// 		});
702
// 	}
703
//
704
// 	#[test]
705
// 	fn test_hrmp_accept() {
706
// 		let mut expected_encoded: Vec<u8> = Vec::new();
707
//
708
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
709
// 			kusama_runtime::Hrmp,
710
// 		>()
711
// 		.unwrap() as u8;
712
// 		expected_encoded.push(index);
713
//
714
// 		let mut expected = polkadot_runtime_parachains::hrmp::Call::<
715
// 			kusama_runtime::Runtime
716
// 		>::hrmp_accept_open_channel {
717
// 			sender: 1000u32.into()
718
// 		}
719
// 		.encode();
720
// 		expected_encoded.append(&mut expected);
721
//
722
// 		assert_eq!(
723
// 			<KusamaEncoder as xcm_primitives::HrmpEncodeCall>::hrmp_encode_call(
724
// 				xcm_primitives::HrmpAvailableCalls::AcceptOpenChannel(1000u32.into(),)
725
// 			),
726
// 			Ok(expected_encoded.clone())
727
// 		);
728
// 		sp_io::TestExternalities::default().execute_with(|| {
729
// 			// Pallet-xcm-transactor default encoder returns same result
730
// 			// insert storage item as per migration to set the storage item
731
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
732
// 				KUSAMA_RELAY_INDICES,
733
// 			);
734
// 			assert_eq!(
735
// 				<pallet_xcm_transactor::Pallet::<
736
// 					moonriver_runtime::Runtime> as xcm_primitives::HrmpEncodeCall
737
// 				>::hrmp_encode_call(
738
// 					xcm_primitives::HrmpAvailableCalls::AcceptOpenChannel(1000u32.into(),)
739
// 				),
740
// 				Ok(expected_encoded)
741
// 			);
742
// 		});
743
// 	}
744
//
745
// 	#[test]
746
// 	fn test_hrmp_close() {
747
// 		let mut expected_encoded: Vec<u8> = Vec::new();
748
//
749
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
750
// 			kusama_runtime::Hrmp,
751
// 		>()
752
// 		.unwrap() as u8;
753
// 		expected_encoded.push(index);
754
//
755
// 		let mut expected = polkadot_runtime_parachains::hrmp::Call::<
756
// 			kusama_runtime::Runtime
757
// 		>::hrmp_close_channel {
758
// 			channel_id: HrmpChannelId {
759
// 				sender: 1000u32.into(),
760
// 				recipient: 1001u32.into()
761
// 			}
762
// 		}
763
// 		.encode();
764
// 		expected_encoded.append(&mut expected);
765
//
766
// 		assert_eq!(
767
// 			<KusamaEncoder as xcm_primitives::HrmpEncodeCall>::hrmp_encode_call(
768
// 				xcm_primitives::HrmpAvailableCalls::CloseChannel(HrmpChannelId {
769
// 					sender: 1000u32.into(),
770
// 					recipient: 1001u32.into()
771
// 				})
772
// 			),
773
// 			Ok(expected_encoded.clone())
774
// 		);
775
// 		sp_io::TestExternalities::default().execute_with(|| {
776
// 			// Pallet-xcm-transactor default encoder returns same result
777
// 			// insert storage item as per migration to set the storage item
778
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
779
// 				KUSAMA_RELAY_INDICES,
780
// 			);
781
// 			assert_eq!(
782
// 				<pallet_xcm_transactor::Pallet::<
783
// 					moonriver_runtime::Runtime> as xcm_primitives::HrmpEncodeCall
784
// 				>::hrmp_encode_call(
785
// 					xcm_primitives::HrmpAvailableCalls::CloseChannel(HrmpChannelId {
786
// 						sender: 1000u32.into(),
787
// 						recipient: 1001u32.into()
788
// 					})
789
// 				),
790
// 				Ok(expected_encoded)
791
// 			);
792
// 		});
793
// 	}
794
//
795
// 	#[test]
796
// 	fn test_hrmp_cancel() {
797
// 		let mut expected_encoded: Vec<u8> = Vec::new();
798
//
799
// 		let index = <kusama_runtime::Runtime as frame_system::Config>::PalletInfo::index::<
800
// 			kusama_runtime::Hrmp,
801
// 		>()
802
// 		.unwrap() as u8;
803
// 		expected_encoded.push(index);
804
//
805
// 		let channel_id = HrmpChannelId {
806
// 			sender: 1u32.into(),
807
// 			recipient: 1u32.into(),
808
// 		};
809
// 		let open_requests: u32 = 1;
810
//
811
// 		let mut expected = polkadot_runtime_parachains::hrmp::Call::<
812
// 			kusama_runtime::Runtime
813
// 		>::hrmp_cancel_open_request {
814
// 			channel_id: channel_id.clone(),
815
// 			open_requests
816
// 		}
817
// 		.encode();
818
// 		expected_encoded.append(&mut expected);
819
//
820
// 		assert_eq!(
821
// 			<KusamaEncoder as xcm_primitives::HrmpEncodeCall>::hrmp_encode_call(
822
// 				xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(
823
// 					channel_id.clone(),
824
// 					open_requests
825
// 				)
826
// 			),
827
// 			Ok(expected_encoded.clone())
828
// 		);
829
// 		sp_io::TestExternalities::default().execute_with(|| {
830
// 			// Pallet-xcm-transactor default encoder returns same result
831
// 			// insert storage item as per migration to set the storage item
832
// 			pallet_xcm_transactor::RelayIndices::<moonriver_runtime::Runtime>::put(
833
// 				KUSAMA_RELAY_INDICES,
834
// 			);
835
// 			assert_eq!(
836
// 				<pallet_xcm_transactor::Pallet::<
837
// 					moonriver_runtime::Runtime> as xcm_primitives::HrmpEncodeCall
838
// 				>::hrmp_encode_call(
839
// 					xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(
840
// 						channel_id.clone(),
841
// 						open_requests
842
// 					)
843
// 				),
844
// 				Ok(expected_encoded)
845
// 			);
846
// 		});
847
// 	}
848
// }