-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the data_struct related testing for the verifier. (#1729)
* support the data_struct testing for verifier append missed code * fix the wrong status code * remove the useless function * change the used scope of the unsafe
- Loading branch information
1 parent
58f0bb6
commit c194798
Showing
22 changed files
with
327 additions
and
131 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
crates/rooch-framework-tests/tests/cases/mvir_tests/data_struct_malformed_struct_name.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
processed 1 task | ||
|
||
task 0 'publish'. lines 1-9: | ||
status ABORTED with code 10006 in 0000000000000000000000000000000000000000000000000000000000000002::move_module |
9 changes: 9 additions & 0 deletions
9
crates/rooch-framework-tests/tests/cases/mvir_tests/data_struct_malformed_struct_name.mvir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//# publish | ||
module 0x1.TestModule1 { | ||
metadata { | ||
data_struct { | ||
// error code 10006: MALFORMED_STRUCT_NAME | ||
invalid_module_struct_name -> true; | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
crates/rooch-framework-tests/tests/cases/mvir_tests/private_generics_function_not_exists.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
processed 1 task | ||
|
||
task 0 'publish'. lines 1-14: | ||
status ABORTED with code 10001 in 0000000000000000000000000000000000000000000000000000000000000002::move_module |
14 changes: 14 additions & 0 deletions
14
...es/rooch-framework-tests/tests/cases/mvir_tests/private_generics_function_not_exists.mvir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//# publish | ||
module 0x1.TestModule1 { | ||
metadata { | ||
private_generics { | ||
// error code 10001: FUNCTION_NOT_EXITS | ||
0x1::TestModule1::f111 -> true; | ||
} | ||
} | ||
|
||
public f1() { | ||
label b0: | ||
return; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...es/rooch-framework-tests/tests/cases/mvir_tests/private_generics_invalid_module_owner.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
processed 1 task | ||
|
||
task 0 'publish'. lines 1-9: | ||
status ABORTED with code 10010 in 0000000000000000000000000000000000000000000000000000000000000002::move_module |
9 changes: 9 additions & 0 deletions
9
...s/rooch-framework-tests/tests/cases/mvir_tests/private_generics_invalid_module_owner.mvir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//# publish | ||
module 0x1.TestModule1 { | ||
metadata { | ||
private_generics { | ||
// error code 10010: INVALID_MODULE_OWNER | ||
0x123::SomeModule::f1 -> true; | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...rooch-framework-tests/tests/cases/mvir_tests/private_generics_malformed_function_name.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
processed 1 task | ||
|
||
task 0 'publish'. lines 1-11: | ||
status ABORTED with code 10007 in 0000000000000000000000000000000000000000000000000000000000000002::move_module |
11 changes: 11 additions & 0 deletions
11
...ooch-framework-tests/tests/cases/mvir_tests/private_generics_malformed_function_name.mvir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//# publish | ||
module 0x1.TestModule1 { | ||
struct S0 has drop { x: u64 } | ||
|
||
metadata { | ||
private_generics { | ||
// error code 10007: MALFORMED_FUNCTION_NAME | ||
invalid_module_function_name -> true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use serde::{de, ser}; | ||
use std::fmt; | ||
macro_rules! derive_code_try_from_repr { | ||
( | ||
#[repr($repr_ty:ident)] | ||
$( #[$metas:meta] )* | ||
$vis:vis enum $enum_name:ident { | ||
$( | ||
$variant:ident = $value: expr | ||
),* | ||
$( , )? | ||
} | ||
) => { | ||
#[repr($repr_ty)] | ||
$( #[$metas] )* | ||
$vis enum $enum_name { | ||
$( | ||
$variant = $value | ||
),* | ||
} | ||
|
||
impl std::convert::TryFrom<$repr_ty> for $enum_name { | ||
type Error = &'static str; | ||
fn try_from(value: $repr_ty) -> Result<Self, Self::Error> { | ||
match value { | ||
$( | ||
$value => Ok($enum_name::$variant), | ||
)* | ||
_ => Err("invalid ErrorCode"), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(any(test, feature = "fuzzing"))] | ||
const ERROR_CODE_VALUES: &'static [$repr_ty] = &[ | ||
$($value),* | ||
]; | ||
}; | ||
} | ||
|
||
derive_code_try_from_repr! { | ||
#[repr(u64)] | ||
#[allow(non_camel_case_types)] | ||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] | ||
pub enum ErrorCode { | ||
MALFORMED_METADATA = 10000, | ||
FUNCTION_NOT_EXITS = 10001, | ||
STRUCT_NOT_EXISTS = 10002, | ||
NOT_ENOUGH_PARAMETERS = 10003, | ||
TOO_MANY_PARAMETERS = 10004, | ||
TYPE_MISMATCH = 10005, | ||
MALFORMED_STRUCT_NAME = 10006, | ||
MALFORMED_FUNCTION_NAME = 10007, | ||
INVALID_DATA_STRUCT = 10008, | ||
INVALID_DATA_STRUCT_TYPE = 10009, | ||
INVALID_MODULE_OWNER = 10010, | ||
|
||
INVALID_ENTRY_FUNC_SIGNATURE = 11000, | ||
INVALID_PARAM_TYPE_ENTRY_FUNCTION = 11001, | ||
|
||
INVALID_PUBLIC_INIT_FUNC = 12000, | ||
INVALID_INIT_FUNC_WITH_ENTRY = 12001, | ||
INVALID_TOO_MANY_PARAMS_INIT_FUNC = 12002, | ||
|
||
INVALID_INSTRUCTION = 13000, | ||
|
||
UNKNOWN_CODE = 18446744073709551615, | ||
} | ||
} | ||
|
||
impl ser::Serialize for ErrorCode { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: ser::Serializer, | ||
{ | ||
serializer.serialize_u64((*self).into()) | ||
} | ||
} | ||
|
||
impl<'de> de::Deserialize<'de> for ErrorCode { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: de::Deserializer<'de>, | ||
{ | ||
struct ErrorCodeVisitor; | ||
impl<'de> de::Visitor<'de> for ErrorCodeVisitor { | ||
type Value = ErrorCode; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
formatter.write_str("StatusCode as u64") | ||
} | ||
|
||
fn visit_u64<E>(self, v: u64) -> Result<ErrorCode, E> | ||
where | ||
E: de::Error, | ||
{ | ||
Ok(ErrorCode::try_from(v).unwrap_or(ErrorCode::UNKNOWN_CODE)) | ||
} | ||
} | ||
|
||
deserializer.deserialize_u64(ErrorCodeVisitor) | ||
} | ||
} | ||
|
||
impl From<ErrorCode> for u64 { | ||
fn from(status: ErrorCode) -> u64 { | ||
status as u64 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
pub mod build; | ||
pub mod metadata; | ||
pub mod verifier; | ||
|
||
pub mod error_code; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.