From 82c45111c15e796dc9ae316e45c8d619692c577a Mon Sep 17 00:00:00 2001 From: Naman Garg <0708ng@gmail.com> Date: Wed, 17 Jul 2024 18:14:31 +0530 Subject: [PATCH] chore(sidecar): add test --- bolt-spammer-helder/src/contract.rs | 32 +++++++++++++++++++++++++++++ bolt-spammer-helder/src/main.rs | 13 +++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/bolt-spammer-helder/src/contract.rs b/bolt-spammer-helder/src/contract.rs index 62bfdd0b2..ea9688c75 100644 --- a/bolt-spammer-helder/src/contract.rs +++ b/bolt-spammer-helder/src/contract.rs @@ -207,4 +207,36 @@ mod tests { Ok(()) } + + #[tokio::test] + async fn test_next_preconfer_from_registry() -> eyre::Result<()> { + let registry = BoltRegistry::new( + Url::parse("http://remotebeast:4485")?, + Address::from_str("0xdF11D829eeC4C192774F3Ec171D822f6Cb4C14d9")?, + ); + + // Mock proposer duties + let proposer_duties = vec![ + ProposerDuty { public_key: Default::default(), validator_index: 2145, slot: 12345 }, + ProposerDuty { public_key: Default::default(), validator_index: 2150, slot: 12346 }, + ]; + + // Calling the next_preconfer_from_registry function + let result = registry.next_preconfer_from_registry(proposer_duties).await?; + + // Expected result + let expected_rpc = "http://135.181.191.125:8000".to_string(); + let expected_slot = 12345; + + // Asserting the result + match result { + Some((rpc, slot)) => { + assert_eq!(rpc, expected_rpc); + assert_eq!(slot, expected_slot); + } + None => panic!("Expected some value but got None"), + } + + Ok(()) + } } diff --git a/bolt-spammer-helder/src/main.rs b/bolt-spammer-helder/src/main.rs index 37e851b37..4ced9f7db 100644 --- a/bolt-spammer-helder/src/main.rs +++ b/bolt-spammer-helder/src/main.rs @@ -1,10 +1,8 @@ -use std::{path::PathBuf, str::FromStr, sync::Arc}; +use std::{path::PathBuf, str::FromStr}; use alloy::{ hex, network::EthereumWallet, - primitives::{utils::keccak256, B256}, - providers::{Provider, ProviderBuilder}, signers::{local::PrivateKeySigner, Signer}, }; use beacon_api_client::mainnet::Client as BeaconApiClient; @@ -49,8 +47,7 @@ async fn main() -> Result<()> { let opts = Opts::parse(); let wallet: PrivateKeySigner = opts.private_key.parse().expect("should parse private key"); - let eth_provider = ProviderBuilder::new().on_http(opts.el_provider_url.parse()?); - let transaction_signer: EthereumWallet = wallet.into(); + let transaction_signer: EthereumWallet = wallet.clone().into(); let beacon_api_client = BeaconApiClient::new(opts.beacon_client_url); @@ -86,7 +83,7 @@ async fn main() -> Result<()> { } }; - let mut tx = if opts.blob { generate_random_blob_tx() } else { generate_random_tx() }; + let tx = if opts.blob { generate_random_blob_tx() } else { generate_random_tx() }; let (tx_hash, tx_rlp) = sign_transaction(&transaction_signer, tx).await?; @@ -94,10 +91,10 @@ async fn main() -> Result<()> { let mut data = Vec::new(); data.extend_from_slice(&next_preconfer_slot.to_le_bytes()); data.extend_from_slice(hex::decode(tx_hash.trim_start_matches("0x"))?.as_slice()); - B256::from(keccak256(data)) + data }; - let signature = wallet.sign_message().await?; + let signature = wallet.sign_message(message_digest.as_ref()).await?; let request = prepare_rpc_request( "bolt_inclusionPreconfirmation",