From 632c03876e7ae0691b12adfb7739ab4c2d1de19e Mon Sep 17 00:00:00 2001 From: Harsh Bajpai Date: Thu, 14 Sep 2023 11:41:45 +0530 Subject: [PATCH] dev: remove unwraps and fix format! macro uses --- crates/test-utils/src/bin/dump-katana.rs | 25 +++++++++---------- crates/test-utils/src/deploy_helpers.rs | 3 ++- .../test-utils/src/hive_utils/hive/genesis.rs | 17 +++++++++---- lib/kakarot | 2 +- lib/madara | 2 +- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/crates/test-utils/src/bin/dump-katana.rs b/crates/test-utils/src/bin/dump-katana.rs index 4f99205b1..e2f922a4d 100644 --- a/crates/test-utils/src/bin/dump-katana.rs +++ b/crates/test-utils/src/bin/dump-katana.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; use std::fs::File; -use std::path::PathBuf; use git2::{Repository, SubmoduleIgnore}; use kakarot_rpc_core::client::api::KakarotStarknetApi; @@ -25,19 +24,19 @@ async fn main() { .dump_state() .expect("Failed to call dump_state on Katana state"); - // Dump the state - std::fs::create_dir_all(".katana/").expect("Failed to create Kakata dump dir"); + // Dump the state + std::fs::create_dir_all(".katana/").expect("Failed to create Kakata dump dir"); - let katana_dump_path = String::from(".katana/dump.json"); - let katana_dump_file = File::options() - .create_new(true) - .read(true) - .write(true) - .append(false) - .open(katana_dump_path) - .expect(format!("Failed to open file {}", katana_dump_path)); - serde_json::to_writer_pretty(katana_dump_file, &dump_state) - .expect(format!("Failed to write to the file {}", katana_dump_path)); + let katana_dump_path = String::from(".katana/dump.json"); + let katana_dump_file = File::options() + .create_new(true) + .read(true) + .write(true) + .append(false) + .open(&katana_dump_path) + .unwrap_or_else(|_| panic!("Failed to open file {}", &katana_dump_path)); + serde_json::to_writer_pretty(katana_dump_file, &dump_state) + .unwrap_or_else(|_| panic!("Failed to write to the file {}", katana_dump_path)); let deployer_account = DeployerAccount { address: test_context.client().deployer_account().address(), diff --git a/crates/test-utils/src/deploy_helpers.rs b/crates/test-utils/src/deploy_helpers.rs index e36f720d7..a13841a20 100644 --- a/crates/test-utils/src/deploy_helpers.rs +++ b/crates/test-utils/src/deploy_helpers.rs @@ -104,7 +104,8 @@ pub fn get_contract(filename: &str) -> CompactContractBytecode { let compiled_solidity_file = File::open(compiled_solidity_path_from_root).unwrap_or_else(|_| { panic!("Could not read file: {}. please run `make setup` to ensure solidity files are compiled", filename) }); - serde_json::from_reader(compiled_solidity_file).unwrap() + serde_json::from_reader(&compiled_solidity_file) + .unwrap_or_else(|_| panic!("Failed at reading from file path {:?}", compiled_solidity_file)) } /// Encodes a contract's bytecode and constructor arguments into deployable bytecode. diff --git a/crates/test-utils/src/hive_utils/hive/genesis.rs b/crates/test-utils/src/hive_utils/hive/genesis.rs index bb33a134f..5c4bc3541 100644 --- a/crates/test-utils/src/hive_utils/hive/genesis.rs +++ b/crates/test-utils/src/hive_utils/hive/genesis.rs @@ -225,8 +225,12 @@ pub async fn serialize_hive_to_madara_genesis_config( madara_loader.storage.push(is_initialized); }); - let combined_genesis_file = - File::options().create_new(true).write(true).append(false).open(combined_genesis_path).unwrap(); + let combined_genesis_file = File::options() + .create_new(true) + .write(true) + .append(false) + .open(combined_genesis_path) + .unwrap_or_else(|_| panic!("Failed to open file at path {:?}", combined_genesis_path)); // Serialize the loader to a file serde_json::to_writer_pretty(combined_genesis_file, &madara_loader)?; @@ -313,13 +317,16 @@ mod tests { .await .unwrap(); - let combined_genesis_file = File::open(combined_genesis_path).unwrap(); + let combined_genesis_file = File::open(combined_genesis_path) + .unwrap_or_else(|_| panic!("Failed to open file at path {:?}", &combined_genesis_path)); // Then - let loader: GenesisLoader = serde_json::from_reader(combined_genesis_file).unwrap(); + let loader: GenesisLoader = serde_json::from_reader(&combined_genesis_file) + .unwrap_or_else(|_| panic!("Failed to read from file at path {:?}", &combined_genesis_path)); assert_eq!(9 + 3 + 7, loader.contracts.len()); // 9 original + 3 Kakarot contracts + 7 hive // After - std::fs::remove_file(combined_genesis_path).unwrap(); + std::fs::remove_file(combined_genesis_path) + .unwrap_or_else(|_| panic!("Failed to remove file at path {:?}", combined_genesis_path)); } } diff --git a/lib/kakarot b/lib/kakarot index aec81a483..7f8d856fb 160000 --- a/lib/kakarot +++ b/lib/kakarot @@ -1 +1 @@ -Subproject commit aec81a483c3862bd71e0d55850a64f338434b4bc +Subproject commit 7f8d856fb0016a02612bb15dc03e3dba9b3fc646 diff --git a/lib/madara b/lib/madara index b7477966f..5e24abafa 160000 --- a/lib/madara +++ b/lib/madara @@ -1 +1 @@ -Subproject commit b7477966f5fe817667f0fda411901bd6da324bf3 +Subproject commit 5e24abafa6e0710cc967bb8c6d3218e3d1aa0772