Skip to content

Commit

Permalink
update: cleaner test integration on update_state_with_blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Aug 18, 2024
1 parent ef35e52 commit a8f4bb1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
37 changes: 20 additions & 17 deletions crates/settlement-clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ pub mod conversion;
// - if "1" then : Testing via impersonating `Starknet Operator Address`.
// Note : changing between "0" and "1" is handled automatically by each test function, `no` manual change in `env.test` is needed.

#[cfg(test)]
lazy_static! {
static ref SHOULD_IMPERSONATE_ACCOUNT: bool = get_env_var_or_panic("SHOULD_IMPERSONATE_ACCOUNT") == *"true";
static ref TEST_DUMMY_CONTRACT_ADDRESS: String = get_env_var_or_panic("TEST_DUMMY_CONTRACT_ADDRESS");
static ref ADDRESS_TO_IMPERSONATE: Address =
Address::from_str("0x2C169DFe5fBbA12957Bdd0Ba47d9CEDbFE260CA7").expect("Unable to parse address");
static ref TEST_NONCE: u64 = 666068;
}

#[cfg(test)]
mod tests;
pub mod types;
Expand Down Expand Up @@ -112,6 +103,7 @@ impl EthereumSettlementClient {

#[cfg(test)]
pub fn with_test_settings(settings: &impl SettingsProvider, provider: RootProvider<Http<Client>>) -> Self {
use tests::{SHOULD_IMPERSONATE_ACCOUNT, TEST_DUMMY_CONTRACT_ADDRESS};
let settlement_cfg: EthereumSettlementConfig = settings.get_settings(SETTLEMENT_SETTINGS_NAME).unwrap();

let private_key = get_env_var_or_panic(ENV_PRIVATE_KEY);
Expand Down Expand Up @@ -205,8 +197,6 @@ impl SettlementClient for EthereumSettlementClient {
nonce: u64,
) -> Result<String> {
//TODO: better file management
#[cfg(test)]
use alloy::network::TransactionBuilder;

let trusted_setup_path: String = CURRENT_PATH
.join("src")
Expand Down Expand Up @@ -262,12 +252,7 @@ impl SettlementClient for EthereumSettlementClient {
let txn_request: TransactionRequest = tx_envelope.into();

#[cfg(test)]
let mut txn_request: TransactionRequest = tx_envelope.into();
#[cfg(test)]
if *SHOULD_IMPERSONATE_ACCOUNT {
txn_request.set_nonce(*TEST_NONCE);
txn_request = txn_request.with_from(*ADDRESS_TO_IMPERSONATE);
}
let txn_request = test_config::configure_transaction(tx_envelope);

let pending_transaction = self.provider.send_transaction(txn_request).await?;
return Ok(pending_transaction.tx_hash().to_string());
Expand Down Expand Up @@ -307,3 +292,21 @@ impl SettlementClient for EthereumSettlementClient {
Ok(nonce)
}
}

#[cfg(test)]
mod test_config {
use super::*;
use alloy::network::TransactionBuilder;
use tests::{ADDRESS_TO_IMPERSONATE, SHOULD_IMPERSONATE_ACCOUNT, TEST_NONCE};

pub fn configure_transaction(tx_envelope: TxEnvelope) -> TransactionRequest {
let mut txn_request: TransactionRequest = tx_envelope.into();

if *SHOULD_IMPERSONATE_ACCOUNT {
txn_request.set_nonce(*TEST_NONCE);
txn_request = txn_request.with_from(*ADDRESS_TO_IMPERSONATE);
}

txn_request
}
}
7 changes: 5 additions & 2 deletions crates/settlement-clients/ethereum/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ lazy_static! {
.to_string();
static ref PORT: u16 = 3000_u16;
static ref ETH_RPC: String = get_env_var_or_panic("ETHEREUM_BLAST_RPC_URL");
static ref SHOULD_IMPERSONATE_ACCOUNT: bool = get_env_var_or_panic("SHOULD_IMPERSONATE_ACCOUNT") == *"true";
static ref TEST_DUMMY_CONTRACT_ADDRESS: String = get_env_var_or_panic("TEST_DUMMY_CONTRACT_ADDRESS");
static ref STARKNET_OPERATOR_ADDRESS: Address =
Address::from_str("0x2C169DFe5fBbA12957Bdd0Ba47d9CEDbFE260CA7").expect("Could not impersonate account.");
static ref STARKNET_CORE_CONTRACT_ADDRESS: Address =
Address::from_str("0xc662c410c0ecf747543f5ba90660f6abebd9c8c4").expect("Could not impersonate account.");
pub static ref ADDRESS_TO_IMPERSONATE: Address =
Address::from_str("0x2C169DFe5fBbA12957Bdd0Ba47d9CEDbFE260CA7").expect("Unable to parse address");
pub static ref TEST_DUMMY_CONTRACT_ADDRESS: String = get_env_var_or_panic("TEST_DUMMY_CONTRACT_ADDRESS");
pub static ref SHOULD_IMPERSONATE_ACCOUNT: bool = get_env_var_or_panic("SHOULD_IMPERSONATE_ACCOUNT") == *"true";
pub static ref TEST_NONCE: u64 = 666068;
}

// SOLIDITY FUNCTIONS NEEDED
Expand Down

0 comments on commit a8f4bb1

Please sign in to comment.