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 19, 2023
1 parent d410a3a commit 632c038
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
25 changes: 12 additions & 13 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 git2::{Repository, SubmoduleIgnore};
use kakarot_rpc_core::client::api::KakarotStarknetApi;
Expand All @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion crates/test-utils/src/deploy_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions crates/test-utils/src/hive_utils/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)
.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)?;

Expand Down Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion lib/kakarot
2 changes: 1 addition & 1 deletion lib/madara
Submodule madara updated 197 files

0 comments on commit 632c038

Please sign in to comment.