mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
Fix call enum's metadata regression (#3513)
This fixes an issue introduced in https://github.com/paritytech/substrate/pull/14101, in which I removed the `Call` enum's documentation and replaced it with a link to the `Pallet` struct, but this also removed any docs related to call from the metadata. I tried to add a regression test for this, but it seems to me that this is not possible, given that using `type-info` we only assert in type-ids for `Call`, `Event` and `Error`. I removed some doc comments from a test setup in `frame-support-test` to demonstrate the issue there. @jsdw do you have any comments on this? I also fixed a small issue in the custom html/css of `polkadot-sdk-doc` crate, making sure it does not affect the rust-doc page of all other crates. - [x] Investigate a regression test - [x] prdoc
This commit is contained in:
@@ -209,7 +209,7 @@ pub mod pallet {
|
||||
where
|
||||
T::AccountId: From<SomeType1> + From<SomeType3> + SomeAssociation1,
|
||||
{
|
||||
/// Doc comment put in metadata
|
||||
/// call foo doc comment put in metadata
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(Weight::from_parts(*foo as u64, 0))]
|
||||
pub fn foo(
|
||||
@@ -225,7 +225,7 @@ pub mod pallet {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
/// Doc comment put in metadata
|
||||
/// call foo_storage_layer doc comment put in metadata
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight({1})]
|
||||
pub fn foo_storage_layer(
|
||||
@@ -270,7 +270,7 @@ pub mod pallet {
|
||||
#[pallet::error]
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub enum Error<T> {
|
||||
/// doc comment put into metadata
|
||||
/// error doc comment put in metadata
|
||||
InsufficientProposersBalance,
|
||||
NonExistentStorageValue,
|
||||
Code(u8),
|
||||
@@ -287,9 +287,8 @@ pub mod pallet {
|
||||
where
|
||||
T::AccountId: SomeAssociation1 + From<SomeType1>,
|
||||
{
|
||||
/// doc comment put in metadata
|
||||
/// event doc comment put in metadata
|
||||
Proposed(<T as frame_system::Config>::AccountId),
|
||||
/// doc
|
||||
Spending(BalanceOf<T>),
|
||||
Something(u32),
|
||||
SomethingElse(<T::AccountId as SomeAssociation1>::_1),
|
||||
@@ -750,8 +749,7 @@ pub type UncheckedExtrinsic =
|
||||
sp_runtime::testing::TestXt<RuntimeCall, frame_system::CheckNonZeroSender<Runtime>>;
|
||||
|
||||
frame_support::construct_runtime!(
|
||||
pub struct Runtime
|
||||
{
|
||||
pub struct Runtime {
|
||||
// Exclude part `Storage` in order not to check its metadata in tests.
|
||||
System: frame_system exclude_parts { Pallet, Storage },
|
||||
Example: pallet,
|
||||
@@ -772,6 +770,14 @@ fn _ensure_call_is_correctly_excluded_and_included(call: RuntimeCall) {
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> {
|
||||
if cfg!(feature = "no-metadata-docs") {
|
||||
vec![]
|
||||
} else {
|
||||
doc
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transactional_works() {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
@@ -1362,19 +1368,47 @@ fn migrate_from_pallet_version_to_storage_version() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pallet_item_docs_in_metadata() {
|
||||
// call
|
||||
let call_variants = match meta_type::<pallet::Call<Runtime>>().type_info().type_def {
|
||||
scale_info::TypeDef::Variant(variants) => variants.variants,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert_eq!(call_variants[0].docs, maybe_docs(vec!["call foo doc comment put in metadata"]));
|
||||
assert_eq!(
|
||||
call_variants[1].docs,
|
||||
maybe_docs(vec!["call foo_storage_layer doc comment put in metadata"])
|
||||
);
|
||||
assert!(call_variants[2].docs.is_empty());
|
||||
|
||||
// event
|
||||
let event_variants = match meta_type::<pallet::Event<Runtime>>().type_info().type_def {
|
||||
scale_info::TypeDef::Variant(variants) => variants.variants,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert_eq!(event_variants[0].docs, maybe_docs(vec!["event doc comment put in metadata"]));
|
||||
assert!(event_variants[1].docs.is_empty());
|
||||
|
||||
// error
|
||||
let error_variants = match meta_type::<pallet::Error<Runtime>>().type_info().type_def {
|
||||
scale_info::TypeDef::Variant(variants) => variants.variants,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert_eq!(error_variants[0].docs, maybe_docs(vec!["error doc comment put in metadata"]));
|
||||
assert!(error_variants[1].docs.is_empty());
|
||||
|
||||
// storage is already covered in the main `fn metadata` test.
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata() {
|
||||
use codec::Decode;
|
||||
use frame_metadata::{v15::*, *};
|
||||
|
||||
fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> {
|
||||
if cfg!(feature = "no-metadata-docs") {
|
||||
vec![]
|
||||
} else {
|
||||
doc
|
||||
}
|
||||
}
|
||||
|
||||
let readme = "Support code for the runtime.\n\nLicense: Apache-2.0\n";
|
||||
let expected_pallet_doc = vec![" Pallet documentation", readme, readme];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user