mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +00:00
sharedtestvalues: Add helper functions and implement throughout exchange tests (#1163)
* exchanges/sharedtestvalues: implement new functions to handle test skipping and announcements for standardising. * exchanges: fin test impl. * linter: fixes * exchange_template: fix test * allocate so it doesn't make a panic at the disco * glorious: nits * glorious: nits * Update exchanges/sharedtestvalues/sharedtestvalues.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/sharedtestvalues/sharedtestvalues.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * glorious: nits * linter: fix * linter: shhhh --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -30,7 +30,7 @@ const (
|
||||
|
||||
const testCurrency = "btcusd"
|
||||
|
||||
var g Gemini
|
||||
var g = &Gemini{}
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -257,7 +257,7 @@ func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !areTestAPIKeysSet() {
|
||||
if !sharedtestvalues.AreAPICredentialsSet(g) {
|
||||
if feeBuilder.FeeType != exchange.OfflineTradeFee {
|
||||
t.Errorf("Expected %v, received %v",
|
||||
exchange.OfflineTradeFee,
|
||||
@@ -275,7 +275,7 @@ func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
func TestGetFee(t *testing.T) {
|
||||
t.Parallel()
|
||||
var feeBuilder = setFeeBuilder()
|
||||
if areTestAPIKeysSet() || mockTests {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) || mockTests {
|
||||
// CryptocurrencyTradeFee Basic
|
||||
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
@@ -369,9 +369,9 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
|
||||
_, err := g.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil && !mockTests:
|
||||
case sharedtestvalues.AreAPICredentialsSet(g) && err != nil && !mockTests:
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
case !sharedtestvalues.AreAPICredentialsSet(g) && err == nil && !mockTests:
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
@@ -389,9 +389,9 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
|
||||
_, err := g.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
case sharedtestvalues.AreAPICredentialsSet(g) && err != nil:
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
case !sharedtestvalues.AreAPICredentialsSet(g) && err == nil && !mockTests:
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
case err != nil && mockTests:
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
@@ -400,14 +400,10 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
|
||||
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
|
||||
// ----------------------------------------------------------------------------------------------------------------------------
|
||||
func areTestAPIKeysSet() bool {
|
||||
return g.ValidateAPICredentials(g.GetDefaultCredentials()) == nil
|
||||
}
|
||||
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
if !mockTests {
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
}
|
||||
|
||||
var orderSubmission = &order.Submit{
|
||||
@@ -427,9 +423,9 @@ func TestSubmitOrder(t *testing.T) {
|
||||
|
||||
response, err := g.SubmitOrder(context.Background(), orderSubmission)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && (err != nil || response.Status != order.New):
|
||||
case sharedtestvalues.AreAPICredentialsSet(g) && (err != nil || response.Status != order.New):
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
case !sharedtestvalues.AreAPICredentialsSet(g) && err == nil && !mockTests:
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
@@ -438,8 +434,8 @@ func TestSubmitOrder(t *testing.T) {
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
if !mockTests {
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
}
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "266029865",
|
||||
@@ -449,9 +445,9 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
err := g.CancelOrder(context.Background(), orderCancellation)
|
||||
switch {
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
case !sharedtestvalues.AreAPICredentialsSet(g) && err == nil && !mockTests:
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
case sharedtestvalues.AreAPICredentialsSet(g) && err != nil:
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
case err != nil && mockTests:
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
@@ -460,8 +456,8 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
if !mockTests {
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
}
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
@@ -475,9 +471,9 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
resp, err := g.CancelAllOrders(context.Background(), orderCancellation)
|
||||
switch {
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
case !sharedtestvalues.AreAPICredentialsSet(g) && err == nil && !mockTests:
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
case sharedtestvalues.AreAPICredentialsSet(g) && err != nil:
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
case mockTests && err != nil:
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
@@ -490,8 +486,9 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := g.ModifyOrder(context.Background(),
|
||||
&order.Modify{AssetType: asset.Spot})
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
|
||||
_, err := g.ModifyOrder(context.Background(), &order.Modify{AssetType: asset.Spot})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
@@ -499,37 +496,36 @@ func TestModifyOrder(t *testing.T) {
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Exchange: g.Name,
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
if !mockTests {
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
}
|
||||
|
||||
_, err := g.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&withdrawCryptoRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
&withdraw.Request{
|
||||
Exchange: g.Name,
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
})
|
||||
if !sharedtestvalues.AreAPICredentialsSet(g) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil && !mockTests {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) && err != nil && !mockTests {
|
||||
t.Errorf("Withdraw failed to be placed: %v", err)
|
||||
}
|
||||
if areTestAPIKeysSet() && err == nil && mockTests {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) && err == nil && mockTests {
|
||||
t.Errorf("Withdraw failed to be placed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
if !mockTests {
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
@@ -543,8 +539,8 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
if !mockTests {
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
@@ -574,7 +570,7 @@ func TestWsAuth(t *testing.T) {
|
||||
}
|
||||
if !g.Websocket.IsEnabled() &&
|
||||
!g.API.AuthenticatedWebsocketSupport ||
|
||||
!areTestAPIKeysSet() {
|
||||
!sharedtestvalues.AreAPICredentialsSet(g) {
|
||||
t.Skip(stream.WebsocketNotEnabled)
|
||||
}
|
||||
var dialer websocket.Dialer
|
||||
|
||||
@@ -806,9 +806,9 @@ func (g *Gemini) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
return req.Filter(g.Name, orders), nil
|
||||
}
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// ValidateAPICredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (g *Gemini) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
|
||||
func (g *Gemini) ValidateAPICredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := g.UpdateAccountInfo(ctx, assetType)
|
||||
return g.CheckTransientError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user