@@ -341,10 +341,12 @@ func TestPreCommitActions(t *testing.T) {
341341}
342342
343343func TestHeaderBackendImplementation (t * testing.T ) {
344- backendMock := mocks.NewBackend [hash.H256 , uint64 , runtime.BlakeTwo256 , * generic.Header [uint64 , hash.H256 , runtime.BlakeTwo256 ],
344+ backendMock := mocks.NewBackend [hash.H256 , uint64 , runtime.BlakeTwo256 ,
345+ * generic.Header [uint64 , hash.H256 , runtime.BlakeTwo256 ],
345346 runtime.OpaqueExtrinsic ](t )
346347
347- blockchainMock := mocks.NewBlockchainBackend [hash.H256 , uint64 , * generic.Header [uint64 , hash.H256 , runtime.BlakeTwo256 ], runtime.OpaqueExtrinsic ](t )
348+ blockchainMock := mocks.NewBlockchainBackend [hash.H256 , uint64 ,
349+ * generic.Header [uint64 , hash.H256 , runtime.BlakeTwo256 ], runtime.OpaqueExtrinsic ](t )
348350
349351 expectedHeader := generic .NewHeader [uint64 , hash.H256 , runtime.BlakeTwo256 ](
350352 1 ,
@@ -429,3 +431,99 @@ func TestHeaderBackendImplementation(t *testing.T) {
429431 require .NotNil (t , blockNumber )
430432 require .Equal (t , expectedNumber , * blockNumber )
431433}
434+
435+ func TestBlockBackendImplementation (t * testing.T ) {
436+ backendMock := mocks.NewBackend [hash.H256 , uint64 , runtime.BlakeTwo256 ,
437+ * generic.Header [uint64 , hash.H256 , runtime.BlakeTwo256 ],
438+ runtime.OpaqueExtrinsic ](t )
439+
440+ blockchainMock := mocks.NewBlockchainBackend [hash.H256 , uint64 ,
441+ * generic.Header [uint64 , hash.H256 , runtime.BlakeTwo256 ], runtime.OpaqueExtrinsic ](t )
442+
443+ c := New (backendMock )
444+
445+ expectedHeader := generic .NewHeader [uint64 , hash.H256 , runtime.BlakeTwo256 ](
446+ 1 ,
447+ hash .H256 ("extrinsicsroot" ),
448+ hash .H256 ("stateroot" ),
449+ hash .H256 ("parent" ),
450+ runtime.Digest {},
451+ )
452+ expectedHash := expectedHeader .Hash ()
453+ expectedNumber := expectedHeader .Number ()
454+
455+ blockchainMock .EXPECT ().Header (expectedHash ).Return (& expectedHeader , nil )
456+ blockchainMock .EXPECT ().Hash (expectedNumber ).Return (& expectedHash , nil )
457+
458+ expectedExtrinsics := []runtime.OpaqueExtrinsic {}
459+ blockchainMock .EXPECT ().Body (expectedHash ).Return (expectedExtrinsics , nil )
460+
461+ expectedStatus := blockchain .BlockStatusInChain
462+ blockchainMock .EXPECT ().Status (expectedHash ).Return (expectedStatus , nil )
463+
464+ expectedIndexedExtrinsics := [][]byte {
465+ []byte ("extrinsic1" ),
466+ []byte ("extrinsic2" ),
467+ }
468+
469+ blockchainMock .EXPECT ().BlockIndexedBody (expectedHash ).Return (expectedIndexedExtrinsics , nil )
470+
471+ var expectedJustifications runtime.Justifications = nil
472+ blockchainMock .EXPECT ().Justifications (expectedHash ).Return (expectedJustifications , nil )
473+
474+ expectedIndexedTransaction := []byte ("transaction1" )
475+ blockchainMock .EXPECT ().IndexedTransaction (expectedHash ).Return (expectedIndexedTransaction , nil )
476+ blockchainMock .EXPECT ().HasIndexedTransaction (expectedHash ).Return (true , nil )
477+
478+ backendMock .EXPECT ().RequiresFullSync ().Return (true )
479+ backendMock .EXPECT ().Blockchain ().Return (blockchainMock )
480+
481+ // Get BlockBody
482+ extrinsics , err := c .BlockBody (expectedHash )
483+ require .NoError (t , err )
484+ require .Equal (t , expectedExtrinsics , extrinsics )
485+
486+ // Get BlockIndexedBody
487+ indexedBody , err := c .BlockIndexedBody (expectedHash )
488+ require .NoError (t , err )
489+ require .Equal (t , expectedIndexedExtrinsics , indexedBody )
490+
491+ // Get Block
492+ expectedBlock := generic .NewSignedBlock (
493+ generic .NewBlock [uint64 , hash.H256 , runtime.BlakeTwo256 ](expectedHeader , expectedExtrinsics ), nil ,
494+ )
495+ block , err := c .Block (expectedHash )
496+ require .NoError (t , err )
497+ require .Equal (t , expectedBlock , block )
498+
499+ // Get BlockStatus
500+ blockStatus , err := c .BlockStatus (expectedHash )
501+ require .NoError (t , err )
502+ require .Equal (t , expectedStatus , blockStatus )
503+
504+ // Get Justifications
505+ justifications , err := c .Justifications (expectedHash )
506+ require .NoError (t , err )
507+ require .Equal (t , expectedJustifications , justifications )
508+
509+ // Get BlockHash
510+ blockHash , err := c .BlockHash (expectedNumber )
511+ require .NoError (t , err )
512+ require .NotNil (t , blockHash )
513+ require .Equal (t , expectedHash , * blockHash )
514+
515+ // Get IndexedTransaction
516+ indexedTransaction , err := c .IndexedTransaction (expectedHash )
517+ require .NoError (t , err )
518+ require .Equal (t , expectedIndexedTransaction , indexedTransaction )
519+
520+ // HasIndexedTransactions
521+ has , err := c .HasIndexedTransaction (expectedHash )
522+ require .NoError (t , err )
523+ require .True (t , has )
524+
525+ // RequiresFullSync
526+ requiresFullSync := c .RequiresFullSync ()
527+ require .NoError (t , err )
528+ require .True (t , requiresFullSync )
529+ }
0 commit comments