Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Oracle price feeders add verification of empty subscribed pairs (backport #675) #677

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions price-feeder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

- [#648](https://github.com/umee-network/umee/pull/648) Add Coinbase as a provider.

### Bug Fixes

- [#675](https://github.com/umee-network/umee/pull/675) Add necessary input validation to SubscribePairs in the price feeder.

## [v0.1.3](https://github.com/umee-network/umee/releases/tag/price-feeder%2Fv0.1.3) - 2022-03-21

### Features
Expand Down
4 changes: 4 additions & 0 deletions price-feeder/oracle/provider/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func (p *BinanceProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[stri

// SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.
func (p *BinanceProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error {
if len(cps) == 0 {
return fmt.Errorf("currency pairs is empty")
}

if err := p.subscribeChannels(cps...); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions price-feeder/oracle/provider/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func TestBinanceProvider_GetTickerPrices(t *testing.T) {
})
}

func TestBinanceProvider_SubscribeCurrencyPairs(t *testing.T) {
p, err := NewBinanceProvider(context.TODO(), zerolog.Nop(), types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.NoError(t, err)

t.Run("invalid_subscribe_channels_empty", func(t *testing.T) {
err = p.SubscribeCurrencyPairs([]types.CurrencyPair{}...)
require.ErrorContains(t, err, "currency pairs is empty")
})
}

func TestBinanceCurrencyPairToBinancePair(t *testing.T) {
cp := types.CurrencyPair{Base: "ATOM", Quote: "USDT"}
binanceSymbol := currencyPairToBinanceTickerPair(cp)
Expand Down
5 changes: 5 additions & 0 deletions price-feeder/oracle/provider/coinbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,14 @@ func (p *CoinbaseProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[str

// SubscribeCurrencyPairs subscribes to websockets for all currency pairs.
func (p *CoinbaseProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error {
if len(cps) == 0 {
return fmt.Errorf("currency pairs is empty")
}

if err := p.subscribe(cps...); err != nil {
return err
}

p.setSubscribedPairs(cps...)
telemetry.IncrCounter(
float32(len(cps)),
Expand Down
10 changes: 10 additions & 0 deletions price-feeder/oracle/provider/coinbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ func TestCoinbaseProvider_GetTickerPrices(t *testing.T) {
})
}

func TestCoinbaseProvider_SubscribeCurrencyPairs(t *testing.T) {
p, err := NewCoinbaseProvider(context.TODO(), zerolog.Nop(), types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.NoError(t, err)

t.Run("invalid_subscribe_channels_empty", func(t *testing.T) {
err = p.SubscribeCurrencyPairs([]types.CurrencyPair{}...)
require.ErrorContains(t, err, "currency pairs is empty")
})
}

func TestCoinbasePairToCurrencyPair(t *testing.T) {
cp := types.CurrencyPair{Base: "ATOM", Quote: "USDT"}
currencyPairSymbol := coinbasePairToCurrencyPair("ATOM-USDT")
Expand Down
4 changes: 4 additions & 0 deletions price-feeder/oracle/provider/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func (p *GateProvider) getCandlePrices(key string) ([]CandlePrice, error) {

// SubscribeCurrencyPairs subscribe to ticker and candle channels for all pairs.
func (p *GateProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error {
if len(cps) == 0 {
return fmt.Errorf("currency pairs is empty")
}

if err := p.subscribeTickers(cps...); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions price-feeder/oracle/provider/gate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func TestGateProvider_GetTickerPrices(t *testing.T) {
})
}

func TestGateProvider_SubscribeCurrencyPairs(t *testing.T) {
p, err := NewGateProvider(context.TODO(), zerolog.Nop(), types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.NoError(t, err)

t.Run("invalid_subscribe_channels_empty", func(t *testing.T) {
err = p.SubscribeCurrencyPairs([]types.CurrencyPair{}...)
require.ErrorContains(t, err, "currency pairs is empty")
})
}

func TestGateCurrencyPairToGatePair(t *testing.T) {
cp := types.CurrencyPair{Base: "ATOM", Quote: "USDT"}
GateSymbol := currencyPairToGatePair(cp)
Expand Down
4 changes: 4 additions & 0 deletions price-feeder/oracle/provider/huobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func (p *HuobiProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string

// SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.
func (p *HuobiProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error {
if len(cps) == 0 {
return fmt.Errorf("currency pairs is empty")
}

if err := p.subscribeChannels(cps...); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions price-feeder/oracle/provider/huobi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ func TestHuobiProvider_GetTickerPrices(t *testing.T) {
})
}

func TestHuobiProvider_SubscribeCurrencyPairs(t *testing.T) {
p, err := NewHuobiProvider(context.TODO(), zerolog.Nop(), types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.NoError(t, err)

t.Run("invalid_subscribe_channels_empty", func(t *testing.T) {
err = p.SubscribeCurrencyPairs([]types.CurrencyPair{}...)
require.ErrorContains(t, err, "currency pairs is empty")
})
}

func TestHuobiCurrencyPairToHuobiPair(t *testing.T) {
cp := types.CurrencyPair{Base: "ATOM", Quote: "USDT"}
binanceSymbol := currencyPairToHuobiTickerPair(cp)
Expand Down
4 changes: 4 additions & 0 deletions price-feeder/oracle/provider/kraken.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ func (p *KrakenProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[strin

// SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.
func (p *KrakenProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error {
if len(cps) == 0 {
return fmt.Errorf("currency pairs is empty")
}

if err := p.subscribeChannels(cps...); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions price-feeder/oracle/provider/kraken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ func TestKrakenProvider_GetTickerPrices(t *testing.T) {
})
}

func TestKrakenProvider_SubscribeCurrencyPairs(t *testing.T) {
p, err := NewKrakenProvider(context.TODO(), zerolog.Nop(), types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.NoError(t, err)

t.Run("invalid_subscribe_channels_empty", func(t *testing.T) {
err = p.SubscribeCurrencyPairs([]types.CurrencyPair{}...)
require.ErrorContains(t, err, "currency pairs is empty")
})
}

func TestKrakenPairToCurrencyPairSymbol(t *testing.T) {
cp := types.CurrencyPair{Base: "ATOM", Quote: "USDT"}
currencyPairSymbol := krakenPairToCurrencyPairSymbol("ATOM/USDT")
Expand Down
4 changes: 4 additions & 0 deletions price-feeder/oracle/provider/okx.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func (p *OkxProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][

// SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.
func (p *OkxProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error {
if len(cps) == 0 {
return fmt.Errorf("currency pairs is empty")
}

if err := p.subscribeChannels(cps...); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions price-feeder/oracle/provider/okx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ func TestOkxProvider_GetTickerPrices(t *testing.T) {
})
}

func TestOkxProvider_SubscribeCurrencyPairs(t *testing.T) {
p, err := NewOkxProvider(context.TODO(), zerolog.Nop(), types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.NoError(t, err)

t.Run("invalid_subscribe_channels_empty", func(t *testing.T) {
err = p.SubscribeCurrencyPairs([]types.CurrencyPair{}...)
require.ErrorContains(t, err, "currency pairs is empty")
})
}

func TestOkxCurrencyPairToOkxPair(t *testing.T) {
cp := types.CurrencyPair{Base: "ATOM", Quote: "USDT"}
okxSymbol := currencyPairToOkxPair(cp)
Expand Down