Add proper test Custom values (#1147)

* add proper tests for custom values

* remove try operators

* use sustrate compat for import of hash

* add license and hex

* add script to artifacts.sh

* custom values with ids not in metadata can be accessed in static interface

* fmt and clippy

* access bytes of custom values directly, even if type id wrong

* final fixes

* removing substrate-compat flag from ui tests

* Update subxt/src/custom_values/custom_values_client.rs

Co-authored-by: James Wilson <james@jsdw.me>

* remove types access in type generator

* 2 extra lines

---------

Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
Tadeo Hepperle
2023-09-12 15:46:12 +02:00
committed by GitHub
parent 022d709d02
commit c8462defab
22 changed files with 208 additions and 44 deletions
@@ -1,95 +0,0 @@
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use scale_info::{
build::{Fields, Variants},
Path, Type, TypeInfo,
};
/// See the `ModuleErrorType` in `subxt_codegen` for more info on the different DispatchError
/// types that we've encountered. We need the path to match `sp_runtime::DispatchError`, otherwise
/// we could just implement roughly the correct types and derive TypeInfo on them.
/// This type has TypeInfo compatible with the `NamedField` version of the DispatchError.
/// This is the oldest version that subxt supports:
/// `DispatchError::Module { index: u8, error: u8 }`
pub enum NamedFieldDispatchError {}
impl TypeInfo for NamedFieldDispatchError {
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new("DispatchError", "sp_runtime"))
.variant(Variants::new().variant("Module", |builder| {
builder
.fields(
Fields::named()
.field(|b| b.name("error").ty::<u8>())
.field(|b| b.name("index").ty::<u8>()),
)
.index(0)
}))
}
}
/// This type has TypeInfo compatible with the `LegacyError` version of the DispatchError.
/// This is the version wasn't around for long:
/// `DispatchError::Module ( sp_runtime::ModuleError { index: u8, error: u8 } )`
pub enum LegacyDispatchError {}
impl TypeInfo for LegacyDispatchError {
type Identity = Self;
fn type_info() -> Type {
struct ModuleError;
impl TypeInfo for ModuleError {
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new("ModuleError", "sp_runtime"))
.composite(
Fields::named()
.field(|b| b.name("index").ty::<u8>())
.field(|b| b.name("error").ty::<u8>()),
)
}
}
Type::builder()
.path(Path::new("DispatchError", "sp_runtime"))
.variant(Variants::new().variant("Module", |builder| {
builder
.fields(Fields::unnamed().field(|b| b.ty::<ModuleError>()))
.index(0)
}))
}
}
/// This type has TypeInfo compatible with the `ArrayError` version of the DispatchError.
/// This is the current version:
/// `DispatchError::Module ( sp_runtime::ModuleError { index: u8, error: [u8; 4] } )`
pub enum ArrayDispatchError {}
impl TypeInfo for ArrayDispatchError {
type Identity = Self;
fn type_info() -> Type {
struct ModuleError;
impl TypeInfo for ModuleError {
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new("ModuleError", "sp_runtime"))
.composite(
Fields::named()
.field(|b| b.name("index").ty::<u8>())
.field(|b| b.name("error").ty::<[u8; 4]>()),
)
}
}
Type::builder()
.path(Path::new("DispatchError", "sp_runtime"))
.variant(Variants::new().variant("Module", |builder| {
builder
.fields(Fields::unnamed().field(|b| b.ty::<ModuleError>()))
.index(0)
}))
}
}
+2 -4
View File
@@ -2,7 +2,6 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
pub mod dispatch_error;
mod metadata_test_runner;
use frame_metadata::{
@@ -12,6 +11,7 @@ use frame_metadata::{
},
RuntimeMetadataPrefixed,
};
use generate_custom_metadata::dispatch_error::ArrayDispatchError;
use scale_info::{meta_type, IntoPortable, TypeInfo};
pub use metadata_test_runner::MetadataTestRunner;
@@ -78,9 +78,7 @@ pub fn generate_metadata_from_pallets_custom_dispatch_error<DispatchError: TypeI
/// We default to a useless extrinsic type, and register a fake `DispatchError`
/// type so that codegen is happy with the metadata generated.
pub fn generate_metadata_from_pallets(pallets: Vec<PalletMetadata>) -> RuntimeMetadataPrefixed {
generate_metadata_from_pallets_custom_dispatch_error::<dispatch_error::ArrayDispatchError>(
pallets,
)
generate_metadata_from_pallets_custom_dispatch_error::<ArrayDispatchError>(pallets)
}
/// Given some storage entries, generate a [`RuntimeMetadataPrefixed`] struct.