Skip to content

Commit 697f4ed

Browse files
committed
More tests
1 parent 635b91f commit 697f4ed

File tree

1 file changed

+107
-1
lines changed
  • cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests

1 file changed

+107
-1
lines changed

cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge.rs

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ use crate::{
2525
create_foreign_on_ah_rococo,
2626
penpal_emulated_chain::penpal_runtime,
2727
snowbridge_common::{
28-
bridged_roc_at_ah_westend, ethereum, register_roc_on_bh, snowbridge_sovereign,
28+
bridge_hub, bridged_roc_at_ah_westend, ethereum, register_roc_on_bh,
29+
snowbridge_sovereign,
2930
},
3031
snowbridge_v2_outbound_from_rococo::create_foreign_on_ah_westend,
3132
},
@@ -2224,3 +2225,108 @@ fn transfer_roc_from_ah_with_transfer_and_then() {
22242225
);
22252226
});
22262227
}
2228+
2229+
#[test]
2230+
fn register_pna_in_v5_while_transfer_in_v4_should_work() {
2231+
let assethub_sovereign = BridgeHubWestend::sovereign_account_id_of(
2232+
BridgeHubWestend::sibling_location_of(AssetHubWestend::para_id()),
2233+
);
2234+
BridgeHubWestend::fund_accounts(vec![(assethub_sovereign.clone(), INITIAL_FUND)]);
2235+
2236+
let asset_id: Location = Location { parents: 1, interior: [].into() };
2237+
let expected_asset_id: Location = Location {
2238+
parents: 1,
2239+
interior: [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))].into(),
2240+
};
2241+
2242+
let _expected_token_id = TokenIdOf::convert_location(&expected_asset_id).unwrap();
2243+
2244+
let ethereum_sovereign: AccountId = snowbridge_sovereign();
2245+
2246+
// Register token in V5
2247+
BridgeHubWestend::execute_with(|| {
2248+
type RuntimeOrigin = <BridgeHubWestend as Chain>::RuntimeOrigin;
2249+
type RuntimeEvent = <BridgeHubWestend as Chain>::RuntimeEvent;
2250+
2251+
assert_ok!(<BridgeHubWestend as BridgeHubWestendPallet>::Balances::force_set_balance(
2252+
RuntimeOrigin::root(),
2253+
sp_runtime::MultiAddress::Id(BridgeHubWestendSender::get()),
2254+
INITIAL_FUND * 10,
2255+
));
2256+
2257+
assert_ok!(<BridgeHubWestend as BridgeHubWestendPallet>::EthereumSystem::register_token(
2258+
RuntimeOrigin::root(),
2259+
Box::new(VersionedLocation::from(asset_id.clone())),
2260+
AssetMetadata {
2261+
name: "wnd".as_bytes().to_vec().try_into().unwrap(),
2262+
symbol: "wnd".as_bytes().to_vec().try_into().unwrap(),
2263+
decimals: 12,
2264+
},
2265+
));
2266+
// Check that a message was sent to Ethereum to create the agent
2267+
assert_expected_events!(
2268+
BridgeHubWestend,
2269+
vec![RuntimeEvent::EthereumSystem(snowbridge_pallet_system::Event::RegisterToken { .. }) => {},]
2270+
);
2271+
});
2272+
2273+
AssetHubWestend::force_xcm_version(bridge_hub(), 4);
2274+
AssetHubWestend::force_xcm_version(ethereum(), 4);
2275+
AssetHubWestend::force_default_xcm_version(Some(4));
2276+
BridgeHubWestend::force_default_xcm_version(Some(4));
2277+
2278+
// Send token to Ethereum in V4 fomat
2279+
AssetHubWestend::execute_with(|| {
2280+
// LTS is V4
2281+
use xcm::lts::{Junction::*, NetworkId::*, *};
2282+
type RuntimeOrigin = <AssetHubWestend as Chain>::RuntimeOrigin;
2283+
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
2284+
2285+
let assets = vec![Asset {
2286+
id: AssetId(Location::parent()),
2287+
fun: Fungibility::try_from(Fungible(TOKEN_AMOUNT)).unwrap(),
2288+
}];
2289+
let versioned_assets = VersionedAssets::V4(Assets::from(assets));
2290+
2291+
let destination = VersionedLocation::V4(Location::new(
2292+
2,
2293+
[GlobalConsensus(Ethereum { chain_id: SEPOLIA_ID })],
2294+
));
2295+
2296+
let beneficiary = VersionedLocation::V4(Location::new(
2297+
0,
2298+
[AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS.into() }],
2299+
));
2300+
2301+
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::limited_reserve_transfer_assets(
2302+
RuntimeOrigin::signed(AssetHubWestendSender::get()),
2303+
Box::new(destination),
2304+
Box::new(beneficiary),
2305+
Box::new(versioned_assets),
2306+
0,
2307+
Unlimited,
2308+
));
2309+
2310+
let events = AssetHubWestend::events();
2311+
// Check that the native asset transferred to some reserved account(sovereign of Ethereum)
2312+
assert!(
2313+
events.iter().any(|event| matches!(
2314+
event,
2315+
RuntimeEvent::Balances(pallet_balances::Event::Transfer { amount, to, ..})
2316+
if *amount == TOKEN_AMOUNT && *to == ethereum_sovereign.clone(),
2317+
)),
2318+
"native token reserved to Ethereum sovereign account."
2319+
);
2320+
});
2321+
2322+
// Check that the transfer token back to Ethereum message was queue in the Ethereum
2323+
// Outbound Queue
2324+
BridgeHubWestend::execute_with(|| {
2325+
type RuntimeEvent = <BridgeHubWestend as Chain>::RuntimeEvent;
2326+
2327+
assert_expected_events!(
2328+
BridgeHubWestend,
2329+
vec![RuntimeEvent::EthereumOutboundQueue(snowbridge_pallet_outbound_queue::Event::MessageQueued{ .. }) => {},]
2330+
);
2331+
});
2332+
}

0 commit comments

Comments
 (0)