Skip to content

Commit

Permalink
update subtree
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Dec 21, 2023
2 parents 8a6e702 + ac09be0 commit 7535c5b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
18 changes: 16 additions & 2 deletions bridges/snowbridge/parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use crate::mock::*;
fn test_submit_happy_path() {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);
let channel_sovereign = sibling_sovereign_account::<Test>(ASSET_HUB_PARAID.into());

let origin = RuntimeOrigin::signed(relayer.clone());

// Submit message
let message = Message {
Expand All @@ -28,6 +30,11 @@ fn test_submit_happy_path() {
data: Default::default(),
},
};

let initial_fund = InitialFund::get();
assert_eq!(Balances::balance(&relayer), 0);
assert_eq!(Balances::balance(&channel_sovereign), initial_fund);

assert_ok!(InboundQueue::submit(origin.clone(), message.clone()));
expect_events(vec![InboundQueueEvent::MessageReceived {
channel_id: hex!("c173fac324158e77fb5840738a1a541f633cbec8884c6a601c567d2b376a0539")
Expand All @@ -39,6 +46,13 @@ fn test_submit_happy_path() {
],
}
.into()]);

let reward = Parameters::get().rewards.local;
assert!(Balances::balance(&relayer) >= reward, "relayer was rewarded");
assert!(
Balances::balance(&channel_sovereign) <= initial_fund - reward,
"sovereign account paid reward"
);
});
}

Expand All @@ -49,7 +63,7 @@ fn test_submit_xcm_invalid_channel() {
let origin = RuntimeOrigin::signed(relayer);

// Deposit funds into sovereign account of parachain 1001
let sovereign_account = sibling_sovereign_account::<Test>(1001u32.into());
let sovereign_account = sibling_sovereign_account::<Test>(TEMPLATE_PARAID.into());
println!("account: {}", sovereign_account);
let _ = Balances::mint_into(&sovereign_account, 10000);

Expand Down
19 changes: 18 additions & 1 deletion bridges/snowbridge/parachain/pallets/outbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn convert_local_currency() {
}

#[test]
fn encode_digest_item() {
fn encode_digest_item_with_correct_index() {
new_tester().execute_with(|| {
let digest_item: DigestItem = CustomDigestItem::Snowbridge(H256::default()).into();
let enum_prefix = match digest_item {
Expand All @@ -249,3 +249,20 @@ fn encode_digest_item() {
assert_eq!(enum_prefix, 0);
});
}

#[test]
fn encode_digest_item() {
new_tester().execute_with(|| {
let digest_item: DigestItem = CustomDigestItem::Snowbridge([5u8; 32].into()).into();
let digest_item_raw = digest_item.encode();
assert_eq!(digest_item_raw[0], 0); // DigestItem::Other
assert_eq!(digest_item_raw[2], 0); // CustomDigestItem::Snowbridge
assert_eq!(
digest_item_raw,
[
0, 132, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ use super::GlobalConsensusEthereumConvertsFor;
use crate::inbound::CallIndex;
use frame_support::parameter_types;
use hex_literal::hex;
use sp_core::crypto::Ss58Codec;
use xcm::v3::prelude::*;
use xcm_executor::traits::ConvertLocation;

const NETWORK: NetworkId = Ethereum { chain_id: 11155111 };
const SS58_FORMAT: u16 = 2;
const EXPECTED_SOVEREIGN_KEY: [u8; 32] =
hex!("ce796ae65569a670d0c1cc1ac12515a3ce21b5fbf729d63d7b289baad070139d");
const EXPECTED_SOVEREIGN_ADDRESS: &str = "HF3T62xRQvoCCowYamEQweEyWbD5yt4mkET8UkNWxfMbvJE";

parameter_types! {
pub EthereumNetwork: NetworkId = NETWORK;
Expand All @@ -21,35 +16,17 @@ parameter_types! {
pub const SendTokenExecutionFee: u128 = 592;
}

#[test]
fn test_contract_location_without_network_converts_successfully() {
let contract_location = MultiLocation { parents: 2, interior: X1(GlobalConsensus(NETWORK)) };

let account =
GlobalConsensusEthereumConvertsFor::<[u8; 32]>::convert_location(&contract_location)
.unwrap();
let address = frame_support::sp_runtime::AccountId32::new(account)
.to_ss58check_with_version(SS58_FORMAT.into());

println!("SS58: {}\nBytes: {:?}", address, account);

assert_eq!(account, EXPECTED_SOVEREIGN_KEY);
assert_eq!(address, EXPECTED_SOVEREIGN_ADDRESS);
}

#[test]
fn test_contract_location_with_network_converts_successfully() {
let expected_account: [u8; 32] =
hex!("ce796ae65569a670d0c1cc1ac12515a3ce21b5fbf729d63d7b289baad070139d");
let contract_location = MultiLocation { parents: 2, interior: X1(GlobalConsensus(NETWORK)) };

let account =
GlobalConsensusEthereumConvertsFor::<[u8; 32]>::convert_location(&contract_location)
.unwrap();
let address = frame_support::sp_runtime::AccountId32::new(account)
.to_ss58check_with_version(SS58_FORMAT.into());
assert_eq!(account, EXPECTED_SOVEREIGN_KEY);
assert_eq!(address, EXPECTED_SOVEREIGN_ADDRESS);

println!("SS58: {}\nBytes: {:?}", address, account);
assert_eq!(account, expected_account);
}

#[test]
Expand Down
16 changes: 15 additions & 1 deletion bridges/snowbridge/parachain/runtime/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
mod test_cases;

use asset_hub_rococo_runtime::xcm_config::bridging::to_ethereum::DefaultBridgeHubEthereumBaseFee;
use bridge_hub_rococo_runtime::{xcm_config::XcmConfig, Runtime, RuntimeEvent, SessionKeys};
use bridge_hub_rococo_runtime::{
xcm_config::XcmConfig, MessageQueueServiceWeight, Runtime, RuntimeEvent, SessionKeys,
};
use codec::Decode;
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees};
use parachains_common::{AccountId, AuraId};
use snowbridge_ethereum_beacon_client::WeightInfo;
use sp_core::H160;
use sp_keyring::AccountKeyring::Alice;

Expand Down Expand Up @@ -78,3 +81,14 @@ pub fn transfer_token_to_ethereum_insufficient_fund() {
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);
}

0 comments on commit 7535c5b

Please sign in to comment.