Skip to content

Commit

Permalink
run_to_block with finalize phase
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Jan 26, 2024
1 parent 0a9f957 commit 4d2c7a7
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 14 deletions.
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.

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-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false }
sp-io = { path = "../../../../../substrate/primitives/io", default-features = false }
Expand Down Expand Up @@ -70,6 +71,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 @@ -342,7 +343,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 @@ -597,7 +599,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
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 @@ -28,6 +28,7 @@ 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-session = { path = "../../../../../substrate/frame/session", default-features = false }
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false }

# Cumulus
asset-test-utils = { path = "../../assets/test-utils" }
Expand Down Expand Up @@ -86,6 +87,7 @@ std = [
"pallet-bridge-relayers/std",
"pallet-collator-selection/std",
"pallet-session/std",
"pallet-timestamp/std",
"pallet-utility/std",
"pallet-xcm-benchmarks?/std",
"pallet-xcm/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
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/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-features =
pallet-assets = { path = "../../../../substrate/frame/assets", default-features = false }
pallet-balances = { path = "../../../../substrate/frame/balances", default-features = false }
pallet-session = { path = "../../../../substrate/frame/session", default-features = false }
pallet-timestamp = { path = "../../../../substrate/frame/timestamp", default-features = false }
sp-consensus-aura = { path = "../../../../substrate/primitives/consensus/aura", 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 @@ -64,6 +65,7 @@ std = [
"pallet-balances/std",
"pallet-collator-selection/std",
"pallet-session/std",
"pallet-timestamp/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
Expand Down
69 changes: 66 additions & 3 deletions cumulus/parachains/runtimes/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub trait BasicParachainRuntime:
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config
{
}

Expand All @@ -140,7 +141,8 @@ where
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config,
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
ValidatorIdOf<T>: From<AccountIdOf<T>>,
{
}
Expand Down Expand Up @@ -259,8 +261,10 @@ pub struct RuntimeHelper<Runtime, AllPalletsWithoutSystem>(
);
/// Utility function that advances the chain to the desired block number.
/// If an author is provided, that author information is injected to all the blocks in the meantime.
impl<Runtime: frame_system::Config, AllPalletsWithoutSystem>
RuntimeHelper<Runtime, AllPalletsWithoutSystem>
impl<
Runtime: frame_system::Config + cumulus_pallet_parachain_system::Config + pallet_timestamp::Config,
AllPalletsWithoutSystem,
> RuntimeHelper<Runtime, AllPalletsWithoutSystem>
where
AccountIdOf<Runtime>:
Into<<<Runtime as frame_system::Config>::RuntimeOrigin as OriginTrait>::AccountId>,
Expand Down Expand Up @@ -296,6 +300,65 @@ where
last_header.expect("run_to_block empty block range")
}

pub fn run_to_block_with_finalize(n: u32) -> HeaderFor<Runtime> {
let mut last_header = None;
loop {
let block_number = frame_system::Pallet::<Runtime>::block_number();
if block_number >= n.into() {
break
}
// Set the new block number and author
let header = frame_system::Pallet::<Runtime>::finalize();

let pre_digest = Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, block_number.encode())],
};
frame_system::Pallet::<Runtime>::reset_events();

let next_block_number = block_number + 1u32.into();
frame_system::Pallet::<Runtime>::initialize(
&next_block_number,
&header.hash(),
&pre_digest,
);
AllPalletsWithoutSystem::on_initialize(next_block_number);

let parent_head = HeadData(header.encode());
let sproof_builder = RelayStateSproofBuilder {
para_id: 1013.into(),
included_para_head: parent_head.clone().into(),
..Default::default()
};

let (relay_parent_storage_root, relay_chain_state) =
sproof_builder.into_state_root_and_proof();
let inherent_data = ParachainInherentData {
validation_data: PersistedValidationData {
parent_head,
relay_parent_number: 10,
relay_parent_storage_root,
max_pov_size: 10000,
},
relay_chain_state,
downward_messages: Default::default(),
horizontal_messages: Default::default(),
};

let _ = cumulus_pallet_parachain_system::Pallet::<Runtime>::set_validation_data(
Runtime::RuntimeOrigin::none(),
inherent_data,
);
let _ = pallet_timestamp::Pallet::<Runtime>::set(
Runtime::RuntimeOrigin::none(),
300_u32.into(),
);
AllPalletsWithoutSystem::on_finalize(next_block_number);
let header = frame_system::Pallet::<Runtime>::finalize();
last_header = Some(header);
}
last_header.expect("run_to_block empty block range")
}

pub fn root_origin() -> <Runtime as frame_system::Config>::RuntimeOrigin {
<Runtime as frame_system::Config>::RuntimeOrigin::root()
}
Expand Down
3 changes: 2 additions & 1 deletion cumulus/parachains/runtimes/test-utils/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ pub fn change_storage_constant_by_governance_works<Runtime, StorageConstant, Sto
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config,
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
StorageConstant: Get<StorageConstantType>,
StorageConstantType: Encode + PartialEq + std::fmt::Debug,
Expand Down

0 comments on commit 4d2c7a7

Please sign in to comment.