Skip to content

Commit

Permalink
Upgrade Errors for struct enum functions (#20151)
Browse files Browse the repository at this point in the history
## Description 

Add struct, enum and function errors to upgrade errors, leaves out type
params to give it, it's own PR.

## Test plan 

snapshots

---

## Release notes

no effect until enabled

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
jordanjennings-mysten authored Nov 15, 2024
1 parent cfb8268 commit 961cd5c
Show file tree
Hide file tree
Showing 26 changed files with 1,583 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "upgrades"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move

[addresses]
upgrades = "0x0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Module: UpgradeErrors

#[allow(unused_field)]
module upgrades::upgrades {

public enum EnumAddAbility has copy { // add drop
A,
}

public enum EnumRemoveAbility has copy, drop {
A,
}

public enum EnumAddAndRemoveAbility has copy, drop {
A,
}

public enum EnumAddVariant {
A,
// B, to be added
}

public enum EnumRemoveVariant {
A,
B, // to be removed
}

public enum EnumChangeVariant {
A,
B, // to be changed to C
}

public enum EnumChangeAndAddVariant {
A,
B, // to be changed to C
// D, to be added
}

public enum EnumChangeAndRemoveVariant {
A,
B, // to be changed to C
C, // to be removed
}

public enum EnumAddAbilityWithTypes has copy { // add drop
A { a: u8 },
}

public enum EnumRemoveAbilityWithTypes has copy, drop {
A { a: u8 },
}

public enum EnumAddVariantWithTypes {
A { a: u8 },
// B { b: u8 }, to be added
}

public enum EnumRemoveVariantWithTypes {
A { a: u8 },
B { b: u8 }, // to be removed
}

public enum EnumChangeVariantWithTypes {
A { a: u8 },
B { b: u8 }, // to be changed to C
}

public enum EnumChangeAndAddVariantWithTypes {
A { a: u8 },
B { b: u8 }, // to be changed to C
// D { d: u8 }, to be added
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "upgrades"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move

[addresses]
upgrades = "0x0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Module: UpgradeErrors

#[allow(unused_field)]
module upgrades::upgrades {

public enum EnumAddAbility has copy, drop { // add drop
A,
}

public enum EnumRemoveAbility has copy { // drop removed
A,
}

public enum EnumAddAndRemoveAbility has copy, store {
A,
}

public enum EnumAddVariant {
A,
B, // added
}

public enum EnumRemoveVariant {
A,
// B, removed
}

public enum EnumChangeVariant {
A,
C, // changed from B
}

public enum EnumChangeAndAddVariant {
A,
C, // to be changed to C
D // added
}

public enum EnumChangeAndRemoveVariant {
A,
C, // changed to C
// removed C,
}

// with types
public enum EnumAddAbilityWithTypes has copy, drop { // drop added
A { a: u8 },
}

public enum EnumRemoveAbilityWithTypes has copy { // drop removed
A { a: u8 },
}

public enum EnumAddVariantWithTypes {
A { a: u8 },
B { b: u8 }, // added
}

public enum EnumRemoveVariantWithTypes {
A { a: u8 },
// B { b: u8 }, removed
}

public enum EnumChangeVariantWithTypes {
A { a: u8 },
C { b: u8 }, // changed to C
}

public enum EnumChangeAndAddVariantWithTypes {
A { a: u8 },
C { b: u8 }, // to be changed to C
D { d: u8 }, // added
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "upgrades"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move

[addresses]
upgrades = "0x0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Module: UpgradeErrors

#[allow(unused_field)]
module upgrades::upgrades {
public fun func_with_wrong_param(a: u64): u64 {
0
}

public fun func_with_wrong_return(): u64 {
0
}

public fun func_with_wrong_param_and_return(a: u64): u64 {
0
}

public fun func_with_wrong_param_length(a: u64, b: u64): u64 {
0
}

public fun func_with_wrong_return_length(): (u64, u64) {
(0,0)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "upgrades"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move

[addresses]
upgrades = "0x0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Module: UpgradeErrors

#[allow(unused_field)]
module upgrades::upgrades {
// changed argument from u64 to u32
public fun func_with_wrong_param(a: u32): u64 {
0
}

// changed return type from u64 to u32
public fun func_with_wrong_return(): u32 {
0
}

// changed argument from u64 to u32 and return type from u64 to u32
public fun func_with_wrong_param_and_return(a: u32): u32 {
0
}

// removed second argument
public fun func_with_wrong_param_length(a: u64): u64 {
0
}

// changed return type from (u64, u64) to u64
public fun func_with_wrong_return_length(): u64 {
0
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "upgrades"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move

[addresses]
upgrades = "0x0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Module: UpgradeErrors

#[allow(unused_field)]
module upgrades::upgrades {

// ability mismatch
public struct AddExtraAbility {}
public struct RemoveAbility has copy, drop {}
public struct AddAndRemoveAbility has copy, drop {}
public struct RemoveMultipleAbilities has copy, drop, store {}
public struct AddMultipleAbilities {}


// field mismatch
public struct AddField {}
// remove field
public struct RemoveField {
a: u64,
b: u64, // remove this field
}

// change field name
public struct ChangeFieldName {
a: u64,
b: u64, // change this field name to c
}

// change field type
public struct ChangeFieldType {
a: u64,
b: u64, // change this field type to u32
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "upgrades"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move

[addresses]
upgrades = "0x0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Module: UpgradeErrors

#[allow(unused_field)]
module upgrades::upgrades {

// ability mismatch
public struct AddExtraAbility has copy {} // added copy
public struct RemoveAbility has drop {} // removed copy
public struct AddAndRemoveAbility has drop, store {} // remove copy, add store
public struct RemoveMultipleAbilities has drop {} // remove copy, store
public struct AddMultipleAbilities has drop, copy {}

// field mismatch
public struct AddField {
a: u64,
b: u64,
}
// remove field
public struct RemoveField {
a: u64,
// b removed here
}

// change field name
public struct ChangeFieldName {
a: u64,
c: u64, // changed from b to c
}

// change field type
public struct ChangeFieldType {
a: u64,
b: u32, // changed to u32
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: normalize_path(err.to_string())
---
error[Compatibility E01001]: missing public declaration
┌─ /fixtures/upgrade_errors/declarations_missing_v2/sources/enum.move:4:18
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/enum.move:4:18
4module upgrades::enum_ {
^^^^^ enum 'EnumToBeRemoved' is missing
= enum is missing expected enum 'EnumToBeRemoved', but found none
= enums are part of a module's public interface and cannot be removed or changed during an upgrade
= enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= add missing enum 'EnumToBeRemoved' back to the module 'enum_'.

error[Compatibility E01001]: missing public declaration
┌─ /fixtures/upgrade_errors/declarations_missing_v2/sources/func.move:4:18
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/func.move:4:18
4 │ module upgrades::func_ {
│ ^^^^^ public function 'fun_to_be_removed' is missing
= public function is missing expected public function 'fun_to_be_removed', but found none
= public functions are part of a module's public interface and cannot be removed or changed during an upgrade
= public functions are part of a module's public interface and cannot be removed or changed during an upgrade.
= add missing public function 'fun_to_be_removed' back to the module 'func_'.

error[Compatibility E01001]: missing public declaration
┌─ /fixtures/upgrade_errors/declarations_missing_v2/sources/struct.move:4:18
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/struct.move:4:18
4 │ module upgrades::struct_ {
│ ^^^^^^^ struct 'StructToBeRemoved' is missing
= struct is missing expected struct 'StructToBeRemoved', but found none
= structs are part of a module's public interface and cannot be removed or changed during an upgrade
= structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= add missing struct 'StructToBeRemoved' back to the module 'struct_'.


Expand Down
Loading

0 comments on commit 961cd5c

Please sign in to comment.