Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
atheeshp committed May 28, 2024
1 parent d5b0c28 commit 0002d1b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 49 deletions.
22 changes: 0 additions & 22 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package simapp

import (
"context"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -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{
Expand Down
22 changes: 22 additions & 0 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}},
},
})

Check warning

Code scanning / gosec

Errors unhandled. Warning

Errors unhandled.

return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
},
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion x/authz/authorization_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion x/authz/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion x/authz/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions x/authz/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
38 changes: 19 additions & 19 deletions x/authz/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -116,15 +116,15 @@ 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)
require.NoError(err)
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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
},
Expand All @@ -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
},
Expand All @@ -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
},
Expand All @@ -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
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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, &notExpired), "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, &notExpired, 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))

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/authz/module/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x/authz/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0002d1b

Please sign in to comment.