diff --git a/crates/sui/src/lib.rs b/crates/sui/src/lib.rs index 8fdafa059819f8..0276489729a95a 100644 --- a/crates/sui/src/lib.rs +++ b/crates/sui/src/lib.rs @@ -15,6 +15,7 @@ pub mod key_identity; pub mod keytool; pub mod shell; pub mod sui_commands; +pub mod upgrade_compatibility; pub mod validator_commands; mod verifier_meter; pub mod zklogin_commands_util; diff --git a/crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__empty.snap b/crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__empty.snap index 8c22e0c68759f9..3fcbbedc9638fa 100644 --- a/crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__empty.snap +++ b/crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__empty.snap @@ -3,7 +3,7 @@ source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs expression: output --- error[Compatibility E01007]: module missing - ┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/malformed_move_toml/empty/Move.toml:1:1 + ┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/missing_module_toml/empty/Move.toml:1:1 │ 1 │ │ ^ Package is missing module 'identifier' diff --git a/crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__whitespace.snap b/crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__whitespace.snap index e9a57c6f360ea9..b76c5aa7047b65 100644 --- a/crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__whitespace.snap +++ b/crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__whitespace.snap @@ -3,10 +3,11 @@ source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs expression: output --- error[Compatibility E01007]: module missing - ┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/malformed_move_toml/whitespace/Move.toml:1:1 - │ -1 │ - │ ^ Package is missing module 'identifier' - │ + ┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/missing_module_toml/whitespace/Move.toml:1:1 + │ +1 │ ╭ +2 │ │ + │ ╰──^ Package is missing module 'identifier' + │ = Modules which are part package cannot be removed during an upgrade. = add missing module 'identifier' back to the package. diff --git a/crates/sui/src/unit_tests/upgrade_compatibility_tests.rs b/crates/sui/src/unit_tests/upgrade_compatibility_tests.rs index f88b8823fec667..7f0901ff91117c 100644 --- a/crates/sui/src/unit_tests/upgrade_compatibility_tests.rs +++ b/crates/sui/src/unit_tests/upgrade_compatibility_tests.rs @@ -96,10 +96,11 @@ fn test_missing_module_toml() { // since a Move.toml which is empty will not build for malformed_pkg in [ "emoji", - // "whitespace", "addresses_first", "starts_second_line", "package_no_name", + "whitespace", + "empty", ] { let move_pkg_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("src/unit_tests/fixtures/upgrade_errors/missing_module_toml/") @@ -108,7 +109,7 @@ fn test_missing_module_toml() { missing_module_diag(&Identifier::from_str("identifier").unwrap(), &move_pkg_path); let move_toml: Arc = fs::read_to_string(move_pkg_path.join("Move.toml")) - .unwrap() + .unwrap_or_default() .into(); let file_hash = FileHash::new(&move_toml); let mut files = FilesSourceText::new(); @@ -129,20 +130,13 @@ fn test_missing_module_toml() { #[test] fn test_malformed_toml() { - // whitespace example + // no_file example let move_pkg_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("src/unit_tests/fixtures/upgrade_errors/missing_module_toml/whitespace/"); + .join("src/unit_tests/fixtures/upgrade_errors/missing_module_toml/no_file/"); let result = missing_module_diag(&Identifier::from_str("identifier").unwrap(), &move_pkg_path); assert!(result.is_err()); - assert_eq!(result.unwrap_err().to_string(), "Malformed Move.toml"); - - // empty example - let move_pkg_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("src/unit_tests/fixtures/upgrade_errors/missing_module_toml/empty/"); - let result = missing_module_diag(&Identifier::from_str("identifier").unwrap(), &move_pkg_path); - assert!(result.is_err()); - assert_eq!(result.unwrap_err().to_string(), "Malformed Move.toml"); + assert_eq!(result.unwrap_err().to_string(), "Unable to read Move.toml"); } fn get_packages(name: &str) -> (Vec, CompiledPackage, PathBuf) { diff --git a/crates/sui/src/upgrade_compatibility.rs b/crates/sui/src/upgrade_compatibility.rs index 9610c21928dbe2..71f12a249406da 100644 --- a/crates/sui/src/upgrade_compatibility.rs +++ b/crates/sui/src/upgrade_compatibility.rs @@ -821,11 +821,11 @@ fn module_compatibility_error_diag( Ok(diags) } -const PACKAGE_TABLE: &str = "[package]"; fn missing_module_diag( module_name: &Identifier, package_path: &PathBuf, ) -> Result { + const PACKAGE_TABLE: &str = "[package]"; let mut diags = Diagnostics::new(); // read Move.toml to get the hash and first line start and end @@ -833,9 +833,7 @@ fn missing_module_diag( let toml_str = fs::read_to_string(&toml_path).context("Unable to read Move.toml")?; let hash = FileHash::new(&toml_str); - let start: usize = toml_str - .find(PACKAGE_TABLE) - .context("Malformed Move.toml")?; + let start: usize = toml_str.find(PACKAGE_TABLE).unwrap_or_default(); // default to the end of the package table definition let mut end = start + PACKAGE_TABLE.len();