From fb583fe098270b512d22f62f1bdfb8ccdcdaf697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9=20=28WSL=20Win11=20Pro=29?= Date: Thu, 14 Sep 2023 17:51:54 +0100 Subject: [PATCH] Add test to disabled `--test` flag in `sui client publish` --- crates/sui/tests/cli_tests.rs | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/crates/sui/tests/cli_tests.rs b/crates/sui/tests/cli_tests.rs index f1bd986a3d9e3..33630a135532e 100644 --- a/crates/sui/tests/cli_tests.rs +++ b/crates/sui/tests/cli_tests.rs @@ -6,6 +6,7 @@ use std::os::unix::prelude::FileExt; use std::{fmt::Write, fs::read_dir, path::PathBuf, str, thread, time::Duration}; use expect_test::expect; +use move_package::BuildConfig as MoveBuildConfig; use serde_json::json; use sui_test_transaction_builder::batch_make_transfer_transactions; use sui_types::object::Owner; @@ -902,6 +903,52 @@ async fn test_package_publish_nonexistent_dependency() -> Result<(), anyhow::Err Ok(()) } +#[sim_test] +async fn test_package_publish_test_flag() -> Result<(), anyhow::Error> { + let mut test_cluster = TestClusterBuilder::new().build().await; + let rgp = test_cluster.get_reference_gas_price().await; + let address = test_cluster.get_address_0(); + let context = &mut test_cluster.wallet; + let client = context.get_client().await?; + let object_refs = client + .read_api() + .get_owned_objects(address, None, None, None) + .await? + .data; + + let gas_obj_id = object_refs.first().unwrap().object().unwrap().object_id; + + let mut package_path = PathBuf::from(TEST_DATA_DIR); + package_path.push("module_publish_with_nonexistent_dependency"); + let mut build_config: MoveBuildConfig = BuildConfig::new_for_testing().config; + // this would have been the result of calling `sui client publish --test` + build_config.test_mode = true; + + let result = SuiClientCommands::Publish { + package_path, + build_config, + gas: Some(gas_obj_id), + gas_budget: rgp * TEST_ONLY_GAS_UNIT_FOR_PUBLISH, + skip_dependency_verification: false, + with_unpublished_dependencies: false, + serialize_unsigned_transaction: false, + serialize_signed_transaction: false, + lint: false, + } + .execute(context) + .await; + + let expect = expect![[r#" + Err( + ModulePublishFailure { + error: "The `publish` subcommand should not be used with the `--test` flag\n\nLibrary code in published packages must not depend on test code.\nIn order to fix this and publish the package without `--test`, search for, and remove instances of e.g. test modules declared as `friend`s of modules from `sources/`.", + }, + ) + "#]]; + expect.assert_debug_eq(&result); + Ok(()) +} + #[sim_test] async fn test_package_upgrade_command() -> Result<(), anyhow::Error> { move_package::package_hooks::register_package_hooks(Box::new(SuiPackageHooks));