mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-23 10:48:00 +00:00
codegen: fix compact unnamed fields (#327)
* codegen: fix compact unnamed fields * Fmt * Regenerate polkadot codegen example. * Ignore clippy for generated code * Limit the number of test threads * Revert "Limit the number of test threads" This reverts commit f1947dc659ee3ac4558ed86eff0d37af913a87ff. * Delete duplicate node_runtime metadata * Update node_runtime metadata * Update balances events
This commit is contained in:
@@ -325,6 +325,73 @@ fn generate_enum() {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_fields() {
|
||||
#[allow(unused)]
|
||||
#[derive(TypeInfo)]
|
||||
struct S {
|
||||
#[codec(compact)]
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(TypeInfo)]
|
||||
struct TupleStruct(#[codec(compact)] u32);
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(TypeInfo)]
|
||||
enum E {
|
||||
A {
|
||||
#[codec(compact)]
|
||||
a: u32,
|
||||
},
|
||||
B(#[codec(compact)] u32),
|
||||
}
|
||||
|
||||
let mut registry = Registry::new();
|
||||
registry.register_type(&meta_type::<S>());
|
||||
registry.register_type(&meta_type::<TupleStruct>());
|
||||
registry.register_type(&meta_type::<E>());
|
||||
let portable_types: PortableRegistry = registry.into();
|
||||
|
||||
let type_gen = TypeGenerator::new(
|
||||
&portable_types,
|
||||
"root",
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let types = type_gen.generate_types_mod();
|
||||
let tests_mod = get_mod(&types, MOD_PATH).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
tests_mod.into_token_stream().to_string(),
|
||||
quote! {
|
||||
pub mod tests {
|
||||
use super::root;
|
||||
#[derive(::subxt::codec::Encode, ::subxt::codec::Decode)]
|
||||
pub enum E {
|
||||
# [codec (index = 0)]
|
||||
A {
|
||||
#[codec(compact)]
|
||||
a: ::core::primitive::u32,
|
||||
},
|
||||
# [codec (index = 1)]
|
||||
B( #[codec(compact)] ::core::primitive::u32,),
|
||||
}
|
||||
|
||||
#[derive(::subxt::codec::Encode, ::subxt::codec::Decode)]
|
||||
pub struct S {
|
||||
#[codec(compact)] pub a: ::core::primitive::u32,
|
||||
}
|
||||
|
||||
#[derive(::subxt::codec::Encode, ::subxt::codec::Decode)]
|
||||
pub struct TupleStruct(#[codec(compact)] pub ::core::primitive::u32,);
|
||||
}
|
||||
}
|
||||
.to_string()
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generate_array_field() {
|
||||
#[allow(unused)]
|
||||
|
||||
@@ -279,7 +279,7 @@ impl<'a> TypeDefGen<'a> {
|
||||
let mut fields_tokens = type_paths
|
||||
.iter()
|
||||
.map(|(ty, ty_name)| {
|
||||
match ty_name {
|
||||
let field_type = match ty_name {
|
||||
Some(ty_name) => {
|
||||
let ty = ty_toks(ty_name, ty);
|
||||
if is_struct {
|
||||
@@ -291,6 +291,11 @@ impl<'a> TypeDefGen<'a> {
|
||||
None => {
|
||||
quote! { #ty }
|
||||
}
|
||||
};
|
||||
if ty.is_compact() {
|
||||
quote!( #[codec(compact)] #field_type )
|
||||
} else {
|
||||
quote!( #field_type )
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Reference in New Issue
Block a user