Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-04-13 19:43:07 +03:00
parent 365e78d739
commit 9302fa2317
9 changed files with 47 additions and 29 deletions
Generated
+1
View File
@@ -1548,6 +1548,7 @@ dependencies = [
"sp-runtime",
"subxt",
"subxt-codegen",
"subxt-metadata",
"syn 1.0.109",
"test-runtime",
"tokio",
+8 -8
View File
@@ -13,10 +13,10 @@ pub enum CodegenError {
#[error("Could not find type with ID {0} in the type registry; please raise a support issue.")]
TypeNotFound(u32),
/// Cannot fetch the metadata bytes.
#[error("Failed to fetch metadata, make sure that you're pointing at a node which is providing V14 metadata: {0}")]
#[error("Failed to fetch metadata, make sure that you're pointing at a node which is providing substrate-based metadata: {0}")]
Fetch(#[from] FetchMetadataError),
/// Failed IO for the metadata file.
#[error("Failed IO for {0}, make sure that you are providing the correct file path for metadata V14: {1}")]
#[error("Failed IO for {0}, make sure that you are providing the correct file path for metadata: {1}")]
Io(String, std::io::Error),
/// Cannot decode the metadata bytes.
#[error("Could not decode metadata, only V14 metadata is supported: {0}")]
@@ -25,7 +25,7 @@ pub enum CodegenError {
#[error("Out-of-line subxt modules are not supported, make sure you are providing a body to your module: pub mod polkadot {{ ... }}")]
InvalidModule(Span),
/// Expected named or unnamed fields.
#[error("Fields should either be all named or all unnamed, make sure you are providing a valid metadata V14: {0}")]
#[error("Fields should either be all named or all unnamed, make sure you are providing a valid metadata: {0}")]
InvalidFields(String),
/// Substitute types must have a valid path.
#[error("Type substitution error: {0}")]
@@ -34,20 +34,20 @@ pub enum CodegenError {
#[error("Invalid type path {0}: {1}")]
InvalidTypePath(String, syn::Error),
/// Metadata for constant could not be found.
#[error("Metadata for constant entry {0}_{1} could not be found. Make sure you are providing a valid metadata V14")]
#[error("Metadata for constant entry {0}_{1} could not be found. Make sure you are providing a valid substrate-based metadata")]
MissingConstantMetadata(String, String),
/// Metadata for storage could not be found.
#[error("Metadata for storage entry {0}_{1} could not be found. Make sure you are providing a valid metadata V14")]
#[error("Metadata for storage entry {0}_{1} could not be found. Make sure you are providing a valid substrate-based metadata")]
MissingStorageMetadata(String, String),
/// Metadata for call could not be found.
#[error("Metadata for call entry {0}_{1} could not be found. Make sure you are providing a valid metadata V14")]
#[error("Metadata for call entry {0}_{1} could not be found. Make sure you are providing a valid substrate-based metadata")]
MissingCallMetadata(String, String),
/// Call variant must have all named fields.
#[error("Call variant for type {0} must have all named fields. Make sure you are providing a valid metadata V14")]
#[error("Call variant for type {0} must have all named fields. Make sure you are providing a valid substrate-based metadata")]
InvalidCallVariant(u32),
/// Type should be an variant/enum.
#[error(
"{0} type should be an variant/enum type. Make sure you are providing a valid metadata V14"
"{0} type should be an variant/enum type. Make sure you are providing a valid substrate-based metadata"
)]
InvalidType(String),
}
+4 -3
View File
@@ -430,7 +430,7 @@ pub(crate) mod test_utils {
use crate::{Config, SubstrateConfig};
use codec::Encode;
use frame_metadata::{
v14::{ExtrinsicMetadata, PalletEventMetadata, PalletMetadata, RuntimeMetadataV14},
v15::{ExtrinsicMetadata, PalletEventMetadata, PalletMetadata, RuntimeMetadataV15},
RuntimeMetadataPrefixed,
};
use scale_info::{meta_type, TypeInfo};
@@ -503,6 +503,7 @@ pub(crate) mod test_utils {
constants: vec![],
error: None,
index: 0,
docs: vec![],
}];
let extrinsic = ExtrinsicMetadata {
@@ -511,8 +512,8 @@ pub(crate) mod test_utils {
signed_extensions: vec![],
};
let v14 = RuntimeMetadataV14::new(pallets, extrinsic, meta_type::<()>());
let runtime_metadata: RuntimeMetadataPrefixed = v14.into();
let meta = RuntimeMetadataV15::new(pallets, extrinsic, meta_type::<()>(), vec![]);
let runtime_metadata: RuntimeMetadataPrefixed = meta.into();
Metadata::try_from(runtime_metadata).unwrap()
}
+1
View File
@@ -29,6 +29,7 @@ sp-keyring = "20.0.0"
syn = "1.0.109"
subxt = { version = "0.27.1", path = "../../subxt" }
subxt-codegen = { version = "0.27.1", path = "../../codegen" }
subxt-metadata = { version = "0.27.1", path = "../../metadata" }
test-runtime = { path = "../test-runtime" }
tokio = { version = "1.27", features = ["macros", "time"] }
tracing = "0.1.34"
+5 -2
View File
@@ -106,8 +106,11 @@ async fn runtime_api_call() -> Result<(), subxt::Error> {
let _ = <Compact<u32>>::decode(cursor)?;
let meta: RuntimeMetadataPrefixed = Decode::decode(cursor)?;
let metadata_call = match meta.1 {
frame_metadata::RuntimeMetadata::V14(metadata) => metadata,
_ => panic!("Metadata V14 unavailable"),
frame_metadata::RuntimeMetadata::V14(metadata) => {
subxt_metadata::metadata_v14_to_latest(metadata)
}
frame_metadata::RuntimeMetadata::V15(metadata) => metadata,
_ => panic!("Metadata V14 or V15 unavailable"),
};
// Compare the runtime API call against the `state_getMetadata`.
+5 -3
View File
@@ -398,10 +398,12 @@ async fn rpc_state_call() {
let _ = <Compact<u32>>::decode(cursor).unwrap();
let meta: RuntimeMetadataPrefixed = Decode::decode(cursor).unwrap();
let metadata_call = match meta.1 {
frame_metadata::RuntimeMetadata::V14(metadata) => metadata,
_ => panic!("Metadata V14 unavailable"),
frame_metadata::RuntimeMetadata::V14(metadata) => {
subxt_metadata::metadata_v14_to_latest(metadata)
}
frame_metadata::RuntimeMetadata::V15(metadata) => metadata,
_ => panic!("Metadata V14 or V15 unavailable"),
};
// Compare the runtime API call against the `state_getMetadata`.
let metadata = api.rpc().metadata(None).await.unwrap();
let metadata = metadata.runtime_metadata();
@@ -4,9 +4,11 @@
use crate::{node_runtime, test_context, TestContext};
use frame_metadata::{
ExtrinsicMetadata, PalletCallMetadata, PalletMetadata, PalletStorageMetadata,
RuntimeMetadataPrefixed, RuntimeMetadataV14, StorageEntryMetadata, StorageEntryModifier,
StorageEntryType,
v15::{
ExtrinsicMetadata, PalletCallMetadata, PalletMetadata, PalletStorageMetadata,
RuntimeMetadataV15, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
},
RuntimeMetadataPrefixed,
};
use scale_info::{
build::{Fields, Variants},
@@ -15,7 +17,7 @@ use scale_info::{
use subxt::{Metadata, OfflineClient, SubstrateConfig};
async fn metadata_to_api(
metadata: RuntimeMetadataV14,
metadata: RuntimeMetadataV15,
ctx: &TestContext,
) -> OfflineClient<SubstrateConfig> {
let prefixed = RuntimeMetadataPrefixed::from(metadata);
@@ -37,7 +39,7 @@ async fn full_metadata_check() {
assert!(node_runtime::validate_codegen(&api).is_ok());
// Modify the metadata.
let mut metadata: RuntimeMetadataV14 = api.metadata().runtime_metadata().clone();
let mut metadata = api.metadata().runtime_metadata().clone();
metadata.pallets[0].name = "NewPallet".to_string();
let api = metadata_to_api(metadata, &ctx).await;
@@ -59,7 +61,7 @@ async fn constant_values_are_not_validated() {
assert!(api.constants().at(&deposit_addr).is_ok());
// Modify the metadata.
let mut metadata: RuntimeMetadataV14 = api.metadata().runtime_metadata().clone();
let mut metadata = api.metadata().runtime_metadata().clone();
let mut existential = metadata
.pallets
@@ -89,11 +91,12 @@ fn default_pallet() -> PalletMetadata {
constants: vec![],
error: None,
index: 0,
docs: vec![],
}
}
fn pallets_to_metadata(pallets: Vec<PalletMetadata>) -> RuntimeMetadataV14 {
RuntimeMetadataV14::new(
fn pallets_to_metadata(pallets: Vec<PalletMetadata>) -> RuntimeMetadataV15 {
RuntimeMetadataV15::new(
pallets,
ExtrinsicMetadata {
ty: meta_type::<()>(),
@@ -101,6 +104,7 @@ fn pallets_to_metadata(pallets: Vec<PalletMetadata>) -> RuntimeMetadataV14 {
signed_extensions: vec![],
},
meta_type::<()>(),
vec![],
)
}
+2 -1
View File
@@ -3,7 +3,8 @@
// see LICENSE for license details.
use frame_metadata::{
RuntimeMetadataPrefixed, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
v15::{StorageEntryMetadata, StorageEntryModifier, StorageEntryType},
RuntimeMetadataPrefixed,
};
use scale_info::meta_type;
+9 -4
View File
@@ -7,8 +7,11 @@ mod metadata_test_runner;
mod pallet_metadata_test_runner;
use frame_metadata::{
v14::RuntimeMetadataV14, ExtrinsicMetadata, PalletMetadata, PalletStorageMetadata,
RuntimeMetadataPrefixed, StorageEntryMetadata,
v15::{
ExtrinsicMetadata, PalletMetadata, PalletStorageMetadata, RuntimeMetadataV15,
StorageEntryMetadata,
},
RuntimeMetadataPrefixed,
};
use scale_info::{meta_type, IntoPortable, TypeInfo};
@@ -28,7 +31,7 @@ pub fn generate_metadata_from_pallets_custom_dispatch_error<DispatchError: TypeI
signed_extensions: vec![],
};
// Construct metadata manually from our types (See `RuntimeMetadataV14::new()`).
// Construct metadata manually from our types (See `RuntimeMetadataV15::new()`).
// Add any extra types we need to the registry.
let mut registry = scale_info::Registry::new();
let pallets = registry.map_into_portable(pallets);
@@ -48,11 +51,12 @@ pub fn generate_metadata_from_pallets_custom_dispatch_error<DispatchError: TypeI
// Metadata needs to contain this DispatchError, since codegen looks for it.
registry.register_type(&meta_type::<DispatchError>());
let metadata = RuntimeMetadataV14 {
let metadata = RuntimeMetadataV15 {
types: registry.into(),
pallets,
extrinsic,
ty,
apis: vec![],
};
RuntimeMetadataPrefixed::from(metadata)
@@ -86,6 +90,7 @@ pub fn generate_metadata_from_storage_entries(
calls: None,
event: None,
error: None,
docs: vec![],
};
generate_metadata_from_pallets(vec![pallet])