Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove MessageSignature from multitest #241

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 194 additions & 0 deletions sylvia-derive/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,149 @@
}
}

pub fn emit_multitest_proxy_methods(
&self,
msg_ty: &MsgType,
custom_msg: &Type,
mt_app: &Type,
error_type: &Type,
) -> TokenStream {
let sylvia = crate_module();
let Self {
name,
fields,
return_type,
..
} = self;

let params = fields.iter().map(|field| field.emit_method_field());
let arguments = fields.iter().map(MsgField::name);
let name = Ident::new(&name.to_string().to_case(Case::Snake), name.span());

match msg_ty {
MsgType::Exec => quote! {
#[track_caller]
pub fn #name (&self, #(#params,)* ) -> #sylvia ::multitest::ExecProxy::<#error_type, ExecMsg, #mt_app, #custom_msg> {
let msg = ExecMsg:: #name ( #(#arguments),* );

#sylvia ::multitest::ExecProxy::new(&self.contract_addr, msg, &self.app)
}
},
MsgType::Migrate => quote! {
#[track_caller]
pub fn #name (&self, #(#params,)* ) -> #sylvia ::multitest::MigrateProxy::<#error_type, MigrateMsg, #mt_app, #custom_msg> {
let msg = MigrateMsg::new( #(#arguments),* );

#sylvia ::multitest::MigrateProxy::new(&self.contract_addr, msg, &self.app)
}
},
MsgType::Query => quote! {
pub fn #name (&self, #(#params,)* ) -> Result<#return_type, #error_type> {
let msg = QueryMsg:: #name ( #(#arguments),* );

(*self.app)
.app()
.wrap()
.query_wasm_smart(self.contract_addr.clone(), &msg)
.map_err(Into::into)
}
},
_ => quote! {},

Check warning on line 700 in sylvia-derive/src/message.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/message.rs#L700

Added line #L700 was not covered by tests
}
}

pub fn emit_interface_multitest_proxy_methods<Generics>(
&self,
msg_ty: &MsgType,
custom_msg: &Type,
mt_app: &Type,
error_type: &Type,
generics: &[&Generics],
module: &TokenStream,
) -> TokenStream
where
Generics: ToTokens,
{
let sylvia = crate_module();
let Self {
name,
fields,
return_type,
..
} = self;

let params = fields.iter().map(|field| field.emit_method_field());
let arguments = fields.iter().map(MsgField::name);
let bracketed_generics = emit_bracketed_generics(generics);
let interface_enum = quote! { < #module InterfaceTypes #bracketed_generics as #sylvia ::types::InterfaceMessages> };
let type_name = msg_ty.as_accessor_name();
let name = Ident::new(&name.to_string().to_case(Case::Snake), name.span());

match msg_ty {
MsgType::Exec => quote! {
#[track_caller]
fn #name (&self, #(#params,)* ) -> #sylvia ::multitest::ExecProxy::<#error_type, #interface_enum :: #type_name, #mt_app, #custom_msg> {
let msg = #interface_enum :: #type_name :: #name ( #(#arguments),* );

#sylvia ::multitest::ExecProxy::new(&self.contract_addr, msg, &self.app)
}
},
MsgType::Query => quote! {
fn #name (&self, #(#params,)* ) -> Result<#return_type, #error_type> {
let msg = #interface_enum :: #type_name :: #name ( #(#arguments),* );

(*self.app)
.app()
.wrap()
.query_wasm_smart(self.contract_addr.clone(), &msg)
.map_err(Into::into)
}
},
_ => quote! {},

Check warning on line 751 in sylvia-derive/src/message.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/message.rs#L751

Added line #L751 was not covered by tests
}
}

pub fn emit_proxy_methods_declarations(
&self,
msg_ty: &MsgType,
custom_msg: &Type,
error_type: &Type,
interface_enum: &TokenStream,
) -> TokenStream {
let sylvia = crate_module();
let Self {
name,
fields,
return_type,
..
} = self;

let params = fields.iter().map(|field| field.emit_method_field());
let type_name = msg_ty.as_accessor_name();
let name = Ident::new(&name.to_string().to_case(Case::Snake), name.span());

match msg_ty {
MsgType::Exec => quote! {
fn #name (&self, #(#params,)* ) -> #sylvia ::multitest::ExecProxy::<#error_type, #interface_enum :: #type_name, MtApp, #custom_msg>;
},
MsgType::Query => quote! {
fn #name (&self, #(#params,)* ) -> Result<#return_type, #error_type>;
},
_ => quote! {},

Check warning on line 781 in sylvia-derive/src/message.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/message.rs#L781

Added line #L781 was not covered by tests
}
}

pub fn as_fields_names(&self) -> Vec<&Ident> {
self.fields.iter().map(MsgField::name).collect()
}

pub fn emit_fields(&self) -> Vec<TokenStream> {
self.fields.iter().map(MsgField::emit).collect()
}

pub fn name(&self) -> &Ident {
&self.name
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -886,6 +1022,64 @@
}
}
}
pub fn emit_multitest_proxy_methods(
&self,
custom_msg: &Type,
mt_app: &Type,
error_type: &Type,
) -> Vec<TokenStream> {
self.variants
.iter()
.map(|variant| {
variant.emit_multitest_proxy_methods(&self.msg_ty, custom_msg, mt_app, error_type)
})
.collect()
}

pub fn emit_interface_multitest_proxy_methods<Generics>(
&self,
custom_msg: &Type,
mt_app: &Type,
error_type: &Type,
generics: &[&Generics],
module: &TokenStream,
) -> Vec<TokenStream>
where
Generics: ToTokens,
{
self.variants
.iter()
.map(|variant| {
variant.emit_interface_multitest_proxy_methods(
&self.msg_ty,
custom_msg,
mt_app,
error_type,
generics,
module,
)
})
.collect()
}

pub fn emit_proxy_methods_declarations(
&self,
custom_msg: &Type,
error_type: &Type,
interface_enum: &TokenStream,
) -> Vec<TokenStream> {
self.variants
.iter()
.map(|variant| {
variant.emit_proxy_methods_declarations(
&self.msg_ty,
custom_msg,
error_type,
interface_enum,
)
})
.collect()
}

pub fn emit_dispatch_legs(&self) -> impl Iterator<Item = TokenStream> + '_ {
self.variants
Expand Down
Loading
Loading