Skip to content

Commit

Permalink
Changed compiler profile names
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug-rdx committed May 13, 2024
1 parent af6c113 commit 6457b8e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
8 changes: 6 additions & 2 deletions radix-engine-tests/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub mod package_loader {
panic!("Package \"{}\" not found. Are you sure that this package is: a) in the blueprints folder, b) that this is the same as the package name in the Cargo.toml file?", name)
}
}

pub fn get_using_standard_compiler_profile(name: &str) -> (Vec<u8>, PackageDefinition) {
panic!("Package \"{}\" already compiled. Cannot use specific compiler profile in compile-blueprints-at-build-time mode.", name)
}
}
}

Expand All @@ -47,8 +51,8 @@ pub mod package_loader {
Self::get_internal(name, CompileProfile::FastWithTraceLogs)
}

pub fn get_using_default_compiler_options(name: &str) -> (Vec<u8>, PackageDefinition) {
Self::get_internal(name, CompileProfile::Default)
pub fn get_using_standard_compiler_profile(name: &str) -> (Vec<u8>, PackageDefinition) {
Self::get_internal(name, CompileProfile::Standard)
}

fn get_internal(
Expand Down
58 changes: 52 additions & 6 deletions scrypto-test/src/ledger_simulator/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::path::Path;
pub enum CompileProfile {
/// Uses default compilation options - same as `scrypto build`. Should be used in all cases which requires
/// compilation results to be as close to production as possible (for instance costing related tests).
Default,
Standard,
/// Same as Standard with enabled all logs from error to trace level.
StandardWithTraceLogs,
/// Disables WASM optimization to speed-up compilation process, by default used by SDK PackageFactory.
Fast,
/// Disables WASM optimization and enables all logs from error to trace level, by default used by Ledger Simulator.
Expand Down Expand Up @@ -42,7 +44,10 @@ impl Compile {
compiler_builder.manifest_path(package_dir.as_ref());

match compile_profile {
CompileProfile::Default => (),
CompileProfile::Standard => (),
CompileProfile::StandardWithTraceLogs => {
compiler_builder.log_level(Level::Trace); // all logs from error to trace
}
CompileProfile::Fast => {
compiler_builder.optimize_with_wasm_opt(None);
}
Expand Down Expand Up @@ -163,14 +168,14 @@ mod tests {
}

#[test]
fn validate_compile_profile_default() {
fn validate_compile_profile_standard() {
// Compile blueprint using `scrypto compile` command
let output_file_content = compile_blueprint(&[]);

// Compile same blueprint using Compile object
let (bin, _) = Compile::compile(
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"),
CompileProfile::Default,
CompileProfile::Standard,
);

// Assert
Expand All @@ -185,6 +190,24 @@ mod tests {
)
}

#[test]
fn validate_compile_profile_standard_with_logs() {
// Compile blueprint using `scrypto compile` command
let output_file_content = compile_blueprint(&[]);

// Compile same blueprint using Compile object
let (bin, _) = Compile::compile(
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"),
CompileProfile::StandardWithTraceLogs,
);

// Assert
assert!(
output_file_content.len() < bin.len(),
"Size of Wasm file compiled by `scrypto build` command should be smaller."
);
}

#[test]
fn validate_compile_profile_fast() {
// Compile blueprint using `scrypto compile` command
Expand All @@ -204,7 +227,7 @@ mod tests {
}

#[test]
fn validate_compile_profile_fast_with_log() {
fn validate_compile_profile_fast_with_logs() {
// Compile blueprint using `scrypto compile` command
let output_file_content = compile_blueprint(&[]);

Expand All @@ -221,6 +244,29 @@ mod tests {
);
}

#[test]
fn verify_scrypto_build_with_args_for_compile_profile_standard_with_logs() {
// Compile blueprint using `scrypto compile` command
let output_file_content = compile_blueprint(&["--log-level", "TRACE"]);

// Compile same blueprint using Compile object
let (bin, _) = Compile::compile(
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"),
CompileProfile::StandardWithTraceLogs,
);

// Assert
assert_eq!(
output_file_content.len(),
bin.len(),
"Wasm files should have same size."
);
assert_eq!(
output_file_content, bin,
"Wasm files should have same content."
)
}

#[test]
fn verify_scrypto_build_with_args_for_compile_profile_fast() {
// Compile blueprint using `scrypto compile` command
Expand All @@ -245,7 +291,7 @@ mod tests {
}

#[test]
fn verify_scrypto_build_with_args_for_compile_profile_fast_with_log() {
fn verify_scrypto_build_with_args_for_compile_profile_fast_with_logs() {
// Compile blueprint using `scrypto compile` command
let output_file_content =
compile_blueprint(&["--disable-wasm-opt", "--log-level", "TRACE"]);
Expand Down

0 comments on commit 6457b8e

Please sign in to comment.