diff --git a/price-feeder/CHANGELOG.md b/price-feeder/CHANGELOG.md index 0ba823cb44..769753c654 100644 --- a/price-feeder/CHANGELOG.md +++ b/price-feeder/CHANGELOG.md @@ -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 diff --git a/price-feeder/oracle/provider/binance.go b/price-feeder/oracle/provider/binance.go index 56623aaa5f..d7a9abc86a 100644 --- a/price-feeder/oracle/provider/binance.go +++ b/price-feeder/oracle/provider/binance.go @@ -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 } diff --git a/price-feeder/oracle/provider/binance_test.go b/price-feeder/oracle/provider/binance_test.go index f7acbaa1b1..bd0fe93c9b 100644 --- a/price-feeder/oracle/provider/binance_test.go +++ b/price-feeder/oracle/provider/binance_test.go @@ -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) diff --git a/price-feeder/oracle/provider/coinbase.go b/price-feeder/oracle/provider/coinbase.go index 627a51d52d..854536d361 100644 --- a/price-feeder/oracle/provider/coinbase.go +++ b/price-feeder/oracle/provider/coinbase.go @@ -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)), diff --git a/price-feeder/oracle/provider/coinbase_test.go b/price-feeder/oracle/provider/coinbase_test.go index b3e2ebf06b..4eda712810 100644 --- a/price-feeder/oracle/provider/coinbase_test.go +++ b/price-feeder/oracle/provider/coinbase_test.go @@ -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") diff --git a/price-feeder/oracle/provider/gate.go b/price-feeder/oracle/provider/gate.go index 6946889412..b5f8296505 100644 --- a/price-feeder/oracle/provider/gate.go +++ b/price-feeder/oracle/provider/gate.go @@ -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 } diff --git a/price-feeder/oracle/provider/gate_test.go b/price-feeder/oracle/provider/gate_test.go index b780b55c1d..56047744a8 100644 --- a/price-feeder/oracle/provider/gate_test.go +++ b/price-feeder/oracle/provider/gate_test.go @@ -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) diff --git a/price-feeder/oracle/provider/huobi.go b/price-feeder/oracle/provider/huobi.go index 6455adfdac..d27809e31c 100644 --- a/price-feeder/oracle/provider/huobi.go +++ b/price-feeder/oracle/provider/huobi.go @@ -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 } diff --git a/price-feeder/oracle/provider/huobi_test.go b/price-feeder/oracle/provider/huobi_test.go index 9b87c5848b..98a0ca3ed3 100644 --- a/price-feeder/oracle/provider/huobi_test.go +++ b/price-feeder/oracle/provider/huobi_test.go @@ -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) diff --git a/price-feeder/oracle/provider/kraken.go b/price-feeder/oracle/provider/kraken.go index d619b3e19b..5ef7295f4d 100644 --- a/price-feeder/oracle/provider/kraken.go +++ b/price-feeder/oracle/provider/kraken.go @@ -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 } diff --git a/price-feeder/oracle/provider/kraken_test.go b/price-feeder/oracle/provider/kraken_test.go index bc4b7753e5..ec030f7135 100644 --- a/price-feeder/oracle/provider/kraken_test.go +++ b/price-feeder/oracle/provider/kraken_test.go @@ -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") diff --git a/price-feeder/oracle/provider/okx.go b/price-feeder/oracle/provider/okx.go index c50abcb1a1..f294eb261f 100644 --- a/price-feeder/oracle/provider/okx.go +++ b/price-feeder/oracle/provider/okx.go @@ -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 } diff --git a/price-feeder/oracle/provider/okx_test.go b/price-feeder/oracle/provider/okx_test.go index bb49ed02da..574880546e 100644 --- a/price-feeder/oracle/provider/okx_test.go +++ b/price-feeder/oracle/provider/okx_test.go @@ -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)