Skip to content

Commit 618de7c

Browse files
committed
integration test passes now
1 parent e43d6a3 commit 618de7c

File tree

9 files changed

+99
-88
lines changed

9 files changed

+99
-88
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/pallets/testsuite/src/tests/xcm_integration_test.rs

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ use futures::StreamExt;
88
use polkadot_sdk::{
99
sp_core::{bytes::from_hex, sr25519, Pair, H256},
1010
sp_runtime::Weight,
11-
staging_xcm::v4::{Asset, AssetId, Fungibility},
11+
staging_xcm::v5::{Asset, AssetId, Fungibility},
1212
*,
1313
};
14+
use polkadot_sdk::staging_xcm::v5::Parent;
1415
use staging_xcm::{
15-
v4::{Junction, Junctions, Location, NetworkId, WeightLimit},
16+
v5::{Junction, Junctions, Location, NetworkId, WeightLimit},
1617
VersionedLocation,
1718
};
1819
use subxt::{
@@ -45,17 +46,27 @@ async fn should_dispatch_ismp_request_when_xcm_is_received() -> anyhow::Result<(
4546
let url = std::env::var("ROCOCO_LOCAL_URL")
4647
.ok()
4748
.unwrap_or("ws://127.0.0.1:9922".to_string());
48-
let client = OnlineClient::<BlakeSubstrateChain>::from_url(&url).await?;
49+
let relay_client = OnlineClient::<BlakeSubstrateChain>::from_url(&url).await?;
4950
let rpc_client = RpcClient::from_url(&url).await?;
5051
let _rpc = LegacyRpcMethods::<BlakeSubstrateChain>::new(rpc_client.clone());
5152

53+
let assethub_url = std::env::var("ASSET_HUB_LOCAL_URL")
54+
.ok()
55+
.unwrap_or("ws://127.0.0.1:9910".to_string());
56+
let assethub_client = OnlineClient::<BlakeSubstrateChain>::from_url(&assethub_url).await?;
57+
let _assethub_rpc_client = RpcClient::from_url(&assethub_url).await?;
58+
let _assethub_rpc = LegacyRpcMethods::<BlakeSubstrateChain>::new(rpc_client.clone());
59+
5260
let para_url = std::env::var("PARA_LOCAL_URL")
5361
.ok()
5462
.unwrap_or("ws://127.0.0.1:9990".to_string());
5563
let _para_client = OnlineClient::<Hyperbridge>::from_url(&para_url).await?;
5664
let para_rpc_client = RpcClient::from_url(&para_url).await?;
5765
let para_rpc = LegacyRpcMethods::<BlakeSubstrateChain>::new(para_rpc_client.clone());
5866

67+
force_open_hrmp_channel(&relay_client, &signer, 1000, 2000).await?;
68+
force_open_hrmp_channel(&relay_client, &signer, 2000, 1000).await?;
69+
5970
// Wait for parachain block production
6071

6172
let sub = para_rpc.chain_subscribe_finalized_heads().await?;
@@ -76,37 +87,23 @@ async fn should_dispatch_ismp_request_when_xcm_is_received() -> anyhow::Result<(
7687
.into_location();
7788
let weight_limit = WeightLimit::Unlimited;
7889

79-
let dest: VersionedLocation = VersionedLocation::V4(Junction::Parachain(2000).into());
90+
let dest: VersionedLocation = VersionedLocation::V5( Location::new(1, [Junction::Parachain(2000)]));
8091

81-
let beneficiary_as_versioned = VersionedLocation::V4(beneficiary);
82-
let assets_vec = vec![(Junctions::Here, SEND_AMOUNT).into()];
92+
let beneficiary_as_versioned = VersionedLocation::V5(beneficiary);
93+
let dot_location: Location = Parent.into();
94+
let assets_vec = vec![Asset {
95+
id: dot_location.into(),
96+
fun: Fungibility::Fungible(SEND_AMOUNT),
97+
}];
8398

8499
let dest_value = versioned_location_to_value(&dest);
85100
let beneficiary_value = versioned_location_to_value(&beneficiary_as_versioned);
86101
let assets_value = versioned_assets_to_value(&assets_vec);
87102
let fee_asset_index_value = Value::u128(0);
88103
let weight_limit_value = weight_limit_to_value(&weight_limit);
89104

90-
{
91-
let signer = InMemorySigner::<BlakeSubstrateChain>::new(pair.clone());
92-
let para_absolute_location: Location = Junction::Parachain(2000).into();
93-
let version = 4u32;
94-
95-
let location_as_value = location_to_value(&para_absolute_location);
96-
let version_as_value = Value::u128(version.into());
97-
98-
// Force set the xcm version to our supported version
99-
let call = subxt::dynamic::tx(
100-
"XcmPallet",
101-
"force_xcm_version",
102-
vec![location_as_value, version_as_value],
103-
);
104-
let tx = subxt::dynamic::tx("Sudo", "sudo", vec![call.into_value()]);
105-
send_extrinsic(&client, &signer, &tx, None).await?;
106-
}
107-
108105
let ext = subxt::dynamic::tx(
109-
"XcmPallet",
106+
"PolkadotXcm",
110107
"limited_reserve_transfer_assets",
111108
vec![
112109
dest_value,
@@ -123,8 +120,10 @@ async fn should_dispatch_ismp_request_when_xcm_is_received() -> anyhow::Result<(
123120
.ok_or_else(|| anyhow!("Failed to fetch latest header"))?
124121
.number();
125122

126-
send_extrinsic(&client, &signer, &ext, None).await?;
123+
send_extrinsic(&assethub_client, &signer, &ext, None).await?;
124+
127125

126+
println!("done performing limited reserve asset transfer");
128127
let mut sub = para_rpc.chain_subscribe_finalized_heads().await?;
129128

130129
while let Some(res) = sub.next().await {
@@ -171,6 +170,28 @@ async fn should_dispatch_ismp_request_when_xcm_is_received() -> anyhow::Result<(
171170
Err(anyhow!("XCM Integration test failed"))
172171
}
173172

173+
async fn force_open_hrmp_channel(
174+
relay_client: &OnlineClient<BlakeSubstrateChain>,
175+
signer: &InMemorySigner<BlakeSubstrateChain>,
176+
sender: u128,
177+
recipient: u128,
178+
) -> anyhow::Result<()> {
179+
let force_call = subxt::dynamic::tx(
180+
"Hrmp",
181+
"force_open_hrmp_channel",
182+
vec![
183+
Value::u128(sender),
184+
Value::u128(recipient),
185+
Value::u128(8),
186+
Value::u128(1024 * 1024),
187+
],
188+
);
189+
let sudo_call = subxt::dynamic::tx("Sudo", "sudo", vec![force_call.into_value()]);
190+
send_extrinsic(relay_client, signer, &sudo_call, None).await?;
191+
192+
Ok(())
193+
}
194+
174195
fn junction_to_value(junction: &Junction) -> Value<()> {
175196
match junction {
176197
Junction::Parachain(id) =>
@@ -253,11 +274,11 @@ pub fn force_xcm_version_value() -> Value<()> {
253274

254275
fn versioned_location_to_value(loc: &VersionedLocation) -> Value<()> {
255276
match loc {
256-
VersionedLocation::V4(location) => {
277+
VersionedLocation::V5(location) => {
257278
let location_value = location_to_value(location);
258-
Value::variant("V4", Composite::unnamed(vec![location_value]))
279+
Value::variant("V5", Composite::unnamed(vec![location_value]))
259280
},
260-
_ => unimplemented!("This helper only supports V4 VersionedLocation"),
281+
_ => unimplemented!("This helper only supports V5 VersionedLocation"),
261282
}
262283
}
263284

@@ -285,7 +306,7 @@ fn versioned_assets_to_value(assets_vec: &Vec<Asset>) -> Value<()> {
285306
let inner_assets_value = Value::unnamed_composite(asset_values);
286307

287308
let assets_struct_value = Value::unnamed_composite(vec![inner_assets_value]);
288-
Value::variant("V4", Composite::unnamed(vec![assets_struct_value]))
309+
Value::variant("V5", Composite::unnamed(vec![assets_struct_value]))
289310
}
290311

291312
fn weight_to_value(weight: &Weight) -> Value<()> {

modules/pallets/testsuite/src/xcm.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ parameter_types! {
8181

8282
parameter_types! {
8383
pub const RelayLocation: Location = Location::parent();
84-
pub ParaALocation: Location = Location::new(1, Parachain(SIBLING_PARA_ID));
8584
pub const RelayNetwork: Option<NetworkId> = None;
8685
pub UniversalLocation: Junctions = Parachain(ParachainInfo::parachain_id().into()).into();
8786
}
@@ -254,19 +253,22 @@ parameter_types! {
254253
}
255254

256255

257-
258-
259-
260-
261-
262-
263-
264256
pub struct TestReserve;
265257
impl ContainsPair<Asset, Location> for TestReserve {
266258
fn contains(asset: &Asset, origin: &Location) -> bool {
267259
println!("TestReserve::contains asset: {asset:?}, origin:{origin:?}");
268-
let assethub_location = Location::new(1, Parachain(ASSET_HUB_PARA_ID));
269-
&assethub_location == origin
260+
let self_para = Location::new(1, [Parachain(ParachainInfo::parachain_id().into())]);
261+
if origin == &self_para {
262+
return false;
263+
}
264+
265+
let asset_hub = Location::new(1, [Parachain(ASSET_HUB_PARA_ID)]);
266+
if origin == &asset_hub {
267+
let AssetId(asset_id) = &asset.id;
268+
return DotOnAssetHub::get() == *asset_id;
269+
}
270+
271+
false
270272
}
271273
}
272274

@@ -402,7 +404,7 @@ impl pallet_xcm::Config for Test {
402404
type XcmExecuteFilter = Everything;
403405
type XcmExecutor = XcmExecutor<XcmConfig>;
404406
type XcmTeleportFilter = Everything;
405-
type XcmReserveTransferFilter = Everything;
407+
type XcmReserveTransferFilter = ReserveTransferFilter;
406408
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
407409
type UniversalLocation = UniversalLocation;
408410
type RuntimeOrigin = RuntimeOrigin;

modules/pallets/xcm-gateway/src/lib.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ use frame_support::{
3333
Get,
3434
},
3535
};
36-
use polkadot_sdk::cumulus_primitives_core::{All, BuyExecution, DepositAsset, Parachain, SetFeesMode, TransferReserveAsset, Weight, Wild, Xcm};
36+
use polkadot_sdk::cumulus_primitives_core::{All, AllCounted, BuyExecution, DepositAsset, Parachain, SetFeesMode, TransferReserveAsset, Weight, Wild, Xcm};
3737
use polkadot_sdk::staging_xcm_executor::traits::TransferType;
38-
use polkadot_sdk::xcm_simulator::AllCounted;
3938

4039
use ismp::{
4140
dispatcher::{DispatchPost, DispatchRequest, FeeMetadata, IsmpDispatcher},
@@ -327,7 +326,6 @@ where
327326
T::AccountId: Into<[u8; 32]> + From<[u8; 32]>,
328327
{
329328
fn on_accept(&self, post: ismp::router::PostRequest) -> Result<(), anyhow::Error> {
330-
println!("accepting module");
331329
let request = Request::Post(post.clone());
332330
// Check that source module is equal to the known token gateway deployment address
333331
ensure!(
@@ -341,7 +339,6 @@ where
341339
},
342340
}
343341
);
344-
println!("ensuring module");
345342
// parachains/solochains shouldn't be sending us a request.
346343
ensure!(
347344
!matches!(
@@ -358,7 +355,6 @@ where
358355
}
359356
);
360357

361-
println!("decoding post request");
362358
let body = Body::abi_decode(&mut &post.body[1..], true).map_err(|_| {
363359
ismp::error::Error::ModuleDispatchError {
364360
msg: "Token Gateway: Failed to decode request body".to_string(),
@@ -370,7 +366,6 @@ where
370366
}
371367
})?;
372368

373-
println!(" asset id {:?} {:?}", body.asset_id.0, Pallet::<T>::dot_asset_id().0);
374369
// Check that the asset id is equal to the known asset id
375370
ensure!(
376371
body.asset_id.0 == Pallet::<T>::dot_asset_id().0,
@@ -414,7 +409,6 @@ where
414409
beneficiary: xcm_beneficiary.clone(),
415410
}]);
416411

417-
println!("sending xcm {:?}, xcm_beneficiary {:?}", xcm_dest, xcm_beneficiary);
418412

419413
// Send xcm back to assethub
420414
pallet_xcm::Pallet::<T>::transfer_assets_using_type_and_then(
@@ -435,8 +429,6 @@ where
435429
},
436430
})?;
437431

438-
println!("done sending xcm");
439-
440432
Pallet::<T>::deposit_event(Event::<T>::AssetReceived {
441433
beneficiary: body.to.0.into(),
442434
amount: amount.into(),
@@ -519,15 +511,14 @@ where
519511
Box::new(TransferType::DestinationReserve),
520512
Box::new(VersionedXcm::from(custom_xcm_on_dest)),
521513
weight_limit,
522-
)
523-
.unwrap();/*map_err(|_| ismp::error::Error::ModuleDispatchError {
514+
).map_err(|_| ismp::error::Error::ModuleDispatchError {
524515
msg: "Token Gateway: Failed to execute xcm to relay chain".to_string(),
525516
meta: Meta {
526517
source: request.source_chain(),
527518
dest: request.dest_chain(),
528519
nonce: request.nonce(),
529520
},
530-
})?;*/
521+
})?;
531522

532523
Pallet::<T>::deposit_event(Event::<T>::AssetRefunded {
533524
beneficiary,

modules/pallets/xcm-gateway/src/xcm_utilities.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use frame_support::traits::{
2323
};
2424
use ismp::host::StateMachine;
2525
use polkadot_sdk::*;
26-
use polkadot_sdk::cumulus_primitives_core::Parachain;
27-
use polkadot_sdk::xcm_emulator::Here;
26+
use polkadot_sdk::cumulus_primitives_core::Here;
2827
use sp_core::{Get, H160};
2928
use sp_runtime::traits::MaybeEquivalence;
3029
use staging_xcm::v5::{
@@ -77,7 +76,7 @@ where
7776
{
7877
fn convert_location(location: &Location) -> Option<MultiAccount<A>> {
7978
match location {
80-
Location { interior: Junctions::X3(arc_junctions), .. } => {
79+
Location { parents: 0, interior: Junctions::X3(arc_junctions) } => {
8180
// Dereference the Arc to access the underlying array
8281
match arc_junctions.as_ref() {
8382
[Junction::AccountId32 { id, .. }, Junction::AccountKey20 { network: Some(network), key }, Junction::GeneralIndex(timeout)] =>
@@ -129,7 +128,6 @@ pub struct ReserveTransferFilter;
129128

130129
impl Contains<(Location, Vec<Asset>)> for ReserveTransferFilter {
131130
fn contains(t: &(Location, Vec<Asset>)) -> bool {
132-
println!("filter for {:?}", t);
133131
let native = Location::new(1, Here);
134132
t.1.iter().all(|asset| {
135133
if let Asset { id: asset_id, fun: Fungible(_) } = asset {
@@ -162,7 +160,6 @@ where
162160
T::AccountId: Eq + Clone + From<[u8; 32]> + Into<[u8; 32]>,
163161
{
164162
fn can_check_in(origin: &Location, what: &Asset, context: &XcmContext) -> XcmResult {
165-
println!("can check in {:?}", origin);
166163
FungiblesMutateAdapter::<
167164
T::Assets,
168165
Matcher,
@@ -174,7 +171,6 @@ where
174171
}
175172

176173
fn check_in(origin: &Location, what: &Asset, context: &XcmContext) {
177-
println!("check in {:?}", origin);
178174
FungiblesMutateAdapter::<
179175
T::Assets,
180176
Matcher,
@@ -208,13 +204,11 @@ where
208204
}
209205

210206
fn deposit_asset(what: &Asset, who: &Location, context: Option<&XcmContext>) -> XcmResult {
211-
println!("depositing asset: what: {what:?}, who: {who:?}, context: {:?}", context.unwrap().origin);
212207
// Check we handle this asset.
213208
let (asset_id, amount) = Matcher::matches_fungibles(what)?;
214209

215210
// Ismp xcm transaction
216211
if let Some(who) = MultilocationToMultiAccount::<T::AccountId>::convert_location(who) {
217-
println!("some account gotten {:?}", what);
218212
// We would remove the protocol fee at this point
219213

220214
let protocol_account = Pallet::<T>::protocol_account_id();
@@ -241,9 +235,7 @@ where
241235
// We dispatch an ismp request to the destination chain
242236
Pallet::<T>::dispatch_request(who, remainder)
243237
.map_err(|e| XcmError::FailedToTransactAsset(e.into()))?;
244-
println!("done minting");
245238
} else {
246-
247239
#[cfg(feature = "std")]
248240
FungiblesMutateAdapter::<
249241
T::Assets,
@@ -266,7 +258,6 @@ where
266258
who: &Location,
267259
maybe_context: Option<&XcmContext>,
268260
) -> Result<AssetsInHolding, XcmError> {
269-
println!("withdrawing asset {:?}, {:?}", &what, &who);
270261
FungiblesMutateAdapter::<
271262
T::Assets,
272263
Matcher,
@@ -283,7 +274,6 @@ where
283274
to: &Location,
284275
context: &XcmContext,
285276
) -> Result<AssetsInHolding, XcmError> {
286-
println!("internal transfer asset from {:?}, to {:?}", &from, &to);
287277
FungiblesMutateAdapter::<
288278
T::Assets,
289279
Matcher,
@@ -300,7 +290,6 @@ where
300290
to: &Location,
301291
context: &XcmContext,
302292
) -> Result<AssetsInHolding, XcmError> {
303-
println!("transfer asset {:?}, {:?}", &from, &to);
304293
FungiblesMutateAdapter::<
305294
T::Assets,
306295
Matcher,

0 commit comments

Comments
 (0)