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
#![cfg_attr(not(feature = "std"), no_std)]
use codec::Encode;
use frame_benchmarking::{account, BenchmarkError};
use sp_std::prelude::*;
use xcm::latest::prelude::*;
use xcm_executor::traits::Convert;
pub mod fungible;
pub mod generic;
#[cfg(test)]
mod mock;
pub trait Config: frame_system::Config {
type XcmConfig: xcm_executor::Config;
type AccountIdConverter: Convert<MultiLocation, Self::AccountId>;
fn valid_destination() -> Result<MultiLocation, BenchmarkError>;
fn worst_case_holding() -> MultiAssets;
}
const SEED: u32 = 0;
pub type ExecutorOf<T> = xcm_executor::XcmExecutor<<T as Config>::XcmConfig>;
pub type OverArchingCallOf<T> = <T as frame_system::Config>::Call;
pub type AssetTransactorOf<T> = <<T as Config>::XcmConfig as xcm_executor::Config>::AssetTransactor;
pub type XcmCallOf<T> = <<T as Config>::XcmConfig as xcm_executor::Config>::Call;
pub fn mock_worst_case_holding() -> MultiAssets {
const HOLDING_FUNGIBLES: u32 = 99;
const HOLDING_NON_FUNGIBLES: u32 = 99;
let fungibles_amount: u128 = 100;
(0..HOLDING_FUNGIBLES)
.map(|i| {
MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
fun: Fungible(fungibles_amount * i as u128),
}
.into()
})
.chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) }))
.chain((0..HOLDING_NON_FUNGIBLES).map(|i| MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
fun: NonFungible(asset_instance_from(i)),
}))
.collect::<Vec<_>>()
.into()
}
pub fn asset_instance_from(x: u32) -> AssetInstance {
let bytes = x.encode();
let mut instance = [0u8; 4];
instance.copy_from_slice(&bytes);
AssetInstance::Array4(instance)
}
pub fn new_executor<T: Config>(origin: MultiLocation) -> ExecutorOf<T> {
ExecutorOf::<T>::new(origin)
}
fn account_id_junction<T: frame_system::Config>(index: u32) -> Junction {
let account: T::AccountId = account("account", index, SEED);
let mut encoded = account.encode();
encoded.resize(32, 0u8);
let mut id = [0u8; 32];
id.copy_from_slice(&encoded);
Junction::AccountId32 { network: NetworkId::Any, id }
}
pub fn account_and_location<T: Config>(index: u32) -> (T::AccountId, MultiLocation) {
let location: MultiLocation = account_id_junction::<T>(index).into();
let account = T::AccountIdConverter::convert(location.clone()).unwrap();
(account, location)
}