Skip to content

Commit

Permalink
fix: add attestation signer test back in
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis committed Oct 11, 2023
1 parent a8ff08f commit 385455e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
39 changes: 39 additions & 0 deletions common/src/attestations/signers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<HashMap<Address, Allocation>>::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));
}
}
}
25 changes: 16 additions & 9 deletions common/src/test_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<Address, Allocation> {
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<Address, Allocation> = HashMap::from([
(
Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(),
Allocation {
Expand Down Expand Up @@ -226,5 +233,5 @@ pub fn expected_eligible_allocations() -> HashMap<Address, Allocation> {
query_fees_collected: None,
},
),
])
]);
}

0 comments on commit 385455e

Please sign in to comment.