Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjennings-mysten committed Dec 10, 2024
1 parent a35cfa0 commit cec243e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
1 change: 1 addition & 0 deletions crates/sui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 6 additions & 12 deletions crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand All @@ -108,7 +109,7 @@ fn test_missing_module_toml() {
missing_module_diag(&Identifier::from_str("identifier").unwrap(), &move_pkg_path);

let move_toml: Arc<str> = 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();
Expand All @@ -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<CompiledModule>, CompiledPackage, PathBuf) {
Expand Down
6 changes: 2 additions & 4 deletions crates/sui/src/upgrade_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,21 +821,19 @@ fn module_compatibility_error_diag(
Ok(diags)
}

const PACKAGE_TABLE: &str = "[package]";
fn missing_module_diag(
module_name: &Identifier,
package_path: &PathBuf,
) -> Result<Diagnostics, Error> {
const PACKAGE_TABLE: &str = "[package]";
let mut diags = Diagnostics::new();

// read Move.toml to get the hash and first line start and end
let toml_path = package_path.join("Move.toml");
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();

Expand Down

0 comments on commit cec243e

Please sign in to comment.