Skip to content

Commit

Permalink
chore(sidecar): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
namn-grg committed Jul 17, 2024
1 parent b598bba commit 82c4511
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
32 changes: 32 additions & 0 deletions bolt-spammer-helder/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
13 changes: 5 additions & 8 deletions bolt-spammer-helder/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -86,18 +83,18 @@ 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?;

let message_digest = {
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",
Expand Down

0 comments on commit 82c4511

Please sign in to comment.