Exchanges: Don't set or update currencies when supplied with a nil array

This commit is contained in:
Adrian Gallagher
2018-10-23 15:10:56 +11:00
parent a94d88debf
commit d0f5f46c9d
2 changed files with 21 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package exchange
import (
"errors"
"fmt"
"log"
"net/http"
"sync"
@@ -475,6 +476,10 @@ func (e *Base) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) {
// SetCurrencies sets the exchange currency pairs for either enabledPairs or
// availablePairs
func (e *Base) SetCurrencies(pairs []pair.CurrencyPair, enabledPairs bool) error {
if len(pairs) == 0 {
return fmt.Errorf("%s SetCurrencies error - pairs is empty", e.Name)
}
cfg := config.GetConfig()
exchCfg, err := cfg.GetExchangeConfig(e.Name)
if err != nil {
@@ -501,6 +506,10 @@ func (e *Base) SetCurrencies(pairs []pair.CurrencyPair, enabledPairs bool) error
// UpdateCurrencies updates the exchange currency pairs for either enabledPairs or
// availablePairs
func (e *Base) UpdateCurrencies(exchangeProducts []string, enabled, force bool) error {
if len(exchangeProducts) == 0 {
return fmt.Errorf("%s UpdateCurrencies error - exchangeProducts is empty", e.Name)
}
exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",")
var products []string

View File

@@ -669,6 +669,11 @@ func TestSetCurrencies(t *testing.T) {
if !pair.Contains(UAC.GetAvailableCurrencies(), newPair, true) {
t.Fatal("Test failed. TestSetCurrencies failed to set currencies")
}
err = UAC.SetCurrencies(nil, false)
if err == nil {
t.Fatal("Test failed. TestSetCurrencies should return an error when attempting to set an empty pairs array")
}
}
func TestUpdateCurrencies(t *testing.T) {
@@ -744,6 +749,13 @@ func TestUpdateCurrencies(t *testing.T) {
if err != nil {
t.Errorf("Test Failed - Forced Exchange UpdateCurrencies() error: %s", err)
}
// Test that empty exchange products should return an error
exchangeProducts = nil
err = UAC.UpdateCurrencies(exchangeProducts, false, false)
if err == nil {
t.Errorf("Test failed - empty available pairs should return an error")
}
}
func TestAPIURL(t *testing.T) {