Skip to content

Commit 926a595

Browse files
committed
Merge branch 'dami/xcm-asset-hub' of github.com:polytope-labs/hyperbridge into dami/xcm-asset-hub
# Conflicts: # modules/pallets/testsuite/src/tests/pallet_xcm_gateway.rs # modules/pallets/testsuite/src/xcm.rs
2 parents 9f2a146 + 28386c8 commit 926a595

File tree

3 files changed

+121
-28
lines changed

3 files changed

+121
-28
lines changed

modules/pallets/testsuite/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ evm-state-machine = { workspace = true, default-features = true }
5353
subxt-utils = { workspace = true, default-features = true }
5454
ismp-grandpa = { workspace = true, default-features = true }
5555
rs_merkle = { version = "1.5.0"}
56+
log = { workspace = true }
5657

5758
[dependencies.polkadot-sdk]
5859
workspace = true

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

Lines changed: 106 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,125 @@ use xcm_simulator::TestExt;
3737
use crate::runtime::ReputationAssetId;
3838

3939
const SEND_AMOUNT: u128 = 1000_000_000_0000;
40-
const PARA_ID: u32 = 100;
40+
const PARA_ID: u32 = crate::xcm::SIBLING_PARA_ID;
4141
pub type RelayChainPalletXcm = pallet_xcm::Pallet<relay_chain::Runtime>;
4242

