Skip to content

Commit 80f8b91

Browse files
chore(bulletin-westend-integration-tests): use sender and receiver instead
1 parent f961316 commit 80f8b91

File tree

2 files changed

+71
-62
lines changed

2 files changed

+71
-62
lines changed

runtimes/bulletin-westend/integration-tests/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ use asset_hub_westend_emulated_chain::AssetHubWestend;
2424
use bulletin_westend_runtime::SessionKeys;
2525
use cumulus_primitives_core::ParaId;
2626
use emulated_integration_tests_common::{
27-
accounts, impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
28-
impl_xcm_helpers_for_parachain, xcm_emulator::decl_test_parachains, AuraDigestProvider,
27+
accounts::{self, ALICE, BOB},
28+
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
29+
impl_xcm_helpers_for_parachain,
30+
xcm_emulator::decl_test_parachains,
31+
AuraDigestProvider,
2932
};
3033
use frame_support::traits::OnInitialize;
3134
use parachains_common::{AuraId, Balance};
3235
use sp_core::sr25519;
3336
use sp_keyring::Sr25519Keyring;
3437
use westend_emulated_chain::Westend;
35-
use xcm_emulator::{decl_test_networks, Parachain};
38+
use xcm_emulator::{
39+
decl_test_networks, decl_test_sender_receiver_accounts_parameter_types, Parachain,
40+
};
3641

3742
/// Bulletin Westend parachain ID (1006 on Westend).
3843
pub const BULLETIN_PARA_ID: u32 = 1006;
@@ -78,6 +83,11 @@ impl_accounts_helpers_for_parachain!(BulletinWestend);
7883
impl_assert_events_helpers_for_parachain!(BulletinWestend);
7984
impl_xcm_helpers_for_parachain!(BulletinWestend);
8085

