From 0002d1b53fce25291ce72a17947defc25e9c16f3 Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 28 May 2024 14:34:28 +0530 Subject: [PATCH] fix build --- simapp/app.go | 22 ---------------- simapp/upgrades.go | 22 ++++++++++++++++ x/authz/authorization_grant_test.go | 2 +- x/authz/keeper/genesis.go | 2 +- x/authz/keeper/genesis_test.go | 2 +- x/authz/keeper/grpc_query_test.go | 4 +-- x/authz/keeper/keeper_test.go | 38 +++++++++++++-------------- x/authz/module/abci_test.go | 2 +- x/authz/simulation/operations_test.go | 4 +-- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index d81602e1f8a9..241f7b54a26a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -3,7 +3,6 @@ package simapp import ( - "context" "encoding/json" "fmt" "io" @@ -563,27 +562,6 @@ func NewSimApp( return app } -func (app *SimApp) RegisterUpgradeHandlers() { - // Upgrade handler for v2 - app.UpgradeKeeper.SetUpgradeHandler( - "v2", - func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - app.AuthzKeeper.SetAuthzRulesKeys(ctx, &authz.AllowedGrantRulesKeys{ - Keys: []*authz.Rule{ - &authz.Rule{Key: sdk.MsgTypeURL(&banktypes.MsgSend{}), Values: []string{ - authz.MaxAmount, authz.AllowedRecipients, - }}, - &authz.Rule{Key: sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), Values: []string{ - authz.AllowedStakeValidators, authz.AllowedMaxStakeAmount, - }}, - }, - }) - - return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) - }, - ) -} - func (app *SimApp) setAnteHandler(txConfig client.TxConfig) { anteHandler, err := NewAnteHandler( HandlerOptions{ diff --git a/simapp/upgrades.go b/simapp/upgrades.go index 66c9fb87e7c0..cdfa1075c9fc 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -7,7 +7,11 @@ import ( circuittypes "cosmossdk.io/x/circuit/types" upgradetypes "cosmossdk.io/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/authz" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade @@ -26,6 +30,24 @@ func (app SimApp) RegisterUpgradeHandlers() { }, ) + app.UpgradeKeeper.SetUpgradeHandler( + "v2", + func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + app.AuthzKeeper.SetAuthzRulesKeys(ctx, &authz.AllowedGrantRulesKeys{ + Keys: []*authz.Rule{ + &authz.Rule{Key: sdk.MsgTypeURL(&banktypes.MsgSend{}), Values: []string{ + authz.MaxAmount, authz.AllowedRecipients, + }}, + &authz.Rule{Key: sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), Values: []string{ + authz.AllowedStakeValidators, authz.AllowedMaxStakeAmount, + }}, + }, + }) + + return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) + }, + ) + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { panic(err) diff --git a/x/authz/authorization_grant_test.go b/x/authz/authorization_grant_test.go index ce14692c0b5a..eddc9ee17c03 100644 --- a/x/authz/authorization_grant_test.go +++ b/x/authz/authorization_grant_test.go @@ -36,7 +36,7 @@ func TestNewGrant(t *testing.T) { for _, tc := range tcs { tc := tc t.Run(tc.title, func(t *testing.T) { - _, err := NewGrant(tc.blockTime, tc.a, tc.expire) + _, err := NewGrant(tc.blockTime, tc.a, tc.expire, nil) expecError(require.New(t), tc.err, err) }) } diff --git a/x/authz/keeper/genesis.go b/x/authz/keeper/genesis.go index 08b84b8ed682..7b18e5b56ad9 100644 --- a/x/authz/keeper/genesis.go +++ b/x/authz/keeper/genesis.go @@ -28,7 +28,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *authz.GenesisState) { panic("expected authorization") } - err = k.SaveGrant(ctx, grantee, granter, a, entry.Expiration) + err = k.SaveGrant(ctx, grantee, granter, a, entry.Expiration, nil) if err != nil { panic(err) } diff --git a/x/authz/keeper/genesis_test.go b/x/authz/keeper/genesis_test.go index 94320f0ff654..e62ee7fea532 100644 --- a/x/authz/keeper/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -76,7 +76,7 @@ func (suite *GenesisTestSuite) TestImportExportGenesis() { now := suite.ctx.BlockTime() expires := now.Add(time.Hour) grant := &bank.SendAuthorization{SpendLimit: coins} - err := suite.keeper.SaveGrant(suite.ctx, granteeAddr, granterAddr, grant, &expires) + err := suite.keeper.SaveGrant(suite.ctx, granteeAddr, granterAddr, grant, &expires, nil) suite.Require().NoError(err) genesis := suite.keeper.ExportGenesis(suite.ctx) diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index 00d16f96381a..4d96d3316137 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -278,7 +278,7 @@ func (suite *TestSuite) createSendAuthorization(grantee, granter sdk.AccAddress) exp := suite.ctx.BlockHeader().Time.Add(time.Hour) newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) authorization := &banktypes.SendAuthorization{SpendLimit: newCoins} - err := suite.authzKeeper.SaveGrant(suite.ctx, grantee, granter, authorization, &exp) + err := suite.authzKeeper.SaveGrant(suite.ctx, grantee, granter, authorization, &exp, nil) suite.Require().NoError(err) return authorization } @@ -287,7 +287,7 @@ func (suite *TestSuite) createSendAuthorizationWithAllowList(grantee, granter sd exp := suite.ctx.BlockHeader().Time.Add(time.Hour) newCoins := sdk.NewCoins(sdk.NewInt64Coin("steak", 100)) authorization := &banktypes.SendAuthorization{SpendLimit: newCoins, AllowList: []string{suite.addrs[5].String()}} - err := suite.authzKeeper.SaveGrant(suite.ctx, grantee, granter, authorization, &exp) + err := suite.authzKeeper.SaveGrant(suite.ctx, grantee, granter, authorization, &exp, nil) suite.Require().NoError(err) return authorization } diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 066e7d70750a..58dc918b4249 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -101,7 +101,7 @@ func (s *TestSuite) TestKeeper() { s.T().Log("verify save, get and delete") sendAutz := &banktypes.SendAuthorization{SpendLimit: coins100} expire := now.AddDate(1, 0, 0) - err = s.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, sendAutz, &expire) + err = s.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, sendAutz, &expire, nil) require.NoError(err) authorizations, err = s.authzKeeper.GetAuthorizations(ctx, granteeAddr, granterAddr) @@ -116,7 +116,7 @@ func (s *TestSuite) TestKeeper() { require.Len(authorizations, 0) s.T().Log("verify granting same authorization overwrite existing authorization") - err = s.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, sendAutz, &expire) + err = s.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, sendAutz, &expire, nil) require.NoError(err) authorizations, err = s.authzKeeper.GetAuthorizations(ctx, granteeAddr, granterAddr) @@ -124,7 +124,7 @@ func (s *TestSuite) TestKeeper() { require.Len(authorizations, 1) sendAutz = &banktypes.SendAuthorization{SpendLimit: coins1000} - err = s.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, sendAutz, &expire) + err = s.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, sendAutz, &expire, nil) require.NoError(err) authorizations, err = s.authzKeeper.GetAuthorizations(ctx, granteeAddr, granterAddr) require.NoError(err) @@ -148,8 +148,8 @@ func (s *TestSuite) TestKeeperIter() { e := ctx.BlockTime().AddDate(1, 0, 0) sendAuthz := banktypes.NewSendAuthorization(coins100, nil) - s.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, sendAuthz, &e) - s.authzKeeper.SaveGrant(ctx, granteeAddr, granter2Addr, sendAuthz, &e) + s.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, sendAuthz, &e, nil) + s.authzKeeper.SaveGrant(ctx, granteeAddr, granter2Addr, sendAuthz, &e, nil) s.authzKeeper.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant authz.Grant) bool { s.Require().Equal(granteeAddr, grantee) @@ -207,7 +207,7 @@ func (s *TestSuite) TestDispatchAction() { "authorization expired", func() sdk.Context { e := now.AddDate(0, 0, 1) - err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e) + err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e, nil) require.NoError(err) return s.ctx.WithBlockTime(s.ctx.BlockTime().AddDate(0, 0, 2)) }, @@ -226,7 +226,7 @@ func (s *TestSuite) TestDispatchAction() { "requested amount is more than spend limit", func() sdk.Context { e := now.AddDate(0, 1, 0) - err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e) + err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e, nil) require.NoError(err) return s.ctx }, @@ -245,7 +245,7 @@ func (s *TestSuite) TestDispatchAction() { "", func() sdk.Context { e := now.AddDate(0, 1, 0) - err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e) + err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e, nil) require.NoError(err) return s.ctx }, @@ -271,7 +271,7 @@ func (s *TestSuite) TestDispatchAction() { "", func() sdk.Context { e := now.AddDate(0, 1, 0) - err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e) + err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e, nil) require.NoError(err) return s.ctx }, @@ -321,7 +321,7 @@ func (s *TestSuite) TestDispatchedEvents() { }) // grant authorization - err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, &banktypes.SendAuthorization{SpendLimit: coins10}, &expiration) + err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, &banktypes.SendAuthorization{SpendLimit: coins10}, &expiration, nil) require.NoError(err) authorizations, err := s.authzKeeper.GetAuthorizations(s.ctx, granteeAddr, granterAddr) require.NoError(err) @@ -363,18 +363,18 @@ func (s *TestSuite) TestDequeueAllGrantsQueue() { a := banktypes.SendAuthorization{SpendLimit: coins100} // create few authorizations - err := s.authzKeeper.SaveGrant(s.ctx, grantee, granter, &a, &exp) + err := s.authzKeeper.SaveGrant(s.ctx, grantee, granter, &a, &exp, nil) require.NoError(err) - err = s.authzKeeper.SaveGrant(s.ctx, grantee1, granter, &a, &exp) + err = s.authzKeeper.SaveGrant(s.ctx, grantee1, granter, &a, &exp, nil) require.NoError(err) exp2 := exp.AddDate(0, 1, 0) - err = s.authzKeeper.SaveGrant(s.ctx, granter, grantee1, &a, &exp2) + err = s.authzKeeper.SaveGrant(s.ctx, granter, grantee1, &a, &exp2, nil) require.NoError(err) exp2 = exp.AddDate(2, 0, 0) - err = s.authzKeeper.SaveGrant(s.ctx, granter, grantee, &a, &exp2) + err = s.authzKeeper.SaveGrant(s.ctx, granter, grantee, &a, &exp2, nil) require.NoError(err) newCtx := s.ctx.WithBlockTime(exp.AddDate(1, 0, 0)) @@ -413,9 +413,9 @@ func (s *TestSuite) TestGetAuthorization() { expired := start.Add(time.Duration(1) * time.Second) notExpired := start.Add(time.Duration(5) * time.Hour) - s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthMulti, nil), "creating grant 1->2") - s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr3, genAuthSend, &expired), "creating grant 1->3") - s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr4, sendAuth, ¬Expired), "creating grant 1->4") + s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthMulti, nil, nil), "creating grant 1->2") + s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr3, genAuthSend, &expired, nil), "creating grant 1->3") + s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr4, sendAuth, ¬Expired, nil), "creating grant 1->4") // Without access to private keeper methods, I don't know how to save a grant with an invalid authorization. newCtx := s.ctx.WithBlockTime(start.Add(time.Duration(1) * time.Minute)) @@ -489,8 +489,8 @@ func (s *TestSuite) TestGetAuthorizations() { start := s.ctx.BlockHeader().Time expired := start.Add(time.Duration(1) * time.Second) - s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthMulti, &expired), "creating multi send grant 1->2") - s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthSend, &expired), "creating send grant 1->2") + s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthMulti, &expired, nil), "creating multi send grant 1->2") + s.Require().NoError(s.authzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthSend, &expired, nil), "creating send grant 1->2") authzs, err := s.authzKeeper.GetAuthorizations(s.ctx, addr1, addr2) require.NoError(err) diff --git a/x/authz/module/abci_test.go b/x/authz/module/abci_test.go index 12055e0cfa12..273fb2858804 100644 --- a/x/authz/module/abci_test.go +++ b/x/authz/module/abci_test.go @@ -68,7 +68,7 @@ func TestExpiredGrantsQueue(t *testing.T) { authzKeeper := keeper.NewKeeper(storeService, encCfg.Codec, baseApp.MsgServiceRouter(), accountKeeper) save := func(grantee sdk.AccAddress, exp *time.Time) { - err := authzKeeper.SaveGrant(ctx, grantee, granter, sendAuthz, exp) + err := authzKeeper.SaveGrant(ctx, grantee, granter, sendAuthz, exp, nil) require.NoError(t, err, "Grant from %s", grantee.String()) } save(grantee1, &expiration) diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 8a6894dc2b07..dcf205ebfaee 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -163,7 +163,7 @@ func (suite *SimTestSuite) TestSimulateRevoke() { a := banktypes.NewSendAuthorization(initCoins, nil) expire := time.Now().Add(30 * time.Hour) - err := suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire) + err := suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire, nil) suite.Require().NoError(err) // execute operation @@ -197,7 +197,7 @@ func (suite *SimTestSuite) TestSimulateExec() { a := banktypes.NewSendAuthorization(initCoins, nil) expire := suite.ctx.BlockTime().Add(1 * time.Hour) - err := suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire) + err := suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire, nil) suite.Require().NoError(err) // execute operation