Skip to content

Commit e43d6a3

Browse files
committed
tests passes now after hacking
1 parent 926a595 commit e43d6a3

File tree

4 files changed

+108
-124
lines changed

4 files changed

+108
-124
lines changed

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

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
init_tracing,
88
relay_chain::{self, RuntimeOrigin},
99
runtime,
10-
runtime::{Test, ALICE, BOB, Assets},
10+
runtime::{Test, ALICE, BOB, Assets, PalletXcm},
1111
xcm::{MockNet, ParaA, ParaB, Relay},
1212
};
1313
use alloy_sol_types::SolValue;
@@ -34,14 +34,18 @@ use polkadot_sdk::{
3434
use sp_core::{crypto::AccountId32, ByteArray, H160, H256};
3535
use staging_xcm::v5::{Junction, Junctions, Location, NetworkId, WeightLimit};
3636
use xcm_simulator::TestExt;
37+
use pallet_xcm_gateway::xcm_utilities::ASSET_HUB_PARA_ID;
3738
use crate::runtime::ReputationAssetId;
3839

3940
const SEND_AMOUNT: u128 = 1000_000_000_0000;
4041
const PARA_ID: u32 = crate::xcm::SIBLING_PARA_ID;
4142
pub type RelayChainPalletXcm = pallet_xcm::Pallet<relay_chain::Runtime>;
4243

43-
fn reserve_transfer_on_AH(amount: u128, beneficiary: Location) {
44-
let asset_location_on_assethub = Location::new(1, Here);
44+
#[test]
45+
fn should_dispatch_ismp_request_when_assets_are_received_from_assethub() {
46+
init_tracing();
47+
MockNet::reset();
48+
let asset_location_on_assethub = Location::new(1, Here);
4549

4650
//let asset_location_on_assethub_h256: H256 = sp_io::hashing::keccak_256(&asset_location_on_assethub.encode()).into();
4751

@@ -78,10 +82,10 @@ fn reserve_transfer_on_AH(amount: u128, beneficiary: Location) {
7882
Parachain(1000),
7983
]));
8084

81-
let assets = Asset {
82-
id: AssetId(asset_location_on_assethub.clone()),
83-
fun: Fungibility::Fungible(amount),
84-
};
85+
let assets = Asset {
86+
id: AssetId(asset_location_on_assethub.clone()),
87+
fun: Fungibility::Fungible(SEND_AMOUNT),
88+
};
8589

8690
let fee_asset = assets.clone().reanchored(&dest, &context).expect("should reanchor");
8791
let fees = fee_asset.clone();
@@ -156,43 +160,10 @@ fn reserve_transfer_on_AH(amount: u128, beneficiary: Location) {
156160
});
157161

158162
}
159-
#[test]
160-
fn should_dispatch_ismp_request_when_assets_are_received_from_assethub() {
161-
init_tracing();
162-
MockNet::reset();
163-
164-
let asset_id: H256 = sp_io::hashing::keccak_256(&Location::new(1, Here).encode()).into();
165-
166-
let beneficiary: Location = Junctions::X3(Arc::new([
167-
Junction::AccountId32 { network: None, id: ALICE.into() },
168-
Junction::AccountKey20 {
169-
network: Some(NetworkId::Ethereum { chain_id: 97 }),
170-
key: [1u8; 20],
171-
},
172-
Junction::GeneralIndex(60 * 60),
173-
]))
174-
.into_location();
175-
176-
reserve_transfer_on_AH(SEND_AMOUNT, beneficiary);
177-
178-
ParaA::execute_with(|| {
179-
let nonce = pallet_ismp::Nonce::<Test>::get();
180-
assert_eq!(nonce, 1);
181-
182-
let protocol_fees = pallet_xcm_gateway::Pallet::<Test>::protocol_fee_percentage();
183-
let custodied_amount = SEND_AMOUNT - (protocol_fees * SEND_AMOUNT);
184-
185-
let pallet_account_balance =
186-
<runtime::Assets as Inspect<<Test as frame_system::Config>::AccountId>>::balance(
187-
asset_id.into(),
188-
&pallet_xcm_gateway::Pallet::<Test>::account_id(),
189-
);
190-
assert_eq!(custodied_amount, pallet_account_balance);
191-
});
192-
}
193163

