Skip to content

Commit

Permalink
dev: remove unwraps and fix format! macro uses
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh Bajpai authored and Harsh Bajpai committed Sep 14, 2023
1 parent 23ac17d commit 72f2ef1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
8 changes: 6 additions & 2 deletions crates/hive-utils/src/hive/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
7 changes: 3 additions & 4 deletions crates/test-utils/src/bin/dump-katana.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;
use std::fs::File;
use std::path::PathBuf;

use ethers::abi::Token;
use git2::{Repository, SubmoduleIgnore};
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 4 additions & 2 deletions crates/test-utils/src/deploy_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));

Check failure on line 779 in crates/test-utils/src/deploy_helpers.rs

View workflow job for this annotation

GitHub Actions / Linters / clippy

use of `expect` followed by a function call
let state: SerializableState =
serde_json::from_reader(katana_dump_file).expect("Failed to deserialize Katana dump");

Expand Down

0 comments on commit 72f2ef1

Please sign in to comment.