mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
* Initial currency overhaul before service system implementation * Remove redundant currency string in orderbook.Base Unexport lastupdated field in orderbook.Base as it was being instantiated multiple times Add error handling for process orderbook * Remove redundant currency string in ticker.Price Unexport lastupdated field in ticker.Price Add error handling for process ticker function and fix tests * Phase Two Update * Update translations to use map type - thankyou to kempeng for spotting this * Change pair method name from Display -> Format for better readability * Fixes misspelling and tests * Implement requested changes from GloriousCode * Remove reduntant function and streamlined return in currency_translation.go * Revert pair method naming conventions * Change currency naming conventions * Changed code type to exported Item type with underlying string to reduce complexity * Added interim orderbook process method to orderbook.Base type * Changed feebuilder struct field to currency.Pair * Adds fall over system for backup fx providers * deprecate function and children and fix linter issue with btcmarkets * Fixed requested changes * Fix bug and move mtx for rates * Fixed after rebase oopsies * Fix linter issues * Fixes race conditions in testing functions * Final phase coinmarketcap update * fix linter issues * Implement requested changes * Adds configuration variables to increase/decrease time durations between updating currency file and fetching new currency rates * Add a collection of tests to improve codecov * After rebase oopsy fixes for btse * Fix requested changes * fix after rebase oopsies and add more efficient comparison checks within currency pair * Fix linter issues
127 lines
3.0 KiB
Go
127 lines
3.0 KiB
Go
package currency
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGetDefaultExchangeRates(t *testing.T) {
|
|
rates, err := GetDefaultExchangeRates()
|
|
if err != nil {
|
|
t.Error("Test failed - GetDefaultExchangeRates() err", err)
|
|
}
|
|
|
|
for _, val := range rates {
|
|
if !val.IsFiat() {
|
|
t.Errorf("Test failed - GetDefaultExchangeRates() %s is not fiat pair",
|
|
val)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetExchangeRates(t *testing.T) {
|
|
rates, err := GetExchangeRates()
|
|
if err != nil {
|
|
t.Error("Test failed - GetExchangeRates() err", err)
|
|
}
|
|
|
|
for _, val := range rates {
|
|
if !val.IsFiat() {
|
|
t.Errorf("Test failed - GetExchangeRates() %s is not fiat pair",
|
|
val)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestUpdateBaseCurrency(t *testing.T) {
|
|
err := UpdateBaseCurrency(AUD)
|
|
if err != nil {
|
|
t.Error("Test failed - UpdateBaseCurrency() err", err)
|
|
}
|
|
|
|
err = UpdateBaseCurrency(LTC)
|
|
if err == nil {
|
|
t.Error("Test failed - UpdateBaseCurrency() cannot be nil")
|
|
}
|
|
|
|
if GetBaseCurrency() != AUD {
|
|
t.Errorf("Test failed - GetBaseCurrency() expected %s but recieved %s",
|
|
AUD, GetBaseCurrency())
|
|
}
|
|
}
|
|
|
|
func TestGetDefaultBaseCurrency(t *testing.T) {
|
|
if GetDefaultBaseCurrency() != USD {
|
|
t.Errorf("Test failed - GetDefaultBaseCurrency() expected %s but recieved %s",
|
|
USD, GetDefaultBaseCurrency())
|
|
}
|
|
}
|
|
|
|
func TestGetDefaulCryptoCurrencies(t *testing.T) {
|
|
expected := Currencies{BTC, LTC, ETH, DOGE, DASH, XRP, XMR}
|
|
if !GetDefaultCryptocurrencies().Match(expected) {
|
|
t.Errorf("Test failed - GetDefaultCryptocurrencies() expected %s but recieved %s",
|
|
expected, GetDefaultCryptocurrencies())
|
|
}
|
|
}
|
|
|
|
func TestGetDefaultFiatCurrencies(t *testing.T) {
|
|
expected := Currencies{USD, AUD, EUR, CNY}
|
|
if !GetDefaultFiatCurrencies().Match(expected) {
|
|
t.Errorf("Test failed - GetDefaultFiatCurrencies() expected %s but recieved %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("Test failed - 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("Test failed - 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("Test Failed - 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")
|
|
}
|
|
}
|