Skip to content

Commit

Permalink
OCR2VRF - stub juelsperfeecoin (#8263)
Browse files Browse the repository at this point in the history
  • Loading branch information
vreff authored Jan 18, 2023
1 parent 74116d9 commit 2aeba0a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type linkEthPriceProvider struct {
aggregator aggregator_v3_interface.AggregatorV3InterfaceInterface
timeout time.Duration
stubbed bool
}

var _ types.JuelsPerFeeCoin = (*linkEthPriceProvider)(nil)
Expand All @@ -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})
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}

0 comments on commit 2aeba0a

Please sign in to comment.