Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/golint #304

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"

feeburnkeeper "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/keeper"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
Expand Down Expand Up @@ -169,9 +167,7 @@ const (
MockFeePort string = ibcmock.ModuleName + ibcfeetypes.ModuleName
)

var (
NodeDir = ".migalood"
)
var NodeDir = ".migalood"

// These constants are derived from the above variables.
// These are the ones we will want to use in the code, based on
Expand Down Expand Up @@ -293,7 +289,7 @@ type MigalooApp struct {
RouterKeeper routerkeeper.Keeper
ContractKeeper *wasmkeeper.PermissionedKeeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
FeeBurnKeeper feeburnkeeper.Keeper
FeeBurnKeeper feeburnmodulekeeper.Keeper

// IBC hooks
IBCHooksKeeper *ibchookskeeper.Keeper
Expand Down Expand Up @@ -928,7 +924,7 @@ func NewMigalooApp(
BankKeeper: app.BankKeeper,
FeeburnKeeper: &app.FeeBurnKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: keys[wasm.StoreKey],
TXCounterStoreKey: keys[wasmtypes.StoreKey],
},
)
if err != nil {
Expand Down Expand Up @@ -1162,14 +1158,11 @@ func (app *MigalooApp) setupUpgradeHandlers() {
return
}

var storeUpgrades *storetypes.StoreUpgrades

switch upgradeInfo.Name {
case v4.UpgradeName:
if upgradeInfo.Name == v4.UpgradeName {
// !! ATTENTION !!
// !! WHEN UPGRADING TO SDK v0.47 MAKE SURE TO INCLUDE THIS
// source: https://github.com/cosmos/cosmos-sdk/blob/release/v0.47.x/UPGRADING.md
storeUpgrades = &storetypes.StoreUpgrades{
storeUpgrades := &storetypes.StoreUpgrades{
Added: []string{
consensusparamtypes.StoreKey,
crisistypes.StoreKey,
Expand All @@ -1180,9 +1173,6 @@ func (app *MigalooApp) setupUpgradeHandlers() {
"intertx",
},
}
}

if storeUpgrades != nil {
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
Expand All @@ -1207,6 +1197,8 @@ func stringMapKeys(m map[string][]string) []string {
}

// initParamsKeeper init params keeper and its subspaces
//
//nolint:staticcheck // ParamsKeyTable is deprecated but used here for migration
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

Expand Down
5 changes: 2 additions & 3 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"cosmossdk.io/simapp"
"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -192,13 +191,13 @@ func TestAppImportExport(t *testing.T) {
{app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}},
{app.keys[authzkeeper.StoreKey], newApp.keys[authzkeeper.StoreKey], [][]byte{}},
{app.keys[feegrant.StoreKey], newApp.keys[feegrant.StoreKey], [][]byte{}},
{app.keys[wasm.StoreKey], newApp.keys[wasm.StoreKey], [][]byte{}},
{app.keys[wasmtypes.StoreKey], newApp.keys[wasmtypes.StoreKey], [][]byte{}},
{app.keys[consensusparamtypes.StoreKey], newApp.keys[consensusparamtypes.StoreKey], [][]byte{}},
{app.keys[crisistypes.StoreKey], newApp.keys[crisistypes.StoreKey], [][]byte{}},
}

// delete persistent tx counter value
ctxA.KVStore(app.keys[wasm.StoreKey]).Delete(wasmtypes.TXCounterPrefix)
ctxA.KVStore(app.keys[wasmtypes.StoreKey]).Delete(wasmtypes.TXCounterPrefix)

// diff both stores
for _, skp := range storeKeysPrefixes {
Expand Down
3 changes: 0 additions & 3 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"
"time"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
config "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params"
dbm "github.com/cometbft/cometbft-db"
Expand Down Expand Up @@ -34,8 +33,6 @@ const (
SimAppChainID = ""
)

var emptyWasmOpts []wasm.Option

type KeeperTestHelper struct {
suite.Suite

Expand Down
3 changes: 2 additions & 1 deletion cmd/migalood/cmd/genaccounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cmd_test
import (
"context"
"fmt"
"testing"

"github.com/terra-money/alliance/app"
alliancecmd "github.com/terra-money/alliance/cmd/allianced/cmd"
"testing"

"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand Down
7 changes: 4 additions & 3 deletions cmd/migalood/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
"errors"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"io"
"os"
"path/filepath"

tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cast"
Expand Down
7 changes: 4 additions & 3 deletions cmd/migalood/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"bufio"
"encoding/json"
"fmt"
"github.com/CosmWasm/wasmd/app"
"net"
"os"
"path/filepath"

"github.com/CosmWasm/wasmd/app"

tmconfig "github.com/cometbft/cometbft/config"
tmos "github.com/cometbft/cometbft/libs/os"
tmrand "github.com/cometbft/cometbft/libs/rand"
Expand Down Expand Up @@ -103,7 +104,8 @@ func NewTestnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBala

// testnetInitFilesCmd returns a cmd to initialize all files for tendermint testnet and application
func testnetInitFilesCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator,
validator genutiltypes.MessageValidator) *cobra.Command {
validator genutiltypes.MessageValidator,
) *cobra.Command {
cmd := &cobra.Command{
Use: "init-files",
Short: "Initialize config directories & files for a multi-validator testnet running locally via separate processes (e.g. Docker Compose or similar)",
Expand Down Expand Up @@ -425,7 +427,6 @@ func collectGenFiles(
}

nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator, validator)

if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/migalood/cmd/testnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cmd
import (
"context"
"fmt"
"github.com/terra-money/alliance/app"
"testing"

"github.com/terra-money/alliance/app"

"github.com/cometbft/cometbft/libs/log"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ require (
require (
cosmossdk.io/errors v1.0.0
github.com/golang/protobuf v1.5.3
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -185,6 +184,7 @@ require (
google.golang.org/api v0.128.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
Expand Down
17 changes: 9 additions & 8 deletions x/feeburn/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@ package ante_test

import (
"fmt"
"math"
"strconv"

config "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/ante"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"math"
"strconv"
)

func (suite *AnteTestSuite) TestFeeBurnDecorator() {
listTxFeeBurnPercent := []string{"0", "10", "40", "50", "80", "100"}
for _, percent := range listTxFeeBurnPercent {
fmt.Println("tx fee burn percent", percent)
suite.SetupTest(false) // reset
suite.SetupTest() // reset
err1 := suite.App.FeeBurnKeeper.UpdateTxFeeBurnPercent(suite.Ctx, percent)
suite.Require().NoError(err1)

fbd := ante.NewDeductFeeDecorator(suite.App.AccountKeeper, suite.App.BankKeeper, suite.App.FeeGrantKeeper, nil,
suite.App.FeeBurnKeeper)
antehandler := sdk.ChainAnteDecorators(fbd)

priv := ed25519.GenPrivKey()
priv := secp256k1.GenPrivKey()
addr := getAddr(priv)
accountAddress := sdk.AccAddress(priv.PubKey().Address().Bytes())
privNew := ed25519.GenPrivKey()
privNew := secp256k1.GenPrivKey()
addrRecv := getAddr(privNew)

accBalance := sdk.Coins{{Denom: config.BaseDenom, Amount: sdk.NewInt(int64(math.Pow10(18) * 2))}}
Expand Down Expand Up @@ -56,13 +57,13 @@ func (suite *AnteTestSuite) TestFeeBurnDecorator() {
}

func (suite *AnteTestSuite) TestFeeBurnDecoratorWhenTxNull() {
suite.SetupTest(false) // reset
suite.SetupTest() // reset

fbd := ante.NewDeductFeeDecorator(suite.App.AccountKeeper, suite.App.BankKeeper, suite.App.FeeGrantKeeper, nil,
suite.App.FeeBurnKeeper)
antehandler := sdk.ChainAnteDecorators(fbd)

priv := ed25519.GenPrivKey()
priv := secp256k1.GenPrivKey()
addr := getAddr(priv)
accBalance := sdk.Coins{{Denom: config.BaseDenom, Amount: sdk.NewInt(int64(math.Pow10(18) * 2))}}
err := suite.FundAccount(suite.Ctx, addr, accBalance)
Expand Down
25 changes: 9 additions & 16 deletions x/feeburn/ante/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package ante_test

import (
"testing"

apptesting "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app"
config "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/ibc-go/v7/testing/simapp"
"testing"

"github.com/stretchr/testify/suite"

Expand All @@ -20,20 +21,19 @@ import (
)

var (
DEFAULT_FEE int64 = 1000000000000
DefaultFee int64 = 1000000000000
s *AnteTestSuite
)
var s *AnteTestSuite

// AnteTestSuite is a test suite to be used with ante handler tests.
type AnteTestSuite struct {
apptesting.KeeperTestHelper
anteHandler sdk.AnteHandler
clientCtx client.Context
txBuilder client.TxBuilder
}

// SetupTest setups a new test, with new app, context, and anteHandler.
func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {
func (suite *AnteTestSuite) SetupTest() {
suite.Setup(suite.T(), apptesting.SimAppChainID)

// Set up TxConfig.
Expand All @@ -57,33 +57,26 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {

suite.Require().NoError(err)
suite.anteHandler = anteHandler
//
//feePoolBalance := sdk.Coins{{Denom: config.BaseDenom, Amount: sdk.NewInt(int64(math.Pow10(18) * 2))}}
//
//err = suite.App.BankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, feePoolBalance)
//suite.Require().NoError(err)
//err = suite.App.BankKeeper.SendCoinsFromModuleToModule(suite.ctx, minttypes.ModuleName, authtypes.FeeCollectorName, feePoolBalance)
//suite.Require().NoError(err)
}

func TestAnteTestSuite(t *testing.T) {
s = new(AnteTestSuite)
suite.Run(t, s)
}

func getAddr(priv *ed25519.PrivKey) sdk.AccAddress {
func getAddr(priv cryptotypes.PrivKey) sdk.AccAddress {
return priv.PubKey().Address().Bytes()
}

func prepareCosmosTx(priv *ed25519.PrivKey, msgs ...sdk.Msg) client.TxBuilder {
func prepareCosmosTx(priv cryptotypes.PrivKey, msgs ...sdk.Msg) client.TxBuilder {
encodingConfig := config.MakeEncodingConfig()
accountAddress := sdk.AccAddress(priv.PubKey().Address().Bytes())

txBuilder := encodingConfig.TxConfig.NewTxBuilder()

txBuilder.SetGasLimit(1000000)
gasPrice := sdk.NewInt(1)
fees := &sdk.Coins{{Denom: config.BaseDenom, Amount: gasPrice.MulRaw(DEFAULT_FEE)}}
fees := &sdk.Coins{{Denom: config.BaseDenom, Amount: gasPrice.MulRaw(DefaultFee)}}
txBuilder.SetFeeAmount(*fees)
err := txBuilder.SetMsgs(msgs...)
s.Require().NoError(err)
Expand Down
3 changes: 2 additions & 1 deletion x/feeburn/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -46,7 +47,7 @@ func NewUpdateTxFeeBurnPercentProposalHandler() *cobra.Command {
return err
}

description, err := cmd.Flags().GetString(cli.FlagDescription)
description, err := cmd.Flags().GetString(cli.FlagDescription) //nolint:staticcheck // SA1019: govcli.FlagDescription is deprecated
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions x/feeburn/client/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
)

var (
UpdateTxFeeBurnPercentProposalHandler = govclient.NewProposalHandler(cli.NewUpdateTxFeeBurnPercentProposalHandler)
)
var UpdateTxFeeBurnPercentProposalHandler = govclient.NewProposalHandler(cli.NewUpdateTxFeeBurnPercentProposalHandler)
3 changes: 2 additions & 1 deletion x/feeburn/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func TestParamsQuery(t *testing.T) {
keeper, ctx := testkeeper.FeeburnKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()
keeper.SetParams(ctx, params)
err := keeper.SetParams(ctx, params)
require.NoError(t, err)

response, err := keeper.Params(wctx, &types.QueryParamsRequest{})
require.NoError(t, err)
Expand Down
Loading
Loading