Skip to content

Commit

Permalink
- Delete Act Arrange Assert comments
Browse files Browse the repository at this point in the history
- Let compiler infer types
  • Loading branch information
fabrobles92 committed Apr 16, 2024
1 parent 2113549 commit c0f7466
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
9 changes: 4 additions & 5 deletions bin/sozo/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct BuildArgs {

impl BuildArgs {
pub fn run(self, config: &Config) -> Result<()> {
let compile_info: dojo_lang::scarb_internal::CompileInfo = compile_workspace(
let compile_info = compile_workspace(
config,
CompileOpts { include_targets: vec![], exclude_targets: vec![TargetKind::TEST] },
)?;
Expand All @@ -52,9 +52,8 @@ impl BuildArgs {

if self.stats {
let target_dir = &compile_info.target_dir;
let contracts_statistics: Vec<ContractStatistics> =
get_contract_statistics_for_dir(target_dir)
.context(format!("Error getting contracts stats"))?;
let contracts_statistics = get_contract_statistics_for_dir(target_dir)
.context(format!("Error getting contracts stats"))?;
let table = create_stats_table(contracts_statistics);
table.printstd()
}
Expand Down Expand Up @@ -85,7 +84,7 @@ fn create_stats_table(contracts_statistics: Vec<ContractStatistics>) -> Table {
table.set_format(*FORMAT_NO_LINESEP_WITH_TITLE);

// Add table headers
table.add_row(Row::new(vec![
table.set_titles(Row::new(vec![
Cell::new_align("Contract", format::Alignment::CENTER),
Cell::new_align("Bytecode size (felts)", format::Alignment::CENTER),
Cell::new_align("Class size (bytes)", format::Alignment::CENTER),
Expand Down
14 changes: 0 additions & 14 deletions crates/sozo/ops/src/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,14 @@ mod tests {

#[test]
fn get_sierra_byte_code_size_returns_correct_size() {
// Arrange
let sierra_json_file = File::open(TEST_SIERRA_JSON_CONTRACT)
.unwrap_or_else(|err| panic!("Failed to open file: {}", err));
let flattened_sierra_class = read_sierra_json_program(&sierra_json_file)
.unwrap_or_else(|err| panic!("Failed to read JSON program: {}", err));
const EXPECTED_NUMBER_OF_FELTS: u64 = 2175;

// Act
let number_of_felts = get_sierra_byte_code_size(flattened_sierra_class);

// Assert
assert_eq!(
number_of_felts, EXPECTED_NUMBER_OF_FELTS,
"Number of felts mismatch. Expected {}, got {}",
Expand All @@ -112,7 +109,6 @@ mod tests {

#[test]
fn get_contract_statistics_for_file_returns_correct_statistics() {
// Arrange
let sierra_json_file = File::open(TEST_SIERRA_JSON_CONTRACT)
.unwrap_or_else(|err| panic!("Failed to open file: {}", err));
let contract_artifact = read_sierra_json_program(&sierra_json_file)
Expand All @@ -128,40 +124,32 @@ mod tests {
file_size: 114925,
};

// Act
let statistics =
get_contract_statistics_for_file(filename.clone(), sierra_json_file, contract_artifact)
.expect("Error getting contract statistics for file");

// Assert
assert_eq!(statistics, expected_contract_statistics);
}

#[test]
fn get_contract_statistics_for_dir_returns_correct_statistics() {
// Arrange
let target_dir = Utf8PathBuf::from(TEST_SIERRA_FOLDER_CONTRACTS);

// Act
let contract_statistics = get_contract_statistics_for_dir(&target_dir)
.expect(format!("Error getting contracts in dir {target_dir}").as_str());

// Assert
assert_eq!(contract_statistics.len(), 1, "Mismatch number of contract statistics");
}

#[test]
fn get_file_size_returns_correct_size() {
// Arrange
let sierra_json_file = File::open(TEST_SIERRA_JSON_CONTRACT)
.unwrap_or_else(|err| panic!("Failed to open test file: {}", err));
const EXPECTED_SIZE: u64 = 114925;

// Act
let file_size = get_file_size(&sierra_json_file)
.expect(format!("Error getting file size for test file").as_str());

// Assert
assert_eq!(file_size, EXPECTED_SIZE, "File size mismatch");
}

Expand All @@ -171,10 +159,8 @@ mod tests {
let sierra_json_file = File::open(TEST_SIERRA_JSON_CONTRACT)
.unwrap_or_else(|err| panic!("Failed to open test file: {}", err));

// Act
let result = read_sierra_json_program(&sierra_json_file);

// Assert
assert!(result.is_ok(), "Expected Ok result");
}
}

0 comments on commit c0f7466

Please sign in to comment.