Skip to content

Commit

Permalink
add publish checks
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Feb 21, 2024
1 parent 1122494 commit 07a894e
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions aptos-move/framework/src/module_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,24 @@ pub struct AttributeValidationError {
pub attribute: u8,
}

pub fn is_valid_function_which_uses_randomness(
functions: &BTreeMap<Identifier, Function>,
fun: &str,
) -> Result<(), AttributeValidationError> {
if let Ok(ident_fun) = Identifier::new(fun) {
if let Some(f) = functions.get(&ident_fun) {
if f.is_entry {
return Ok(());
}
}
}

Check warning on line 358 in aptos-move/framework/src/module_metadata.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/framework/src/module_metadata.rs#L357-L358

Added lines #L357 - L358 were not covered by tests

Err(AttributeValidationError {
key: fun.to_string(),
attribute: KnownAttributeKind::UsesRandomness as u8,
})
}

pub fn is_valid_view_function(
functions: &BTreeMap<Identifier, Function>,
fun: &str,
Expand Down Expand Up @@ -429,10 +447,10 @@ pub fn verify_module_metadata(
for (fun, attrs) in &metadata.fun_attributes {
for attr in attrs {
if attr.is_view_function() {
is_valid_view_function(&functions, fun)?
};

if !attr.is_uses_randomness() && !attr.is_view_function() {
is_valid_view_function(&functions, fun)?;
} else if attr.is_uses_randomness() {
is_valid_function_which_uses_randomness(&functions, fun)?;
} else {
return Err(AttributeValidationError {
key: fun.clone(),
attribute: attr.kind,
Expand Down

0 comments on commit 07a894e

Please sign in to comment.