Files
gocryptotrader/currency/manager_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

208 lines
4.7 KiB
Go

package currency
import (
"testing"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
)
var p PairsManager
func initTest() {
p.Store(asset.Spot,
PairStore{
Available: NewPairsFromStrings([]string{"BTC-USD", "LTC-USD"}),
Enabled: NewPairsFromStrings([]string{"BTC-USD"}),
RequestFormat: &PairFormat{
Uppercase: true,
},
ConfigFormat: &PairFormat{
Uppercase: true,
Delimiter: "-",
},
},
)
}
func TestGetAssetTypes(t *testing.T) {
initTest()
a := p.GetAssetTypes()
if len(a) == 0 {
t.Errorf("GetAssetTypes shouldn't be nil")
}
if !a.Contains(asset.Spot) {
t.Errorf("AssetTypeSpot should be in the assets list")
}
}
func TestGet(t *testing.T) {
initTest()
if p.Get(asset.Spot) == nil {
t.Error("Spot assets shouldn't be nil")
}
if p.Get(asset.Futures) != nil {
t.Error("Futures should be nil")
}
}
func TestStore(t *testing.T) {
p.Store(asset.Futures,
PairStore{
Available: NewPairsFromStrings([]string{"BTC-USD", "LTC-USD"}),
Enabled: NewPairsFromStrings([]string{"BTC-USD"}),
RequestFormat: &PairFormat{
Uppercase: true,
},
ConfigFormat: &PairFormat{
Uppercase: true,
Delimiter: "-",
},
},
)
if p.Get(asset.Futures) == nil {
t.Error("Futures assets shouldn't be nil")
}
}
func TestDelete(t *testing.T) {
p.Pairs = nil
p.Delete(asset.Spot)
p.Store(asset.Spot,
PairStore{
Available: NewPairsFromStrings([]string{"BTC-USD"}),
},
)
p.Delete(asset.UpsideProfitContract)
if p.Get(asset.Spot) == nil {
t.Error("AssetTypeSpot should exist")
}
p.Delete(asset.Spot)
if p.Get(asset.Spot) != nil {
t.Error("Delete should have deleted AssetTypeSpot")
}
}
func TestGetPairs(t *testing.T) {
p.Pairs = nil
pairs := p.GetPairs(asset.Spot, true)
if pairs != nil {
t.Fatal("pairs shouldn't be populated")
}
initTest()
pairs = p.GetPairs(asset.Spot, true)
if pairs == nil {
t.Fatal("pairs should be populated")
}
pairs = p.GetPairs("blah", true)
if pairs != nil {
t.Fatal("pairs shouldn't be populated")
}
}
func TestStorePairs(t *testing.T) {
p.Pairs = nil
p.StorePairs(asset.Spot, NewPairsFromStrings([]string{"ETH-USD"}), false)
pairs := p.GetPairs(asset.Spot, false)
if !pairs.Contains(NewPairFromString("ETH-USD"), true) {
t.Errorf("TestStorePairs failed, unexpected result")
}
initTest()
p.StorePairs(asset.Spot, NewPairsFromStrings([]string{"ETH-USD"}), false)
pairs = p.GetPairs(asset.Spot, false)
if pairs == nil {
t.Errorf("pairs should be populated")
}
if !pairs.Contains(NewPairFromString("ETH-USD"), true) {
t.Errorf("TestStorePairs failed, unexpected result")
}
p.StorePairs(asset.Futures, NewPairsFromStrings([]string{"ETH-KRW"}), true)
pairs = p.GetPairs(asset.Futures, true)
if pairs == nil {
t.Errorf("pairs futures should be populated")
}
if !pairs.Contains(NewPairFromString("ETH-KRW"), true) {
t.Errorf("TestStorePairs failed, unexpected result")
}
}
func TestDisablePair(t *testing.T) {
p.Pairs = nil
// Test disabling a pair when the pair manager is not initialised
if err := p.DisablePair(asset.Spot, NewPair(BTC, USD)); err == nil {
t.Error("unexpected result")
}
// Test asset type which doesn't exist
initTest()
if err := p.DisablePair(asset.Futures, Pair{}); err == nil {
t.Error("unexpected result")
}
// Test asset type which has an empty pair store
p.Pairs[asset.Spot] = nil
if err := p.DisablePair(asset.Spot, Pair{}); err == nil {
t.Error("unexpected result")
}
// Test disabling a pair which isn't enabled
initTest()
if err := p.DisablePair(asset.Spot, NewPair(LTC, USD)); err == nil {
t.Error("unexpected result")
}
// Test disabling a valid pair and ensure nil is empty
if err := p.DisablePair(asset.Spot, NewPair(BTC, USD)); err != nil {
t.Error("unexpected result")
}
}
func TestEnablePair(t *testing.T) {
p.Pairs = nil
// Test enabling a pair when the pair manager is not initialised
if err := p.EnablePair(asset.Spot, NewPair(BTC, USD)); err == nil {
t.Error("unexpected result")
}
// Test asset type which doesn't exist
initTest()
if err := p.EnablePair(asset.Futures, Pair{}); err == nil {
t.Error("unexpected result")
}
// Test asset type which has an empty pair store
p.Pairs[asset.Spot] = nil
if err := p.EnablePair(asset.Spot, Pair{}); err == nil {
t.Error("unexpected result")
}
// Test enabling a pair which isn't in the list of available pairs
initTest()
if err := p.EnablePair(asset.Spot, NewPair(ETH, USD)); err == nil {
t.Error("unexpected result")
}
// Test enabling a pair which already is enabled
if err := p.EnablePair(asset.Spot, NewPair(BTC, USD)); err == nil {
t.Error("unexpected result")
}
// Test enabling a valid pair
if err := p.EnablePair(asset.Spot, NewPair(LTC, USD)); err != nil {
t.Error("unexpected result")
}
}