From 7042da1e03faedbebf3bf5940feabece847edbc9 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Thu, 27 Jul 2017 16:02:12 +1000 Subject: [PATCH] Fixed linter issues and added test files --- config_routes.go | 7 +++++- exchanges/exchange.go | 26 ++++++++++++++----- exchanges/exchange_test.go | 16 ++++++------ main.go | 51 +++++++++++++++++++++++++++++++------- main_test.go | 27 ++++++++++++++++++++ orders.go | 22 ++++++++++------ orders_test.go | 37 +++++++++++++++++++++++++++ restful_logger.go | 1 + restful_router.go | 2 ++ restful_router_test.go | 11 ++++++++ restful_routes.go | 2 ++ ticker_routes.go | 20 ++++++++++++--- ticker_routes_test.go | 1 + tools/config/config.go | 5 +++- wallet_routes.go | 13 +++++++++- wallet_routes_test.go | 28 +++++++++++++++++++++ 16 files changed, 230 insertions(+), 39 deletions(-) create mode 100644 main_test.go create mode 100644 orders_test.go create mode 100644 restful_router_test.go create mode 100644 ticker_routes_test.go create mode 100644 wallet_routes_test.go diff --git a/config_routes.go b/config_routes.go index 32897fa4..28413d7a 100644 --- a/config_routes.go +++ b/config_routes.go @@ -7,6 +7,8 @@ import ( "github.com/thrasher-/gocryptotrader/config" ) +// GetAllSettings replies to a request with an encoded JSON response about the +// trading bots configuration. func GetAllSettings(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) @@ -15,6 +17,8 @@ func GetAllSettings(w http.ResponseWriter, r *http.Request) { } } +// SaveAllSettings saves all current settings from request body as a JSON +// document then reloads state and returns the settings func SaveAllSettings(w http.ResponseWriter, r *http.Request) { //Get the data from the request decoder := json.NewDecoder(r.Body) @@ -24,7 +28,7 @@ func SaveAllSettings(w http.ResponseWriter, r *http.Request) { panic(jsonerr) } //Save change the settings - for x, _ := range bot.config.Exchanges { + for x := range bot.config.Exchanges { for i := 0; i < len(responseData.Data.Exchanges); i++ { if responseData.Data.Exchanges[i].Name == bot.config.Exchanges[x].Name { bot.config.Exchanges[x].Enabled = responseData.Data.Exchanges[i].Enabled @@ -52,6 +56,7 @@ func SaveAllSettings(w http.ResponseWriter, r *http.Request) { } } +// ConfigRoutes declares the current routes for config_routes.go var ConfigRoutes = Routes{ Route{ "GetAllSettings", diff --git a/exchanges/exchange.go b/exchanges/exchange.go index 0f555aa8..be24b4c1 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -12,23 +12,26 @@ import ( ) const ( - WarningBase64DecryptSecretKeyFailed = "WARNING -- Exchange %s unable to base64 decode secret key.. Disabling Authenticated API support." - ErrExchangeNotFound = "Exchange not found in dataset." + warningBase64DecryptSecretKeyFailed = "WARNING -- Exchange %s unable to base64 decode secret key.. Disabling Authenticated API support." + // ErrExchangeNotFound is a constant for an error message + ErrExchangeNotFound = "Exchange not found in dataset." ) -//ExchangeAccountInfo : Generic type to hold each exchange's holdings in all enabled currencies +// ExchangeAccountInfo is a Generic type to hold each exchange's holdings in +// all enabled currencies type ExchangeAccountInfo struct { ExchangeName string Currencies []ExchangeAccountCurrencyInfo } -//ExchangeAccountCurrencyInfo : Sub type to store currency name and value +// ExchangeAccountCurrencyInfo is a sub type to store currency name and value type ExchangeAccountCurrencyInfo struct { CurrencyName string TotalValue float64 Hold float64 } +// ExchangeBase stores the individual exchange information type ExchangeBase struct { Name string Enabled bool @@ -45,7 +48,8 @@ type ExchangeBase struct { APIUrl string } -//IBotExchange : Enforces standard functions for all exchanges supported in gocryptotrader +// IBotExchange enforces standard functions for all exchanges supported in +// GoCryptoTrader type IBotExchange interface { Setup(exch config.ExchangeConfig) Start() @@ -58,20 +62,28 @@ type IBotExchange interface { GetExchangeAccountInfo() (ExchangeAccountInfo, error) } +// GetName is a method that returns the name of the exchange base func (e *ExchangeBase) GetName() string { return e.Name } + +// GetEnabledCurrencies is a method that returns the enabled currency pairs of +// the exchange base func (e *ExchangeBase) GetEnabledCurrencies() []string { return e.EnabledPairs } + +// SetEnabled is a method that sets if the exchange is enabled func (e *ExchangeBase) SetEnabled(enabled bool) { e.Enabled = enabled } +// IsEnabled is a method that returns if the current exchange is enabled func (e *ExchangeBase) IsEnabled() bool { return e.Enabled } +// SetAPIKeys is a method that sets the current API keys for the exchange func (e *ExchangeBase) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) { e.APIKey = APIKey e.ClientID = ClientID @@ -80,7 +92,7 @@ func (e *ExchangeBase) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode result, err := common.Base64Decode(APISecret) if err != nil { e.AuthenticatedAPISupport = false - log.Printf(WarningBase64DecryptSecretKeyFailed, e.Name) + log.Printf(warningBase64DecryptSecretKeyFailed, e.Name) } e.APISecret = string(result) } else { @@ -88,6 +100,8 @@ func (e *ExchangeBase) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode } } +// UpdateAvailableCurrencies is a method that sets new pairs to the current +// exchange func (e *ExchangeBase) UpdateAvailableCurrencies(exchangeProducts []string) error { exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",") diff := common.StringSliceDifference(e.AvailablePairs, exchangeProducts) diff --git a/exchanges/exchange_test.go b/exchanges/exchange_test.go index 80165f98..9c7062f3 100644 --- a/exchanges/exchange_test.go +++ b/exchanges/exchange_test.go @@ -60,25 +60,23 @@ func TestSetAPIKeys(t *testing.T) { } SetAPIKeys.SetAPIKeys("RocketMan", "Digereedoo", "007", false) - if SetAPIKeys.APIKey != "RocketMan" && SetAPIKeys.APISecret != "Digereedoo" && SetAPIKeys.ClientID != "007" { t.Error("Test Failed - Exchange SetAPIKeys() did not set correct values") } - + SetAPIKeys.SetAPIKeys("RocketMan", "Digereedoo", "007", true) } func TestUpdateAvailableCurrencies(t *testing.T) { cfg := config.GetConfig() err := cfg.LoadConfig(config.ConfigTestFile) - if err != nil { - t.Log("SOMETHING DONE HAPPENED!") - } - - UAC := ExchangeBase{ - Name: "ANX", - } + UAC := ExchangeBase{Name: "ANX"} exchangeProducts := []string{"ltc", "btc", "usd", "aud"} + if err != nil { + t.Error( + "Test Failed - Exchange UpdateAvailableCurrencies() did not set correct values", + ) + } err2 := UAC.UpdateAvailableCurrencies(exchangeProducts) if err2 != nil { t.Errorf("Test Failed - Exchange UpdateAvailableCurrencies() error: %s", err2) diff --git a/main.go b/main.go index e4d5a4b3..de51b53d 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,7 @@ import ( "github.com/thrasher-/gocryptotrader/smsglobal" ) +// ExchangeMain contains all the necessary exchange packages type ExchangeMain struct { anx anx.ANX btcc btcc.BTCC @@ -56,6 +57,8 @@ type ExchangeMain struct { kraken kraken.Kraken } +// Bot contains configuration, portfolio, exchange & ticker data and is the +// overarching type across this code base. type Bot struct { config *config.Config portfolio *portfolio.Base @@ -74,10 +77,18 @@ func setupBotExchanges() { if bot.exchanges[i].GetName() == exch.Name { bot.exchanges[i].Setup(exch) if bot.exchanges[i].IsEnabled() { - log.Printf("%s: Exchange support: %s (Authenticated API support: %s - Verbose mode: %s).\n", exch.Name, common.IsEnabled(exch.Enabled), common.IsEnabled(exch.AuthenticatedAPISupport), common.IsEnabled(exch.Verbose)) + log.Printf( + "%s: Exchange support: %s (Authenticated API support: %s - Verbose mode: %s).\n", + exch.Name, common.IsEnabled(exch.Enabled), + common.IsEnabled(exch.AuthenticatedAPISupport), + common.IsEnabled(exch.Verbose), + ) bot.exchanges[i].Start() } else { - log.Printf("%s: Exchange support: %s\n", exch.Name, common.IsEnabled(exch.Enabled)) + log.Printf( + "%s: Exchange support: %s\n", exch.Name, + common.IsEnabled(exch.Enabled), + ) } } } @@ -104,13 +115,19 @@ func main() { log.Println(err) // non fatal event bot.config.SMS.Enabled = false } else { - log.Printf("SMS support enabled. Number of SMS contacts %d.\n", smsglobal.GetEnabledSMSContacts(bot.config.SMS)) + log.Printf( + "SMS support enabled. Number of SMS contacts %d.\n", + smsglobal.GetEnabledSMSContacts(bot.config.SMS), + ) } } else { log.Println("SMS support disabled.") } - log.Printf("Available Exchanges: %d. Enabled Exchanges: %d.\n", len(bot.config.Exchanges), bot.config.GetConfigEnabledExchanges()) + log.Printf( + "Available Exchanges: %d. Enabled Exchanges: %d.\n", + len(bot.config.Exchanges), bot.config.GetConfigEnabledExchanges(), + ) log.Println("Bot Exchange support:") bot.exchanges = []exchange.IBotExchange{ @@ -137,7 +154,10 @@ func main() { for i := 0; i < len(bot.exchanges); i++ { if bot.exchanges[i] != nil { bot.exchanges[i].SetDefaults() - log.Printf("Exchange %s successfully set default settings.\n", bot.exchanges[i].GetName()) + log.Printf( + "Exchange %s successfully set default settings.\n", + bot.exchanges[i].GetName(), + ) } } @@ -164,7 +184,10 @@ func main() { //bot.config.Webserver.Enabled = false } else { listenAddr := bot.config.Webserver.ListenAddress - log.Printf("HTTP Webserver support enabled. Listen URL: http://%s:%d/\n", common.ExtractHost(listenAddr), common.ExtractPort(listenAddr)) + log.Printf( + "HTTP Webserver support enabled. Listen URL: http://%s:%d/\n", + common.ExtractHost(listenAddr), common.ExtractPort(listenAddr), + ) router := NewRouter(bot.exchanges) log.Fatal(http.ListenAndServe(listenAddr, router)) } @@ -177,6 +200,7 @@ func main() { Shutdown() } +// AdjustGoMaxProcs adjusts the maximum processes that the CPU can handle. func AdjustGoMaxProcs() { log.Println("Adjusting bot runtime performance..") maxProcsEnv := os.Getenv("GOMAXPROCS") @@ -186,17 +210,20 @@ func AdjustGoMaxProcs() { if maxProcsEnv != "" { log.Println("GOMAXPROCS env =", maxProcsEnv) env, err := strconv.Atoi(maxProcsEnv) - if err != nil { log.Println("Unable to convert GOMAXPROCS to int, using", maxProcs) } else { maxProcs = env } } + if i := runtime.GOMAXPROCS(maxProcs); i != maxProcs { + log.Fatal("Go Max Procs were not set correctly.") + } log.Println("Set GOMAXPROCS to:", maxProcs) - runtime.GOMAXPROCS(maxProcs) } +// HandleInterrupt monitors and captures the SIGTERM in a new goroutine then +// shuts down bot func HandleInterrupt() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) @@ -207,6 +234,7 @@ func HandleInterrupt() { }() } +// Shutdown correctly shuts down bot saving configuration files func Shutdown() { log.Println("Bot shutting down..") bot.config.Portfolio = portfolio.Portfolio @@ -222,6 +250,7 @@ func Shutdown() { os.Exit(1) } +// SeedExchangeAccountInfo seeds account info func SeedExchangeAccountInfo(data []exchange.ExchangeAccountInfo) { if len(data) == 0 { return @@ -242,7 +271,11 @@ func SeedExchangeAccountInfo(data []exchange.ExchangeAccountInfo) { } if !port.ExchangeAddressExists(exchangeName, currencyName) { - port.Addresses = append(port.Addresses, portfolio.Address{Address: exchangeName, CoinType: currencyName, Balance: total, Decscription: portfolio.PortfolioAddressExchange}) + port.Addresses = append( + port.Addresses, + portfolio.Address{Address: exchangeName, CoinType: currencyName, + Balance: total, Decscription: portfolio.PortfolioAddressExchange}, + ) } else { port.UpdateExchangeAddressBalance(exchangeName, currencyName, total) } diff --git a/main_test.go b/main_test.go new file mode 100644 index 00000000..2c0f70d9 --- /dev/null +++ b/main_test.go @@ -0,0 +1,27 @@ +package main + +import "testing" + +func TestSetupBotExchanges(t *testing.T) { + // setupBotExchanges() +} + +func TestMain(t *testing.T) { + // Nothing +} + +func TestAdjustGoMaxProcs(t *testing.T) { + AdjustGoMaxProcs() +} + +func TestHandleInterrupt(t *testing.T) { + HandleInterrupt() +} + +func TestShutdown(t *testing.T) { + // Nothing +} + +func TestSeedExchangeAccountInfo(t *testing.T) { + SeedExchangeAccountInfo(GetAllEnabledExchangeAccountInfo().Data) +} diff --git a/orders.go b/orders.go index 95a72803..bf13cb1f 100644 --- a/orders.go +++ b/orders.go @@ -1,12 +1,14 @@ package main const ( - LIMIT_ORDER = iota - MARKET_ORDER + limitOrder = iota + marketOrder ) +// Orders variable holds an array of pointers to order structs var Orders []*Order +// Order struct holds order values type Order struct { OrderID int Exchange string @@ -15,6 +17,7 @@ type Order struct { Price float64 } +// NewOrder creates a new order and returns a an orderID func NewOrder(Exchange string, amount, price float64) int { order := &Order{} if len(Orders) == 0 { @@ -30,6 +33,7 @@ func NewOrder(Exchange string, amount, price float64) int { return order.OrderID } +// DeleteOrder deletes orders by ID and returns state func DeleteOrder(orderID int) bool { for i := range Orders { if Orders[i].OrderID == orderID { @@ -40,7 +44,8 @@ func DeleteOrder(orderID int) bool { return false } -func GetOrdersByExchange(exchange string) ([]*Order, bool) { +// GetOrdersByExchange returns order pointer grouped by exchange +func GetOrdersByExchange(exchange string) []*Order { orders := []*Order{} for i := range Orders { if Orders[i].Exchange == exchange { @@ -48,16 +53,17 @@ func GetOrdersByExchange(exchange string) ([]*Order, bool) { } } if len(orders) > 0 { - return orders, true + return orders } - return nil, false + return nil } -func GetOrderByOrderID(orderID int) (*Order, bool) { +// GetOrderByOrderID returns order pointer by ID +func GetOrderByOrderID(orderID int) *Order { for i := range Orders { if Orders[i].OrderID == orderID { - return Orders[i], true + return Orders[i] } } - return nil, false + return nil } diff --git a/orders_test.go b/orders_test.go new file mode 100644 index 00000000..f41fd8cf --- /dev/null +++ b/orders_test.go @@ -0,0 +1,37 @@ +package main + +import ( + "testing" +) + +func TestNewOrder(t *testing.T) { + ID := NewOrder("ANX", 2000, 20.00) + if ID != 0 { + t.Error("Test Failed - Orders_test.go NewOrder() - Error") + } + ID = NewOrder("BATMAN", 400, 25.00) + if ID != 1 { + t.Error("Test Failed - Orders_test.go NewOrder() - Error") + } +} + +func TestDeleteOrder(t *testing.T) { + if value := DeleteOrder(0); !value { + t.Error("Test Failed - Orders_test.go DeleteOrder() - Error") + } + if value := DeleteOrder(100); value { + t.Error("Test Failed - Orders_test.go DeleteOrder() - Error") + } +} + +func TestGetOrdersByExchange(t *testing.T) { + if value := GetOrdersByExchange("ANX"); len(value) != 0 { + t.Error("Test Failed - Orders_test.go GetOrdersByExchange() - Error") + } +} + +func TestGetOrderByOrderID(t *testing.T) { + if value := GetOrderByOrderID(69); value != nil { + t.Error("Test Failed - Orders_test.go GetOrdersByExchange() - Error") + } +} diff --git a/restful_logger.go b/restful_logger.go index 3f002e31..2025c5a3 100644 --- a/restful_logger.go +++ b/restful_logger.go @@ -6,6 +6,7 @@ import ( "time" ) +// Logger logs the requests internally func Logger(inner http.Handler, name string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { start := time.Now() diff --git a/restful_router.go b/restful_router.go index e675e8f5..bc97ff40 100644 --- a/restful_router.go +++ b/restful_router.go @@ -7,6 +7,8 @@ import ( "github.com/thrasher-/gocryptotrader/exchanges" ) +// NewRouter takes in the exchange interfaces and returns a new multiplexor +// router func NewRouter(exchanges []exchange.IBotExchange) *mux.Router { router := mux.NewRouter().StrictSlash(true) allRoutes := append(routes, ExchangeRoutes...) diff --git a/restful_router_test.go b/restful_router_test.go new file mode 100644 index 00000000..e7fd9cf8 --- /dev/null +++ b/restful_router_test.go @@ -0,0 +1,11 @@ +package main + +import ( + "testing" +) + +func TestNewRouter(t *testing.T) { + if value := NewRouter(bot.exchanges); value.KeepContext { + t.Error("Test Failed - Restful_Router_Test.go - NewRouter Error") + } +} diff --git a/restful_routes.go b/restful_routes.go index 1e7a9626..4728f9be 100644 --- a/restful_routes.go +++ b/restful_routes.go @@ -2,6 +2,7 @@ package main import "net/http" +// Route is a sub type that holds the request routes type Route struct { Name string Method string @@ -9,6 +10,7 @@ type Route struct { HandlerFunc http.HandlerFunc } +// Routes is an array of all the registered routes type Routes []Route var routes = Routes{} diff --git a/ticker_routes.go b/ticker_routes.go index 44d764a6..4ec16ea3 100644 --- a/ticker_routes.go +++ b/ticker_routes.go @@ -19,7 +19,9 @@ func jsonTickerResponse(w http.ResponseWriter, r *http.Request) { for i := 0; i < len(bot.exchanges); i++ { if bot.exchanges[i] != nil { if bot.exchanges[i].IsEnabled() && bot.exchanges[i].GetName() == exchangeName { - response, err = bot.exchanges[i].GetTickerPrice(pair.NewCurrencyPairFromString(currency)) + response, err = bot.exchanges[i].GetTickerPrice( + pair.NewCurrencyPairFromString(currency), + ) if err != nil { log.Println(err) continue @@ -37,10 +39,13 @@ func jsonTickerResponse(w http.ResponseWriter, r *http.Request) { } } +// AllEnabledExchangeCurrencies holds the enabled exchange currencies type AllEnabledExchangeCurrencies struct { Data []EnabledExchangeCurrencies `json:"data"` } +// EnabledExchangeCurrencies is a sub type for singular exchanges and respective +// currencies type EnabledExchangeCurrencies struct { ExchangeName string `json:"exchangeName"` ExchangeValues []ticker.TickerPrice `json:"exchangeValues"` @@ -53,17 +58,23 @@ func getAllActiveTickersResponse(w http.ResponseWriter, r *http.Request) { if individualBot != nil && individualBot.IsEnabled() { var individualExchange EnabledExchangeCurrencies individualExchange.ExchangeName = individualBot.GetName() - log.Println("Getting enabled currencies for '" + individualBot.GetName() + "'") + log.Println( + "Getting enabled currencies for '" + individualBot.GetName() + "'", + ) currencies := individualBot.GetEnabledCurrencies() log.Println(currencies) for _, currency := range currencies { - tickerPrice, err := individualBot.GetTickerPrice(pair.NewCurrencyPairFromString(currency)) + tickerPrice, err := individualBot.GetTickerPrice( + pair.NewCurrencyPairFromString(currency), + ) if err != nil { continue } log.Println(tickerPrice) - individualExchange.ExchangeValues = append(individualExchange.ExchangeValues, tickerPrice) + individualExchange.ExchangeValues = append( + individualExchange.ExchangeValues, tickerPrice, + ) } response.Data = append(response.Data, individualExchange) } @@ -75,6 +86,7 @@ func getAllActiveTickersResponse(w http.ResponseWriter, r *http.Request) { } } +// ExchangeRoutes denotes the current exchange routes var ExchangeRoutes = Routes{ Route{ "AllActiveExchangesAndCurrencies", diff --git a/ticker_routes_test.go b/ticker_routes_test.go new file mode 100644 index 00000000..06ab7d0f --- /dev/null +++ b/ticker_routes_test.go @@ -0,0 +1 @@ +package main diff --git a/tools/config/config.go b/tools/config/config.go index 8e8eba81..a9eeea50 100644 --- a/tools/config/config.go +++ b/tools/config/config.go @@ -73,5 +73,8 @@ func main() { if err != nil { log.Fatalf("Unable to write output file %s. Error: %s", outFile, err) } - log.Printf("Successfully %s input file %s and wrote output to %s.\n", EncryptOrDecrypt(encrypt), inFile, outFile) + log.Printf( + "Successfully %s input file %s and wrote output to %s.\n", + EncryptOrDecrypt(encrypt), inFile, outFile, + ) } diff --git a/wallet_routes.go b/wallet_routes.go index 7efa0298..93b6b570 100644 --- a/wallet_routes.go +++ b/wallet_routes.go @@ -9,10 +9,14 @@ import ( "github.com/thrasher-/gocryptotrader/exchanges" ) +// AllEnabledExchangeAccounts holds all enabled accounts info type AllEnabledExchangeAccounts struct { Data []exchange.ExchangeAccountInfo `json:"data"` } +// GetCollatedExchangeAccountInfoByCoin collates individual exchange account +// information and turns into into a map string of +// exchange.ExchangeAccountCurrencyInfo func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.ExchangeAccountInfo) map[string]exchange.ExchangeAccountCurrencyInfo { result := make(map[string]exchange.ExchangeAccountCurrencyInfo) for i := 0; i < len(accounts); i++ { @@ -35,6 +39,7 @@ func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.ExchangeAccountInf return result } +// GetAccountCurrencyInfoByExchangeName returns info for an exchange func GetAccountCurrencyInfoByExchangeName(accounts []exchange.ExchangeAccountInfo, exchangeName string) (exchange.ExchangeAccountInfo, error) { for i := 0; i < len(accounts); i++ { if accounts[i].ExchangeName == exchangeName { @@ -44,13 +49,16 @@ func GetAccountCurrencyInfoByExchangeName(accounts []exchange.ExchangeAccountInf return exchange.ExchangeAccountInfo{}, errors.New(exchange.ErrExchangeNotFound) } +// GetAllEnabledExchangeAccountInfo returns all the current enabled exchanges func GetAllEnabledExchangeAccountInfo() AllEnabledExchangeAccounts { var response AllEnabledExchangeAccounts for _, individualBot := range bot.exchanges { if individualBot != nil && individualBot.IsEnabled() { individualExchange, err := individualBot.GetExchangeAccountInfo() if err != nil { - log.Println("Error encountered retrieving exchange account for '" + individualExchange.ExchangeName + "'") + log.Println( + "Error encountered retrieving exchange account for '" + individualExchange.ExchangeName + "'", + ) } response.Data = append(response.Data, individualExchange) } @@ -58,6 +66,8 @@ func GetAllEnabledExchangeAccountInfo() AllEnabledExchangeAccounts { return response } +// SendAllEnabledAccountInfo via get request returns JSON response of account +// info func SendAllEnabledAccountInfo(w http.ResponseWriter, r *http.Request) { response := GetAllEnabledExchangeAccountInfo() w.Header().Set("Content-Type", "application/json; charset=UTF-8") @@ -67,6 +77,7 @@ func SendAllEnabledAccountInfo(w http.ResponseWriter, r *http.Request) { } } +// WalletRoutes are current routes specified for queries. var WalletRoutes = Routes{ Route{ "AllEnabledAccountInfo", diff --git a/wallet_routes_test.go b/wallet_routes_test.go new file mode 100644 index 00000000..b8f5d9b9 --- /dev/null +++ b/wallet_routes_test.go @@ -0,0 +1,28 @@ +package main + +import ( + "testing" +) + +func TestGetCollatedExchangeAccountInfoByCoin(t *testing.T) { + GetCollatedExchangeAccountInfoByCoin(GetAllEnabledExchangeAccountInfo().Data) +} + +func TestGetAccountCurrencyInfoByExchangeName(t *testing.T) { + _, err := GetAccountCurrencyInfoByExchangeName( + GetAllEnabledExchangeAccountInfo().Data, "ANX", + ) + if err == nil { + t.Error( + "Test Failed - Wallet_Routes_Test.go - GetAccountCurrencyInfoByExchangeName", + ) + } +} + +func TestGetAllEnabledExchangeAccountInfo(t *testing.T) { + if value := GetAllEnabledExchangeAccountInfo(); len(value.Data) != 0 { + t.Error( + "Test Failed - Wallet_Routes_Test.go - GetAllEnabledExchangeAccountInfo", + ) + } +}