Skip to content

Commit

Permalink
add index table lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjennings-mysten committed Oct 22, 2024
1 parent 5cc439e commit 401334e
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 182 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,29 @@
// 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,30 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Module: UpgradeErrors

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

public fun func_with_wrong_return(): u32 {
0
}

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

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

public fun func_with_wrong_return_length(): u64 {
0
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: err.to_string()
---
Upgrade compatibility check failed:
error: Function signature mismatch
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/function_signature_v2/sources/UpgradeErrors.move:9:38
9public fun func_with_wrong_param(a: u32): u64 {
^ Function 'func_with_wrong_param' unexpected parameter u32 at position 0, expected u64
= Functions are part of a module's public interface and cannot be changed during an upgrade, restore the original function's parameters for function 'func_with_wrong_param'.

error: Function signature mismatch
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/function_signature_v2/sources/UpgradeErrors.move:17:49
17 │ public fun func_with_wrong_param_and_return(a: u32): u32 {
^ Function 'func_with_wrong_param_and_return' unexpected parameter u32 at position 0, expected u64
= Functions are part of a module's public interface and cannot be changed during an upgrade, restore the original function's parameters for function 'func_with_wrong_param_and_return'.

error: Function signature mismatch
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/function_signature_v2/sources/UpgradeErrors.move:17:58
17 │ public fun func_with_wrong_param_and_return(a: u32): u32 {
^^^ Module 'upgrades' function 'func_with_wrong_param_and_return' has an unexpected return type u32, expected u64
= Functions are part of a module's public interface and cannot be changed during an upgrade, restore the original function's return types for function 'func_with_wrong_param_and_return'.

error: Function signature mismatch
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/function_signature_v2/sources/UpgradeErrors.move:21:16
21 │ public fun func_with_wrong_param_length(a: u64): u64 {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Function 'func_with_wrong_param_length' expected 2 parameters, have 1
= Functions are part of a module's public interface and cannot be changed during an upgrade, restore the original function's parameters for function 'func_with_wrong_param_length', expected 2 parameters.

error: Function signature mismatch
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/function_signature_v2/sources/UpgradeErrors.move:13:42
13 │ public fun func_with_wrong_return(): u32 {
^^^ Module 'upgrades' function 'func_with_wrong_return' has an unexpected return type u32, expected u64
= Functions are part of a module's public interface and cannot be changed during an upgrade, restore the original function's return types for function 'func_with_wrong_return'.

error: Function signature mismatch
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/function_signature_v2/sources/UpgradeErrors.move:25:16
25 │ public fun func_with_wrong_return_length(): u64 {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Function 'func_with_wrong_return_length' expected to have 2 return type(s), have 1
= Functions are part of a module's public interface and cannot be changed during an upgrade, restore the original function's return types for function 'func_with_wrong_return_length'.


10 changes: 10 additions & 0 deletions crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ fn test_declarations_missing() {
assert_snapshot!(normalize_path(err.to_string()));
}

#[test]
fn test_function_signature() {
let (pkg_v1, pkg_v2) = get_packages("function_signature");
let result = compare_packages(pkg_v1, pkg_v2);

assert!(result.is_err());
let err = result.unwrap_err();
assert_snapshot!(err.to_string());
}

#[test]
fn test_friend_link_ok() {
let (pkg_v1, pkg_v2) = get_packages("friend_linking");
Expand Down
Loading

0 comments on commit 401334e

Please sign in to comment.