Skip to content

Commit

Permalink
Add test for finality violation.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Dec 19, 2024
1 parent 8c8e37e commit c01c7f8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/contractreader/extended_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

chainreadermocks "github.com/smartcontractkit/chainlink-ccip/mocks/pkg/contractreader"
"github.com/smartcontractkit/chainlink-ccip/pkg/contractreader"
Expand Down Expand Up @@ -58,3 +62,34 @@ func TestDoubleWrap(t *testing.T) {
doubleWrapped := contractreader.NewExtendedContractReader(cr)
require.Equal(t, wrapped, doubleWrapped)
}

func TestFinalityViolation(t *testing.T) {
cr := chainreadermocks.NewMockContractReaderFacade(t)
cr.EXPECT().HealthReport().Return(map[string]error{"farmerwolfcabbagegoat": types.ErrFinalityViolated}).Times(3)
cr.EXPECT().QueryKey(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil)
cr.EXPECT().GetLatestValue(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
cr.EXPECT().BatchGetLatestValues(mock.Anything, mock.Anything).Return(nil, nil)

wrapped := contractreader.NewExtendedContractReader(cr)

_, err := wrapped.QueryKey(
tests.Context(t),
types.BoundContract{},
query.KeyFilter{},
query.LimitAndSort{},
nil)
require.ErrorIs(t, err, contractreader.ErrFinalityViolated)

err = wrapped.GetLatestValue(
tests.Context(t),
"",
primitives.Finalized,
nil,
nil)
require.ErrorIs(t, err, contractreader.ErrFinalityViolated)

_, err = wrapped.BatchGetLatestValues(
tests.Context(t),
types.BatchGetLatestValuesRequest{})
require.ErrorIs(t, err, contractreader.ErrFinalityViolated)
}

0 comments on commit c01c7f8

Please sign in to comment.