1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- use amaru_kernel:: { protocol_parameters:: GlobalParameters , EraHistory , Nonce , Point , RawBlock } ;
15+ use amaru_kernel:: {
16+ network:: NetworkName , protocol_parameters:: GlobalParameters , EraHistory , Header , Nonce , Point ,
17+ RawBlock ,
18+ } ;
1619use amaru_ouroboros:: { praos:: nonce, Nonces } ;
1720use amaru_ouroboros_traits:: { IsHeader , Praos } ;
1821use pallas_crypto:: hash:: Hash ;
1922use slot_arithmetic:: TimeHorizonError ;
20- use std:: fmt:: Display ;
23+ use std:: { collections :: BTreeMap , fmt:: Display } ;
2124use thiserror:: Error ;
2225
23- #[ derive( Error , PartialEq , Debug ) ]
26+ #[ derive( Error , PartialEq , Debug , serde :: Serialize , serde :: Deserialize ) ]
2427pub enum StoreError {
2528 WriteError { error : String } ,
2629 ReadError { error : String } ,
@@ -86,7 +89,7 @@ impl<H: IsHeader> ChainStore<H> for Box<dyn ChainStore<H>> {
8689 }
8790}
8891
89- #[ derive( Error , Debug , PartialEq ) ]
92+ #[ derive( Error , Debug , PartialEq , serde :: Serialize , serde :: Deserialize ) ]
9093pub enum NoncesError {
9194 #[ error( "cannot find nonces: unknown parent {parent} from header {header}" ) ]
9295 UnknownParent { header : Hash < 32 > , parent : Hash < 32 > } ,
@@ -189,6 +192,44 @@ impl<H: IsHeader> Praos<H> for dyn ChainStore<H> {
189192 }
190193}
191194
195+ #[ derive( Default ) ]
196+ pub struct FakeStore {
197+ headers : BTreeMap < Hash < 32 > , Header > ,
198+ nonces : BTreeMap < Hash < 32 > , Nonces > ,
199+ }
200+
201+ impl ChainStore < Header > for FakeStore {
202+ fn load_header ( & self , hash : & Hash < 32 > ) -> Option < Header > {
203+ self . headers . get ( hash) . cloned ( )
204+ }
205+
206+ fn store_header ( & mut self , hash : & Hash < 32 > , header : & Header ) -> Result < ( ) , StoreError > {
207+ self . headers . insert ( * hash, header. clone ( ) ) ;
208+ Ok ( ( ) )
209+ }
210+
211+ fn get_nonces ( & self , header : & Hash < 32 > ) -> Option < Nonces > {
212+ self . nonces . get ( header) . cloned ( )
213+ }
214+
215+ fn put_nonces ( & mut self , header : & Hash < 32 > , nonces : & Nonces ) -> Result < ( ) , StoreError > {
216+ self . nonces . insert ( * header, nonces. clone ( ) ) ;
217+ Ok ( ( ) )
218+ }
219+
220+ fn era_history ( & self ) -> & EraHistory {
221+ NetworkName :: Preprod . into ( )
222+ }
223+
224+ fn load_block ( & self , _hash : & Hash < 32 > ) -> Result < RawBlock , StoreError > {
225+ unimplemented ! ( )
226+ }
227+
228+ fn store_block ( & mut self , _hash : & Hash < 32 > , _block : & RawBlock ) -> Result < ( ) , StoreError > {
229+ unimplemented ! ( )
230+ }
231+ }
232+
192233#[ cfg( test) ]
193234mod test {
194235 use super :: * ;
@@ -197,7 +238,7 @@ mod test {
197238 use amaru_ouroboros_traits:: { IsHeader , Praos } ;
198239 use proptest:: { prelude:: * , prop_compose, proptest} ;
199240 use slot_arithmetic:: Epoch ;
200- use std:: { collections :: BTreeMap , sync:: LazyLock } ;
241+ use std:: sync:: LazyLock ;
201242
202243 // Epoch 164's last header
203244 include_header ! ( PREPROD_HEADER_69638382 , 69638382 ) ;
@@ -242,44 +283,6 @@ mod test {
242283 tail : hash ! ( "d6fe6439aed8bddc10eec22c1575bf0648e4a76125387d9e985e9a3f8342870d" ) ,
243284 } ) ;
244285
245- #[ derive( Default ) ]
246- struct FakeStore {
247- headers : BTreeMap < Hash < 32 > , Header > ,
248- nonces : BTreeMap < Hash < 32 > , Nonces > ,
249- }
250-
251- impl ChainStore < Header > for FakeStore {
252- fn load_header ( & self , hash : & Hash < 32 > ) -> Option < Header > {
253- self . headers . get ( hash) . cloned ( )
254- }
255-
256- fn store_header ( & mut self , hash : & Hash < 32 > , header : & Header ) -> Result < ( ) , StoreError > {
257- self . headers . insert ( * hash, header. clone ( ) ) ;
258- Ok ( ( ) )
259- }
260-
261- fn get_nonces ( & self , header : & Hash < 32 > ) -> Option < Nonces > {
262- self . nonces . get ( header) . cloned ( )
263- }
264-
265- fn put_nonces ( & mut self , header : & Hash < 32 > , nonces : & Nonces ) -> Result < ( ) , StoreError > {
266- self . nonces . insert ( * header, nonces. clone ( ) ) ;
267- Ok ( ( ) )
268- }
269-
270- fn era_history ( & self ) -> & EraHistory {
271- NetworkName :: Preprod . into ( )
272- }
273-
274- fn load_block ( & self , _hash : & Hash < 32 > ) -> Result < RawBlock , StoreError > {
275- unimplemented ! ( )
276- }
277-
278- fn store_block ( & mut self , _hash : & Hash < 32 > , _block : & RawBlock ) -> Result < ( ) , StoreError > {
279- unimplemented ! ( )
280- }
281- }
282-
283286 fn evolve_nonce (
284287 last_header_last_epoch : & Header ,
285288 parent : ( & Header , & Nonces ) ,
0 commit comments