86+
decl_test_sender_receiver_accounts_parameter_types! {
87+
BulletinWestendPara { sender: ALICE, receiver: BOB },
88+
AssetHubWestendPara { sender: ALICE, receiver: BOB }
89+
}
90+
8191
/// Genesis configuration for Bulletin Westend parachain.
8292
pub fn bulletin_genesis() -> sp_runtime::Storage {
8393
use bulletin_westend_runtime::RuntimeGenesisConfig;

runtimes/bulletin-westend/integration-tests/src/tests/reserve_transfers.rs

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
//! 1. WND reserve transfers from Asset Hub to Bulletin (Asset Hub is reserve - LocalReserve)
2020
//! 2. WND reserve transfers from Bulletin back to Asset Hub (DestinationReserve)
2121
22-
use crate::{BulletinWestend, WestendMockNet, BULLETIN_PARA_ID};
22+
use crate::{
23+
AssetHubWestendParaReceiver, AssetHubWestendParaSender, BulletinWestend,
24+
BulletinWestendParaReceiver, BulletinWestendParaSender, WestendMockNet, BULLETIN_PARA_ID,
25+
};
2326
use asset_hub_westend_emulated_chain::AssetHubWestend;
2427
use frame_support::{
2528
assert_ok,
2629
traits::fungible::{Inspect, Mutate},
2730
};
2831
use parachains_common::Balance;
29-
use sp_keyring::Sr25519Keyring;
3032
use xcm::{latest::prelude::*, VersionedXcm};
3133
use xcm_emulator::{Chain, Network, Parachain, TestExt};
3234
use xcm_executor::traits::TransferType;
@@ -40,11 +42,6 @@ const TRANSFER_AMOUNT: Balance = 1_000_000_000_000; // 1 WND
4042
/// Amount to use for fees.
4143
const FEE_AMOUNT: Balance = 500_000_000_000; // 0.5 WND
4244

43-
/// Get the account ID for a keyring as bytes.
44-
fn account_id(keyring: Sr25519Keyring) -> [u8; 32] {
45-
keyring.to_account_id().into()
46-
}
47-
4845
/// Type alias for AssetHubWestend with our network.
4946
type AssetHubWestendNet = AssetHubWestend<WestendMockNet>;
5047

@@ -64,31 +61,32 @@ fn reserve_transfer_wnd_from_asset_hub_to_bulletin() {
6461
// Reset the network state for a clean test
6562
WestendMockNet::reset();
6663

67-
let alice = Sr25519Keyring::Alice;
68-
let bob = Sr25519Keyring::Bob;
64+
let sender = AssetHubWestendParaSender::get();
65+
let receiver = BulletinWestendParaReceiver::get();
6966

7067
// Get initial balances
71-
let alice_initial_on_asset_hub = AssetHubWestendNet::execute_with(|| {
68+
let sender_initial_on_asset_hub = AssetHubWestendNet::execute_with(|| {
7269
type Balances = asset_hub_westend_runtime::Balances;
73-
<Balances as Inspect<_>>::balance(&alice.to_account_id())
70+
<Balances as Inspect<_>>::balance(&sender)
7471
});
7572

76-
let bob_initial_on_bulletin = BulletinWestendNet::execute_with(|| {
73+
let receiver_initial_on_bulletin = BulletinWestendNet::execute_with(|| {
7774
type Balances = bulletin_westend_runtime::Balances;
78-
<Balances as Inspect<_>>::balance(&bob.to_account_id())
75+
<Balances as Inspect<_>>::balance(&receiver)
7976
});
8077

81-
// Ensure Alice has enough balance
78+
// Ensure sender has enough balance
8279
assert!(
83-
alice_initial_on_asset_hub >= TRANSFER_AMOUNT + FEE_AMOUNT,
84-
"Alice needs sufficient balance on Asset Hub"
80+
sender_initial_on_asset_hub >= TRANSFER_AMOUNT + FEE_AMOUNT,
81+
"Sender needs sufficient balance on Asset Hub"
8582
);
8683

8784
// Construct the destination: Bulletin parachain (from Asset Hub's perspective)
8885
let dest = Location::new(1, [Parachain(BULLETIN_PARA_ID)]);
8986

90-
// Construct the beneficiary: Bob on the destination chain
91-
let beneficiary = Location::new(0, [AccountId32 { network: None, id: account_id(bob) }]);
87+
// Construct the beneficiary: receiver on the destination chain
88+
let beneficiary =
89+
Location::new(0, [AccountId32 { network: None, id: receiver.clone().into() }]);
9290

9391
// WND asset location (relay chain native token)
9492
let wnd_location = Location::parent();
@@ -109,7 +107,7 @@ fn reserve_transfer_wnd_from_asset_hub_to_bulletin() {
109107
type RuntimeOrigin = <AssetHubWestendNet as Chain>::RuntimeOrigin;
110108

111109
let result = PolkadotXcm::transfer_assets_using_type_and_then(
112-
RuntimeOrigin::signed(alice.to_account_id()),
110+
RuntimeOrigin::signed(sender.clone()),
113111
Box::new(dest.into()),
114112
Box::new(assets.into()),
115113
Box::new(TransferType::LocalReserve),
@@ -131,23 +129,23 @@ fn reserve_transfer_wnd_from_asset_hub_to_bulletin() {
131129
assert_ok!(result);
132130
});
133131

134-
// Verify Alice's balance decreased on Asset Hub
132+
// Verify sender's balance decreased on Asset Hub
135133
AssetHubWestendNet::execute_with(|| {
136134
type Balances = asset_hub_westend_runtime::Balances;
137-
let alice_balance = <Balances as Inspect<_>>::balance(&alice.to_account_id());
135+
let sender_balance = <Balances as Inspect<_>>::balance(&sender);
138136
assert!(
139-
alice_balance < alice_initial_on_asset_hub,
140-
"Alice's balance should decrease after transfer"
137+
sender_balance < sender_initial_on_asset_hub,
138+
"Sender's balance should decrease after transfer"
141139
);
142140
// Account for transfer amount + fees
143141
assert!(
144-
alice_initial_on_asset_hub - alice_balance >= TRANSFER_AMOUNT,
145-
"Alice should have transferred at least {} WND",
142+
sender_initial_on_asset_hub - sender_balance >= TRANSFER_AMOUNT,
143+
"Sender should have transferred at least {} WND",
146144
TRANSFER_AMOUNT
147145
);
148146
});
149147

150-
// Verify Bob's balance increased on Bulletin
148+
// Verify receiver's balance increased on Bulletin
151149
BulletinWestendNet::execute_with(|| {
152150
type Balances = bulletin_westend_runtime::Balances;
153151

@@ -158,13 +156,13 @@ fn reserve_transfer_wnd_from_asset_hub_to_bulletin() {
158156
println!(" Bulletin Event: {:?}", event.event);
159157
}
160158

161-
let bob_balance = <Balances as Inspect<_>>::balance(&bob.to_account_id());
162-
// Bob should receive the transferred amount minus any execution fees
159+
let receiver_balance = <Balances as Inspect<_>>::balance(&receiver);
160+
// Receiver should receive the transferred amount minus any execution fees
163161
assert!(
164-
bob_balance > bob_initial_on_bulletin,
165-
"Bob's balance should increase after receiving transfer. Initial: {}, Current: {}",
166-
bob_initial_on_bulletin,
167-
bob_balance
162+
receiver_balance > receiver_initial_on_bulletin,
163+
"Receiver's balance should increase after receiving transfer. Initial: {}, Current: {}",
164+
receiver_initial_on_bulletin,
165+
receiver_balance
168166
);
169167
});
170168
}
@@ -198,36 +196,37 @@ fn reserve_transfer_wnd_from_bulletin_to_asset_hub() {
198196
<Balances as Mutate<_>>::mint_into(&sovereign_account, fund_amount).unwrap();
199197
});
200198

201-
let alice = Sr25519Keyring::Alice;
202-
let bob = Sr25519Keyring::Bob;
199+
let sender = BulletinWestendParaSender::get();
200+
let receiver = AssetHubWestendParaReceiver::get();
203201

204202
// Get initial balances
205-
let alice_initial_on_bulletin = BulletinWestendNet::execute_with(|| {
203+
let sender_initial_on_bulletin = BulletinWestendNet::execute_with(|| {
206204
type Balances = bulletin_westend_runtime::Balances;
207-
<Balances as Inspect<_>>::balance(&alice.to_account_id())
205+
<Balances as Inspect<_>>::balance(&sender)
208206
});
209207

210-
let bob_initial_on_asset_hub = AssetHubWestendNet::execute_with(|| {
208+
let receiver_initial_on_asset_hub = AssetHubWestendNet::execute_with(|| {
211209
type Balances = asset_hub_westend_runtime::Balances;
212-
<Balances as Inspect<_>>::balance(&bob.to_account_id())
210+
<Balances as Inspect<_>>::balance(&receiver)
213211
});
214212

215-
// Ensure Alice has enough balance on Bulletin
216-
// If Alice doesn't have enough, we skip this test since it depends on genesis config
217-
if alice_initial_on_bulletin < TRANSFER_AMOUNT + FEE_AMOUNT {
213+
// Ensure sender has enough balance on Bulletin
214+
// If sender doesn't have enough, we skip this test since it depends on genesis config
215+
if sender_initial_on_bulletin < TRANSFER_AMOUNT + FEE_AMOUNT {
218216
println!(
219-
"Skipping test: Alice needs at least {} on Bulletin, has {}",
217+
"Skipping test: Sender needs at least {} on Bulletin, has {}",
220218
TRANSFER_AMOUNT + FEE_AMOUNT,
221-
alice_initial_on_bulletin
219+
sender_initial_on_bulletin
222220
);
223221
return;
224222
}
225223

226224
// Construct the destination: Asset Hub parachain (from Bulletin's perspective)
227225
let dest = Location::new(1, [Parachain(ASSET_HUB_PARA_ID)]);
228226

229-
// Construct the beneficiary: Bob on the destination chain
230-
let beneficiary = Location::new(0, [AccountId32 { network: None, id: account_id(bob) }]);
227+
// Construct the beneficiary: receiver on the destination chain
228+
let beneficiary =
229+
Location::new(0, [AccountId32 { network: None, id: receiver.clone().into() }]);
231230

232231
// WND asset location (relay chain native token)
233232
let wnd_location = Location::parent();
@@ -248,7 +247,7 @@ fn reserve_transfer_wnd_from_bulletin_to_asset_hub() {
248247
type RuntimeOrigin = <BulletinWestendNet as Chain>::RuntimeOrigin;
249248

250249
let result = PolkadotXcm::transfer_assets_using_type_and_then(
251-
RuntimeOrigin::signed(alice.to_account_id()),
250+
RuntimeOrigin::signed(sender.clone()),
252251
Box::new(dest.into()),
253252
Box::new(assets.into()),
254253
Box::new(TransferType::DestinationReserve),
@@ -270,23 +269,23 @@ fn reserve_transfer_wnd_from_bulletin_to_asset_hub() {
270269
assert_ok!(result);
271270
});
272271

273-
// Verify Alice's balance decreased on Bulletin
272+
// Verify sender's balance decreased on Bulletin
274273
BulletinWestendNet::execute_with(|| {
275274
type Balances = bulletin_westend_runtime::Balances;
276-
let alice_balance = <Balances as Inspect<_>>::balance(&alice.to_account_id());
275+
let sender_balance = <Balances as Inspect<_>>::balance(&sender);
277276
assert!(
278-
alice_balance < alice_initial_on_bulletin,
279-
"Alice's balance should decrease after transfer"
277+
sender_balance < sender_initial_on_bulletin,
278+
"Sender's balance should decrease after transfer"
280279
);
281280
// Account for transfer amount + fees
282281
assert!(
283-
alice_initial_on_bulletin - alice_balance >= TRANSFER_AMOUNT,
284-
"Alice should have transferred at least {} WND",
282+
sender_initial_on_bulletin - sender_balance >= TRANSFER_AMOUNT,
283+
"Sender should have transferred at least {} WND",
285284
TRANSFER_AMOUNT
286285
);
287286
});
288287

289-
// Verify Bob's balance increased on Asset Hub
288+
// Verify receiver's balance increased on Asset Hub
290289
AssetHubWestendNet::execute_with(|| {
291290
type Balances = asset_hub_westend_runtime::Balances;
292291

@@ -297,13 +296,13 @@ fn reserve_transfer_wnd_from_bulletin_to_asset_hub() {
297296
println!(" Asset Hub Event: {:?}", event.event);
298297
}
299298

300-
let bob_balance = <Balances as Inspect<_>>::balance(&bob.to_account_id());
301-
// Bob should receive the transferred amount minus any execution fees
299+
let receiver_balance = <Balances as Inspect<_>>::balance(&receiver);
300+
// Receiver should receive the transferred amount minus any execution fees
302301
assert!(
303-
bob_balance > bob_initial_on_asset_hub,
304-
"Bob's balance should increase after receiving transfer. Initial: {}, Current: {}",
305-
bob_initial_on_asset_hub,
306-
bob_balance
302+
receiver_balance > receiver_initial_on_asset_hub,
303+
"Receiver's balance should increase after receiving transfer. Initial: {}, Current: {}",
304+
receiver_initial_on_asset_hub,
305+
receiver_balance
307306
);
308307
});
309308
}

0 commit comments

Comments
 (0)