mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +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:
@@ -33,7 +33,7 @@ const (
|
||||
canManipulateRealOrders = false
|
||||
)
|
||||
|
||||
var g Gateio
|
||||
var g = &Gateio{}
|
||||
var wsSetupRan bool
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -92,10 +92,7 @@ func TestGetMarketInfo(t *testing.T) {
|
||||
|
||||
func TestSpotNewOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if !areTestAPIKeysSet() || !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g, canManipulateRealOrders)
|
||||
|
||||
_, err := g.SpotNewOrder(context.Background(),
|
||||
SpotNewOrderRequestParams{
|
||||
@@ -111,10 +108,7 @@ func TestSpotNewOrder(t *testing.T) {
|
||||
|
||||
func TestCancelExistingOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if !areTestAPIKeysSet() || !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g, canManipulateRealOrders)
|
||||
|
||||
_, err := g.CancelExistingOrder(context.Background(), 917591554, "btc_usdt")
|
||||
if err != nil {
|
||||
@@ -124,10 +118,7 @@ func TestCancelExistingOrder(t *testing.T) {
|
||||
|
||||
func TestGetBalances(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip()
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
|
||||
|
||||
_, err := g.GetBalances(context.Background())
|
||||
if err != nil {
|
||||
@@ -210,7 +201,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, feeBuilder.FeeType)
|
||||
}
|
||||
@@ -223,7 +214,7 @@ func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
var feeBuilder = setFeeBuilder()
|
||||
if areTestAPIKeysSet() {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) {
|
||||
// CryptocurrencyTradeFee Basic
|
||||
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
@@ -290,6 +281,7 @@ func TestGetFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedResult := exchange.AutoWithdrawCryptoText + " & " + exchange.NoFiatWithdrawalsText
|
||||
withdrawPermissions := g.FormatWithdrawPermissions()
|
||||
if withdrawPermissions != expectedResult {
|
||||
@@ -298,6 +290,7 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
@@ -305,14 +298,15 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := g.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) && err != nil {
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(g) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
@@ -324,23 +318,18 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
getOrdersRequest.Pairs = []currency.Pair{currPair}
|
||||
|
||||
_, err := g.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) && err != nil {
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(g) && 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 g.ValidateAPICredentials(g.GetDefaultCredentials()) == nil
|
||||
}
|
||||
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
|
||||
var orderSubmission = &order.Submit{
|
||||
Exchange: g.Name,
|
||||
@@ -357,17 +346,16 @@ func TestSubmitOrder(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
response, err := g.SubmitOrder(context.Background(), orderSubmission)
|
||||
if areTestAPIKeysSet() && (err != nil || response.Status != order.New) {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) && (err != nil || response.Status != order.New) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(g) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &order.Cancel{
|
||||
@@ -379,18 +367,17 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
err := g.CancelOrder(context.Background(), orderCancellation)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
if !sharedtestvalues.AreAPICredentialsSet(g) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &order.Cancel{
|
||||
@@ -403,10 +390,10 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
resp, err := g.CancelAllOrders(context.Background(), orderCancellation)
|
||||
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
if !sharedtestvalues.AreAPICredentialsSet(g) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
|
||||
@@ -416,6 +403,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
if apiSecret == "" || apiKey == "" {
|
||||
_, err := g.UpdateAccountInfo(context.Background(), asset.Spot)
|
||||
if err == nil {
|
||||
@@ -430,9 +418,9 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
|
||||
_, err := g.ModifyOrder(context.Background(),
|
||||
&order.Modify{AssetType: asset.Spot})
|
||||
if err == nil {
|
||||
@@ -441,34 +429,28 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
|
||||
_, err := g.WithdrawCryptocurrencyFunds(context.Background(), &withdraw.Request{
|
||||
Exchange: g.Name,
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
_, err := g.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&withdrawCryptoRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
}})
|
||||
if !sharedtestvalues.AreAPICredentialsSet(g) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) && err != nil {
|
||||
t.Errorf("Withdraw failed to be placed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := g.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
|
||||
@@ -478,9 +460,8 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, g, canManipulateRealOrders)
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := g.WithdrawFiatFundsToInternationalBank(context.Background(),
|
||||
@@ -491,7 +472,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
if areTestAPIKeysSet() {
|
||||
t.Parallel()
|
||||
if sharedtestvalues.AreAPICredentialsSet(g) {
|
||||
_, err := g.GetDepositAddress(context.Background(), currency.USDT, "", "TRX")
|
||||
if err != nil {
|
||||
t.Error("Test Fail - GetDepositAddress error", err)
|
||||
@@ -504,9 +486,8 @@ func TestGetDepositAddress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestGetOrderInfo(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("no API keys set skipping test")
|
||||
}
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
|
||||
|
||||
_, err := g.GetOrderInfo(context.Background(),
|
||||
"917591554", currency.EMPTYPAIR, asset.Spot)
|
||||
@@ -519,7 +500,7 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
|
||||
// TestWsGetBalance dials websocket, sends balance request.
|
||||
func TestWsGetBalance(t *testing.T) {
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport || !areTestAPIKeysSet() {
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport || !sharedtestvalues.AreAPICredentialsSet(g) {
|
||||
t.Skip(stream.WebsocketNotEnabled)
|
||||
}
|
||||
var dialer websocket.Dialer
|
||||
@@ -544,7 +525,7 @@ func TestWsGetBalance(t *testing.T) {
|
||||
|
||||
// TestWsGetOrderInfo dials websocket, sends order info request.
|
||||
func TestWsGetOrderInfo(t *testing.T) {
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport || !areTestAPIKeysSet() {
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport || !sharedtestvalues.AreAPICredentialsSet(g) {
|
||||
t.Skip(stream.WebsocketNotEnabled)
|
||||
}
|
||||
var dialer websocket.Dialer
|
||||
@@ -568,7 +549,7 @@ func setupWSTestAuth(t *testing.T) {
|
||||
if wsSetupRan {
|
||||
return
|
||||
}
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport || !areTestAPIKeysSet() {
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport || !sharedtestvalues.AreAPICredentialsSet(g) {
|
||||
t.Skip(stream.WebsocketNotEnabled)
|
||||
}
|
||||
if err := g.Websocket.Connect(); err != nil {
|
||||
@@ -890,9 +871,8 @@ func TestUpdateTickers(t *testing.T) {
|
||||
|
||||
func TestGetCryptoDepositAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("api keys not set")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
|
||||
|
||||
_, err := g.GetCryptoDepositAddress(context.Background(), currency.USDT.String())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -901,9 +881,8 @@ func TestGetCryptoDepositAddress(t *testing.T) {
|
||||
|
||||
func TestGetAvailableTransferTrains(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("api keys not set")
|
||||
}
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
|
||||
|
||||
_, err := g.GetAvailableTransferChains(context.Background(), currency.USDT)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -888,9 +888,9 @@ func (g *Gateio) AuthenticateWebsocket(ctx context.Context) error {
|
||||
return g.wsServerSignIn(ctx)
|
||||
}
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// ValidateAPICredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (g *Gateio) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
|
||||
func (g *Gateio) ValidateAPICredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := g.UpdateAccountInfo(ctx, assetType)
|
||||
return g.CheckTransientError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user