Skip to content

Commit

Permalink
improve hygiene & clean up - common
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoPal committed Aug 29, 2023
1 parent 2524436 commit b13e4e8
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 49 deletions.
8 changes: 0 additions & 8 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 @@ -14,20 +14,15 @@ grandpa = { package = "sc-consensus-grandpa", path = "../../../../../substrate/c
sp-authority-discovery = { path = "../../../../../substrate/primitives/authority-discovery", default-features = false}
sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false}
frame-support = { path = "../../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../../substrate/frame/system", default-features = false}
sp-core = { path = "../../../../../substrate/primitives/core", default-features = false}
sp-weights = { path = "../../../../../substrate/primitives/weights", default-features = false}
sp-consensus-babe = { path = "../../../../../substrate/primitives/consensus/babe", default-features = false}
sp-tracing = { path = "../../../../../substrate/primitives/tracing" }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false}
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false}
pallet-staking = { path = "../../../../../substrate/frame/staking", default-features = false}
pallet-message-queue = { path = "../../../../../substrate/frame/message-queue", default-features = false}
pallet-im-online = { path = "../../../../../substrate/frame/im-online", default-features = false}
beefy-primitives = { package = "sp-consensus-beefy", path = "../../../../../substrate/primitives/consensus/beefy" }

# Polkadot
polkadot-core-primitives = { path = "../../../../../polkadot/core-primitives", default-features = false}
polkadot-parachain = { path = "../../../../../polkadot/parachain", default-features = false}
polkadot-service = { path = "../../../../../polkadot/node/service", default-features = false, features = ["full-node"] }
polkadot-primitives = { path = "../../../../../polkadot/primitives", default-features = false}
Expand All @@ -41,12 +36,10 @@ rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/cons
westend-runtime = { path = "../../../../../polkadot/runtime/westend" }
westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants" }
xcm = { path = "../../../../../polkadot/xcm", default-features = false}
xcm-executor = { path = "../../../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false}

# Cumulus
parachains-common = { path = "../../../common" }
parachain-info = { path = "../../../pallets/parachain-info" }
cumulus-primitives-core = { path = "../../../../primitives/core" }
penpal-runtime = { path = "../../../runtimes/testing/penpal" }
asset-hub-polkadot-runtime = { path = "../../../runtimes/assets/asset-hub-polkadot" }
Expand All @@ -61,7 +54,6 @@ cumulus-pallet-dmp-queue = { path = "../../../../pallets/dmp-queue" }
cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false}
cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system" }
bp-messages = { path = "../../../../bridges/primitives/messages" }
bp-runtime = { path = "../../../../bridges/primitives/runtime" }
pallet-bridge-messages = { path = "../../../../bridges/modules/messages" }
bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common" }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
// Copyright 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/>.

// Substrate
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{sr25519, storage::Storage, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
BuildStorage, MultiSignature, Perbill,
};
use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId;
use grandpa::AuthorityId as GrandpaId;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;

// Cumulus
use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber};

// Polkadot
use polkadot_parachain::primitives::{HeadData, ValidationCode};
use polkadot_primitives::{AssignmentId, ValidatorId};
use polkadot_runtime_parachains::{
configuration::HostConfiguration,
paras::{ParaGenesisArgs, ParaKind},
};
use polkadot_service::chain_spec::get_authority_keys_from_seed_no_beefy;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{sr25519, storage::Storage, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
BuildStorage, MultiSignature, Perbill,
};
use xcm;

pub const XCM_V2: u32 = 3;
Expand Down
66 changes: 44 additions & 22 deletions cumulus/parachains/integration-tests/emulated/common/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
use super::{BridgeHubRococo, BridgeHubWococo};
pub use crate::constants::{PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD};
pub use crate::xcm_helpers::xcm_transact_unpaid_execution;
// Copyright 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/>.

pub use codec::{Decode, Encode};
pub use paste;

pub use crate::{
constants::{PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD},
xcm_helpers::xcm_transact_unpaid_execution,
BridgeHubRococo, BridgeHubWococo,
};

// Substrate
use sp_core::Get;
pub use frame_support::{traits::fungibles::Inspect, assert_ok};

// Cumulus
use bp_messages::{
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
LaneId, MessageKey, OutboundLaneData,
};
use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult;
pub use codec::{Decode, Encode};
pub use frame_support::{traits::fungibles::Inspect, assert_ok};
pub use cumulus_primitives_core::{relay_chain::HrmpChannelId, DmpMessageHandler, ParaId, XcmpMessageHandler};
use pallet_bridge_messages::{Config, Instance1, Instance2, OutboundLanes, Pallet};
use sp_core::Get;
pub use cumulus_primitives_core::{relay_chain::HrmpChannelId, DmpMessageHandler, ParaId, XcmpMessageHandler};
pub use parachains_common::{AccountId, Balance};
pub use xcm_emulator::{
helpers::weight_within_threshold, BridgeMessageHandler, Chain, DefaultMessageProcessor,
assert_expected_events, bx,
helpers::weight_within_threshold, BridgeMessageHandler, Chain,
BridgeMessage, BridgeMessageDispatchError, TestExt, Parachain, RelayChain,
};
pub use paste;
pub use parachains_common::{AccountId, Balance};

