Skip to content

Commit

Permalink
Add test to disabled --test flag in sui client publish
Browse files Browse the repository at this point in the history
  • Loading branch information
rockbmb committed Sep 14, 2023
1 parent 391b811 commit fb583fe
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions crates/sui/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit fb583fe

Please sign in to comment.