Skip to content

Commit

Permalink
chore: fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Max authored and xlab committed May 11, 2023
1 parent 14cdb34 commit 1b19eba
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ run:
skip-files:
- schema/applications/base/application.go
- utilities/cuckoo/filter.go
- x/lsnative/distribution/types/distribution.pb.go
skip-dirs:
- x/lsnative
- ibctesting
linters:
disable-all: false
enable:
Expand Down
7 changes: 7 additions & 0 deletions simapp/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee
}

tx := txConfig.NewTxBuilder()

err := tx.SetMsgs(msgs...)
if err != nil {
return nil, err
}

err = tx.SetSignatures(sigs...)
if err != nil {
return nil, err
}

tx.SetMemo(memo)
tx.SetFeeAmount(feeAmt)
tx.SetGasLimit(gas)
Expand All @@ -60,15 +63,19 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee
Sequence: accSeqs[i],
PubKey: p.PubKey(),
}

signBytes, err := txConfig.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx())
if err != nil {
panic(err)
}

sig, err := p.Sign(signBytes)
if err != nil {
panic(err)
}

sigs[i].Data.(*signing.SingleSignatureData).Signature = sig

err = tx.SetSignatures(sigs...)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/stretchr/testify/require"

svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/genutil/client/cli"
"github.com/persistenceOne/persistence-sdk/v2/simapp"
"github.com/persistenceOne/persistence-sdk/v2/simapp/simd/cmd"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/genutil/client/cli"
)

