From 300cc40438af2805f53aa87d3e363ab995dadc96 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 24 Aug 2023 19:53:38 +0000 Subject: [PATCH] fix(x/authz): GetAuthorizations (backport #17334) (#17527) Co-authored-by: devon <80245700+devon-chain@users.noreply.github.com> Co-authored-by: Julien Robert --- CHANGELOG.md | 6 +++++- x/authz/keeper/keeper_test.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a84128e4081..6a44501ee702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Bug Fixes + +* (x/authz) [#17524](https://github.com/cosmos/cosmos-sdk/pull/17524) Fix an issue where the `cachedValue` of an authorization would not be correcty populated when there are multiple authorizations returned in `GetAuthorizations`. + ## [v0.46.15](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.14) - 2023-08-21 ### Improvements @@ -47,7 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Add `MigrateHandler` to allow reuse migrate genesis related function. * In v0.46, v0.47 this function is additive to the `genesis migrate` command. However in v0.50+, adding custom migrations to the `genesis migrate` command is directly possible. -## Bug Fixes +### Bug Fixes * (server) [#17181](https://github.com/cosmos/cosmos-sdk/pull/17181) Fix `db_backend` lookup fallback from `config.toml`. diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 1199c127e2cd..3cce6b1fc65b 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -551,6 +551,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.app.AuthzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthMulti, &expired), "creating multi send grant 1->2") + s.Require().NoError(s.app.AuthzKeeper.SaveGrant(s.ctx, addr1, addr2, genAuthSend, &expired), "creating send grant 1->2") + + authzs, err := s.app.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)) }