diff --git a/Makefile b/Makefile index 867dbadc1e..f02ceece13 100644 --- a/Makefile +++ b/Makefile @@ -205,7 +205,11 @@ generate: lint: @echo "Linting all go modules..." - @find . -name 'go.mod' -type f -execdir golangci-lint run --out-format=tab \; + @find . -name 'go.mod' -type f | while read modfile; do \ + moddir=$$(dirname "$$modfile"); \ + echo "Linting module at $$moddir"; \ + (cd "$$moddir" && golangci-lint run --out-format=tab); \ + done lint-fix: format @echo "Attempting to fix lint errors in all go modules..." diff --git a/app/app.go b/app/app.go index cd89d33368..cc52691ade 100644 --- a/app/app.go +++ b/app/app.go @@ -17,6 +17,7 @@ import ( dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/app/simulation/app_after_import_test.go b/app/simulation/app_after_import_test.go index 4afd4c1ce0..e043f58e47 100644 --- a/app/simulation/app_after_import_test.go +++ b/app/simulation/app_after_import_test.go @@ -4,13 +4,15 @@ package simulation import ( "fmt" + "os" + "testing" + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/server" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" - "os" - "testing" abci "github.com/cometbft/cometbft/abci/types" "github.com/stretchr/testify/require" diff --git a/app/simulation/app_determinism_test.go b/app/simulation/app_determinism_test.go index 3573c62b4f..17347e0328 100644 --- a/app/simulation/app_determinism_test.go +++ b/app/simulation/app_determinism_test.go @@ -10,9 +10,10 @@ import ( dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/baseapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" diff --git a/app/simulation/app_import_export_test.go b/app/simulation/app_import_export_test.go index aae8da9e58..e5b57ac542 100644 --- a/app/simulation/app_import_export_test.go +++ b/app/simulation/app_import_export_test.go @@ -5,8 +5,15 @@ package simulation import ( "encoding/json" "fmt" + "os" + "runtime/debug" + "strings" + "testing" + "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/server" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -30,11 +37,6 @@ import ( regen "github.com/regen-network/regen-ledger/v5/app" "github.com/regen-network/regen-ledger/x/data/v3" "github.com/regen-network/regen-ledger/x/ecocredit/v3" - "github.com/stretchr/testify/require" - "os" - "runtime/debug" - "strings" - "testing" ) func TestAppImportExport(t *testing.T) { diff --git a/app/simulation/app_test.go b/app/simulation/app_test.go index a0725a9d96..9b587feee8 100644 --- a/app/simulation/app_test.go +++ b/app/simulation/app_test.go @@ -6,9 +6,10 @@ import ( "os" "testing" + "github.com/stretchr/testify/require" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" - "github.com/stretchr/testify/require" regen "github.com/regen-network/regen-ledger/v5/app" ) diff --git a/app/testsuite/app_test.go b/app/testsuite/app_test.go index ce7cafba0c..1c264cbf88 100644 --- a/app/testsuite/app_test.go +++ b/app/testsuite/app_test.go @@ -2,12 +2,13 @@ package testsuite import ( "fmt" + "os" + "testing" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v7/testing/simapp" regenapp "github.com/regen-network/regen-ledger/v5/app" - "os" - "testing" dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" diff --git a/app/testsuite/modules_test.go b/app/testsuite/modules_test.go index b391ead9ac..7555c9fe33 100644 --- a/app/testsuite/modules_test.go +++ b/app/testsuite/modules_test.go @@ -5,9 +5,10 @@ package testsuite import ( "testing" - "github.com/cosmos/cosmos-sdk/testutil/network" "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/testutil/network" + data "github.com/regen-network/regen-ledger/x/data/v3/client/testsuite" ecocredit "github.com/regen-network/regen-ledger/x/ecocredit/v3/client/testsuite" ) diff --git a/app/testsuite/network_config.go b/app/testsuite/network_config.go index 1489bc8c6b..6a5371eb49 100644 --- a/app/testsuite/network_config.go +++ b/app/testsuite/network_config.go @@ -6,6 +6,7 @@ import ( dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" servertypes "github.com/cosmos/cosmos-sdk/server/types" diff --git a/app/testsuite/suite.go b/app/testsuite/suite.go index 721269989a..3a56a4118b 100644 --- a/app/testsuite/suite.go +++ b/app/testsuite/suite.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/suite" tmtypes "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/app/upgrades.go b/app/upgrades.go index 9a1b110b14..d32276dcf7 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -2,6 +2,7 @@ package app import ( "github.com/cometbft/cometbft/libs/log" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" "github.com/cosmos/cosmos-sdk/baseapp" @@ -72,7 +73,7 @@ func (app *RegenApp) registerUpgrade6_0(upgradeInfo upgradetypes.Plan) { baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) app.UpgradeKeeper.SetUpgradeHandler(planName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { printPlanName(planName, ctx.Logger()) // Migrate CometBFT consensus parameters from x/params module to a dedicated x/consensus module. diff --git a/app/upgrades/v5_0/upgrade.go b/app/upgrades/v5_0/upgrade.go index 997fa841c8..b7046b5680 100644 --- a/app/upgrades/v5_0/upgrade.go +++ b/app/upgrades/v5_0/upgrade.go @@ -24,7 +24,7 @@ const Name = "v5.0" var Upgrade = upgrades.Upgrade{ UpgradeName: Name, CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { // set regen module consensus version fromVM[ecocredit.ModuleName] = 2 fromVM[data.ModuleName] = 1 diff --git a/app/upgrades/v5_0/upgrade_test.go b/app/upgrades/v5_0/upgrade_test.go index 706ffed852..bfb5646cf4 100644 --- a/app/upgrades/v5_0/upgrade_test.go +++ b/app/upgrades/v5_0/upgrade_test.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/cometbft/cometbft/abci/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/regen-network/regen-ledger/v5/app/testsuite" diff --git a/app/upgrades/v5_1/upgrade.go b/app/upgrades/v5_1/upgrade.go index 5df9667d83..828d29ac6e 100644 --- a/app/upgrades/v5_1/upgrade.go +++ b/app/upgrades/v5_1/upgrade.go @@ -14,7 +14,7 @@ const Name = "v5.1" var Upgrade = upgrades.Upgrade{ UpgradeName: Name, CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { // run in-place store migrations for ecocredit module return mm.RunMigrations(ctx, cfg, fromVM) } diff --git a/types/coin.go b/types/coin.go index 4d80f737d3..f4491fe96c 100644 --- a/types/coin.go +++ b/types/coin.go @@ -2,6 +2,7 @@ package types import ( basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/types/coin_test.go b/types/coin_test.go index e8a90006a4..df8c45ab8c 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/regen-network/regen-ledger/types/v2" diff --git a/types/go.mod b/types/go.mod index f5586c4975..c2072d24e4 100644 --- a/types/go.mod +++ b/types/go.mod @@ -14,7 +14,7 @@ require ( github.com/golang/mock v1.6.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/regen-network/gocuke v1.1.0 - github.com/regen-network/regen-ledger/api/v2 v2.0.0-00010101000000-000000000000 + github.com/regen-network/regen-ledger/api/v2 v2.0.0 github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.62.1 diff --git a/types/ormstore/db.go b/types/ormstore/db.go index 6dd4f32a8e..f2cf496c21 100644 --- a/types/ormstore/db.go +++ b/types/ormstore/db.go @@ -4,6 +4,7 @@ import ( "context" ormv1alpha1 "cosmossdk.io/api/cosmos/orm/v1alpha1" + "github.com/cosmos/cosmos-sdk/orm/model/ormdb" "github.com/cosmos/cosmos-sdk/orm/model/ormtable" storetypes "github.com/cosmos/cosmos-sdk/store/types" diff --git a/types/ormstore/db_test.go b/types/ormstore/db_test.go index 4a29ad55cd..473e74bf55 100644 --- a/types/ormstore/db_test.go +++ b/types/ormstore/db_test.go @@ -10,6 +10,7 @@ import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" ormv1alpha1 "cosmossdk.io/api/cosmos/orm/v1alpha1" + "github.com/cosmos/cosmos-sdk/orm/model/ormdb" "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" diff --git a/types/ormutil/compatability.go b/types/ormutil/compatability.go index 4ad1eac071..b9921d5530 100644 --- a/types/ormutil/compatability.go +++ b/types/ormutil/compatability.go @@ -5,6 +5,7 @@ import ( "google.golang.org/protobuf/proto" queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1" + "github.com/cosmos/cosmos-sdk/orm/model/ormlist" "github.com/cosmos/cosmos-sdk/types/query" ) diff --git a/types/ormutil/tm_db.go b/types/ormutil/tm_db.go index 0ae559fdec..bc070dede4 100644 --- a/types/ormutil/tm_db.go +++ b/types/ormutil/tm_db.go @@ -2,6 +2,7 @@ package ormutil import ( dbm "github.com/cometbft/cometbft-db" + "github.com/cosmos/cosmos-sdk/orm/types/kv" // tdbm "github.com/tendermint/tm-db" ) diff --git a/types/testutil/events.go b/types/testutil/events.go index 2fc80b7b93..75a2310cf6 100644 --- a/types/testutil/events.go +++ b/types/testutil/events.go @@ -4,8 +4,9 @@ import ( "fmt" abci "github.com/cometbft/cometbft/abci/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" + + sdk "github.com/cosmos/cosmos-sdk/types" ) // MatchEvent matches the values in a proto message to a sdk.Event. diff --git a/types/testutil/fixture/impl.go b/types/testutil/fixture/impl.go index 5c67ffdd11..6b68576611 100644 --- a/types/testutil/fixture/impl.go +++ b/types/testutil/fixture/impl.go @@ -9,15 +9,16 @@ import ( abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/regen-network/gocuke" + "github.com/stretchr/testify/require" + "google.golang.org/grpc" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" sdkmodules "github.com/cosmos/cosmos-sdk/types/module" - "github.com/regen-network/gocuke" - "github.com/stretchr/testify/require" - "google.golang.org/grpc" ) type factoryImpl struct { diff --git a/x/data/client/testsuite/tx.go b/x/data/client/testsuite/tx.go index c887a53342..1ed56b5876 100644 --- a/x/data/client/testsuite/tx.go +++ b/x/data/client/testsuite/tx.go @@ -418,7 +418,7 @@ func (s *IntegrationTestSuite) TestRegisterResolverCmd() { }, { "invalid resolver id", - []string{fmt.Sprintf("%s", "123a5"), filePath}, + []string{"123a5", filePath}, true, false, "invalid resolver id", diff --git a/x/data/iri.go b/x/data/iri.go index bd5cff82c5..8e33da49e8 100644 --- a/x/data/iri.go +++ b/x/data/iri.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/cosmos/btcutil/base58" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) diff --git a/x/data/keys.go b/x/data/keys.go index bd791039a1..dd32a2ef7d 100644 --- a/x/data/keys.go +++ b/x/data/keys.go @@ -2,6 +2,7 @@ package data import ( ormv1alpha1 "cosmossdk.io/api/cosmos/orm/v1alpha1" + api "github.com/regen-network/regen-ledger/api/v2/regen/data/v1" ) diff --git a/x/data/msg_anchor.go b/x/data/msg_anchor.go index 9a7083f4d2..cd2e7432d5 100644 --- a/x/data/msg_anchor.go +++ b/x/data/msg_anchor.go @@ -28,9 +28,9 @@ func (m *MsgAnchor) GetSigners() []sdk.AccAddress { } // LegacyMsg.Type implementations -func (msg MsgAnchor) Route() string { return "" } -func (msg MsgAnchor) Type() string { return sdk.MsgTypeURL(&msg) } -func (msg *MsgAnchor) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) +func (m MsgAnchor) Route() string { return "" } +func (m MsgAnchor) Type() string { return sdk.MsgTypeURL(&m) } +func (m *MsgAnchor) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(m) return sdk.MustSortJSON(bz) } diff --git a/x/data/msg_attest.go b/x/data/msg_attest.go index 6b6f13ee2a..a1b40fb376 100644 --- a/x/data/msg_attest.go +++ b/x/data/msg_attest.go @@ -37,9 +37,9 @@ func (m *MsgAttest) GetSigners() []sdk.AccAddress { } // LegacyMsg.Type implementations -func (msg MsgAttest) Route() string { return "" } -func (msg MsgAttest) Type() string { return sdk.MsgTypeURL(&msg) } -func (msg *MsgAttest) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) +func (m MsgAttest) Route() string { return "" } +func (m MsgAttest) Type() string { return sdk.MsgTypeURL(&m) } +func (m *MsgAttest) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(m) return sdk.MustSortJSON(bz) } diff --git a/x/data/msg_define_resolver.go b/x/data/msg_define_resolver.go index 5608b8db30..1b1e776fe3 100644 --- a/x/data/msg_define_resolver.go +++ b/x/data/msg_define_resolver.go @@ -30,9 +30,9 @@ func (m *MsgDefineResolver) GetSigners() []sdk.AccAddress { } // LegacyMsg.Type implementations -func (msg MsgDefineResolver) Route() string { return "" } -func (msg MsgDefineResolver) Type() string { return sdk.MsgTypeURL(&msg) } -func (msg *MsgDefineResolver) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) +func (m MsgDefineResolver) Route() string { return "" } +func (m MsgDefineResolver) Type() string { return sdk.MsgTypeURL(&m) } +func (m *MsgDefineResolver) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(m) return sdk.MustSortJSON(bz) } diff --git a/x/data/server/genesis.go b/x/data/server/genesis.go index 3e37469bb4..b4556117bc 100644 --- a/x/data/server/genesis.go +++ b/x/data/server/genesis.go @@ -3,10 +3,11 @@ package server import ( "encoding/json" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/orm/types/ormjson" sdk "github.com/cosmos/cosmos-sdk/types" - abci "github.com/cometbft/cometbft/abci/types" ) // InitGenesis performs genesis initialization for the data module. It diff --git a/x/data/server/hasher/hasher.go b/x/data/server/hasher/hasher.go index f5df41ddc7..77865ea8d0 100644 --- a/x/data/server/hasher/hasher.go +++ b/x/data/server/hasher/hasher.go @@ -2,6 +2,7 @@ package hasher import ( "encoding/binary" + "fmt" "hash" "golang.org/x/crypto/blake2b" @@ -95,6 +96,9 @@ func (t hasher) CreateID(value []byte, collisions int) (id []byte) { id = append(id, hashBz[collisions]) } else { id = id[:t.bufLen] + if collisions < 0 { + panic(fmt.Sprintf("collisions must be non-negative, got %d", collisions)) + } n := binary.PutUvarint(id[t.hashLen:], uint64(collisions)) id = id[:t.hashLen+n] } diff --git a/x/data/server/hasher/hasher_test.go b/x/data/server/hasher/hasher_test.go index af10bd235a..cc3fed6559 100644 --- a/x/data/server/hasher/hasher_test.go +++ b/x/data/server/hasher/hasher_test.go @@ -9,8 +9,9 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/crypto/blake2b" - "github.com/cosmos/cosmos-sdk/store/mem" "github.com/cometbft/cometbft/libs/rand" + + "github.com/cosmos/cosmos-sdk/store/mem" ) func TestHasher(t *testing.T) { diff --git a/x/data/server/query_anchor_by_hash.go b/x/data/server/query_anchor_by_hash.go index c3447d8bab..2308f09d12 100644 --- a/x/data/server/query_anchor_by_hash.go +++ b/x/data/server/query_anchor_by_hash.go @@ -27,7 +27,7 @@ func (s serverImpl) AnchorByHash(ctx context.Context, request *data.QueryAnchorB anchor, err := s.stateStore.DataAnchorTable().Get(ctx, dataID.Id) if err != nil { - return nil, regenerrors.ErrNotFound.Wrapf(err.Error()) + return nil, regenerrors.ErrNotFound.Wrap(err.Error()) } return &data.QueryAnchorByHashResponse{ diff --git a/x/data/server/server.go b/x/data/server/server.go index c18ebf3219..279a0d558c 100644 --- a/x/data/server/server.go +++ b/x/data/server/server.go @@ -3,11 +3,12 @@ package server import ( "encoding/json" + "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/orm/model/ormdb" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cometbft/cometbft/abci/types" api "github.com/regen-network/regen-ledger/api/v2/regen/data/v1" "github.com/regen-network/regen-ledger/types/v2/ormstore" diff --git a/x/data/server/server_test.go b/x/data/server/server_test.go index 7c110a1f32..c7e5988289 100644 --- a/x/data/server/server_test.go +++ b/x/data/server/server_test.go @@ -3,10 +3,10 @@ package server import ( "context" + dbm "github.com/cometbft/cometbft-db" "github.com/golang/mock/gomock" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" - dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" diff --git a/x/ecocredit/base/client/query.go b/x/ecocredit/base/client/query.go index b49fcde510..26efd6852c 100644 --- a/x/ecocredit/base/client/query.go +++ b/x/ecocredit/base/client/query.go @@ -18,7 +18,7 @@ func QueryClassesCmd() *cobra.Command { Example: `regen q ecocredit classes regen q ecocredit classes --limit 10 --offset 10`, Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -104,7 +104,7 @@ func QueryProjectsCmd() *cobra.Command { Example: `regen q ecocredit projects regen q ecocredit projects --limit 10 --offset 10`, Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -193,7 +193,7 @@ func QueryBatchesCmd() *cobra.Command { Example: `regen q ecocredit batches regen q ecocredit batches --limit 10 --offset 10`, Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -397,7 +397,7 @@ func QueryCreditTypesCmd() *cobra.Command { Long: "List all credit types.", Example: "regen q ecocredit types", Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -415,7 +415,7 @@ func QueryParamsCmd() *cobra.Command { Short: "List the current ecocredit module parameters", Long: "List the current ecocredit module parameters.", Example: "regen q ecocredit params", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -521,7 +521,7 @@ func QueryClassFeeCmd() *cobra.Command { Short: "Retrieve the credit class creation fee", Long: "Retrieve the credit class creation fee", Example: "regen q ecocredit class-fee", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -540,7 +540,7 @@ func QueryClassCreatorAllowlistCmd() *cobra.Command { Short: "Retrieve the class creator allowlist enabled setting", Long: "Retrieve the class creator allowlist enabled setting", Example: "regen q ecocredit class-creator-allowlist", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -560,7 +560,7 @@ func QueryAllowedClassCreatorsCmd() *cobra.Command { Long: "Retrieve the list of allowed credit class creators with optional pagination flags.", Example: `regen q ecocredit allowed-class-creators regen q ecocredit allowed-class-creators --limit 10`, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -592,7 +592,7 @@ func QueryAllBalancesCmd() *cobra.Command { Long: "Retrieve all ecocredit balances across all addresses and credit batches with optional pagination flags.", Example: `regen q ecocredit all-balances regen q ecocredit all-balances --limit 10`, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err @@ -655,7 +655,7 @@ func QueryAllowedBridgeChainsCmd() *cobra.Command { Short: "Retrieve the list of allowed bridge chains", Long: "Retrieve the list of chains that are allowed to be used in bridge operations", Example: "regen q ecocredit allowed-bridge-chains", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { c, ctx, err := mkQueryClient(cmd) if err != nil { return err diff --git a/x/ecocredit/base/keeper/msg_burn_regen.go b/x/ecocredit/base/keeper/msg_burn_regen.go index 0e33658e67..e51215aaf8 100644 --- a/x/ecocredit/base/keeper/msg_burn_regen.go +++ b/x/ecocredit/base/keeper/msg_burn_regen.go @@ -5,6 +5,7 @@ import ( "fmt" "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/regen-network/regen-ledger/x/ecocredit/v3" diff --git a/x/ecocredit/base/keeper/msg_burn_regen_test.go b/x/ecocredit/base/keeper/msg_burn_regen_test.go index ef20d523cd..984921c62b 100644 --- a/x/ecocredit/base/keeper/msg_burn_regen_test.go +++ b/x/ecocredit/base/keeper/msg_burn_regen_test.go @@ -3,11 +3,12 @@ package keeper import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/jsonpb" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/regen-network/regen-ledger/types/v2/testutil" "github.com/regen-network/regen-ledger/x/ecocredit/v3" types "github.com/regen-network/regen-ledger/x/ecocredit/v3/base/types/v1" diff --git a/x/ecocredit/base/keeper/msg_update_batch_metadata_test.go b/x/ecocredit/base/keeper/msg_update_batch_metadata_test.go index 4ef911309f..831c06bf07 100644 --- a/x/ecocredit/base/keeper/msg_update_batch_metadata_test.go +++ b/x/ecocredit/base/keeper/msg_update_batch_metadata_test.go @@ -175,6 +175,6 @@ func (s *updateBatchMetadata) ExpectEventWithProperties(a gocuke.DocString) { require.Equal(s.t, proto.MessageName(&event), lastEvent.Type) require.Len(s.t, lastEvent.Attributes, 1) - batchDenom := strings.Trim(string(lastEvent.Attributes[0].Value), `"`) + batchDenom := strings.Trim(lastEvent.Attributes[0].Value, `"`) require.Equal(s.t, event.BatchDenom, batchDenom) } diff --git a/x/ecocredit/base/keeper/msg_update_class_fee.go b/x/ecocredit/base/keeper/msg_update_class_fee.go index d7ae850a27..4bb3190d7b 100644 --- a/x/ecocredit/base/keeper/msg_update_class_fee.go +++ b/x/ecocredit/base/keeper/msg_update_class_fee.go @@ -4,6 +4,7 @@ import ( "context" sdkbase "cosmossdk.io/api/cosmos/base/v1beta1" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" api "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1" diff --git a/x/ecocredit/base/keeper/msg_update_class_metadata_test.go b/x/ecocredit/base/keeper/msg_update_class_metadata_test.go index ab96e0a7ec..b6f3f0f194 100644 --- a/x/ecocredit/base/keeper/msg_update_class_metadata_test.go +++ b/x/ecocredit/base/keeper/msg_update_class_metadata_test.go @@ -120,6 +120,6 @@ func (s *updateClassMetadata) ExpectEventWithProperties(a gocuke.DocString) { require.Equal(s.t, proto.MessageName(&event), lastEvent.Type) require.Len(s.t, lastEvent.Attributes, 1) // should only have classID - classID := strings.Trim(string(lastEvent.Attributes[0].Value), `"`) + classID := strings.Trim(lastEvent.Attributes[0].Value, `"`) require.Equal(s.t, event.ClassId, classID) } diff --git a/x/ecocredit/base/keeper/query_params_test.go b/x/ecocredit/base/keeper/query_params_test.go index 962a1c7247..b02064a0d9 100644 --- a/x/ecocredit/base/keeper/query_params_test.go +++ b/x/ecocredit/base/keeper/query_params_test.go @@ -6,6 +6,7 @@ import ( "gotest.tools/v3/assert" sdkbase "cosmossdk.io/api/cosmos/base/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" baskettypes "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/basket/v1" diff --git a/x/ecocredit/base/simulation/msg_add_class_creator.go b/x/ecocredit/base/simulation/msg_add_class_creator.go index b1ad9598d3..9dcac1995c 100644 --- a/x/ecocredit/base/simulation/msg_add_class_creator.go +++ b/x/ecocredit/base/simulation/msg_add_class_creator.go @@ -26,7 +26,7 @@ const WeightAddClassCreator = 33 func SimulateMsgAddClassCreator(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, govk ecocredit.GovKeeper, qryClient types.QueryServer, authority sdk.AccAddress) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { proposer, _ := simtypes.RandomAcc(r, accs) proposerAddr := proposer.Address.String() diff --git a/x/ecocredit/base/simulation/msg_add_credit_type.go b/x/ecocredit/base/simulation/msg_add_credit_type.go index 7c2de56273..2bd953cacc 100644 --- a/x/ecocredit/base/simulation/msg_add_credit_type.go +++ b/x/ecocredit/base/simulation/msg_add_credit_type.go @@ -28,7 +28,7 @@ const WeightAddCreditType = 33 func SimulateMsgAddCreditType(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, govk ecocredit.GovKeeper, qryClient types.QueryServer, authority sdk.AccAddress) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { proposer, _ := simtypes.RandomAcc(r, accs) proposerAddr := proposer.Address.String() diff --git a/x/ecocredit/base/simulation/msg_cancel.go b/x/ecocredit/base/simulation/msg_cancel.go index 38ee74bbdb..bd702a819f 100644 --- a/x/ecocredit/base/simulation/msg_cancel.go +++ b/x/ecocredit/base/simulation/msg_cancel.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -25,7 +25,7 @@ const WeightCancel = 30 func SimulateMsgCancel(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { ctx := sdk.WrapSDKContext(sdkCtx) diff --git a/x/ecocredit/base/simulation/msg_create_batch.go b/x/ecocredit/base/simulation/msg_create_batch.go index b2924c20f7..1491d5ddb5 100644 --- a/x/ecocredit/base/simulation/msg_create_batch.go +++ b/x/ecocredit/base/simulation/msg_create_batch.go @@ -5,8 +5,8 @@ import ( "time" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -25,7 +25,7 @@ const WeightCreateBatch = 50 func SimulateMsgCreateBatch(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { issuer, _ := simtypes.RandomAcc(r, accs) diff --git a/x/ecocredit/base/simulation/msg_create_class.go b/x/ecocredit/base/simulation/msg_create_class.go index 6317b803fc..a8b9a00378 100644 --- a/x/ecocredit/base/simulation/msg_create_class.go +++ b/x/ecocredit/base/simulation/msg_create_class.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -24,7 +24,7 @@ const WeightCreateClass = 10 func SimulateMsgCreateClass(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { admin, _ := simtypes.RandomAcc(r, accs) issuers := randomIssuers(r, accs) diff --git a/x/ecocredit/base/simulation/msg_create_project.go b/x/ecocredit/base/simulation/msg_create_project.go index c0091e9448..c08a9a712b 100644 --- a/x/ecocredit/base/simulation/msg_create_project.go +++ b/x/ecocredit/base/simulation/msg_create_project.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -24,7 +24,7 @@ const WeightCreateProject = 20 func SimulateMsgCreateProject(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { class, op, err := utils.GetRandomClass(sdkCtx, r, qryClient, TypeMsgCreateProject) if class == nil { diff --git a/x/ecocredit/base/simulation/msg_mint_batch_credits.go b/x/ecocredit/base/simulation/msg_mint_batch_credits.go index 4e3b5f7556..8b9a9a435c 100644 --- a/x/ecocredit/base/simulation/msg_mint_batch_credits.go +++ b/x/ecocredit/base/simulation/msg_mint_batch_credits.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -23,7 +23,7 @@ const WeightMintBatchCredits = 33 // SimulateMsgMintBatchCredits generates a MsgMintBatchCredits with random values. func SimulateMsgMintBatchCredits(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { issuerAcc, _ := simtypes.RandomAcc(r, accs) issuerAddr := issuerAcc.Address.String() diff --git a/x/ecocredit/base/simulation/msg_remove_class_creator.go b/x/ecocredit/base/simulation/msg_remove_class_creator.go index 4f53f102bd..5e82610ad0 100644 --- a/x/ecocredit/base/simulation/msg_remove_class_creator.go +++ b/x/ecocredit/base/simulation/msg_remove_class_creator.go @@ -26,7 +26,7 @@ const WeightRemoveClassCreator = 33 func SimulateMsgRemoveClassCreator(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, govk ecocredit.GovKeeper, qryClient types.QueryServer, authority sdk.AccAddress) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { proposer, _ := simtypes.RandomAcc(r, accs) proposerAddr := proposer.Address.String() diff --git a/x/ecocredit/base/simulation/msg_retire.go b/x/ecocredit/base/simulation/msg_retire.go index be9fe8a56b..076a73eb88 100644 --- a/x/ecocredit/base/simulation/msg_retire.go +++ b/x/ecocredit/base/simulation/msg_retire.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -25,7 +25,7 @@ const WeightRetire = 80 func SimulateMsgRetire(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { ctx := sdk.WrapSDKContext(sdkCtx) diff --git a/x/ecocredit/base/simulation/msg_seal_batch.go b/x/ecocredit/base/simulation/msg_seal_batch.go index cfdf7762f8..d354c9fb28 100644 --- a/x/ecocredit/base/simulation/msg_seal_batch.go +++ b/x/ecocredit/base/simulation/msg_seal_batch.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -23,7 +23,7 @@ const WeightSealBatch = 33 // SimulateMsgSealBatch generates a MsgSealBatch with random values. func SimulateMsgSealBatch(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { issuerAcc, _ := simtypes.RandomAcc(r, accs) issuerAddr := issuerAcc.Address.String() diff --git a/x/ecocredit/base/simulation/msg_send.go b/x/ecocredit/base/simulation/msg_send.go index 737f5827bb..5328d88c18 100644 --- a/x/ecocredit/base/simulation/msg_send.go +++ b/x/ecocredit/base/simulation/msg_send.go @@ -5,8 +5,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -26,7 +26,7 @@ const WeightSend = 100 func SimulateMsgSend(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { ctx := sdk.WrapSDKContext(sdkCtx) diff --git a/x/ecocredit/base/simulation/msg_set_class_creator_allowlist.go b/x/ecocredit/base/simulation/msg_set_class_creator_allowlist.go index e0c659a288..85323bd5c5 100644 --- a/x/ecocredit/base/simulation/msg_set_class_creator_allowlist.go +++ b/x/ecocredit/base/simulation/msg_set_class_creator_allowlist.go @@ -26,7 +26,7 @@ const WeightSetClassCreatorAllowlist = 33 func SimulateMsgSetClassCreatorAllowlist(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, govk ecocredit.GovKeeper, _ types.QueryServer, authority sdk.AccAddress) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { proposer, _ := simtypes.RandomAcc(r, accs) proposerAddr := proposer.Address.String() diff --git a/x/ecocredit/base/simulation/msg_update_batch_metadata.go b/x/ecocredit/base/simulation/msg_update_batch_metadata.go index c98f373bfb..79cd83a941 100644 --- a/x/ecocredit/base/simulation/msg_update_batch_metadata.go +++ b/x/ecocredit/base/simulation/msg_update_batch_metadata.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -24,7 +24,7 @@ const WeightUpdateBatchMetadata = 30 // SimulateMsgUpdateBatchMetadata generates a MsgUpdateBatchMetadata with random values. func SimulateMsgUpdateBatchMetadata(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { class, op, err := utils.GetRandomClass(sdkCtx, r, qryClient, TypeMsgUpdateBatchMetadata) if err != nil { diff --git a/x/ecocredit/base/simulation/msg_update_class_admin.go b/x/ecocredit/base/simulation/msg_update_class_admin.go index ab6cfffe48..9172441cbd 100644 --- a/x/ecocredit/base/simulation/msg_update_class_admin.go +++ b/x/ecocredit/base/simulation/msg_update_class_admin.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -24,7 +24,7 @@ const WeightUpdateClass = 30 func SimulateMsgUpdateClassAdmin(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { class, op, err := utils.GetRandomClass(sdkCtx, r, qryClient, TypeMsgUpdateClassAdmin) if class == nil { diff --git a/x/ecocredit/base/simulation/msg_update_class_fee.go b/x/ecocredit/base/simulation/msg_update_class_fee.go index f577b32e51..73696b52e4 100644 --- a/x/ecocredit/base/simulation/msg_update_class_fee.go +++ b/x/ecocredit/base/simulation/msg_update_class_fee.go @@ -26,7 +26,7 @@ const WeightUpdateClassFee = 33 func SimulateMsgUpdateClassFee(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, govk ecocredit.GovKeeper, _ types.QueryServer, authority sdk.AccAddress) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { proposer, _ := simtypes.RandomAcc(r, accs) proposerAddr := proposer.Address.String() diff --git a/x/ecocredit/base/simulation/msg_update_class_issuers.go b/x/ecocredit/base/simulation/msg_update_class_issuers.go index ec25614f4a..a3ac9773e8 100644 --- a/x/ecocredit/base/simulation/msg_update_class_issuers.go +++ b/x/ecocredit/base/simulation/msg_update_class_issuers.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -24,7 +24,7 @@ const MsgUpdateClassIssuers = 33 func SimulateMsgUpdateClassIssuers(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { class, op, err := utils.GetRandomClass(sdkCtx, r, qryClient, TypeMsgUpdateClassIssuers) if class == nil { diff --git a/x/ecocredit/base/simulation/msg_update_class_metadata.go b/x/ecocredit/base/simulation/msg_update_class_metadata.go index 1477abee6a..fbcde9cb77 100644 --- a/x/ecocredit/base/simulation/msg_update_class_metadata.go +++ b/x/ecocredit/base/simulation/msg_update_class_metadata.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -24,7 +24,7 @@ const WeightUpdateClassMetadata = 33 func SimulateMsgUpdateClassMetadata(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { class, op, err := utils.GetRandomClass(sdkCtx, r, qryClient, TypeMsgUpdateClassMetadata) if class == nil { diff --git a/x/ecocredit/base/simulation/msg_update_project_admin.go b/x/ecocredit/base/simulation/msg_update_project_admin.go index 6ae8fee7fa..63de2c8e01 100644 --- a/x/ecocredit/base/simulation/msg_update_project_admin.go +++ b/x/ecocredit/base/simulation/msg_update_project_admin.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -23,7 +23,7 @@ const WeightUpdateProjectAdmin = 30 // SimulateMsgUpdateProjectAdmin generates a MsgUpdateProjectAdmin with random values. func SimulateMsgUpdateProjectAdmin(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { class, op, err := utils.GetRandomClass(sdkCtx, r, qryClient, TypeMsgUpdateProjectAdmin) if err != nil { diff --git a/x/ecocredit/base/simulation/msg_update_project_metadata.go b/x/ecocredit/base/simulation/msg_update_project_metadata.go index b3f626591e..2b7b58164c 100644 --- a/x/ecocredit/base/simulation/msg_update_project_metadata.go +++ b/x/ecocredit/base/simulation/msg_update_project_metadata.go @@ -4,8 +4,8 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -24,7 +24,7 @@ const WeightUpdateProjectMetadata = 30 // SimulateMsgUpdateProjectMetadata generates a MsgUpdateProjectMetadata with random values. func SimulateMsgUpdateProjectMetadata(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { class, op, err := utils.GetRandomClass(sdkCtx, r, qryClient, TypeMsgUpdateProjectMetadata) if err != nil { diff --git a/x/ecocredit/base/types/v1/msg_burn_regen.go b/x/ecocredit/base/types/v1/msg_burn_regen.go index bfe455478d..68f0a6b920 100644 --- a/x/ecocredit/base/types/v1/msg_burn_regen.go +++ b/x/ecocredit/base/types/v1/msg_burn_regen.go @@ -2,6 +2,7 @@ package v1 import ( "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" diff --git a/x/ecocredit/basket/client/query.go b/x/ecocredit/basket/client/query.go index d0ea5bdd29..19bd5eab85 100644 --- a/x/ecocredit/basket/client/query.go +++ b/x/ecocredit/basket/client/query.go @@ -49,7 +49,7 @@ regen q ecocredit baskets regen q ecocredit baskets --limit 10 --offset 10 `, Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx, err := client.GetClientQueryContext(cmd) if err != nil { return err @@ -160,7 +160,7 @@ func QueryBasketFeeCmd() *cobra.Command { regen q ecocredit basket-fee `, Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx, err := client.GetClientQueryContext(cmd) if err != nil { return err diff --git a/x/ecocredit/basket/keeper/invariants.go b/x/ecocredit/basket/keeper/invariants.go index c09d621b9b..f672f32143 100644 --- a/x/ecocredit/basket/keeper/invariants.go +++ b/x/ecocredit/basket/keeper/invariants.go @@ -3,6 +3,7 @@ package keeper import ( "context" "fmt" + stdmath "math" "sort" "strings" @@ -52,6 +53,9 @@ func SupplyInvariant(ctx sdk.Context, store api.BasketTable, bank bankSupplyStor return fmt.Sprintf("failed to get basket %v: %v", bid, err), true } bal := basketBalances[bid] + if b.Exponent > stdmath.MaxInt32 { + return fmt.Sprintf("exponent %d is too large", b.Exponent), true + } exp := math.NewDecFinite(1, int32(b.Exponent)) //nolint:staticcheck mul, err := bal.Mul(exp) if err != nil { diff --git a/x/ecocredit/basket/keeper/msg_put_test.go b/x/ecocredit/basket/keeper/msg_put_test.go index c24da4d039..22a107cb91 100644 --- a/x/ecocredit/basket/keeper/msg_put_test.go +++ b/x/ecocredit/basket/keeper/msg_put_test.go @@ -2,6 +2,8 @@ package keeper import ( "encoding/json" + "fmt" + stdmath "math" "strconv" "strings" "testing" @@ -578,6 +580,11 @@ func (s *putSuite) calculateExpectedCoin(amount string) sdk.Coin { } require.NoError(s.t, err) + // Check credit type precision safe casting value + if creditType.Precision > stdmath.MaxInt32 { + err = fmt.Errorf("credit type precision %d is too large", creditType.Precision) + } + require.NoError(s.t, err) tokenAmt, err := math.NewDecFinite(1, int32(creditType.Precision)).MulExact(dec) require.NoError(s.t, err) diff --git a/x/ecocredit/basket/keeper/msg_take.go b/x/ecocredit/basket/keeper/msg_take.go index 0bb2ec05c6..badb77908e 100644 --- a/x/ecocredit/basket/keeper/msg_take.go +++ b/x/ecocredit/basket/keeper/msg_take.go @@ -3,6 +3,7 @@ package keeper import ( "context" "fmt" + stdmath "math" sdkMath "cosmossdk.io/math" @@ -71,6 +72,10 @@ func (k Keeper) Take(ctx context.Context, msg *types.MsgTake) (*types.MsgTakeRes return nil, err } + if creditType.Precision > stdmath.MaxInt32 { + return nil, fmt.Errorf("credit type precision %d is too large", creditType.Precision) + + } multiplier := math.NewDecFinite(1, int32(creditType.Precision)) amountCreditsNeeded, err := amountBasketCreditsDec.QuoExact(multiplier) if err != nil { diff --git a/x/ecocredit/basket/keeper/msg_update_basket_fee.go b/x/ecocredit/basket/keeper/msg_update_basket_fee.go index 0d1016aa2f..e6fa81f961 100644 --- a/x/ecocredit/basket/keeper/msg_update_basket_fee.go +++ b/x/ecocredit/basket/keeper/msg_update_basket_fee.go @@ -4,6 +4,7 @@ import ( "context" sdkbase "cosmossdk.io/api/cosmos/base/v1beta1" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" api "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/basket/v1" diff --git a/x/ecocredit/basket/keeper/query_basket_fees_test.go b/x/ecocredit/basket/keeper/query_basket_fees_test.go index 7e8aded8da..e081af7773 100644 --- a/x/ecocredit/basket/keeper/query_basket_fees_test.go +++ b/x/ecocredit/basket/keeper/query_basket_fees_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/basket/v1" diff --git a/x/ecocredit/basket/keeper/utils.go b/x/ecocredit/basket/keeper/utils.go index 77ff96de8c..c215492d50 100644 --- a/x/ecocredit/basket/keeper/utils.go +++ b/x/ecocredit/basket/keeper/utils.go @@ -2,6 +2,8 @@ package keeper import ( "context" + "fmt" + stdmath "math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -62,6 +64,10 @@ func (k Keeper) GetBasketBalanceMap(ctx context.Context) (map[uint64]math.Dec, e // creditAmountToBasketCoin calculates the coins to mint to the credit depositor using the following formula: // coinAmount = creditAmt * (1 * 10^exp) func creditAmountToBasketCoin(creditAmt math.Dec, exp uint32, denom string) (sdk.Coin, error) { + // check exp value + if exp > stdmath.MaxInt32 { + return sdk.Coin{}, fmt.Errorf("exponent value %d is too large", exp) + } multiplier := math.NewDecFinite(1, int32(exp)) tokenAmt, err := multiplier.MulExact(creditAmt) if err != nil { diff --git a/x/ecocredit/basket/simulation/msg_create.go b/x/ecocredit/basket/simulation/msg_create.go index db213ec7d4..fc6345b34f 100644 --- a/x/ecocredit/basket/simulation/msg_create.go +++ b/x/ecocredit/basket/simulation/msg_create.go @@ -57,7 +57,7 @@ func SimulateMsgCreate(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgCreate, "credit type not found"), nil, nil } - classIDs, op, err := randomClassIds(r, sdkCtx, baseClient, creditType.Abbreviation, TypeMsgPut) + classIDs, op, err := randomClassIDs(r, sdkCtx, baseClient, creditType.Abbreviation, TypeMsgPut) if len(classIDs) == 0 { return op, nil, err } @@ -170,7 +170,7 @@ func randomDateCriteria(r *rand.Rand, ctx sdk.Context) *types.DateCriteria { return nil } -func randomClassIds(r *rand.Rand, ctx sdk.Context, qryClient basetypes.QueryServer, +func randomClassIDs(r *rand.Rand, ctx sdk.Context, qryClient basetypes.QueryServer, creditTypeAbbrev string, msgType string) ([]string, simtypes.OperationMsg, error) { classes, op, err := utils.GetClasses(ctx, r, qryClient, msgType) if len(classes) == 0 { @@ -181,9 +181,9 @@ func randomClassIds(r *rand.Rand, ctx sdk.Context, qryClient basetypes.QueryServ return []string{classes[0].Id}, simtypes.NoOpMsg(ecocredit.ModuleName, msgType, ""), nil } - max := simtypes.RandIntBetween(r, 1, min(5, len(classes))) + maxVal := simtypes.RandIntBetween(r, 1, minVal(5, len(classes))) var classIDs []string - for i := 0; i < max; i++ { + for i := 0; i < maxVal; i++ { class := classes[i] if class.CreditTypeAbbrev == creditTypeAbbrev { classIDs = append(classIDs, class.Id) @@ -193,7 +193,7 @@ func randomClassIds(r *rand.Rand, ctx sdk.Context, qryClient basetypes.QueryServ return classIDs, simtypes.NoOpMsg(ecocredit.ModuleName, msgType, ""), nil } -func min(x, y int) int { +func minVal(x, y int) int { if x > y { return y } diff --git a/x/ecocredit/basket/simulation/msg_put.go b/x/ecocredit/basket/simulation/msg_put.go index ddcf4fa14f..5ec9781001 100644 --- a/x/ecocredit/basket/simulation/msg_put.go +++ b/x/ecocredit/basket/simulation/msg_put.go @@ -48,7 +48,7 @@ func SimulateMsgPut(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, rBasket := baskets[r.Intn(len(baskets))] var classInfoList []basetypes.ClassInfo - max := 0 + maxVal := 0 var ownerAddr string var owner simtypes.Account @@ -76,14 +76,14 @@ func SimulateMsgPut(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, ownerAddr = issuers[0] owner = acc classInfoList = append(classInfoList, *class) - max++ + maxVal++ } } else if utils.Contains(issuers, ownerAddr) { classInfoList = append(classInfoList, *class) - max++ + maxVal++ } - if max == 2 { + if maxVal == 2 { break } } diff --git a/x/ecocredit/basket/simulation/msg_take.go b/x/ecocredit/basket/simulation/msg_take.go index 9603728797..14adf66ec9 100644 --- a/x/ecocredit/basket/simulation/msg_take.go +++ b/x/ecocredit/basket/simulation/msg_take.go @@ -6,8 +6,8 @@ import ( "strconv" "github.com/cosmos/cosmos-sdk/baseapp" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -27,7 +27,7 @@ var TypeMsgTake = types.MsgTake{}.Route() func SimulateMsgTake(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, _ basetypes.QueryServer, bsktQryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { owner, _ := simtypes.RandomAcc(r, accs) ownerAddr := owner.Address.String() diff --git a/x/ecocredit/basket/simulation/msg_update_basket_fees.go b/x/ecocredit/basket/simulation/msg_update_basket_fees.go index d72b180a30..52e5a1a3f1 100644 --- a/x/ecocredit/basket/simulation/msg_update_basket_fees.go +++ b/x/ecocredit/basket/simulation/msg_update_basket_fees.go @@ -27,7 +27,7 @@ const WeightUpdateBasketFees = 100 func SimulateMsgUpdateBasketFee(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, _ basetypes.QueryServer, _ types.QueryServer, govk ecocredit.GovKeeper, authority sdk.AccAddress) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { proposer, _ := simtypes.RandomAcc(r, accs) diff --git a/x/ecocredit/basket/types/v1/msg_put.go b/x/ecocredit/basket/types/v1/msg_put.go index ede261f655..722bb8a6c8 100644 --- a/x/ecocredit/basket/types/v1/msg_put.go +++ b/x/ecocredit/basket/types/v1/msg_put.go @@ -28,7 +28,7 @@ func (m MsgPut) GetSignBytes() []byte { // ValidateBasic does a stateless sanity check on the provided data. func (m MsgPut) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Owner); err != nil { - return sdkerrors.ErrInvalidRequest.Wrapf(err.Error()) + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if err := basket.ValidateBasketDenom(m.BasketDenom); err != nil { diff --git a/x/ecocredit/basket/types/v1/msg_take.go b/x/ecocredit/basket/types/v1/msg_take.go index f54a08ed36..e8865426b6 100644 --- a/x/ecocredit/basket/types/v1/msg_take.go +++ b/x/ecocredit/basket/types/v1/msg_take.go @@ -26,7 +26,7 @@ func (m MsgTake) GetSignBytes() []byte { // ValidateBasic does a stateless sanity check on the provided data. func (m MsgTake) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Owner); err != nil { - return sdkerrors.ErrInvalidRequest.Wrapf(err.Error()) + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } if err := basket.ValidateBasketDenom(m.BasketDenom); err != nil { diff --git a/x/ecocredit/basket/utils_test.go b/x/ecocredit/basket/utils_test.go index 67683a80d3..7ff84b98a4 100644 --- a/x/ecocredit/basket/utils_test.go +++ b/x/ecocredit/basket/utils_test.go @@ -30,7 +30,7 @@ func TestFormatBasketDenom(t *testing.T) { } require := require.New(t) for _, tc := range tcs { - t.Run(tc.tname, func(t *testing.T) { + t.Run(tc.tname, func(_ *testing.T) { d, displayD, err := FormatBasketDenom("foo", tc.abbrev, tc.exponent) if tc.err { require.Error(err, tc.tname) diff --git a/x/ecocredit/client/testsuite/query.go b/x/ecocredit/client/testsuite/query.go index 1667e6a940..5f80a7249e 100644 --- a/x/ecocredit/client/testsuite/query.go +++ b/x/ecocredit/client/testsuite/query.go @@ -83,12 +83,12 @@ func (s *IntegrationTestSuite) TestQueryClassesCmd() { if tc.expectedAmtClasses > 0 { s.Require().Len(res.Classes, tc.expectedAmtClasses) } else { - resClassIds := make([]string, len(res.Classes)) + resClassIDs := make([]string, len(res.Classes)) for i, cls := range res.Classes { - resClassIds[i] = cls.Id + resClassIDs[i] = cls.Id } for _, id := range classIDs { - s.Require().Contains(resClassIds, id) + s.Require().Contains(resClassIDs, id) } } } diff --git a/x/ecocredit/client/testsuite/suite.go b/x/ecocredit/client/testsuite/suite.go index 9ea7b04f2c..3d2c8399c3 100644 --- a/x/ecocredit/client/testsuite/suite.go +++ b/x/ecocredit/client/testsuite/suite.go @@ -1,14 +1,18 @@ package testsuite import ( - "cosmossdk.io/math" "encoding/json" "fmt" "strconv" "strings" + "cosmossdk.io/math" + sdkbase "cosmossdk.io/api/cosmos/base/v1beta1" dbm "github.com/cometbft/cometbft-db" + "github.com/cosmos/gogoproto/proto" + "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" @@ -20,8 +24,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/gogoproto/proto" - "github.com/stretchr/testify/suite" basketapi "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/basket/v1" marketapi "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/marketplace/v1" diff --git a/x/ecocredit/genesis/genesis_test.go b/x/ecocredit/genesis/genesis_test.go index 3f1e6be8cd..0482568283 100644 --- a/x/ecocredit/genesis/genesis_test.go +++ b/x/ecocredit/genesis/genesis_test.go @@ -12,6 +12,7 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/orm/model/ormdb" diff --git a/x/ecocredit/marketplace/client/query.go b/x/ecocredit/marketplace/client/query.go index 98e76b0169..20916c205b 100644 --- a/x/ecocredit/marketplace/client/query.go +++ b/x/ecocredit/marketplace/client/query.go @@ -55,7 +55,7 @@ func QuerySellOrdersCmd() *cobra.Command { Example: `regen q sell-orders regen q sell-orders --limit 10 --offset 10`, Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx, err := sdkclient.GetClientQueryContext(cmd) if err != nil { return err @@ -164,7 +164,7 @@ func QueryAllowedDenomsCmd() *cobra.Command { Example: `regen q ecocredit allowed-denoms regen q ecocredit allowed-denoms --limit 10 --offset 10`, Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx, err := sdkclient.GetClientQueryContext(cmd) if err != nil { return err diff --git a/x/ecocredit/marketplace/keeper/msg_gov_send_from_fee_pool_test.go b/x/ecocredit/marketplace/keeper/msg_gov_send_from_fee_pool_test.go index 6ca51c2733..c3f012b5d8 100644 --- a/x/ecocredit/marketplace/keeper/msg_gov_send_from_fee_pool_test.go +++ b/x/ecocredit/marketplace/keeper/msg_gov_send_from_fee_pool_test.go @@ -3,12 +3,13 @@ package keeper import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/golang/mock/gomock" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + types "github.com/regen-network/regen-ledger/x/ecocredit/v3/marketplace/types/v1" ) diff --git a/x/ecocredit/marketplace/keeper/prune_sell_orders.go b/x/ecocredit/marketplace/keeper/prune_sell_orders.go index e6b50993f4..0c644c330f 100644 --- a/x/ecocredit/marketplace/keeper/prune_sell_orders.go +++ b/x/ecocredit/marketplace/keeper/prune_sell_orders.go @@ -17,11 +17,11 @@ import ( func (k Keeper) PruneSellOrders(ctx context.Context) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - // we set the min to 1 ns because nil expirations are encoded as the 0 value timestamp, + // we set the minVal to 1 ns because nil expirations are encoded as the 0 value timestamp, // and we DO NOT want those to be deleted/unescrowed. // https://github.com/cosmos/cosmos-sdk/issues/11980 - min, blockTime := timestamppb.New(time.Unix(0, 1)), timestamppb.New(sdkCtx.BlockTime()) - fromKey, toKey := api.SellOrderExpirationIndexKey{}.WithExpiration(min), api.SellOrderExpirationIndexKey{}.WithExpiration(blockTime) + minVal, blockTime := timestamppb.New(time.Unix(0, 1)), timestamppb.New(sdkCtx.BlockTime()) + fromKey, toKey := api.SellOrderExpirationIndexKey{}.WithExpiration(minVal), api.SellOrderExpirationIndexKey{}.WithExpiration(blockTime) it, err := k.stateStore.SellOrderTable().ListRange(ctx, fromKey, toKey) if err != nil { diff --git a/x/ecocredit/marketplace/simulation/msg_add_allowed_denom.go b/x/ecocredit/marketplace/simulation/msg_add_allowed_denom.go index 81d7951b9f..e2d45355ce 100644 --- a/x/ecocredit/marketplace/simulation/msg_add_allowed_denom.go +++ b/x/ecocredit/marketplace/simulation/msg_add_allowed_denom.go @@ -26,7 +26,7 @@ var TypeMsgAddAllowedDenom = types.MsgAddAllowedDenom{}.Route() func SimulateMsgAddAllowedDenom(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient types.QueryServer, govk ecocredit.GovKeeper, authority sdk.AccAddress) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { proposer, _ := simtypes.RandomAcc(r, accs) diff --git a/x/ecocredit/marketplace/simulation/msg_buy_direct.go b/x/ecocredit/marketplace/simulation/msg_buy_direct.go index 8e67e518ed..72da498471 100644 --- a/x/ecocredit/marketplace/simulation/msg_buy_direct.go +++ b/x/ecocredit/marketplace/simulation/msg_buy_direct.go @@ -26,7 +26,7 @@ var TypeMsgBuyDirect = types.MsgBuyDirect{}.Route() func SimulateMsgBuyDirect(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, _ basetypes.QueryServer, mktQryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { buyer, _ := simtypes.RandomAcc(r, accs) buyerAddr := buyer.Address.String() @@ -42,13 +42,13 @@ func SimulateMsgBuyDirect(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgBuyDirect, "no sell orders"), nil, nil } - max := 1 + maxVal := 1 if len(sellOrders) > 1 { - max = simtypes.RandIntBetween(r, 1, len(sellOrders)) + maxVal = simtypes.RandIntBetween(r, 1, len(sellOrders)) } var buyOrders []*types.MsgBuyDirect_Order - for i := 0; i < max; i++ { + for i := 0; i < maxVal; i++ { if sellOrders[i].Seller == buyerAddr { continue } diff --git a/x/ecocredit/marketplace/simulation/msg_cancel_sell_order.go b/x/ecocredit/marketplace/simulation/msg_cancel_sell_order.go index adf36029a9..4fd722a7b1 100644 --- a/x/ecocredit/marketplace/simulation/msg_cancel_sell_order.go +++ b/x/ecocredit/marketplace/simulation/msg_cancel_sell_order.go @@ -25,7 +25,7 @@ var TypeMsgCancelSellOrder = types.MsgCancelSellOrder{}.Route() func SimulateMsgCancelSellOrder(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, _ basetypes.QueryServer, mktQryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { seller, _ := simtypes.RandomAcc(r, accs) sellerAddr := seller.Address.String() diff --git a/x/ecocredit/marketplace/simulation/msg_remove_allowed_denom.go b/x/ecocredit/marketplace/simulation/msg_remove_allowed_denom.go index a535107748..cdafd390f0 100644 --- a/x/ecocredit/marketplace/simulation/msg_remove_allowed_denom.go +++ b/x/ecocredit/marketplace/simulation/msg_remove_allowed_denom.go @@ -25,7 +25,7 @@ var TypeMsgRemoveAllowedDenom = types.MsgRemoveAllowedDenom{}.Route() func SimulateMsgRemoveAllowedDenom(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, mktClient types.QueryServer, govk ecocredit.GovKeeper, authority sdk.AccAddress) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { response, err := mktClient.AllowedDenoms(sdkCtx, &types.QueryAllowedDenomsRequest{}) diff --git a/x/ecocredit/marketplace/simulation/msg_sell.go b/x/ecocredit/marketplace/simulation/msg_sell.go index 942e9fde03..c574cdb558 100644 --- a/x/ecocredit/marketplace/simulation/msg_sell.go +++ b/x/ecocredit/marketplace/simulation/msg_sell.go @@ -27,7 +27,7 @@ var TypeMsgSell = types.MsgSell{}.Route() func SimulateMsgSell(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, qryClient basetypes.QueryServer) simtypes.Operation { return func( - r *rand.Rand, baseApp *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, baseApp *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { seller, _ := simtypes.RandomAcc(r, accs) sellerAddr := seller.Address.String() @@ -47,13 +47,13 @@ func SimulateMsgSell(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, if len(batches) == 0 { return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgSell, "no credit batches"), nil, nil } - max := 1 + maxVal := 1 if len(batches) > 1 { - max = simtypes.RandIntBetween(r, 1, len(batches)) + maxVal = simtypes.RandIntBetween(r, 1, len(batches)) } - sellOrders := make([]*types.MsgSell_Order, max) - for i := 0; i < max; i++ { + sellOrders := make([]*types.MsgSell_Order, maxVal) + for i := 0; i < maxVal; i++ { bal, err := qryClient.Balance(ctx, &basetypes.QueryBalanceRequest{Address: sellerAddr, BatchDenom: batches[i].Denom}) if err != nil { return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgSell, err.Error()), nil, err diff --git a/x/ecocredit/marketplace/simulation/msg_update_sell_order.go b/x/ecocredit/marketplace/simulation/msg_update_sell_order.go index def7062df6..77512190bc 100644 --- a/x/ecocredit/marketplace/simulation/msg_update_sell_order.go +++ b/x/ecocredit/marketplace/simulation/msg_update_sell_order.go @@ -27,7 +27,7 @@ var TypeMsgUpdateSellOrder = types.MsgUpdateSellOrders{}.Route() func SimulateMsgUpdateSellOrder(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper, _ basetypes.QueryServer, mktQryClient types.QueryServer) simtypes.Operation { return func( - r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, chainID string, + r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accs []simtypes.Account, _ string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { seller, _ := simtypes.RandomAcc(r, accs) sellerAddr := seller.Address.String() @@ -43,13 +43,13 @@ func SimulateMsgUpdateSellOrder(ak ecocredit.AccountKeeper, bk ecocredit.BankKee return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgUpdateSellOrder, "no sell orders present"), nil, nil } - max := 1 + maxVal := 1 if len(orders) > 1 { - max = simtypes.RandIntBetween(r, 1, len(orders)) + maxVal = simtypes.RandIntBetween(r, 1, len(orders)) } updatedOrders := make([]*types.MsgUpdateSellOrders_Update, len(orders)) - for i := 0; i < max; i++ { + for i := 0; i < maxVal; i++ { askPrice := sdk.NewInt64Coin(sdk.DefaultBondDenom, int64(simtypes.RandIntBetween(r, 1, 50))) exp := simtypes.RandTimestamp(r) if exp.Before(sdkCtx.BlockTime()) { diff --git a/x/ecocredit/marketplace/types/v1/msg_gov_send_from_fee_pool_test.go b/x/ecocredit/marketplace/types/v1/msg_gov_send_from_fee_pool_test.go index 8faff2dd3a..14e25165e7 100644 --- a/x/ecocredit/marketplace/types/v1/msg_gov_send_from_fee_pool_test.go +++ b/x/ecocredit/marketplace/types/v1/msg_gov_send_from_fee_pool_test.go @@ -3,9 +3,10 @@ package v1 import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) type govSendFromFeePool struct { diff --git a/x/ecocredit/migrations/v4/state_test.go b/x/ecocredit/migrations/v4/state_test.go index 5b33f480bd..2ed2d46f87 100644 --- a/x/ecocredit/migrations/v4/state_test.go +++ b/x/ecocredit/migrations/v4/state_test.go @@ -3,8 +3,8 @@ package v4_test import ( "testing" - "github.com/stretchr/testify/require" dbm "github.com/cometbft/cometbft-db" + "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" @@ -321,7 +321,11 @@ func TestMainnetMigrations(t *testing.T) { // ensure all other fields are unchanged for i := range batches { - b, err := baseStore.BatchTable().Get(sdkCtx, uint64(i+1)) + idx := i + 1 + if idx < 0 { + t.Fatalf("index out of range") + } + b, err := baseStore.BatchTable().Get(sdkCtx, uint64(idx)) require.NoError(t, err) require.Equal(t, b.Issuer, issuer.Bytes()) diff --git a/x/ecocredit/mocks/expected_keepers.go b/x/ecocredit/mocks/expected_keepers.go index a967b18e3e..006c455152 100644 --- a/x/ecocredit/mocks/expected_keepers.go +++ b/x/ecocredit/mocks/expected_keepers.go @@ -7,11 +7,12 @@ package mocks import ( reflect "reflect" + gomock "github.com/golang/mock/gomock" + types "github.com/cosmos/cosmos-sdk/types" types0 "github.com/cosmos/cosmos-sdk/x/auth/types" types1 "github.com/cosmos/cosmos-sdk/x/bank/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - gomock "github.com/golang/mock/gomock" ) // MockAccountKeeper is a mock of AccountKeeper interface. diff --git a/x/ecocredit/server/invariants_test.go b/x/ecocredit/server/invariants_test.go index 10b7fc5de3..5b69294758 100644 --- a/x/ecocredit/server/invariants_test.go +++ b/x/ecocredit/server/invariants_test.go @@ -4,9 +4,9 @@ import ( "context" "testing" + dbm "github.com/cometbft/cometbft-db" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - dbm "github.com/cometbft/cometbft-db" "gotest.tools/v3/assert" "github.com/cometbft/cometbft/libs/log" diff --git a/x/ecocredit/server/testsuite/genesis.go b/x/ecocredit/server/testsuite/genesis.go index 43e79c6802..b9975f4686 100644 --- a/x/ecocredit/server/testsuite/genesis.go +++ b/x/ecocredit/server/testsuite/genesis.go @@ -8,6 +8,7 @@ import ( "google.golang.org/protobuf/proto" sdkbase "cosmossdk.io/api/cosmos/base/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" diff --git a/x/ecocredit/server/testsuite/suite.go b/x/ecocredit/server/testsuite/suite.go index 8045dec9ac..29f3559a86 100644 --- a/x/ecocredit/server/testsuite/suite.go +++ b/x/ecocredit/server/testsuite/suite.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/suite" sdkbase "cosmossdk.io/api/cosmos/base/v1beta1" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/orm/model/ormdb" "github.com/cosmos/cosmos-sdk/orm/model/ormtable" @@ -24,7 +25,7 @@ import ( basketApi "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/basket/v1" marketapi "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/marketplace/v1" baseapi "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1" - "github.com/regen-network/regen-ledger/types/v2" + regentypes "github.com/regen-network/regen-ledger/types/v2" "github.com/regen-network/regen-ledger/types/v2/math" "github.com/regen-network/regen-ledger/types/v2/ormutil" @@ -342,9 +343,9 @@ func (s *IntegrationTestSuite) createClassAndIssueBatch(admin, recipient sdk.Acc }) require.NoError(err) classID := cRes.ClassId - start, err := types.ParseDate("start date", startStr) + start, err := regentypes.ParseDate("start date", startStr) require.NoError(err) - end, err := types.ParseDate("end date", endStr) + end, err := regentypes.ParseDate("end date", endStr) require.NoError(err) pRes, err := s.msgClient.CreateProject(s.ctx, &basetypes.MsgCreateProject{ Admin: admin.String(), @@ -926,7 +927,7 @@ func (s *IntegrationTestSuite) TestScenario() { coinPrice := sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000) expiration := time.Date(2030, 01, 01, 0, 0, 0, 0, time.UTC) - expectedSellOrderIds := []uint64{1, 2} + expectedSellOrderIDs := []uint64{1, 2} sellerAcc := acc3 order1Qty, order2Qty := "10.54321", "15.54321" @@ -954,7 +955,7 @@ func (s *IntegrationTestSuite) TestScenario() { }, }) s.Require().Nil(err) - s.Require().Equal(expectedSellOrderIds, createSellOrder.SellOrderIds) + s.Require().Equal(expectedSellOrderIDs, createSellOrder.SellOrderIds) orderID1 := createSellOrder.SellOrderIds[0] orderID2 := createSellOrder.SellOrderIds[1] diff --git a/x/ecocredit/simulation/genesis.go b/x/ecocredit/simulation/genesis.go index 295f1f5c2f..df0fdcd778 100644 --- a/x/ecocredit/simulation/genesis.go +++ b/x/ecocredit/simulation/genesis.go @@ -10,6 +10,7 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" sdkbase "cosmossdk.io/api/cosmos/base/v1beta1" + "github.com/cosmos/cosmos-sdk/orm/model/ormdb" "github.com/cosmos/cosmos-sdk/orm/model/ormtable" "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" @@ -34,7 +35,7 @@ func genCreditClassFee(r *rand.Rand) sdk.Coin { // genAllowedClassCreators generate random set of creators func genAllowedClassCreators(r *rand.Rand, accs []simtypes.Account) []sdk.AccAddress { - max := 50 + maxVal := 50 switch len(accs) { case 0: @@ -42,11 +43,11 @@ func genAllowedClassCreators(r *rand.Rand, accs []simtypes.Account) []sdk.AccAdd case 1: return []sdk.AccAddress{accs[0].Address} default: - if len(accs) < max { - max = len(accs) + if len(accs) < maxVal { + maxVal = len(accs) } } - n := simtypes.RandIntBetween(r, 1, max) + n := simtypes.RandIntBetween(r, 1, maxVal) creators := make([]sdk.AccAddress, n) for i := 0; i < n; i++ { diff --git a/x/ecocredit/simulation/genesis_test.go b/x/ecocredit/simulation/genesis_test.go index 4ac8998956..dd2d48fbf4 100644 --- a/x/ecocredit/simulation/genesis_test.go +++ b/x/ecocredit/simulation/genesis_test.go @@ -7,8 +7,8 @@ import ( "cosmossdk.io/math" - "github.com/stretchr/testify/require" dbm "github.com/cometbft/cometbft-db" + "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" diff --git a/x/intertx/client/tx.go b/x/intertx/client/tx.go index e9419980ec..b980420652 100644 --- a/x/intertx/client/tx.go +++ b/x/intertx/client/tx.go @@ -54,7 +54,7 @@ func getRegisterAccountCmd() *cobra.Command { regen tx intertx register --connection-id connection-0 regen tx intertx register --connection-id connection-0 --version '{"version":"ics27-1","tx_type":"sdk_multi_msg","encoding":"proto3","host_connection_id":"connection-0","controller_connection_id":"connection-0","address":"regen14zs2x38lmkw4eqvl3lpml5l8crzaxn6mpvh79z"}' `, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err diff --git a/x/intertx/keeper/expected_keepers.go b/x/intertx/keeper/expected_keepers.go index c8e83b2349..5f8460c01a 100644 --- a/x/intertx/keeper/expected_keepers.go +++ b/x/intertx/keeper/expected_keepers.go @@ -9,7 +9,7 @@ import ( //go:generate mockgen -source=expected_keepers.go -package mocks -destination mocks/expected_keepers.go type CapabilityKeeper interface { - ClaimCapability(ctx sdk.Context, cap *types.Capability, name string) error + ClaimCapability(ctx sdk.Context, cpb *types.Capability, name string) error GetCapability(ctx sdk.Context, name string) (*types.Capability, bool) } diff --git a/x/intertx/keeper/keeper.go b/x/intertx/keeper/keeper.go index c468018e9d..cd5bf0cbff 100644 --- a/x/intertx/keeper/keeper.go +++ b/x/intertx/keeper/keeper.go @@ -3,10 +3,11 @@ package keeper import ( "fmt" + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - "github.com/cometbft/cometbft/libs/log" "github.com/regen-network/regen-ledger/x/intertx" ) @@ -32,6 +33,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // ClaimCapability claims the channel capability passed via the OnOpenChanInit callback -func (k *Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { - return k.scopedKeeper.ClaimCapability(ctx, cap, name) +func (k *Keeper) ClaimCapability(ctx sdk.Context, cpb *capabilitytypes.Capability, name string) error { + return k.scopedKeeper.ClaimCapability(ctx, cpb, name) } diff --git a/x/intertx/keeper/keeper_test.go b/x/intertx/keeper/keeper_test.go index 307804aa4e..e2c2de7dae 100644 --- a/x/intertx/keeper/keeper_test.go +++ b/x/intertx/keeper/keeper_test.go @@ -3,10 +3,13 @@ package keeper import ( "context" + dbm "github.com/cometbft/cometbft-db" "github.com/golang/mock/gomock" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" - dbm "github.com/cometbft/cometbft-db" + + "github.com/cometbft/cometbft/libs/log" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -16,8 +19,6 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cometbft/cometbft/libs/log" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/regen-network/regen-ledger/x/intertx/keeper/mocks" ) diff --git a/x/intertx/keeper/msg_submit_tx.go b/x/intertx/keeper/msg_submit_tx.go index ae31a83296..3b53f2c04e 100644 --- a/x/intertx/keeper/msg_submit_tx.go +++ b/x/intertx/keeper/msg_submit_tx.go @@ -4,9 +4,10 @@ import ( "context" "time" + "github.com/cosmos/gogoproto/proto" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/gogoproto/proto" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -51,6 +52,9 @@ func (k Keeper) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types. // timeoutTimestamp set to max value with the unsigned bit shifted to satisfy hermes timestamp conversion. // it is the responsibility of the auth module developer to ensure an appropriate timeout timestamp. timeoutTimestamp := ctx.BlockTime().Add(time.Minute).UnixNano() + if timeoutTimestamp < 0 { + return nil, sdkerrors.ErrInvalidRequest.Wrap("timeout timestamp is negative") + } _, err = k.icaControllerKeeper.SendTx(ctx, chanCap, msg.ConnectionId, portID, packetData, uint64(timeoutTimestamp)) if err != nil { return nil, err diff --git a/x/intertx/keeper/msg_submit_tx_test.go b/x/intertx/keeper/msg_submit_tx_test.go index 39b6a6b2d3..560114b19d 100644 --- a/x/intertx/keeper/msg_submit_tx_test.go +++ b/x/intertx/keeper/msg_submit_tx_test.go @@ -7,11 +7,12 @@ import ( "github.com/golang/mock/gomock" "gotest.tools/v3/assert" + "github.com/cosmos/gogoproto/proto" + "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - "github.com/cosmos/gogoproto/proto" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -53,7 +54,14 @@ func TestSubmitTx(t *testing.T) { blockTime := time.Unix(35235, 30) s.sdkCtx.WithBlockTime(blockTime) timeOut := s.sdkCtx.BlockTime().Add(time.Minute).UnixNano() - capability := &capabilitytypes.Capability{Index: 32} + // check safe cast to uint64 for timeOut + if timeOut < 0 { + t.Fatalf("timeout timestamp is negative") + } + + capability := &capabilitytypes.Capability{ + Index: 32, + } gomock.InOrder( s.ica.EXPECT(). GetActiveChannelID(s.sdkCtx, msg.ConnectionId, portID). diff --git a/x/intertx/module/module.go b/x/intertx/module/module.go index ce61e5f9b1..096c8a7d14 100644 --- a/x/intertx/module/module.go +++ b/x/intertx/module/module.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" diff --git a/x/intertx/types/v1/msg_register_account.go b/x/intertx/types/v1/msg_register_account.go index 3c34fcbbcc..e0db6e1467 100644 --- a/x/intertx/types/v1/msg_register_account.go +++ b/x/intertx/types/v1/msg_register_account.go @@ -34,9 +34,9 @@ func (m MsgRegisterAccount) GetSigners() []sdk.AccAddress { } // LegacyMsg.Type implementations -func (msg MsgRegisterAccount) Route() string { return "" } -func (msg MsgRegisterAccount) Type() string { return sdk.MsgTypeURL(&msg) } -func (msg *MsgRegisterAccount) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) +func (m MsgRegisterAccount) Route() string { return "" } +func (m MsgRegisterAccount) Type() string { return sdk.MsgTypeURL(&m) } +func (m *MsgRegisterAccount) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(m) return sdk.MustSortJSON(bz) } diff --git a/x/intertx/types/v1/msg_submit_tx.go b/x/intertx/types/v1/msg_submit_tx.go index 1cf644eb4d..38aed4950e 100644 --- a/x/intertx/types/v1/msg_submit_tx.go +++ b/x/intertx/types/v1/msg_submit_tx.go @@ -41,10 +41,10 @@ func (m MsgSubmitTx) GetSigners() []sdk.AccAddress { } // LegacyMsg.Type implementations -func (msg MsgSubmitTx) Route() string { return "" } -func (msg MsgSubmitTx) Type() string { return sdk.MsgTypeURL(&msg) } -func (msg *MsgSubmitTx) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) +func (m MsgSubmitTx) Route() string { return "" } +func (m MsgSubmitTx) Type() string { return sdk.MsgTypeURL(&m) } +func (m *MsgSubmitTx) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(m) return sdk.MustSortJSON(bz) }