github.com/onflow/flow-go@v0.33.17/engine/execution/ingestion/loader/unfinalized_loader_test.go (about) 1 package loader_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/engine/execution/ingestion" 10 "github.com/onflow/flow-go/engine/execution/ingestion/loader" 11 stateMock "github.com/onflow/flow-go/engine/execution/state/mock" 12 "github.com/onflow/flow-go/model/flow" 13 storage "github.com/onflow/flow-go/storage/mock" 14 "github.com/onflow/flow-go/utils/unittest" 15 "github.com/onflow/flow-go/utils/unittest/mocks" 16 ) 17 18 var _ ingestion.BlockLoader = (*loader.UnfinalizedLoader)(nil) 19 20 func TestLoadingUnfinalizedBlocks(t *testing.T) { 21 ps := mocks.NewProtocolState() 22 23 // Genesis <- A <- B <- C (finalized) <- D 24 chain, result, seal := unittest.ChainFixture(5) 25 genesis, blockA, blockB, blockC, blockD := 26 chain[0], chain[1], chain[2], chain[3], chain[4] 27 28 logChain(chain) 29 30 require.NoError(t, ps.Bootstrap(genesis, result, seal)) 31 require.NoError(t, ps.Extend(blockA)) 32 require.NoError(t, ps.Extend(blockB)) 33 require.NoError(t, ps.Extend(blockC)) 34 require.NoError(t, ps.Extend(blockD)) 35 require.NoError(t, ps.Finalize(blockC.ID())) 36 37 es := new(stateMock.FinalizedExecutionState) 38 es.On("GetHighestFinalizedExecuted").Return(genesis.Header.Height) 39 headers := new(storage.Headers) 40 headers.On("BlockIDByHeight", blockA.Header.Height).Return(blockA.Header.ID(), nil) 41 headers.On("BlockIDByHeight", blockB.Header.Height).Return(blockB.Header.ID(), nil) 42 headers.On("BlockIDByHeight", blockC.Header.Height).Return(blockC.Header.ID(), nil) 43 44 loader := loader.NewUnfinalizedLoader(unittest.Logger(), ps, headers, es) 45 46 unexecuted, err := loader.LoadUnexecuted(context.Background()) 47 require.NoError(t, err) 48 49 unittest.IDsEqual(t, []flow.Identifier{ 50 blockA.ID(), 51 blockB.ID(), 52 blockC.ID(), 53 blockD.ID(), 54 }, unexecuted) 55 }