diff --git a/Cargo.lock b/Cargo.lock index 7241a70d4..36c10a876 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2672,9 +2672,11 @@ dependencies = [ "arc-swap", "bs58 0.5.0", "eip-712-derive", + "env_logger", "ethereum-types", "ethers", "ethers-core", + "faux", "keccak-hash", "lazy_static", "log", @@ -2682,6 +2684,7 @@ dependencies = [ "secp256k1 0.27.0", "serde", "serde_json", + "test-log", "tokio", "wiremock", ] diff --git a/common/Cargo.toml b/common/Cargo.toml index d43a3dede..aa9e5381d 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -12,6 +12,7 @@ eip-712-derive = { git = "https://github.com/graphprotocol/eip-712-derive" } ethereum-types = "0.14.1" ethers = "2.0.10" ethers-core = "2.0.10" +faux = { version = "0.1.10", optional = true } keccak-hash = "0.10.0" lazy_static = "1.4.0" log = "0.4.20" @@ -19,7 +20,13 @@ reqwest = "0.11.20" secp256k1 = { version = "0.27.0", features = ["recovery"] } serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" -tokio = { version = "1.32.0", features = ["full", "macros"] } +tokio = { version = "1.32.0", features = ["full", "macros", "rt"] } [dev-dependencies] +env_logger = "0.9.0" +faux = "0.1.10" +test-log = "0.2.12" wiremock = "0.5.19" + +[features] +mock = ["dep:faux"] diff --git a/common/src/allocations/mod.rs b/common/src/allocations/mod.rs index 7c20545a7..4e050f2d3 100644 --- a/common/src/allocations/mod.rs +++ b/common/src/allocations/mod.rs @@ -148,8 +148,9 @@ pub fn allocation_signer(indexer_mnemonic: &str, allocation: &Allocation) -> Res mod test { use std::str::FromStr; + use crate::prelude::SubgraphDeploymentID; + use super::*; - use crate::common::types::SubgraphDeploymentID; const INDEXER_OPERATOR_MNEMONIC: &str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; diff --git a/common/src/allocations/monitor.rs b/common/src/allocations/monitor.rs index 22a6d3b09..1980ae4b4 100644 --- a/common/src/allocations/monitor.rs +++ b/common/src/allocations/monitor.rs @@ -23,14 +23,14 @@ struct AllocationMonitorInner { watch_receiver: Receiver<()>, } -#[cfg_attr(test, faux::create)] +#[cfg_attr(any(test, feature = "mock"), faux::create)] #[derive(Debug, Clone)] pub struct AllocationMonitor { _monitor_handle: Arc>, inner: Arc, } -#[cfg_attr(test, faux::methods)] +#[cfg_attr(any(test, feature = "mock"), faux::methods)] impl AllocationMonitor { pub async fn new( network_subgraph: NetworkSubgraph, @@ -281,7 +281,7 @@ mod tests { use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; - use crate::common::network_subgraph::NetworkSubgraph; + use crate::prelude::NetworkSubgraph; use crate::test_vectors; use super::*; diff --git a/common/src/attestations/mod.rs b/common/src/attestations/mod.rs index 25acf5298..21ee4aa50 100644 --- a/common/src/attestations/mod.rs +++ b/common/src/attestations/mod.rs @@ -67,11 +67,12 @@ pub fn attestation_signer_for_allocation( #[cfg(test)] mod tests { + use alloy_primitives::Address; + use ethers_core::types::U256; use std::str::FromStr; use test_log::test; - use crate::test_vectors; - use crate::types::SubgraphDeploymentID; + use crate::prelude::{Allocation, AllocationStatus, SubgraphDeployment, SubgraphDeploymentID}; use super::*; @@ -184,37 +185,4 @@ mod tests { }; assert!(attestation_signer_for_allocation(INDEXER_OPERATOR_MNEMONIC, &allocation).is_err()); } - - #[test(tokio::test)] - async fn test_update_attestation_signers() { - unsafe { - let mut mock_allocation_monitor = AllocationMonitor::faux(); - - faux::when!(mock_allocation_monitor.get_eligible_allocations).then_unchecked(|_| { - // Spawn a thread to be able to call `blocking_read` on the RwLock, which actually spins its own async - // runtime. - // This is needed because `faux` will also use a runtime to mock the async function. - let t = std::thread::spawn(|| { - let eligible_allocations = Box::leak(Box::new(Arc::new(RwLock::new( - test_vectors::expected_eligible_allocations(), - )))); - eligible_allocations.blocking_read() - }); - t.join().unwrap() - }); - - let inner = Arc::new(AttestationSignersInner { - attestation_signers: Arc::new(RwLock::new(HashMap::new())), - allocation_monitor: mock_allocation_monitor, - indexer_mnemonic: test_vectors::INDEXER_OPERATOR_MNEMONIC.to_string(), - chain_id: U256::from(1), - dispute_manager: Address::from_str(test_vectors::DISPUTE_MANAGER_ADDRESS).unwrap(), - }); - - AttestationSigners::update_attestation_signers(inner.clone()).await; - - // Check that the attestation signers were found for the allocations - assert_eq!(inner.attestation_signers.read().await.len(), 4); - } - } } diff --git a/common/src/attestations/signers.rs b/common/src/attestations/signers.rs index b56b79b8f..e14bb5d8a 100644 --- a/common/src/attestations/signers.rs +++ b/common/src/attestations/signers.rs @@ -19,7 +19,7 @@ pub struct AttestationSigners { } #[derive(Debug)] -struct AttestationSignersInner { +pub(crate) struct AttestationSignersInner { attestation_signers: Arc>>, allocation_monitor: AllocationMonitor, indexer_mnemonic: String, @@ -53,7 +53,7 @@ impl AttestationSigners { } } - async fn update_attestation_signers(inner: Arc) { + pub(crate) async fn update_attestation_signers(inner: Arc) { let mut attestation_signers_write = inner.attestation_signers.write().await; for allocation in inner .allocation_monitor @@ -116,3 +116,49 @@ impl AttestationSigners { self.inner.attestation_signers.read().await } } + +#[cfg(test)] +mod tests { + use alloy_primitives::Address; + use ethers_core::types::U256; + use std::str::FromStr; + use std::sync::Arc; + + use crate::prelude::AllocationMonitor; + use crate::test_vectors; + + use super::*; + + #[tokio::test] + async fn test_update_attestation_signers() { + unsafe { + let mut mock_allocation_monitor = AllocationMonitor::faux(); + + faux::when!(mock_allocation_monitor.get_eligible_allocations).then_unchecked(|_| { + // Spawn a thread to be able to call `blocking_read` on the RwLock, which actually spins its own async + // runtime. + // This is needed because `faux` will also use a runtime to mock the async function. + let t = std::thread::spawn(|| { + let eligible_allocations = Box::leak(Box::new(Arc::new(RwLock::new( + test_vectors::expected_eligible_allocations(), + )))); + eligible_allocations.blocking_read() + }); + t.join().unwrap() + }); + + let inner = Arc::new(AttestationSignersInner { + attestation_signers: Arc::new(RwLock::new(HashMap::new())), + allocation_monitor: mock_allocation_monitor, + indexer_mnemonic: test_vectors::INDEXER_OPERATOR_MNEMONIC.to_string(), + chain_id: U256::from(1), + dispute_manager: Address::from_str(test_vectors::DISPUTE_MANAGER_ADDRESS).unwrap(), + }); + + AttestationSigners::update_attestation_signers(inner.clone()).await; + + // Check that the attestation signers were found for the allocations + assert_eq!(inner.attestation_signers.read().await.len(), 4); + } + } +} diff --git a/common/src/lib.rs b/common/src/lib.rs index 95da87eb9..339084436 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -7,10 +7,17 @@ pub mod network_subgraph; pub mod signature_verification; pub mod types; +#[cfg(test)] +mod test_vectors; + pub mod prelude { pub use super::allocations::monitor::AllocationMonitor; - pub use super::allocations::{Allocation, AllocationStatus}; - pub use super::attestations::{signer::AttestationSigner, signers::AttestationSigners}; + pub use super::allocations::{Allocation, AllocationStatus, SubgraphDeployment}; + pub use super::attestations::{ + attestation_signer_for_allocation, + signer::{create_attestation_signer, AttestationSigner}, + signers::AttestationSigners, + }; pub use super::network_subgraph::NetworkSubgraph; pub use super::types::*; } diff --git a/common/src/network_subgraph/mod.rs b/common/src/network_subgraph/mod.rs index 994c75d08..d8fc317ee 100644 --- a/common/src/network_subgraph/mod.rs +++ b/common/src/network_subgraph/mod.rs @@ -136,13 +136,11 @@ mod test { let query = r#""{\"data\":{\"graphNetwork\":{\"currentEpoch\":960}}}""#; - let response = network_subgraph + // Check that the response is valid JSON + network_subgraph .network_query(query.to_string(), None) .await .unwrap(); - - // Check that the response is valid JSON - let _json: serde_json::Value = serde_json::from_str(&response.graphql_response).unwrap(); } #[tokio::test] @@ -159,12 +157,10 @@ mod test { } "#; - let response = network_subgraph + // Check that the response is valid JSON + network_subgraph .network_query(query.to_string(), None) .await .unwrap(); - - // Check that the response is valid JSON - let _json: serde_json::Value = serde_json::from_str(&response.graphql_response).unwrap(); } } diff --git a/common/src/test_vectors.rs b/common/src/test_vectors.rs new file mode 100644 index 000000000..d4f3e2f0c --- /dev/null +++ b/common/src/test_vectors.rs @@ -0,0 +1,225 @@ +// Copyright 2023-, GraphOps and Semiotic Labs. +// SPDX-License-Identifier: Apache-2.0 + +use std::{collections::HashMap, str::FromStr}; + +use alloy_primitives::Address; +use ethers_core::types::U256; + +use crate::prelude::{Allocation, AllocationStatus, SubgraphDeployment, SubgraphDeploymentID}; + +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" +/// and the following epoch and index: +/// +/// - (createdAtEpoch, 0) +/// - (createdAtEpoch-1, 0) +/// - (createdAtEpoch, 2) +/// - (createdAtEpoch-1, 1) +/// +/// Using https://github.com/graphprotocol/indexer/blob/f8786c979a8ed0fae93202e499f5ce25773af473/packages/indexer-common/src/allocations/keys.ts#L41-L71 +pub const ALLOCATIONS_QUERY_RESPONSE: &str = r#" + { + "data": { + "indexer": { + "activeAllocations": [ + { + "id": "0xfa44c72b753a66591f241c7dc04e8178c30e13af", + "indexer": { + "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" + }, + "allocatedTokens": "5081382841000000014901161", + "createdAtBlockHash": "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf", + "createdAtEpoch": 953, + "closedAtEpoch": null, + "subgraphDeployment": { + "id": "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + "deniedAt": 0, + "stakedTokens": "96183284152000000014901161", + "signalledTokens": "182832939554154667498047", + "queryFeesAmount": "19861336072168874330350" + } + }, + { + "id": "0xdd975e30aafebb143e54d215db8a3e8fd916a701", + "indexer": { + "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" + }, + "allocatedTokens": "601726452999999979510903", + "createdAtBlockHash": "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf", + "createdAtEpoch": 953, + "closedAtEpoch": null, + "subgraphDeployment": { + "id": "0xcda7fa0405d6fd10721ed13d18823d24b535060d8ff661f862b26c23334f13bf", + "deniedAt": 0, + "stakedTokens": "53885041676589999979510903", + "signalledTokens": "104257136417832003117925", + "queryFeesAmount": "2229358609434396563687" + } + } + ], + "recentlyClosedAllocations": [ + { + "id": "0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658", + "indexer": { + "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" + }, + "allocatedTokens": "5247998688000000081956387", + "createdAtBlockHash": "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887", + "createdAtEpoch": 940, + "closedAtEpoch": 953, + "subgraphDeployment": { + "id": "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + "deniedAt": 0, + "stakedTokens": "96183284152000000014901161", + "signalledTokens": "182832939554154667498047", + "queryFeesAmount": "19861336072168874330350" + } + }, + { + "id": "0x69f961358846fdb64b04e1fd7b2701237c13cd9a", + "indexer": { + "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" + }, + "allocatedTokens": "2502334654999999795109034", + "createdAtBlockHash": "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887", + "createdAtEpoch": 940, + "closedAtEpoch": 953, + "subgraphDeployment": { + "id": "0xc064c354bc21dd958b1d41b67b8ef161b75d2246b425f68ed4c74964ae705cbd", + "deniedAt": 0, + "stakedTokens": "85450761241000000055879354", + "signalledTokens": "154944508746646550301048", + "queryFeesAmount": "4293718622418791971020" + } + } + ] + } + } + } +"#; + +/// 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([ + ( + Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), + Allocation { + id: Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), + indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + allocated_tokens: U256::from_str("5081382841000000014901161").unwrap(), + created_at_block_hash: + "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), + created_at_epoch: 953, + closed_at_epoch: None, + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + ) + .unwrap(), + denied_at: Some(0), + staked_tokens: U256::from_str("96183284152000000014901161").unwrap(), + signalled_tokens: U256::from_str("182832939554154667498047").unwrap(), + query_fees_amount: U256::from_str("19861336072168874330350").unwrap(), + }, + status: AllocationStatus::Null, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }, + ), + ( + Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(), + Allocation { + id: Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(), + indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + allocated_tokens: U256::from_str("601726452999999979510903").unwrap(), + created_at_block_hash: + "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), + created_at_epoch: 953, + closed_at_epoch: None, + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xcda7fa0405d6fd10721ed13d18823d24b535060d8ff661f862b26c23334f13bf", + ) + .unwrap(), + denied_at: Some(0), + staked_tokens: U256::from_str("53885041676589999979510903").unwrap(), + signalled_tokens: U256::from_str("104257136417832003117925").unwrap(), + query_fees_amount: U256::from_str("2229358609434396563687").unwrap(), + }, + status: AllocationStatus::Null, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }, + ), + ( + Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), + Allocation { + id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), + indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + allocated_tokens: U256::from_str("5247998688000000081956387").unwrap(), + created_at_block_hash: + "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), + created_at_epoch: 940, + closed_at_epoch: Some(953), + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + ) + .unwrap(), + denied_at: Some(0), + staked_tokens: U256::from_str("96183284152000000014901161").unwrap(), + signalled_tokens: U256::from_str("182832939554154667498047").unwrap(), + query_fees_amount: U256::from_str("19861336072168874330350").unwrap(), + }, + status: AllocationStatus::Null, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }, + ), + ( + Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(), + Allocation { + id: Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(), + indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + allocated_tokens: U256::from_str("2502334654999999795109034").unwrap(), + created_at_block_hash: + "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), + created_at_epoch: 940, + closed_at_epoch: Some(953), + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xc064c354bc21dd958b1d41b67b8ef161b75d2246b425f68ed4c74964ae705cbd", + ) + .unwrap(), + denied_at: Some(0), + staked_tokens: U256::from_str("85450761241000000055879354").unwrap(), + signalled_tokens: U256::from_str("154944508746646550301048").unwrap(), + query_fees_amount: U256::from_str("4293718622418791971020").unwrap(), + }, + status: AllocationStatus::Null, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }, + ), + ]) +} diff --git a/service/Cargo.toml b/service/Cargo.toml index 696f90622..15608bc13 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -64,6 +64,7 @@ alloy-sol-types = "0.3.2" [dev-dependencies] faux = "0.1.10" hex-literal = "0.4.1" +indexer-common = { path = "../common", features = ["mock"] } test-log = "0.2.12" wiremock = "0.5.19" diff --git a/service/src/query_processor.rs b/service/src/query_processor.rs index 137153f0e..19f661418 100644 --- a/service/src/query_processor.rs +++ b/service/src/query_processor.rs @@ -161,9 +161,9 @@ mod tests { use alloy_primitives::Address; use hex_literal::hex; - use crate::{ - common::allocation::{allocation_signer, Allocation, AllocationStatus, SubgraphDeployment}, - util::create_attestation_signer, + use indexer_common::prelude::{ + attestation_signer_for_allocation, create_attestation_signer, Allocation, AllocationStatus, + SubgraphDeployment, }; use super::*; @@ -259,7 +259,8 @@ mod tests { query_fees_collected: None, }; - let allocation_key = allocation_signer(INDEXER_OPERATOR_MNEMONIC, allocation).unwrap(); + let allocation_key = + attestation_signer_for_allocation(INDEXER_OPERATOR_MNEMONIC, allocation).unwrap(); let attestation_signer = create_attestation_signer( U256::from(1), diff --git a/service/src/tap_manager.rs b/service/src/tap_manager.rs index 0a9f0e9aa..4a4795b97 100644 --- a/service/src/tap_manager.rs +++ b/service/src/tap_manager.rs @@ -106,7 +106,7 @@ mod test { use tap_core::tap_manager::SignedReceipt; use tap_core::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt}; - use crate::allocation_monitor::AllocationMonitor; + use indexer_common::prelude::AllocationMonitor; use super::*; diff --git a/service/src/test_vectors.rs b/service/src/test_vectors.rs index d6d7fe6ed..f8ff89e56 100644 --- a/service/src/test_vectors.rs +++ b/service/src/test_vectors.rs @@ -1,231 +1,12 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::{collections::HashMap, str::FromStr}; - use alloy_primitives::Address; use ethers_core::types::U256; +use std::collections::HashMap; +use std::str::FromStr; -use crate::common::{ - allocation::{Allocation, AllocationStatus, SubgraphDeployment}, - types::SubgraphDeploymentID, -}; - -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" -/// and the following epoch and index: -/// -/// - (createdAtEpoch, 0) -/// - (createdAtEpoch-1, 0) -/// - (createdAtEpoch, 2) -/// - (createdAtEpoch-1, 1) -/// -/// Using https://github.com/graphprotocol/indexer/blob/f8786c979a8ed0fae93202e499f5ce25773af473/packages/indexer-common/src/allocations/keys.ts#L41-L71 -pub const ALLOCATIONS_QUERY_RESPONSE: &str = r#" - { - "data": { - "indexer": { - "activeAllocations": [ - { - "id": "0xfa44c72b753a66591f241c7dc04e8178c30e13af", - "indexer": { - "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" - }, - "allocatedTokens": "5081382841000000014901161", - "createdAtBlockHash": "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf", - "createdAtEpoch": 953, - "closedAtEpoch": null, - "subgraphDeployment": { - "id": "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - "deniedAt": 0, - "stakedTokens": "96183284152000000014901161", - "signalledTokens": "182832939554154667498047", - "queryFeesAmount": "19861336072168874330350" - } - }, - { - "id": "0xdd975e30aafebb143e54d215db8a3e8fd916a701", - "indexer": { - "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" - }, - "allocatedTokens": "601726452999999979510903", - "createdAtBlockHash": "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf", - "createdAtEpoch": 953, - "closedAtEpoch": null, - "subgraphDeployment": { - "id": "0xcda7fa0405d6fd10721ed13d18823d24b535060d8ff661f862b26c23334f13bf", - "deniedAt": 0, - "stakedTokens": "53885041676589999979510903", - "signalledTokens": "104257136417832003117925", - "queryFeesAmount": "2229358609434396563687" - } - } - ], - "recentlyClosedAllocations": [ - { - "id": "0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658", - "indexer": { - "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" - }, - "allocatedTokens": "5247998688000000081956387", - "createdAtBlockHash": "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887", - "createdAtEpoch": 940, - "closedAtEpoch": 953, - "subgraphDeployment": { - "id": "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - "deniedAt": 0, - "stakedTokens": "96183284152000000014901161", - "signalledTokens": "182832939554154667498047", - "queryFeesAmount": "19861336072168874330350" - } - }, - { - "id": "0x69f961358846fdb64b04e1fd7b2701237c13cd9a", - "indexer": { - "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" - }, - "allocatedTokens": "2502334654999999795109034", - "createdAtBlockHash": "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887", - "createdAtEpoch": 940, - "closedAtEpoch": 953, - "subgraphDeployment": { - "id": "0xc064c354bc21dd958b1d41b67b8ef161b75d2246b425f68ed4c74964ae705cbd", - "deniedAt": 0, - "stakedTokens": "85450761241000000055879354", - "signalledTokens": "154944508746646550301048", - "queryFeesAmount": "4293718622418791971020" - } - } - ] - } - } - } -"#; - -/// 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([ - ( - Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), - Allocation { - id: Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), - allocated_tokens: U256::from_str("5081382841000000014901161").unwrap(), - created_at_block_hash: - "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), - created_at_epoch: 953, - closed_at_epoch: None, - subgraph_deployment: SubgraphDeployment { - id: SubgraphDeploymentID::new( - "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - ) - .unwrap(), - denied_at: Some(0), - staked_tokens: U256::from_str("96183284152000000014901161").unwrap(), - signalled_tokens: U256::from_str("182832939554154667498047").unwrap(), - query_fees_amount: U256::from_str("19861336072168874330350").unwrap(), - }, - status: AllocationStatus::Null, - closed_at_epoch_start_block_hash: None, - previous_epoch_start_block_hash: None, - poi: None, - query_fee_rebates: None, - query_fees_collected: None, - }, - ), - ( - Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(), - Allocation { - id: Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(), - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), - allocated_tokens: U256::from_str("601726452999999979510903").unwrap(), - created_at_block_hash: - "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), - created_at_epoch: 953, - closed_at_epoch: None, - subgraph_deployment: SubgraphDeployment { - id: SubgraphDeploymentID::new( - "0xcda7fa0405d6fd10721ed13d18823d24b535060d8ff661f862b26c23334f13bf", - ) - .unwrap(), - denied_at: Some(0), - staked_tokens: U256::from_str("53885041676589999979510903").unwrap(), - signalled_tokens: U256::from_str("104257136417832003117925").unwrap(), - query_fees_amount: U256::from_str("2229358609434396563687").unwrap(), - }, - status: AllocationStatus::Null, - closed_at_epoch_start_block_hash: None, - previous_epoch_start_block_hash: None, - poi: None, - query_fee_rebates: None, - query_fees_collected: None, - }, - ), - ( - Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), - Allocation { - id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), - allocated_tokens: U256::from_str("5247998688000000081956387").unwrap(), - created_at_block_hash: - "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), - created_at_epoch: 940, - closed_at_epoch: Some(953), - subgraph_deployment: SubgraphDeployment { - id: SubgraphDeploymentID::new( - "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - ) - .unwrap(), - denied_at: Some(0), - staked_tokens: U256::from_str("96183284152000000014901161").unwrap(), - signalled_tokens: U256::from_str("182832939554154667498047").unwrap(), - query_fees_amount: U256::from_str("19861336072168874330350").unwrap(), - }, - status: AllocationStatus::Null, - closed_at_epoch_start_block_hash: None, - previous_epoch_start_block_hash: None, - poi: None, - query_fee_rebates: None, - query_fees_collected: None, - }, - ), - ( - Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(), - Allocation { - id: Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(), - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), - allocated_tokens: U256::from_str("2502334654999999795109034").unwrap(), - created_at_block_hash: - "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), - created_at_epoch: 940, - closed_at_epoch: Some(953), - subgraph_deployment: SubgraphDeployment { - id: SubgraphDeploymentID::new( - "0xc064c354bc21dd958b1d41b67b8ef161b75d2246b425f68ed4c74964ae705cbd", - ) - .unwrap(), - denied_at: Some(0), - staked_tokens: U256::from_str("85450761241000000055879354").unwrap(), - signalled_tokens: U256::from_str("154944508746646550301048").unwrap(), - query_fees_amount: U256::from_str("4293718622418791971020").unwrap(), - }, - status: AllocationStatus::Null, - closed_at_epoch_start_block_hash: None, - previous_epoch_start_block_hash: None, - poi: None, - query_fee_rebates: None, - query_fees_collected: None, - }, - ), - ]) -} pub const ESCROW_QUERY_RESPONSE: &str = r#" {