Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Dec 6, 2024
1 parent d4a7dbd commit ca366fc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 64 deletions.
28 changes: 7 additions & 21 deletions crates/ef-testing/src/evm_sequencer/sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_vm::types::errors::program_errors::ProgramError;
use sequencer::{sequencer::Sequencer, state::State};
use starknet::core::types::contract::{legacy::LegacyContractClass, CompiledClass};
use starknet_api::block::{BlockInfo, GasPriceVector, GasPrices};
use starknet_api::block::BlockInfo;
use starknet_api::{
block::{BlockNumber, BlockTimestamp},
core::{ChainId, ClassHash, ContractAddress},
Expand Down Expand Up @@ -109,18 +109,7 @@ impl KakarotSequencer {
)
.try_into()
.expect("Failed to convert to ContractAddress"),
gas_prices: GasPrices {
eth_gas_prices: GasPriceVector {
l1_gas_price: Default::default(),
l1_data_gas_price: Default::default(),
l2_gas_price: Default::default(),
},
strk_gas_prices: GasPriceVector {
l1_gas_price: Default::default(),
l1_data_gas_price: Default::default(),
l2_gas_price: Default::default(),
},
},
gas_prices: Default::default(),
use_kzg_da: false,
};

Expand Down Expand Up @@ -185,21 +174,18 @@ impl DerefMut for KakarotSequencer {
pub fn convert_contract_class_v0(
class: &LegacyContractClass,
) -> Result<RunnableCompiledClass, eyre::Error> {
Result::<RunnableCompiledClass, eyre::Error>::Ok(RunnableCompiledClass::V0(
CompiledClassV0::try_from_json_string(
&serde_json::to_string(class).map_err(ProgramError::Parse)?,
)?,
))
Ok(CompiledClassV0::try_from_json_string(
&serde_json::to_string(class).map_err(ProgramError::Parse)?,
)?
.into())
}

pub fn convert_contract_class_v1(
class: &CompiledClass,
) -> Result<RunnableCompiledClass, eyre::Error> {
let casm_contract_class = CasmContractClassWrapper::try_from(class)?;
let casm_contract_class: CasmContractClass = casm_contract_class.into();
Ok(RunnableCompiledClass::V1(CompiledClassV1::try_from(
casm_contract_class,
)?))
Ok(CompiledClassV1::try_from(casm_contract_class)?.into())
}

lazy_static! {
Expand Down
3 changes: 2 additions & 1 deletion crates/ef-testing/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub fn setup() {
}

pub struct TestMonitor {
thresholds: Vec<u64>, // thresholds in seconds
/// thresholds in seconds
thresholds: Vec<u64>,
}

impl TestMonitor {
Expand Down
17 changes: 5 additions & 12 deletions crates/sequencer/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ lazy_static! {
}

fn generate_library_path(class_hash: ClassHash) -> PathBuf {
let mut path = NATIVE_CACHE_DIR.clone();
path.push(class_hash.to_string().trim_start_matches("0x"));
path
NATIVE_CACHE_DIR.join(class_hash.to_string().trim_start_matches("0x"))
}

fn setup_native_cache_dir() -> PathBuf {
let path: PathBuf = match std::env::var("NATIVE_CACHE_DIR") {
Ok(path) => path.into(),
Err(_err) => {
let mut path = std::env::current_dir().unwrap();
path.push("native_cache");
path
}
};
let _ = fs::create_dir_all(&path);
let path = std::env::var("NATIVE_CACHE_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| std::env::current_dir().unwrap().join("native_cache"));
fs::create_dir_all(&path).ok();
path
}

Expand Down
35 changes: 9 additions & 26 deletions crates/sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use blockifier::{
},
};
use starknet_api::core::ContractAddress;
use starknet_api::executable_transaction::AccountTransaction;

/// Sequencer is the main struct of the sequencer crate.
#[derive(Clone)]
Expand Down Expand Up @@ -75,15 +76,9 @@ where
Transaction::Account(account_tx) => {
let tx = &account_tx.tx;
match tx {
starknet_api::executable_transaction::AccountTransaction::Invoke(tx) => {
tx.sender_address()
}
starknet_api::executable_transaction::AccountTransaction::Declare(tx) => {
tx.sender_address()
}
starknet_api::executable_transaction::AccountTransaction::DeployAccount(tx) => {
tx.contract_address()
}
AccountTransaction::Invoke(tx) => tx.sender_address(),
AccountTransaction::Declare(tx) => tx.sender_address(),
AccountTransaction::DeployAccount(tx) => tx.contract_address(),
}
}
Transaction::L1Handler(_) => ContractAddress::from(0u8),
Expand Down Expand Up @@ -132,13 +127,13 @@ mod tests {
use starknet::core::types::Felt;
use starknet::macros::selector;
use starknet_api::abi::abi_utils::get_storage_var_address;
use starknet_api::block::{BlockInfo, GasPriceVector, GasPrices};
use starknet_api::block::BlockInfo;
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce};
use starknet_api::core::{ChainId, ClassHash, ContractAddress};
use starknet_api::executable_transaction::{
AccountTransaction as AccountTransactionEnum, InvokeTransaction,
};
use starknet_api::transaction::fields::{Calldata, Fee, TransactionSignature};
use starknet_api::transaction::fields::{Calldata, Fee};
use starknet_api::transaction::{
InvokeTransaction as InvokeTransactionTypes, InvokeTransactionV1,
};
Expand Down Expand Up @@ -260,18 +255,7 @@ mod tests {
block_number: BlockNumber(1),
block_timestamp: BlockTimestamp(1),
sequencer_address: *SEQUENCER_ADDRESS,
gas_prices: GasPrices {
eth_gas_prices: GasPriceVector {
l1_gas_price: Default::default(),
l1_data_gas_price: Default::default(),
l2_gas_price: Default::default(),
},
strk_gas_prices: GasPriceVector {
l1_gas_price: Default::default(),
l1_data_gas_price: Default::default(),
l2_gas_price: Default::default(),
},
},
gas_prices: Default::default(),
use_kzg_da: false,
};

Expand Down Expand Up @@ -304,8 +288,7 @@ mod tests {
.into(),
),
max_fee: Fee(1_000_000),
signature: TransactionSignature(vec![]),
nonce: Nonce(Felt::ZERO),
..Default::default()
};
let transaction = InvokeTransaction::create(
InvokeTransactionTypes::V1(invoke_tx),
Expand Down
5 changes: 1 addition & 4 deletions crates/sequencer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@ mod tests {

// When
state
.set_contract_class(
ClassHash(Felt::ONE),
RunnableCompiledClass::V0(CompiledClassV0::default()),
)
.set_contract_class(ClassHash(Felt::ONE), CompiledClassV0::default().into())
.unwrap();

// Then
Expand Down

0 comments on commit ca366fc

Please sign in to comment.