diff --git a/stylus-proc/src/macros/derive/solidity_error/mod.rs b/stylus-proc/src/macros/derive/solidity_error/mod.rs index e1465966..e97948a0 100644 --- a/stylus-proc/src/macros/derive/solidity_error/mod.rs +++ b/stylus-proc/src/macros/derive/solidity_error/mod.rs @@ -70,6 +70,17 @@ impl DeriveSolidityError { } } } + + fn method_error_impl(&self) -> syn::ItemImpl { + let name = &self.name; + parse_quote! { + impl stylus_sdk::stylus_core::errors::MethodError for #name { + fn encode(self) -> alloc::vec::Vec { + self.into() + } + } + } + } } impl From<&syn::ItemEnum> for DeriveSolidityError { @@ -101,6 +112,7 @@ impl ToTokens for DeriveSolidityError { from_impl.to_tokens(tokens); } self.vec_u8_from_impl().to_tokens(tokens); + self.method_error_impl().to_tokens(tokens); Extension::codegen(self).to_tokens(tokens); } } @@ -160,5 +172,13 @@ mod tests { } }, ); + assert_ast_eq( + derived.method_error_impl(), + parse_quote!{ + impl stylus_sdk::stylus_core::errors::MethodError for MyError { + fn encode(self) -> alloc::vec::Vec { self.into() } + } + } + ) } }