github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/snowman/block/test_state_summary.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package block 5 6 import ( 7 "context" 8 "errors" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 13 "github.com/MetalBlockchain/metalgo/ids" 14 ) 15 16 var ( 17 _ StateSummary = (*TestStateSummary)(nil) 18 19 errAccept = errors.New("unexpectedly called Accept") 20 ) 21 22 type TestStateSummary struct { 23 IDV ids.ID 24 HeightV uint64 25 BytesV []byte 26 27 T *testing.T 28 CantAccept bool 29 AcceptF func(context.Context) (StateSyncMode, error) 30 } 31 32 func (s *TestStateSummary) ID() ids.ID { 33 return s.IDV 34 } 35 36 func (s *TestStateSummary) Height() uint64 { 37 return s.HeightV 38 } 39 40 func (s *TestStateSummary) Bytes() []byte { 41 return s.BytesV 42 } 43 44 func (s *TestStateSummary) Accept(ctx context.Context) (StateSyncMode, error) { 45 if s.AcceptF != nil { 46 return s.AcceptF(ctx) 47 } 48 if s.CantAccept && s.T != nil { 49 require.FailNow(s.T, errAccept.Error()) 50 } 51 return StateSyncSkipped, errAccept 52 }