Skip to content

Commit

Permalink
Test attribute on non-migrate function
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Apr 25, 2024
1 parent 80be776 commit c90c014
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn expand_attributes(func: &mut ItemFn) -> syn::Result<TokenStream> {
if func.sig.ident != "migrate" {
return Err(syn::Error::new_spanned(
&attribute,
"you only want to add this macro to your migrate function",
"you only want to add this attribute to your migrate function",
));
}

Expand Down Expand Up @@ -192,6 +192,23 @@ mod test {

use crate::entry_point_impl;

#[test]
fn contract_state_version_on_non_migratee() {
let code = quote! {
#[state_version(42)]
fn anything_else() -> Response {
// Logic here
}
};

let actual = entry_point_impl(TokenStream::new(), code);
let expected = quote! {
::core::compile_error! { "you only want to add this attribute to your migrate function" }
};

assert_eq!(actual.to_string(), expected.to_string());
}

#[test]
fn contract_state_version_in_u64() {
let code = quote! {
Expand Down

0 comments on commit c90c014

Please sign in to comment.