// Polkadot
pub use polkadot_runtime_parachains::{
dmp,
hrmp::HrmpChannels,
inclusion::{AggregateMessageOrigin, UmpQueueId},
};
pub use xcm_emulator::{
assert_expected_events, bx,
};
pub use xcm::{
prelude::{
OriginKind, Outcome, VersionedXcm, Weight,
Expand All @@ -32,8 +56,6 @@ pub use xcm::{
DoubleEncoded,
};



pub struct BridgeHubMessageHandler<S, T, I> {
_marker: std::marker::PhantomData<(S, T, I)>,
}
Expand Down Expand Up @@ -305,7 +327,7 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain {

/// A root origin force to open a channel between two Parachains
pub fn force_process_hrmp_open(sender: $crate::impls::ParaId, recipient: $crate::impls::ParaId) {
use $crate::impls::{Chain, HrmpChannelId};
use $crate::impls::Chain;

<Self as $crate::impls::TestExt>::execute_with(|| {
let relay_root_origin = <Self as Chain>::RuntimeOrigin::root();
Expand All @@ -316,9 +338,9 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
0
));

let channel_id = HrmpChannelId { sender, recipient };
let channel_id = $crate::impls::HrmpChannelId { sender, recipient };

let hrmp_channel_exist = polkadot_runtime_parachains::hrmp::HrmpChannels::<
let hrmp_channel_exist = $crate::impls::HrmpChannels::<
<Self as Chain>::Runtime,
>::contains_key(&channel_id);

Expand Down Expand Up @@ -577,10 +599,10 @@ macro_rules! impl_assets_helpers_for_parachain {
asset_owner: $crate::impls::AccountId,
amount_to_mint: u128,
) {
use $crate::impls::{bx, Chain, RelayChain, Parachain, Inspect};
use $crate::impls::{bx, Chain, RelayChain, Parachain, Inspect, TestExt};
// Init values for Relay Chain
let root_origin = <$relay_chain as Chain>::RuntimeOrigin::root();
let destination = <$relay_chain as RelayChain>::child_location_of(<$chain as Parachain>::para_id());
let destination = <$relay_chain>::child_location_of(<$chain>::para_id());
let xcm = Self::force_create_asset_xcm(
$crate::impls::OriginKind::Superuser,
id,
Expand All @@ -589,7 +611,7 @@ macro_rules! impl_assets_helpers_for_parachain {
min_balance,
);

<$relay_chain as $crate::impls::TestExt>::execute_with(|| {
<$relay_chain>::execute_with(|| {
$crate::impls::assert_ok!(<$relay_chain as [<$relay_chain Pallet>]>::XcmPallet::send(
root_origin,
bx!(destination.into()),
Expand All @@ -599,7 +621,7 @@ macro_rules! impl_assets_helpers_for_parachain {
<$relay_chain>::assert_xcm_pallet_sent();
});

<Self as $crate::impls::TestExt>::execute_with(|| {
Self::execute_with(|| {
Self::assert_dmp_queue_complete(Some($crate::impls::Weight::from_parts(1_019_445_000, 200_000)));

type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent;
Expand Down
22 changes: 21 additions & 1 deletion cumulus/parachains/integration-tests/emulated/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 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/>.

pub mod constants;
pub mod impls;
pub mod xcm_helpers;
Expand All @@ -7,8 +23,12 @@ use constants::{
asset_hub_kusama, asset_hub_polkadot, asset_hub_westend, bridge_hub_kusama,
bridge_hub_polkadot, bridge_hub_rococo, collectives, kusama, penpal, polkadot, rococo, westend,
};
use frame_support::traits::OnInitialize;
use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler};

// Substrate
use frame_support::traits::OnInitialize;

// Cumulus
use xcm_emulator::{
decl_test_bridges, decl_test_networks, decl_test_parachains,
decl_test_relay_chains, decl_test_sender_receiver_accounts_parameter_types,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 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/>.

use parachains_common::AccountId;
use xcm::{
prelude::{
Expand Down
7 changes: 4 additions & 3 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use std::{
ops::Deref,
sync::Mutex,
};
pub use codec::{Encode, Decode};

// Substrate
pub use frame_support::{
Expand All @@ -40,7 +41,7 @@ pub use frame_support::{
pub use frame_system::{Config as SystemConfig, Pallet as SystemPallet};
pub use pallet_balances::AccountData;
pub use sp_arithmetic::traits::Bounded;
pub use sp_core::{parameter_types, sr25519, storage::Storage, Pair, Encode};
pub use sp_core::{parameter_types, sr25519, storage::Storage, Pair};
pub use sp_io::TestExternalities;
pub use sp_std::{cell::RefCell, collections::vec_deque::VecDeque, fmt::Debug};
pub use sp_tracing;
Expand Down Expand Up @@ -1009,8 +1010,8 @@ macro_rules! decl_test_networks {
}

fn process_upward_messages() {
use $crate::{ProcessMessage, TestExt};
use sp_core::Encode;
use $crate::{Encode, ProcessMessage, TestExt};

while let Some((from_para_id, msg)) = $crate::UPWARD_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
let mut weight_meter = $crate::WeightMeter::max_limit();
<$relay_chain>::ext_wrapper(|| {
Expand Down

0 comments on commit b13e4e8

Please sign in to comment.