194164
#[test]
195165
fn should_process_on_accept_module_callback_correctly() {
166+
init_tracing();
196167
MockNet::reset();
197168

198169
let beneficiary: Location = Junctions::X3(Arc::new([
@@ -206,14 +177,22 @@ fn should_process_on_accept_module_callback_correctly() {
206177
.into_location();
207178
let weight_limit = WeightLimit::Unlimited;
208179

209-
let asset_id: H256 = sp_io::hashing::keccak_256(&Location::new(1, Here).encode()).into();
210-
211-
212-
reserve_transfer_on_AH(SEND_AMOUNT, beneficiary);
180+
let asset_location = Location::new(1, Here);
213181

182+
let dest = Location::new(1, [Parachain(PARA_ID)]);
183+
let asset_id: H256 = sp_io::hashing::keccak_256(&asset_location.encode()).into();
214184

215185

216186
let alice_balance = ParaB::execute_with(|| {
187+
let result = PalletXcm::limited_reserve_transfer_assets(
188+
runtime::RuntimeOrigin::signed(ALICE),
189+
Box::new(dest.clone().into()),
190+
Box::new(beneficiary.clone().into()),
191+
Box::new((asset_location, SEND_AMOUNT).into()),
192+
0,
193+
weight_limit,
194+
);
195+
assert_ok!(result);
217196
let alice_balance = <runtime::Assets as Inspect<
218197
<Test as frame_system::Config>::AccountId,
219198
>>::balance(asset_id, &ALICE);
@@ -244,15 +223,9 @@ fn should_process_on_accept_module_callback_correctly() {
244223
assert_eq!(custodied_amount, pallet_account_balance);
245224
});
246225

247-
ParaB::execute_with(|| {
248-
let dot_asset_location = Location::new(1, Parachain(1000));
249-
let dot_asset_id: H256 = sp_io::hashing::keccak_256(&dot_asset_location.encode()).into();
250-
251-
Assets::set_balance(dot_asset_id, &pallet_xcm_gateway::Pallet::<Test>::account_id(), SEND_AMOUNT * 10);
252-
});
253-
254226
// Process on accept call back
255227
let transferred = ParaA::execute_with(|| {
228+
256229
let protocol_fees = pallet_xcm_gateway::Pallet::<Test>::protocol_fee_percentage();
257230
let amount = SEND_AMOUNT - (protocol_fees * SEND_AMOUNT);
258231
let body = Body {
@@ -284,6 +257,7 @@ fn should_process_on_accept_module_callback_correctly() {
284257
let initial_total_issuance = <pallet_assets::Pallet<Test> as Inspect<
285258
<Test as frame_system::Config>::AccountId,
286259
>>::total_issuance(asset_id.clone());
260+
dbg!(initial_total_issuance);
287261
ismp_module.on_accept(post).unwrap();
288262

289263
let total_issuance_after = <pallet_assets::Pallet<Test> as Inspect<
@@ -294,15 +268,16 @@ fn should_process_on_accept_module_callback_correctly() {
294268
amount
295269
});
296270

297-
Relay::execute_with(|| {
298-
// Alice's balance on relay chain should have increased by the amount transferred
299-
let current_balance = pallet_balances::Pallet::<relay_chain::Runtime>::free_balance(&ALICE);
271+
ParaB::execute_with(|| {
272+
// Alice's balance on asset hub should have increased by the amount transferred
273+
let current_balance = Assets::balance(asset_id, &ALICE);
300274
assert_eq!(current_balance, alice_balance + transferred);
301275
})
302276
}
303277

304278
#[test]
305279
fn should_process_on_timeout_module_callback_correctly() {
280+
init_tracing();
306281
MockNet::reset();
307282

308283
let beneficiary: Location = Junctions::X3(Arc::new([
@@ -316,22 +291,26 @@ fn should_process_on_timeout_module_callback_correctly() {
316291
.into_location();
317292
let weight_limit = WeightLimit::Unlimited;
318293

319-
let dest: Location = Junction::Parachain(PARA_ID).into();
320-
let asset_id: H256 = sp_io::hashing::keccak_256(&Location::parent().encode()).into();
294+
let asset_location = Location::new(1, Here);
295+
296+
let dest = Location::new(1, [Parachain(PARA_ID)]);
297+
let asset_id: H256 = sp_io::hashing::keccak_256(&asset_location.encode()).into();
321298

322-
let alice_balance = Relay::execute_with(|| {
323-
// call extrinsic
324-
let result = RelayChainPalletXcm::limited_reserve_transfer_assets(
325-
RuntimeOrigin::signed(ALICE),
299+
let alice_balance = ParaB::execute_with(|| {
300+
let result = PalletXcm::limited_reserve_transfer_assets(
301+
runtime::RuntimeOrigin::signed(ALICE),
326302
Box::new(dest.clone().into()),
327303
Box::new(beneficiary.clone().into()),
328-
Box::new((Junctions::Here, SEND_AMOUNT).into()),
304+
Box::new((asset_location, SEND_AMOUNT).into()),
329305
0,
330306
weight_limit,
331307
);
332308
assert_ok!(result);
333-
// return alice's account balance
334-
pallet_balances::Pallet::<relay_chain::Runtime>::free_balance(&ALICE)
309+
let alice_balance = <runtime::Assets as Inspect<
310+
<Test as frame_system::Config>::AccountId,
311+
>>::balance(asset_id, &ALICE);
312+
dbg!(alice_balance);
313+
alice_balance
335314
});
336315

337316
// Parachain should receive xcm
@@ -403,9 +382,9 @@ fn should_process_on_timeout_module_callback_correctly() {
403382
amount
404383
});
405384

406-
Relay::execute_with(|| {
385+
ParaB::execute_with(|| {
407386
// Alice's balance on relay chain should have increased by the amount transferred
408-
let current_balance = pallet_balances::Pallet::<relay_chain::Runtime>::free_balance(&ALICE);
387+
let current_balance = Assets::balance(asset_id, &ALICE);
409388
assert_eq!(current_balance, alice_balance + transferred);
410389
})
411390
}

modules/pallets/testsuite/src/xcm.rs

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

8282
parameter_types! {
8383
pub const RelayLocation: Location = Location::parent();
84+
pub ParaALocation: Location = Location::new(1, Parachain(SIBLING_PARA_ID));
8485
pub const RelayNetwork: Option<NetworkId> = None;
8586
pub UniversalLocation: Junctions = Parachain(ParachainInfo::parachain_id().into()).into();
8687
}
@@ -138,21 +139,16 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
138139
let asset_location = Location::new(1, Here);
139140
let asset_id: H256 = sp_io::hashing::keccak_256(&asset_location.encode()).into();
140141

141-
let dot_asset_location = Location::new(1, Parachain(1000));
142-
let dot_asset_id: H256 = sp_io::hashing::keccak_256(&dot_asset_location.encode()).into();
143142

144143
let config: pallet_assets::GenesisConfig<Test> = pallet_assets::GenesisConfig {
145144
assets: vec![
146145
// id, owner, is_sufficient, min_balance
147146
(asset_id.clone(), ALICE, true, 1),
148-
(dot_asset_id.clone(), ALICE, true, 1),
149147
],
150-
accounts: vec![(asset_id, ALICE.into(), 1000_000_000_0000 * 10), (asset_id, BOB.into(), 0),
151-
(dot_asset_id, ALICE.into(), 1000_000_000_0000 * 10), (dot_asset_id, BOB.into(), 0)],
148+
accounts: vec![(asset_id, ALICE.into(), 10000_000_000_00000 * 10), (asset_id, BOB.into(), 0),],
152149
metadata: vec![
153150
// id, name, symbol, decimals
154151
(asset_id, "Token Name".into(), "TOKEN".into(), 10),
155-
(dot_asset_id, "Token Name 2".into(), "TOKEN2".into(), 10),
156152
],
157153
next_asset_id: None,
158154
};
@@ -221,7 +217,7 @@ decl_test_parachain! {
221217

222218
decl_test_parachain! {
223219
pub struct ParaB {
224-
Runtime = Test,
220+
Runtime = crate::asset_hub_runtime::AssetHubTest,
225221
XcmpMessageHandler = crate::runtime::MsgQueue,
226222
DmpMessageHandler = DmpMessageExecutor,
227223
new_ext = para_ext(1000),
@@ -254,24 +250,21 @@ pub type XcmRouter = ParachainXcmRouter<crate::runtime::MsgQueue>;
254250
pub type Barrier = AllowUnpaidExecutionFrom<Everything>;
255251

256252
parameter_types! {
257-
pub DotOnAssetHub: Location = Location::new(1, [Parachain(ASSET_HUB_PARA_ID)]);
253+
pub DotOnAssetHub: Location = Location::new(1, Here);
258254
}
259255

260-
parameter_types! {
261-
pub NativeAssetOnAssetHub: Location = Location {
262-
parents: 1,
263-
interior: X3(Arc::new([
264-
Parachain(ASSET_HUB_PARA_ID),
265-
PalletInstance(50),
266-
GeneralIndex(123),
267-
])),
268-
};
269-
}
256+
257+
258+
259+
260+
261+
262+
270263

271264
pub struct TestReserve;
272265
impl ContainsPair<Asset, Location> for TestReserve {
273266
fn contains(asset: &Asset, origin: &Location) -> bool {
274-
log::trace!(target: "xcm", "TestReserve::contains asset: {asset:?}, origin:{origin:?}");
267+
println!("TestReserve::contains asset: {asset:?}, origin:{origin:?}");
275268
let assethub_location = Location::new(1, Parachain(ASSET_HUB_PARA_ID));
276269
&assethub_location == origin
277270
}
@@ -351,6 +344,7 @@ use polkadot_sdk::{
351344
staging_xcm_builder::ExternalConsensusLocationsConverterFor,
352345
xcm_simulator::Junctions::{X1, X3},
353346
};
347+
use polkadot_sdk::sp_runtime::traits::AccountIdConversion;
354348

355349
impl cumulus_pallet_xcmp_queue::Config for Test {
356350
type RuntimeEvent = RuntimeEvent;
@@ -407,7 +401,7 @@ impl pallet_xcm::Config for Test {
407401
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
408402
type XcmExecuteFilter = Everything;
409403
type XcmExecutor = XcmExecutor<XcmConfig>;
410-
type XcmTeleportFilter = Nothing;
404+
type XcmTeleportFilter = Everything;
411405
type XcmReserveTransferFilter = Everything;
412406
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
413407
type UniversalLocation = UniversalLocation;

0 commit comments

Comments
 (0)