diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e083601e8c..774c32f9fa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,32 +1,3 @@ -# name: Release - -# on: -# release: -# types: -# - published - -# jobs: -# dispatch: -# runs-on: ubuntu-latest -# steps: -# - name: Get the tag -# id: release_tag -# run: echo ::set-output name=name::${GITHUB_REF/refs\/tags\//} - -# - uses: convictional/trigger-workflow-and-wait@v1.6.1 -# with: -# owner: sifchain -# repo: sifchain-chainops -# github_token: ${{ secrets.GIT_PAT }} -# workflow_file_name: sifnode-release.yml -# client_payload: '{ "release_tag": "${{ steps.release_tag.outputs.name }}" }' -# propagate_failure: false -# trigger_workflow: true -# wait_workflow: true - -# This workflow creates a release using goreleaser -# via the 'make release' command. - name: Create release on: push: diff --git a/.golangci.yml b/.golangci.yml index a6744083d4..d819360473 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,7 +27,7 @@ linters: - nakedret - prealloc # - scopelint - - exportloopref + - copyloopvar - staticcheck # WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. # - structcheck diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index d99f489c5b..23ca29ac6c 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -53,7 +53,6 @@ func TestAdjustGasPriceDecorator_AnteHandle(t *testing.T) { {"other messages without dispensation", ctx, []sdk.Msg{otherMsg, otherMsg}, highGasPrice, true}, } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { tx := legacytx.StdTx{ Msgs: tc.msgs, @@ -108,7 +107,6 @@ func TestAdjustGasPriceDecorator_AnteHandle_MinFee(t *testing.T) { {"low fee - transfer", ctx, lowFee, []sdk.Msg{transferMsg}, false}, } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { tx := legacytx.StdTx{ Msgs: tc.msgs, diff --git a/app/ante/commission_test.go b/app/ante/commission_test.go index 2b4a7a036d..38d6b5c0af 100644 --- a/app/ante/commission_test.go +++ b/app/ante/commission_test.go @@ -47,8 +47,7 @@ func TestAnte_CalculateDelegateProjectedVotingPower(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { app := sifapp.Setup(false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) @@ -106,8 +105,7 @@ func TestAnte_CalculateRedelegateProjectedVotingPower(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { app := sifapp.Setup(false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) diff --git a/cmd/ebrelayer/txs/relayToEthereum.go b/cmd/ebrelayer/txs/relayToEthereum.go index 4e3f6389f8..ef9a9a4a02 100644 --- a/cmd/ebrelayer/txs/relayToEthereum.go +++ b/cmd/ebrelayer/txs/relayToEthereum.go @@ -168,7 +168,8 @@ func InitRelayConfig( sugaredLogger.Infow("final gas price after adjustment.", "finalGasPrice", gasPrice) - transactOptsAuth.Nonce = big.NewInt(int64(nonce)) + // Using SetUint64 to avoid potential integer overflow when converting uint64 to int64 + transactOptsAuth.Nonce = new(big.Int).SetUint64(nonce) transactOptsAuth.Value = big.NewInt(0) // in wei transactOptsAuth.GasLimit = GasLimit transactOptsAuth.GasPrice = gasPrice diff --git a/cmd/siftest/main.go b/cmd/siftest/main.go index bd37026686..bedc770c6e 100644 --- a/cmd/siftest/main.go +++ b/cmd/siftest/main.go @@ -106,7 +106,7 @@ func GetVerifyOpen() *cobra.Command { err = VerifyOpenLong(clientCtx, viper.GetString("from"), - int64(viper.GetUint64("height")), + int64(viper.GetUint64("height")), // nolint:gosec collateralAmount, viper.GetString("collateral-asset"), viper.GetString("borrow-asset"), diff --git a/cmd/siftest/verify.go b/cmd/siftest/verify.go index 57c51f6425..caeefc9801 100644 --- a/cmd/siftest/verify.go +++ b/cmd/siftest/verify.go @@ -62,7 +62,7 @@ func GetVerifyAdd() *cobra.Command { func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmount, externalAmount sdk.Uint, externalAsset string) error { // Lookup wallet balances before remove // Lookup wallet balances after remove - bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) + bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) // nolint: gosec extBefore, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{ Address: from, Denom: externalAsset, @@ -80,7 +80,7 @@ func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmoun // Lookup LP units before remove // Lookup LP units after remove - clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) + clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) // nolint: gosec lpBefore, err := clpQueryClient.GetLiquidityProvider(context.Background(), &clptypes.LiquidityProviderReq{ Symbol: externalAsset, LpAddress: from, @@ -145,7 +145,7 @@ func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmoun } // Lookup wallet balances after - bankQueryClient = banktypes.NewQueryClient(clientCtx.WithHeight(int64(height))) + bankQueryClient = banktypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec extAfter, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{ Address: from, Denom: externalAsset, @@ -162,7 +162,7 @@ func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmoun } // Lookup LP after - clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) + clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec lpAfter, err := clpQueryClient.GetLiquidityProvider(context.Background(), &clptypes.LiquidityProviderReq{ Symbol: externalAsset, LpAddress: from, @@ -203,7 +203,7 @@ func VerifyAdd(clientCtx client.Context, from string, height uint64, nativeAmoun fmt.Printf("LP units after %s \n", lpAfter.LiquidityProvider.LiquidityProviderUnits.String()) fmt.Printf("LP units diff %s (expected: %s unexpected: %s)\n", lpUnitsDiff.String(), lpUnits.String(), lpUnitsDiff.Sub(sdk.NewIntFromBigInt(lpUnits.BigInt()))) - clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) + clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec poolAfter, err := clpQueryClient.GetPool(context.Background(), &clptypes.PoolReq{Symbol: externalAsset}) if err != nil { return err @@ -284,7 +284,7 @@ func GetVerifyRemove() *cobra.Command { func VerifyRemove(clientCtx client.Context, from string, height uint64, units sdk.Uint, externalAsset string) error { // Lookup wallet balances before remove // Lookup wallet balances after remove - bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) + bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) // nolint: gosec extBefore, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{ Address: from, Denom: externalAsset, @@ -302,7 +302,7 @@ func VerifyRemove(clientCtx client.Context, from string, height uint64, units sd // Lookup LP units before remove // Lookup LP units after remove - clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) + clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(int64(height - 1))) // nolint: gosec lpBefore, err := clpQueryClient.GetLiquidityProvider(context.Background(), &clptypes.LiquidityProviderReq{ Symbol: externalAsset, LpAddress: from, @@ -325,7 +325,7 @@ func VerifyRemove(clientCtx client.Context, from string, height uint64, units sd units) // Lookup wallet balances after - bankQueryClient = banktypes.NewQueryClient(clientCtx.WithHeight(int64(height))) + bankQueryClient = banktypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec extAfter, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{ Address: from, Denom: externalAsset, @@ -342,7 +342,7 @@ func VerifyRemove(clientCtx client.Context, from string, height uint64, units sd } // Lookup LP after - clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) + clpQueryClient = clptypes.NewQueryClient(clientCtx.WithHeight(int64(height))) // nolint: gosec lpAfter, err := clpQueryClient.GetLiquidityProvider(context.Background(), &clptypes.LiquidityProviderReq{ Symbol: externalAsset, LpAddress: from, @@ -415,7 +415,7 @@ func GetVerifyClose() *cobra.Command { err = VerifyClose(clientCtx, viper.GetString("from"), - int64(viper.GetUint64("height")), + int64(viper.GetUint64("height")), // nolint:gosec viper.GetUint64("id")) if err != nil { panic(err) diff --git a/test/load/margin/main.go b/test/load/margin/main.go index 17042390f4..6f7c8255fc 100644 --- a/test/load/margin/main.go +++ b/test/load/margin/main.go @@ -3,7 +3,6 @@ package main import ( "log" "os" - "strconv" "github.com/Sifchain/sifnode/app" "github.com/Sifchain/sifnode/x/margin/types" @@ -11,13 +10,11 @@ import ( "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/spf13/cobra" ) @@ -75,6 +72,9 @@ func run(cmd *cobra.Command, args []string) error { txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()) key, err := txf.Keybase().Key(clientCtx.GetFromName()) + if err != nil { + panic(err) + } accountNumber, seq, err := txf.AccountRetriever().GetAccountNumberSequence(clientCtx, key.GetAddress()) if err != nil { @@ -84,7 +84,7 @@ func run(cmd *cobra.Command, args []string) error { txf.WithAccountNumber(accountNumber) for a := 0; a < positions; a++ { - txf = txf.WithSequence(seq + uint64(a)) + txf = txf.WithSequence(seq + uint64(a)) // nolint:gosec err := broadcastTrade(clientCtx, txf, key) if err != nil { panic(err) @@ -94,113 +94,6 @@ func run(cmd *cobra.Command, args []string) error { return nil } -func generateAddresses(addresses chan keyring.Info, keys keyring.Keyring, num int) { - for a := 0; a < num; a++ { - info, _, err := keys.NewMnemonic("funded_"+strconv.Itoa(a), keyring.English, hd.CreateHDPath(118, 0, 0).String(), keyring.DefaultBIP39Passphrase, hd.Secp256k1) - if err != nil { - log.Printf("%s", err) - } - - addresses <- info - } -} - -func newAccountFunder(funded chan keyring.Info, clientCtx client.Context, txf tx.Factory, fromAddress sdk.AccAddress, coins sdk.Coins) func(keyring.Info) { - accountNumber, seq, err := txf.AccountRetriever().GetAccountNumberSequence(clientCtx, fromAddress) - if err != nil { - panic(err) - } - - log.Printf("Got account num(%d)/seq(%d) for address %s", accountNumber, seq, fromAddress.String()) - - return func(key keyring.Info) { - msg := banktypes.NewMsgSend(fromAddress, key.GetAddress(), coins) - - txf = txf.WithAccountNumber(accountNumber).WithSequence(seq) - - txb, err := tx.BuildUnsignedTx(txf, msg) - if err != nil { - panic(err) - } - - err = tx.Sign(txf, "faucet", txb, true) - if err != nil { - panic(err) - } - - txBytes, err := clientCtx.TxConfig.TxEncoder()(txb.GetTx()) - if err != nil { - panic(err) - } - - res, err := clientCtx.WithSimulation(true).WithBroadcastMode("block").BroadcastTx(txBytes) - if err != nil { - log.Printf("ERR %s", err) - } else { - log.Printf("Funded address %s", key.GetAddress().String()) - } - - log.Print(res) - - seq++ - funded <- key - } -} - -func newFaucet(keys keyring.Keyring, from, mnemonic string) (keyring.Info, error) { - return keys.NewAccount(from, mnemonic, keyring.DefaultBIP39Passphrase, hd.CreateHDPath(118, 0, 0).String(), hd.Secp256k1) -} - -func buildMsgs(traders []sdk.AccAddress) []*types.MsgOpen { - collateralAsset := "rowan" - collateralAmount := uint64(100) - borrowAsset := "ceth" - - var msgs []*types.MsgOpen - for i := range traders { - log.Printf("%s", traders[i].String()) - msgs = append(msgs, &types.MsgOpen{ - Signer: traders[i].String(), - CollateralAsset: collateralAsset, - CollateralAmount: sdk.NewUint(collateralAmount), - BorrowAsset: borrowAsset, - Position: types.Position_LONG, - }) - } - - return msgs -} - -func buildTxs(txf tx.Factory, msgs []*types.MsgOpen) []client.TxBuilder { - var txs []client.TxBuilder - for i := range msgs { - txb, err := tx.BuildUnsignedTx(txf, msgs[i]) - if err != nil { - panic(err) - } - err = tx.Sign(txf, msgs[i].Signer, txb, true) - if err != nil { - panic(err) - } - txs = append(txs, txb) - } - return txs -} - -func sendTxs(clientCtx client.Context, txs []client.TxBuilder) { - for t := range txs { - txBytes, err := clientCtx.TxConfig.TxEncoder()(txs[t].GetTx()) - if err != nil { - panic(err) - } - - _, err = clientCtx.WithSimulation(true).WithBroadcastMode("block").BroadcastTx(txBytes) - if err != nil { - log.Printf("ERR %s", err) - } - } -} - func broadcastTrade(clientCtx client.Context, txf tx.Factory, key keyring.Info) error { collateralAsset := "rowan" collateralAmount := uint64(100) diff --git a/x/clp/abci_test.go b/x/clp/abci_test.go index a0cd101da6..d59516ab2a 100644 --- a/x/clp/abci_test.go +++ b/x/clp/abci_test.go @@ -255,7 +255,6 @@ func TestBeginBlocker(t *testing.T) { } for _, tc := range testcases { - tc := tc t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ @@ -521,7 +520,6 @@ func TestBeginBlocker_Incremental(t *testing.T) { } for _, tc := range testcases { - tc := tc t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ diff --git a/x/clp/client/cli/query_rewards_bucket_test.go b/x/clp/client/cli/query_rewards_bucket_test.go index 70c8cec034..3ea62d4c56 100644 --- a/x/clp/client/cli/query_rewards_bucket_test.go +++ b/x/clp/client/cli/query_rewards_bucket_test.go @@ -118,7 +118,7 @@ func TestListRewardsBucket(t *testing.T) { t.Run("ByOffset", func(t *testing.T) { step := 2 for i := 0; i < len(objs); i += step { - args := request(nil, uint64(i), uint64(step), false) + args := request(nil, uint64(i), uint64(step), false) // nolint: gosec // print args fmt.Println(args) out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetCmdListRewardsBucket(), args) @@ -136,7 +136,7 @@ func TestListRewardsBucket(t *testing.T) { step := 2 var next []byte for i := 0; i < len(objs); i += step { - args := request(next, 0, uint64(step), false) + args := request(next, 0, uint64(step), false) // nolint: gosec // print args fmt.Println(args) out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetCmdListRewardsBucket(), args) @@ -158,7 +158,7 @@ func TestListRewardsBucket(t *testing.T) { var resp types.AllRewardsBucketRes require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.NoError(t, err) - require.Equal(t, len(objs), int(resp.Pagination.Total)) + require.Equal(t, len(objs), int(resp.Pagination.Total)) // nolint:gosec require.ElementsMatch(t, nullify.Fill(objs), nullify.Fill(resp.RewardsBucket), diff --git a/x/clp/genesis_test.go b/x/clp/genesis_test.go index 66e3456220..db07d2ab07 100644 --- a/x/clp/genesis_test.go +++ b/x/clp/genesis_test.go @@ -81,7 +81,6 @@ func CreateState(ctx sdk.Context, keeper keeper.Keeper, t *testing.T) (int, int) // Setting Liquidity providers lpList := test.GenerateRandomLP(10) for _, lp := range lpList { - lp := lp keeper.SetLiquidityProvider(ctx, lp) } v1 := test.GenerateWhitelistAddress("") diff --git a/x/clp/keeper/calculations_test.go b/x/clp/keeper/calculations_test.go index 8b139e8bff..167765fe64 100644 --- a/x/clp/keeper/calculations_test.go +++ b/x/clp/keeper/calculations_test.go @@ -141,8 +141,7 @@ func TestKeeper_SwapOne(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { //ctx, app := test.CreateTestAppClp(false) poolUnits := sdk.NewUint(2000) //don't care pool := types.NewPool(&tc.toAsset, tc.nativeAssetBalance, tc.externalAssetBalance, poolUnits) @@ -2222,8 +2221,7 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ diff --git a/x/clp/keeper/epoch_hooks_test.go b/x/clp/keeper/epoch_hooks_test.go index 5d2978424d..767fa49aa3 100644 --- a/x/clp/keeper/epoch_hooks_test.go +++ b/x/clp/keeper/epoch_hooks_test.go @@ -43,7 +43,7 @@ func TestAfterEpochEnd_DistributeToLPWallets(t *testing.T) { // Create a liquidity provider lpAddress, err := sdk.AccAddressFromBech32("sif1azpar20ck9lpys89r8x7zc8yu0qzgvtp48ng5v") require.NoError(t, err) - lp := types.NewLiquidityProvider(&asset, sdk.NewUint(1), lpAddress, ctx.BlockHeight()-int64(rewardsParams.RewardsLockPeriod)-1) + lp := types.NewLiquidityProvider(&asset, sdk.NewUint(1), lpAddress, ctx.BlockHeight()-int64(rewardsParams.RewardsLockPeriod)-1) // nolint:gosec clpKeeper.SetLiquidityProvider(ctx, &lp) // check account balance @@ -122,7 +122,7 @@ func TestAfterEpochEnd_AddToLiquidityPool(t *testing.T) { }, lp) // set last updated block to be before the rewards lock period - lp.LastUpdatedBlock = ctx.BlockHeight() - int64(rewardsParams.RewardsLockPeriod) - 1 + lp.LastUpdatedBlock = ctx.BlockHeight() - int64(rewardsParams.RewardsLockPeriod) - 1 // nolint:gosec clpKeeper.SetLiquidityProvider(ctx, &lp) lps, err := clpKeeper.GetAllLiquidityProviders(ctx) @@ -266,7 +266,7 @@ func TestAfterEpochEnd_AddToLiquidityPoolWithMultipleLiquidityProviders(t *testi lp2 := *lp2ptr // set last updated block to be before the rewards lock period - lp2.LastUpdatedBlock = ctx.BlockHeight() - int64(rewardsParams.RewardsLockPeriod) - 1 + lp2.LastUpdatedBlock = ctx.BlockHeight() - int64(rewardsParams.RewardsLockPeriod) - 1 // nolint:gosec clpKeeper.SetLiquidityProvider(ctx, &lp2) lps, err := clpKeeper.GetAllLiquidityProviders(ctx) diff --git a/x/clp/keeper/grpc_query_test.go b/x/clp/keeper/grpc_query_test.go index 2c1ed0e40e..fae6c600a5 100644 --- a/x/clp/keeper/grpc_query_test.go +++ b/x/clp/keeper/grpc_query_test.go @@ -207,8 +207,7 @@ func TestQuerier_GetPoolShareEstimate(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ @@ -340,7 +339,7 @@ func TestRewardsBucketQueryPaginated(t *testing.T) { t.Run("ByOffset", func(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { - resp, err := querier.GetRewardsBucketAll(wctx, request(nil, uint64(i), uint64(step), false)) + resp, err := querier.GetRewardsBucketAll(wctx, request(nil, uint64(i), uint64(step), false)) // nolint:gosec require.NoError(t, err) require.LessOrEqual(t, len(resp.RewardsBucket), step) require.Subset(t, @@ -353,7 +352,7 @@ func TestRewardsBucketQueryPaginated(t *testing.T) { step := 2 var next []byte for i := 0; i < len(msgs); i += step { - resp, err := querier.GetRewardsBucketAll(wctx, request(next, 0, uint64(step), false)) + resp, err := querier.GetRewardsBucketAll(wctx, request(next, 0, uint64(step), false)) // nolint:gosec require.NoError(t, err) require.LessOrEqual(t, len(resp.RewardsBucket), step) require.Subset(t, @@ -366,7 +365,7 @@ func TestRewardsBucketQueryPaginated(t *testing.T) { t.Run("Total", func(t *testing.T) { resp, err := querier.GetRewardsBucketAll(wctx, request(nil, 0, 0, true)) require.NoError(t, err) - require.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) // nolint:gosec require.ElementsMatch(t, nullify.Fill(msgs), nullify.Fill(resp.RewardsBucket), diff --git a/x/clp/keeper/keeper_test.go b/x/clp/keeper/keeper_test.go index 765699d332..6504cba61c 100644 --- a/x/clp/keeper/keeper_test.go +++ b/x/clp/keeper/keeper_test.go @@ -125,8 +125,7 @@ func TestKeeper_GetAssetDecimals(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClp(false) clpKeeper := app.ClpKeeper diff --git a/x/clp/keeper/liquidityprotection_test.go b/x/clp/keeper/liquidityprotection_test.go index f31277c42e..6d84559f7d 100644 --- a/x/clp/keeper/liquidityprotection_test.go +++ b/x/clp/keeper/liquidityprotection_test.go @@ -43,8 +43,7 @@ func TestKeeper_GetNativePrice(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { if tc.createPool { @@ -110,8 +109,7 @@ func TestKeeper_IsBlockedByLiquidityProtection(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { app, ctx := test.CreateTestApp(false) liquidityProtectionRateParams := app.ClpKeeper.GetLiquidityProtectionRateParams(ctx) @@ -186,8 +184,7 @@ func TestKeeper_MustUpdateLiquidityProtectionThreshold(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { app, ctx := test.CreateTestApp(false) liquidityProtectionParams := app.ClpKeeper.GetLiquidityProtectionParams(ctx) diff --git a/x/clp/keeper/liquidityprovider.go b/x/clp/keeper/liquidityprovider.go index 30271ae644..f4a5251717 100644 --- a/x/clp/keeper/liquidityprovider.go +++ b/x/clp/keeper/liquidityprovider.go @@ -209,8 +209,12 @@ func (k Keeper) filterLiquidityProvidersByLockPeriod(ctx sdk.Context, lps []*typ // get reward param lock period lockPeriod := k.GetRewardsParams(ctx).RewardsLockPeriod var filtered []*types.LiquidityProvider + currentHeight := ctx.BlockHeight() + for _, lp := range lps { - if lp.LastUpdatedBlock < (ctx.BlockHeight() - int64(lockPeriod)) { + // Safe comparison without type conversion + // If lockPeriod is too large or currentHeight is too small, this condition will be false + if lockPeriod <= uint64(math.MaxInt64) && lp.LastUpdatedBlock < currentHeight - int64(lockPeriod) { filtered = append(filtered, lp) } } diff --git a/x/clp/keeper/liquidityprovider_test.go b/x/clp/keeper/liquidityprovider_test.go index 76b0cf9aee..0f155a7457 100644 --- a/x/clp/keeper/liquidityprovider_test.go +++ b/x/clp/keeper/liquidityprovider_test.go @@ -68,11 +68,11 @@ func TestKeeper_GetLiquidityProviderData(t *testing.T) { pools, lpList := test.GeneratePoolsAndLPs(clpKeeper, ctx, tokens) lpaddr, err := sdk.AccAddressFromBech32(lpList[0].LiquidityProviderAddress) require.NoError(t, err) - assetList, pageRes, err := clpKeeper.GetAssetsForLiquidityProviderPaginated(ctx, lpaddr, &query.PageRequest{Limit: uint64(queryLimit)}) + assetList, pageRes, err := clpKeeper.GetAssetsForLiquidityProviderPaginated(ctx, lpaddr, &query.PageRequest{Limit: uint64(queryLimit)}) // nolint: gosec require.NoError(t, err) require.Len(t, assetList, queryLimit) require.NotNil(t, pageRes.NextKey) - assetList, pageRes, err = clpKeeper.GetAssetsForLiquidityProviderPaginated(ctx, lpaddr, &query.PageRequest{Key: pageRes.NextKey, Limit: uint64(queryLimit)}) + assetList, pageRes, err = clpKeeper.GetAssetsForLiquidityProviderPaginated(ctx, lpaddr, &query.PageRequest{Key: pageRes.NextKey, Limit: uint64(queryLimit)}) // nolint: gosec require.NoError(t, err) require.Len(t, assetList, len(tokens)-queryLimit) require.Nil(t, pageRes.NextKey) @@ -104,8 +104,8 @@ func TestKeeper_GetLiquidityProviderData(t *testing.T) { require.Contains(t, lpList, *lpData.LiquidityProvider) require.Equal(t, lpList[0].LiquidityProviderAddress, lpData.LiquidityProvider.LiquidityProviderAddress) require.Equal(t, assetList[i], lpData.LiquidityProvider.Asset) - require.Equal(t, fmt.Sprint(100*uint64(i+1)), lpData.ExternalAssetBalance) - require.Equal(t, fmt.Sprint(1000*uint64(i+1)), lpData.NativeAssetBalance) + require.Equal(t, fmt.Sprint(100*uint64(i+1)), lpData.ExternalAssetBalance) // nolint: gosec + require.Equal(t, fmt.Sprint(1000*uint64(i+1)), lpData.NativeAssetBalance) // nolint: gosec } } @@ -121,7 +121,7 @@ func TestKeeper_GetRewardsEligibleLiquidityProviders(t *testing.T) { if (i % 2) == 0 { continue } - lpList[i].LastUpdatedBlock = ctx.BlockHeight() - int64(clpKeeper.GetRewardsParams(ctx).RewardsLockPeriod) - 1 + lpList[i].LastUpdatedBlock = ctx.BlockHeight() - int64(clpKeeper.GetRewardsParams(ctx).RewardsLockPeriod) - 1 // nolint:gosec clpKeeper.SetLiquidityProvider(ctx, &lpList[i]) } // get rewards eligible lps diff --git a/x/clp/keeper/msg_server_test.go b/x/clp/keeper/msg_server_test.go index f2549bc491..81f88b84e4 100644 --- a/x/clp/keeper/msg_server_test.go +++ b/x/clp/keeper/msg_server_test.go @@ -150,8 +150,7 @@ func TestMsgServer_DecommissionPool(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ @@ -710,8 +709,7 @@ func TestMsgServer_Swap(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ @@ -986,8 +984,7 @@ func TestMsgServer_RemoveLiquidity(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ @@ -1199,8 +1196,7 @@ func TestMsgServer_CreatePool(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ @@ -1739,8 +1735,7 @@ func TestMsgServer_AddLiquidity(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ diff --git a/x/clp/keeper/pmtp.go b/x/clp/keeper/pmtp.go index 55021358ed..3556e36d0b 100644 --- a/x/clp/keeper/pmtp.go +++ b/x/clp/keeper/pmtp.go @@ -46,9 +46,19 @@ func (k Keeper) PolicyCalculations(ctx sdk.Context) sdk.Dec { rateParams := k.GetPmtpRateParams(ctx) pmtpPeriodBlockRate := rateParams.PmtpPeriodBlockRate pmtpInterPolicyRate := rateParams.PmtpInterPolicyRate - // compute running rate - pmtpCurrentRunningRate := (sdk.NewDec(1).Add(pmtpPeriodBlockRate)).Power(uint64(currentHeight - pmtpPeriodStartBlock + 1)).Sub(sdk.NewDec(1)) + + // Calculate power value safely without unsafe int64->uint64 conversion + var powerValue uint64 = 1 // Default to 1 + if currentHeight >= pmtpPeriodStartBlock { + difference := currentHeight - pmtpPeriodStartBlock + 1 + // Safely convert the difference to uint64 only when we know it's non-negative + powerValue = uint64(difference) // nolint: gosec + } + + // compute running rate using the safe power value + pmtpCurrentRunningRate := (sdk.NewDec(1).Add(pmtpPeriodBlockRate)).Power(powerValue).Sub(sdk.NewDec(1)) pmtpCurrentRunningRate = pmtpCurrentRunningRate.Add(pmtpInterPolicyRate) + // set running rate k.SetPmtpCurrentRunningRate(ctx, pmtpCurrentRunningRate) return pmtpCurrentRunningRate diff --git a/x/clp/keeper/pmtp_test.go b/x/clp/keeper/pmtp_test.go index 63cd84ecd0..7e105c9953 100644 --- a/x/clp/keeper/pmtp_test.go +++ b/x/clp/keeper/pmtp_test.go @@ -224,8 +224,7 @@ func TestKeeper_PolicyRun(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ diff --git a/x/clp/keeper/provider_distribution.go b/x/clp/keeper/provider_distribution.go index 29fac42e58..e2c6862e85 100644 --- a/x/clp/keeper/provider_distribution.go +++ b/x/clp/keeper/provider_distribution.go @@ -124,7 +124,7 @@ func FindProviderDistributionPeriod(currentHeight int64, periods []*types.Provid } func isActivePeriod(current int64, start, end uint64) bool { - return current >= int64(start) && current <= int64(end) + return current >= int64(start) && current <= int64(end) // nolint:gosec } func (k Keeper) CollectProviderDistributions(ctx sdk.Context, pools []*types.Pool, blockRate sdk.Dec) (PoolRowanMap, LpRowanMap, LpPoolMap) { @@ -287,5 +287,5 @@ func (k Keeper) IsDistributionBlock(ctx sdk.Context) bool { // do the thing every mod blocks starting at startHeight func IsDistributionBlockPure(blockHeight int64, startHeight, mod uint64) bool { - return (blockHeight-int64(startHeight))%int64(mod) == 0 + return (blockHeight-int64(startHeight))%int64(mod) == 0 // nolint:gosec } diff --git a/x/clp/keeper/pureCalculation.go b/x/clp/keeper/pureCalculation.go index a2ef36ef1f..82852c8511 100644 --- a/x/clp/keeper/pureCalculation.go +++ b/x/clp/keeper/pureCalculation.go @@ -66,7 +66,7 @@ func IsAnyZero(inputs []sdk.Uint) bool { } func Int64ToUint8Safe(x int64) (uint8, error) { - trial := uint8(x) + trial := uint8(x) // nolint:gosec if int64(trial) != x { return 0, types.ErrTypeCast } diff --git a/x/clp/keeper/pureCalculation_test.go b/x/clp/keeper/pureCalculation_test.go index b3ae23d8ce..b6902d2b87 100644 --- a/x/clp/keeper/pureCalculation_test.go +++ b/x/clp/keeper/pureCalculation_test.go @@ -94,8 +94,7 @@ func TestKeeper_RatToDec(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { var rat big.Rat rat.SetFrac(tc.num, tc.denom) @@ -171,8 +170,7 @@ func TestKeeper_Int64ToUint8Safe(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { y, err := clpkeeper.Int64ToUint8Safe(tc.x) @@ -212,8 +210,7 @@ func TestKeeper_Abs(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { y := clpkeeper.Abs(tc.x) @@ -251,8 +248,7 @@ func TestKeeper_DecToRat(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { y := clpkeeper.DecToRat(&tc.dec) require.Equal(t, tc.expected.String(), y.String()) @@ -288,8 +284,7 @@ func TestKeeper_RatIntQuo(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { y := clpkeeper.RatIntQuo(&tc.rat) require.Equal(t, tc.expected.String(), y.String()) @@ -321,8 +316,7 @@ func TestKeeper_ApproxRatSquareRoot(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { y := clpkeeper.ApproxRatSquareRoot(&tc.x) require.Equal(t, tc.expected.String(), y.String()) diff --git a/x/clp/keeper/querier_test.go b/x/clp/keeper/querier_test.go index bd2723dd48..1b72262a9c 100644 --- a/x/clp/keeper/querier_test.go +++ b/x/clp/keeper/querier_test.go @@ -221,8 +221,8 @@ func TestQueryGetLiquidityProviderData(t *testing.T) { assert.Contains(t, lpList, *lpData.LiquidityProvider) assert.Equal(t, lpList[0].LiquidityProviderAddress, lpData.LiquidityProvider.LiquidityProviderAddress) assert.Equal(t, test.TrimFirstRune(tokens[i]), lpData.LiquidityProvider.Asset.Symbol) - assert.Equal(t, fmt.Sprint(100*uint64(i+1)), lpData.ExternalAssetBalance) - assert.Equal(t, fmt.Sprint(1000*uint64(i+1)), lpData.NativeAssetBalance) + assert.Equal(t, fmt.Sprint(100*uint64(i+1)), lpData.ExternalAssetBalance) // nolint: gosec + assert.Equal(t, fmt.Sprint(1000*uint64(i+1)), lpData.NativeAssetBalance) // nolint: gosec } } diff --git a/x/clp/keeper/removalqueue.go b/x/clp/keeper/removalqueue.go index 49e43c0613..f47eb1f017 100644 --- a/x/clp/keeper/removalqueue.go +++ b/x/clp/keeper/removalqueue.go @@ -54,7 +54,7 @@ func (k Keeper) GetRemovalQueueIterator(ctx sdk.Context) sdk.Iterator { func (k Keeper) ProcessRemovalQueue(ctx sdk.Context, msg *types.MsgAddLiquidity, unitsToDistribute sdk.Uint) { queue := k.GetRemovalQueue(ctx, msg.ExternalAsset.Symbol) - perRequestUnits := unitsToDistribute.Quo(sdk.NewUint(uint64(queue.Count))) + perRequestUnits := unitsToDistribute.Quo(sdk.NewUint(uint64(queue.Count))) // nolint:gosec it := k.GetRemovalQueueIterator(ctx) defer it.Close() diff --git a/x/clp/keeper/rewards.go b/x/clp/keeper/rewards.go index 04d2982515..39c69cf11b 100644 --- a/x/clp/keeper/rewards.go +++ b/x/clp/keeper/rewards.go @@ -2,12 +2,13 @@ package keeper import ( "fmt" + "github.com/Sifchain/sifnode/x/clp/types" sdk "github.com/cosmos/cosmos-sdk/types" ) func (k Keeper) GetCurrentRewardPeriod(ctx sdk.Context, params *types.RewardParams) *types.RewardPeriod { - height := uint64(ctx.BlockHeight()) + height := uint64(ctx.BlockHeight()) // nolint:gosec for _, period := range params.RewardPeriods { if height >= period.RewardPeriodStartBlock && height <= period.RewardPeriodEndBlock { // mod 0 is undefined - in which case we'll run every block @@ -26,7 +27,7 @@ func CalcBlockDistribution(period *types.RewardPeriod) sdk.Uint { } func (k Keeper) DistributeDepthRewards(ctx sdk.Context, blockDistribution sdk.Uint, period *types.RewardPeriod, pools []*types.Pool) error { - height := uint64(ctx.BlockHeight()) + height := uint64(ctx.BlockHeight()) // nolint:gosec if height == period.RewardPeriodStartBlock { rewardsParams := k.GetRewardsParams(ctx) rewardsParams.RewardPeriodStartTime = ctx.BlockTime().String() @@ -289,7 +290,7 @@ func (k Keeper) PruneUnlockRecords(ctx sdk.Context, lp *types.LiquidityProvider, //var records []*types.LiquidityUnlock records := make([]*types.LiquidityUnlock, 0) for _, record := range lp.Unlocks { - if currentHeight >= record.RequestHeight+int64(lockPeriod)+int64(cancelPeriod) { + if currentHeight >= record.RequestHeight+int64(lockPeriod)+int64(cancelPeriod) { // nolint: gosec // prune auto cancelled record ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( diff --git a/x/clp/keeper/rewards_test.go b/x/clp/keeper/rewards_test.go index 315a9bf3c0..e238897ca8 100644 --- a/x/clp/keeper/rewards_test.go +++ b/x/clp/keeper/rewards_test.go @@ -145,8 +145,7 @@ func TestUseUnlockedLiquidity(t *testing.T) { } for _, tc := range tt { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { app, ctx := test.CreateTestApp(false) ctx = ctx.WithBlockHeight(tc.height) params := app.ClpKeeper.GetRewardsParams(ctx) diff --git a/x/clp/keeper/swap_fee_params_test.go b/x/clp/keeper/swap_fee_params_test.go index 574b9a2c64..bb151f206e 100644 --- a/x/clp/keeper/swap_fee_params_test.go +++ b/x/clp/keeper/swap_fee_params_test.go @@ -85,8 +85,7 @@ func TestKeeper_GetSwapFeeRate(t *testing.T) { } for _, tc := range testcases { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { ctx, app := test.CreateTestAppClp(false) diff --git a/x/clp/scenarios_test.go b/x/clp/scenarios_test.go index f011509ff2..fbea3971f6 100644 --- a/x/clp/scenarios_test.go +++ b/x/clp/scenarios_test.go @@ -55,7 +55,6 @@ func TestScenarios(t *testing.T) { require.Nil(t, err, "error occurred during unmarshalling. Error: %s", err) for _, tc := range scenarios { - tc := tc ctx, app := test.CreateTestAppClpFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { trGs := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ diff --git a/x/clp/test/test_common.go b/x/clp/test/test_common.go index c7701b7512..92e6c2930c 100644 --- a/x/clp/test/test_common.go +++ b/x/clp/test/test_common.go @@ -192,7 +192,7 @@ func GeneratePoolsSetLPs(keeper clpkeeper.Keeper, ctx sdk.Context, nPools, nLPs poolUnits := make([]uint64, nLPs) totalPoolUnits := sdk.ZeroUint() for i := 0; i < nLPs; i++ { - val := uint64(rand.Int31()) + val := uint64(rand.Int31()) // nolint:gosec poolUnits[i] = val totalPoolUnits = totalPoolUnits.Add(sdk.NewUint(val)) } @@ -202,7 +202,7 @@ func GeneratePoolsSetLPs(keeper clpkeeper.Keeper, ctx sdk.Context, nPools, nLPs keeper.SetLiquidityProvider(ctx, lp) } - pool := types.NewPool(&externalAsset, sdk.NewUint(100000000000*uint64(i+1)), sdk.NewUint(100*uint64(i+1)), totalPoolUnits) + pool := types.NewPool(&externalAsset, sdk.NewUint(100000000000*uint64(i+1)), sdk.NewUint(100*uint64(i+1)), totalPoolUnits) // nolint:gosec err := keeper.SetPool(ctx, &pool) if err != nil { panic(err) @@ -237,7 +237,7 @@ func GeneratePoolsAndLPs(keeper clpkeeper.Keeper, ctx sdk.Context, tokens []stri for i := 0; i < len(tokens); i++ { externalToken := tokens[i] externalAsset := types.NewAsset(TrimFirstRune(externalToken)) - pool := types.NewPool(&externalAsset, sdk.NewUint(1000*uint64(i+1)), sdk.NewUint(100*uint64(i+1)), sdk.NewUint(1)) + pool := types.NewPool(&externalAsset, sdk.NewUint(1000*uint64(i+1)), sdk.NewUint(100*uint64(i+1)), sdk.NewUint(1)) // nolint:gosec err := keeper.SetPool(ctx, &pool) if err != nil { panic(err) diff --git a/x/epochs/keeper/grpc_query_test.go b/x/epochs/keeper/grpc_query_test.go index 2c7df480b4..5845f0bf94 100644 --- a/x/epochs/keeper/grpc_query_test.go +++ b/x/epochs/keeper/grpc_query_test.go @@ -87,7 +87,7 @@ func TestEntryQueryPaginated(t *testing.T) { t.Run("ByOffset", func(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { - resp, err := keeper.EpochInfos(wctx, request(nil, uint64(i), uint64(step), false)) + resp, err := keeper.EpochInfos(wctx, request(nil, uint64(i), uint64(step), false)) // nolint: gosec require.NoError(t, err) require.LessOrEqual(t, len(resp.Epochs), step) require.Subset(t, @@ -100,7 +100,7 @@ func TestEntryQueryPaginated(t *testing.T) { step := 2 var next []byte for i := 0; i < len(msgs); i += step { - resp, err := keeper.EpochInfos(wctx, request(next, 0, uint64(step), false)) + resp, err := keeper.EpochInfos(wctx, request(next, 0, uint64(step), false)) // nolint:gosec require.NoError(t, err) require.LessOrEqual(t, len(resp.Epochs), step) require.Subset(t, @@ -113,7 +113,7 @@ func TestEntryQueryPaginated(t *testing.T) { t.Run("Total", func(t *testing.T) { resp, err := keeper.EpochInfos(wctx, request(nil, 0, 0, true)) require.NoError(t, err) - require.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) // nolint:gosec require.ElementsMatch(t, nullify.Fill(msgs), nullify.Fill(resp.Epochs), diff --git a/x/epochs/types/genesis_test.go b/x/epochs/types/genesis_test.go index 3861ffc1ab..fc618861f3 100644 --- a/x/epochs/types/genesis_test.go +++ b/x/epochs/types/genesis_test.go @@ -112,7 +112,6 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { } for _, tc := range testCases { - tc := tc err := tc.genState.Validate() if tc.expPass { suite.Require().NoError(err, tc.name) diff --git a/x/ethbridge/keeper/blacklist_test.go b/x/ethbridge/keeper/blacklist_test.go index bbc77cf831..806be23eb7 100644 --- a/x/ethbridge/keeper/blacklist_test.go +++ b/x/ethbridge/keeper/blacklist_test.go @@ -42,8 +42,7 @@ func TestIsBlacklisted(t *testing.T) { adminAddress, err := sdk.AccAddressFromBech32(types.TestAddress) require.NoError(t, err) for _, tc := range tt { - tc := tc - app, ctx := test.CreateTestApp(false) + app, ctx := test.CreateTestApp(false) admin := admintypes.AdminAccount{ AdminType: admintypes.AdminType_ETHBRIDGE, AdminAddress: adminAddress.String(), @@ -106,8 +105,7 @@ func TestSetBlacklist(t *testing.T) { require.NoError(t, err) for _, tc := range tt { - tc := tc - app, ctx := test.CreateTestApp(false) + app, ctx := test.CreateTestApp(false) admin := admintypes.AdminAccount{ AdminType: admintypes.AdminType_ETHBRIDGE, AdminAddress: adminAddress.String(), diff --git a/x/ibctransfer/helpers/conversion_helper.go b/x/ibctransfer/helpers/conversion_helper.go index 83751e01aa..13e48329af 100644 --- a/x/ibctransfer/helpers/conversion_helper.go +++ b/x/ibctransfer/helpers/conversion_helper.go @@ -22,14 +22,37 @@ import ( func ConvertCoinsForTransfer(msg *sdktransfertypes.MsgTransfer, sendRegistryEntry *tokenregistrytypes.RegistryEntry, sendAsRegistryEntry *tokenregistrytypes.RegistryEntry) (sdk.Coin, sdk.Coin) { // calculate the conversion difference and reduce precision - po := uint64(sendRegistryEntry.Decimals - sendAsRegistryEntry.Decimals) + var po uint64 + if sendRegistryEntry.Decimals >= sendAsRegistryEntry.Decimals { + po = uint64(sendRegistryEntry.Decimals - sendAsRegistryEntry.Decimals) // nolint: gosec + } else { + // If sendRegistryEntry.Decimals < sendAsRegistryEntry.Decimals, we'd have a negative value + // which would cause overflow when converting to uint64. + // In this case, we'll use IncreasePrecision instead of ReducePrecision below + po = uint64(sendAsRegistryEntry.Decimals - sendRegistryEntry.Decimals) // nolint: gosec + } + decAmount := sdk.NewDecFromInt(msg.Token.Amount) - convAmountDec := ReducePrecision(decAmount, po) + var convAmountDec sdk.Dec + + if sendRegistryEntry.Decimals >= sendAsRegistryEntry.Decimals { + convAmountDec = ReducePrecision(decAmount, po) + } else { + convAmountDec = IncreasePrecision(decAmount, po) + } + convAmount := sdk.NewIntFromBigInt(convAmountDec.TruncateInt().BigInt()) // create converted and Sifchain tokens with corresponding denoms and amounts convToken := sdk.NewCoin(sendRegistryEntry.IbcCounterpartyDenom, convAmount) - // increase convAmount precision to ensure amount deducted from address is the same that gets sent - tokenAmountDec := IncreasePrecision(sdk.NewDecFromInt(convAmount), po) + + // adjust precision to ensure amount deducted from address is the same that gets sent + var tokenAmountDec sdk.Dec + if sendRegistryEntry.Decimals >= sendAsRegistryEntry.Decimals { + tokenAmountDec = IncreasePrecision(sdk.NewDecFromInt(convAmount), po) + } else { + tokenAmountDec = ReducePrecision(sdk.NewDecFromInt(convAmount), po) + } + tokenAmount := sdk.NewIntFromBigInt(tokenAmountDec.TruncateInt().BigInt()) token := sdk.NewCoin(msg.Token.Denom, tokenAmount) return token, convToken @@ -132,7 +155,7 @@ func ExecConvForIncomingCoins( convAmount := amount finalCoins := sdk.NewCoins(sdk.NewCoin(convertToDenomEntry.Denom, convAmount)) if convertToDenomEntry.Decimals > mintedDenomEntry.Decimals { - diff := uint64(convertToDenomEntry.Decimals - mintedDenomEntry.Decimals) + diff := uint64(convertToDenomEntry.Decimals - mintedDenomEntry.Decimals) // nolint: gosec // This is the reduced precision xToken coming in , so we know for sure conversion to uint64 will not cause problems convAmount, err = ConvertIncomingCoins(data.Amount, diff) if err != nil { diff --git a/x/ibctransfer/keeper/msg_server_test.go b/x/ibctransfer/keeper/msg_server_test.go index 0127573f62..7bf8adf25b 100644 --- a/x/ibctransfer/keeper/msg_server_test.go +++ b/x/ibctransfer/keeper/msg_server_test.go @@ -136,8 +136,7 @@ func TestMsgServer_Transfer(t *testing.T) { }, } for _, tc := range tt { - tc := tc - t.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { tc.setupMsgServerCalls() tc.setupBankKeeperCalls() srv := keeper.NewMsgServerImpl(tc.msgSrv, tc.bankKeeper, app.TokenRegistryKeeper) diff --git a/x/ibctransfer/onrecv_packet_test.go b/x/ibctransfer/onrecv_packet_test.go index 81d2b12bfb..b99fa60dc5 100644 --- a/x/ibctransfer/onrecv_packet_test.go +++ b/x/ibctransfer/onrecv_packet_test.go @@ -43,7 +43,7 @@ func TestShouldConvertIncomingCoins(t *testing.T) { entry1c, err := app.TokenRegistryKeeper.GetEntry(registry, entry1.UnitDenom) require.NoError(t, err) require.True(t, entry1c.Decimals > entry1.Decimals) - diff := uint64(entry1c.Decimals - entry1.Decimals) + diff := uint64(entry1c.Decimals - entry1.Decimals) // nolint:gosec convAmount, err := helpers.ConvertIncomingCoins("1000000000000", diff) require.NoError(t, err) incomingDeduction := sdk.NewCoin("ueth", sdk.NewIntFromUint64(1000000000000)) @@ -79,7 +79,7 @@ func TestGetConvForIncomingCoins(t *testing.T) { entry1c, err := app.TokenRegistryKeeper.GetEntry(registry, entry1.UnitDenom) require.NoError(t, err) require.True(t, entry1c.Decimals > entry1.Decimals) - diff := uint64(entry1c.Decimals - entry1.Decimals) + diff := uint64(entry1c.Decimals - entry1.Decimals) // nolint:gosec convAmount, err := helpers.ConvertIncomingCoins("1000000000000", diff) require.NoError(t, err) incomingDeduction := sdk.NewCoin("ueth", sdk.NewIntFromUint64(1000000000000)) @@ -246,7 +246,7 @@ func TestOnRecvPacketV2(t *testing.T) { err = app2.AddCoinsToAccount(sctransfertypes.ModuleName, app.BankKeeper, ctx, addrs[0], sdk.NewCoins(sdk.NewCoin("xrowan", intAmount))) require.NoError(t, err) - diff := uint64(convertToDenomEntry.Decimals - mintedXRowanEntry.Decimals) + diff := uint64(convertToDenomEntry.Decimals - mintedXRowanEntry.Decimals) // nolint:gosec // This is the reduced precision xToken coming in , so we know for sure conversion to uint64 will not cause problems convAmount, err := helpers.ConvertIncomingCoins(xRowanV2Amount, diff) require.NoError(t, err) diff --git a/x/margin/client/testutil/suite.go b/x/margin/client/testutil/suite.go index f27fb70acf..7a8b1eb1d9 100644 --- a/x/margin/client/testutil/suite.go +++ b/x/margin/client/testutil/suite.go @@ -298,8 +298,7 @@ func (s *IntegrationTestSuite) TestB_OpenLongMTP() { } for _, tc := range testCases { - tc := tc - + _, err := s.network.WaitForHeight(tc.height) s.Require().NoError(err) diff --git a/x/margin/keeper/admin_msg_server_test.go b/x/margin/keeper/admin_msg_server_test.go index 1914a5b147..06cb4b7abb 100644 --- a/x/margin/keeper/admin_msg_server_test.go +++ b/x/margin/keeper/admin_msg_server_test.go @@ -58,8 +58,7 @@ func TestMsgServer_AdminCloseAll(t *testing.T) { }, } for _, tt := range table { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { asset := clptypes.Asset{Symbol: tt.poolAsset} ctx, app := test.CreateTestAppMarginFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { diff --git a/x/margin/keeper/events.go b/x/margin/keeper/events.go index 9adfd27366..1f2055c825 100644 --- a/x/margin/keeper/events.go +++ b/x/margin/keeper/events.go @@ -10,7 +10,7 @@ import ( func (k Keeper) EmitForceClose(ctx sdk.Context, mtp *types.MTP, repayAmount sdk.Uint, closer string) { ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventForceClose, - sdk.NewAttribute("id", strconv.FormatInt(int64(mtp.Id), 10)), + sdk.NewAttribute("id", strconv.FormatUint(mtp.Id, 10)), sdk.NewAttribute("position", mtp.Position.String()), sdk.NewAttribute("address", mtp.Address), sdk.NewAttribute("collateral_asset", mtp.CollateralAsset), @@ -30,7 +30,7 @@ func (k Keeper) EmitForceClose(ctx sdk.Context, mtp *types.MTP, repayAmount sdk. func (k Keeper) EmitAdminClose(ctx sdk.Context, mtp *types.MTP, repayAmount sdk.Uint, closer string) { ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventAdminClose, - sdk.NewAttribute("id", strconv.FormatInt(int64(mtp.Id), 10)), + sdk.NewAttribute("id", strconv.FormatUint(mtp.Id, 10)), sdk.NewAttribute("position", mtp.Position.String()), sdk.NewAttribute("address", mtp.Address), sdk.NewAttribute("collateral_asset", mtp.CollateralAsset), @@ -56,7 +56,7 @@ func (k Keeper) EmitAdminCloseAll(ctx sdk.Context, takeMarginFund bool) { func (k Keeper) EmitFundPayment(ctx sdk.Context, mtp *types.MTP, takeAmount sdk.Uint, takeAsset string, paymentType string) { ctx.EventManager().EmitEvent(sdk.NewEvent(paymentType, - sdk.NewAttribute("id", strconv.FormatInt(int64(mtp.Id), 10)), + sdk.NewAttribute("id", strconv.FormatUint(mtp.Id, 10)), sdk.NewAttribute("payment_amount", takeAmount.String()), sdk.NewAttribute("payment_asset", takeAsset), )) diff --git a/x/margin/keeper/grpc_query.go b/x/margin/keeper/grpc_query.go index f1dd82e0c7..bb5f31c6a4 100644 --- a/x/margin/keeper/grpc_query.go +++ b/x/margin/keeper/grpc_query.go @@ -106,7 +106,7 @@ func (srv queryServer) GetSQParams(ctx context.Context, request *types.GetSQPara return nil, err } return &types.GetSQParamsResponse{ - BeginBlock: int64(srv.keeper.GetSQBeginBlock(sdk.UnwrapSDKContext(ctx), &pool)), + BeginBlock: int64(srv.keeper.GetSQBeginBlock(sdk.UnwrapSDKContext(ctx), &pool)), // nolint:gosec }, nil } diff --git a/x/margin/keeper/keeper.go b/x/margin/keeper/keeper.go index 13e48c4867..b3eac6df8b 100644 --- a/x/margin/keeper/keeper.go +++ b/x/margin/keeper/keeper.go @@ -630,7 +630,7 @@ func (k Keeper) TrackSQBeginBlock(ctx sdk.Context, pool *clptypes.Pool) { sqBeginBlock := k.GetSQBeginBlock(ctx, pool) if sqBeginBlock == 0 { if pool.Health.LTE(threshold) { - k.SetSQBeginBlock(ctx, pool, uint64(ctx.BlockHeight())) + k.SetSQBeginBlock(ctx, pool, uint64(ctx.BlockHeight())) // nolint:gosec k.EmitBelowRemovalThreshold(ctx, pool) } } else if pool.Health.GT(threshold) { @@ -645,7 +645,7 @@ func (k Keeper) GetSQFromBlocks(ctx sdk.Context, pool clptypes.Pool, poolInteres return sdk.ZeroDec() } - blocks := ctx.BlockHeight() - int64(beginBlock) + blocks := ctx.BlockHeight() - int64(beginBlock) // nolint:gosec maxInterestRate := k.GetInterestRateMax(ctx) poolInterestRateFloat, _ := poolInterestRate.Float64() minus := math.Pow(math.E, -1*poolInterestRateFloat*float64(blocks)) diff --git a/x/margin/keeper/keeper_test.go b/x/margin/keeper/keeper_test.go index 915e5bcc87..e0e88ffbb5 100644 --- a/x/margin/keeper/keeper_test.go +++ b/x/margin/keeper/keeper_test.go @@ -57,8 +57,7 @@ func TestKeeper_SetMTP(t *testing.T) { } for _, tt := range table { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, _, marginKeeper := initKeeper(t) got := marginKeeper.SetMTP(ctx, &tt.mtp) @@ -214,8 +213,7 @@ func TestKeeper_CLPSwap(t *testing.T) { } for _, tt := range custodySwapTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, app, marginKeeper := initKeeper(t) app.TokenRegistryKeeper.SetToken(ctx, &tokenregistrytypes.RegistryEntry{ @@ -351,8 +349,7 @@ func TestKeeper_Borrow(t *testing.T) { } for _, tt := range borrowTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, app, marginKeeper := initKeeper(t) app.TokenRegistryKeeper.SetToken(ctx, &tokenregistrytypes.RegistryEntry{ @@ -518,8 +515,7 @@ func TestKeeper_UpdateMTPHealth(t *testing.T) { } for _, tt := range updateMTPHealthTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, app, marginKeeper := initKeeper(t) app.TokenRegistryKeeper.SetToken(ctx, &tokenregistrytypes.RegistryEntry{ @@ -804,8 +800,7 @@ func TestKeeper_Repay(t *testing.T) { } for _, tt := range repayTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, app, marginKeeper := initKeeper(t) app.TokenRegistryKeeper.SetToken(ctx, &tokenregistrytypes.RegistryEntry{ @@ -959,8 +954,7 @@ func TestKeeper_InterestRateComputation(t *testing.T) { } for _, tt := range interestRateComputationTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, app, marginKeeper := initKeeper(t) app.TokenRegistryKeeper.SetToken(ctx, &tokenregistrytypes.RegistryEntry{ diff --git a/x/margin/keeper/legacy_test.go b/x/margin/keeper/legacy_test.go index 64611556de..1455f27734 100644 --- a/x/margin/keeper/legacy_test.go +++ b/x/margin/keeper/legacy_test.go @@ -75,8 +75,7 @@ func TestKeeper_NewLegacyHandler(t *testing.T) { } for _, tt := range newLegacyHandlerTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { _, got := handler(ctx, tt.msg) if tt.errString != nil { diff --git a/x/margin/keeper/msg_server.go b/x/margin/keeper/msg_server.go index 2543075016..91dd5729fd 100644 --- a/x/margin/keeper/msg_server.go +++ b/x/margin/keeper/msg_server.go @@ -70,7 +70,7 @@ func (k msgServer) Open(goCtx context.Context, msg *types.MsgOpen) (*types.MsgOp } ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventOpen, - sdk.NewAttribute("id", strconv.FormatInt(int64(mtp.Id), 10)), + sdk.NewAttribute("id", strconv.FormatUint(mtp.Id, 10)), sdk.NewAttribute("position", mtp.Position.String()), sdk.NewAttribute("address", mtp.Address), sdk.NewAttribute("collateral_asset", mtp.CollateralAsset), @@ -109,7 +109,7 @@ func (k msgServer) Close(goCtx context.Context, msg *types.MsgClose) (*types.Msg } ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventClose, - sdk.NewAttribute("id", strconv.FormatInt(int64(closedMtp.Id), 10)), + sdk.NewAttribute("id", strconv.FormatUint(closedMtp.Id, 10)), sdk.NewAttribute("position", closedMtp.Position.String()), sdk.NewAttribute("address", closedMtp.Address), sdk.NewAttribute("collateral_asset", closedMtp.CollateralAsset), diff --git a/x/margin/keeper/msg_server_test.go b/x/margin/keeper/msg_server_test.go index 7056e61303..703249b544 100644 --- a/x/margin/keeper/msg_server_test.go +++ b/x/margin/keeper/msg_server_test.go @@ -138,8 +138,7 @@ func TestKeeper_Open(t *testing.T) { } for _, tt := range table { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, app := test.CreateTestAppMargin(false) marginKeeper := app.MarginKeeper @@ -358,8 +357,7 @@ func TestKeeper_Close(t *testing.T) { } for _, tt := range table { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, app := test.CreateTestAppMargin(false) marginKeeper := app.MarginKeeper @@ -649,8 +647,7 @@ func TestKeeper_ForceClose(t *testing.T) { } for _, tt := range table { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { asset := clptypes.Asset{Symbol: tt.poolAsset} ctx, app := test.CreateTestAppMarginFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { @@ -833,8 +830,7 @@ func TestKeeper_OpenClose(t *testing.T) { } for _, tt := range table { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { ctx, app := test.CreateTestAppMargin(false) marginKeeper := app.MarginKeeper @@ -1761,12 +1757,9 @@ func TestKeeper_EC(t *testing.T) { nativeAsset := clptypes.NativeSymbol for _, ec := range table { - ec := ec asset := clptypes.Asset{Symbol: ec.externalAsset} for _, testItem := range ec.tests { - testItem := testItem - ctx, app := test.CreateTestAppMarginFromGenesis(false, func(app *sifapp.SifchainApp, genesisState sifapp.GenesisState) sifapp.GenesisState { gs2 := &tokenregistrytypes.GenesisState{ Registry: &tokenregistrytypes.Registry{ @@ -1881,8 +1874,6 @@ func TestKeeper_EC(t *testing.T) { app.ClpKeeper.SetSwapFeeParams(ctx, clptypes.GetDefaultSwapFeeParams()) for i, chunkItem := range testItem.chunks { - i := i - chunkItem := chunkItem name := fmt.Sprintf("%v, X_A=%v, Y_A=%v, delta x=%v%%", ec.name, testItem.X_A, testItem.Y_A, chunkItem.chunk) t.Run(name, func(t *testing.T) { msgOpen := types.MsgOpen{ @@ -1895,7 +1886,7 @@ func TestKeeper_EC(t *testing.T) { } msgClose := types.MsgClose{ Signer: signer, - Id: uint64(i + 1), + Id: uint64(i + 1), // nolint:gosec } marginKeeper.WhitelistAddress(ctx, msgOpen.Signer) @@ -1929,9 +1920,9 @@ func TestKeeper_EC(t *testing.T) { Leverage: sdk.NewDec(2), MtpHealth: chunkItem.mtpHealth, Position: types.Position_LONG, - Id: uint64(i + 1), + Id: uint64(i + 1), // nolint:gosec } - openMTP, err := marginKeeper.GetMTP(ctx, signer, uint64(i+1)) + openMTP, err := marginKeeper.GetMTP(ctx, signer, uint64(i+1)) // nolint:gosec require.NoError(t, err) require.NotNil(t, openMTP) require.NotNil(t, openExpectedMTP) diff --git a/x/margin/keeper/params_test.go b/x/margin/keeper/params_test.go index 8f269c1e9a..417ec78aed 100644 --- a/x/margin/keeper/params_test.go +++ b/x/margin/keeper/params_test.go @@ -79,8 +79,7 @@ func TestKeeper_ParamGetter(t *testing.T) { } for _, tt := range paramGetterTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { got := tt.method(ctx) require.Equal(t, got, tt.want) diff --git a/x/margin/types/msgs_test.go b/x/margin/types/msgs_test.go index 60cb13427e..24c22dcf86 100644 --- a/x/margin/types/msgs_test.go +++ b/x/margin/types/msgs_test.go @@ -26,7 +26,6 @@ func TestTypes_ValidateAsset(t *testing.T) { }, } for _, tt := range validateTests { - tt := tt t.Run(fmt.Sprintf("asset: %v", tt.asset), func(t *testing.T) { got := types.Validate(tt.asset) require.Equal(t, got, tt.valid) @@ -103,7 +102,6 @@ func TestTypes_MsgOpenValidateBasic(t *testing.T) { }, } for _, tt := range validateBasicTests { - tt := tt t.Run(tt.name, func(t *testing.T) { got := tt.msgOpen.ValidateBasic() @@ -152,7 +150,6 @@ func TestTypes_MsgOpenGetSigners(t *testing.T) { }, } for _, tt := range getSignersTests { - tt := tt t.Run(tt.name, func(t *testing.T) { if tt.errString != "" { require.PanicsWithError(t, tt.errString, func() { @@ -196,7 +193,6 @@ func TestTypes_MsgCloseValidateBasic(t *testing.T) { }, } for _, tt := range validateBasicTests { - tt := tt t.Run(tt.name, func(t *testing.T) { got := tt.msgClose.ValidateBasic() @@ -245,7 +241,6 @@ func TestTypes_MsgCloseGetSigners(t *testing.T) { }, } for _, tt := range getSignersTests { - tt := tt t.Run(tt.name, func(t *testing.T) { if tt.errString != "" { require.PanicsWithError(t, tt.errString, func() { @@ -289,7 +284,6 @@ func TestTypes_MsgForceCloseValidateBasic(t *testing.T) { }, } for _, tt := range validateBasicTests { - tt := tt t.Run(tt.name, func(t *testing.T) { got := tt.msgForceClose.ValidateBasic() @@ -338,8 +332,7 @@ func TestTypes_MsgForceCloseGetSigners(t *testing.T) { }, } for _, tt := range getSignersTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { if tt.errString != "" { require.PanicsWithError(t, tt.errString, func() { tt.msgForceClose.GetSigners() diff --git a/x/margin/types/types_test.go b/x/margin/types/types_test.go index b34da83bb4..549aa17709 100644 --- a/x/margin/types/types_test.go +++ b/x/margin/types/types_test.go @@ -50,8 +50,7 @@ func TestTypes_MtpValidate(t *testing.T) { }, } for _, tt := range validateTests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { got := tt.mtp.Validate() if tt.errString != nil { diff --git a/x/tokenregistry/handler/handler_test.go b/x/tokenregistry/handler/handler_test.go index aad02988d9..5d80d5be7f 100644 --- a/x/tokenregistry/handler/handler_test.go +++ b/x/tokenregistry/handler/handler_test.go @@ -109,7 +109,6 @@ func TestHandleRegister(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { res, err := h(ctx, &tt.msg) tt.errorAssertion(t, err) @@ -202,7 +201,6 @@ func TestHandleSetRegistry(t *testing.T) { }, } for _, tt := range setup { - tt := tt t.Run(tt.name, func(t *testing.T) { res, err := h(ctx, &tt.msg) tt.errorAssertion(t, err) @@ -210,7 +208,6 @@ func TestHandleSetRegistry(t *testing.T) { }) } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { res, err := h(ctx, &tt.msg) tt.errorAssertion(t, err) @@ -294,8 +291,7 @@ func TestHandleDeregister(t *testing.T) { }, } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { res, err := h(ctx, &tt.msg) tt.errorAssertion(t, err) tt.valueAssertion(t, res) diff --git a/x/tokenregistry/types/msgs_test.go b/x/tokenregistry/types/msgs_test.go index 415d5f33f1..e5b538d50e 100644 --- a/x/tokenregistry/types/msgs_test.go +++ b/x/tokenregistry/types/msgs_test.go @@ -72,7 +72,6 @@ func TestMsgUpdateWhitelist_ValidateBasic(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { tt.assertion(t, tt.msg.ValidateBasic(), "") })