From c01c7f8dccaf2ec217277dd72adbaadab66ac434 Mon Sep 17 00:00:00 2001 From: Will Winder Date: Thu, 19 Dec 2024 13:01:22 -0500 Subject: [PATCH] Add test for finality violation. --- pkg/contractreader/extended_test.go | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/contractreader/extended_test.go b/pkg/contractreader/extended_test.go index 2b716efa..efd91411 100644 --- a/pkg/contractreader/extended_test.go +++ b/pkg/contractreader/extended_test.go @@ -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" @@ -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) +}