Skip to content

Commit

Permalink
Added new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug-rdx committed May 13, 2024
1 parent ad2bf64 commit af6c113
Showing 1 changed file with 69 additions and 3 deletions.
72 changes: 69 additions & 3 deletions scrypto-test/src/ledger_simulator/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mod tests {
use super::{Compile, CompileProfile};
use std::process::Command;

fn compile_blueprint() -> Vec<u8> {
fn compile_blueprint(additional_args: &[&str]) -> Vec<u8> {
// Build `scrypto` cli
Command::new("cargo")
.arg("build")
Expand All @@ -144,6 +144,7 @@ mod tests {
"/../radix-clis/target/release/scrypto"
))
.arg("build")
.args(additional_args)
.current_dir(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/blueprints/tuple-return"
Expand All @@ -164,7 +165,7 @@ mod tests {
#[test]
fn validate_compile_profile_default() {
// Compile blueprint using `scrypto compile` command
let output_file_content = compile_blueprint();
let output_file_content = compile_blueprint(&[]);

// Compile same blueprint using Compile object
let (bin, _) = Compile::compile(
Expand All @@ -184,10 +185,28 @@ mod tests {
)
}

#[test]
fn validate_compile_profile_fast() {
// 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::Fast,
);

// 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_with_log() {
// Compile blueprint using `scrypto compile` command
let output_file_content = compile_blueprint();
let output_file_content = compile_blueprint(&[]);

// Compile same blueprint using Compile object
let (bin, _) = Compile::compile(
Expand All @@ -201,4 +220,51 @@ mod tests {
"Size of Wasm file compiled by `scrypto build` command should be smaller."
);
}

#[test]
fn verify_scrypto_build_with_args_for_compile_profile_fast() {
// Compile blueprint using `scrypto compile` command
let output_file_content = compile_blueprint(&["--disable-wasm-opt"]);

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

// 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_with_log() {
// Compile blueprint using `scrypto compile` command
let output_file_content =
compile_blueprint(&["--disable-wasm-opt", "--log-level", "TRACE"]);

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

// 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."
)
}
}

0 comments on commit af6c113

Please sign in to comment.