Skip to content

Commit

Permalink
Simplified Impl
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Dec 20, 2024
1 parent bb7e851 commit 8eed51d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 82 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ members = [
"crates/starknet-os",
"crates/starknet-os-types",
"tests",
"crates/utils",
]

[workspace.package]
Expand Down Expand Up @@ -82,7 +81,6 @@ starknet-core = "0.11.1"
starknet-crypto = "0.6.2"
starknet-os = { path = "crates/starknet-os" }
starknet-os-types = { path = "crates/starknet-os-types" }
utils = { path = "crates/utils" }
starknet-types-core = "0.1.5"
thiserror = "1.0.48"
tokio = { version = "1.37.0", features = ["rt-multi-thread"] }
Expand Down
1 change: 0 additions & 1 deletion crates/rpc-replay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ serde_json = { workspace = true }
starknet = { workspace = true }
starknet_api = { workspace = true }
starknet-os-types = { workspace = true }
utils = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
serial_test = "3.2.0"
Expand Down
32 changes: 30 additions & 2 deletions crates/rpc-replay/src/block_context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::num::NonZeroU128;

use blockifier::blockifier::block::{BlockInfo, GasPrices};
Expand All @@ -8,10 +9,15 @@ use starknet::core::types::{BlockWithTxs, Felt, L1DataAvailabilityMode};
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{ChainId, ContractAddress, PatriciaKey};
use starknet_api::{contract_address, felt, patricia_key};
use utils::env_utils::get_env_var_or_default;

use crate::utils::{felt_to_u128, FeltConversionError};

/// Fetches environment variable based on provided key.
/// If key is not found in env, it returns default value provided
pub fn get_env_var_or_default(key: &str, default: &str) -> String {
env::var(key).unwrap_or(default.to_string())
}

fn felt_to_gas_price(price: &Felt) -> Result<NonZeroU128, FeltConversionError> {
// Inspiration taken from Papyrus:
// https://github.com/starkware-libs/sequencer/blob/7218aa1f7ca3fe21c0a2bede2570820939ffe069/crates/papyrus_execution/src/lib.rs#L363-L371
Expand Down Expand Up @@ -76,12 +82,34 @@ pub fn build_block_context(

#[cfg(test)]
mod tests {

use starknet::core::types::{Felt, ResourcePrice};
use starknet_api::core::ChainId;

use super::*;

#[test]
fn test_get_env_var_or_default_existing() {
let test_key = "TEST_ENV_VAR_DEFAULT";
let test_value = "actual_value";
let default_value = "default_value";
env::set_var(test_key, test_value);

let result = get_env_var_or_default(test_key, default_value);
assert_eq!(result, test_value);

env::remove_var(test_key);
}

#[test]
fn test_get_env_var_or_default_non_existing() {
let test_key = "NON_EXISTING_VAR_DEFAULT";
let default_value = "default_value";
env::remove_var(test_key); // Ensure it doesn't exist

let result = get_env_var_or_default(test_key, default_value);
assert_eq!(result, default_value);
}

#[test]
fn test_build_block_context_with_zero_gas_prices() {
let chain_id = ChainId::Mainnet;
Expand Down
9 changes: 0 additions & 9 deletions crates/utils/Cargo.toml

This file was deleted.

62 changes: 0 additions & 62 deletions crates/utils/src/env_utils.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/utils/src/lib.rs

This file was deleted.

0 comments on commit 8eed51d

Please sign in to comment.