From 72f2ef1925ae86e9564cca0e4f7873e96b03d5a9 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 --- .vscode/settings.json | 5 ++++- crates/hive-utils/src/hive/genesis.rs | 8 ++++++-- crates/test-utils/src/bin/dump-katana.rs | 7 +++---- crates/test-utils/src/deploy_helpers.rs | 6 ++++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f17bf4ddd..dc899290f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,8 @@ "files.exclude": { "**/.git": false }, - "rust-analyzer.check.command": "clippy" + "rust-analyzer.check.command": "clippy", + "rust-analyzer.linkedProjects": [ + "./crates/test-utils/Cargo.toml" + ] } diff --git a/crates/hive-utils/src/hive/genesis.rs b/crates/hive-utils/src/hive/genesis.rs index d5dfd6955..d528fcbaf 100644 --- a/crates/hive-utils/src/hive/genesis.rs +++ b/crates/hive-utils/src/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) + .expect(&format!("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)?; diff --git a/crates/test-utils/src/bin/dump-katana.rs b/crates/test-utils/src/bin/dump-katana.rs index 14337db35..49f72ca86 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 ethers::abi::Token; use git2::{Repository, SubmoduleIgnore}; @@ -46,10 +45,10 @@ async fn main() { .read(true) .write(true) .append(false) - .open(katana_dump_path) - .expect(format!("Failed to open file {}", katana_dump_path)); + .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)); + .expect(&format!("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 f0ab8d49c..5e1468698 100644 --- a/crates/test-utils/src/deploy_helpers.rs +++ b/crates/test-utils/src/deploy_helpers.rs @@ -106,7 +106,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. @@ -774,7 +775,8 @@ impl KakarotTestEnvironmentContext { let mut katana_dump_path = root_project_path!(".katana/dump.json"); // Load the dumped state into the sequencer - let katana_dump_file = File::open(&katana_dump_path).unwrap(); + let katana_dump_file = + File::open(&katana_dump_path).expect(&format!("Failed to open file at path {:?}", katana_dump_path)); let state: SerializableState = serde_json::from_reader(katana_dump_file).expect("Failed to deserialize Katana dump");