mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 15:09:51 +00:00
* 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
108 lines
2.1 KiB
Go
108 lines
2.1 KiB
Go
package script
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/thrasher-corp/gocryptotrader/database"
|
|
"github.com/thrasher-corp/gocryptotrader/database/drivers"
|
|
"github.com/thrasher-corp/gocryptotrader/database/testhelpers"
|
|
"github.com/volatiletech/null"
|
|
)
|
|
|
|
var verbose = false
|
|
|
|
func TestMain(m *testing.M) {
|
|
var err error
|
|
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
|
|
testhelpers.TempDir, err = os.MkdirTemp("", "gct-temp")
|
|
if err != nil {
|
|
fmt.Printf("failed to create temp file: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if verbose {
|
|
err = testhelpers.EnableVerboseTestOutput()
|
|
if err != nil {
|
|
fmt.Printf("failed to enable verbose test output: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
t := m.Run()
|
|
|
|
err = os.RemoveAll(testhelpers.TempDir)
|
|
if err != nil {
|
|
fmt.Printf("Failed to remove temp db file: %v", err)
|
|
}
|
|
|
|
os.Exit(t)
|
|
}
|
|
|
|
func TestScript(t *testing.T) {
|
|
t.Parallel()
|
|
for _, tc := range []struct {
|
|
name string
|
|
config *database.Config
|
|
runner func()
|
|
closer func(dbConn *database.Instance) error
|
|
output any
|
|
}{
|
|
{
|
|
"SQLite-Write",
|
|
&database.Config{
|
|
Driver: database.DBSQLite3,
|
|
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
|
|
},
|
|
writeScript,
|
|
testhelpers.CloseDatabase,
|
|
nil,
|
|
},
|
|
{
|
|
"Postgres-Write",
|
|
testhelpers.PostgresTestDatabase,
|
|
writeScript,
|
|
nil,
|
|
nil,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
if !testhelpers.CheckValidConfig(&tc.config.ConnectionDetails) {
|
|
t.Skip("database not configured skipping test")
|
|
}
|
|
|
|
dbConn, err := testhelpers.ConnectToDatabase(tc.config)
|
|
require.NoError(t, err)
|
|
|
|
if tc.runner != nil {
|
|
tc.runner()
|
|
}
|
|
|
|
if tc.closer != nil {
|
|
assert.NoError(t, tc.closer(dbConn))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func writeScript() {
|
|
var wg sync.WaitGroup
|
|
for x := range 20 {
|
|
wg.Add(1)
|
|
|
|
go func(x int) {
|
|
defer wg.Done()
|
|
test := fmt.Sprintf("test-%v", x)
|
|
var data null.Bytes
|
|
Event(test, test, test, data, test, test, time.Now())
|
|
}(x)
|
|
}
|
|
wg.Wait()
|
|
}
|