Skip to content

Commit 4c930dc

Browse files
committed
fix: go-sec linter issues
1 parent 1f07f1b commit 4c930dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+150
-312
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
# name: Release
2-
3-
# on:
4-
# release:
5-
# types:
6-
# - published
7-
8-
# jobs:
9-
# dispatch:
10-
# runs-on: ubuntu-latest
11-
# steps:
12-
# - name: Get the tag
13-
# id: release_tag
14-
# run: echo ::set-output name=name::${GITHUB_REF/refs\/tags\//}
15-
16-
# - uses: convictional/[email protected]
17-
# with:
18-
# owner: sifchain
19-
# repo: sifchain-chainops
20-
# github_token: ${{ secrets.GIT_PAT }}
21-
# workflow_file_name: sifnode-release.yml
22-
# client_payload: '{ "release_tag": "${{ steps.release_tag.outputs.name }}" }'
23-
# propagate_failure: false
24-
# trigger_workflow: true
25-
# wait_workflow: true
26-
27-
# This workflow creates a release using goreleaser
28-
# via the 'make release' command.
29-
301
name: Create release
312
on:
323
push:

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ linters:
2727
- nakedret
2828
- prealloc
2929
# - scopelint
30-
- exportloopref
30+
- copyloopvar
3131
- staticcheck
3232
# WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
3333
# - structcheck

