Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test pallet order #112

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion bridges/snowbridge/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl pallet_balances::Config for Test {
type MaxFreezes = ();
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
type MaxHolds = ();
}

parameter_types! {
Expand Down
1 change: 0 additions & 1 deletion bridges/snowbridge/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl pallet_balances::Config for Test {
type MaxFreezes = ();
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
type MaxHolds = ();
}

impl pallet_xcm_origin::Config for Test {
Expand Down
108 changes: 99 additions & 9 deletions bridges/snowbridge/runtime/test-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
};
use snowbridge_core::{ChannelId, ParaId};
use snowbridge_pallet_ethereum_client_fixtures::*;
use sp_core::H160;
use sp_core::{H160, U256};
use sp_keyring::AccountKeyring::*;
use sp_runtime::{traits::Header, AccountId32, SaturatedConversion, Saturating};
use sp_runtime::{traits::Header, AccountId32, DigestItem, SaturatedConversion, Saturating};
use xcm::{
latest::prelude::*,
v3::Error::{self, Barrier},
Expand Down Expand Up @@ -53,7 +53,8 @@
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ snowbridge_pallet_outbound_queue::Config,
+ snowbridge_pallet_outbound_queue::Config
+ pallet_timestamp::Config,
XcmConfig: xcm_executor::Config,
{
let assethub_parachain_location = Location::new(1, Parachain(assethub_parachain_id));
Expand Down Expand Up @@ -125,7 +126,8 @@
+ pallet_message_queue::Config
+ cumulus_pallet_parachain_system::Config
+ snowbridge_pallet_outbound_queue::Config
+ snowbridge_pallet_system::Config,
+ snowbridge_pallet_system::Config
+ pallet_timestamp::Config,
XcmConfig: xcm_executor::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as frame_system::Config>::AccountId: From<sp_runtime::AccountId32> + AsRef<[u8]>,
Expand Down Expand Up @@ -193,12 +195,96 @@

let digest = included_head.digest();

//let digest = frame_system::Pallet::<Runtime>::digest();
let digest_items = digest.logs();
assert!(digest_items.len() == 1 && digest_items[0].as_other().is_some());
});
}

pub fn test_pallet_order_works<Runtime, XcmConfig, AllPalletsWithoutSystem>(

Check warning on line 203 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L203 was not covered by tests
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32,
assethub_parachain_id: u32,
weth_contract_address: H160,
destination_address: H160,
fee_amount: u128,
snowbridge_pallet_outbound_queue: Box<
dyn Fn(Vec<u8>) -> Option<snowbridge_pallet_outbound_queue::Event<Runtime>>,
>,
) where
Runtime: frame_system::Config
+ pallet_balances::Config
+ pallet_session::Config
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ pallet_message_queue::Config
+ cumulus_pallet_parachain_system::Config
+ snowbridge_pallet_outbound_queue::Config
+ snowbridge_pallet_system::Config
+ pallet_timestamp::Config,
XcmConfig: xcm_executor::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as frame_system::Config>::AccountId: From<sp_runtime::AccountId32> + AsRef<[u8]>,
{
ExtBuilder::<Runtime>::default()
.with_collators(collator_session_key.collators())
.with_session_keys(collator_session_key.session_keys())
.with_para_id(runtime_para_id.into())

Check warning on line 234 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bridges/snowbridge/runtime/test-common/src/lib.rs#L231-L234

Added lines #L231 - L234 were not covered by tests
.with_tracing()
.build()
.execute_with(|| {
<snowbridge_pallet_system::Pallet<Runtime>>::initialize(
runtime_para_id.into(),
assethub_parachain_id.into(),

Check warning on line 240 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bridges/snowbridge/runtime/test-common/src/lib.rs#L237-L240

Added lines #L237 - L240 were not covered by tests
)
.unwrap();

Check warning on line 242 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L242 was not covered by tests

// fund asset hub sovereign account enough so it can pay fees
initial_fund::<Runtime>(assethub_parachain_id, 5_000_000_000_000);

Check warning on line 245 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L245 was not covered by tests

let outcome = send_transfer_token_message::<Runtime, XcmConfig>(
assethub_parachain_id,
weth_contract_address,
destination_address,
fee_amount,

Check warning on line 251 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bridges/snowbridge/runtime/test-common/src/lib.rs#L247-L251

Added lines #L247 - L251 were not covered by tests
);

assert_ok!(outcome.ensure_complete());

Check warning on line 254 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L254 was not covered by tests

// check events
let mut events = <frame_system::Pallet<Runtime>>::events()
.into_iter()
.filter_map(|e| snowbridge_pallet_outbound_queue(e.event.encode()));
assert!(events.any(|e| matches!(
e,
snowbridge_pallet_outbound_queue::Event::MessageQueued { .. }

Check warning on line 262 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bridges/snowbridge/runtime/test-common/src/lib.rs#L257-L262

Added lines #L257 - L262 were not covered by tests
)));

let next_block_number: U256 = <frame_system::Pallet<Runtime>>::block_number()
.saturating_add(BlockNumberFor::<Runtime>::from(1u32))
.into();

Check warning on line 267 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bridges/snowbridge/runtime/test-common/src/lib.rs#L265-L267

Added lines #L265 - L267 were not covered by tests

let included_head =
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::run_to_block_with_finalize(
next_block_number.as_u32(),

Check warning on line 271 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bridges/snowbridge/runtime/test-common/src/lib.rs#L269-L271

Added lines #L269 - L271 were not covered by tests
);
let digest = included_head.digest();
let digest_items = digest.logs();

Check warning on line 274 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bridges/snowbridge/runtime/test-common/src/lib.rs#L273-L274

Added lines #L273 - L274 were not covered by tests

let mut found_outbound_digest = false;
for digest_item in digest_items {
match digest_item {
DigestItem::Other(_) => found_outbound_digest = true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we assert that the message is queued on a block and then the DigestItem exists in the next block. This test asserts that the pallet order is correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so if the pallet order is incorrect (i.e. the MessageQueue pallet is before the EthereumOutboundQueue pallet in the construct_runtime macro), our message digest won't be found. I tested this locally, works nicely.

_ => {},

Check warning on line 280 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

bridges/snowbridge/runtime/test-common/src/lib.rs#L276-L280

Added lines #L276 - L280 were not covered by tests
}
}

assert_eq!(found_outbound_digest, true);

Check warning on line 284 in bridges/snowbridge/runtime/test-common/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L284 was not covered by tests
});
}

