diff --git a/near-sdk-macros/src/core_impl/code_generator/item_impl_info.rs b/near-sdk-macros/src/core_impl/code_generator/item_impl_info.rs index fc461f291..1b51a73da 100644 --- a/near-sdk-macros/src/core_impl/code_generator/item_impl_info.rs +++ b/near-sdk-macros/src/core_impl/code_generator/item_impl_info.rs @@ -81,6 +81,43 @@ mod tests { assert_eq!(expected.to_string(), actual.to_string()); } + #[test] + fn owned_no_args_no_return_no_mut() { + let impl_type: Type = syn::parse_str("Hello").unwrap(); + let mut method: ImplItemMethod = syn::parse_str("pub fn method(self) { }").unwrap(); + let method_info = ImplItemMethodInfo::new(&mut method, impl_type).unwrap(); + let actual = method_info.method_wrapper(); + let expected = quote!( + #[cfg(target_arch = "wasm32")] + #[no_mangle] + pub extern "C" fn method() { + near_sdk::env::setup_panic_hook(); + let contract: Hello = near_sdk::env::state_read().unwrap_or_default(); + contract.method(); + } + ); + assert_eq!(expected.to_string(), actual.to_string()); + } + + + #[test] + fn mut_owned_no_args_no_return() { + let impl_type: Type = syn::parse_str("Hello").unwrap(); + let mut method: ImplItemMethod = syn::parse_str("pub fn method(mut self) { }").unwrap(); + let method_info = ImplItemMethodInfo::new(&mut method, impl_type).unwrap(); + let actual = method_info.method_wrapper(); + let expected = quote!( + #[cfg(target_arch = "wasm32")] + #[no_mangle] + pub extern "C" fn method() { + near_sdk::env::setup_panic_hook(); + let mut contract: Hello = near_sdk::env::state_read().unwrap_or_default(); + contract.method(); + } + ); + assert_eq!(expected.to_string(), actual.to_string()); + } + #[test] fn no_args_no_return_mut() { let impl_type: Type = syn::parse_str("Hello").unwrap(); diff --git a/near-sdk-macros/src/core_impl/info_extractor/attr_sig_info.rs b/near-sdk-macros/src/core_impl/info_extractor/attr_sig_info.rs index dd447e488..e670eefd6 100644 --- a/near-sdk-macros/src/core_impl/info_extractor/attr_sig_info.rs +++ b/near-sdk-macros/src/core_impl/info_extractor/attr_sig_info.rs @@ -105,7 +105,7 @@ impl AttrSigInfo { if let Some(ref receiver) = receiver { if matches!(method_type, MethodType::Regular) { - if receiver.mutability.is_none() { + if receiver.mutability.is_none() || receiver.reference.is_none() { method_type = MethodType::View; } } else {