Skip to content

Commit

Permalink
test(sidecar): bolt manager wrapper contract
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Oct 30, 2024
1 parent 4a32a06 commit 4c0c9ee
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
54 changes: 53 additions & 1 deletion bolt-sidecar/src/chain_io/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use BoltManagerContract::{BoltManagerContractErrors, BoltManagerContractInstance

use crate::config::chain::Chain;

use super::utils;
use super::utils::{self, CompressedHash};

/// A wrapper over a BoltManagerContract that exposes various utility methods.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -137,3 +137,55 @@ sol! {
error ValidatorDoesNotExist(bytes20 pubkeyHash);
}
}

#[cfg(test)]
mod tests {
use ::hex::FromHex;
use alloy::{hex, primitives::Address};
use ethereum_consensus::primitives::BlsPublicKey;
use reqwest::Url;

use crate::{
chain_io::{manager::generate_operator_keys_mismatch_error, utils::pubkey_hash},
config::chain::Chain,
};

use super::BoltManager;

#[tokio::test]
async fn test_verify_validator_pubkeys() {
let url = Url::parse("http://remotebeast:48545").expect("valid url");
let manager =
BoltManager::from_chain(url, Chain::Holesky).expect("manager deployed on Holesky");

let operator =
Address::from_hex("725028b0b7c3db8b8242d35cd3a5779838b217b1").expect("valid address");

let keys = vec![BlsPublicKey::try_from([0; 48].as_ref()).expect("valid bls public key")];
let commitment_signer_pubkey = Address::ZERO;

let res = manager.verify_validator_pubkeys(&keys, commitment_signer_pubkey).await;
assert!(res.unwrap_err().to_string().contains("ValidatorDoesNotExist"));

let keys = vec![
BlsPublicKey::try_from(
hex!("87cbbfe6f08a0fd424507726cfcf5b9df2b2fd6b78a65a3d7bb6db946dca3102eb8abae32847d5a9a27e414888414c26")
.as_ref()).expect("valid bls public key")];
let res = manager.verify_validator_pubkeys(&keys, commitment_signer_pubkey).await;
assert!(
res.unwrap_err().to_string()
== generate_operator_keys_mismatch_error(
pubkey_hash(&keys[0]),
commitment_signer_pubkey,
operator
)
);

let commitment_signer_pubkey = operator;
let res = manager
.verify_validator_pubkeys(&keys, commitment_signer_pubkey)
.await
.expect("active validator and correct operator");
assert!(res[0].active);
}
}
2 changes: 1 addition & 1 deletion bolt-sidecar/src/chain_io/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use reth_primitives::keccak256;
/// A 20-byte compressed hash of a BLS public key.
///
/// Reference: https://github.com/chainbound/bolt/blob/lore/feat/holesky-launch/bolt-contracts/script/holesky/validators/registervalidators.s.sol#l65-l69.
type CompressedHash = FixedBytes<20>;
pub(crate) type CompressedHash = FixedBytes<20>;

/// Hash the public keys of the proposers. This follows the same
/// implementation done on-chain in the BoltValidators contract.
Expand Down

0 comments on commit 4c0c9ee

Please sign in to comment.