chore: gofumpt (#11839)

* fumpt using main not master...

* be more descriptive

* fumpt

* fix nits

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Jacob Gadikian
2022-05-19 10:55:27 +02:00
committed by GitHub
co-authored by Julien Robert
parent bc2d553f77
commit 55054282d2
412 changed files with 1020 additions and 1059 deletions
+1 -3
View File
@@ -30,9 +30,7 @@ func NewGrant(blockTime time.Time, a Authorization, expiration *time.Time) (Gran
}, nil
}
var (
_ cdctypes.UnpackInterfacesMessage = &Grant{}
)
var _ cdctypes.UnpackInterfacesMessage = &Grant{}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (g Grant) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error {
+1 -2
View File
@@ -19,7 +19,7 @@ func expecError(r *require.Assertions, expected string, received error) {
func TestNewGrant(t *testing.T) {
a := NewGenericAuthorization("some-type")
var tcs = []struct {
tcs := []struct {
title string
a Authorization
blockTime time.Time
@@ -40,7 +40,6 @@ func TestNewGrant(t *testing.T) {
expecError(require.New(t), tc.err, err)
})
}
}
func unixTime(s, ns int64) *time.Time {
+3 -2
View File
@@ -65,7 +65,7 @@ $ %s query %s grants cosmos1skjw.. cosmos1skjwj.. %s
if err != nil {
return err
}
var msgAuthorized = ""
msgAuthorized := ""
if len(args) >= 3 {
msgAuthorized = args[2]
}
@@ -80,7 +80,8 @@ $ %s query %s grants cosmos1skjw.. cosmos1skjwj.. %s
Granter: granter.String(),
Grantee: grantee.String(),
MsgTypeUrl: msgAuthorized,
Pagination: pageReq},
Pagination: pageReq,
},
)
if err != nil {
return err
-1
View File
@@ -245,7 +245,6 @@ Example:
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
-3
View File
@@ -160,7 +160,6 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() {
s.Require().NoError(err)
tc.postRun(&authorizations)
}
})
}
}
@@ -213,7 +212,6 @@ func (s *IntegrationTestSuite) TestQueryGranterGrantsGRPC() {
// FIXME: https://github.com/cosmos/cosmos-sdk/issues/10965
require.Len(authorizations.Grants, tc.numItems)
}
})
}
}
@@ -266,7 +264,6 @@ func (s *IntegrationTestSuite) TestQueryGranteeGrantsGRPC() {
// FIXME: https://github.com/cosmos/cosmos-sdk/issues/10965
require.Len(authorizations.Grants, tc.numItems)
}
})
}
}
+5 -5
View File
@@ -105,7 +105,6 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().Equal(int(response.Code), 0)
s.Require().NotEqual(int(response.Height), 0)
}
func (s *IntegrationTestSuite) createAccount(uid string) sdk.AccAddress {
@@ -140,9 +139,11 @@ func (s *IntegrationTestSuite) TearDownSuite() {
s.network.Cleanup()
}
var typeMsgSend = bank.SendAuthorization{}.MsgTypeURL()
var typeMsgVote = sdk.MsgTypeURL(&govv1.MsgVote{})
var typeMsgSubmitProposal = sdk.MsgTypeURL(&govv1.MsgSubmitProposal{})
var (
typeMsgSend = bank.SendAuthorization{}.MsgTypeURL()
typeMsgVote = sdk.MsgTypeURL(&govv1.MsgVote{})
typeMsgSubmitProposal = sdk.MsgTypeURL(&govv1.MsgSubmitProposal{})
)
func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() {
val := s.network.Validators[0]
@@ -752,7 +753,6 @@ func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() {
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
cmd := cli.NewCmdExecAuthorization()
clientCtx := val.ClientCtx
+1
View File
@@ -36,6 +36,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
msgservice.RegisterMsgServiceDesc(registry, MsgServiceDesc())
}
func init() {
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
+1 -1
View File
@@ -6,7 +6,7 @@ import (
// x/authz module sentinel errors
var (
//ErrNoAuthorizationFound error if there is no authorization found given a grant key
// ErrNoAuthorizationFound error if there is no authorization found given a grant key
ErrNoAuthorizationFound = sdkerrors.Register(ModuleName, 2, "authorization not found")
// ErrInvalidExpirationTime error if the set expiration time is in the past
ErrInvalidExpirationTime = sdkerrors.Register(ModuleName, 3, "expiration time of authorization should be more than current time")
+1 -3
View File
@@ -4,9 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
_ Authorization = &GenericAuthorization{}
)
var _ Authorization = &GenericAuthorization{}
// NewGenericAuthorization creates a new GenericAuthorization object.
func NewGenericAuthorization(msgTypeURL string) *GenericAuthorization {
+2 -4
View File
@@ -119,8 +119,7 @@ func (k Keeper) GranterGrants(c context.Context, req *authz.QueryGranterGrantsRe
authzStore := prefix.NewStore(store, grantStoreKey(nil, granter, ""))
var grants []*authz.GrantAuthorization
pageRes, err := query.FilteredPaginate(authzStore, req.Pagination, func(key []byte, value []byte,
accumulate bool) (bool, error) {
pageRes, err := query.FilteredPaginate(authzStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) {
auth, err := unmarshalAuthorization(k.cdc, value)
if err != nil {
return false, err
@@ -172,8 +171,7 @@ func (k Keeper) GranteeGrants(c context.Context, req *authz.QueryGranteeGrantsRe
store := prefix.NewStore(ctx.KVStore(k.storeKey), GrantKey)
var authorizations []*authz.GrantAuthorization
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key []byte, value []byte,
accumulate bool) (bool, error) {
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) {
auth, err := unmarshalAuthorization(k.cdc, value)
if err != nil {
return false, err
+6 -5
View File
@@ -83,7 +83,7 @@ func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA
// DispatchActions attempts to execute the provided messages via authorization
// grants from the message signer to the grantee.
func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs []sdk.Msg) ([][]byte, error) {
var results = make([][]byte, len(msgs))
results := make([][]byte, len(msgs))
now := ctx.BlockTime()
for i, msg := range msgs {
signers := msg.GetSigners()
@@ -245,7 +245,8 @@ func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, grant
// It should not be used in query or msg services without charging additional gas.
// The iteration stops when the handler function returns true or the iterator exhaust.
func (k Keeper) IterateGrants(ctx sdk.Context,
handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant authz.Grant) bool) {
handler func(granterAddr sdk.AccAddress, granteeAddr sdk.AccAddress, grant authz.Grant) bool,
) {
store := ctx.KVStore(k.storeKey)
iter := sdk.KVStorePrefixIterator(store, GrantKey)
defer iter.Close()
@@ -274,7 +275,8 @@ func (keeper Keeper) getGrantQueueItem(ctx sdk.Context, expiration time.Time, gr
}
func (k Keeper) setGrantQueueItem(ctx sdk.Context, expiration time.Time,
granter sdk.AccAddress, grantee sdk.AccAddress, queueItems *authz.GrantQueueItem) error {
granter sdk.AccAddress, grantee sdk.AccAddress, queueItems *authz.GrantQueueItem,
) error {
store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(queueItems)
if err != nil {
@@ -286,8 +288,7 @@ func (k Keeper) setGrantQueueItem(ctx sdk.Context, expiration time.Time,
}
// insertIntoGrantQueue inserts a grant key into the grant queue
func (keeper Keeper) insertIntoGrantQueue(ctx sdk.Context, granter, grantee sdk.AccAddress, msgType string,
expiration time.Time) error {
func (keeper Keeper) insertIntoGrantQueue(ctx sdk.Context, granter, grantee sdk.AccAddress, msgType string, expiration time.Time) error {
queueItems, err := keeper.getGrantQueueItem(ctx, expiration, granter, grantee)
if err != nil {
return err
-2
View File
@@ -118,7 +118,6 @@ func (s *TestSuite) TestKeeperIter() {
s.Require().Contains([]sdk.AccAddress{granterAddr, granter2Addr}, granter)
return true
})
}
func (s *TestSuite) TestDispatchAction() {
@@ -265,7 +264,6 @@ func (s *TestSuite) TestDispatchAction() {
tc.postRun()
})
}
}
// Tests that all msg events included in an authz MsgExec tx
+5 -3
View File
@@ -12,9 +12,11 @@ import (
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
)
var granter = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
var grantee = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
var msgType = bank.SendAuthorization{}.MsgTypeURL()
var (
granter = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
grantee = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
msgType = bank.SendAuthorization{}.MsgTypeURL()
)
func TestGrantkey(t *testing.T) {
require := require.New(t)
+2 -2
View File
@@ -30,7 +30,7 @@ func GrantQueueKey(expiration time.Time, granter sdk.AccAddress, grantee sdk.Acc
grantee = address.MustLengthPrefix(grantee)
l := 1 + len(exp) + len(granter) + len(grantee)
var key = make([]byte, l)
key := make([]byte, l)
copy(key, GrantQueuePrefix)
copy(key[1:], exp)
copy(key[1+len(exp):], granter)
@@ -48,7 +48,7 @@ func GrantStoreKey(grantee sdk.AccAddress, granter sdk.AccAddress, msgType strin
grantee = address.MustLengthPrefix(grantee)
l := 1 + len(grantee) + len(granter) + len(m)
var key = make([]byte, l)
key := make([]byte, l)
copy(key, GrantPrefix)
copy(key[1:], granter)
copy(key[1+len(granter):], grantee)
+5 -3
View File
@@ -10,9 +10,11 @@ import (
"github.com/stretchr/testify/require"
)
var granter = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
var grantee = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
var msgType = bank.SendAuthorization{}.MsgTypeURL()
var (
granter = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
grantee = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
msgType = bank.SendAuthorization{}.MsgTypeURL()
)
func TestGrantkey(t *testing.T) {
require := require.New(t)
-1
View File
@@ -7,7 +7,6 @@ import (
// BeginBlocker is called at the begining of every block
func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
// delete all the mature grants
if err := keeper.DequeueAndDeleteExpiredGrants(ctx); err != nil {
panic(err)
+2 -2
View File
@@ -27,7 +27,7 @@ func TestExpiredGrantsQueue(t *testing.T) {
expiration2 := expiration.AddDate(1, 0, 0)
smallCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 10))
var save = func(grantee sdk.AccAddress, exp *time.Time) {
save := func(grantee sdk.AccAddress, exp *time.Time) {
err := app.AuthzKeeper.SaveGrant(ctx, grantee, granter, banktypes.NewSendAuthorization(smallCoins), exp)
require.NoError(t, err, "Grant from %s", grantee.String())
}
@@ -40,7 +40,7 @@ func TestExpiredGrantsQueue(t *testing.T) {
authz.RegisterQueryServer(queryHelper, app.AuthzKeeper)
queryClient := authz.NewQueryClient(queryHelper)
var checkGrants = func(ctx sdk.Context, expectedNum int) {
checkGrants := func(ctx sdk.Context, expectedNum int) {
authzmodule.BeginBlocker(ctx, app.AuthzKeeper)
res, err := queryClient.GranterGrants(ctx.Context(), &authz.QueryGranterGrantsRequest{
+2 -1
View File
@@ -1,9 +1,10 @@
package authz
import (
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
"time"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
"github.com/gogo/protobuf/proto"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
+31 -15
View File
@@ -1,10 +1,11 @@
package authz_test
import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"testing"
"time"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
@@ -46,6 +47,7 @@ func TestMsgExecAuthorized(t *testing.T) {
}
}
}
func TestMsgRevokeAuthorization(t *testing.T) {
tests := []struct {
title string
@@ -84,21 +86,35 @@ func TestMsgGrantAuthorization(t *testing.T) {
expectErr bool
valBasic bool
}{
{"nil granter address",
nil, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, &now, false, false},
{"nil grantee address",
granter, nil, &banktypes.SendAuthorization{SpendLimit: coinsPos}, &now, false, false},
{"nil granter and grantee address",
nil, nil, &banktypes.SendAuthorization{SpendLimit: coinsPos}, &now, false, false},
{"nil authorization should fail",
granter, grantee, nil, &now, true, false},
{"valid test case",
granter, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, addDatePtr(&now, 1, 0), false, true},
{"valid test case with nil expire time",
granter, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, nil, false, true},
{
"nil granter address",
nil, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, &now, false, false,
},
{
"nil grantee address",
granter, nil, &banktypes.SendAuthorization{SpendLimit: coinsPos}, &now, false, false,
},
{
"nil granter and grantee address",
nil, nil, &banktypes.SendAuthorization{SpendLimit: coinsPos}, &now, false, false,
},
{
"nil authorization should fail",
granter, grantee, nil, &now, true, false,
},
{
"valid test case",
granter, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, addDatePtr(&now, 1, 0), false, true,
},
{
"valid test case with nil expire time",
granter, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, nil, false, true,
},
// we don't access the block time / nor time.Now, so we don't know if it's in the past at this level.
{"past expire time should not fail",
granter, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, addDatePtr(&now, 0, -1), false, true},
{
"past expire time should not fail",
granter, grantee, &banktypes.SendAuthorization{SpendLimit: coinsPos}, addDatePtr(&now, 0, -1), false, true,
},
}
for _, tc := range tests {
msg, err := authz.NewMsgGrant(
+2 -2
View File
@@ -41,8 +41,8 @@ const (
// WeightedOperations returns all the operations from the module with their respective weights
func WeightedOperations(
appParams simtypes.AppParams, cdc codec.JSONCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker) simulation.WeightedOperations {
appParams simtypes.AppParams, cdc codec.JSONCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker,
) simulation.WeightedOperations {
var (
weightMsgGrant int
weightExec int
+2 -4
View File
@@ -114,7 +114,6 @@ func (suite *SimTestSuite) TestSimulateGrant() {
suite.Require().Equal(granter.Address.String(), msg.Granter)
suite.Require().Equal(grantee.Address.String(), msg.Grantee)
suite.Require().Len(futureOperations, 0)
}
func (suite *SimTestSuite) TestSimulateRevoke() {
@@ -128,7 +127,8 @@ func (suite *SimTestSuite) TestSimulateRevoke() {
Header: tmproto.Header{
Height: suite.app.LastBlockHeight() + 1,
AppHash: suite.app.LastCommitID().Hash,
}})
},
})
initAmt := suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 200000)
initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt))
@@ -154,7 +154,6 @@ func (suite *SimTestSuite) TestSimulateRevoke() {
suite.Require().Equal(grantee.Address.String(), msg.Grantee)
suite.Require().Equal(banktypes.SendAuthorization{}.MsgTypeURL(), msg.MsgTypeUrl)
suite.Require().Len(futureOperations, 0)
}
func (suite *SimTestSuite) TestSimulateExec() {
@@ -189,7 +188,6 @@ func (suite *SimTestSuite) TestSimulateExec() {
suite.Require().True(operationMsg.OK)
suite.Require().Equal(grantee.Address.String(), msg.Grantee)
suite.Require().Len(futureOperations, 0)
}
func TestSimTestSuite(t *testing.T) {