From 2a06d071979e87ac166c2d6f9089a14d69d9f23b Mon Sep 17 00:00:00 2001 From: Mark Logan <103447440+mystenmark@users.noreply.github.com> Date: Mon, 30 Jan 2023 11:53:05 -0800 Subject: [PATCH] Use temp directory for BuildConfig in sui-core/src/test_utils.rs (#7893) --- Cargo.lock | 1 + crates/sui-core/src/test_utils.rs | 2 +- crates/sui-framework-build/Cargo.toml | 1 + crates/sui-framework-build/src/compiled_package.rs | 6 ++++++ crates/test-utils/src/messages.rs | 3 +-- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d456fb648c4bb..c46ce0fa76a8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8774,6 +8774,7 @@ dependencies = [ "serde-reflection", "sui-types", "sui-verifier", + "tempfile", "workspace-hack", ] diff --git a/crates/sui-core/src/test_utils.rs b/crates/sui-core/src/test_utils.rs index 6a4f824189485..54ca95d94f07d 100644 --- a/crates/sui-core/src/test_utils.rs +++ b/crates/sui-core/src/test_utils.rs @@ -148,7 +148,7 @@ pub fn compile_basics_package() -> CompiledPackage { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); path.push("../../sui_programmability/examples/basics"); - let build_config = BuildConfig::default(); + let build_config = BuildConfig::new_for_testing(); sui_framework::build_move_package(&path, build_config).unwrap() } diff --git a/crates/sui-framework-build/Cargo.toml b/crates/sui-framework-build/Cargo.toml index ada7493eca041..1584763332b39 100644 --- a/crates/sui-framework-build/Cargo.toml +++ b/crates/sui-framework-build/Cargo.toml @@ -11,6 +11,7 @@ publish = false anyhow = { version = "1.0.64", features = ["backtrace"] } fastcrypto = { workspace = true } once_cell = "1.16" +tempfile = "3.3.0" serde-reflection = "0.3.6" sui-types = { path = "../sui-types" } diff --git a/crates/sui-framework-build/src/compiled_package.rs b/crates/sui-framework-build/src/compiled_package.rs index 3bc73d9c4cb60..00442ab404a24 100644 --- a/crates/sui-framework-build/src/compiled_package.rs +++ b/crates/sui-framework-build/src/compiled_package.rs @@ -48,6 +48,12 @@ pub struct BuildConfig { } impl BuildConfig { + pub fn new_for_testing() -> Self { + let mut build_config: Self = Default::default(); + build_config.config.install_dir = Some(tempfile::TempDir::new().unwrap().into_path()); + build_config + } + /// Given a `path` and a `build_config`, build the package in that path, including its dependencies. /// If we are building the Sui framework, we skip the check that the addresses should be 0 pub fn build(self, path: PathBuf) -> SuiResult { diff --git a/crates/test-utils/src/messages.rs b/crates/test-utils/src/messages.rs index c7fbfd8b4af2a..aec7f4e83f465 100644 --- a/crates/test-utils/src/messages.rs +++ b/crates/test-utils/src/messages.rs @@ -284,8 +284,7 @@ pub fn create_publish_move_package_transaction( keypair: &AccountKeyPair, gas_price: Option, ) -> VerifiedTransaction { - let mut build_config = BuildConfig::default(); - build_config.config.install_dir = Some(tempfile::TempDir::new().unwrap().into_path()); + let build_config = BuildConfig::new_for_testing(); let all_module_bytes = sui_framework::build_move_package(&path, build_config) .unwrap() .get_package_bytes(/* with_unpublished_deps */ false);