Skip to content

Commit

Permalink
[5/n][enums] All Move tests except source lang tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed May 2, 2024
1 parent da14260 commit 9382454
Show file tree
Hide file tree
Showing 273 changed files with 7,847 additions and 228 deletions.
1 change: 1 addition & 0 deletions external-crates/move/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use move_binary_format::{
};
use move_bytecode_verifier::{
ability_field_requirements, constants, instantiation_loops::InstantiationLoopChecker,
DuplicationChecker, InstructionConsistency, RecursiveStructDefChecker, SignatureChecker,
DuplicationChecker, InstructionConsistency, RecursiveDataDefChecker, SignatureChecker,
};
use move_core_types::{
account_address::AccountAddress, identifier::Identifier, vm_status::StatusCode,
Expand Down Expand Up @@ -106,7 +106,7 @@ proptest! {
InstructionConsistency::verify_module(&module).expect("InstructionConsistency failure");
constants::verify_module(&module).expect("constants failure");
ability_field_requirements::verify_module(&module).expect("ability_field_requirements failure");
RecursiveStructDefChecker::verify_module(&module).expect("RecursiveStructDefChecker failure");
RecursiveDataDefChecker::verify_module(&module).expect("RecursiveDataDefChecker failure");
InstantiationLoopChecker::verify_module(&module).expect("InstantiationLoopChecker failure");
}

Expand Down Expand Up @@ -143,7 +143,7 @@ proptest! {

#[test]
fn valid_recursive_struct_defs(module in CompiledModule::valid_strategy(20)) {
prop_assert!(RecursiveStructDefChecker::verify_module(&module).is_ok());
prop_assert!(RecursiveDataDefChecker::verify_module(&module).is_ok());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 2beb0a0e65962432af560e626fa109d269b07db8807968413425f0bb14bb3667 # shrinks to module = CompiledModule: { struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] }
cc c14ae393a6eefae82c0f4ede2acaa0aa0e993c1bba3fe3e5958e6e31cb5d2957 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = []
cc 88615e15ef42d29405cd91d6d0a573ccbeb833d0c7471f718ee794bc5ba399ca # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 }, StructDefinition { struct_handle: 2, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [OutOfBoundsMutation { src_kind: StructDefinition, src_idx: Index(0), dst_kind: FieldDefinition, offset: 0 }]
cc a34039f5d57751762a6eacf3ca3a2857781fb0bd0af0b7a06a9427f896f29aa9 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x2, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x0, code: CodeUnit { max_stack_size: 0, locals: 0 code: [ BrTrue(1),] } },] type_signatures: [ TypeSignature(Unit), TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = []
cc 2beb0a0e65962432af560e626fa109d269b07db8807968413425f0bb14bb3667 # shrinks to module = CompiledModule: { datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] }
cc c14ae393a6eefae82c0f4ede2acaa0aa0e993c1bba3fe3e5958e6e31cb5d2957 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = []
cc 88615e15ef42d29405cd91d6d0a573ccbeb833d0c7471f718ee794bc5ba399ca # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 }, StructDefinition { struct_handle: 2, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [OutOfBoundsMutation { src_kind: StructDefinition, src_idx: Index(0), dst_kind: FieldDefinition, offset: 0 }]
cc a34039f5d57751762a6eacf3ca3a2857781fb0bd0af0b7a06a9427f896f29aa9 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x2, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x0, code: CodeUnit { max_stack_size: 0, locals: 0 code: [ BrTrue(1),] } },] type_signatures: [ TypeSignature(Unit), TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = []
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn invalid_struct_in_fn_return_() {
let mut m = basic_test_module();
m.function_handles[0].return_ = SignatureIndex(1);
m.signatures
.push(Signature(vec![Struct(StructHandleIndex::new(1))]));
.push(Signature(vec![Datatype(DatatypeHandleIndex::new(1))]));
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
Expand Down Expand Up @@ -94,7 +94,7 @@ fn invalid_struct_in_field() {
let mut m = basic_test_module();
match &mut m.struct_defs[0].field_information {
StructFieldInformation::Declared(ref mut fields) => {
fields[0].signature.0 = Struct(StructHandleIndex::new(3));
fields[0].signature.0 = Datatype(DatatypeHandleIndex::new(3));
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
Expand All @@ -111,8 +111,8 @@ fn invalid_struct_with_actuals_in_field() {
let mut m = basic_test_module();
match &mut m.struct_defs[0].field_information {
StructFieldInformation::Declared(ref mut fields) => {
fields[0].signature.0 = StructInstantiation(Box::new((
StructHandleIndex::new(0),
fields[0].signature.0 = DatatypeInstantiation(Box::new((
DatatypeHandleIndex::new(0),
vec![TypeParameter(0)],
)));
assert_eq!(
Expand Down Expand Up @@ -167,7 +167,7 @@ fn invalid_struct_as_type_actual_in_exists() {

let mut m = basic_test_module();
m.signatures
.push(Signature(vec![Struct(StructHandleIndex::new(3))]));
.push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))]));
m.function_instantiations.push(FunctionInstantiation {
handle: FunctionHandleIndex::new(0),
type_parameters: SignatureIndex::new(1),
Expand Down Expand Up @@ -239,7 +239,7 @@ fn invalid_struct_for_vector_operation() {
let mut skeleton = basic_test_module();
skeleton
.signatures
.push(Signature(vec![Struct(StructHandleIndex::new(3))]));
.push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))]));
let sig_index = SignatureIndex((skeleton.signatures.len() - 1) as u16);
for bytecode in [
VecPack(sig_index, 0),
Expand Down Expand Up @@ -286,3 +286,77 @@ fn invalid_type_param_for_vector_operation() {
);
}
}

#[test]
fn invalid_variant_handle_index_for_enum_operation() {
use Bytecode::*;

let skeleton = basic_test_module();
let variant_handle_index = VariantHandleIndex(skeleton.variant_handles.len() as u16);
let variant_handle_inst_index =
VariantInstantiationHandleIndex(skeleton.variant_instantiation_handles.len() as u16);
for bytecode in [
PackVariant(variant_handle_index),
UnpackVariant(variant_handle_index),
UnpackVariantImmRef(variant_handle_index),
UnpackVariantMutRef(variant_handle_index),
PackVariantGeneric(variant_handle_inst_index),
UnpackVariantGeneric(variant_handle_inst_index),
UnpackVariantGenericImmRef(variant_handle_inst_index),
UnpackVariantGenericMutRef(variant_handle_inst_index),
] {
let mut m = skeleton.clone();
m.function_defs[0].code.as_mut().unwrap().code = vec![bytecode];
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
);
}
}

#[test]
fn invalid_variant_jump_table_index() {
use Bytecode::*;

let skeleton = basic_test_module();
let jt_index = VariantJumpTableIndex(
skeleton.function_defs[0]
.code
.as_ref()
.map(|c| c.jump_tables.len() as u16)
.unwrap_or(0u16),
);
let mut m = skeleton.clone();
m.function_defs[0].code.as_mut().unwrap().code = vec![VariantSwitch(jt_index)];
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
);
}

#[test]
fn invalid_variant_jump_table_code_offset() {
use Bytecode::*;

let mut skeleton = basic_test_module_with_enum();
let enum_index = EnumDefinitionIndex(0);
skeleton.function_defs[0].code.as_mut().unwrap().code = vec![LdU64(0), Pop, Ret];
skeleton.function_defs[0].code.as_mut().unwrap().jump_tables = vec![VariantJumpTable {
head_enum: enum_index,
jump_table: JumpTableInner::Full(vec![100]),
}];

let jt_index = VariantJumpTableIndex(
skeleton.function_defs[0]
.code
.as_ref()
.map(|c| c.jump_tables.len() as u16)
.unwrap_or(0u16),
);
let mut m = skeleton.clone();
m.function_defs[0].code.as_mut().unwrap().code = vec![VariantSwitch(jt_index)];
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn invalid_types() {

// TODO cannot check structs are banned currently. This can be handled by IR and source lang
// tests
// invalid_type(SignatureToken::Struct(StructHandleIndex(0)), vec![0]);
// invalid_type(SignatureToken::Datatype(DatatypeHandleIndex(0)), vec![0]);
}

fn tvec(s: SignatureToken) -> SignatureToken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ fn duplicated_friend_decls() {
m.friend_decls.push(handle);
DuplicationChecker::verify_module(&m).unwrap_err();
}

#[test]
fn duplicated_variant_handles() {
let mut m = basic_test_module_with_enum();
m.variant_handles.push(m.variant_handles[0].clone());
DuplicationChecker::verify_module(&m).unwrap_err();
}
Loading

0 comments on commit 9382454

Please sign in to comment.