diff --git a/.gitignore b/.gitignore index ad72e980c17..38d6c10bc20 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,6 @@ dependency-graph.png # Go go.work go.work.sum + +# Python +venv diff --git a/Makefile b/Makefile index 756c3fc693d..4e883c8d8bb 100644 --- a/Makefile +++ b/Makefile @@ -176,7 +176,7 @@ TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test- # Test runs-specific rules. To add a new test target, just add # a new rule, customise ARGS or TEST_PACKAGES ad libitum, and # append the new rule to the TEST_TARGETS list. -test-unit: ARGS=-tags='cgo ledger test_ledger_mock' +test-unit: ARGS=-tags='cgo ledger test_ledger_mock test_e2e' test-unit-amino: ARGS=-tags='ledger test_ledger_mock test_amino' test-ledger: ARGS=-tags='cgo ledger' test-ledger-mock: ARGS=-tags='ledger test_ledger_mock' @@ -192,12 +192,9 @@ check-test-unit-amino: ARGS=-tags='ledger test_ledger_mock test_amino' $(CHECK_TEST_TARGETS): EXTRA_ARGS=-run=none $(CHECK_TEST_TARGETS): run-tests -run-tests: -ifneq (,$(shell which tparse 2>/dev/null)) - go test -mod=readonly -json $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES) | tparse -else - go test -mod=readonly $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES) -endif +ARGS += -tags "$(test_tags)" +run-tests: + @ARGS="$(ARGS)" TEST_PACKAGES=$(TEST_PACKAGES) EXTRA_ARGS="$(EXTRA_ARGS)" python3 ./scripts/go-test-all.py .PHONY: run-tests test test-all $(TEST_TARGETS) @@ -283,10 +280,12 @@ setup-pre-commit: @ln -sf ../../scripts/hooks/pre-commit.sh .git/hooks/pre-commit lint: - golangci-lint run --out-format=tab + @echo "--> Running linter" + @./scripts/go-lint-all.sh --timeout=15m lint-fix: - golangci-lint run --fix --out-format=tab --issues-exit-code=0 + @echo "--> Running linter" + @./scripts/go-lint-all.sh --fix format: find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs gofumpt -w diff --git a/e2e/tests/core/02-client/client_test.go b/e2e/tests/core/02-client/client_test.go index 62ab6baeb25..38ef53eebbf 100644 --- a/e2e/tests/core/02-client/client_test.go +++ b/e2e/tests/core/02-client/client_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package client import ( diff --git a/e2e/tests/core/03-connection/connection_test.go b/e2e/tests/core/03-connection/connection_test.go index fc93db35b97..39a6110008e 100644 --- a/e2e/tests/core/03-connection/connection_test.go +++ b/e2e/tests/core/03-connection/connection_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package connection import ( diff --git a/e2e/tests/interchain_accounts/base_test.go b/e2e/tests/interchain_accounts/base_test.go index 89e885db025..d2e693da9a5 100644 --- a/e2e/tests/interchain_accounts/base_test.go +++ b/e2e/tests/interchain_accounts/base_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package interchainaccounts import ( diff --git a/e2e/tests/interchain_accounts/gov_test.go b/e2e/tests/interchain_accounts/gov_test.go index 19fded717fa..4c84901c292 100644 --- a/e2e/tests/interchain_accounts/gov_test.go +++ b/e2e/tests/interchain_accounts/gov_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package interchainaccounts import ( diff --git a/e2e/tests/interchain_accounts/groups_test.go b/e2e/tests/interchain_accounts/groups_test.go index b7710f69f7f..acf82702d5f 100644 --- a/e2e/tests/interchain_accounts/groups_test.go +++ b/e2e/tests/interchain_accounts/groups_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package interchainaccounts import ( diff --git a/e2e/tests/interchain_accounts/incentivized_test.go b/e2e/tests/interchain_accounts/incentivized_test.go index e7025dfd088..4181029d489 100644 --- a/e2e/tests/interchain_accounts/incentivized_test.go +++ b/e2e/tests/interchain_accounts/incentivized_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package interchainaccounts import ( diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index dbf80bd8f7d..7ea4ccb55d2 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package interchainaccounts import ( diff --git a/e2e/tests/interchain_accounts/params_test.go b/e2e/tests/interchain_accounts/params_test.go index 4853395920e..2ecfe91c3f9 100644 --- a/e2e/tests/interchain_accounts/params_test.go +++ b/e2e/tests/interchain_accounts/params_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package interchainaccounts import ( diff --git a/e2e/tests/transfer/authz_test.go b/e2e/tests/transfer/authz_test.go index d9533035329..f9af5f15468 100644 --- a/e2e/tests/transfer/authz_test.go +++ b/e2e/tests/transfer/authz_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package transfer import ( diff --git a/e2e/tests/transfer/base_test.go b/e2e/tests/transfer/base_test.go index cd18973b1e9..1330a4bba80 100644 --- a/e2e/tests/transfer/base_test.go +++ b/e2e/tests/transfer/base_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package transfer import ( diff --git a/e2e/tests/transfer/incentivized_test.go b/e2e/tests/transfer/incentivized_test.go index 3ff5779df88..92a8109924a 100644 --- a/e2e/tests/transfer/incentivized_test.go +++ b/e2e/tests/transfer/incentivized_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package transfer import ( diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 8e50c335bb0..1182429abc4 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package transfer import ( diff --git a/e2e/tests/upgrades/genesis_test.go b/e2e/tests/upgrades/genesis_test.go index 9d1d367d4c0..344073aa2a0 100644 --- a/e2e/tests/upgrades/genesis_test.go +++ b/e2e/tests/upgrades/genesis_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package upgrades import ( @@ -194,7 +196,7 @@ func (s *GenesisTestSuite) HaltChainAndExportGenesis(ctx context.Context, chain err = chain.StopAllNodes(ctx) s.Require().NoError(err, "error stopping node(s)") - state, err := chain.ExportState(ctx, int64(haltHeight)) + state, err := chain.ExportState(ctx, haltHeight) s.Require().NoError(err) appTomlOverrides := make(test.Toml) diff --git a/e2e/tests/upgrades/upgrade_test.go b/e2e/tests/upgrades/upgrade_test.go index 3dee14ce45f..7d34322f250 100644 --- a/e2e/tests/upgrades/upgrade_test.go +++ b/e2e/tests/upgrades/upgrade_test.go @@ -1,3 +1,5 @@ +//go:build !test_e2e + package upgrades import ( @@ -6,9 +8,7 @@ import ( "testing" "time" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/gogoproto/proto" - interchaintest "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v8/ibc" @@ -19,6 +19,7 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" e2erelayer "github.com/cosmos/ibc-go/e2e/relayer" "github.com/cosmos/ibc-go/e2e/testsuite" diff --git a/e2e/testsuite/codec.go b/e2e/testsuite/codec.go index 649422c6620..8eb1d050b30 100644 --- a/e2e/testsuite/codec.go +++ b/e2e/testsuite/codec.go @@ -5,13 +5,13 @@ import ( "encoding/hex" "fmt" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/gogoproto/jsonpb" "github.com/cosmos/gogoproto/proto" upgradetypes "cosmossdk.io/x/upgrade/types" "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module/testutil" diff --git a/e2e/testsuite/grpc_query.go b/e2e/testsuite/grpc_query.go index 38f2ab0e2b8..ae0257da567 100644 --- a/e2e/testsuite/grpc_query.go +++ b/e2e/testsuite/grpc_query.go @@ -85,15 +85,15 @@ func (s *E2ETestSuite) InitGRPCClients(chain *cosmos.CosmosChain) { FeeQueryClient: feetypes.NewQueryClient(grpcConn), ICAControllerQueryClient: controllertypes.NewQueryClient(grpcConn), ICAHostQueryClient: hosttypes.NewQueryClient(grpcConn), - BankQueryClient: banktypes.NewQueryClient(grpcConn), - GovQueryClient: govtypesv1beta1.NewQueryClient(grpcConn), - GovQueryClientV1: govtypesv1.NewQueryClient(grpcConn), - GroupsQueryClient: grouptypes.NewQueryClient(grpcConn), - ParamsQueryClient: paramsproposaltypes.NewQueryClient(grpcConn), - AuthQueryClient: authtypes.NewQueryClient(grpcConn), - AuthZQueryClient: authz.NewQueryClient(grpcConn), - ConsensusServiceClient: cmtservice.NewServiceClient(grpcConn), - UpgradeQueryClient: upgradetypes.NewQueryClient(grpcConn), + BankQueryClient: banktypes.NewQueryClient(grpcConn), + GovQueryClient: govtypesv1beta1.NewQueryClient(grpcConn), + GovQueryClientV1: govtypesv1.NewQueryClient(grpcConn), + GroupsQueryClient: grouptypes.NewQueryClient(grpcConn), + ParamsQueryClient: paramsproposaltypes.NewQueryClient(grpcConn), + AuthQueryClient: authtypes.NewQueryClient(grpcConn), + AuthZQueryClient: authz.NewQueryClient(grpcConn), + ConsensusServiceClient: cmtservice.NewServiceClient(grpcConn), + UpgradeQueryClient: upgradetypes.NewQueryClient(grpcConn), } } diff --git a/e2e/testsuite/testconfig.go b/e2e/testsuite/testconfig.go index 6c213b6ebad..6b5f4527299 100644 --- a/e2e/testsuite/testconfig.go +++ b/e2e/testsuite/testconfig.go @@ -8,7 +8,6 @@ import ( "path" "strings" - tmjson "github.com/cometbft/cometbft/libs/json" "github.com/strangelove-ventures/interchaintest/v8/ibc" interchaintestutil "github.com/strangelove-ventures/interchaintest/v8/testutil" "gopkg.in/yaml.v2" @@ -21,6 +20,8 @@ import ( govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + tmjson "github.com/cometbft/cometbft/libs/json" + "github.com/cosmos/ibc-go/e2e/relayer" "github.com/cosmos/ibc-go/e2e/semverutil" "github.com/cosmos/ibc-go/e2e/testvalues" diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 47fc9d8e441..9cde49618a9 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -273,7 +273,7 @@ func (s *E2ETestSuite) RecoverRelayerWallets(ctx context.Context, ibcrelayer ibc // StartRelayer starts the given ibcrelayer. func (s *E2ETestSuite) StartRelayer(ibcrelayer ibc.Relayer) { if s.startRelayerFn == nil { - panic(errors.New("cannot start relayer before it is created!")) + panic(errors.New("cannot start relayer before it is created")) } s.startRelayerFn(ibcrelayer) diff --git a/modules/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index e5d853f0285..fa345c5164b 100644 --- a/modules/capability/keeper/keeper.go +++ b/modules/capability/keeper/keeper.go @@ -206,11 +206,11 @@ func (k Keeper) GetOwners(ctx sdk.Context, index uint64) (types.CapabilityOwners func (k Keeper) InitializeCapability(ctx sdk.Context, index uint64, owners types.CapabilityOwners) { memStore := ctx.KVStore(k.memKey) - cap := types.NewCapability(index) + capability := types.NewCapability(index) for _, owner := range owners.Owners { // Set the forward mapping between the module and capability tuple and the // capability name in the memKVStore - memStore.Set(types.FwdCapabilityKey(owner.Module, cap), []byte(owner.Name)) + memStore.Set(types.FwdCapabilityKey(owner.Module, capability), []byte(owner.Name)) // Set the reverse mapping between the module and capability name and the // index in the in-memory store. Since marshalling and unmarshalling into a store @@ -219,7 +219,7 @@ func (k Keeper) InitializeCapability(ctx sdk.Context, index uint64, owners types memStore.Set(types.RevCapabilityKey(owner.Module, owner.Name), sdk.Uint64ToBigEndian(index)) // Set the mapping from index from index to in-memory capability in the go map - k.capMap[index] = cap + k.capMap[index] = capability } } @@ -244,10 +244,10 @@ func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capab // create new capability with the current global index index := types.IndexFromKey(store.Get(types.KeyIndex)) - cap := types.NewCapability(index) + capability := types.NewCapability(index) // update capability owner set - if err := sk.addOwner(ctx, cap, name); err != nil { + if err := sk.addOwner(ctx, capability, name); err != nil { return nil, err } @@ -258,7 +258,7 @@ func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capab // Set the forward mapping between the module and capability tuple and the // capability name in the memKVStore - memStore.Set(types.FwdCapabilityKey(sk.module, cap), []byte(name)) + memStore.Set(types.FwdCapabilityKey(sk.module, capability), []byte(name)) // Set the reverse mapping between the module and capability name and the // index in the in-memory store. Since marshalling and unmarshalling into a store @@ -267,11 +267,11 @@ func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capab memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(index)) // Set the mapping from index from index to in-memory capability in the go map - sk.capMap[index] = cap + sk.capMap[index] = capability logger(ctx).Info("created new capability", "module", sk.module, "name", name) - return cap, nil + return capability, nil } // AuthenticateCapability attempts to authenticate a given capability and name @@ -389,12 +389,12 @@ func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capab return nil, false } - cap := sk.capMap[index] - if cap == nil { + capability := sk.capMap[index] + if capability == nil { panic(errors.New("capability found in memstore is missing from map")) } - return cap, true + return capability, true } // GetCapabilityName allows a module to retrieve the name under which it stored a given @@ -414,13 +414,13 @@ func (sk ScopedKeeper) GetOwners(ctx sdk.Context, name string) (*types.Capabilit if strings.TrimSpace(name) == "" { return nil, false } - cap, ok := sk.GetCapability(ctx, name) + capability, ok := sk.GetCapability(ctx, name) if !ok { return nil, false } prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability) - indexKey := types.IndexToKey(cap.GetIndex()) + indexKey := types.IndexToKey(capability.GetIndex()) var capOwners types.CapabilityOwners @@ -442,7 +442,7 @@ func (sk ScopedKeeper) LookupModules(ctx sdk.Context, name string) ([]string, *t if strings.TrimSpace(name) == "" { return nil, nil, errorsmod.Wrap(types.ErrInvalidCapabilityName, "cannot lookup modules with empty capability name") } - cap, ok := sk.GetCapability(ctx, name) + capability, ok := sk.GetCapability(ctx, name) if !ok { return nil, nil, errorsmod.Wrap(types.ErrCapabilityNotFound, name) } @@ -457,7 +457,7 @@ func (sk ScopedKeeper) LookupModules(ctx sdk.Context, name string) ([]string, *t mods[i] = co.Module } - return mods, cap, nil + return mods, capability, nil } func (sk ScopedKeeper) addOwner(ctx sdk.Context, cap *types.Capability, name string) error { diff --git a/modules/capability/keeper/keeper_test.go b/modules/capability/keeper/keeper_test.go index 357c2e72314..9fada176f38 100644 --- a/modules/capability/keeper/keeper_test.go +++ b/modules/capability/keeper/keeper_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" - storetypes "cosmossdk.io/store/types" testifysuite "github.com/stretchr/testify/suite" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -17,8 +18,8 @@ import ( ) var ( - stakingModuleName string = "staking" - bankModuleName string = "bank" + stakingModuleName = "staking" + bankModuleName = "bank" ) type KeeperTestSuite struct { @@ -47,12 +48,12 @@ func (suite *KeeperTestSuite) TestSeal() { prevIndex := suite.keeper.GetLatestIndex(suite.ctx) for i := range caps { - cap, err := sk.NewCapability(suite.ctx, fmt.Sprintf("transfer-%d", i)) + transferCap, err := sk.NewCapability(suite.ctx, fmt.Sprintf("transfer-%d", i)) suite.Require().NoError(err) - suite.Require().NotNil(cap) - suite.Require().Equal(uint64(i)+prevIndex, cap.GetIndex()) + suite.Require().NotNil(transferCap) + suite.Require().Equal(uint64(i)+prevIndex, transferCap.GetIndex()) - caps[i] = cap + caps[i] = transferCap } suite.Require().NotPanics(func() { @@ -82,14 +83,14 @@ func (suite *KeeperTestSuite) TestNewCapability() { suite.Require().False(ok) suite.Require().Nil(got) - cap, err := sk.NewCapability(suite.ctx, "transfer") + transferCap, err := sk.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) - suite.Require().NotNil(cap) + suite.Require().NotNil(transferCap) got, ok = sk.GetCapability(suite.ctx, "transfer") suite.Require().True(ok) - suite.Require().Equal(cap, got) - suite.Require().True(cap == got, "expected memory addresses to be equal") + suite.Require().Equal(transferCap, got) + suite.Require().True(transferCap == got, "expected memory addresses to be equal") got, ok = sk.GetCapability(suite.ctx, "invalid") suite.Require().False(ok) @@ -97,8 +98,8 @@ func (suite *KeeperTestSuite) TestNewCapability() { got, ok = sk.GetCapability(suite.ctx, "transfer") suite.Require().True(ok) - suite.Require().Equal(cap, got) - suite.Require().True(cap == got, "expected memory addresses to be equal") + suite.Require().Equal(transferCap, got) + suite.Require().True(transferCap == got, "expected memory addresses to be equal") cap2, err := sk.NewCapability(suite.ctx, "transfer") suite.Require().Error(err) @@ -106,12 +107,12 @@ func (suite *KeeperTestSuite) TestNewCapability() { got, ok = sk.GetCapability(suite.ctx, "transfer") suite.Require().True(ok) - suite.Require().Equal(cap, got) - suite.Require().True(cap == got, "expected memory addresses to be equal") + suite.Require().Equal(transferCap, got) + suite.Require().True(transferCap == got, "expected memory addresses to be equal") - cap, err = sk.NewCapability(suite.ctx, " ") + transferCap, err = sk.NewCapability(suite.ctx, " ") suite.Require().Error(err) - suite.Require().Nil(cap) + suite.Require().Nil(transferCap) } func (suite *KeeperTestSuite) TestAuthenticateCapability() { @@ -159,22 +160,22 @@ func (suite *KeeperTestSuite) TestClaimCapability() { sk2 := suite.keeper.ScopeToModule(stakingModuleName) sk3 := suite.keeper.ScopeToModule("foo") - cap, err := sk1.NewCapability(suite.ctx, "transfer") + transferCap, err := sk1.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) - suite.Require().NotNil(cap) + suite.Require().NotNil(transferCap) - suite.Require().Error(sk1.ClaimCapability(suite.ctx, cap, "transfer")) - suite.Require().NoError(sk2.ClaimCapability(suite.ctx, cap, "transfer")) + suite.Require().Error(sk1.ClaimCapability(suite.ctx, transferCap, "transfer")) + suite.Require().NoError(sk2.ClaimCapability(suite.ctx, transferCap, "transfer")) got, ok := sk1.GetCapability(suite.ctx, "transfer") suite.Require().True(ok) - suite.Require().Equal(cap, got) + suite.Require().Equal(transferCap, got) got, ok = sk2.GetCapability(suite.ctx, "transfer") suite.Require().True(ok) - suite.Require().Equal(cap, got) + suite.Require().Equal(transferCap, got) - suite.Require().Error(sk3.ClaimCapability(suite.ctx, cap, " ")) + suite.Require().Error(sk3.ClaimCapability(suite.ctx, transferCap, " ")) suite.Require().Error(sk3.ClaimCapability(suite.ctx, nil, "transfer")) } @@ -185,12 +186,12 @@ func (suite *KeeperTestSuite) TestGetOwners() { sks := []keeper.ScopedKeeper{sk1, sk2, sk3} - cap, err := sk1.NewCapability(suite.ctx, "transfer") + transferCap, err := sk1.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) - suite.Require().NotNil(cap) + suite.Require().NotNil(transferCap) - suite.Require().NoError(sk2.ClaimCapability(suite.ctx, cap, "transfer")) - suite.Require().NoError(sk3.ClaimCapability(suite.ctx, cap, "transfer")) + suite.Require().NoError(sk2.ClaimCapability(suite.ctx, transferCap, "transfer")) + suite.Require().NoError(sk3.ClaimCapability(suite.ctx, transferCap, "transfer")) expectedOrder := []string{bankModuleName, "foo", stakingModuleName} // Ensure all scoped keepers can get owners @@ -204,7 +205,7 @@ func (suite *KeeperTestSuite) TestGetOwners() { suite.Require().NoError(err, "could not retrieve modules") suite.Require().NotNil(gotCap, "capability is nil") suite.Require().NotNil(mods, "modules is nil") - suite.Require().Equal(cap, gotCap, "caps not equal") + suite.Require().Equal(transferCap, gotCap, "caps not equal") suite.Require().Equal(len(expectedOrder), len(owners.Owners), "length of owners is unexpected") for i, o := range owners.Owners { @@ -215,7 +216,7 @@ func (suite *KeeperTestSuite) TestGetOwners() { } // foo module releases capability - err = sk3.ReleaseCapability(suite.ctx, cap) + err = sk3.ReleaseCapability(suite.ctx, transferCap) suite.Require().Nil(err, "could not release capability") // new expected order and scoped capabilities @@ -225,13 +226,13 @@ func (suite *KeeperTestSuite) TestGetOwners() { // Ensure all scoped keepers can get owners for _, sk := range sks { owners, ok := sk.GetOwners(suite.ctx, "transfer") - mods, cap, err := sk.LookupModules(suite.ctx, "transfer") + mods, transferCap, err := sk.LookupModules(suite.ctx, "transfer") suite.Require().True(ok, "could not retrieve owners") suite.Require().NotNil(owners, "owners is nil") suite.Require().NoError(err, "could not retrieve modules") - suite.Require().NotNil(cap, "capability is nil") + suite.Require().NotNil(transferCap, "capability is nil") suite.Require().NotNil(mods, "modules is nil") suite.Require().Equal(len(expectedOrder), len(owners.Owners), "length of owners is unexpected") @@ -284,14 +285,14 @@ func (suite *KeeperTestSuite) TestRevertCapability() { cacheCtx := suite.ctx.WithMultiStore(msCache) capName := "revert" - // Create capability on cached context - cap, err := sk.NewCapability(cacheCtx, capName) + // Create cachedCap on cached context + cachedCap, err := sk.NewCapability(cacheCtx, capName) suite.Require().NoError(err, "could not create capability") // Check that capability written in cached context gotCache, ok := sk.GetCapability(cacheCtx, capName) suite.Require().True(ok, "could not retrieve capability from cached context") - suite.Require().Equal(cap, gotCache, "did not get correct capability from cached context") + suite.Require().Equal(cachedCap, gotCache, "did not get correct capability from cached context") // Check that capability is NOT written to original context got, ok := sk.GetCapability(suite.ctx, capName) @@ -303,7 +304,7 @@ func (suite *KeeperTestSuite) TestRevertCapability() { got, ok = sk.GetCapability(suite.ctx, capName) suite.Require().True(ok, "could not retrieve capability from context") - suite.Require().Equal(cap, got, "did not get correct capability from context") + suite.Require().Equal(cachedCap, got, "did not get correct capability from context") } func TestKeeperTestSuite(t *testing.T) { diff --git a/modules/capability/types/keys_test.go b/modules/capability/types/keys_test.go index d0874ea27b0..c79cf2723ec 100644 --- a/modules/capability/types/keys_test.go +++ b/modules/capability/types/keys_test.go @@ -15,9 +15,9 @@ func TestRevCapabilityKey(t *testing.T) { } func TestFwdCapabilityKey(t *testing.T) { - cap := types.NewCapability(23) - expected := []byte(fmt.Sprintf("bank/fwd/%#016p", cap)) - require.Equal(t, expected, types.FwdCapabilityKey("bank", cap)) + capability := types.NewCapability(23) + expected := []byte(fmt.Sprintf("bank/fwd/%#016p", capability)) + require.Equal(t, expected, types.FwdCapabilityKey("bank", capability)) } func TestIndexToKey(t *testing.T) { diff --git a/modules/capability/types/types_test.go b/modules/capability/types/types_test.go index b81d79877da..0e623aaefa7 100644 --- a/modules/capability/types/types_test.go +++ b/modules/capability/types/types_test.go @@ -12,9 +12,9 @@ import ( func TestCapabilityKey(t *testing.T) { idx := uint64(3162) - cap := types.NewCapability(idx) - require.Equal(t, idx, cap.GetIndex()) - require.Equal(t, fmt.Sprintf("Capability{%p, %d}", cap, idx), cap.String()) + capability := types.NewCapability(idx) + require.Equal(t, idx, capability.GetIndex()) + require.Equal(t, fmt.Sprintf("Capability{%p, %d}", capability, idx), capability.String()) } func TestOwner(t *testing.T) { diff --git a/scripts/go-lint-all.sh b/scripts/go-lint-all.sh new file mode 100755 index 00000000000..7a7883b36aa --- /dev/null +++ b/scripts/go-lint-all.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )" +export REPO_ROOT + +lint_module() { + local root="$1" + shift + cd "$(dirname "$root")" && + echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" && + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" +} +export -f lint_module + +find "${REPO_ROOT}" -type f -name go.mod -print0 | + xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@" \ No newline at end of file diff --git a/scripts/go-test-all.py b/scripts/go-test-all.py new file mode 100755 index 00000000000..2ce44e7f455 --- /dev/null +++ b/scripts/go-test-all.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +""" +The purpose of this script is to run unit tests for all go modules in the current +directory. It works by recursively searching for all go.mod files in the directory and +subdirectories and then running `go test` on each of them. + +It is not intended to be run directly, but rather to be called by the Makefile. +""" +import os +import subprocess + +def require_env_var(name): + """ Require an environment variable to be set. """ + value = os.environ.get(name, None) + if value is None: + print(f"Error: {name} environment variable is not set") + exit(1) + return value + +def find_go_modules(directory): + """ Find all go.mod files in the current directory and subdirectories. """ + go_mod_files = [] + for root, _, files in os.walk(directory): + if 'go.mod' in files: + go_mod_files.append(root) + return go_mod_files + +def run_tests_for_module(module, *runargs): + """ Run the unit tests for the given module. """ + os.chdir(module) + + print(f"Running unit tests for {module}") + + # add runargs to test_command + test_command = f'go test -mod=readonly {" ".join(runargs)} ./...' + result = subprocess.run(test_command, shell=True) + return result.returncode + + +def run_tests(directory, *runargs): + """ Run the unit tests for all modules in dir. """ + print("Starting unit tests") + + # Find all go.mod files and get their directory names + go_modules = find_go_modules(directory) + + exit_code = 0 + for gomod in sorted(go_modules): + res = run_tests_for_module(gomod, *runargs) + if res != 0: + exit_code = res + exit(exit_code) + +if __name__ == '__main__': + # Get the environment variables given to us by the Makefile + ARGS = require_env_var('ARGS') + EXTRA_ARGS = require_env_var('EXTRA_ARGS') + TEST_PACKAGES = require_env_var('TEST_PACKAGES') + + run_tests(os.getcwd(), ARGS, EXTRA_ARGS, TEST_PACKAGES)