Skip to content

Commit

Permalink
fix(x/authz): GetAuthorizations (#17334)
Browse files Browse the repository at this point in the history
(cherry picked from commit a429238)
  • Loading branch information
devon-chain authored and mergify[bot] committed Aug 24, 2023
1 parent 99101ab commit 408f692
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x/authz/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ func (k Keeper) GetAuthorizations(ctx context.Context, grantee, granter sdk.AccA
iter := storetypes.KVStorePrefixIterator(store, key)
defer iter.Close()

var authorization authz.Grant
var authorizations []authz.Authorization
for ; iter.Valid(); iter.Next() {
var authorization authz.Grant
if err := k.cdc.Unmarshal(iter.Value(), &authorization); err != nil {
return nil, err
}
Expand Down
21 changes: 21 additions & 0 deletions x/authz/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,27 @@ func (s *TestSuite) TestGetAuthorization() {
}
}

func (s *TestSuite) TestGetAuthorizations() {
require := s.Require()
addr1 := s.addrs[1]
addr2 := s.addrs[2]

genAuthMulti := authz.NewGenericAuthorization(sdk.MsgTypeURL(&banktypes.MsgMultiSend{}))
genAuthSend := authz.NewGenericAuthorization(sdk.MsgTypeURL(&banktypes.MsgSend{}))

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")

authzs, err := s.authzKeeper.GetAuthorizations(s.ctx, addr1, addr2)
require.NoError(err)
require.Len(authzs, 2)
require.Equal(sdk.MsgTypeURL(&banktypes.MsgMultiSend{}), authzs[0].MsgTypeURL())
require.Equal(sdk.MsgTypeURL(&banktypes.MsgSend{}), authzs[1].MsgTypeURL())
}

func TestTestSuite(t *testing.T) {
suite.Run(t, new(TestSuite))
}

0 comments on commit 408f692

Please sign in to comment.