From 3951b5bbf28fbcc8e7c111104d60f2a6ad70057e Mon Sep 17 00:00:00 2001 From: Michael George Date: Mon, 27 Jan 2025 11:31:01 -0500 Subject: [PATCH 01/10] dump script into snapshots --- crates/sui-move/tests/cli_tests.rs | 7 ++++++- .../snapshots/cli_tests__dummy__dummy.sh.snap | 10 +++++++++ ...tests__new_tests__gitignore_exists.sh.snap | 11 ++++++++++ ...ts__new_tests__gitignore_has_build.sh.snap | 16 ++++++++++++++ ...ests__new_tests__manifest_template.sh.snap | 8 +++++++ .../cli_tests__new_tests__new_files.sh.snap | 14 +++++++++++++ ...i_tests__new_tests__new_then_build.sh.snap | 21 +++++++++++++++++++ ...li_tests__new_tests__new_then_test.sh.snap | 20 ++++++++++++++++++ 8 files changed, 106 insertions(+), 1 deletion(-) diff --git a/crates/sui-move/tests/cli_tests.rs b/crates/sui-move/tests/cli_tests.rs index 990940433dd18..36c22feba7086 100644 --- a/crates/sui-move/tests/cli_tests.rs +++ b/crates/sui-move/tests/cli_tests.rs @@ -33,6 +33,10 @@ fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { fs::copy(srcfile, dstfile)?; } } + // let tempdir = tempfile::tempdir()?; + // let sandbox = tempdir.path(); + // + // fs_extra::dir::copy(srcdir, sandbox, &Default::default())?; // set up command let mut shell = Command::new("bash"); @@ -44,7 +48,8 @@ fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { // run it; snapshot test output let output = shell.output()?; let result = format!( - "success: {:?}\nexit_code: {}\n----- stdout -----\n{}\n----- stderr -----\n{}", + "----- script -----\n{}\n----- results -----\nsuccess: {:?}\nexit_code: {}\n----- stdout -----\n{}\n----- stderr -----\n{}", + fs::read_to_string(path)?, output.status.success(), output.status.code().unwrap_or(!0), String::from_utf8_lossy(&output.stdout), diff --git a/crates/sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap index 15f146522559f..dfc8f97fcf944 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap @@ -2,6 +2,16 @@ source: crates/sui-move/tests/cli_tests.rs description: tests/tests/dummy/dummy.sh --- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# simple test just to make sure the test runner works +echo "dummy test" +cat data/data.txt +sui-move new dummy + +----- results ----- success: true exit_code: 0 ----- stdout ----- diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap index 98273f8ed0c71..d0a678a071c57 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap @@ -2,6 +2,17 @@ source: crates/sui-move/tests/cli_tests.rs description: tests/tests/new_tests/gitignore_exists.sh --- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# check that sui-move new correctly updates existing .gitignore +mkdir example +echo "existing_ignore" > example/.gitignore +sui-move new example +cat example/.gitignore + +----- results ----- success: true exit_code: 0 ----- stdout ----- diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap index 5af9fb5d7b873..3f8d5c65fc0cc 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap @@ -2,6 +2,22 @@ source: crates/sui-move/tests/cli_tests.rs description: tests/tests/new_tests/gitignore_has_build.sh --- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# sui-move new example when `example/.gitignore` already contains build/*; it should be unchanged +mkdir example +echo "ignore1" >> example/.gitignore +echo "build/*" >> example/.gitignore +echo "ignore2" >> example/.gitignore +sui-move new example +cat example/.gitignore +echo +echo ==== files in example/ ==== +ls -A example + +----- results ----- success: true exit_code: 0 ----- stdout ----- diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__manifest_template.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__new_tests__manifest_template.sh.snap index b60ec26122809..abed820fda56b 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__manifest_template.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__new_tests__manifest_template.sh.snap @@ -2,6 +2,14 @@ source: crates/sui-move/tests/cli_tests.rs description: tests/tests/new_tests/manifest_template.sh --- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +sui-move new example +cat example/Move.toml + +----- results ----- success: true exit_code: 0 ----- stdout ----- diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap index 2f8a7212059dd..460477567aba0 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap @@ -2,6 +2,20 @@ source: crates/sui-move/tests/cli_tests.rs description: tests/tests/new_tests/new_files.sh --- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# basic test that sui-move new outputs correct files +sui-move new example +echo ==== files in project ==== +ls -A example +echo ==== files in sources ==== +ls -A example/sources +echo ==== files in tests ===== +ls -A example/tests + +----- results ----- success: true exit_code: 0 ----- stdout ----- diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap index ceff62071690e..44e74da4fa2b3 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap @@ -2,6 +2,27 @@ source: crates/sui-move/tests/cli_tests.rs description: tests/tests/new_tests/new_then_build.sh --- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# tests that sui-move new followed by sui-move build succeeds + +sui-move new example + +# we mangle the generated toml file to replace the framework dependency with a local dependency +FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui-move##g') +cat example/Move.toml \ + | sed 's#\(Sui = .*\)git = "[^"]*", \(.*\)#\1\2#' \ + | sed 's#\(Sui = .*\), rev = "[^"]*"\(.*\)#\1\2#' \ + | sed 's#\(Sui = .*\)subdir = "\([^"]*\)"\(.*\)#\1local = "FRAMEWORK/\2"\3#' \ + | sed "s#\(Sui = .*\)FRAMEWORK\(.*\)#\1$FRAMEWORK_DIR\2#" \ + > Move.toml +mv Move.toml example/Move.toml + +cd example && sui-move build + +----- results ----- success: true exit_code: 0 ----- stdout ----- diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap index 63ed656458958..e245366dad19a 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap @@ -2,6 +2,26 @@ source: crates/sui-move/tests/cli_tests.rs description: tests/tests/new_tests/new_then_test.sh --- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# check that sui-move new followed by sui-move test succeeds +sui-move new example + +# we mangle the generated toml file to replace the framework dependency with a local dependency +FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui-move##g') +cat example/Move.toml \ + | sed 's#\(Sui = .*\)git = "[^"]*", \(.*\)#\1\2#' \ + | sed 's#\(Sui = .*\), rev = "[^"]*"\(.*\)#\1\2#' \ + | sed 's#\(Sui = .*\)subdir = "\([^"]*\)"\(.*\)#\1local = "FRAMEWORK/\2"\3#' \ + | sed "s#\(Sui = .*\)FRAMEWORK\(.*\)#\1$FRAMEWORK_DIR\2#" \ + > Move.toml +mv Move.toml example/Move.toml + +cd example && sui-move test + +----- results ----- success: true exit_code: 0 ----- stdout ----- From 11a7bcecde6dbb8579e2f41f5e02191126701c00 Mon Sep 17 00:00:00 2001 From: Michael George Date: Mon, 27 Jan 2025 16:04:29 -0500 Subject: [PATCH 02/10] changed to use fs_extra::dir::copy --- Cargo.lock | 1 + crates/sui-move/Cargo.toml | 1 + crates/sui-move/tests/cli_tests.rs | 19 +++---------------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe1fdd8579a0f..6f488fe0f7457 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14515,6 +14515,7 @@ dependencies = [ "clap", "colored", "datatest-stable", + "fs_extra", "futures", "insta", "insta-cmd", diff --git a/crates/sui-move/Cargo.toml b/crates/sui-move/Cargo.toml index c4c6c3dc73ef6..0f61899b8aee9 100644 --- a/crates/sui-move/Cargo.toml +++ b/crates/sui-move/Cargo.toml @@ -49,6 +49,7 @@ tempfile.workspace = true walkdir.workspace = true insta-cmd.workspace = true insta.workspace = true +fs_extra.workspace = true move-package.workspace = true diff --git a/crates/sui-move/tests/cli_tests.rs b/crates/sui-move/tests/cli_tests.rs index 36c22feba7086..49d52f6afd0a1 100644 --- a/crates/sui-move/tests/cli_tests.rs +++ b/crates/sui-move/tests/cli_tests.rs @@ -1,11 +1,11 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +use fs_extra::dir::CopyOptions; use insta_cmd::get_cargo_bin; use std::fs; use std::path::Path; use std::process::Command; -use walkdir::WalkDir; // [test_shell_snapshot] is run on every file matching [TEST_PATTERN] in [TEST_DIR]; this runs the // files as shell scripts and compares their output to the snapshots; use `cargo insta test @@ -21,22 +21,9 @@ fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { // copy files into temporary directory let srcdir = path.parent().unwrap(); let tmpdir = tempfile::tempdir()?; - let sandbox = tmpdir.path().join("sandbox"); + let sandbox = tmpdir.path(); - for entry in WalkDir::new(srcdir) { - let entry = entry.unwrap(); - let srcfile = entry.path(); - let dstfile = sandbox.join(srcfile.strip_prefix(srcdir)?); - if srcfile.is_dir() { - fs::create_dir_all(dstfile)?; - } else { - fs::copy(srcfile, dstfile)?; - } - } - // let tempdir = tempfile::tempdir()?; - // let sandbox = tempdir.path(); - // - // fs_extra::dir::copy(srcdir, sandbox, &Default::default())?; + fs_extra::dir::copy(srcdir, sandbox, &CopyOptions::new().content_only(true))?; // set up command let mut shell = Command::new("bash"); From 092045589e7f0d907fc7d811ee003958e049a877 Mon Sep 17 00:00:00 2001 From: Michael George Date: Tue, 28 Jan 2025 11:28:20 -0500 Subject: [PATCH 03/10] moved sui-move cli tests into sui crate --- Cargo.lock | 1 + crates/sui-move/Cargo.toml | 4 -- crates/sui/Cargo.toml | 7 ++- .../cli_tests.rs => sui/tests/shell_tests.rs} | 44 ++++++++++++++----- .../tests/shell_tests}/dummy/data/data.txt | 0 .../tests/shell_tests}/dummy/dummy.sh | 2 +- .../new_tests/gitignore_exists.sh | 4 +- .../new_tests/gitignore_has_build.sh | 4 +- .../new_tests/manifest_template.sh | 2 +- .../tests/shell_tests}/new_tests/new_files.sh | 4 +- .../shell_tests}/new_tests/new_then_build.sh | 8 ++-- .../shell_tests}/new_tests/new_then_test.sh | 8 ++-- ...body_fn.snap => shell_tests__body_fn.snap} | 0 .../shell_tests__dummy__dummy.sh.snap} | 6 +-- ...ests__new_tests__gitignore_exists.sh.snap} | 8 ++-- ...s__new_tests__gitignore_has_build.sh.snap} | 8 ++-- ...sts__new_tests__manifest_template.sh.snap} | 6 +-- ...shell_tests__new_tests__new_files.sh.snap} | 8 ++-- ..._tests__new_tests__new_then_build.sh.snap} | 12 ++--- ...l_tests__new_tests__new_then_test.sh.snap} | 12 ++--- 20 files changed, 86 insertions(+), 62 deletions(-) rename crates/{sui-move/tests/cli_tests.rs => sui/tests/shell_tests.rs} (58%) rename crates/{sui-move/tests/tests => sui/tests/shell_tests}/dummy/data/data.txt (100%) rename crates/{sui-move/tests/tests => sui/tests/shell_tests}/dummy/dummy.sh (89%) rename crates/{sui-move/tests/tests => sui/tests/shell_tests}/new_tests/gitignore_exists.sh (64%) rename crates/{sui-move/tests/tests => sui/tests/shell_tests}/new_tests/gitignore_has_build.sh (78%) rename crates/{sui-move/tests/tests => sui/tests/shell_tests}/new_tests/manifest_template.sh (81%) rename crates/{sui-move/tests/tests => sui/tests/shell_tests}/new_tests/new_files.sh (75%) rename crates/{sui-move/tests/tests => sui/tests/shell_tests}/new_tests/new_then_build.sh (72%) rename crates/{sui-move/tests/tests => sui/tests/shell_tests}/new_tests/new_then_test.sh (72%) rename crates/sui/tests/snapshots/{cli_tests__body_fn.snap => shell_tests__body_fn.snap} (100%) rename crates/{sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap => sui/tests/snapshots/shell_tests__dummy__dummy.sh.snap} (74%) rename crates/{sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap => sui/tests/snapshots/shell_tests__new_tests__gitignore_exists.sh.snap} (61%) rename crates/{sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap => sui/tests/snapshots/shell_tests__new_tests__gitignore_has_build.sh.snap} (72%) rename crates/{sui-move/tests/snapshots/cli_tests__new_tests__manifest_template.sh.snap => sui/tests/snapshots/shell_tests__new_tests__manifest_template.sh.snap} (93%) rename crates/{sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap => sui/tests/snapshots/shell_tests__new_tests__new_files.sh.snap} (74%) rename crates/{sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap => sui/tests/snapshots/shell_tests__new_tests__new_then_build.sh.snap} (70%) rename crates/{sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap => sui/tests/snapshots/shell_tests__new_tests__new_then_test.sh.snap} (73%) diff --git a/Cargo.lock b/Cargo.lock index 6f488fe0f7457..73a5eb413c303 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12742,6 +12742,7 @@ dependencies = [ "im", "inquire", "insta", + "insta-cmd", "jemalloc-ctl", "json_to_table", "miette", diff --git a/crates/sui-move/Cargo.toml b/crates/sui-move/Cargo.toml index 0f61899b8aee9..e3b6e81573777 100644 --- a/crates/sui-move/Cargo.toml +++ b/crates/sui-move/Cargo.toml @@ -62,9 +62,5 @@ sui-simulator.workspace = true [package.metadata.cargo-udeps.ignore] normal = ["jemalloc-ctl"] -[[test]] -name = "cli_tests" -harness = false - [lints] workspace = true diff --git a/crates/sui/Cargo.toml b/crates/sui/Cargo.toml index 08e35e0639baf..0c043560dd70b 100644 --- a/crates/sui/Cargo.toml +++ b/crates/sui/Cargo.toml @@ -26,7 +26,6 @@ futures.workspace = true http.workspace = true im.workspace = true inquire.workspace = true -insta.workspace = true json_to_table.workspace = true miette.workspace = true num-bigint.workspace = true @@ -110,6 +109,8 @@ fs_extra.workspace = true expect-test.workspace = true assert_cmd.workspace = true toml.workspace = true +insta.workspace = true +insta-cmd.workspace = true test-cluster.workspace = true sui-macros.workspace = true @@ -132,6 +133,10 @@ test = false name = "ptb_files_tests" harness = false +[[test]] +name = "shell_tests" +harness = false + [features] tracing = [ "sui-types/tracing", diff --git a/crates/sui-move/tests/cli_tests.rs b/crates/sui/tests/shell_tests.rs similarity index 58% rename from crates/sui-move/tests/cli_tests.rs rename to crates/sui/tests/shell_tests.rs index 49d52f6afd0a1..10421c4b3b43f 100644 --- a/crates/sui-move/tests/cli_tests.rs +++ b/crates/sui/tests/shell_tests.rs @@ -6,18 +6,26 @@ use insta_cmd::get_cargo_bin; use std::fs; use std::path::Path; use std::process::Command; +use sui_config::SUI_CLIENT_CONFIG; +use test_cluster::{TestCluster, TestClusterBuilder}; -// [test_shell_snapshot] is run on every file matching [TEST_PATTERN] in [TEST_DIR]; this runs the -// files as shell scripts and compares their output to the snapshots; use `cargo insta test -// --review` to update the snapshots. +// [test_shell_snapshot] is run on every file matching [TEST_PATTERN] in [TEST_DIR], and +// [test_shell_snapshot_with_net] is run on every file matching [TEST_PATTERN] in [TEST_NET_DIR]. +// +// These run the files as shell scripts and compares their output to the snapshots; use `cargo +// insta test --review` to update the snapshots. -const TEST_DIR: &str = "tests/tests"; -const TEST_PATTERN: &str = r"^test.*\.sh$"; +const TEST_DIR: &str = "tests/shell_tests"; +const TEST_NET_DIR: &str = "tests/shell_tests_net"; +const TEST_PATTERN: &str = r"\.sh$"; /// run the bash script at [path], comparing its output to the insta snapshot of the same name. /// The script is run in a temporary working directory that contains a copy of the parent directory -/// of [path], with the `sui-move` binary on the path. -fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { +/// of [path], with the `sui` binary on the path. +/// +/// If [cluster] is provided, the config file for the cluster is passed as the `CONFIG` environment +/// variable. +fn run_shell(path: &Path, cluster: Option) -> datatest_stable::Result<()> { // copy files into temporary directory let srcdir = path.parent().unwrap(); let tmpdir = tempfile::tempdir()?; @@ -28,10 +36,14 @@ fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { // set up command let mut shell = Command::new("bash"); shell - .env("PATH", format!("/bin:/usr/bin:{}", get_sui_move_path())) + .env("PATH", format!("/bin:/usr/bin:{}", get_sui_bin_path())) .current_dir(sandbox) .arg(path.file_name().unwrap()); + if let Some(test) = cluster { + shell.env("CONFIG", test.swarm.dir().join(SUI_CLIENT_CONFIG)); + } + // run it; snapshot test output let output = shell.output()?; let result = format!( @@ -44,7 +56,7 @@ fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { ); let snapshot_name: String = path - .strip_prefix("tests/tests")? + .strip_prefix("tests/shell_tests")? .to_string_lossy() .to_string(); @@ -55,8 +67,9 @@ fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { Ok(()) } -fn get_sui_move_path() -> String { - get_cargo_bin("sui-move") +/// return the path to the `sui` binary that is currently under test +fn get_sui_bin_path() -> String { + get_cargo_bin("sui") .parent() .unwrap() .to_str() @@ -64,6 +77,15 @@ fn get_sui_move_path() -> String { .to_owned() } +fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { + run_shell(path, None) +} + +#[tokio::main] +async fn test_shell_snapshot_with_net(path: &Path) -> datatest_stable::Result<()> { + run_shell(path, Some(TestClusterBuilder::new().build().await)) +} + #[cfg(not(msim))] datatest_stable::harness!(test_shell_snapshot, TEST_DIR, TEST_PATTERN); diff --git a/crates/sui-move/tests/tests/dummy/data/data.txt b/crates/sui/tests/shell_tests/dummy/data/data.txt similarity index 100% rename from crates/sui-move/tests/tests/dummy/data/data.txt rename to crates/sui/tests/shell_tests/dummy/data/data.txt diff --git a/crates/sui-move/tests/tests/dummy/dummy.sh b/crates/sui/tests/shell_tests/dummy/dummy.sh similarity index 89% rename from crates/sui-move/tests/tests/dummy/dummy.sh rename to crates/sui/tests/shell_tests/dummy/dummy.sh index 55dc94f21fbc1..c6359b0c9bc45 100644 --- a/crates/sui-move/tests/tests/dummy/dummy.sh +++ b/crates/sui/tests/shell_tests/dummy/dummy.sh @@ -4,4 +4,4 @@ # simple test just to make sure the test runner works echo "dummy test" cat data/data.txt -sui-move new dummy +sui move new dummy diff --git a/crates/sui-move/tests/tests/new_tests/gitignore_exists.sh b/crates/sui/tests/shell_tests/new_tests/gitignore_exists.sh similarity index 64% rename from crates/sui-move/tests/tests/new_tests/gitignore_exists.sh rename to crates/sui/tests/shell_tests/new_tests/gitignore_exists.sh index 90bc5f8cf9d7b..1777a7051a217 100644 --- a/crates/sui-move/tests/tests/new_tests/gitignore_exists.sh +++ b/crates/sui/tests/shell_tests/new_tests/gitignore_exists.sh @@ -1,8 +1,8 @@ # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# check that sui-move new correctly updates existing .gitignore +# check that sui move new correctly updates existing .gitignore mkdir example echo "existing_ignore" > example/.gitignore -sui-move new example +sui move new example cat example/.gitignore diff --git a/crates/sui-move/tests/tests/new_tests/gitignore_has_build.sh b/crates/sui/tests/shell_tests/new_tests/gitignore_has_build.sh similarity index 78% rename from crates/sui-move/tests/tests/new_tests/gitignore_has_build.sh rename to crates/sui/tests/shell_tests/new_tests/gitignore_has_build.sh index 4ef0230b0fee6..a00401b70ad1b 100644 --- a/crates/sui-move/tests/tests/new_tests/gitignore_has_build.sh +++ b/crates/sui/tests/shell_tests/new_tests/gitignore_has_build.sh @@ -1,12 +1,12 @@ # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# sui-move new example when `example/.gitignore` already contains build/*; it should be unchanged +# sui move new example when `example/.gitignore` already contains build/*; it should be unchanged mkdir example echo "ignore1" >> example/.gitignore echo "build/*" >> example/.gitignore echo "ignore2" >> example/.gitignore -sui-move new example +sui move new example cat example/.gitignore echo echo ==== files in example/ ==== diff --git a/crates/sui-move/tests/tests/new_tests/manifest_template.sh b/crates/sui/tests/shell_tests/new_tests/manifest_template.sh similarity index 81% rename from crates/sui-move/tests/tests/new_tests/manifest_template.sh rename to crates/sui/tests/shell_tests/new_tests/manifest_template.sh index e8544500ab64b..d3613ca78f5d5 100644 --- a/crates/sui-move/tests/tests/new_tests/manifest_template.sh +++ b/crates/sui/tests/shell_tests/new_tests/manifest_template.sh @@ -1,5 +1,5 @@ # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -sui-move new example +sui move new example cat example/Move.toml diff --git a/crates/sui-move/tests/tests/new_tests/new_files.sh b/crates/sui/tests/shell_tests/new_tests/new_files.sh similarity index 75% rename from crates/sui-move/tests/tests/new_tests/new_files.sh rename to crates/sui/tests/shell_tests/new_tests/new_files.sh index 3f36222121448..4dcd4e4762c7a 100644 --- a/crates/sui-move/tests/tests/new_tests/new_files.sh +++ b/crates/sui/tests/shell_tests/new_tests/new_files.sh @@ -1,8 +1,8 @@ # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# basic test that sui-move new outputs correct files -sui-move new example +# basic test that sui move new outputs correct files +sui move new example echo ==== files in project ==== ls -A example echo ==== files in sources ==== diff --git a/crates/sui-move/tests/tests/new_tests/new_then_build.sh b/crates/sui/tests/shell_tests/new_tests/new_then_build.sh similarity index 72% rename from crates/sui-move/tests/tests/new_tests/new_then_build.sh rename to crates/sui/tests/shell_tests/new_tests/new_then_build.sh index 13b2df54a9caf..26ef628b91151 100644 --- a/crates/sui-move/tests/tests/new_tests/new_then_build.sh +++ b/crates/sui/tests/shell_tests/new_tests/new_then_build.sh @@ -1,12 +1,12 @@ # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# tests that sui-move new followed by sui-move build succeeds +# tests that sui move new followed by sui move build succeeds -sui-move new example +sui move new example # we mangle the generated toml file to replace the framework dependency with a local dependency -FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui-move##g') +FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui##g') cat example/Move.toml \ | sed 's#\(Sui = .*\)git = "[^"]*", \(.*\)#\1\2#' \ | sed 's#\(Sui = .*\), rev = "[^"]*"\(.*\)#\1\2#' \ @@ -15,4 +15,4 @@ cat example/Move.toml \ > Move.toml mv Move.toml example/Move.toml -cd example && sui-move build +cd example && sui move build diff --git a/crates/sui-move/tests/tests/new_tests/new_then_test.sh b/crates/sui/tests/shell_tests/new_tests/new_then_test.sh similarity index 72% rename from crates/sui-move/tests/tests/new_tests/new_then_test.sh rename to crates/sui/tests/shell_tests/new_tests/new_then_test.sh index d6ba83403a7b4..051d2945589a5 100644 --- a/crates/sui-move/tests/tests/new_tests/new_then_test.sh +++ b/crates/sui/tests/shell_tests/new_tests/new_then_test.sh @@ -1,11 +1,11 @@ # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# check that sui-move new followed by sui-move test succeeds -sui-move new example +# check that sui move new followed by sui move test succeeds +sui move new example # we mangle the generated toml file to replace the framework dependency with a local dependency -FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui-move##g') +FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui##g') cat example/Move.toml \ | sed 's#\(Sui = .*\)git = "[^"]*", \(.*\)#\1\2#' \ | sed 's#\(Sui = .*\), rev = "[^"]*"\(.*\)#\1\2#' \ @@ -14,4 +14,4 @@ cat example/Move.toml \ > Move.toml mv Move.toml example/Move.toml -cd example && sui-move test +cd example && sui move test diff --git a/crates/sui/tests/snapshots/cli_tests__body_fn.snap b/crates/sui/tests/snapshots/shell_tests__body_fn.snap similarity index 100% rename from crates/sui/tests/snapshots/cli_tests__body_fn.snap rename to crates/sui/tests/snapshots/shell_tests__body_fn.snap diff --git a/crates/sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap b/crates/sui/tests/snapshots/shell_tests__dummy__dummy.sh.snap similarity index 74% rename from crates/sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap rename to crates/sui/tests/snapshots/shell_tests__dummy__dummy.sh.snap index dfc8f97fcf944..3efc740d07d5c 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__dummy__dummy.sh.snap @@ -1,6 +1,6 @@ --- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/dummy/dummy.sh +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/dummy/dummy.sh --- ----- script ----- # Copyright (c) Mysten Labs, Inc. @@ -9,7 +9,7 @@ description: tests/tests/dummy/dummy.sh # simple test just to make sure the test runner works echo "dummy test" cat data/data.txt -sui-move new dummy +sui move new dummy ----- results ----- success: true diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_exists.sh.snap similarity index 61% rename from crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap rename to crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_exists.sh.snap index d0a678a071c57..8cef1cdd2fbca 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_exists.sh.snap @@ -1,15 +1,15 @@ --- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/gitignore_exists.sh +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/new_tests/gitignore_exists.sh --- ----- script ----- # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# check that sui-move new correctly updates existing .gitignore +# check that sui move new correctly updates existing .gitignore mkdir example echo "existing_ignore" > example/.gitignore -sui-move new example +sui move new example cat example/.gitignore ----- results ----- diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_has_build.sh.snap similarity index 72% rename from crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap rename to crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_has_build.sh.snap index 3f8d5c65fc0cc..798662ea1855d 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_has_build.sh.snap @@ -1,17 +1,17 @@ --- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/gitignore_has_build.sh +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/new_tests/gitignore_has_build.sh --- ----- script ----- # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# sui-move new example when `example/.gitignore` already contains build/*; it should be unchanged +# sui move new example when `example/.gitignore` already contains build/*; it should be unchanged mkdir example echo "ignore1" >> example/.gitignore echo "build/*" >> example/.gitignore echo "ignore2" >> example/.gitignore -sui-move new example +sui move new example cat example/.gitignore echo echo ==== files in example/ ==== diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__manifest_template.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__manifest_template.sh.snap similarity index 93% rename from crates/sui-move/tests/snapshots/cli_tests__new_tests__manifest_template.sh.snap rename to crates/sui/tests/snapshots/shell_tests__new_tests__manifest_template.sh.snap index abed820fda56b..64f1a3cae2ce4 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__manifest_template.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__manifest_template.sh.snap @@ -1,12 +1,12 @@ --- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/manifest_template.sh +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/new_tests/manifest_template.sh --- ----- script ----- # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -sui-move new example +sui move new example cat example/Move.toml ----- results ----- diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__new_files.sh.snap similarity index 74% rename from crates/sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap rename to crates/sui/tests/snapshots/shell_tests__new_tests__new_files.sh.snap index 460477567aba0..147b4a0d89e5b 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__new_files.sh.snap @@ -1,13 +1,13 @@ --- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/new_files.sh +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/new_tests/new_files.sh --- ----- script ----- # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# basic test that sui-move new outputs correct files -sui-move new example +# basic test that sui move new outputs correct files +sui move new example echo ==== files in project ==== ls -A example echo ==== files in sources ==== diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_build.sh.snap similarity index 70% rename from crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap rename to crates/sui/tests/snapshots/shell_tests__new_tests__new_then_build.sh.snap index 44e74da4fa2b3..06501ff6f3e5a 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_build.sh.snap @@ -1,17 +1,17 @@ --- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/new_then_build.sh +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/new_tests/new_then_build.sh --- ----- script ----- # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# tests that sui-move new followed by sui-move build succeeds +# tests that sui move new followed by sui move build succeeds -sui-move new example +sui move new example # we mangle the generated toml file to replace the framework dependency with a local dependency -FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui-move##g') +FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui##g') cat example/Move.toml \ | sed 's#\(Sui = .*\)git = "[^"]*", \(.*\)#\1\2#' \ | sed 's#\(Sui = .*\), rev = "[^"]*"\(.*\)#\1\2#' \ @@ -20,7 +20,7 @@ cat example/Move.toml \ > Move.toml mv Move.toml example/Move.toml -cd example && sui-move build +cd example && sui move build ----- results ----- success: true diff --git a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_test.sh.snap similarity index 73% rename from crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap rename to crates/sui/tests/snapshots/shell_tests__new_tests__new_then_test.sh.snap index e245366dad19a..e70031835eb4f 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_test.sh.snap @@ -1,16 +1,16 @@ --- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/new_then_test.sh +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/new_tests/new_then_test.sh --- ----- script ----- # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# check that sui-move new followed by sui-move test succeeds -sui-move new example +# check that sui move new followed by sui move test succeeds +sui move new example # we mangle the generated toml file to replace the framework dependency with a local dependency -FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui-move##g') +FRAMEWORK_DIR=$(echo $CARGO_MANIFEST_DIR | sed 's#/crates/sui##g') cat example/Move.toml \ | sed 's#\(Sui = .*\)git = "[^"]*", \(.*\)#\1\2#' \ | sed 's#\(Sui = .*\), rev = "[^"]*"\(.*\)#\1\2#' \ @@ -19,7 +19,7 @@ cat example/Move.toml \ > Move.toml mv Move.toml example/Move.toml -cd example && sui-move test +cd example && sui move test ----- results ----- success: true From 368369f5ce24d64b4e001b6d38da61d30f917d4c Mon Sep 17 00:00:00 2001 From: Michael George Date: Tue, 28 Jan 2025 11:29:56 -0500 Subject: [PATCH 04/10] fixed an accidentally moved file --- .../{shell_tests__body_fn.snap => cli_tests__body_fn.snap} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename crates/sui/tests/snapshots/{shell_tests__body_fn.snap => cli_tests__body_fn.snap} (100%) diff --git a/crates/sui/tests/snapshots/shell_tests__body_fn.snap b/crates/sui/tests/snapshots/cli_tests__body_fn.snap similarity index 100% rename from crates/sui/tests/snapshots/shell_tests__body_fn.snap rename to crates/sui/tests/snapshots/cli_tests__body_fn.snap From b210ad4ea9a5b6ea7097415e3e6c35b7e8dc227c Mon Sep 17 00:00:00 2001 From: Michael George Date: Tue, 28 Jan 2025 12:24:29 -0500 Subject: [PATCH 05/10] added network test facility --- crates/sui/tests/shell_tests.rs | 33 +++++++++---------- .../tests/shell_tests/with_network/dummy.sh | 5 +++ .../shell_tests__with_network__dummy.sh.snap | 22 +++++++++++++ 3 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 crates/sui/tests/shell_tests/with_network/dummy.sh create mode 100644 crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap diff --git a/crates/sui/tests/shell_tests.rs b/crates/sui/tests/shell_tests.rs index 10421c4b3b43f..4697e7e6b73b4 100644 --- a/crates/sui/tests/shell_tests.rs +++ b/crates/sui/tests/shell_tests.rs @@ -3,20 +3,20 @@ use fs_extra::dir::CopyOptions; use insta_cmd::get_cargo_bin; -use std::fs; use std::path::Path; use std::process::Command; +use std::{fs, thread}; use sui_config::SUI_CLIENT_CONFIG; -use test_cluster::{TestCluster, TestClusterBuilder}; +use test_cluster::TestClusterBuilder; -// [test_shell_snapshot] is run on every file matching [TEST_PATTERN] in [TEST_DIR], and -// [test_shell_snapshot_with_net] is run on every file matching [TEST_PATTERN] in [TEST_NET_DIR]. +// [test_shell_snapshot] is run on every file matching [TEST_PATTERN] in [TEST_DIR]. +// Files in [TEST_NET_DIR] will be run with a [TestCluster] configured. // // These run the files as shell scripts and compares their output to the snapshots; use `cargo // insta test --review` to update the snapshots. const TEST_DIR: &str = "tests/shell_tests"; -const TEST_NET_DIR: &str = "tests/shell_tests_net"; +const TEST_NET_DIR: &str = "tests/shell_tests/with_network"; const TEST_PATTERN: &str = r"\.sh$"; /// run the bash script at [path], comparing its output to the insta snapshot of the same name. @@ -25,7 +25,15 @@ const TEST_PATTERN: &str = r"\.sh$"; /// /// If [cluster] is provided, the config file for the cluster is passed as the `CONFIG` environment /// variable. -fn run_shell(path: &Path, cluster: Option) -> datatest_stable::Result<()> { +#[tokio::main] +async fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { + // set up test cluster + let cluster = if path.starts_with(TEST_NET_DIR) { + Some(TestClusterBuilder::new().build().await) + } else { + None + }; + // copy files into temporary directory let srcdir = path.parent().unwrap(); let tmpdir = tempfile::tempdir()?; @@ -40,8 +48,8 @@ fn run_shell(path: &Path, cluster: Option) -> datatest_stable::Resu .current_dir(sandbox) .arg(path.file_name().unwrap()); - if let Some(test) = cluster { - shell.env("CONFIG", test.swarm.dir().join(SUI_CLIENT_CONFIG)); + if let Some(ref cluster) = cluster { + shell.env("CONFIG", cluster.swarm.dir().join(SUI_CLIENT_CONFIG)); } // run it; snapshot test output @@ -77,15 +85,6 @@ fn get_sui_bin_path() -> String { .to_owned() } -fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { - run_shell(path, None) -} - -#[tokio::main] -async fn test_shell_snapshot_with_net(path: &Path) -> datatest_stable::Result<()> { - run_shell(path, Some(TestClusterBuilder::new().build().await)) -} - #[cfg(not(msim))] datatest_stable::harness!(test_shell_snapshot, TEST_DIR, TEST_PATTERN); diff --git a/crates/sui/tests/shell_tests/with_network/dummy.sh b/crates/sui/tests/shell_tests/with_network/dummy.sh new file mode 100644 index 0000000000000..5d85b20c8e367 --- /dev/null +++ b/crates/sui/tests/shell_tests/with_network/dummy.sh @@ -0,0 +1,5 @@ +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# simple test just to make sure the test runner works with the network +sui client --client.config $CONFIG envs diff --git a/crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap b/crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap new file mode 100644 index 0000000000000..aa17783c07945 --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap @@ -0,0 +1,22 @@ +--- +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/with_network/dummy.sh +--- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# simple test just to make sure the test runner works with the network +sui client --client.config $CONFIG envs + +----- results ----- +success: true +exit_code: 0 +----- stdout ----- +╭──────────┬────────────────────────┬────────╮ +│ alias │ url │ active │ +├──────────┼────────────────────────┼────────┤ +│ localnet │ http://127.0.0.1:53065 │ * │ +╰──────────┴────────────────────────┴────────╯ + +----- stderr ----- From c6ca5478de4140b17692c31f84ac0c5fd382630a Mon Sep 17 00:00:00 2001 From: Michael George Date: Tue, 28 Jan 2025 16:16:30 -0500 Subject: [PATCH 06/10] migrated a test to shell script framework --- crates/sui/tests/cli_tests.rs | 37 ------------------- crates/sui/tests/shell_tests.rs | 7 +++- .../with_network/regression_6546.sh | 12 ++++++ ...sts__with_network__regression_6546.sh.snap | 27 ++++++++++++++ 4 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 crates/sui/tests/shell_tests/with_network/regression_6546.sh create mode 100644 crates/sui/tests/snapshots/shell_tests__with_network__regression_6546.sh.snap diff --git a/crates/sui/tests/cli_tests.rs b/crates/sui/tests/cli_tests.rs index aa60fc2305b45..b5f34179634c2 100644 --- a/crates/sui/tests/cli_tests.rs +++ b/crates/sui/tests/cli_tests.rs @@ -355,43 +355,6 @@ async fn test_ptb_publish() -> Result<(), anyhow::Error> { Ok(()) } -// fixing issue https://github.com/MystenLabs/sui/issues/6546 -#[tokio::test] -async fn test_regression_6546() -> Result<(), anyhow::Error> { - let mut test_cluster = TestClusterBuilder::new().build().await; - let address = test_cluster.get_address_0(); - let context = &mut test_cluster.wallet; - - let SuiClientCommandResult::Objects(coins) = SuiClientCommands::Objects { - address: Some(KeyIdentity::Address(address)), - } - .execute(context) - .await? - else { - panic!() - }; - let config_path = test_cluster.swarm.dir().join(SUI_CLIENT_CONFIG); - - test_with_sui_binary(&[ - "client", - "--client.config", - config_path.to_str().unwrap(), - "call", - "--package", - "0x2", - "--module", - "sui", - "--function", - "transfer", - "--args", - &coins.first().unwrap().object()?.object_id.to_string(), - &test_cluster.get_address_1().to_string(), - "--gas-budget", - "100000000", - ]) - .await -} - #[sim_test] async fn test_custom_genesis() -> Result<(), anyhow::Error> { // Create and save genesis config file diff --git a/crates/sui/tests/shell_tests.rs b/crates/sui/tests/shell_tests.rs index 4697e7e6b73b4..c899913138294 100644 --- a/crates/sui/tests/shell_tests.rs +++ b/crates/sui/tests/shell_tests.rs @@ -3,9 +3,9 @@ use fs_extra::dir::CopyOptions; use insta_cmd::get_cargo_bin; +use std::fs; use std::path::Path; use std::process::Command; -use std::{fs, thread}; use sui_config::SUI_CLIENT_CONFIG; use test_cluster::TestClusterBuilder; @@ -44,7 +44,10 @@ async fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { // set up command let mut shell = Command::new("bash"); shell - .env("PATH", format!("/bin:/usr/bin:{}", get_sui_bin_path())) + .env( + "PATH", + format!("{}:{}", get_sui_bin_path(), std::env::var("PATH")?), + ) .current_dir(sandbox) .arg(path.file_name().unwrap()); diff --git a/crates/sui/tests/shell_tests/with_network/regression_6546.sh b/crates/sui/tests/shell_tests/with_network/regression_6546.sh new file mode 100644 index 0000000000000..392edb20b48a3 --- /dev/null +++ b/crates/sui/tests/shell_tests/with_network/regression_6546.sh @@ -0,0 +1,12 @@ +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# fixing issue https://github.com/MystenLabs/sui/issues/6546 + +COIN=$(sui client --client.config $CONFIG objects --json | jq '.[0].data.objectId') +ADDR=$(sui client --client.config $CONFIG addresses --json | jq '.addresses[0][1]') + +sui client --client.config $CONFIG \ + call --package 0x2 --module sui --function transfer --args $COIN $ADDR \ + --gas-budget 100000000 \ + --json | jq '.effects.status' diff --git a/crates/sui/tests/snapshots/shell_tests__with_network__regression_6546.sh.snap b/crates/sui/tests/snapshots/shell_tests__with_network__regression_6546.sh.snap new file mode 100644 index 0000000000000..f31b5968fbee0 --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__with_network__regression_6546.sh.snap @@ -0,0 +1,27 @@ +--- +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/with_network/regression_6546.sh +--- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# fixing issue https://github.com/MystenLabs/sui/issues/6546 + +COIN=$(sui client --client.config $CONFIG objects --json | jq '.[0].data.objectId') +ADDR=$(sui client --client.config $CONFIG addresses --json | jq '.addresses[0][1]') + +sui client --client.config $CONFIG \ + call --package 0x2 --module sui --function transfer --args $COIN $ADDR \ + --gas-budget 100000000 \ + --json | jq '.effects.status' + +----- results ----- +success: true +exit_code: 0 +----- stdout ----- +{ + "status": "success" +} + +----- stderr ----- From 2d5a24d7ffc2b8c271f9390679afa991242a4033 Mon Sep 17 00:00:00 2001 From: Michael George Date: Tue, 28 Jan 2025 16:44:59 -0500 Subject: [PATCH 07/10] migrated another test --- crates/sui/tests/cli_tests.rs | 53 ------------------- .../depends_on_simple/Move.toml | 0 .../sources/depends_on_simple.move | 0 ..._build_bytecode_with_address_resolution.sh | 14 +++++ .../simple/Move.toml | 0 .../simple/sources/simple.move | 0 ...d_bytecode_with_address_resolution.sh.snap | 33 ++++++++++++ 7 files changed, 47 insertions(+), 53 deletions(-) rename crates/sui/tests/{data => shell_tests/with_network/move_build_bytecode_with_address_resolution}/depends_on_simple/Move.toml (100%) rename crates/sui/tests/{data => shell_tests/with_network/move_build_bytecode_with_address_resolution}/depends_on_simple/sources/depends_on_simple.move (100%) create mode 100644 crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh rename crates/sui/tests/{data => shell_tests/with_network/move_build_bytecode_with_address_resolution}/simple/Move.toml (100%) rename crates/sui/tests/{data => shell_tests/with_network/move_build_bytecode_with_address_resolution}/simple/sources/simple.move (100%) create mode 100644 crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap diff --git a/crates/sui/tests/cli_tests.rs b/crates/sui/tests/cli_tests.rs index b5f34179634c2..8a9bd44335f37 100644 --- a/crates/sui/tests/cli_tests.rs +++ b/crates/sui/tests/cli_tests.rs @@ -3907,59 +3907,6 @@ async fn test_clever_errors() -> Result<(), anyhow::Error> { Ok(()) } -#[tokio::test] -async fn test_move_build_bytecode_with_address_resolution() -> Result<(), anyhow::Error> { - let test_cluster = TestClusterBuilder::new().build().await; - let config_path = test_cluster.swarm.dir().join(SUI_CLIENT_CONFIG); - - // Package setup: a simple package depends on another and copied to tmpdir - let mut simple_package_path = PathBuf::from(TEST_DATA_DIR); - simple_package_path.push("simple"); - - let mut depends_on_simple_package_path = PathBuf::from(TEST_DATA_DIR); - depends_on_simple_package_path.push("depends_on_simple"); - - let tmp_dir = tempfile::tempdir().unwrap(); - - fs_extra::dir::copy( - &simple_package_path, - &tmp_dir, - &fs_extra::dir::CopyOptions::default(), - )?; - - fs_extra::dir::copy( - &depends_on_simple_package_path, - &tmp_dir, - &fs_extra::dir::CopyOptions::default(), - )?; - - // Publish simple package. - let simple_tmp_dir = tmp_dir.path().join("simple"); - test_with_sui_binary(&[ - "client", - "--client.config", - config_path.to_str().unwrap(), - "publish", - simple_tmp_dir.to_str().unwrap(), - ]) - .await?; - - // Build the package that depends on 'simple' package. Addresses must resolve successfully - // from the `Move.lock` for this command to succeed at all. - let depends_on_simple_tmp_dir = tmp_dir.path().join("depends_on_simple"); - test_with_sui_binary(&[ - "move", - "--client.config", - config_path.to_str().unwrap(), - "build", - "--dump-bytecode-as-base64", - "--path", - depends_on_simple_tmp_dir.to_str().unwrap(), - ]) - .await?; - Ok(()) -} - #[tokio::test] async fn test_parse_host_port() { let input = "127.0.0.0"; diff --git a/crates/sui/tests/data/depends_on_simple/Move.toml b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/depends_on_simple/Move.toml similarity index 100% rename from crates/sui/tests/data/depends_on_simple/Move.toml rename to crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/depends_on_simple/Move.toml diff --git a/crates/sui/tests/data/depends_on_simple/sources/depends_on_simple.move b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/depends_on_simple/sources/depends_on_simple.move similarity index 100% rename from crates/sui/tests/data/depends_on_simple/sources/depends_on_simple.move rename to crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/depends_on_simple/sources/depends_on_simple.move diff --git a/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh new file mode 100644 index 0000000000000..4ea1cba44bbec --- /dev/null +++ b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh @@ -0,0 +1,14 @@ +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# fixing issue https://github.com/MystenLabs/sui/issues/6546 + +COIN=$(sui client --client.config $CONFIG objects --json | jq '.[0].data.objectId') +ADDR=$(sui client --client.config $CONFIG addresses --json | jq '.addresses[0][1]') + +sui client --client.config $CONFIG \ + publish simple \ + --json | jq '.effects.status' + +sui move --client.config $CONFIG \ + build --path depends_on_simple diff --git a/crates/sui/tests/data/simple/Move.toml b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/simple/Move.toml similarity index 100% rename from crates/sui/tests/data/simple/Move.toml rename to crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/simple/Move.toml diff --git a/crates/sui/tests/data/simple/sources/simple.move b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/simple/sources/simple.move similarity index 100% rename from crates/sui/tests/data/simple/sources/simple.move rename to crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/simple/sources/simple.move diff --git a/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap b/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap new file mode 100644 index 0000000000000..5c98f7e19fdee --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap @@ -0,0 +1,33 @@ +--- +source: crates/sui/tests/shell_tests.rs +description: tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh +--- +----- script ----- +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# fixing issue https://github.com/MystenLabs/sui/issues/6546 + +COIN=$(sui client --client.config $CONFIG objects --json | jq '.[0].data.objectId') +ADDR=$(sui client --client.config $CONFIG addresses --json | jq '.addresses[0][1]') + +sui client --client.config $CONFIG \ + publish simple \ + --json | jq '.effects.status' + +sui move --client.config $CONFIG \ + build --path depends_on_simple + +----- results ----- +success: true +exit_code: 0 +----- stdout ----- +{ + "status": "success" +} + +----- stderr ----- +BUILDING simple +Successfully verified dependencies on-chain against source. +INCLUDING DEPENDENCY simple +BUILDING depends_on_simple From 3f2d63b29acd219edb58c19d7f37397fa29a471e Mon Sep 17 00:00:00 2001 From: Michael George Date: Tue, 28 Jan 2025 16:47:58 -0500 Subject: [PATCH 08/10] removed some copy-pasta --- .../move_build_bytecode_with_address_resolution.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh index 4ea1cba44bbec..5d500554a4fc3 100644 --- a/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh +++ b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh @@ -3,9 +3,6 @@ # fixing issue https://github.com/MystenLabs/sui/issues/6546 -COIN=$(sui client --client.config $CONFIG objects --json | jq '.[0].data.objectId') -ADDR=$(sui client --client.config $CONFIG addresses --json | jq '.addresses[0][1]') - sui client --client.config $CONFIG \ publish simple \ --json | jq '.effects.status' From 1fe60e3b5a22e40f9807827481b030c328e97eb9 Mon Sep 17 00:00:00 2001 From: Michael George Date: Wed, 29 Jan 2025 11:40:41 -0500 Subject: [PATCH 09/10] deterministic tests --- crates/sui/tests/shell_tests/with_network/dummy.sh | 2 +- .../snapshots/shell_tests__with_network__dummy.sh.snap | 8 ++------ ...n__move_build_bytecode_with_address_resolution.sh.snap | 3 --- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/crates/sui/tests/shell_tests/with_network/dummy.sh b/crates/sui/tests/shell_tests/with_network/dummy.sh index 5d85b20c8e367..b7da468061edc 100644 --- a/crates/sui/tests/shell_tests/with_network/dummy.sh +++ b/crates/sui/tests/shell_tests/with_network/dummy.sh @@ -2,4 +2,4 @@ # SPDX-License-Identifier: Apache-2.0 # simple test just to make sure the test runner works with the network -sui client --client.config $CONFIG envs +sui client --client.config $CONFIG objects --json | jq 'length' diff --git a/crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap b/crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap index aa17783c07945..d443b5b10876b 100644 --- a/crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap @@ -7,16 +7,12 @@ description: tests/shell_tests/with_network/dummy.sh # SPDX-License-Identifier: Apache-2.0 # simple test just to make sure the test runner works with the network -sui client --client.config $CONFIG envs +sui client --client.config $CONFIG objects --json | jq 'length' ----- results ----- success: true exit_code: 0 ----- stdout ----- -╭──────────┬────────────────────────┬────────╮ -│ alias │ url │ active │ -├──────────┼────────────────────────┼────────┤ -│ localnet │ http://127.0.0.1:53065 │ * │ -╰──────────┴────────────────────────┴────────╯ +5 ----- stderr ----- diff --git a/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap b/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap index 5c98f7e19fdee..e8cc24c5aa7a5 100644 --- a/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap @@ -8,9 +8,6 @@ description: tests/shell_tests/with_network/move_build_bytecode_with_address_res # fixing issue https://github.com/MystenLabs/sui/issues/6546 -COIN=$(sui client --client.config $CONFIG objects --json | jq '.[0].data.objectId') -ADDR=$(sui client --client.config $CONFIG addresses --json | jq '.addresses[0][1]') - sui client --client.config $CONFIG \ publish simple \ --json | jq '.effects.status' From 56b8b5f62fac0b41f255b665c7480d1a10779ff7 Mon Sep 17 00:00:00 2001 From: Michael George Date: Wed, 29 Jan 2025 15:22:36 -0500 Subject: [PATCH 10/10] copy pasta --- .../move_build_bytecode_with_address_resolution.sh | 2 -- ...olution__move_build_bytecode_with_address_resolution.sh.snap | 2 -- 2 files changed, 4 deletions(-) diff --git a/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh index 5d500554a4fc3..71a79d247fa6d 100644 --- a/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh +++ b/crates/sui/tests/shell_tests/with_network/move_build_bytecode_with_address_resolution/move_build_bytecode_with_address_resolution.sh @@ -1,8 +1,6 @@ # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# fixing issue https://github.com/MystenLabs/sui/issues/6546 - sui client --client.config $CONFIG \ publish simple \ --json | jq '.effects.status' diff --git a/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap b/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap index e8cc24c5aa7a5..d3afab6c23ec4 100644 --- a/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap +++ b/crates/sui/tests/snapshots/shell_tests__with_network__move_build_bytecode_with_address_resolution__move_build_bytecode_with_address_resolution.sh.snap @@ -6,8 +6,6 @@ description: tests/shell_tests/with_network/move_build_bytecode_with_address_res # Copyright (c) Mysten Labs, Inc. # SPDX-License-Identifier: Apache-2.0 -# fixing issue https://github.com/MystenLabs/sui/issues/6546 - sui client --client.config $CONFIG \ publish simple \ --json | jq '.effects.status'