Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move] Add large enum test #19075

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// tests error after serializing a large enum return value

//# init --addresses test=0x0 --accounts A

//# publish

module test::m {

public enum X1 has drop {
Big1(u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8),
}

public enum X2 has drop {
V1(X1, X1, X1),
V2(X1, X1, X1),
V3(X1, X1, X1),
}

public enum X3 has drop {
X2(X2, X2, X2),
U64(u64),
}

entry fun x1(): X1 {
X1::Big1(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
}

entry fun x3(): X3 {
X3::U64(0)
}

}

//# programmable --sender A
//> test::m::x1()

//# programmable --sender A
//> test::m::x3()
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
processed 4 tasks

task 2, line 34:
//# run 0x42::m::x1
return values: |0|{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

task 3, line 36:
//# run 0x42::m::x3
Error: Function execution failed with VMError: {
major_status: VERIFICATION_ERROR,
sub_status: None,
location: undefined,
indices: [],
offsets: [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// tests error after serializing a large enum return value

//# init --edition 2024.alpha

//# publish

module 0x42::m {

public enum X1 {
Big(u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8),
}

public enum X2 {
V1(X1, X1, X1),
V2(X1, X1, X1),
V3(X1, X1, X1),
}

public enum X3 {
X2(X2, X2, X2),
U64(u64),
}

entry fun x1(): X1 {
X1::Big(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
}

entry fun x3(): X3 {
X3::U64(0)
}

}

//# run 0x42::m::x1

//# run 0x42::m::x3
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ impl<const AFTER_TYPING: bool> ProgramInfo<AFTER_TYPING> {
_ => panic!("ICE should have failed in naming"),
}
}

pub fn datatype_declared_loc(&self, m: &ModuleIdent, n: &DatatypeName) -> Loc {
match self.datatype_kind(m, n) {
DatatypeKind::Struct => self.struct_declared_loc_(m, &n.0.value),
DatatypeKind::Enum => self.enum_declared_loc_(m, &n.0.value),
}
}

pub fn datatype_declared_abilities(&self, m: &ModuleIdent, n: &DatatypeName) -> &AbilitySet {
match self.datatype_kind(m, n) {
DatatypeKind::Struct => self.struct_declared_abilities(m, n),
DatatypeKind::Enum => self.enum_declared_abilities(m, n),
}
}

pub fn struct_definition(&self, m: &ModuleIdent, n: &DatatypeName) -> &StructDefinition {
self.struct_definition_opt(m, n)
.expect("ICE should have failed in naming")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,8 @@ fn entry_return(
let (declared_loc_opt, declared_abilities) = match tn_ {
TypeName_::Multiple(_) => (None, AbilitySet::collection(*tloc)),
TypeName_::ModuleType(m, n) => (
Some(context.info.struct_declared_loc(m, n)),
context.info.struct_declared_abilities(m, n).clone(),
Some(context.info.datatype_declared_loc(m, n)),
context.info.datatype_declared_abilities(m, n).clone(),
),
TypeName_::Builtin(b) => (None, b.value.declared_abilities(b.loc)),
};
Expand Down Expand Up @@ -1064,7 +1064,7 @@ fn check_private_transfer(context: &mut Context, loc: Loc, mcall: &ModuleCall) {
let store_loc = if let Some((first_ty_module, first_ty_name)) = &first_ty_tn {
let abilities = context
.info
.struct_declared_abilities(first_ty_module, first_ty_name);
.datatype_declared_abilities(first_ty_module, first_ty_name);
abilities.ability_loc_(Ability_::Store).unwrap()
} else {
first_ty
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
error[Sui E02007]: invalid object declaration
┌─ tests/sui_mode/move_2024/typing/enum_in_struct_position.move:11:13
11 │ public enum Obj has key, store {
│ ^^^ --- Enums cannot have the 'key' ability.
│ │
│ Invalid object 'Obj'

error[Sui E02002]: invalid 'entry' function signature
┌─ tests/sui_mode/move_2024/typing/enum_in_struct_position.move:18:1
3 │ public enum E {
│ - To satisfy the constraint, the 'drop' ability would need to be added here
·
18 │ entry fun ret(): E {
│ ^^^^^ - The type 'a::m::E' does not have the ability 'drop'
│ │
│ Invalid return type for entry function 'ret'

error[Sui E02002]: invalid 'entry' function signature
┌─ tests/sui_mode/move_2024/typing/enum_in_struct_position.move:22:14
22 │ entry fun x3(_: E) {
│ ----- ^ - 'entry' parameters must be primitives (by-value), vectors of primitives, objects (by-reference or by-value), vectors of objects, or 'Receiving' arguments (by-reference or by-value)
│ │ │
│ │ Invalid 'entry' parameter type for parameter '_'
│ 'x3' was declared 'entry' here

error[Sui E02009]: invalid private transfer call
┌─ tests/sui_mode/move_2024/typing/enum_in_struct_position.move:30:5
11 │ public enum Obj has key, store {
│ ----- The object has 'store' so 'sui::transfer::public_transfer' can be called instead
·
29 │ public fun transfer(o: a::m::Obj) {
│ --------- The type 'a::m::Obj' is not declared in the current module
30 │ transfer::transfer(o, @0)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^ Invalid private transfer. The function 'sui::transfer::transfer' is restricted to being called in the object's module, 'a::m'

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module a::m {

public enum E {
V()
}

public enum M has drop {
V()
}

public enum Obj has key, store {
V()
}

fun init(_: M, _: &mut TxContext) {
}

entry fun ret(): E {
E::V()
}

entry fun x3(_: E) {
abort 0
}

}

module a::n {
public fun transfer(o: a::m::Obj) {
transfer::transfer(o, @0)
}
}

module sui::transfer {
public fun transfer<T: key>(_: T, _: address) {
abort 0
}
}

module sui::tx_context{
public struct TxContext has drop {}
}
Loading