Skip to content

Commit 3a66cdb

Browse files
committed
More tests
1 parent 5226eed commit 3a66cdb

File tree

3 files changed

+98
-27
lines changed
  • bridges/snowbridge
  • cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests

3 files changed

+98
-27
lines changed

bridges/snowbridge/primitives/router/src/outbound/barriers.rs

-23
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,4 @@ mod tests {
100100
);
101101
assert!(result.is_ok());
102102
}
103-
104-
#[test]
105-
fn deny_with_reserve_transfer_to_relay_chain() {
106-
let mut xcm: Vec<Instruction<()>> = vec![DepositReserveAsset {
107-
assets: Wild(All),
108-
dest: Location { parents: 1, interior: Here },
109-
xcm: Default::default(),
110-
}];
111-
112-
let result = DenyThenTry::<
113-
DenyFirstExportMessageFrom<
114-
EverythingBut<Equals<AssetHubLocation>>,
115-
Equals<EthereumNetwork>,
116-
>,
117-
DenyThenTry<DenyReserveTransferToRelayChain, TakeWeightCredit>,
118-
>::should_execute(
119-
&AssetHubLocation::get(),
120-
&mut xcm,
121-
Weight::zero(),
122-
&mut Properties { weight_credit: Weight::zero(), message_id: None },
123-
);
124-
assert_err!(result, ProcessMessageError::Unsupported);
125-
}
126103
}

bridges/snowbridge/runtime/test-common/src/lib.rs

+53
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,56 @@ pub fn ethereum_to_polkadot_message_extrinsics_work<Runtime>(
623623
assert_ok!(sync_committee_outcome);
624624
});
625625
}
626+
627+
#[allow(clippy::too_many_arguments)]
628+
pub fn send_transfer_token_message_from_source_other_than_asset_hub_failure<Runtime, XcmConfig>(
629+
ethereum_chain_id: u64,
630+
collator_session_key: CollatorSessionKeys<Runtime>,
631+
runtime_para_id: u32,
632+
assethub_parachain_id: u32,
633+
another_parachain_id: u32,
634+
initial_amount: u128,
635+
weth_contract_address: H160,
636+
destination_address: H160,
637+
fee_amount: u128,
638+
expected_error: XcmError,
639+
) where
640+
Runtime: frame_system::Config
641+
+ pallet_balances::Config
642+
+ pallet_session::Config
643+
+ pallet_xcm::Config
644+
+ parachain_info::Config
645+
+ pallet_collator_selection::Config
646+
+ cumulus_pallet_parachain_system::Config
647+
+ snowbridge_pallet_outbound_queue::Config
648+
+ snowbridge_pallet_system::Config
649+
+ pallet_timestamp::Config,
650+
XcmConfig: xcm_executor::Config,
651+
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
652+
{
653+
ExtBuilder::<Runtime>::default()
654+
.with_collators(collator_session_key.collators())
655+
.with_session_keys(collator_session_key.session_keys())
656+
.with_para_id(runtime_para_id.into())
657+
.with_tracing()
658+
.build()
659+
.execute_with(|| {
660+
<snowbridge_pallet_system::Pallet<Runtime>>::initialize(
661+
runtime_para_id.into(),
662+
assethub_parachain_id.into(),
663+
)
664+
.unwrap();
665+
666+
// fund asset hub sovereign account enough so it can pay fees
667+
initial_fund::<Runtime>(assethub_parachain_id, initial_amount);
668+
669+
let outcome = send_transfer_token_message::<Runtime, XcmConfig>(
670+
ethereum_chain_id,
671+
another_parachain_id,
672+
weth_contract_address,
673+
destination_address,
674+
fee_amount,
675+
);
676+
assert_err!(outcome.ensure_complete(), expected_error);
677+
});
678+
}

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs

+45-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ use bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID;
2020
use bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID;
2121
use bp_polkadot_core::Signature;
2222
use bridge_hub_westend_runtime::{
23-
bridge_to_rococo_config, xcm_config::XcmConfig, AllPalletsWithoutSystem,
24-
BridgeRejectObsoleteHeadersAndMessages, Executive, MessageQueueServiceWeight, Runtime,
25-
RuntimeCall, RuntimeEvent, SessionKeys, TxExtension, UncheckedExtrinsic,
23+
bridge_to_rococo_config,
24+
xcm_config::{Barrier, XcmConfig},
25+
AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive,
26+
MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, TxExtension,
27+
UncheckedExtrinsic,
2628
};
2729
use codec::{Decode, Encode};
2830
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees};
29-
use frame_support::parameter_types;
31+
use frame_support::{assert_err, parameter_types, traits::ProcessMessageError};
3032
use parachains_common::{AccountId, AuraId, Balance};
3133
use snowbridge_pallet_ethereum_client::WeightInfo;
3234
use sp_core::H160;
@@ -35,9 +37,15 @@ use sp_runtime::{
3537
generic::{Era, SignedPayload},
3638
AccountId32,
3739
};
40+
use xcm::prelude::{
41+
All, AssetFilter, DepositReserveAsset, Here, Instruction, Location, Parachain, Weight, Wild,
42+
XcmError,
43+
};
44+
use xcm_executor::traits::{Properties, ShouldExecute};
3845

3946
parameter_types! {
4047
pub const DefaultBridgeHubEthereumBaseFee: Balance = 2_750_872_500_000;
48+
pub AssetHubLocation: Location = Location::new(1, Parachain(ASSET_HUB_WESTEND_PARACHAIN_ID));
4149
}
4250

4351
fn collator_session_keys() -> bridge_hub_test_utils::CollatorSessionKeys<Runtime> {
@@ -200,3 +208,36 @@ fn construct_and_apply_extrinsic(
200208
let r = Executive::apply_extrinsic(xt);
201209
r.unwrap()
202210
}
211+
212+
#[test]
213+
pub fn transfer_token_to_ethereum_from_source_other_than_asset_hub_failure() {
214+
snowbridge_runtime_test_common::send_transfer_token_message_from_source_other_than_asset_hub_failure::<Runtime, XcmConfig>(
215+
11155111,
216+
collator_session_keys(),
217+
BRIDGE_HUB_WESTEND_PARACHAIN_ID,
218+
ASSET_HUB_WESTEND_PARACHAIN_ID,
219+
2000,
220+
DefaultBridgeHubEthereumBaseFee::get(),
221+
H160::random(),
222+
H160::random(),
223+
DefaultBridgeHubEthereumBaseFee::get(),
224+
XcmError::Barrier,
225+
)
226+
}
227+
228+
#[test]
229+
fn deny_reserve_transfer_to_relay_chain() {
230+
let mut xcm: Vec<Instruction<()>> = vec![DepositReserveAsset {
231+
assets: AssetFilter::try_from(Wild(All)).unwrap(),
232+
dest: Location { parents: 1, interior: Here },
233+
xcm: Default::default(),
234+
}];
235+
236+
let result = Barrier::should_execute(
237+
&AssetHubLocation::get(),
238+
&mut xcm,
239+
Weight::zero(),
240+
&mut Properties { weight_credit: Weight::zero(), message_id: None },
241+
);
242+
assert_err!(result, ProcessMessageError::Unsupported);
243+
}

0 commit comments

Comments
 (0)