Skip to content

Commit

Permalink
chore: lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Aug 14, 2024
1 parent e7023af commit 391d693
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
13 changes: 9 additions & 4 deletions crates/orchestrator/src/tests/jobs/state_update_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bytes::Bytes;
use httpmock::prelude::*;
use mockall::predicate::eq;
use rstest::*;
use settlement_client_interface::{MockSettlementClient, SettlementClient};
use settlement_client_interface::MockSettlementClient;

use color_eyre::eyre::eyre;

Expand Down Expand Up @@ -76,14 +76,17 @@ async fn test_process_job_works(
// functions while fetching the blob data from storage client.
TestConfigBuilder::new().build().await;

let nonce: u64 = 3;
settlement_client.expect_get_nonce().with().returning(move || Ok(nonce));

// Adding expectations for each block number to be called by settlement client.
for block in block_numbers.iter().skip(processing_start_index as usize) {
let blob_data = fetch_blob_data_for_block(block.to_u64().unwrap()).await.unwrap();
settlement_client
.expect_update_state_with_blobs()
.with(eq(vec![]), eq(blob_data))
.with(eq(vec![]), eq(blob_data), eq(nonce))
.times(1)
.returning(|_, _| Ok("0xbeef".to_string()));
.returning(|_, _, _| Ok("0xbeef".to_string()));
}
settlement_client.expect_get_last_settled_block().with().returning(move || Ok(651052));

Expand Down Expand Up @@ -178,7 +181,9 @@ async fn test_process_job() {
.expect("Failed to read the blob data txt file");
storage_client.expect_get_data().with(eq(x_0_key)).returning(move |_| Ok(Bytes::from(x_0.clone())));

let nonce = settlement_client.get_nonce().await.expect("Unable to fetch nonce for settlement client.");
// let nonce = settlement_client.get_nonce().await.expect("Unable to fetch nonce for settlement client.");
let nonce: u64 = 1;
settlement_client.expect_get_nonce().returning(|| Ok(1));

settlement_client
.expect_update_state_with_blobs()
Expand Down
6 changes: 3 additions & 3 deletions crates/settlement-clients/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ version.workspace = true
edition.workspace = true

[dependencies]
alloy = { workspace = true, features = ["full", "node-bindings" ] }
alloy = { workspace = true, features = ["full", "node-bindings"] }
alloy-primitives = { version = "0.7.7", default-features = false }
async-trait = { workspace = true }
lazy_static = "1.4.0"
c-kzg = "1.0.0"
color-eyre = { workspace = true }
dotenv = "0.15"
dotenvy = { workspace = true }
lazy_static = "1.4.0"
mockall = "0.12.1"
reqwest = { version = "0.12.3" }
rstest = { workspace = true }
Expand All @@ -20,7 +21,6 @@ snos = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }
utils = { workspace = true }
dotenvy = {workspace = true}

[dev-dependencies]
tokio-test = "*"
12 changes: 8 additions & 4 deletions crates/settlement-clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use alloy::{
use alloy::eips::eip2930::AccessList;
use alloy::eips::eip4844::BYTES_PER_BLOB;
use alloy::hex;
use alloy::network::TransactionBuilder;
// use alloy::node_bindings::Anvil;
use alloy::rpc::types::TransactionRequest;
use alloy_primitives::Bytes;
Expand All @@ -42,7 +41,7 @@ pub mod conversion;

#[cfg(test)]
lazy_static! {
static ref SHOULD_IMPERSONATE_ACCOUNT: bool = get_env_var_or_panic("TEST_IMPERSONATE_OPERATOR") == "1".to_string();
static ref SHOULD_IMPERSONATE_ACCOUNT: bool = get_env_var_or_panic("TEST_IMPERSONATE_OPERATOR") == *"1";
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");
Expand Down Expand Up @@ -196,6 +195,8 @@ impl SettlementClient for EthereumSettlementClient {
nonce: u64,
) -> Result<String> {
//TODO: better file management
#[cfg(test)]
use alloy::network::TransactionBuilder;

let trusted_setup = KzgSettings::load_trusted_setup_file(Path::new("/Users/dexterhv/Work/Karnot/madara-alliance/madara-orchestrator/crates/settlement-clients/ethereum/src/trusted_setup.txt"))?;
let (sidecar_blobs, sidecar_commitments, sidecar_proofs) = prepare_sidecar(&state_diff, &trusted_setup).await?;
Expand Down Expand Up @@ -240,9 +241,12 @@ impl SettlementClient for EthereumSettlementClient {
let tx_signed = variant.into_signed(signature);
let tx_envelope: TxEnvelope = tx_signed.into();
// IMP: this conversion strips signature from the transaction

let mut txn_request: TransactionRequest = tx_envelope.into();

#[cfg(not(test))]
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);
Expand Down
6 changes: 3 additions & 3 deletions crates/settlement-clients/ethereum/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ lazy_static! {
.to_string();
static ref PORT: u16 = 3000_u16;
static ref ETH_RPC: String = "https://eth.llamarpc.com".to_string();
static ref SHOULD_IMPERSONATE_ACCOUNT: bool = get_env_var_or_panic("TEST_IMPERSONATE_OPERATOR") == "1".to_string();
static ref SHOULD_IMPERSONATE_ACCOUNT: bool = get_env_var_or_panic("TEST_IMPERSONATE_OPERATOR") == *"1";
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.");
Expand Down Expand Up @@ -129,7 +129,7 @@ async fn update_state_blob_with_dummy_contract_works(#[case] block_no: u64) {

// Testing verify_tx_inclusion
sleep(Duration::from_secs(2)).await;
let _ = ethereum_settlement_client
ethereum_settlement_client
.wait_for_tx_finality(update_state_result.as_str())
.await
.expect("Could not wait for txn finality.");
Expand Down Expand Up @@ -284,7 +284,7 @@ fn get_program_output(block_no: u64) -> Vec<[u8; 32]> {
.expect("Unable to convert line")
.to_be_bytes_vec()
.as_slice()
.pipe(|bytes| to_padded_hex(bytes))
.pipe(to_padded_hex)
.pipe(|hex| hex_string_to_u8_vec(&hex).expect("unable to convert"))
.try_into()
.expect("Vector length must be 32");
Expand Down

0 comments on commit 391d693

Please sign in to comment.