diff --git a/Cargo.lock b/Cargo.lock index fe1fdd8579a0f..73a5eb413c303 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12742,6 +12742,7 @@ dependencies = [ "im", "inquire", "insta", + "insta-cmd", "jemalloc-ctl", "json_to_table", "miette", @@ -14515,6 +14516,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..e3b6e81573777 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 @@ -61,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-move/tests/cli_tests.rs b/crates/sui-move/tests/cli_tests.rs deleted file mode 100644 index 990940433dd18..0000000000000 --- a/crates/sui-move/tests/cli_tests.rs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -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 -// --review` to update the snapshots. - -const TEST_DIR: &str = "tests/tests"; -const TEST_PATTERN: &str = r"^test.*\.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<()> { - // copy files into temporary directory - let srcdir = path.parent().unwrap(); - let tmpdir = tempfile::tempdir()?; - let sandbox = tmpdir.path().join("sandbox"); - - 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)?; - } - } - - // set up command - let mut shell = Command::new("bash"); - shell - .env("PATH", format!("/bin:/usr/bin:{}", get_sui_move_path())) - .current_dir(sandbox) - .arg(path.file_name().unwrap()); - - // run it; snapshot test output - let output = shell.output()?; - let result = format!( - "success: {:?}\nexit_code: {}\n----- stdout -----\n{}\n----- stderr -----\n{}", - output.status.success(), - output.status.code().unwrap_or(!0), - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr) - ); - - let snapshot_name: String = path - .strip_prefix("tests/tests")? - .to_string_lossy() - .to_string(); - - insta::with_settings!({description => path.to_string_lossy(), omit_expression => true}, { - insta::assert_snapshot!(snapshot_name, result); - }); - - Ok(()) -} - -fn get_sui_move_path() -> String { - get_cargo_bin("sui-move") - .parent() - .unwrap() - .to_str() - .expect("directory name is valid UTF-8") - .to_owned() -} - -#[cfg(not(msim))] -datatest_stable::harness!(test_shell_snapshot, TEST_DIR, TEST_PATTERN); - -#[cfg(msim)] -fn main() {} 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 deleted file mode 100644 index 15f146522559f..0000000000000 --- a/crates/sui-move/tests/snapshots/cli_tests__dummy__dummy.sh.snap +++ /dev/null @@ -1,11 +0,0 @@ ---- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/dummy/dummy.sh ---- -success: true -exit_code: 0 ------ stdout ----- -dummy test -some dummy data - ------ stderr ----- 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 deleted file mode 100644 index 98273f8ed0c71..0000000000000 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_exists.sh.snap +++ /dev/null @@ -1,11 +0,0 @@ ---- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/gitignore_exists.sh ---- -success: true -exit_code: 0 ------ stdout ----- -existing_ignore -build/* - ------ stderr ----- 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 deleted file mode 100644 index 5af9fb5d7b873..0000000000000 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__gitignore_has_build.sh.snap +++ /dev/null @@ -1,18 +0,0 @@ ---- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/gitignore_has_build.sh ---- -success: true -exit_code: 0 ------ stdout ----- -ignore1 -build/* -ignore2 - -==== files in example/ ==== -.gitignore -Move.toml -sources -tests - ------ stderr ----- 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 deleted file mode 100644 index 2f8a7212059dd..0000000000000 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_files.sh.snap +++ /dev/null @@ -1,18 +0,0 @@ ---- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/new_files.sh ---- -success: true -exit_code: 0 ------ stdout ----- -==== files in project ==== -.gitignore -Move.toml -sources -tests -==== files in sources ==== -example.move -==== files in tests ===== -example_tests.move - ------ stderr ----- 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 deleted file mode 100644 index ceff62071690e..0000000000000 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_build.sh.snap +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/new_then_build.sh ---- -success: true -exit_code: 0 ------ stdout ----- - ------ stderr ----- -INCLUDING DEPENDENCY Sui -INCLUDING DEPENDENCY MoveStdlib -BUILDING example 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 deleted file mode 100644 index 63ed656458958..0000000000000 --- a/crates/sui-move/tests/snapshots/cli_tests__new_tests__new_then_test.sh.snap +++ /dev/null @@ -1,14 +0,0 @@ ---- -source: crates/sui-move/tests/cli_tests.rs -description: tests/tests/new_tests/new_then_test.sh ---- -success: true -exit_code: 0 ------ stdout ----- -INCLUDING DEPENDENCY Sui -INCLUDING DEPENDENCY MoveStdlib -BUILDING example -Running Move unit tests -Test result: OK. Total tests: 0; passed: 0; failed: 0 - ------ stderr ----- 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/tests/cli_tests.rs b/crates/sui/tests/cli_tests.rs index aa60fc2305b45..8a9bd44335f37 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 @@ -3944,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/shell_tests.rs b/crates/sui/tests/shell_tests.rs new file mode 100644 index 0000000000000..c899913138294 --- /dev/null +++ b/crates/sui/tests/shell_tests.rs @@ -0,0 +1,95 @@ +// 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 sui_config::SUI_CLIENT_CONFIG; +use test_cluster::TestClusterBuilder; + +// [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/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. +/// The script is run in a temporary working directory that contains a copy of the parent directory +/// 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. +#[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()?; + let sandbox = tmpdir.path(); + + fs_extra::dir::copy(srcdir, sandbox, &CopyOptions::new().content_only(true))?; + + // set up command + let mut shell = Command::new("bash"); + shell + .env( + "PATH", + format!("{}:{}", get_sui_bin_path(), std::env::var("PATH")?), + ) + .current_dir(sandbox) + .arg(path.file_name().unwrap()); + + if let Some(ref cluster) = cluster { + shell.env("CONFIG", cluster.swarm.dir().join(SUI_CLIENT_CONFIG)); + } + + // run it; snapshot test output + let output = shell.output()?; + let result = format!( + "----- 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), + String::from_utf8_lossy(&output.stderr) + ); + + let snapshot_name: String = path + .strip_prefix("tests/shell_tests")? + .to_string_lossy() + .to_string(); + + insta::with_settings!({description => path.to_string_lossy(), omit_expression => true}, { + insta::assert_snapshot!(snapshot_name, result); + }); + + Ok(()) +} + +/// 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() + .expect("directory name is valid UTF-8") + .to_owned() +} + +#[cfg(not(msim))] +datatest_stable::harness!(test_shell_snapshot, TEST_DIR, TEST_PATTERN); + +#[cfg(msim)] +fn main() {} 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/shell_tests/with_network/dummy.sh b/crates/sui/tests/shell_tests/with_network/dummy.sh new file mode 100644 index 0000000000000..b7da468061edc --- /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 objects --json | jq 'length' 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..71a79d247fa6d --- /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,9 @@ +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +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/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__dummy__dummy.sh.snap b/crates/sui/tests/snapshots/shell_tests__dummy__dummy.sh.snap new file mode 100644 index 0000000000000..3efc740d07d5c --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__dummy__dummy.sh.snap @@ -0,0 +1,21 @@ +--- +source: crates/sui/tests/shell_tests.rs +description: tests/shell_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 ----- +dummy test +some dummy data + +----- stderr ----- diff --git a/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_exists.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_exists.sh.snap new file mode 100644 index 0000000000000..8cef1cdd2fbca --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_exists.sh.snap @@ -0,0 +1,22 @@ +--- +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 +mkdir example +echo "existing_ignore" > example/.gitignore +sui move new example +cat example/.gitignore + +----- results ----- +success: true +exit_code: 0 +----- stdout ----- +existing_ignore +build/* + +----- stderr ----- diff --git a/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_has_build.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_has_build.sh.snap new file mode 100644 index 0000000000000..798662ea1855d --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__gitignore_has_build.sh.snap @@ -0,0 +1,34 @@ +--- +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 +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 ----- +ignore1 +build/* +ignore2 + +==== files in example/ ==== +.gitignore +Move.toml +sources +tests + +----- stderr ----- 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 85% 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 b60ec26122809..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,7 +1,15 @@ --- -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 +cat example/Move.toml + +----- results ----- success: true exit_code: 0 ----- stdout ----- diff --git a/crates/sui/tests/snapshots/shell_tests__new_tests__new_files.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__new_files.sh.snap new file mode 100644 index 0000000000000..147b4a0d89e5b --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__new_files.sh.snap @@ -0,0 +1,32 @@ +--- +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 +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 ----- +==== files in project ==== +.gitignore +Move.toml +sources +tests +==== files in sources ==== +example.move +==== files in tests ===== +example_tests.move + +----- stderr ----- diff --git a/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_build.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_build.sh.snap new file mode 100644 index 0000000000000..06501ff6f3e5a --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_build.sh.snap @@ -0,0 +1,33 @@ +--- +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 + +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##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 ----- + +----- stderr ----- +INCLUDING DEPENDENCY Sui +INCLUDING DEPENDENCY MoveStdlib +BUILDING example diff --git a/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_test.sh.snap b/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_test.sh.snap new file mode 100644 index 0000000000000..e70031835eb4f --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__new_tests__new_then_test.sh.snap @@ -0,0 +1,34 @@ +--- +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 + +# 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##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 ----- +INCLUDING DEPENDENCY Sui +INCLUDING DEPENDENCY MoveStdlib +BUILDING example +Running Move unit tests +Test result: OK. Total tests: 0; passed: 0; failed: 0 + +----- stderr ----- 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..d443b5b10876b --- /dev/null +++ b/crates/sui/tests/snapshots/shell_tests__with_network__dummy.sh.snap @@ -0,0 +1,18 @@ +--- +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 objects --json | jq 'length' + +----- results ----- +success: true +exit_code: 0 +----- stdout ----- +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 new file mode 100644 index 0000000000000..d3afab6c23ec4 --- /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,28 @@ +--- +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 + +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 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 -----