Skip to content

Commit 89be3cb

Browse files
committed
graph: Move 'struct PoI' into tests module
Otherwise, we get warnings about unused code
1 parent dc0068a commit 89be3cb

2 files changed

Lines changed: 29 additions & 34 deletions

File tree

graph/src/components/subgraph/proof_of_indexing/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl SharedProofOfIndexing {
8181
#[cfg(test)]
8282
mod tests {
8383
use super::*;
84+
use crate::util::stable_hash_glue::{impl_stable_hash, AsBytes};
8485
use crate::{
8586
data::store::Id,
8687
prelude::{BlockPtr, DeploymentHash, Value},
@@ -97,6 +98,33 @@ mod tests {
9798
use std::convert::TryInto;
9899
use web3::types::{Address, H256};
99100

101+
/// The PoI is the StableHash of this struct. This reference implementation is
102+
/// mostly here just to make sure that the online implementation is
103+
/// well-implemented (without conflicting sequence numbers, or other oddities).
104+
/// It's just way easier to check that this works, and serves as a kind of
105+
/// documentation as a side-benefit.
106+
pub struct PoI<'a> {
107+
pub causality_regions: HashMap<String, PoICausalityRegion<'a>>,
108+
pub subgraph_id: DeploymentHash,
109+
pub block_hash: H256,
110+
pub indexer: Option<Address>,
111+
}
112+
113+
fn h256_as_bytes(val: &H256) -> AsBytes<&[u8]> {
114+
AsBytes(val.as_bytes())
115+
}
116+
117+
fn indexer_opt_as_bytes(val: &Option<Address>) -> Option<AsBytes<&[u8]>> {
118+
val.as_ref().map(|v| AsBytes(v.as_bytes()))
119+
}
120+
121+
impl_stable_hash!(PoI<'_> {
122+
causality_regions,
123+
subgraph_id,
124+
block_hash: h256_as_bytes,
125+
indexer: indexer_opt_as_bytes
126+
});
127+
100128
/// Verify that the stable hash of a reference and online implementation match
101129
fn check(case: Case, cache: &mut HashMap<String, &str>) {
102130
let logger = Logger::root(Discard, o!());

graph/src/components/subgraph/proof_of_indexing/reference.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,5 @@
11
use super::ProofOfIndexingEvent;
2-
use crate::prelude::DeploymentHash;
3-
use crate::util::stable_hash_glue::{impl_stable_hash, AsBytes};
4-
use std::collections::HashMap;
5-
use web3::types::{Address, H256};
6-
7-
/// The PoI is the StableHash of this struct. This reference implementation is
8-
/// mostly here just to make sure that the online implementation is
9-
/// well-implemented (without conflicting sequence numbers, or other oddities).
10-
/// It's just way easier to check that this works, and serves as a kind of
11-
/// documentation as a side-benefit.
12-
#[allow(dead_code)]
13-
pub struct PoI<'a> {
14-
pub causality_regions: HashMap<String, PoICausalityRegion<'a>>,
15-
pub subgraph_id: DeploymentHash,
16-
pub block_hash: H256,
17-
pub indexer: Option<Address>,
18-
}
19-
20-
#[allow(dead_code)]
21-
fn h256_as_bytes(val: &H256) -> AsBytes<&[u8]> {
22-
AsBytes(val.as_bytes())
23-
}
24-
25-
#[allow(dead_code)]
26-
fn indexer_opt_as_bytes(val: &Option<Address>) -> Option<AsBytes<&[u8]>> {
27-
val.as_ref().map(|v| AsBytes(v.as_bytes()))
28-
}
29-
30-
impl_stable_hash!(PoI<'_> {
31-
causality_regions,
32-
subgraph_id,
33-
block_hash: h256_as_bytes,
34-
indexer: indexer_opt_as_bytes
35-
});
2+
use crate::util::stable_hash_glue::impl_stable_hash;
363

374
pub struct PoICausalityRegion<'a> {
385
pub blocks: Vec<Block<'a>>,

0 commit comments

Comments
 (0)