mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 23:16:54 +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:
@@ -31,7 +31,7 @@ const (
|
||||
canManipulateRealOrders = false
|
||||
)
|
||||
|
||||
var b Bitmex
|
||||
var b = &Bitmex{}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
b.SetDefaults()
|
||||
@@ -88,9 +88,7 @@ func TestGetFullFundingHistory(t *testing.T) {
|
||||
|
||||
func TestGetUrgentAnnouncement(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.GetUrgentAnnouncement(context.Background())
|
||||
if err == nil {
|
||||
t.Error("GetUrgentAnnouncement() Expected error")
|
||||
@@ -99,9 +97,7 @@ func TestGetUrgentAnnouncement(t *testing.T) {
|
||||
|
||||
func TestGetAPIKeys(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.GetAPIKeys(context.Background())
|
||||
if err == nil {
|
||||
t.Error("GetAPIKeys() Expected error")
|
||||
@@ -119,9 +115,7 @@ func TestRemoveAPIKey(t *testing.T) {
|
||||
|
||||
func TestDisableAPIKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.DisableAPIKey(context.Background(), APIKeyParams{APIKeyID: "1337"})
|
||||
if err == nil {
|
||||
t.Error("DisableAPIKey() Expected error")
|
||||
@@ -130,9 +124,7 @@ func TestDisableAPIKey(t *testing.T) {
|
||||
|
||||
func TestEnableAPIKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.EnableAPIKey(context.Background(), APIKeyParams{APIKeyID: "1337"})
|
||||
if err == nil {
|
||||
t.Error("EnableAPIKey() Expected error")
|
||||
@@ -149,9 +141,7 @@ func TestGetTrollboxMessages(t *testing.T) {
|
||||
|
||||
func TestSendTrollboxMessage(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.SendTrollboxMessage(context.Background(),
|
||||
ChatSendParams{
|
||||
ChannelID: 1337,
|
||||
@@ -179,9 +169,7 @@ func TestGetTrollboxConnectedUsers(t *testing.T) {
|
||||
|
||||
func TestGetAccountExecutions(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.GetAccountExecutions(context.Background(),
|
||||
&GenericRequestParams{})
|
||||
if err == nil {
|
||||
@@ -191,9 +179,7 @@ func TestGetAccountExecutions(t *testing.T) {
|
||||
|
||||
func TestGetAccountExecutionTradeHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.GetAccountExecutionTradeHistory(context.Background(),
|
||||
&GenericRequestParams{})
|
||||
if err == nil {
|
||||
@@ -298,9 +284,7 @@ func TestGetLiquidationOrders(t *testing.T) {
|
||||
|
||||
func TestGetCurrentNotifications(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.GetCurrentNotifications(context.Background())
|
||||
if err == nil {
|
||||
t.Error("GetCurrentNotifications() Expected error")
|
||||
@@ -309,9 +293,7 @@ func TestGetCurrentNotifications(t *testing.T) {
|
||||
|
||||
func TestAmendOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.AmendOrder(context.Background(), &OrderAmendParams{})
|
||||
if err == nil {
|
||||
t.Error("AmendOrder() Expected error")
|
||||
@@ -320,9 +302,7 @@ func TestAmendOrder(t *testing.T) {
|
||||
|
||||
func TestCreateOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.CreateOrder(context.Background(),
|
||||
&OrderNewParams{Symbol: "XBTM15",
|
||||
Price: 219.0,
|
||||
@@ -335,9 +315,7 @@ func TestCreateOrder(t *testing.T) {
|
||||
|
||||
func TestCancelOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.CancelOrders(context.Background(), &OrderCancelParams{})
|
||||
if err == nil {
|
||||
t.Error("CancelOrders() Expected error")
|
||||
@@ -346,9 +324,7 @@ func TestCancelOrders(t *testing.T) {
|
||||
|
||||
func TestCancelAllOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.CancelAllExistingOrders(context.Background(),
|
||||
OrderCancelAllParams{})
|
||||
if err == nil {
|
||||
@@ -358,9 +334,7 @@ func TestCancelAllOrders(t *testing.T) {
|
||||
|
||||
func TestAmendBulkOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.AmendBulkOrders(context.Background(), OrderAmendBulkParams{})
|
||||
if err == nil {
|
||||
t.Error("AmendBulkOrders() Expected error")
|
||||
@@ -369,9 +343,7 @@ func TestAmendBulkOrders(t *testing.T) {
|
||||
|
||||
func TestCreateBulkOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.CreateBulkOrders(context.Background(), OrderNewBulkParams{})
|
||||
if err == nil {
|
||||
t.Error("CreateBulkOrders() Expected error")
|
||||
@@ -380,9 +352,7 @@ func TestCreateBulkOrders(t *testing.T) {
|
||||
|
||||
func TestCancelAllOrdersAfterTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.CancelAllOrdersAfterTime(context.Background(),
|
||||
OrderCancelAllAfterParams{})
|
||||
if err == nil {
|
||||
@@ -536,7 +506,7 @@ func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !areTestAPIKeysSet() {
|
||||
if !sharedtestvalues.AreAPICredentialsSet(b) {
|
||||
if feeBuilder.FeeType != exchange.OfflineTradeFee {
|
||||
t.Errorf("Expected %v, received %v", exchange.OfflineTradeFee, feeBuilder.FeeType)
|
||||
}
|
||||
@@ -627,9 +597,9 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) && err != nil {
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(b) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
@@ -644,24 +614,19 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) && err != nil {
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(b) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
|
||||
// ----------------------------------------------------------------------------------------------------------------------------
|
||||
func areTestAPIKeysSet() bool {
|
||||
return b.ValidateAPICredentials(b.GetDefaultCredentials()) == nil
|
||||
}
|
||||
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
|
||||
var orderSubmission = &order.Submit{
|
||||
Exchange: b.Name,
|
||||
@@ -677,18 +642,16 @@ func TestSubmitOrder(t *testing.T) {
|
||||
AssetType: asset.Futures,
|
||||
}
|
||||
response, err := b.SubmitOrder(context.Background(), orderSubmission)
|
||||
if areTestAPIKeysSet() && (err != nil || response.Status != order.New) {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) && (err != nil || response.Status != order.New) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(b) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &order.Cancel{
|
||||
@@ -700,19 +663,17 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
err := b.CancelOrder(context.Background(), orderCancellation)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
if !sharedtestvalues.AreAPICredentialsSet(b) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &order.Cancel{
|
||||
@@ -725,10 +686,10 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
resp, err := b.CancelAllOrders(context.Background(), orderCancellation)
|
||||
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
if !sharedtestvalues.AreAPICredentialsSet(b) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
|
||||
@@ -739,7 +700,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
||||
_, err := b.UpdateAccountInfo(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("GetAccountInfo(spot) error", err)
|
||||
@@ -764,9 +725,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
_, err := b.ModifyOrder(context.Background(),
|
||||
&order.Modify{OrderID: "1337", AssetType: asset.Futures})
|
||||
if err == nil {
|
||||
@@ -776,6 +735,8 @@ func TestModifyOrder(t *testing.T) {
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Exchange: b.Name,
|
||||
Crypto: withdraw.CryptoRequest{
|
||||
@@ -787,25 +748,19 @@ func TestWithdraw(t *testing.T) {
|
||||
OneTimePassword: 000000, //nolint // gocritic false positive
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&withdrawCryptoRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
if !sharedtestvalues.AreAPICredentialsSet(b) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) && err != nil {
|
||||
t.Errorf("Withdraw failed to be placed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := b.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
|
||||
@@ -816,9 +771,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(context.Background(),
|
||||
@@ -830,7 +783,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() {
|
||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
||||
_, err := b.GetDepositAddress(context.Background(), currency.BTC, "", "")
|
||||
if err != nil {
|
||||
t.Error("GetDepositAddress() error", err)
|
||||
@@ -846,7 +799,7 @@ func TestGetDepositAddress(t *testing.T) {
|
||||
// TestWsAuth dials websocket, sends login request.
|
||||
func TestWsAuth(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !b.Websocket.IsEnabled() && !b.API.AuthenticatedWebsocketSupport || !areTestAPIKeysSet() {
|
||||
if !b.Websocket.IsEnabled() && !b.API.AuthenticatedWebsocketSupport || !sharedtestvalues.AreAPICredentialsSet(b) {
|
||||
t.Skip(stream.WebsocketNotEnabled)
|
||||
}
|
||||
var dialer websocket.Dialer
|
||||
|
||||
@@ -925,9 +925,9 @@ func (b *Bitmex) AuthenticateWebsocket(ctx context.Context) error {
|
||||
return b.websocketSendAuth(ctx)
|
||||
}
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// ValidateAPICredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (b *Bitmex) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
|
||||
func (b *Bitmex) ValidateAPICredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(ctx, assetType)
|
||||
return b.CheckTransientError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user