diff --git a/common/src/attestations/signers.rs b/common/src/attestations/signers.rs index b985d7cb..d235102a 100644 --- a/common/src/attestations/signers.rs +++ b/common/src/attestations/signers.rs @@ -53,3 +53,42 @@ pub fn attestation_signers( } }) } + +#[cfg(test)] +mod tests { + use alloy_primitives::Address; + + use crate::test_vectors::{ + DISPUTE_MANAGER_ADDRESS, INDEXER_ALLOCATIONS, INDEXER_OPERATOR_MNEMONIC, + }; + + use super::*; + + #[tokio::test] + async fn test_attestation_signers_update_with_allocations() { + let (mut allocations_writer, allocations) = Eventual::>::new(); + + let signers = attestation_signers( + allocations, + (*INDEXER_OPERATOR_MNEMONIC).to_string(), + U256::from(1), + *DISPUTE_MANAGER_ADDRESS, + ); + let mut signers = signers.subscribe(); + + // Test that an empty set of allocations leads to an empty set of signers + allocations_writer.write(HashMap::new()); + let latest_signers = signers.next().await.unwrap(); + assert_eq!(latest_signers, HashMap::new()); + + // Test that writing our set of test allocations results in corresponding signers for all of them + allocations_writer.write((*INDEXER_ALLOCATIONS).clone()); + let latest_signers = signers.next().await.unwrap(); + assert_eq!(latest_signers.len(), INDEXER_ALLOCATIONS.len()); + for signer_allocation_id in latest_signers.keys() { + assert!(INDEXER_ALLOCATIONS + .keys() + .any(|allocation_id| signer_allocation_id == allocation_id)); + } + } +} diff --git a/common/src/test_vectors.rs b/common/src/test_vectors.rs index 16314c88..c5582ea8 100644 --- a/common/src/test_vectors.rs +++ b/common/src/test_vectors.rs @@ -5,15 +5,12 @@ use std::{collections::HashMap, str::FromStr}; use alloy_primitives::Address; use ethers_core::types::U256; +use lazy_static::lazy_static; use toolshed::thegraph::DeploymentId; use crate::prelude::{Allocation, AllocationStatus, SubgraphDeployment}; -pub const INDEXER_OPERATOR_MNEMONIC: &str = - "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; -pub const INDEXER_ADDRESS: &str = "0x1234567890123456789012345678901234567890"; pub const NETWORK_SUBGRAPH_ID: &str = "QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP"; -pub const DISPUTE_MANAGER_ADDRESS: &str = "0xdeadbeefcafebabedeadbeefcafebabedeadbeef"; /// The allocation IDs below are generated using the mnemonic /// "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" @@ -106,10 +103,20 @@ pub const ALLOCATIONS_QUERY_RESPONSE: &str = r#" } "#; -/// These are the expected json-serialized contents of the value returned by -/// AllocationMonitor::current_eligible_allocations with the values above at epoch threshold 940. -pub fn expected_eligible_allocations() -> HashMap { - HashMap::from([ +lazy_static! { + pub static ref INDEXER_OPERATOR_MNEMONIC: String = String::from( + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + ); + + pub static ref INDEXER_ADDRESS: Address = + Address::from_str("0x1234567890123456789012345678901234567890").unwrap(); + + pub static ref DISPUTE_MANAGER_ADDRESS: Address = + Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(); + + /// These are the expected json-serialized contents of the value returned by + /// AllocationMonitor::current_eligible_allocations with the values above at epoch threshold 940. + pub static ref INDEXER_ALLOCATIONS: HashMap = HashMap::from([ ( Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), Allocation { @@ -226,5 +233,5 @@ pub fn expected_eligible_allocations() -> HashMap { query_fees_collected: None, }, ), - ]) + ]); }