github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/snowman/block/batched_vm_test.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 "time" 11 12 "github.com/stretchr/testify/require" 13 14 "github.com/MetalBlockchain/metalgo/database" 15 "github.com/MetalBlockchain/metalgo/ids" 16 "github.com/MetalBlockchain/metalgo/snow/consensus/snowman" 17 "github.com/MetalBlockchain/metalgo/utils/logging" 18 ) 19 20 var errTest = errors.New("non-nil error") 21 22 func TestGetAncestorsDatabaseNotFound(t *testing.T) { 23 require := require.New(t) 24 25 vm := &TestVM{} 26 someID := ids.GenerateTestID() 27 vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { 28 require.Equal(someID, id) 29 return nil, database.ErrNotFound 30 } 31 containers, err := GetAncestors(context.Background(), logging.NoLog{}, vm, someID, 10, 10, 1*time.Second) 32 require.NoError(err) 33 require.Empty(containers) 34 } 35 36 // TestGetAncestorsPropagatesErrors checks errors other than 37 // database.ErrNotFound propagate to caller. 38 func TestGetAncestorsPropagatesErrors(t *testing.T) { 39 require := require.New(t) 40 41 vm := &TestVM{} 42 someID := ids.GenerateTestID() 43 vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { 44 require.Equal(someID, id) 45 return nil, errTest 46 } 47 containers, err := GetAncestors(context.Background(), logging.NoLog{}, vm, someID, 10, 10, 1*time.Second) 48 require.Nil(containers) 49 require.ErrorIs(err, errTest) 50 }