mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 23:16:49 +00:00
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
This commit is contained in:
@@ -56,7 +56,7 @@ func TestMain(m *testing.M) {
|
||||
cfg.LoadConfig("../../testdata/configtest.json")
|
||||
your_current_exchange_nameConfig, err := cfg.GetExchangeConfig("your_current_exchange_name")
|
||||
if err != nil {
|
||||
log.Fatal("Test Failed - your_current_exchange_name Setup() init error", err)
|
||||
log.Fatal("your_current_exchange_name Setup() init error", err)
|
||||
}
|
||||
your_current_exchange_nameConfig.AuthenticatedAPISupport = true
|
||||
your_current_exchange_nameConfig.APIKey = apiKey
|
||||
@@ -96,7 +96,7 @@ func TestMain(m *testing.M) {
|
||||
cfg.LoadConfig("../../testdata/configtest.json")
|
||||
your_current_exchange_nameConfig, err := cfg.GetExchangeConfig("your_current_exchange_name")
|
||||
if err != nil {
|
||||
log.Fatal("Test Failed - your_current_exchange_name Setup() init error", err)
|
||||
log.Fatal("your_current_exchange_name Setup() init error", err)
|
||||
}
|
||||
your_current_exchange_nameConfig.AuthenticatedAPISupport = true
|
||||
your_current_exchange_nameConfig.APIKey = apiKey
|
||||
@@ -106,7 +106,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
|
||||
if err != nil {
|
||||
log.Fatalf("Test Failed - Mock server error %s", err)
|
||||
log.Fatalf("Mock server error %s", err)
|
||||
}
|
||||
|
||||
g.HTTPClient = newClient
|
||||
|
||||
@@ -19,42 +19,42 @@ func TestMatchURLVals(t *testing.T) {
|
||||
var expected = false
|
||||
received := MatchURLVals(testVal, emptyVal)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
|
||||
received = MatchURLVals(emptyVal, testVal)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
|
||||
received = MatchURLVals(testVal, testVal2)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
|
||||
received = MatchURLVals(testVal2, testVal)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
|
||||
received = MatchURLVals(testVal, testVal3)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
|
||||
received = MatchURLVals(nonceVal1, testVal2)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
@@ -62,21 +62,21 @@ func TestMatchURLVals(t *testing.T) {
|
||||
expected = true
|
||||
received = MatchURLVals(emptyVal, emptyVal)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
|
||||
received = MatchURLVals(testVal, testVal)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
|
||||
received = MatchURLVals(nonceVal1, nonceVal2)
|
||||
if received != expected {
|
||||
t.Errorf("Test Failed - MatchURLVals error expected %v received %v",
|
||||
t.Errorf("MatchURLVals error expected %v received %v",
|
||||
expected,
|
||||
received)
|
||||
}
|
||||
@@ -105,12 +105,12 @@ func TestDeriveURLValsFromJSON(t *testing.T) {
|
||||
|
||||
payload, err := json.Marshal(test1)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - marshal error", err)
|
||||
t.Error("marshal error", err)
|
||||
}
|
||||
|
||||
_, err = DeriveURLValsFromJSONMap(payload)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - DeriveURLValsFromJSON error", err)
|
||||
t.Error("DeriveURLValsFromJSON error", err)
|
||||
}
|
||||
|
||||
test2 := map[string]string{
|
||||
@@ -125,16 +125,16 @@ func TestDeriveURLValsFromJSON(t *testing.T) {
|
||||
|
||||
payload, err = json.Marshal(test2)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - marshal error", err)
|
||||
t.Error("marshal error", err)
|
||||
}
|
||||
|
||||
vals, err := DeriveURLValsFromJSONMap(payload)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - DeriveURLValsFromJSON error", err)
|
||||
t.Error("DeriveURLValsFromJSON error", err)
|
||||
}
|
||||
|
||||
if vals["val"][0] != "1" {
|
||||
t.Error("Test Failed - DeriveURLValsFromJSON unexpected value",
|
||||
t.Error("DeriveURLValsFromJSON unexpected value",
|
||||
vals["val"][0])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestGetFilteredHeader(t *testing.T) {
|
||||
}
|
||||
|
||||
if fMap.Get("Key") != "" {
|
||||
t.Error("Test Failed - risky vals where not replaced correctly")
|
||||
t.Error("risky vals where not replaced correctly")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ func TestGetFilteredURLVals(t *testing.T) {
|
||||
shadyVals.Set("real_name", superSecretData)
|
||||
cleanVals, err := GetFilteredURLVals(shadyVals)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - GetFilteredURLVals error", err)
|
||||
t.Error("GetFilteredURLVals error", err)
|
||||
}
|
||||
|
||||
if strings.Contains(cleanVals, superSecretData) {
|
||||
t.Error("Test Failed - Super secret data found")
|
||||
t.Error("Super secret data found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ func TestCheckResponsePayload(t *testing.T) {
|
||||
|
||||
payload, err := json.Marshal(testbody)
|
||||
if err != nil {
|
||||
t.Fatal("Test Failed - json marshal error", err)
|
||||
t.Fatal("json marshal error", err)
|
||||
}
|
||||
|
||||
data, err := CheckResponsePayload(payload)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - CheckBody error", err)
|
||||
t.Error("CheckBody error", err)
|
||||
}
|
||||
|
||||
expected := `{
|
||||
@@ -126,23 +126,23 @@ func TestCheckJSON(t *testing.T) {
|
||||
|
||||
exclusionList, err := GetExcludedItems()
|
||||
if err != nil {
|
||||
t.Error("Test Failed - GetExcludedItems error", err)
|
||||
t.Error("GetExcludedItems error", err)
|
||||
}
|
||||
|
||||
vals, err := CheckJSON(testVal, &exclusionList)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Check JSON error", err)
|
||||
t.Error("Check JSON error", err)
|
||||
}
|
||||
|
||||
payload, err := json.Marshal(vals)
|
||||
if err != nil {
|
||||
t.Fatal("Test Failed - json marshal error", err)
|
||||
t.Fatal("json marshal error", err)
|
||||
}
|
||||
|
||||
newStruct := TestStructLevel0{}
|
||||
err = json.Unmarshal(payload, &newStruct)
|
||||
if err != nil {
|
||||
t.Fatal("Test Failed - Umarshal error", err)
|
||||
t.Fatal("Umarshal error", err)
|
||||
}
|
||||
|
||||
if newStruct.StructVal.BadVal != "" {
|
||||
@@ -173,14 +173,14 @@ func TestCheckJSON(t *testing.T) {
|
||||
func TestGetExcludedItems(t *testing.T) {
|
||||
exclusionList, err := GetExcludedItems()
|
||||
if err != nil {
|
||||
t.Error("Test Failed - GetExcludedItems error", err)
|
||||
t.Error("GetExcludedItems error", err)
|
||||
}
|
||||
|
||||
if len(exclusionList.Headers) == 0 {
|
||||
t.Error("Test Failed - Header exclusion list not popoulated")
|
||||
t.Error("Header exclusion list not popoulated")
|
||||
}
|
||||
|
||||
if len(exclusionList.Variables) == 0 {
|
||||
t.Error("Test Failed - Variable exclusion list not popoulated")
|
||||
t.Error("Variable exclusion list not popoulated")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ const testFile = "test.json"
|
||||
func TestNewVCRServer(t *testing.T) {
|
||||
_, _, err := NewVCRServer("")
|
||||
if err == nil {
|
||||
t.Error("Test Failed - NewVCRServer error cannot be nil")
|
||||
t.Error("NewVCRServer error cannot be nil")
|
||||
}
|
||||
|
||||
// Set up mock data
|
||||
@@ -36,7 +36,7 @@ func TestNewVCRServer(t *testing.T) {
|
||||
Amount: 1,
|
||||
Currency: "bitcoin"})
|
||||
if err != nil {
|
||||
t.Fatal("Test Failed - marshal error", err)
|
||||
t.Fatal("marshal error", err)
|
||||
}
|
||||
|
||||
testValue := HTTPResponse{Data: rp, QueryString: queryString, BodyParams: queryString}
|
||||
@@ -44,17 +44,17 @@ func TestNewVCRServer(t *testing.T) {
|
||||
|
||||
payload, err := json.Marshal(test1)
|
||||
if err != nil {
|
||||
t.Fatal("Test Failed - marshal error", err)
|
||||
t.Fatal("marshal error", err)
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(testFile, payload, os.ModePerm)
|
||||
if err != nil {
|
||||
t.Fatal("Test Failed - marshal error", err)
|
||||
t.Fatal("marshal error", err)
|
||||
}
|
||||
|
||||
deets, client, err := NewVCRServer(testFile)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - NewVCRServer error", err)
|
||||
t.Error("NewVCRServer error", err)
|
||||
}
|
||||
|
||||
common.HTTPClient = client // Set common package global HTTP Client
|
||||
@@ -64,7 +64,7 @@ func TestNewVCRServer(t *testing.T) {
|
||||
nil,
|
||||
bytes.NewBufferString(""))
|
||||
if err == nil {
|
||||
t.Error("Test Failed - Sending http request expected an error")
|
||||
t.Error("Sending http request expected an error")
|
||||
}
|
||||
|
||||
// Expected good outcome
|
||||
@@ -73,11 +73,11 @@ func TestNewVCRServer(t *testing.T) {
|
||||
nil,
|
||||
bytes.NewBufferString(""))
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Sending http request error", err)
|
||||
t.Error("Sending http request error", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(r, "404 page not found") {
|
||||
t.Error("Test Failed - Was not expecting any value returned:", r)
|
||||
t.Error("Was not expecting any value returned:", r)
|
||||
}
|
||||
|
||||
r, err = common.SendHTTPRequest(http.MethodGet,
|
||||
@@ -85,33 +85,33 @@ func TestNewVCRServer(t *testing.T) {
|
||||
nil,
|
||||
bytes.NewBufferString(""))
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Sending http request error", err)
|
||||
t.Error("Sending http request error", err)
|
||||
}
|
||||
|
||||
var res responsePayload
|
||||
err = json.Unmarshal([]byte(r), &res)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - unmarshal error", err)
|
||||
t.Error("unmarshal error", err)
|
||||
}
|
||||
|
||||
if res.Price != 8000 {
|
||||
t.Error("Test Failed - response error expected 8000 but received:",
|
||||
t.Error("response error expected 8000 but received:",
|
||||
res.Price)
|
||||
}
|
||||
|
||||
if res.Amount != 1 {
|
||||
t.Error("Test Failed - response error expected 1 but received:",
|
||||
t.Error("response error expected 1 but received:",
|
||||
res.Amount)
|
||||
}
|
||||
|
||||
if res.Currency != "bitcoin" {
|
||||
t.Error("Test Failed - response error expected \"bitcoin\" but received:",
|
||||
t.Error("response error expected \"bitcoin\" but received:",
|
||||
res.Currency)
|
||||
}
|
||||
|
||||
// clean up test.json file
|
||||
err = os.Remove(testFile)
|
||||
if err != nil {
|
||||
t.Fatal("Test Failed - Remove error", err)
|
||||
t.Fatal("Remove error", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user