From 18ef64a22b48a2b3c4906edd027ddc5cf2edd2db Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Thu, 25 Apr 2024 10:37:57 +0200 Subject: [PATCH] Enforce value to be in u64 range --- packages/derive/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/derive/src/lib.rs b/packages/derive/src/lib.rs index 48f2ceb2f9..2439215ba5 100644 --- a/packages/derive/src/lib.rs +++ b/packages/derive/src/lib.rs @@ -136,6 +136,8 @@ fn expand_attributes(func: &mut ItemFn) -> syn::Result { } let version: syn::LitInt = attribute.parse_args()?; + // Enforce that the version is in range of a u64 + version.base10_parse::()?; let version = version.base10_digits(); stream = quote! { @@ -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! {