func TestInitCmd(t *testing.T) {
Expand Down
23 changes: 22 additions & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor {

// Config defines the necessary configuration used to bootstrap and start an
// in-process local testing network.
type Config struct {
type Config struct { //nolint: maligned // not important
Codec codec.Codec
LegacyAmino *codec.LegacyAmino // TODO: Remove!
InterfaceRegistry codectypes.InterfaceRegistry
Expand Down Expand Up @@ -250,6 +250,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
appCfg.GRPC.Enable = false
appCfg.GRPCWeb.Enable = false
apiListenAddr := ""

if i == 0 {
if cfg.APIAddress != "" {
apiListenAddr = cfg.APIAddress
Expand All @@ -262,10 +263,12 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
}

appCfg.API.Address = apiListenAddr

apiURL, err := url.Parse(apiListenAddr)
if err != nil {
return nil, err
}

apiAddr = fmt.Sprintf("http://%s:%s", apiURL.Hostname(), apiURL.Port())

if cfg.RPCAddress != "" {
Expand All @@ -287,17 +290,20 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
}
appCfg.GRPC.Address = fmt.Sprintf("0.0.0.0:%s", grpcPort)
}

appCfg.GRPC.Enable = true

_, grpcWebPort, err := server.FreeTCPAddr()
if err != nil {
return nil, err
}

appCfg.GRPCWeb.Address = fmt.Sprintf("0.0.0.0:%s", grpcWebPort)
appCfg.GRPCWeb.Enable = true
}

logger := server.ZeroLogWrapper{Logger: zerolog.Nop()}

if cfg.EnableTMLogging {
logWriter := zerolog.ConsoleWriter{Out: os.Stderr}
logger = server.ZeroLogWrapper{Logger: zerolog.New(logWriter).Level(zerolog.InfoLevel).With().Timestamp().Logger()}
Expand Down Expand Up @@ -328,6 +334,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if err != nil {
return nil, err
}

tmCfg.ProxyApp = proxyAddr

p2pAddr, _, err := server.FreeTCPAddr()
Expand All @@ -353,6 +360,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
}

keyringAlgos, _ := kb.SupportedAlgorithms()

algo, err := keyring.NewSigningAlgoFromString(cfg.SigningAlgo, keyringAlgos)
if err != nil {
return nil, err
Expand All @@ -375,6 +383,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
}

info := map[string]string{"secret": secret}

infoBz, err := json.Marshal(info)
if err != nil {
return nil, err
Expand Down Expand Up @@ -419,10 +428,12 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port())
fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(0)))
txBuilder := cfg.TxConfig.NewTxBuilder()

err = txBuilder.SetMsgs(createValMsg)
if err != nil {
return nil, err
}

txBuilder.SetFeeAmount(fee) // Arbitrary fee
txBuilder.SetGasLimit(1000000) // Need at least 100386
txBuilder.SetMemo(memo)
Expand All @@ -443,6 +454,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if err != nil {
return nil, err
}

err = writeFile(fmt.Sprintf("%v.json", nodeDirName), gentxsDir, txBz)
if err != nil {
return nil, err
Expand Down Expand Up @@ -481,17 +493,20 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if err != nil {
return nil, err
}

err = collectGenFiles(cfg, network.Validators, network.BaseDir)
if err != nil {
return nil, err
}

l.Log("starting test network...")

for idx, v := range network.Validators {
err := startInProcess(cfg, v)
if err != nil {
return nil, err
}

l.Log("started validator", idx)
}

Expand Down Expand Up @@ -535,16 +550,19 @@ func (n *Network) WaitForHeight(h int64) (int64, error) {
// provide a custom timeout.
func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error) {
ticker := time.NewTicker(time.Second)

defer ticker.Stop()

timeout := time.NewTimer(t)

defer timeout.Stop()

if len(n.Validators) == 0 {
return 0, errors.New("no validators available")
}

var latestHeight int64

val := n.Validators[0]

for {
Expand Down Expand Up @@ -602,6 +620,7 @@ func (n *Network) Cleanup() {

if v.grpc != nil {
v.grpc.Stop()

if v.grpcWeb != nil {
_ = v.grpcWeb.Close()
}
Expand Down Expand Up @@ -645,9 +664,11 @@ func printMnemonic(l Logger, secret string) {

l.Log("\n")
l.Log(strings.Repeat("+", maxLineLength+8))

for _, line := range lines {
l.Logf("++ %s ++\n", centerText(line, maxLineLength))
}

l.Log(strings.Repeat("+", maxLineLength+8))
l.Log("\n")
}
Expand Down
6 changes: 5 additions & 1 deletion testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func startInProcess(cfg Config, val *Validator) error {
}
}
}

return nil
}

Expand All @@ -132,6 +133,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error {
initCfg := genutiltypes.NewInitConfig(cfg.ChainID, gentxsDir, vals[i].NodeID, vals[i].PubKey)

genFile := tmCfg.GenesisFile()

genDoc, err := types.GenesisDocFromFile(genFile)
if err != nil {
return err
Expand All @@ -155,6 +157,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error {
func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string) error {
// set the accounts in the genesis state
var authGenState authtypes.GenesisState

cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[authtypes.ModuleName], &authGenState)

accounts, err := authtypes.PackAccounts(genAccounts)
Expand All @@ -167,6 +170,7 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance

// set the balances in the genesis state
var bankGenState banktypes.GenesisState

cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[banktypes.ModuleName], &bankGenState)

bankGenState.Balances = append(bankGenState.Balances, genBalances...)
Expand Down Expand Up @@ -202,7 +206,7 @@ func writeFile(name string, dir string, contents []byte) error {
return err
}

err = os.WriteFile(file, contents, 0o644) // nolint: gosec
err = os.WriteFile(file, contents, 0o644) //nolint: gosec
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/persistenceOne/persistence-sdk/v2/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
"github.com/persistenceOne/persistence-sdk/v2/testutil/network"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/client/cli"
stakingcli "github.com/persistenceOne/persistence-sdk/v2/x/lsnative/staking/client/cli"
"github.com/stretchr/testify/suite"
Expand Down
2 changes: 1 addition & 1 deletion x/lsnative/distribution/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package simulation
import (
"math/rand"

simappparams "github.com/persistenceOne/persistence-sdk/v2/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
simappparams "github.com/persistenceOne/persistence-sdk/v2/simapp/params"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/keeper"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)
Expand Down
11 changes: 6 additions & 5 deletions x/lsnative/distribution/types/distribution.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/lsnative/genutil/types/genesis_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/genutil/types"
"github.com/persistenceOne/persistence-sdk/v2/simapp"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/genutil/types"
stakingtypes "github.com/persistenceOne/persistence-sdk/v2/x/lsnative/staking/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ message Params {
// The reference count indicates the number of objects
// which might need to reference this historical entry at any point.
// ReferenceCount =
//
// number of outstanding delegations which ended the associated period (and
// might need to read that record)
// + number of slashes which ended the associated period (and might need to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ message Params {
// The reference count indicates the number of objects
// which might need to reference this historical entry at any point.
// ReferenceCount =
//
// number of outstanding delegations which ended the associated period (and
// might need to read that record)
// + number of slashes which ended the associated period (and might need to
Expand Down
2 changes: 1 addition & 1 deletion x/lsnative/staking/types/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/persistenceOne/persistence-sdk/v2/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/persistenceOne/persistence-sdk/v2/simapp"
stakingtypes "github.com/persistenceOne/persistence-sdk/v2/x/lsnative/staking/types"
)

Expand Down
12 changes: 6 additions & 6 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"strings"

"cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
sdkstaking "github.com/cosmos/cosmos-sdk/x/staking/types"
gogotypes "github.com/gogo/protobuf/types"
Expand Down Expand Up @@ -76,7 +76,7 @@ func (k Keeper) GetExchangeRate(ctx sdk.Context, denom string) (sdk.Dec, error)

b := store.Get(types.GetExchangeRateKey(denom))
if b == nil {
return sdk.ZeroDec(), sdkerrors.Wrap(types.ErrUnknownDenom, denom)
return sdk.ZeroDec(), errors.Wrap(types.ErrUnknownDenom, denom)
}

decProto := sdk.DecProto{}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (k Keeper) IterateExchangeRates(ctx sdk.Context, handler func(string, sdk.D
func (k Keeper) GetFeederDelegation(ctx sdk.Context, operator sdk.ValAddress) (sdk.AccAddress, error) {
// check that the given validator exists
if val := k.StakingKeeper.Validator(ctx, operator); val == nil || !val.IsBonded() {
return nil, sdkerrors.Wrapf(sdkstaking.ErrNoValidatorFound, "validator %s is not active set", operator.String())
return nil, errors.Wrapf(sdkstaking.ErrNoValidatorFound, "validator %s is not active set", operator.String())
}

store := ctx.KVStore(k.storeKey)
Expand Down Expand Up @@ -246,7 +246,7 @@ func (k Keeper) GetAggregateExchangeRatePrevote(

bz := store.Get(types.GetAggregateExchangeRatePrevoteKey(voter))
if bz == nil {
return types.AggregateExchangeRatePrevote{}, sdkerrors.Wrap(types.ErrNoAggregatePrevote, voter.String())
return types.AggregateExchangeRatePrevote{}, errors.Wrap(types.ErrNoAggregatePrevote, voter.String())
}

var aggregatePrevote types.AggregateExchangeRatePrevote
Expand Down Expand Up @@ -313,7 +313,7 @@ func (k Keeper) GetAggregateExchangeRateVote(

bz := store.Get(types.GetAggregateExchangeRateVoteKey(voter))
if bz == nil {
return types.AggregateExchangeRateVote{}, sdkerrors.Wrap(types.ErrNoAggregateVote, voter.String())
return types.AggregateExchangeRateVote{}, errors.Wrap(types.ErrNoAggregateVote, voter.String())
}

var aggregateVote types.AggregateExchangeRateVote
Expand Down Expand Up @@ -375,7 +375,7 @@ func (k Keeper) ValidateFeeder(ctx sdk.Context, valAddr sdk.ValAddress, feederAd
}

if !delegate.Equals(feederAddr) {
return sdkerrors.Wrap(types.ErrNoVotingPermission, feederAddr.String())
return errors.Wrap(types.ErrNoVotingPermission, feederAddr.String())
}

return nil
Expand Down
Loading

0 comments on commit 1b19eba

Please sign in to comment.