sui
sui copied to clipboard
[4/n][enums] Move enums all of the Move tests
Description
This PR consists of tests only! (and updates to exp files of existing tests).
Stack:
- #17245
- #17246 << You are here
- #17247
- #17248
- #17249
- #17250
- #17251
Test Plan
File format
Status: Done
- Bounds checking and serialization proptests updated.
Deserializer
Status: Done
- Added test to verify that we are properly checking for versioning issues -- e.g., if someone manually changed the version of the serialized module so the version was pre-enums, but contained enum-data inside of it.
Serializer
Status: Done
- Ensured that serializing a version 7 module at version 6 works as long as no version 7 features are used, and that the resulting module can be deserialized into version 6 and version 7 modules.
- Proptests for serializer/deserializer round-trips
- Tested round-trip properties:
- Version 7 module with no eums can:
- Be serialized under version 6
- Result can be deserialized under version 6 and 7 and reserialized at version 6 and 7.
- Version 7 module with no eums can:
- Updated serializer, and added tests to make sure we use the module's version when serializing, unless it is specified as an override.
Compatibility
Status: Done
- [x] Add config to allow adding new variants
- [x] Existing variants must be in the same order (have the same tag)
- [x] Cannot remove a variant
- [x] Cannot change a field or fields of an existing variant
- [x] Cannot rename existing variant
Bytecode Verifier
Status: Done
- [x] Unpack
- [x] [type-checker] Unpack a non-generic enum with generic instruction (by value, imm ref, and mut ref)
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/unpack_non_generic_enum_generically.mvir]
- [x] [type-checker] Unpack a generic enum with non-generic instruction (by value, imm ref, and mut ref)
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/unpack_generic_enum_non_generically.mvir]
- [x] [type-checker] Unpack a generic enum with invalid type arguments (by value, imm ref, and mut ref)
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/unpack_generic_enum_wrong_type_arg.mvir]
- [x] ImmRef
- [type-checker] Unpack a mutable reference [generic, non-generic]
- [type-checker] Unpack a value [generic, non-generic]
- [x] MutRef
- [type-checker] Unpack an immutable reference [generic, non-generic]
- [type-checker] Unpack a value [generic, non-generic]
- [x] [stack-balance] Unpack with invalid number of arguments [too many, too little]
- [x] [bound-checker] Invalid variant index [generic, non-generic]
- [x] [bound-checker] Invalid enum definition/definition instantiation index [generic, non-generic]
- [x] [type-checker] Unpack a non-generic enum with generic instruction (by value, imm ref, and mut ref)
- [x] Write test to make sure we properly track borrows out of variant ref unpacks:
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/factor_invalid_2_enum.mvir]
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/reference_safety/imm_borrow_on_mut_trivial_invalid_enum.mvir]
- Pack
- [x] [type-checker] Pack a non-generic enum [generic]
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/pack_generic_enum_non_generically.mvir]
- [x] [type-checker] Pack a generic enum [non-generic]
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/pack_non_generic_enum_generically.mvir]
- [x] [type-checker] Pack a generic enum with invalid type arguments [generic]
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/pack_generic_enum_invalid_type_arguments.mvir]
- [bound-checker] Invalid variant index [generic, non-generic]
- [x] Pack with invalid number of arguments [generic, non-generic][too many, too little]
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/stack_usage_verifier/pack_invalid_number_arguments_enum.mvir]
- [x] Pack with references [generic, non-generic][imm-ref, mut-ref]
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/pack_enum_with_refs.mvir]
- [x] [type-checker] Pack a non-generic enum [generic]
- VariantSwitch/Jump Table (these cannot be IR tests sadly except for the last)
- [type-checker] Head Type
- [x] Head type isn't an enum [struct, primitive type]
- Structurally impossible to represent since it takes an enum definition index
- [x] Head type is a reference type [enum, struct, primitive type]
- Structurally impossible to represent since it takes an enum definition index
- [x] Head type is to a different enum [generic, mono]
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/variant_switch_invalid_head_type.mvir]
- [x] Head type isn't an enum [struct, primitive type]
- Switch value type
- [x] [type-checker] Not a reference [enum, struct, primitive type]
- [x] [type-checker] Is a mutable reference [enum, struct, primitive type]
- [x] [type-checker] Switch value type and head type disagree [enum/struct, struct/enum, enum/primitive, struct/primitive, reference[enum,struct,primitive]]
- [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/variant_switch_invalid_head_type.mvir]
- [x] [bounds-checker] Invalid code index in jump table
- [x] [bound-checker] Invalid jump table index
- Exhaustiveness
- [x] [type-checker] Write test that checks we properly error if an inexhaustive jump table is supplied [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/variant_switch_partial_enum_switch.mvir]
- [type-checker] Head Type
Abilities
- [x] Enum can have fewer abilities than the type that it contains [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/ability_field_requirements/unrestricted_enum_has_resource_field.exp]
- [x] Enum cannot have abilities that a type that it contains does not satisfy [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/ability_field_requirements/unrestricted_enum_has_resource_field.mvir]
check_bounds
- [x] Generic enum cannot have too few type arguments [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/check_bounds/too_few_type_actuals_enum.mvir]
- [x] Generic enum cannot have too many type arguments [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/check_bounds/too_many_type_actuals_enum.mvir]
check_duplication
- [x] Cannot have enum and struct in the same module with the same name [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/check_duplication/duplicate_enum_and_struct_names.mvir]
- [x] Cannot have two enums in the same module with the same name [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/check_duplication/duplicate_enum_name.mvir]
- [x] Cannot have an enum variant with duplicate field names [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/check_duplication/duplicate_field_name_enum.mvir]
- [x] Cannot have an enum with duplicate variant names [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/check_duplication/duplicate_variant_name.mvir]
- [x] Cannot have an empty enum [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/check_duplication/empty_enums.mvir]
- [x] Check for duplicated variant handles [external-crates/move/crates/bytecode-verifier-tests/src/unit_tests/duplication_tests.rs]
- [x] Check for duplicated datatype names [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/enum_defs/module_enum_struct_shared_name.mvir]
enum_defs
- [x] Can have an enum with the same name as the module [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/enum_defs/module_enum_shared_name.mvir]
- [x] Cannot have mutually recursive enums (simple test) [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/enum_defs/mutual_recursive_enum.mvir]
- [x] More complex recursive enum definition checks [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/enum_defs/recursive_enum.mvir]
- [x] Cannot declare an enum with references inside of it [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/enum_defs/ref_in_enum.mvir]
instantiaion_loops [each test is an existing test that we have for structs but ported over to enums]
- [x] Complex type instantiation loop using enums [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/instantiation_loops/complex_1_enum.mvir]
- [x] Mutually recursive enum type instantiated with a type is OK [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/instantiation_loops/mutually_recursive_non_generic_type_ok_enum.mvir]
- [x] Mutually recursive enum type instantiation with a type is OK since the types eventually shuffle to ground out [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/instantiation_loops/mutually_recursive_three_args_type_con_non_generic_types_ok_enum.mvir]
- ...
locals_safety
- [x] Re-assign an enum that doesn't have drop [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/locals_safety/assign_enum_resource.mvir]
stack_usage_verifier
- [x] Unpack an enum variant with too many fields [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/stack_usage_verifier/unpack_extra_binding_enum.mvir]
- [x] Unpack an enum variant with too few fields [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/stack_usage_verifier/unpack_missing_binding_enum.mvir]
type_safety
- [x] Write a mutable non-drop reference containing an enum [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/assign_local_resource.mvir]
- [x] Write a mutable non-drop reference containing an enum twice [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/assign_local_resource_twice.mvir]
- [x] Write a mutable non-drop reference contained in an enum [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/assign_resource_type_enum.mvir]
- [x] Dereference an non-copy enum reference type [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/cant_deref_resource.mvir]
- [x] Check that equality can occur over enum references without drop [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/equality_resource_refs.mvir]
- [x] Check that equality cannot be called over non-drop enum types [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/equality_resource_values.mvir]
- [x] Verify that we can take immutable references into an enum variant, and then take those fields by ownership once those references are no longer live [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_abilities_imm_unpack_enum.mvir]
- [x] Verify that we can take mutable references into an enum variant, and then take those fields by ownership once those references are no longer live [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_abilities_unpack_mut_enum.mvir]
- [x] Verify that we properly typecheck a valid generic pack of an enum variant [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_abilities_pack.mvir]
- [x] Try to copy an enum type that does not have copy [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_abilities_struct_non_nominal_resource.mvir]
- [x] Unpack a generic enum where the inner value's type parameter doesn't have copy, and then fail to the destroy the value after unpacking [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_abilities_unpack.mvir]
- [x] Can call a generic function with an instantiated enum variant value [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_call.mvir]
- [x] Can borrow a deep generic field from within an enum/its variants and properly dereference and return the resulting value [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_field_borrow.mvir]
- [x] Can borrow and unpack an enum reference returned from a generic function call [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_field_unpack_borrow_after_call_enum.mvir]
- [x] Can import and use a generic enum type from another module [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_import_struct.mvir]
- [x] Example using
Option
(the actual one this time!) and making sure it typechecks [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_option.mvir] - [x] We can call pack a generic enum variant correctly [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_pack.mvir]
- [x] Check correct ability constraints for enum definition parameters [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_struct_def.mvir]
- [x] Type mismatch in a field write inside an enum variant [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/invalid_field_write_mut_unpack_enum.mvir]
- [x] Type mismatch in generic unpack of enum [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_unpack_type_mismatch.mvir]
- [x] Type mismatch in generic pack of enum (and struct) [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/generic_pack_type_mismatch.mvir]
- [x] Try to overwrite a non-drop value by mut ref held inside an enum [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/invalid_resouce_write_unpack_mut_enum.mvir]
- [x] Try to unpack_mut on an immutable reference (both generic and non-generic) [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/mut_borrow_from_imm_ref_enum.mvir]
- [x] Pass an imm ref enum type to a function expecting a mut ref [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/mut_call_with_imm_ref_enum.mvir]
- [x] Make sure bytecode operations ability requirements respect enum type abilities [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/phantom_params/bytecode_ops_abilities_bad.mvir]
- [x] Make sure bytecode operations ability requirements work with enum abilities (positive tests) [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/phantom_params/bytecode_ops_abilities_ok.mvir]
- [x] Verify ability constraints are properly enforced for enum types [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/phantom_params/constraints_abilities_bad.mvir]
- [x] Verify ability constraints are properly enforced for enum types (positive tests)[external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/phantom_params/constraints_abilities_ok.mvir]
- [x] Make sure field abilities (or lack thereof) are properly computed and enforced [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/phantom_params/fields_abilities_bad.mvir]
- [x] Make sure field abilities (or lack thereof) are properly computed and enforced (positive tests)[external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/phantom_params/fields_abilities_ok.mvir]
- [x] Check for illegal phantom type parameter usage on enums [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/phantom_params/struct_definition_bad.mvir]
- [x] Check for legal phantom type parameter usage on enums [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/phantom_params/struct_definition_ok.mvir]
- [x] Check for invalid instantiations of a ref enum type in function parameters [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/ref_type_param.mvir]
- [x] Check for invalid (and exploitable) usage patterns around references of enums [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/ref_type_param_exploits.mvir]
- [x] Pack a monomorphic enum with the wrong (non-primitive) type [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/resource_instantiate_bad_type.mvir]
- [x] Return type mismatch with enum type and unused non-drop enum (sequencing of these checks) [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/return_type_mismatch_and_unused_resource.mvir]
- [x] Verify that generic enums instantiated with other (non-copy/drop) enums behave as expected [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/struct_kind_inference.mvir]
- [x] Verify that a non-copy/drop enum can be unpacked, and its contents returned from a function successfully [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/unpack_resource.mvir]
- [x] Verify that unpacking with a different type, but same variant name/tag/layout will result in a type error [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/unpack_wrong_type.mvir]
- [x] Verify that we can create droppable enums, and that they can be dropped [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/unrestricted_instantiate.mvir]
- [x] Try to pack a monomorphic enum with an invalid field type [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/unrestricted_instantiate_bad_type.mvir]
- [x] Fail to do anything with a non-drop enum type [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/unused_resource_holder.mvir]
- [x] Ensure that type parameter constraints are properly computed and reported for function type parameters without the proper abilities even though they are inside a native container (vector) [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/type_safety/vector_type_param.mvir]
- [x] Fail to handle an undroppable value within a variant switch [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/control_flow/variant_switch.mvir]
- [x] Try to use an unassigned value within a variant switch arm [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/control_flow/variant_switch.mvir]
- [x] Fail to unpack an undroppable enum within a variant switch [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/control_flow/variant_switch_successor.mvir]
- [x] Make sure we properly construct the control flow graph for a variant switch as an unconditional branch [external-crates/move/crates/bytecode-verifier-transactional-tests/tests/control_flow/variant_switch_unconditional_branch.mvir]
- [x] Added low-level tests to make sure we properly construct the control flow graph [external-crates/move/crates/move-binary-format/src/unit_tests/control_flow_graph_tests.rs] and in [external-crates/move/crates/move-ir-compiler/src/unit_tests/cfg_tests.rs]
- [x] Added test to make sure successors are always sorted/stable, and that the control-flow graph generated is the same regardless of the order of the jumps within a variant switch [external-crates/move/crates/move-binary-format/src/unit_tests/control_flow_graph_tests.rs:out_of_order_blocks_variant_switch]
VM
- [x] Test trying to unpack the wrong variant (generic, non-generic)
- [x] Test that execution proceeds normally, and that we get expected results for computations that use enums
- [x] Test that mutable references taken from an enum variant can be modified, and that these modifications are reflected correctly
- [x] Test that we can mutate the variant inside of an enum type.
- [x] Added tests to make sure we can't infinitie loop within a variant switch [external-crates/move/crates/move-vm-transactional-tests/tests/enums/variant_switch_loop.mvir]
Values
- [x] Test that enum
Option
is backwards compatible with vectorOption
.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
sui-core | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 24, 2024 5:53pm |
sui-docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 24, 2024 5:53pm |
3 Ignored Deployments
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
multisig-toolkit | ⬜️ Ignored (Inspect) | Visit Preview | May 24, 2024 5:53pm | |
sui-kiosk | ⬜️ Ignored (Inspect) | Visit Preview | May 24, 2024 5:53pm | |
sui-typescript-docs | ⬜️ Ignored (Inspect) | Visit Preview | May 24, 2024 5:53pm |
Should we preserve / move the development/enums/matching
tests to move_2024/
for the compiler suite as well? It is somewhat redundant, but I often rely on the compiler tests during development.