diff --git a/core/services/ocr2/plugins/ocr2vrf/juelsfeecoin/link_eth_price_provider.go b/core/services/ocr2/plugins/ocr2vrf/juelsfeecoin/link_eth_price_provider.go index 9073b88def5..4b0e40048e3 100644 --- a/core/services/ocr2/plugins/ocr2vrf/juelsfeecoin/link_eth_price_provider.go +++ b/core/services/ocr2/plugins/ocr2vrf/juelsfeecoin/link_eth_price_provider.go @@ -18,6 +18,7 @@ import ( type linkEthPriceProvider struct { aggregator aggregator_v3_interface.AggregatorV3InterfaceInterface timeout time.Duration + stubbed bool } var _ types.JuelsPerFeeCoin = (*linkEthPriceProvider)(nil) @@ -27,10 +28,14 @@ func NewLinkEthPriceProvider(linkEthFeedAddress common.Address, client evmclient if err != nil { return nil, errors.Wrap(err, "new aggregator v3 interface") } - return &linkEthPriceProvider{aggregator: aggregator, timeout: timeout}, nil + // Return the stubbed implementation, as we are not currently using juelsPerFeeCoin. + return &linkEthPriceProvider{aggregator: aggregator, timeout: timeout, stubbed: true}, nil } func (p *linkEthPriceProvider) JuelsPerFeeCoin() (*big.Int, error) { + if p.stubbed { + return p.juelsPerFeeCoinStubbed() + } ctx, cancel := context.WithTimeout(context.Background(), p.timeout) defer cancel() roundData, err := p.aggregator.LatestRoundData(&bind.CallOpts{Context: ctx}) @@ -39,3 +44,8 @@ func (p *linkEthPriceProvider) JuelsPerFeeCoin() (*big.Int, error) { } return roundData.Answer, nil } + +// Stubbed implementation, returns 0 and does not make an RPC call. +func (p *linkEthPriceProvider) juelsPerFeeCoinStubbed() (*big.Int, error) { + return big.NewInt(0), nil +} diff --git a/core/services/ocr2/plugins/ocr2vrf/juelsfeecoin/link_eth_price_provider_test.go b/core/services/ocr2/plugins/ocr2vrf/juelsfeecoin/link_eth_price_provider_test.go index f834b3a3a40..13899235836 100644 --- a/core/services/ocr2/plugins/ocr2vrf/juelsfeecoin/link_eth_price_provider_test.go +++ b/core/services/ocr2/plugins/ocr2vrf/juelsfeecoin/link_eth_price_provider_test.go @@ -38,4 +38,26 @@ func Test_JuelsPerFeeCoin(t *testing.T) { assert.Nil(t, price) assert.Equal(t, "get aggregator latest answer: network failure", err.Error()) }) + + t.Run("returns juels per fee coin", func(t *testing.T) { + latestRoundData := aggregator_v3_interface.LatestRoundData{Answer: big.NewInt(10000)} + mockAggregator.On("LatestRoundData", mock.Anything).Return(latestRoundData, nil) + p := linkEthPriceProvider{aggregator: mockAggregator, stubbed: true} + price, err := p.JuelsPerFeeCoin() + + require.NoError(t, err) + assert.Equal(t, int64(0), price.Int64()) + mockAggregator.AssertNotCalled(t, "LatestRoundData") + }) + + t.Run("returns error when contract call fails", func(t *testing.T) { + latestRoundData := aggregator_v3_interface.LatestRoundData{} + mockAggregator.On("LatestRoundData", mock.Anything).Return(latestRoundData, errors.New("network failure")) + p := linkEthPriceProvider{aggregator: mockAggregator, stubbed: true} + price, err := p.JuelsPerFeeCoin() + + require.NoError(t, err) + assert.Zero(t, price.Int64()) + mockAggregator.AssertNotCalled(t, "LatestRoundData") + }) }