Skip to content

Commit

Permalink
Use temp directory for BuildConfig in sui-core/src/test_utils.rs (Mys…
Browse files Browse the repository at this point in the history
  • Loading branch information
mystenmark authored Jan 30, 2023
1 parent 910c3e2 commit 2a06d07
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sui-core/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
1 change: 1 addition & 0 deletions crates/sui-framework-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
6 changes: 6 additions & 0 deletions crates/sui-framework-build/src/compiled_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompiledPackage> {
Expand Down
3 changes: 1 addition & 2 deletions crates/test-utils/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ pub fn create_publish_move_package_transaction(
keypair: &AccountKeyPair,
gas_price: Option<u64>,
) -> 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);
Expand Down

0 comments on commit 2a06d07

Please sign in to comment.