mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
141 lines
3.0 KiB
Go
141 lines
3.0 KiB
Go
package currency
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/thrasher-/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("Test failed. GetAssetTypes shouldn't be nil")
|
|
}
|
|
|
|
if !a.Contains(asset.Spot) {
|
|
t.Errorf("Test failed. AssetTypeSpot should be in the assets list")
|
|
}
|
|
}
|
|
|
|
func TestGet(t *testing.T) {
|
|
initTest()
|
|
|
|
if p.Get(asset.Spot) == nil {
|
|
t.Error("Test failed. Spot assets shouldn't be nil")
|
|
}
|
|
|
|
if p.Get(asset.Futures) != nil {
|
|
t.Error("Test Failed. 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("Test failed. 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("Test failed. AssetTypeSpot should exist")
|
|
}
|
|
|
|
p.Delete(asset.Spot)
|
|
if p.Get(asset.Spot) != nil {
|
|
t.Error("Test failed. 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")
|
|
}
|
|
}
|