4343
fn reserve_transfer_on_AH(amount: u128, beneficiary: Location) {
4444
let asset_location_on_assethub = Location::new(1, Here);
4545

46-
let dest = Location::new(1, [Parachain(100)]);
46+
//let asset_location_on_assethub_h256: H256 = sp_io::hashing::keccak_256(&asset_location_on_assethub.encode()).into();
47+
48+
let asset_id_on_paraa: H256 =
49+
sp_io::hashing::keccak_256(&Location::new(1, Here).encode())
50+
.into();
51+
52+
53+
ParaA::execute_with(|| {
54+
/*assert_ok!(runtime::Assets::force_create(
55+
runtime::RuntimeOrigin::root(),
56+
asset_id_on_paraa.into(),
57+
ALICE.into(),
58+
true,
59+
1
60+
));*/
61+
});
62+
63+
64+
ParaB::execute_with(|| {
65+
let dest = Location::new(1, [Parachain(PARA_ID)]);
66+
let beneficiary: Location = Junctions::X3(Arc::new([
67+
Junction::AccountId32 { network: None, id: ALICE.into() },
68+
Junction::AccountKey20 {
69+
network: Some(NetworkId::Ethereum { chain_id: 97 }),
70+
key: [1u8; 20],
71+
},
72+
Junction::GeneralIndex(60 * 60),
73+
]))
74+
.into_location();
75+
76+
let context = Junctions::X2(Arc::new([
77+
Junction::GlobalConsensus(NetworkId::Polkadot),
78+
Parachain(1000),
79+
]));
4780

4881
let assets = Asset {
4982
id: AssetId(asset_location_on_assethub.clone()),
5083
fun: Fungibility::Fungible(amount),
5184
};
5285

53-
let remote_xcm = Xcm(vec![
54-
BuyExecution { fees: assets.clone(), weight_limit: WeightLimit::Unlimited },
55-
DepositAsset { assets: Wild(All), beneficiary },
56-
]);
86+
let fee_asset = assets.clone().reanchored(&dest, &context).expect("should reanchor");
87+
let fees = fee_asset.clone();
88+
89+
// let xcm = Xcm(vec![
90+
// BuyExecution { fees, weight_limit: WeightLimit::Unlimited },
91+
// DepositAsset {
92+
// assets: Wild(All),
93+
// beneficiary,
94+
// },
95+
// ]);
96+
97+
// let message = Xcm(vec![
98+
// SetFeesMode { jit_withdraw: true },
99+
// TransferReserveAsset {
100+
// assets: assets.into(),
101+
// dest,
102+
// xcm,
103+
// },
104+
// ]);
105+
106+
// assert_ok!(runtime::PalletXcm::execute(
107+
// runtime::RuntimeOrigin::signed(ALICE.into()),
108+
// Box::new(VersionedXcm::from(message)),
109+
// Weight::MAX
110+
// ));
111+
112+
assert_ok!(runtime::PalletXcm::limited_reserve_transfer_assets(
113+
runtime::RuntimeOrigin::signed(ALICE.into()),
114+
Box::new(dest.into()),
115+
Box::new(beneficiary.into()),
116+
Box::new(vec![(asset_location_on_assethub, SEND_AMOUNT).into()].into()),
117+
0,
118+
WeightLimit::Unlimited,
119+
));
120+
});
121+
122+
123+
ParaA::execute_with(|| {
124+
125+
let bobs_balance = <runtime::Assets as Inspect<
126+
<Test as frame_system::Config>::AccountId,
127+
>>::balance(
128+
asset_id_on_paraa,
129+
&BOB,
130+
);
131+
dbg!(bobs_balance);
132+
133+
let parachain_account: ParaId = PARA_ID.into();
134+
let parachain_account = parachain_account.into_account_truncating();
135+
136+
let alice_balance = <runtime::Assets as Inspect<
137+
<Test as frame_system::Config>::AccountId,
138+
>>::balance(
139+
asset_id_on_paraa,
140+
&parachain_account,
141+
);
142+
dbg!(alice_balance);
143+
let nonce = pallet_ismp::Nonce::<Test>::get();
144+
assert_eq!(nonce, 1);
145+
146+
let protocol_fees = pallet_xcm_gateway::Pallet::<Test>::protocol_fee_percentage();
147+
let custodied_amount = SEND_AMOUNT - (protocol_fees * SEND_AMOUNT);
148+
149+
let pallet_account_balance = <runtime::Assets as Inspect<
150+
<Test as frame_system::Config>::AccountId,
151+
>>::balance(
152+
asset_id_on_paraa.into(),
153+
&pallet_xcm_gateway::Pallet::<Test>::account_id(),
154+
);
155+
assert_eq!(custodied_amount, pallet_account_balance);
156+
});
57157

58-
let message = Xcm(vec![
59-
SetFeesMode { jit_withdraw: true },
60-
TransferReserveAsset { assets: assets.into(), dest, xcm: remote_xcm },
61-
]);
62-
63-
ParaB::execute_with(|| {
64-
assert_ok!(runtime::PalletXcm::execute(
65-
runtime::RuntimeOrigin::signed(ALICE.into()),
66-
Box::new(VersionedXcm::from(message)),
67-
Weight::MAX
68-
));
69-
});
70158
}
71-
72159
#[test]
73160
fn should_dispatch_ismp_request_when_assets_are_received_from_assethub() {
74161
init_tracing();

modules/pallets/testsuite/src/xcm.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ parameter_types! {
8080
}
8181

8282
parameter_types! {
83-
pub const KsmLocation: Location = Location::parent();
83+
pub const RelayLocation: Location = Location::parent();
8484
pub const RelayNetwork: Option<NetworkId> = None;
8585
pub UniversalLocation: Junctions = Parachain(ParachainInfo::parachain_id().into()).into();
8686
}
8787

8888
parameter_types! {
89-
pub ExternalConsensus: InteriorLocation = [Parachain(100), Parachain(1000)].into();
89+
pub ExternalConsensus: InteriorLocation = [Parachain(SIBLING_PARA_ID), Parachain(1000)].into();
9090
}
9191

9292
pub type LocationToAccountId = (
@@ -207,12 +207,15 @@ impl DmpMessageHandler for DmpMessageExecutor {
207207
}
208208
}
209209

210+
/// 1000-2000 are considered system parachains, so let's use higher para_id
211+
pub const SIBLING_PARA_ID: u32 = 2222;
212+
210213
decl_test_parachain! {
211214
pub struct ParaA {
212215
Runtime = Test,
213216
XcmpMessageHandler = crate::runtime::MsgQueue,
214217
DmpMessageHandler = DmpMessageExecutor,
215-
new_ext = para_ext(100),
218+
new_ext = para_ext(SIBLING_PARA_ID),
216219
}
217220
}
218221

@@ -241,7 +244,7 @@ decl_test_network! {
241244
pub struct MockNet {
242245
relay_chain = Relay,
243246
parachains = vec![
244-
(100, ParaA),
247+
(SIBLING_PARA_ID, ParaA),
245248
(1000, ParaB),
246249
],
247250
}
@@ -268,10 +271,9 @@ parameter_types! {
268271
pub struct TestReserve;
269272
impl ContainsPair<Asset, Location> for TestReserve {
270273
fn contains(asset: &Asset, origin: &Location) -> bool {
271-
println!("TestReserve::contains asset: {asset:?}, origin:{origin:?}");
272-
//let assethub_location = Location::new(1, Parachain(ASSET_HUB_PARA_ID));
273-
//&assethub_location == origin
274-
true
274+
log::trace!(target: "xcm", "TestReserve::contains asset: {asset:?}, origin:{origin:?}");
275+
let assethub_location = Location::new(1, Parachain(ASSET_HUB_PARA_ID));
276+
&assethub_location == origin
275277
}
276278
}
277279

@@ -282,7 +284,10 @@ impl staging_xcm_executor::Config for XcmConfig {
282284
type AssetTransactor = LocalAssetTransactor;
283285
type OriginConverter = XcmOriginToCallOrigin;
284286
type IsReserve = TestReserve;
285-
type IsTeleporter = ();
287+
type IsTeleporter = (
288+
// Important setting reflecting AssetHub
289+
parachains_common::xcm_config::ConcreteAssetFromSystem<RelayLocation>,
290+
);
286291
type UniversalLocation = UniversalLocation;
287292
type Barrier = Barrier;
288293
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;

0 commit comments

Comments
 (0)