Files
gocryptotrader/currency/currency_test.go
Scott ccfcdf26aa Engine: Protocol Features, coverage, types, BTC markets websocket (#368)
* Attempts to update orderbook so it doesn't need to sort

* Reverts the ws ob stuff. Gets rid of sorting because it happens later. Adds some exchange features

* update existing feature lists. Expands list definition to match my emotions

* Adds bithumb bitmex and bitstamp. adds a couple more types

* Features for you, features for me, features for bittrex, btcmarkets, btse, coinbasepro, coinut, exmo, gateio and gemini

* Features for hitbtc, huobi, itbit, kraken, lakebtc, lbank, localbitcoins, okcoin, okex, poloniex, yobit, zb

* Who can forget good old alphapoint?

* Adds btcmarksets websocket :glitch_crab: fixes alphapoint features

* Adds extra data not in the documentation :/

* Replaces websocket features by using protocol features. However, it breaks it due to import cycles. I'm not sure what I'll do just yet

* Removes import cycle via duplicate structs.

* Increases coverage of config with `TestCheckCurrencyConfigValues`. Moves all currency pair package types into their own files or places it at the bottom of files if necessary

* Increase coverage in code.go

* One way of determining a test has failed, is when to it fails. Removed redundant explanation

* Increases code coverage of conversion

* Lint fixes

* Fixes orderbook tests

* Re-adds sorting because its important to still have the internal pre-processed orderbook to be representative of a real orderbook

* Secret lints that did not show up via Windows linting

* Adds protocol package to contain exchange features

* Fixes protocol implementation

* Fixes ws tests

* Addresses the following: Removes st-st-stutters in config types, changes GetAvailableForexProviders -> GetSupportedForexProviders, removes errors from tests where error is nil, removes orderbook setup when not necessary, removes import newlines, removes false bools from declaration, changes should of to should have

* imports and casing

* Fixes two more nil error checks
2019-10-22 10:56:20 +11:00

127 lines
2.8 KiB
Go

package currency
import (
"testing"
)
func TestGetDefaultExchangeRates(t *testing.T) {
rates, err := GetDefaultExchangeRates()
if err != nil {
t.Error("GetDefaultExchangeRates() err", err)
}
for _, val := range rates {
if !val.IsFiat() {
t.Errorf("GetDefaultExchangeRates() %s is not fiat pair",
val)
}
}
}
func TestGetExchangeRates(t *testing.T) {
rates, err := GetExchangeRates()
if err != nil {
t.Error("GetExchangeRates() err", err)
}
for _, val := range rates {
if !val.IsFiat() {
t.Errorf("GetExchangeRates() %s is not fiat pair",
val)
}
}
}
func TestUpdateBaseCurrency(t *testing.T) {
err := UpdateBaseCurrency(AUD)
if err != nil {
t.Error("UpdateBaseCurrency() err", err)
}
err = UpdateBaseCurrency(LTC)
if err == nil {
t.Error("UpdateBaseCurrency() error cannot be nil")
}
if GetBaseCurrency() != AUD {
t.Errorf("GetBaseCurrency() expected %s but received %s",
AUD, GetBaseCurrency())
}
}
func TestGetDefaultBaseCurrency(t *testing.T) {
if GetDefaultBaseCurrency() != USD {
t.Errorf("GetDefaultBaseCurrency() expected %s but received %s",
USD, GetDefaultBaseCurrency())
}
}
func TestGetDefaulCryptoCurrencies(t *testing.T) {
expected := Currencies{BTC, LTC, ETH, DOGE, DASH, XRP, XMR}
if !GetDefaultCryptocurrencies().Match(expected) {
t.Errorf("GetDefaultCryptocurrencies() expected %s but received %s",
expected, GetDefaultCryptocurrencies())
}
}
func TestGetDefaultFiatCurrencies(t *testing.T) {
expected := Currencies{USD, AUD, EUR, CNY}
if !GetDefaultFiatCurrencies().Match(expected) {
t.Errorf("GetDefaultFiatCurrencies() expected %s but received %s",
expected, GetDefaultFiatCurrencies())
}
}
func TestUpdateCurrencies(t *testing.T) {
fiat := Currencies{HKN, JPY}
UpdateCurrencies(fiat, false)
rFiat := GetFiatCurrencies()
if !rFiat.Contains(HKN) || !rFiat.Contains(JPY) {
t.Error("UpdateCurrencies() currencies did not update")
}
crypto := Currencies{ZAR, ZCAD, B2}
UpdateCurrencies(crypto, true)
rCrypto := GetCryptocurrencies()
if !rCrypto.Contains(ZAR) || !rCrypto.Contains(ZCAD) || !rCrypto.Contains(B2) {
t.Error("UpdateCurrencies() currencies did not update")
}
}
func TestConvertCurrency(t *testing.T) {
_, err := ConvertCurrency(100, AUD, USD)
if err != nil {
t.Fatal(err)
}
r, err := ConvertCurrency(100, AUD, AUD)
if err != nil {
t.Fatal(err)
}
if r != 100 {
t.Errorf("ConvertCurrency error, incorrect rate return %2.f but received %2.f",
100.00, r)
}
_, err = ConvertCurrency(100, USD, AUD)
if err != nil {
t.Fatal(err)
}
_, err = ConvertCurrency(100, CNY, AUD)
if err != nil {
t.Fatal(err)
}
_, err = ConvertCurrency(100, LTC, USD)
if err == nil {
t.Fatal("Expected err on non-existent currency")
}
_, err = ConvertCurrency(100, USD, LTC)
if err == nil {
t.Fatal("Expected err on non-existent currency")
}
}