@@ -81,6 +81,7 @@ impl SharedProofOfIndexing {
8181#[ cfg( test) ]
8282mod 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 ! ( ) ) ;
0 commit comments