pub fn send_unpaid_transfer_token_message<Runtime, XcmConfig>(
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32,
Expand All @@ -213,7 +299,8 @@
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ snowbridge_pallet_outbound_queue::Config,
+ snowbridge_pallet_outbound_queue::Config
+ pallet_timestamp::Config,
XcmConfig: xcm_executor::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
{
Expand Down Expand Up @@ -301,7 +388,8 @@
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ snowbridge_pallet_outbound_queue::Config
+ snowbridge_pallet_system::Config,
+ snowbridge_pallet_system::Config
+ pallet_timestamp::Config,
XcmConfig: xcm_executor::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
{
Expand Down Expand Up @@ -349,7 +437,8 @@
+ cumulus_pallet_parachain_system::Config
+ snowbridge_pallet_outbound_queue::Config
+ snowbridge_pallet_system::Config
+ snowbridge_pallet_ethereum_client::Config,
+ snowbridge_pallet_ethereum_client::Config
+ pallet_timestamp::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as pallet_utility::Config>::RuntimeCall:
From<snowbridge_pallet_ethereum_client::Call<Runtime>>,
Expand Down Expand Up @@ -430,7 +519,8 @@
+ cumulus_pallet_parachain_system::Config
+ snowbridge_pallet_outbound_queue::Config
+ snowbridge_pallet_system::Config
+ snowbridge_pallet_ethereum_client::Config,
+ snowbridge_pallet_ethereum_client::Config
+ pallet_timestamp::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as pallet_utility::Config>::RuntimeCall:
From<snowbridge_pallet_ethereum_client::Call<Runtime>>,
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/assets/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ frame-system = { path = "../../../../../substrate/frame/system", default-feature
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false }
pallet-asset-conversion = { path = "../../../../../substrate/frame/asset-conversion", default-features = false }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false }
pallet-session = { path = "../../../../../substrate/frame/session", default-features = false }
sp-io = { path = "../../../../../substrate/primitives/io", default-features = false }
sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false }
Expand Down Expand Up @@ -61,6 +62,7 @@ std = [
"pallet-balances/std",
"pallet-collator-selection/std",
"pallet-session/std",
"pallet-timestamp/std",
"pallet-xcm-bridge-hub-router/std",
"pallet-xcm/std",
"parachain-info/std",
Expand Down
18 changes: 12 additions & 6 deletions cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ pub fn teleports_for_native_asset_works<
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config,
+ cumulus_pallet_xcmp_queue::Config
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
Expand Down Expand Up @@ -350,7 +351,8 @@ pub fn teleports_for_foreign_assets_works<
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config
+ pallet_assets::Config<ForeignAssetsPalletInstance>,
+ pallet_assets::Config<ForeignAssetsPalletInstance>
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
Expand Down Expand Up @@ -701,7 +703,8 @@ pub fn asset_transactor_transfer_with_local_consensus_currency_works<Runtime, Xc
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config,
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
AccountIdOf<Runtime>: Into<[u8; 32]>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
BalanceOf<Runtime>: From<Balance>,
Expand Down Expand Up @@ -826,7 +829,8 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ pallet_assets::Config<AssetsPalletInstance>,
+ pallet_assets::Config<AssetsPalletInstance>
+ pallet_timestamp::Config,
AccountIdOf<Runtime>: Into<[u8; 32]>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
BalanceOf<Runtime>: From<Balance>,
Expand Down Expand Up @@ -1093,7 +1097,8 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ pallet_assets::Config<ForeignAssetsPalletInstance>,
+ pallet_assets::Config<ForeignAssetsPalletInstance>
+ pallet_timestamp::Config,
AccountIdOf<Runtime>: Into<[u8; 32]>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
BalanceOf<Runtime>: From<Balance>,
Expand Down Expand Up @@ -1422,7 +1427,8 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config,
+ cumulus_pallet_xcmp_queue::Config
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config,
+ cumulus_pallet_xcmp_queue::Config
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
Expand Down Expand Up @@ -347,7 +348,8 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config
+ pallet_assets::Config<ForeignAssetsPalletInstance>
+ pallet_asset_conversion::Config,
+ pallet_asset_conversion::Config
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]> + From<[u8; 32]>,
Expand Down Expand Up @@ -602,7 +604,8 @@ pub fn report_bridge_status_from_xcm_bridge_router_works<
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config
+ pallet_xcm_bridge_hub_router::Config<XcmBridgeHubRouterInstance>,
+ pallet_xcm_bridge_hub_router::Config<XcmBridgeHubRouterInstance>
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ construct_runtime!(

// Message Queue. Importantly, is registered last so that messages are processed after
// the `on_initialize` hooks of bridging pallets.
MessageQueue: pallet_message_queue = 250,
MessageQueue: pallet_message_queue = 175,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use bp_polkadot_core::Signature;
use bridge_hub_rococo_runtime::{
bridge_to_bulletin_config::OnBridgeHubRococoRefundRococoBulletinMessages,
bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages,
xcm_config::XcmConfig, BridgeRejectObsoleteHeadersAndMessages, Executive,
MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, SignedExtra,
UncheckedExtrinsic,
xcm_config::XcmConfig, AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages,
Executive, MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys,
SignedExtra, UncheckedExtrinsic,
};
use codec::{Decode, Encode};
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees};
Expand Down Expand Up @@ -135,6 +135,28 @@ fn ethereum_to_polkadot_message_extrinsics_work() {
);
}

