mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 07:26:48 +00:00
codebase: Cleanup various things (#1935)
* codebase: Rid base64/hex to string common funcs * codebase: Rid local scope variable usage and other improvements * codebase: Refactor currency pair usage across multiple exchanges - Updated HitBTC tests to use the new currency pair format. - Modified Kraken futures types to use currency.Pair instead of string for Symbol. - Adjusted Kraken wrapper methods to handle currency pairs correctly. - Refined OKX tests and types to utilize currency.Pair for instrument IDs. - Enhanced Poloniex tests to consistently use predefined currency pairs. - Streamlined order and orderbook tests to replace string pairs with currency.NewBTCUSD(). - Improved Yobit tests to utilize a standardized currency pair format. - Updated validator wrapper to use currency pairs directly instead of string conversions. * codebase: Use types.Number where possible * refactor: update PayoutFee type to types.Number for consistency * Refactor: Remove crypto functions to use standard library and other minor changes - Removed custom crypto functions for SHA256, SHA512, and MD5 from the common/crypto package. - Replaced usages of removed functions with standard library implementations in various files including: - cmd/websocket_client/main.go - engine/apiserver.go - exchanges/kraken/kraken.go - exchanges/lbank/lbank.go - exchanges/okx/okx_business_websocket.go - exchanges/kucoin/kucoin_websocket.go - gctscript/vm/vm.go - Updated tests to reflect changes in the crypto functions. - Renamed several functions for clarity, particularly in the context of order book updates across multiple exchanges. * refactor: replace assert with require for consistency in test assertions * refactor: Improve Binance futures candlestick test, standardise orderbook update function names and improve test parallelism * refactor: Replace require.Len with require.Equal for better output in TestGetFuturesKlineData
This commit is contained in:
@@ -56,7 +56,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
testCases := []struct {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
config *database.Config
|
||||
seedDB func(includeOHLCVData bool) error
|
||||
@@ -76,60 +76,36 @@ func TestInsert(t *testing.T) {
|
||||
},
|
||||
seedDB: seedDB,
|
||||
},
|
||||
}
|
||||
|
||||
for x := range testCases {
|
||||
test := testCases[x]
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&tc.config.ConnectionDetails) {
|
||||
t.Skip("database not configured skipping test")
|
||||
}
|
||||
|
||||
dbConn, err := testhelpers.ConnectToDatabase(test.config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dbConn, err := testhelpers.ConnectToDatabase(tc.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
if test.seedDB != nil {
|
||||
err = test.seedDB(false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tc.seedDB != nil {
|
||||
require.NoError(t, tc.seedDB(false))
|
||||
}
|
||||
|
||||
data, err := genOHCLVData()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
r, err := Insert(&data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
if r != 365 {
|
||||
t.Errorf("unexpected number inserted: %v", r)
|
||||
}
|
||||
assert.Equal(t, uint64(365), r)
|
||||
|
||||
d, err := DeleteCandles(&data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if d != 365 {
|
||||
t.Errorf("unexpected number deleted: %v", d)
|
||||
}
|
||||
|
||||
err = testhelpers.CloseDatabase(dbConn)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(365), d)
|
||||
assert.NoError(t, testhelpers.CloseDatabase(dbConn))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInsertFromCSV(t *testing.T) {
|
||||
testCases := []struct {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
config *database.Config
|
||||
seedDB func(includeOHLCVData bool) error
|
||||
@@ -149,48 +125,32 @@ func TestInsertFromCSV(t *testing.T) {
|
||||
},
|
||||
seedDB: seedDB,
|
||||
},
|
||||
}
|
||||
|
||||
for x := range testCases {
|
||||
test := testCases[x]
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&tc.config.ConnectionDetails) {
|
||||
t.Skip("database not configured skipping test")
|
||||
}
|
||||
|
||||
dbConn, err := testhelpers.ConnectToDatabase(test.config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dbConn, err := testhelpers.ConnectToDatabase(tc.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
if test.seedDB != nil {
|
||||
err = test.seedDB(false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tc.seedDB != nil {
|
||||
require.NoError(t, tc.seedDB(false))
|
||||
}
|
||||
|
||||
exchange.ResetExchangeCache()
|
||||
testFile := filepath.Join("..", "..", "..", "testdata", "binance_BTCUSDT_24h_2019_01_01_2020_01_01.csv")
|
||||
count, err := InsertFromCSV(testExchanges[0].Name, "BTC", "USDT", 86400, "spot", testFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if count != 365 {
|
||||
t.Fatalf("expected 365 results to be inserted received: %v", count)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, uint64(365), count)
|
||||
|
||||
err = testhelpers.CloseDatabase(dbConn)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.NoError(t, testhelpers.CloseDatabase(dbConn))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeries(t *testing.T) {
|
||||
testCases := []struct {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
config *database.Config
|
||||
seedDB func(includeOHLCVData bool) error
|
||||
@@ -210,46 +170,30 @@ func TestSeries(t *testing.T) {
|
||||
},
|
||||
seedDB: seedDB,
|
||||
},
|
||||
}
|
||||
|
||||
for x := range testCases {
|
||||
test := testCases[x]
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&tc.config.ConnectionDetails) {
|
||||
t.Skip("database not configured skipping test")
|
||||
}
|
||||
|
||||
dbConn, err := testhelpers.ConnectToDatabase(test.config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dbConn, err := testhelpers.ConnectToDatabase(tc.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
if test.seedDB != nil {
|
||||
err = test.seedDB(true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tc.seedDB != nil {
|
||||
require.NoError(t, tc.seedDB(true))
|
||||
}
|
||||
|
||||
start := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
end := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
ret, err := Series(testExchanges[0].Name,
|
||||
"BTC", "USDT",
|
||||
86400, "spot",
|
||||
start, end)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ret.Candles) != 365 {
|
||||
t.Errorf("unexpected number of results received: %v", len(ret.Candles))
|
||||
}
|
||||
ret, err := Series(testExchanges[0].Name, "BTC", "USDT", 86400, "spot", start, end)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 365, len(ret.Candles))
|
||||
|
||||
_, err = Series("", "", "", 0, "", start, end)
|
||||
require.ErrorIs(t, err, errInvalidInput)
|
||||
|
||||
_, err = Series(testExchanges[0].Name, "BTC", "MOON", 864000, "spot", start, end)
|
||||
require.ErrorIs(t, err, ErrNoCandleDataFound)
|
||||
assert.ErrorIs(t, err, ErrNoCandleDataFound)
|
||||
assert.NoError(t, testhelpers.CloseDatabase(dbConn))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user