Skip to content

Commit

Permalink
Enforce value to be in u64 range
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Apr 25, 2024
1 parent 41632e0 commit 18ef64a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ fn expand_attributes(func: &mut ItemFn) -> syn::Result<TokenStream> {
}

let version: syn::LitInt = attribute.parse_args()?;
// Enforce that the version is in range of a u64
version.base10_parse::<u64>()?;
let version = version.base10_digits();

stream = quote! {
Expand Down Expand Up @@ -190,6 +192,23 @@ mod test {

use crate::entry_point_impl;

#[test]
fn contract_state_version_in_u64() {
let code = quote! {
#[set_state_version(0xDEAD_BEEF_FFFF_DEAD_2BAD)]
fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Response {
// Logic here
}
};

let actual = entry_point_impl(TokenStream::new(), code);
let expected = quote! {
::core::compile_error! { "number too large to fit in target type" }
};

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

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

0 comments on commit 18ef64a

Please sign in to comment.