diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index ee6912f2840..b7256356f2a 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -345,7 +345,7 @@ func TestFCancelOrder(t *testing.T) { func TestFCancelAllOrders(t *testing.T) { t.Parallel() sharedtestvalues.SkipTestIfCredentialsUnset(t, h, canManipulateRealOrders) - updatePairsOnce(t) + updatePairsOnce(t, h) _, err := h.FCancelAllOrders(context.Background(), btcFutureDatedPair, "", "") require.NoError(t, err) } @@ -483,7 +483,7 @@ func TestUpdateOrderbookFuture(t *testing.T) { func TestGetOrderHistory(t *testing.T) { t.Parallel() sharedtestvalues.SkipTestIfCredentialsUnset(t, h) - updatePairsOnce(t) + updatePairsOnce(t, h) getOrdersRequest := order.MultiOrderRequest{ Type: order.AnyType, Pairs: []currency.Pair{currency.NewPair(currency.BTC, currency.USDT)}, @@ -861,7 +861,9 @@ func TestGetSpotKline(t *testing.T) { func TestGetHistoricCandles(t *testing.T) { t.Parallel() - updatePairsOnce(t) + h := new(HUOBI) //nolint:govet // Intentional shadow to avoid future copy/paste mistakes + require.NoError(t, testexch.Setup(h), "Setup Instance must not error") + updatePairsOnce(t, h) endTime := time.Now().Add(-time.Hour).Truncate(time.Hour) _, err := h.GetHistoricCandles(context.Background(), btcusdtPair, asset.Spot, kline.OneMin, endTime.Add(-time.Hour), endTime) @@ -880,7 +882,9 @@ func TestGetHistoricCandles(t *testing.T) { func TestGetHistoricCandlesExtended(t *testing.T) { t.Parallel() - updatePairsOnce(t) + h := new(HUOBI) //nolint:govet // Intentional shadow to avoid future copy/paste mistakes + require.NoError(t, testexch.Setup(h), "Setup Instance must not error") + updatePairsOnce(t, h) endTime := time.Now().Add(-time.Hour).Truncate(time.Hour) _, err := h.GetHistoricCandlesExtended(context.Background(), btcusdtPair, asset.Spot, kline.OneMin, endTime.Add(-time.Hour), endTime) @@ -1615,7 +1619,8 @@ func TestGetAvailableTransferChains(t *testing.T) { } func TestFormatFuturesPair(t *testing.T) { - updatePairsOnce(t) + t.Parallel() + updatePairsOnce(t, h) r, err := h.formatFuturesPair(btccwPair, false) require.NoError(t, err) @@ -1750,7 +1755,7 @@ func TestGetBatchFuturesContracts(t *testing.T) { func TestUpdateTickers(t *testing.T) { t.Parallel() - updatePairsOnce(t) + updatePairsOnce(t, h) for _, a := range h.GetAssetTypes(false) { err := h.UpdateTickers(context.Background(), a) require.NoErrorf(t, err, "asset %s", a) @@ -1803,7 +1808,7 @@ func TestPairFromContractExpiryCode(t *testing.T) { func TestGetOpenInterest(t *testing.T) { t.Parallel() - updatePairsOnce(t) + updatePairsOnce(t, h) _, err := h.GetOpenInterest(context.Background(), key.PairAsset{ Base: currency.ETH.Item, @@ -1859,7 +1864,7 @@ func TestContractOpenInterestUSDT(t *testing.T) { func TestGetCurrencyTradeURL(t *testing.T) { t.Parallel() - updatePairsOnce(t) + updatePairsOnce(t, h) for _, a := range h.GetAssetTypes(false) { pairs, err := h.CurrencyPairs.GetPairs(a, false) require.NoError(t, err, "cannot get pairs for %s", a) @@ -1962,7 +1967,7 @@ func TestSubscribe(t *testing.T) { func TestAuthSubscribe(t *testing.T) { t.Parallel() subCfg := h.Features.Subscriptions - h := testexch.MockWsInstance[HUOBI](t, mockws.CurryWsMockUpgrader(t, wsFixture)) //nolint:govet // Intentional shadow to avoid future copy/paste mistakes + h := testexch.MockWsInstance[HUOBI](t, mockws.CurryWsMockUpgrader(t, wsFixture)) h.Websocket.SetCanUseAuthenticatedEndpoints(true) subs, err := subCfg.ExpandTemplates(h) require.NoError(t, err, "ExpandTemplates must not error") @@ -2002,7 +2007,7 @@ func TestGetErrResp(t *testing.T) { func TestBootstrap(t *testing.T) { t.Parallel() - h := new(HUOBI) //nolint:govet // Intentional shadow to avoid future copy/paste mistakes + h := new(HUOBI) require.NoError(t, testexch.Setup(h), "Test Instance Setup must not fail") c, err := h.Bootstrap(context.Background()) @@ -2018,7 +2023,8 @@ func TestBootstrap(t *testing.T) { var updatePairsMutex sync.Mutex -func updatePairsOnce(tb testing.TB) { +// updatePairsOnce updates the pairs once, and ensures a future dated contract is enabled +func updatePairsOnce(tb testing.TB, h *HUOBI) { tb.Helper() updatePairsMutex.Lock() @@ -2026,9 +2032,12 @@ func updatePairsOnce(tb testing.TB) { testexch.UpdatePairsOnce(tb, h) - p, err := h.pairFromContractExpiryCode(btccwPair) - require.NoError(tb, err, "pairFromContractCode must not error") - err = h.CurrencyPairs.EnablePair(asset.Futures, p) + if btcFutureDatedPair == currency.EMPTYPAIR { + p, err := h.pairFromContractExpiryCode(btccwPair) + require.NoError(tb, err, "pairFromContractCode must not error") + btcFutureDatedPair = p + } + + err := h.CurrencyPairs.EnablePair(asset.Futures, btcFutureDatedPair) // Must enable every time we refresh the CurrencyPairs from cache require.NoError(tb, common.ExcludeError(err, currency.ErrPairAlreadyEnabled)) - btcFutureDatedPair = p } diff --git a/internal/testing/exchange/exchange.go b/internal/testing/exchange/exchange.go index fdd380c97b9..2788993c695 100644 --- a/internal/testing/exchange/exchange.go +++ b/internal/testing/exchange/exchange.go @@ -200,6 +200,7 @@ var updatePairsOnce = make(map[string]*currency.PairsManager) // UpdatePairsOnce ensures pairs are only updated once in parallel tests // A clone of the cache of the updated pairs is used to populate duplicate requests +// Any pairs enabled after this is called will be lost on the next call func UpdatePairsOnce(tb testing.TB, e exchange.IBotExchange) { tb.Helper()