mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 07:26:47 +00:00
CI/build: Update Go version, linters and fix minor issues (#1612)
* CI/build: Update Go version, linters and fix minor issues * linters: Add intrange, copyloopvar, additional go vet linters to match gopls and fix issues
This commit is contained in:
@@ -63,18 +63,17 @@ func createSnapshot() (holder *Orderbook, asks, bids orderbook.Tranches, err err
|
||||
}
|
||||
|
||||
func bidAskGenerator() []orderbook.Tranche {
|
||||
var response []orderbook.Tranche
|
||||
randIterator := 100
|
||||
for i := 0; i < randIterator; i++ {
|
||||
response := make([]orderbook.Tranche, 100)
|
||||
for i := range 100 {
|
||||
price := float64(rand.Intn(1000)) //nolint:gosec // no need to import crypo/rand for testing
|
||||
if price == 0 {
|
||||
price = 1
|
||||
}
|
||||
response = append(response, orderbook.Tranche{
|
||||
response[i] = orderbook.Tranche{
|
||||
Amount: float64(rand.Intn(10)), //nolint:gosec // no need to import crypo/rand for testing
|
||||
Price: price,
|
||||
ID: int64(i),
|
||||
})
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
@@ -520,7 +519,6 @@ func TestOrderbookLastUpdateID(t *testing.T) {
|
||||
func TestRunUpdateWithoutSnapshot(t *testing.T) {
|
||||
t.Parallel()
|
||||
var holder Orderbook
|
||||
var snapShot1 orderbook.Base
|
||||
asks := []orderbook.Tranche{
|
||||
{Price: 4000, Amount: 1, ID: 8},
|
||||
}
|
||||
@@ -528,10 +526,6 @@ func TestRunUpdateWithoutSnapshot(t *testing.T) {
|
||||
{Price: 5999, Amount: 1, ID: 8},
|
||||
{Price: 4000, Amount: 1, ID: 9},
|
||||
}
|
||||
snapShot1.Asks = asks
|
||||
snapShot1.Bids = bids
|
||||
snapShot1.Asset = asset.Spot
|
||||
snapShot1.Pair = cp
|
||||
holder.exchangeName = exchangeName
|
||||
err := holder.Update(&orderbook.Update{
|
||||
Bids: bids,
|
||||
@@ -549,15 +543,10 @@ func TestRunUpdateWithoutSnapshot(t *testing.T) {
|
||||
func TestRunUpdateWithoutAnyUpdates(t *testing.T) {
|
||||
t.Parallel()
|
||||
var obl Orderbook
|
||||
var snapShot1 orderbook.Base
|
||||
snapShot1.Asks = []orderbook.Tranche{}
|
||||
snapShot1.Bids = []orderbook.Tranche{}
|
||||
snapShot1.Asset = asset.Spot
|
||||
snapShot1.Pair = cp
|
||||
obl.exchangeName = exchangeName
|
||||
err := obl.Update(&orderbook.Update{
|
||||
Bids: snapShot1.Asks,
|
||||
Asks: snapShot1.Bids,
|
||||
Bids: []orderbook.Tranche{},
|
||||
Asks: []orderbook.Tranche{},
|
||||
Pair: cp,
|
||||
UpdateTime: time.Now(),
|
||||
Asset: asset.Spot,
|
||||
@@ -912,9 +901,9 @@ func TestEnsureMultipleUpdatesViaPrice(t *testing.T) {
|
||||
}
|
||||
|
||||
func deploySliceOrdered(size int) orderbook.Tranches {
|
||||
var items []orderbook.Tranche
|
||||
for i := 0; i < size; i++ {
|
||||
items = append(items, orderbook.Tranche{Amount: 1, Price: rand.Float64() + float64(i), ID: rand.Int63()}) //nolint:gosec // Not needed for tests
|
||||
items := make([]orderbook.Tranche, size)
|
||||
for i := range size {
|
||||
items[i] = orderbook.Tranche{Amount: 1, Price: rand.Float64() + float64(i), ID: rand.Int63()} //nolint:gosec // Not needed for tests
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
@@ -265,19 +265,19 @@ func (w *WebsocketConnection) parseBinaryResponse(resp []byte) ([]byte, error) {
|
||||
|
||||
// GenerateMessageID Creates a random message ID
|
||||
func (w *WebsocketConnection) GenerateMessageID(highPrec bool) int64 {
|
||||
var min int64 = 1e8
|
||||
var max int64 = 2e8
|
||||
var minValue int64 = 1e8
|
||||
var maxValue int64 = 2e8
|
||||
if highPrec {
|
||||
max = 2e12
|
||||
min = 1e12
|
||||
maxValue = 2e12
|
||||
minValue = 1e12
|
||||
}
|
||||
// utilization of hard coded positive numbers and default crypto/rand
|
||||
// io.reader will panic on error instead of returning
|
||||
randomNumber, err := rand.Int(rand.Reader, big.NewInt(max-min+1))
|
||||
randomNumber, err := rand.Int(rand.Reader, big.NewInt(maxValue-minValue+1))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return randomNumber.Int64() + min
|
||||
return randomNumber.Int64() + minValue
|
||||
}
|
||||
|
||||
// Shutdown shuts down and closes specific connection
|
||||
|
||||
@@ -201,7 +201,7 @@ func TestTrafficMonitorTrafficAlerts(t *testing.T) {
|
||||
assert.True(t, ws.IsTrafficMonitorRunning(), "traffic monitor should be running")
|
||||
require.Equal(t, connectedState, ws.state.Load(), "websocket must be connected")
|
||||
|
||||
for i := 0; i < 6; i++ { // Timeout will happen at 200ms so we want 6 * 50ms checks to pass
|
||||
for i := range 6 { // Timeout will happen at 200ms so we want 6 * 50ms checks to pass
|
||||
select {
|
||||
case ws.TrafficAlert <- signal:
|
||||
if i == 0 {
|
||||
@@ -896,7 +896,7 @@ func TestGenerateMessageID(t *testing.T) {
|
||||
wc := WebsocketConnection{}
|
||||
const spins = 1000
|
||||
ids := make([]int64, spins)
|
||||
for i := 0; i < spins; i++ {
|
||||
for i := range spins {
|
||||
id := wc.GenerateMessageID(true)
|
||||
assert.NotContains(t, ids, id, "GenerateMessageID must not generate the same ID twice")
|
||||
ids[i] = id
|
||||
|
||||
Reference in New Issue
Block a user