#[test]
pub fn test_pallet_order_works() {
snowbridge_runtime_test_common::test_pallet_order_works::<
Runtime,
XcmConfig,
AllPalletsWithoutSystem,
>(
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,
}
}),
)
}

fn construct_extrinsic(
sender: sp_keyring::AccountKeyring,
call: RuntimeCall,
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/bridge-hubs/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sp-std = { path = "../../../../../substrate/primitives/std", default-features =
sp-tracing = { path = "../../../../../substrate/primitives/tracing" }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
pallet-utility = { path = "../../../../../substrate/frame/utility", default-features = false }
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false }

# Cumulus
asset-test-utils = { path = "../../assets/test-utils" }
Expand Down Expand Up @@ -73,6 +74,7 @@ std = [
"pallet-bridge-messages/std",
"pallet-bridge-parachains/std",
"pallet-bridge-relayers/std",
"pallet-timestamp/std",
"pallet-utility/std",
"parachains-common/std",
"parachains-runtimes-test-utils/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ where
pub(crate) fn initialize_bridge_grandpa_pallet<Runtime, GPI>(
init_data: bp_header_chain::InitializationData<BridgedHeader<Runtime, GPI>>,
) where
Runtime: BridgeGrandpaConfig<GPI>,
Runtime: BridgeGrandpaConfig<GPI>
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
{
pallet_bridge_grandpa::Pallet::<Runtime, GPI>::initialize(
RuntimeHelper::<Runtime>::root_origin(),
Expand Down
Loading
Loading