cosmos-sdk/x/authz/module/abci_test.go
MD Aleem 6d1525f039
feat(authz)!: pruning expired authorizations (#10714)
## Description

Ref: #8311 
closes: #10611 



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2022-02-16 17:36:50 +00:00

53 lines
1.9 KiB
Go

package authz_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/proto/tendermint/types"
)
func TestExpiredGrantsQueue(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, types.Header{})
addrs := simapp.AddTestAddrsIncremental(app, ctx, 4, sdk.NewInt(30000000))
granter := addrs[0]
grantee1 := addrs[1]
grantee2 := addrs[2]
grantee3 := addrs[3]
expiration := ctx.BlockTime().AddDate(0, 1, 0)
smallCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 10))
app.AuthzKeeper.SaveGrant(ctx, grantee1, granter, banktypes.NewSendAuthorization(smallCoins), expiration)
app.AuthzKeeper.SaveGrant(ctx, grantee2, granter, banktypes.NewSendAuthorization(smallCoins), expiration)
app.AuthzKeeper.SaveGrant(ctx, grantee3, granter, banktypes.NewSendAuthorization(smallCoins), expiration.AddDate(1, 0, 0))
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
authz.RegisterQueryServer(queryHelper, app.AuthzKeeper)
queryClient := authz.NewQueryClient(queryHelper)
authzmodule.BeginBlocker(ctx, app.AuthzKeeper)
res, err := queryClient.GranterGrants(ctx.Context(), &authz.QueryGranterGrantsRequest{
Granter: granter.String(),
})
require.NoError(t, err)
require.NotNil(t, res)
require.Len(t, res.Grants, 3)
ctx = ctx.WithBlockTime(expiration.AddDate(0, 2, 0))
authzmodule.BeginBlocker(ctx, app.AuthzKeeper)
res, err = queryClient.GranterGrants(ctx.Context(), &authz.QueryGranterGrantsRequest{
Granter: granter.String(),
})
require.NoError(t, err)
require.NotNil(t, res)
require.Len(t, res.Grants, 1)
}