This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Cumulus. | ||
|
||
// Cumulus is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Cumulus is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#![cfg(test)] | ||
|
||
use bridge_hub_rococo_runtime::{ | ||
xcm_config::XcmConfig, MessageQueueServiceWeight, Runtime, RuntimeEvent, SessionKeys, | ||
}; | ||
use codec::Decode; | ||
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees}; | ||
use frame_support::parameter_types; | ||
use parachains_common::{AccountId, AuraId, Balance}; | ||
use snowbridge_ethereum_beacon_client::WeightInfo; | ||
use sp_core::H160; | ||
use sp_keyring::AccountKeyring::Alice; | ||
|
||
parameter_types! { | ||
pub const DefaultBridgeHubEthereumBaseFee: Balance = 2_750_872_500_000; | ||
} | ||
|
||
fn collator_session_keys() -> bridge_hub_test_utils::CollatorSessionKeys<Runtime> { | ||
bridge_hub_test_utils::CollatorSessionKeys::new( | ||
AccountId::from(Alice), | ||
AccountId::from(Alice), | ||
SessionKeys { aura: AuraId::from(Alice.public()) }, | ||
) | ||
} | ||
|
||
#[test] | ||
pub fn transfer_token_to_ethereum_works() { | ||
snowbridge_runtime_tests::send_transfer_token_message_success::<Runtime, XcmConfig>( | ||
collator_session_keys(), | ||
1013, | ||
1000, | ||
H160::random(), | ||
H160::random(), | ||
DefaultBridgeHubEthereumBaseFee::get(), | ||
Box::new(|runtime_event_encoded: Vec<u8>| { | ||
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) { | ||
Ok(RuntimeEvent::EthereumOutboundQueue(event)) => Some(event), | ||
_ => None, | ||
} | ||
}), | ||
) | ||
} | ||
|
||
#[test] | ||
pub fn unpaid_transfer_token_to_ethereum_fails_with_barrier() { | ||
snowbridge_runtime_tests::send_unpaid_transfer_token_message::<Runtime, XcmConfig>( | ||
collator_session_keys(), | ||
1013, | ||
1000, | ||
H160::random(), | ||
H160::random(), | ||
) | ||
} | ||
|
||
#[test] | ||
pub fn transfer_token_to_ethereum_fee_not_enough() { | ||
snowbridge_runtime_tests::send_transfer_token_message_failure::<Runtime, XcmConfig>( | ||
collator_session_keys(), | ||
1013, | ||
1000, | ||
DefaultBridgeHubEthereumBaseFee::get() + 1_000_000_000, | ||
H160::random(), | ||
H160::random(), | ||
// fee not enough | ||
1_000_000_000, | ||
NotHoldingFees, | ||
) | ||
} | ||
|
||
#[test] | ||
pub fn transfer_token_to_ethereum_insufficient_fund() { | ||
snowbridge_runtime_tests::send_transfer_token_message_failure::<Runtime, XcmConfig>( | ||
collator_session_keys(), | ||
1013, | ||
1000, | ||
1_000_000_000, | ||
H160::random(), | ||
H160::random(), | ||
DefaultBridgeHubEthereumBaseFee::get(), | ||
FailedToTransactAsset("InsufficientBalance"), | ||
) | ||
} | ||
|
||
#[test] | ||
fn max_message_queue_service_weight_is_more_than_beacon_extrinsic_weights() { | ||
let max_message_queue_weight = MessageQueueServiceWeight::get(); | ||
let force_checkpoint = | ||
<Runtime as snowbridge_ethereum_beacon_client::Config>::WeightInfo::force_checkpoint(); | ||
let submit_checkpoint = | ||
<Runtime as snowbridge_ethereum_beacon_client::Config>::WeightInfo::submit(); | ||
max_message_queue_weight.all_gt(force_checkpoint); | ||
max_message_queue_weight.all_gt(submit_checkpoint); | ||
} |