app/ante/ante_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func TestAdjustGasPriceDecorator_AnteHandle(t *testing.T) {
5353
{"other messages without dispensation", ctx, []sdk.Msg{otherMsg, otherMsg}, highGasPrice, true},
5454
}
5555
for _, tc := range tt {
56-
tc := tc
5756
t.Run(tc.name, func(t *testing.T) {
5857
tx := legacytx.StdTx{
5958
Msgs: tc.msgs,
@@ -108,7 +107,6 @@ func TestAdjustGasPriceDecorator_AnteHandle_MinFee(t *testing.T) {
108107
{"low fee - transfer", ctx, lowFee, []sdk.Msg{transferMsg}, false},
109108
}
110109
for _, tc := range tt {
111-
tc := tc
112110
t.Run(tc.name, func(t *testing.T) {
113111
tx := legacytx.StdTx{
114112
Msgs: tc.msgs,

app/ante/commission_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ func TestAnte_CalculateDelegateProjectedVotingPower(t *testing.T) {
4747
}
4848

4949
for _, tc := range testcases {
50-
tc := tc
51-
t.Run(tc.name, func(t *testing.T) {
50+
t.Run(tc.name, func(t *testing.T) {
5251
app := sifapp.Setup(false)
5352
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
5453

@@ -106,8 +105,7 @@ func TestAnte_CalculateRedelegateProjectedVotingPower(t *testing.T) {
106105
}
107106

108107
for _, tc := range testcases {
109-
tc := tc
110-
t.Run(tc.name, func(t *testing.T) {
108+
t.Run(tc.name, func(t *testing.T) {
111109
app := sifapp.Setup(false)
112110
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
113111

cmd/ebrelayer/txs/relayToEthereum.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ func InitRelayConfig(
168168
sugaredLogger.Infow("final gas price after adjustment.",
169169
"finalGasPrice", gasPrice)
170170

171-
transactOptsAuth.Nonce = big.NewInt(int64(nonce))
171+
// Using SetUint64 to avoid potential integer overflow when converting uint64 to int64
172+
transactOptsAuth.Nonce = new(big.Int).SetUint64(nonce)
172173
transactOptsAuth.Value = big.NewInt(0) // in wei
173174
transactOptsAuth.GasLimit = GasLimit
174175
transactOptsAuth.GasPrice = gasPrice

cmd/siftest/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func GetVerifyOpen() *cobra.Command {
106106

107107
err = VerifyOpenLong(clientCtx,
108108
viper.GetString("from"),
109-
int64(viper.GetUint64("height")),
109+
int64(viper.GetUint64("height")), // nolint:gosec
110110
collateralAmount,
111111
viper.GetString("collateral-asset"),
112112
viper.GetString("borrow-asset"),

cmd/siftest/verify.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func GetVerifyAdd() *cobra.Command {
6262
func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmount, externalAmount sdk.Uint, externalAsset string) error {
6363
// Lookup wallet balances before remove
6464
// Lookup wallet balances after remove
65-
bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1)))
65+
bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) // nolint: gosec
6666
extBefore, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{
6767
Address: from,
6868
Denom: externalAsset,
@@ -80,7 +80,7 @@ func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmoun
8080

8181
// Lookup LP units before remove
8282
// Lookup LP units after remove
83-
clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1)))
83+
clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) // nolint: gosec
8484
lpBefore, err := clpQueryClient.GetLiquidityProvider(context.Background(), &clptypes.LiquidityProviderReq{
8585
Symbol: externalAsset,
8686
LpAddress: from,
@@ -145,7 +145,7 @@ func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmoun
145145
}
146146

147147
// Lookup wallet balances after
148-
bankQueryClient = banktypes.NewQueryClient(clientCtx.WithHeight(int64(height)))
148+
bankQueryClient = banktypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec
149149
extAfter, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{
150150
Address: from,
151151
Denom: externalAsset,
@@ -162,7 +162,7 @@ func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmoun
162162
}
163163

164164
// Lookup LP after
165-
clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height)))
165+
clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec
166166
lpAfter, err := clpQueryClient.GetLiquidityProvider(context.Background(), &clptypes.LiquidityProviderReq{
167167
Symbol: externalAsset,
168168
LpAddress: from,
@@ -203,7 +203,7 @@ func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmoun
203203
fmt.Printf("LP units after %s \n", lpAfter.LiquidityProvider.LiquidityProviderUnits.String())
204204
fmt.Printf("LP units diff %s (expected: %s unexpected: %s)\n", lpUnitsDiff.String(), lpUnits.String(), lpUnitsDiff.Sub(sdk.NewIntFromBigInt(lpUnits.BigInt())))
205205

206-
clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height)))
206+
clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec
207207
poolAfter, err := clpQueryClient.GetPool(context.Background(), &clptypes.PoolReq{Symbol: externalAsset})
208208
if err != nil {
209209
return err
@@ -284,7 +284,7 @@ func GetVerifyRemove() *cobra.Command {
284284
func VerifyRemove(clientCtx client.Context, from string, height uint64, units sdk.Uint, externalAsset string) error {
285285
// Lookup wallet balances before remove
286286
// Lookup wallet balances after remove
287-
bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1)))
287+
bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) // nolint: gosec
288288
extBefore, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{
289289
Address: from,
290290
Denom: externalAsset,
@@ -302,7 +302,7 @@ func VerifyRemove(clientCtx client.Context, from string, height uint64, units sd
302302

303303
// Lookup LP units before remove
304304
// Lookup LP units after remove
305-
clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1)))
305+
clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) // nolint: gosec
306306
lpBefore, err := clpQueryClient.GetLiquidityProvider(context.Background(), &clptypes.LiquidityProviderReq{
307307
Symbol: externalAsset,
308308
LpAddress: from,
@@ -325,7 +325,7 @@ func VerifyRemove(clientCtx client.Context, from string, height uint64, units sd
325325
units)
326326

327327
// Lookup wallet balances after
328-
bankQueryClient = banktypes.NewQueryClient(clientCtx.WithHeight(int64(height)))
328+
bankQueryClient = banktypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec
329329
extAfter, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{
330330
Address: from,
331331
Denom: externalAsset,
@@ -342,7 +342,7 @@ func VerifyRemove(clientCtx client.Context, from string, height uint64, units sd
342342
}
343343

344344
// Lookup LP after
345-
clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height)))
345+
clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec
346346
lpAfter, err := clpQueryClient.GetLiquidityProvider(context.Background(), &clptypes.LiquidityProviderReq{
347347
Symbol: externalAsset,
348348
LpAddress: from,
@@ -415,7 +415,7 @@ func GetVerifyClose() *cobra.Command {
415415

416416
err = VerifyClose(clientCtx,
417417
viper.GetString("from"),
418-
int64(viper.GetUint64("height")),
418+
int64(viper.GetUint64("height")), // nolint:gosec
419419
viper.GetUint64("id"))
420420
if err != nil {
421421
panic(err)

test/load/margin/main.go

Lines changed: 4 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@ package main
33
import (
44
"log"
55
"os"
6-
"strconv"
76

87
"github.com/Sifchain/sifnode/app"
98
"github.com/Sifchain/sifnode/x/margin/types"
109
"github.com/cosmos/cosmos-sdk/client"
1110
"github.com/cosmos/cosmos-sdk/client/config"
1211
"github.com/cosmos/cosmos-sdk/client/flags"
1312
"github.com/cosmos/cosmos-sdk/client/tx"
14-
"github.com/cosmos/cosmos-sdk/crypto/hd"
1513
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1614
"github.com/cosmos/cosmos-sdk/server"
1715
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
1816
sdk "github.com/cosmos/cosmos-sdk/types"
1917
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
20-
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
2118
"github.com/spf13/cobra"
2219
)
2320

@@ -75,6 +72,9 @@ func run(cmd *cobra.Command, args []string) error {
7572

7673
txf := tx.NewFactoryCLI(clientCtx, cmd.Flags())
7774
key, err := txf.Keybase().Key(clientCtx.GetFromName())
75+
if err != nil {
76+
panic(err)
77+
}
7878

7979
accountNumber, seq, err := txf.AccountRetriever().GetAccountNumberSequence(clientCtx, key.GetAddress())
8080
if err != nil {
@@ -84,7 +84,7 @@ func run(cmd *cobra.Command, args []string) error {
8484
txf.WithAccountNumber(accountNumber)
8585

8686
for a := 0; a < positions; a++ {
87-
txf = txf.WithSequence(seq + uint64(a))
87+
txf = txf.WithSequence(seq + uint64(a)) // nolint:gosec
8888
err := broadcastTrade(clientCtx, txf, key)
8989
if err != nil {
9090
panic(err)
@@ -94,113 +94,6 @@ func run(cmd *cobra.Command, args []string) error {
9494
return nil
9595
}
9696

97-
func generateAddresses(addresses chan keyring.Info, keys keyring.Keyring, num int) {
98-
for a := 0; a < num; a++ {
99-
info, _, err := keys.NewMnemonic("funded_"+strconv.Itoa(a), keyring.English, hd.CreateHDPath(118, 0, 0).String(), keyring.DefaultBIP39Passphrase, hd.Secp256k1)
100-
if err != nil {
101-
log.Printf("%s", err)
102-
}
103-
104-
addresses <- info
105-
}
106-
}
107-
108-
func newAccountFunder(funded chan keyring.Info, clientCtx client.Context, txf tx.Factory, fromAddress sdk.AccAddress, coins sdk.Coins) func(keyring.Info) {
109-
accountNumber, seq, err := txf.AccountRetriever().GetAccountNumberSequence(clientCtx, fromAddress)
110-
if err != nil {
111-
panic(err)
112-
}
113-
114-
log.Printf("Got account num(%d)/seq(%d) for address %s", accountNumber, seq, fromAddress.String())
115-
116-
return func(key keyring.Info) {
117-
msg := banktypes.NewMsgSend(fromAddress, key.GetAddress(), coins)
118-
119-
txf = txf.WithAccountNumber(accountNumber).WithSequence(seq)
120-
121-
txb, err := tx.BuildUnsignedTx(txf, msg)
122-
if err != nil {
123-
panic(err)
124-
}
125-
126-
err = tx.Sign(txf, "faucet", txb, true)
127-
if err != nil {
128-
panic(err)
129-
}
130-
131-
txBytes, err := clientCtx.TxConfig.TxEncoder()(txb.GetTx())
132-
if err != nil {
133-
panic(err)
134-
}
135-
136-
res, err := clientCtx.WithSimulation(true).WithBroadcastMode("block").BroadcastTx(txBytes)
137-
if err != nil {
138-
log.Printf("ERR %s", err)
139-
} else {
140-
log.Printf("Funded address %s", key.GetAddress().String())
141-
}
142-
143-
log.Print(res)
144-
145-
seq++
146-
funded <- key
147-
}
148-
}
149-
150-
func newFaucet(keys keyring.Keyring, from, mnemonic string) (keyring.Info, error) {
151-
return keys.NewAccount(from, mnemonic, keyring.DefaultBIP39Passphrase, hd.CreateHDPath(118, 0, 0).String(), hd.Secp256k1)
152-
}
153-
154-
func buildMsgs(traders []sdk.AccAddress) []*types.MsgOpen {
155-
collateralAsset := "rowan"
156-
collateralAmount := uint64(100)
157-
borrowAsset := "ceth"
158-
159-
var msgs []*types.MsgOpen
160-
for i := range traders {
161-
log.Printf("%s", traders[i].String())
162-
msgs = append(msgs, &types.MsgOpen{
163-
Signer: traders[i].String(),
164-
CollateralAsset: collateralAsset,
165-
CollateralAmount: sdk.NewUint(collateralAmount),
166-
BorrowAsset: borrowAsset,
167-
Position: types.Position_LONG,
168-
})
169-
}
170-
171-
return msgs
172-
}
173-
174-
func buildTxs(txf tx.Factory, msgs []*types.MsgOpen) []client.TxBuilder {
175-
var txs []client.TxBuilder
176-
for i := range msgs {
177-
txb, err := tx.BuildUnsignedTx(txf, msgs[i])
178-
if err != nil {
179-
panic(err)
180-
}
181-
err = tx.Sign(txf, msgs[i].Signer, txb, true)
182-
if err != nil {
183-
panic(err)
184-
}
185-
txs = append(txs, txb)
186-
}
187-
return txs
188-
}
189-
190-
func sendTxs(clientCtx client.Context, txs []client.TxBuilder) {
191-
for t := range txs {
192-
txBytes, err := clientCtx.TxConfig.TxEncoder()(txs[t].GetTx())
193-
if err != nil {
194-
panic(err)
195-
}
196-
197-
_, err = clientCtx.WithSimulation(true).WithBroadcastMode("block").BroadcastTx(txBytes)
198-
if err != nil {
199-
log.Printf("ERR %s", err)
200-
}
201-
}
202-
}
203-
20497
func broadcastTrade(clientCtx client.Context, txf tx.Factory, key keyring.Info) error {
20598
collateralAsset := "rowan"
20699
collateralAmount := uint64(100)

x/clp/abci_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ func TestBeginBlocker(t *testing.T) {
255255
}
256256

257257
for _, tc := range testcases {
258-
tc := tc
259258
t.Run(tc.name, func(t *testing.T) {
260259
ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState {
261260
trGs := &tokenregistrytypes.GenesisState{
@@ -521,7 +520,6 @@ func TestBeginBlocker_Incremental(t *testing.T) {
521520
}
522521

523522
for _, tc := range testcases {
524-
tc := tc
525523
t.Run(tc.name, func(t *testing.T) {
526524
ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState {
527525
trGs := &tokenregistrytypes.GenesisState{

x/clp/client/cli/query_rewards_bucket_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestListRewardsBucket(t *testing.T) {
118118
t.Run("ByOffset", func(t *testing.T) {
119119
step := 2
120120
for i := 0; i < len(objs); i += step {
121-
args := request(nil, uint64(i), uint64(step), false)
121+
args := request(nil, uint64(i), uint64(step), false) // nolint: gosec
122122
// print args
123123
fmt.Println(args)
124124
out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetCmdListRewardsBucket(), args)
@@ -136,7 +136,7 @@ func TestListRewardsBucket(t *testing.T) {
136136
step := 2
137137
var next []byte
138138
for i := 0; i < len(objs); i += step {
139-
args := request(next, 0, uint64(step), false)
139+
args := request(next, 0, uint64(step), false) // nolint: gosec
140140
// print args
141141
fmt.Println(args)
142142
out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetCmdListRewardsBucket(), args)
@@ -158,7 +158,7 @@ func TestListRewardsBucket(t *testing.T) {
158158
var resp types.AllRewardsBucketRes
159159
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
160160
require.NoError(t, err)
161-
require.Equal(t, len(objs), int(resp.Pagination.Total))
161+
require.Equal(t, len(objs), int(resp.Pagination.Total)) // nolint:gosec
162162
require.ElementsMatch(t,
163163
nullify.Fill(objs),
164164
nullify.Fill(resp.RewardsBucket),

0 commit comments

Comments
 (0)