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:
Ryan O'Hara-Reid
2023-04-28 13:05:42 +10:00
committed by GitHub
parent 492ea20f21
commit b20cf75d13
63 changed files with 2115 additions and 3161 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
@@ -28,7 +29,7 @@ const (
testCurrency = "btc"
)
var b Bithumb
var b = &Bithumb{}
func TestMain(m *testing.M) {
b.SetDefaults()
@@ -122,9 +123,7 @@ func TestGetAccountInformation(t *testing.T) {
t.Error("expected error when no order currency is specified")
}
if !areTestAPIKeysSet() {
t.Skip()
}
sharedtestvalues.SkipTestIfCredentialsUnset(t, b)
_, err = b.GetAccountInformation(context.Background(),
testCurrency,
@@ -136,9 +135,7 @@ func TestGetAccountInformation(t *testing.T) {
func TestGetAccountBalance(t *testing.T) {
t.Parallel()
if !areTestAPIKeysSet() {
t.Skip()
}
sharedtestvalues.SkipTestIfCredentialsUnset(t, b)
_, err := b.GetAccountBalance(context.Background(), testCurrency)
if err == nil {
@@ -148,9 +145,7 @@ func TestGetAccountBalance(t *testing.T) {
func TestGetWalletAddress(t *testing.T) {
t.Parallel()
if !areTestAPIKeysSet() {
t.Skip()
}
sharedtestvalues.SkipTestIfCredentialsUnset(t, b)
_, err := b.GetWalletAddress(context.Background(), currency.BTC)
if err == nil {
@@ -220,9 +215,7 @@ func TestWithdrawCrypto(t *testing.T) {
func TestRequestKRWDepositDetails(t *testing.T) {
t.Parallel()
if !areTestAPIKeysSet() {
t.Skip()
}
sharedtestvalues.SkipTestIfCredentialsUnset(t, b)
_, err := b.RequestKRWDepositDetails(context.Background())
if err == nil {
t.Error("Bithumb RequestKRWDepositDetails() Expected error")
@@ -289,7 +282,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)
}
@@ -379,9 +372,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")
}
}
@@ -395,24 +388,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,
@@ -428,18 +416,16 @@ func TestSubmitOrder(t *testing.T) {
AssetType: asset.Spot,
}
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{
@@ -451,19 +437,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 order: %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{
@@ -476,10 +460,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 order: %v", err)
}
@@ -490,7 +474,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("Bithumb GetAccountInfo() error", err)
@@ -524,9 +508,7 @@ func TestModifyOrder(t *testing.T) {
func TestWithdraw(t *testing.T) {
t.Parallel()
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders)
withdrawCryptoRequest := withdraw.Request{
Exchange: b.Name,
@@ -540,19 +522,17 @@ func TestWithdraw(t *testing.T) {
_, 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{
Fiat: withdraw.FiatRequest{
@@ -566,19 +546,17 @@ func TestWithdrawFiat(t *testing.T) {
}
_, err := b.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
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 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(),
@@ -590,7 +568,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)

View File

@@ -775,9 +775,9 @@ func (b *Bithumb) GetOrderHistory(ctx context.Context, req *order.GetOrdersReque
return req.Filter(b.Name, orders), nil
}
// ValidateCredentials validates current credentials used for wrapper
// ValidateAPICredentials validates current credentials used for wrapper
// functionality
func (b *Bithumb) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
func (b *Bithumb) ValidateAPICredentials(ctx context.Context, assetType asset.Item) error {
_, err := b.UpdateAccountInfo(ctx, assetType)
return b.CheckTransientError(err)
}