Skip to content

Commit

Permalink
handle additive and deponly upgrades for upgrade errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjennings-mysten committed Jan 7, 2025
1 parent 721c02f commit d2a0931
Show file tree
Hide file tree
Showing 21 changed files with 1,134 additions and 306 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,30 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module upgrades::upgrades {

public struct StructToChange {
new_field: u64 // change to u32
}

public struct StructToRemove {
new_field: u64
}

public enum EnumToChange {
A, // change to B
}

public enum EnumToRemove {
A
}

// no public on functions
fun function_to_change(): u64 { // change to u32 return
0
}

fun function_to_remove(): 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,23 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module upgrades::upgrades {

public struct StructToChange {
new_field: u32 // changed to u32
}

// public struct StructToRemove {}

public enum EnumToChange {
B, // changed to B
}

// public enum EnumToRemove {}

fun function_to_change(): u32 { // changed to u32
0
}

// fun function_to_remove(): u64 {}
}
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,5 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module upgrades::upgrades {
}
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,21 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module upgrades::upgrades {

// created new struct
public struct NewStruct {
new_field: u64
}

// created new enum
public enum NewEnum {
A,
}

// created new function
fun new_function(): u64 {
0
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: normalize_path(err.to_string())
---
error[Compatibility E01008]: missing declaration
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
4module upgrades::upgrades {
^^^^^^^^ enum 'EnumToRemove' is missing
= enums cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= add missing enum 'EnumToRemove' back to the module 'upgrades'.

error[Compatibility E01008]: missing declaration
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
4module upgrades::upgrades {
^^^^^^^^ function 'function_to_remove' is missing
= functions cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= add missing function 'function_to_remove' back to the module 'upgrades'.

error[Compatibility E01008]: missing declaration
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
4 │ module upgrades::upgrades {
^^^^^^^^ struct 'StructToRemove' is missing
= structs cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= add missing struct 'StructToRemove' back to the module 'upgrades'.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:7:9
6public struct StructToChange {
│ -------------- Struct definition
7 │ new_field: u32 // changed to u32
│ ^^^^^^^^^ Mismatched field type 'u32', expected 'u64'.
= Structs cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= Restore the original struct's field for struct 'StructToChange' including the ordering.

error[Compatibility E03001]: function signature mismatch
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:18:31
18 │ fun function_to_change(): u32 { // changed to u32
^^^ Unexpected return type 'u32', expected 'u64'
= Functions cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= Restore the original function's return type for function 'function_to_change'.


Upgrade failed, this package requires changes to be compatible with the existing package. Its upgrade policy is set to 'additive'.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[Compatibility E01001]: missing public declaration
6module upgrades::upgrades {
^^^^^^^^ enum 'EnumToBeRemoved' is missing
= 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 a 'compatible' upgrade.
= add missing enum 'EnumToBeRemoved' back to the module 'upgrades'.

error[Compatibility E01001]: missing public declaration
Expand All @@ -17,7 +17,7 @@ error[Compatibility E01001]: missing public declaration
6module upgrades::upgrades {
^^^^^^^^ struct 'StructToBeRemoved' is missing
= 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 a 'compatible' upgrade.
= add missing struct 'StructToBeRemoved' back to the module 'upgrades'.

error[Compatibility E01003]: ability mismatch
Expand All @@ -26,7 +26,7 @@ error[Compatibility E01003]: ability mismatch
11public struct StructAbilityMismatchAdd has copy {} // added the copy ability where none existed
^^^^^^^^^^^^^^^^^^^^^^^^ Unexpected ability: 'copy'
= Structs are part of a module's public interface and cannot be changed during an upgrade.
= Structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original abilities of struct 'StructAbilityMismatchAdd': none.

error[Compatibility E01003]: ability mismatch
Expand All @@ -35,7 +35,7 @@ error[Compatibility E01003]: ability mismatch
14public struct StructAbilityMismatchRemove {} // removed the copy ability
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing ability: 'copy'
= Structs are part of a module's public interface and cannot be changed during an upgrade.
= Structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original ability of struct 'StructAbilityMismatchRemove': 'copy'.

error[Compatibility E01003]: ability mismatch
Expand All @@ -44,7 +44,7 @@ error[Compatibility E01003]: ability mismatch
17public struct StructAbilityMismatchChange has drop {} // changed from drop to copy
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mismatched abilities: missing 'copy', unexpected 'drop'
= Structs are part of a module's public interface and cannot be changed during an upgrade.
= Structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original ability of struct 'StructAbilityMismatchChange': 'copy'.

error[Compatibility E01005]: type parameter mismatch
Expand All @@ -53,7 +53,7 @@ error[Compatibility E01005]: type parameter mismatch
20public struct StructTypeParamMismatch<T> { a: T } // changed S to T
│ ^^^^^^^^^^^^^^^^^^^^^^^ Incorrect number of type parameters: expected 2, found 1
= Structs are part of a module's public interface and cannot be changed during an upgrade.
= Structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original struct's type parameters for struct 'StructTypeParamMismatch' including the ordering.

error[Compatibility E01002]: type mismatch
Expand All @@ -62,7 +62,7 @@ error[Compatibility E01002]: type mismatch
23public struct StructFieldMismatchAdd {
│ ^^^^^^^^^^^^^^^^^^^^^^ Incorrect number of fields: expected 2, found 3
= Structs are part of a module's public interface and cannot be changed during an upgrade.
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's fields for struct 'StructFieldMismatchAdd' including the ordering.

error[Compatibility E01002]: type mismatch
Expand All @@ -71,7 +71,7 @@ error[Compatibility E01002]: type mismatch
30 │ public struct StructFieldMismatchRemove {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^ Incorrect number of fields: expected 2, found 1
= Structs are part of a module's public interface and cannot be changed during an upgrade.
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's fields for struct 'StructFieldMismatchRemove' including the ordering.

error[Compatibility E01002]: type mismatch
Expand All @@ -83,7 +83,7 @@ error[Compatibility E01002]: type mismatch
38 │ b: u8 // changed b from u64 to u8
│ ^ Mismatched field type 'u8', expected 'u64'.
= Structs are part of a module's public interface and cannot be changed during an upgrade.
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's fields for struct 'StructFieldMismatchChange' including the ordering.

error[Compatibility E01003]: ability mismatch
Expand All @@ -92,7 +92,7 @@ error[Compatibility E01003]: ability mismatch
45 │ public enum EnumAbilityMismatchAdd has copy {
│ ^^^^^^^^^^^^^^^^^^^^^^ Unexpected ability: 'copy'
= Enums are part of a module's public interface and cannot be changed during an upgrade.
= Enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original abilities of the enum: none for enum 'EnumAbilityMismatchAdd'.

error[Compatibility E01003]: ability mismatch
Expand All @@ -101,7 +101,7 @@ error[Compatibility E01003]: ability mismatch
50 │ public enum EnumAbilityMismatchRemove {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^ Missing ability: 'copy'
= Enums are part of a module's public interface and cannot be changed during an upgrade.
= Enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original ability of the enum: 'copy' for enum 'EnumAbilityMismatchRemove'.

error[Compatibility E01003]: ability mismatch
Expand All @@ -110,7 +110,7 @@ error[Compatibility E01003]: ability mismatch
55 │ public enum EnumAbilityMismatchChange has drop {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^ Mismatched abilities: missing 'copy', unexpected 'drop'
= Enums are part of a module's public interface and cannot be changed during an upgrade.
= Enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original ability of the enum: 'copy' for enum 'EnumAbilityMismatchChange'.

error[Compatibility E02001]: variant mismatch
Expand All @@ -122,7 +122,7 @@ error[Compatibility E02001]: variant mismatch
64 │ D // new variant
│ ^ New unexpected variant 'D'.
= Enums are part of a module's public interface and cannot be changed during an upgrade.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumNewVariant' including the ordering.

error[Compatibility E02001]: variant mismatch
Expand All @@ -140,7 +140,7 @@ error[Compatibility E01001]: missing public declaration
74 │ fun function_to_have_public_removed() {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Function 'function_to_have_public_removed' has lost its public visibility
= Functions are part of a module's public interface and cannot be changed during an upgrade.
= Functions are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original function's 'public' visibility for function 'function_to_have_public_removed'.

error[Compatibility E03001]: function signature mismatch
Expand All @@ -149,7 +149,7 @@ error[Compatibility E03001]: function signature mismatch
82 │ public fun function_add_arg(a: u64) {}
│ ^^^^^^^^^^^^^^^^ Expected 0 parameters, found 1
= Functions are part of a module's public interface and cannot be changed during an upgrade.
= Functions are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original function's parameters for function 'function_add_arg', expected 0 parameters.

error[Compatibility E03001]: function signature mismatch
Expand All @@ -158,7 +158,7 @@ error[Compatibility E03001]: function signature mismatch
85 │ public fun function_remove_arg() {}
│ ^^^^^^^^^^^^^^^^^^^ Expected 1 parameter, found 0
= Functions are part of a module's public interface and cannot be changed during an upgrade.
= Functions are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original function's parameter for function 'function_remove_arg', expected 1 parameter.

error[Compatibility E03001]: function signature mismatch
Expand All @@ -167,7 +167,7 @@ error[Compatibility E03001]: function signature mismatch
88 │ public fun function_change_arg(a: u8) {} // now has u8 instead of u64
│ ^ Unexpected parameter 'u8', expected 'u64'
= Functions are part of a module's public interface and cannot be changed during an upgrade.
= Functions are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Restore the original function's parameter for function 'function_change_arg'.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[Compatibility E01001]: missing public declaration
4module upgrades::enum_ {
^^^^^ enum 'EnumToBeRemoved' is missing
= 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 a 'compatible' upgrade.
= add missing enum 'EnumToBeRemoved' back to the module 'enum_'.

error[Compatibility E01001]: missing public declaration
Expand All @@ -17,7 +17,7 @@ error[Compatibility E01001]: missing public declaration
4module upgrades::func_ {
^^^^^ public function 'fun_to_be_removed' is missing
= 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 a 'compatible' upgrade.
= add missing public function 'fun_to_be_removed' back to the module 'func_'.

error[Compatibility E01001]: missing public declaration
Expand All @@ -26,7 +26,7 @@ error[Compatibility E01001]: missing public declaration
7 │ fun fun_to_lose_public(): u64 {
^^^^^^^^^^^^^^^^^^ Function 'fun_to_lose_public' has lost its public visibility
= Functions are part of a module's public interface and cannot be changed during an upgrade.
= Functions are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original function's 'public' visibility for function 'fun_to_lose_public'.

error[Compatibility E01001]: missing public declaration
Expand All @@ -35,7 +35,7 @@ error[Compatibility E01001]: missing public declaration
4 │ module upgrades::struct_ {
^^^^^^^ struct 'StructToBeRemoved' is missing
= 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 a 'compatible' upgrade.
= add missing struct 'StructToBeRemoved' back to the module 'struct_'.

error[Compatibility E01007]: module missing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: normalize_path(err.to_string())
---
error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:18
4module upgrades::upgrades {
^^^^^^^^ New unexpected struct 'NewStruct'.
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct 'NewStruct' including the ordering.

error[Compatibility E02001]: variant mismatch
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:18
4module upgrades::upgrades {
^^^^^^^^ New unexpected enum 'NewEnum'.
= Enums are part of a module's public interface and cannot be changed during an upgrade.
= Restore the original enum 'NewEnum' including the ordering.

error[Compatibility E03001]: function signature mismatch
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:18
4 │ module upgrades::upgrades {
^^^^^^^^ New unexpected function 'new_function'.
= Functions are part of a module's public interface and cannot be changed during an upgrade.
= Restore the original function 'new_function' including the ordering.


Upgrade failed, this package requires changes to be compatible with the existing package. Its upgrade policy is set to 'dependency only'.
Loading

0 comments on commit d2a0931

Please sign in to comment.