Skip to content

Commit 1b66b44

Browse files
committed
graph: Move MockStore to EntityCache tests
That is the last place still using it. With that, it's also clear that MockStore does not need to implement SubgraphStore
1 parent 7316fd8 commit 1b66b44

File tree

2 files changed

+105
-175
lines changed

2 files changed

+105
-175
lines changed

graph/src/components/store.rs

Lines changed: 0 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,173 +1128,6 @@ mock! {
11281128
// connection checkouts
11291129
pub type PoolWaitStats = Arc<RwLock<MovingStats>>;
11301130

1131-
// The store trait must be implemented manually because mockall does not support async_trait, nor borrowing from arguments.
1132-
#[async_trait]
1133-
impl SubgraphStore for MockStore {
1134-
fn ens_lookup(&self) -> Arc<dyn EnsLookup> {
1135-
unimplemented!()
1136-
}
1137-
1138-
fn create_subgraph_deployment(
1139-
&self,
1140-
_: SubgraphName,
1141-
_: &Schema,
1142-
_: SubgraphDeploymentEntity,
1143-
_: NodeId,
1144-
_: String,
1145-
_: SubgraphVersionSwitchingMode,
1146-
) -> Result<DeploymentLocator, StoreError> {
1147-
unimplemented!()
1148-
}
1149-
1150-
fn create_subgraph(&self, _: SubgraphName) -> Result<String, StoreError> {
1151-
unimplemented!()
1152-
}
1153-
1154-
fn remove_subgraph(&self, _: SubgraphName) -> Result<(), StoreError> {
1155-
unimplemented!()
1156-
}
1157-
1158-
fn reassign_subgraph(&self, _: &DeploymentLocator, _: &NodeId) -> Result<(), StoreError> {
1159-
unimplemented!()
1160-
}
1161-
1162-
fn assigned_node(&self, _: &DeploymentLocator) -> Result<Option<NodeId>, StoreError> {
1163-
unimplemented!()
1164-
}
1165-
1166-
fn assignments(&self, _: &NodeId) -> Result<Vec<DeploymentLocator>, StoreError> {
1167-
unimplemented!()
1168-
}
1169-
1170-
fn subgraph_exists(&self, _: &SubgraphName) -> Result<bool, StoreError> {
1171-
unimplemented!()
1172-
}
1173-
1174-
fn input_schema(&self, _: &DeploymentHash) -> Result<Arc<Schema>, StoreError> {
1175-
unimplemented!()
1176-
}
1177-
1178-
fn api_schema(&self, _: &DeploymentHash) -> Result<Arc<ApiSchema>, StoreError> {
1179-
unimplemented!()
1180-
}
1181-
1182-
async fn writable(
1183-
self: Arc<Self>,
1184-
_: Logger,
1185-
_: DeploymentId,
1186-
) -> Result<Arc<dyn WritableStore>, StoreError> {
1187-
Ok(Arc::new(MockStore::new()))
1188-
}
1189-
1190-
fn is_deployed(&self, _: &DeploymentHash) -> Result<bool, StoreError> {
1191-
unimplemented!()
1192-
}
1193-
1194-
fn least_block_ptr(&self, _: &DeploymentHash) -> Result<Option<BlockPtr>, StoreError> {
1195-
unimplemented!()
1196-
}
1197-
1198-
fn writable_for_network_indexer(
1199-
&self,
1200-
_: Logger,
1201-
_: &DeploymentHash,
1202-
) -> Result<Arc<dyn WritableStore>, StoreError> {
1203-
unimplemented!()
1204-
}
1205-
1206-
fn locators(&self, _: &str) -> Result<Vec<DeploymentLocator>, StoreError> {
1207-
unimplemented!()
1208-
}
1209-
}
1210-
1211-
// The store trait must be implemented manually because mockall does not support async_trait, nor borrowing from arguments.
1212-
#[async_trait]
1213-
impl WritableStore for MockStore {
1214-
fn block_ptr(&self) -> Result<Option<BlockPtr>, StoreError> {
1215-
unimplemented!()
1216-
}
1217-
1218-
fn block_cursor(&self) -> Result<Option<String>, StoreError> {
1219-
unimplemented!()
1220-
}
1221-
1222-
fn start_subgraph_deployment(&self, _: &Logger) -> Result<(), StoreError> {
1223-
unimplemented!()
1224-
}
1225-
1226-
fn revert_block_operations(&self, _: BlockPtr) -> Result<(), StoreError> {
1227-
unimplemented!()
1228-
}
1229-
1230-
fn unfail_deterministic_error(&self, _: &BlockPtr, _: &BlockPtr) -> Result<(), StoreError> {
1231-
unimplemented!()
1232-
}
1233-
1234-
fn unfail_non_deterministic_error(&self, _: &BlockPtr) -> Result<(), StoreError> {
1235-
unimplemented!()
1236-
}
1237-
1238-
async fn fail_subgraph(&self, _: SubgraphError) -> Result<(), StoreError> {
1239-
unimplemented!()
1240-
}
1241-
1242-
async fn supports_proof_of_indexing(&self) -> Result<bool, StoreError> {
1243-
unimplemented!()
1244-
}
1245-
1246-
fn get(&self, _: &EntityKey) -> Result<Option<Entity>, StoreError> {
1247-
unimplemented!()
1248-
}
1249-
1250-
fn transact_block_operations(
1251-
&self,
1252-
_: BlockPtr,
1253-
_: Option<String>,
1254-
_: Vec<EntityModification>,
1255-
_: StopwatchMetrics,
1256-
_: Vec<StoredDynamicDataSource>,
1257-
_: Vec<SubgraphError>,
1258-
) -> Result<(), StoreError> {
1259-
unimplemented!()
1260-
}
1261-
1262-
fn get_many(
1263-
&self,
1264-
ids_for_type: BTreeMap<&EntityType, Vec<&str>>,
1265-
) -> Result<BTreeMap<EntityType, Vec<Entity>>, StoreError> {
1266-
self.get_many_mock(ids_for_type)
1267-
}
1268-
1269-
async fn is_deployment_synced(&self) -> Result<bool, StoreError> {
1270-
unimplemented!()
1271-
}
1272-
1273-
fn unassign_subgraph(&self) -> Result<(), StoreError> {
1274-
unimplemented!()
1275-
}
1276-
1277-
async fn load_dynamic_data_sources(&self) -> Result<Vec<StoredDynamicDataSource>, StoreError> {
1278-
unimplemented!()
1279-
}
1280-
1281-
fn deployment_synced(&self) -> Result<(), StoreError> {
1282-
unimplemented!()
1283-
}
1284-
1285-
fn shard(&self) -> &str {
1286-
unimplemented!()
1287-
}
1288-
1289-
async fn health(&self, _: &DeploymentHash) -> Result<SubgraphHealth, StoreError> {
1290-
unimplemented!()
1291-
}
1292-
1293-
fn input_schema(&self) -> Arc<Schema> {
1294-
unimplemented!()
1295-
}
1296-
}
1297-
12981131
pub trait BlockStore: Send + Sync + 'static {
12991132
type ChainStore: ChainStore;
13001133

graph/tests/entity_cache.rs

Lines changed: 105 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
use graph::prelude::SubgraphStore;
1+
use async_trait::async_trait;
2+
use graph::blockchain::BlockPtr;
3+
use graph::data::subgraph::schema::{SubgraphError, SubgraphHealth};
4+
use graph::prelude::{Schema, StopwatchMetrics, StoreError};
25
use lazy_static::lazy_static;
3-
use slog::{o, Logger};
6+
use mockall::predicate::*;
7+
use mockall::*;
8+
use slog::Logger;
49
use std::collections::BTreeMap;
510
use std::sync::Arc;
611

7-
use graph::{components::store::EntityType, mock::MockStore};
12+
use graph::components::store::{EntityType, StoredDynamicDataSource, WritableStore};
813
use graph::{
914
components::store::{DeploymentId, DeploymentLocator},
1015
prelude::{DeploymentHash, Entity, EntityCache, EntityKey, EntityModification, Value},
@@ -16,6 +21,102 @@ lazy_static! {
1621
DeploymentLocator::new(DeploymentId::new(-12), SUBGRAPH_ID.clone());
1722
}
1823

24+
mock! {
25+
pub Store {
26+
fn get_many_mock<'a>(
27+
&self,
28+
_ids_for_type: BTreeMap<&'a EntityType, Vec<&'a str>>,
29+
) -> Result<BTreeMap<EntityType, Vec<Entity>>, StoreError>;
30+
}
31+
}
32+
33+
// The store trait must be implemented manually because mockall does not support async_trait, nor borrowing from arguments.
34+
#[async_trait]
35+
impl WritableStore for MockStore {
36+
fn block_ptr(&self) -> Result<Option<BlockPtr>, StoreError> {
37+
unimplemented!()
38+
}
39+
40+
fn block_cursor(&self) -> Result<Option<String>, StoreError> {
41+
unimplemented!()
42+
}
43+
44+
fn start_subgraph_deployment(&self, _: &Logger) -> Result<(), StoreError> {
45+
unimplemented!()
46+
}
47+
48+
fn revert_block_operations(&self, _: BlockPtr) -> Result<(), StoreError> {
49+
unimplemented!()
50+
}
51+
52+
fn unfail_deterministic_error(&self, _: &BlockPtr, _: &BlockPtr) -> Result<(), StoreError> {
53+
unimplemented!()
54+
}
55+
56+
fn unfail_non_deterministic_error(&self, _: &BlockPtr) -> Result<(), StoreError> {
57+
unimplemented!()
58+
}
59+
60+
async fn fail_subgraph(&self, _: SubgraphError) -> Result<(), StoreError> {
61+
unimplemented!()
62+
}
63+
64+
async fn supports_proof_of_indexing(&self) -> Result<bool, StoreError> {
65+
unimplemented!()
66+
}
67+
68+
fn get(&self, _: &EntityKey) -> Result<Option<Entity>, StoreError> {
69+
unimplemented!()
70+
}
71+
72+
fn transact_block_operations(
73+
&self,
74+
_: BlockPtr,
75+
_: Option<String>,
76+
_: Vec<EntityModification>,
77+
_: StopwatchMetrics,
78+
_: Vec<StoredDynamicDataSource>,
79+
_: Vec<SubgraphError>,
80+
) -> Result<(), StoreError> {
81+
unimplemented!()
82+
}
83+
84+
fn get_many(
85+
&self,
86+
ids_for_type: BTreeMap<&EntityType, Vec<&str>>,
87+
) -> Result<BTreeMap<EntityType, Vec<Entity>>, StoreError> {
88+
self.get_many_mock(ids_for_type)
89+
}
90+
91+
async fn is_deployment_synced(&self) -> Result<bool, StoreError> {
92+
unimplemented!()
93+
}
94+
95+
fn unassign_subgraph(&self) -> Result<(), StoreError> {
96+
unimplemented!()
97+
}
98+
99+
async fn load_dynamic_data_sources(&self) -> Result<Vec<StoredDynamicDataSource>, StoreError> {
100+
unimplemented!()
101+
}
102+
103+
fn deployment_synced(&self) -> Result<(), StoreError> {
104+
unimplemented!()
105+
}
106+
107+
fn shard(&self) -> &str {
108+
unimplemented!()
109+
}
110+
111+
async fn health(&self, _: &DeploymentHash) -> Result<SubgraphHealth, StoreError> {
112+
unimplemented!()
113+
}
114+
115+
fn input_schema(&self) -> Arc<Schema> {
116+
unimplemented!()
117+
}
118+
}
119+
19120
fn make_band(id: &'static str, data: Vec<(&str, Value)>) -> (EntityKey, Entity) {
20121
(
21122
EntityKey::data(SUBGRAPH_ID.clone(), "Band".to_string(), id.into()),
@@ -30,11 +131,7 @@ fn sort_by_entity_key(mut mods: Vec<EntityModification>) -> Vec<EntityModificati
30131

31132
#[tokio::test]
32133
async fn empty_cache_modifications() {
33-
let logger = Logger::root(slog::Discard, o!());
34-
let store = Arc::new(MockStore::new())
35-
.writable(logger, DEPLOYMENT.id)
36-
.await
37-
.unwrap();
134+
let store = Arc::new(MockStore::new());
38135
let cache = EntityCache::new(store.clone());
39136
let result = cache.as_modifications();
40137
assert_eq!(result.unwrap().modifications, vec![]);

0 commit comments

Comments
 (0)