fix(x/authz): GetAuthorizations (#17334)

This commit is contained in:
devon 2023-08-24 23:32:00 +08:00 committed by GitHub
parent 7c10b2482c
commit a429238fc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -266,9 +266,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
}

View File

@ -482,6 +482,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))
}