Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/env utils #447

Conversation

heemankv
Copy link

@heemankv heemankv commented Dec 8, 2024

Issue Number: N/A

Type

  • feature
  • bugfix
  • dev (no functional changes, no API changes)
  • fmt (formatting, renaming)
  • build
  • docs
  • testing

Description

  • This PR allows for env based input of certain variables.
  • Currently being used for strk and eth token addresses found in rpc-replay crate.
  • While testing sequencers such as Madara with Madara Orchestrator, having this capability to customise the address allows for testing with dummy tokens, which the tester can control more easily.

Breaking changes?

  • yes
  • no

}
}

pub fn get_env_car_optional_or_panic(key: &str) -> Option<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn get_env_car_optional_or_panic(key: &str) -> Option<String> {
pub fn get_env_var_optional_or_panic(key: &str) -> Option<String> {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep all if they aren't being used right now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, we'll add them when we need them.
Removed for now.

@@ -0,0 +1 @@
pub mod env_utils;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a full crate for this? cc @notlesh

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, these are some pretty short utility functions, an entire utils crate seems like overkill to me as it would come with a lot of extra overhead.

Copy link
Author

@heemankv heemankv Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you suggest any other location where this function will fit better @whichqua @notlesh ?

  • maybe as a new function inside crates/rpc-replay/src/block_context.rs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heemankv I would suggest so. Or just inline the code and skip the functions part.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright added, can you re-review @whichqua

@heemankv heemankv requested a review from whichqua December 12, 2024 06:13
Copy link
Collaborator

@whichqua whichqua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some needed changes. Let me know if you have any thoughts or questions.

@@ -11,6 +12,12 @@ use starknet_api::{contract_address, felt, patricia_key};

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn get_env_var_or_default(key: &str, default: &str) -> String {
#[inline]
fn get_env_var_or_default(key: &str, default: &str) -> String {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -16,6 +16,7 @@ starknet_api = { workspace = true }
starknet-os-types = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
serial_test = "3.2.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a dev dependency. +1 if we can avoid adding it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now updated it to be a dev-dependency, I hope that solves the issue,
This is required to ensure

  • test_build_block_context_with_default_env_works
  • test_build_block_context_with_default_env_fails
    works together properly.
    WDYT ?

crates/rpc-replay/src/block_context.rs Show resolved Hide resolved
crates/rpc-replay/src/block_context.rs Show resolved Hide resolved
);
let eth_fee_token_address = get_env_var_or_default(
"SNOS_ETH_FEE_TOKEN_ADDRESS",
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating constants for these, something like:

const DEFAULT_ETH_FEE_TOKEN_ADDRESS = ....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, added.

Cargo.toml Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are lint changes, will revert to keep as is.

@heemankv heemankv requested a review from whichqua December 24, 2024 04:22
Copy link
Collaborator

@whichqua whichqua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@notlesh notlesh merged commit 3c95181 into keep-starknet-strange:tmp/snos_devnet_zero_txs Jan 3, 2025
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants