From e3618e1a0904f5953314c324f9b051ca42b4d6b7 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Tue, 1 Apr 2025 08:06:46 +0200 Subject: [PATCH] Huobi: Fix TestPairFromContractExpiryCode on CW (#1866) When testing CW against today, we were using a time.Now().Truncate() and documentation says to not do that. Driveby refactored the tz out of the loop --- exchanges/huobi/huobi_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index 84d162e3..0374d560 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -1827,7 +1827,12 @@ func TestPairFromContractExpiryCode(t *testing.T) { _, err := h.FetchTradablePairs(context.Background(), asset.Futures) require.NoError(t, err) - n := time.Now().Truncate(24 * time.Hour) + tz, err := time.LoadLocation("Asia/Singapore") // Huobi HQ and apparent local time for when codes become effective + require.NoError(t, err, "LoadLocation must not error") + + n := time.Now() + n = time.Date(n.Year(), n.Month(), n.Day(), 0, 0, 0, 0, tz) // Do not use Truncate; https://github.com/golang/go/issues/55921 + for _, cType := range contractExpiryNames { p, err := h.pairFromContractExpiryCode(currency.Pair{ Base: currency.BTC, @@ -1844,8 +1849,6 @@ func TestPairFromContractExpiryCode(t *testing.T) { require.True(t, ok, "%s type must be in contractExpiryNames", cType) assert.Equal(t, currency.BTC, p.Base, "pair Base should be the same") assert.Equal(t, exp, p.Quote, "pair Quote should be the same") - tz, err := time.LoadLocation("Asia/Singapore") // Huobi HQ and apparent local time for when codes become effective - require.NoError(t, err, "LoadLocation must not error") d, err := time.ParseInLocation("060102", p.Quote.String(), tz) require.NoError(t, err, "currency code must be a parsable date") require.Falsef(t, d.Before(n), "%s expiry must be today or after", cType)