Skip to content

Commit

Permalink
runtime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Oct 5, 2023
1 parent 324468e commit a68c472
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ mod bridge_hub_rococo_tests {
BridgeGrandpaWococoInstance, BridgeParachainWococoInstance,
WithBridgeHubWococoMessagesInstance,
};
use bridge_hub_rococo_runtime::bridge_hub_wococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO;

bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!(
Runtime,
Expand Down Expand Up @@ -272,6 +273,18 @@ mod bridge_hub_rococo_tests {
construct_and_apply_extrinsic,
);
}

#[test]
pub fn transfer_token_works() {
bridge_hub_test_utils::test_cases::handle_transfer_token_message::<
Runtime,
XcmConfig,
>(
collator_session_keys(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
SIBLING_PARACHAIN_ID,
)
}
}

mod bridge_hub_wococo_tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pallet-bridge-parachains = { path = "../../../../../bridges/modules/parachains",
pallet-bridge-messages = { path = "../../../../../bridges/modules/messages", default-features = false }
pallet-bridge-relayers = { path = "../../../../../bridges/modules/relayers", default-features = false }
bridge-runtime-common = { path = "../../../../../bridges/bin/runtime-common", default-features = false }
snowbridge-outbound-queue = { path = "../../../../../../parachain/pallets/outbound-queue", default-features = false }

[features]
default = [ "std" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,100 @@ where
estimated_fee.into()
}

pub fn handle_transfer_token_message<
Runtime,
XcmConfig,
>(
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32,
sibling_parachain_id: u32,
lane_id: u32
) where
Runtime: frame_system::Config
+ pallet_balances::Config
+ pallet_session::Config
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_dmp_queue::Config
+ cumulus_pallet_parachain_system::Config
+ snowbridge_outbound_queue::Config,
XcmConfig: xcm_executor::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
{
assert_ne!(runtime_para_id, sibling_parachain_id);
let _sibling_parachain_location = MultiLocation::new(1, Parachain(sibling_parachain_id));

ExtBuilder::<Runtime>::default()
.with_collators(collator_session_key.collators())
.with_session_keys(collator_session_key.session_keys())
.with_para_id(runtime_para_id.into())
.with_tracing()
.build()
.execute_with(|| {
// prepare `ExportMessage`
let xcm = if let Some(fee) = maybe_paid_export_message {
// deposit ED to origin (if needed)
if let Some(ed) = existential_deposit {
XcmConfig::AssetTransactor::deposit_asset(
&ed,
&sibling_parachain_location,
&XcmContext::with_message_id([0; 32]),
)
.expect("deposited ed");
}
// deposit fee to origin
XcmConfig::AssetTransactor::deposit_asset(
&fee,
&sibling_parachain_location,
&XcmContext::with_message_id([0; 32]),
)
.expect("deposited fee");

Xcm(vec![
WithdrawAsset(MultiAssets::from(vec![fee.clone()])),
BuyExecution { fees: fee, weight_limit: Unlimited },
export_message_instruction(),
])
} else {
Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
export_message_instruction(),
])
};

// execute XCM
//let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
//assert_ok!(XcmExecutor::<XcmConfig>::execute_xcm(
// sibling_parachain_location,
// xcm,
// hash,
// RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
//)
//.ensure_complete());
//
//// check queue after
//assert_eq!(
// pallet_bridge_messages::OutboundLanes::<Runtime, MessagesPalletInstance>::try_get(
// expected_lane_id
// ),
// Ok(OutboundLaneData {
// oldest_unpruned_nonce: 1,
// latest_received_nonce: 0,
// latest_generated_nonce: 1,
// })
//);
//
//// check events
//let mut events = <frame_system::Pallet<Runtime>>::events()
// .into_iter()
// .filter_map(|e| unwrap_pallet_bridge_messages_event(e.event.encode()));
//assert!(
// events.any(|e| matches!(e, pallet_bridge_messages::Event::MessageAccepted { .. }))
//);
});
}

pub mod test_data {
use super::*;
use bp_header_chain::justification::GrandpaJustification;
Expand Down

0 comments on commit a68c472

Please sign in to comment.