Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
5acda5d78d
commit
cea0fb50bb
@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
* [#21044](https://github.com/cosmos/cosmos-sdk/pull/21044) `k.DispatchActions` returns a slice of byte slices of proto marshaled anys instead of a slice of byte slices of `sdk.Result.Data`.
|
||||
* [#20502](https://github.com/cosmos/cosmos-sdk/pull/20502) `Accept` on the `Authorization` interface now expects the authz environment in the `context.Context`. This is already done when `Accept` is called by `k.DispatchActions`, but should be done manually if `Accept` is called directly.
|
||||
* [#19783](https://github.com/cosmos/cosmos-sdk/pull/19783) Removes the use of Accounts String() method
|
||||
* `NewMsgExec`, `NewMsgGrant` and `NewMsgRevoke` now takes strings as arguments instead of `sdk.AccAddress`.
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
gogoproto "github.com/cosmos/gogoproto/proto"
|
||||
gogoprotoany "github.com/cosmos/gogoproto/types/any"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
corecontext "cosmossdk.io/core/context"
|
||||
@ -145,10 +146,20 @@ func (k Keeper) DispatchActions(ctx context.Context, grantee sdk.AccAddress, msg
|
||||
}
|
||||
|
||||
// no need to use the branch service here, as if the transaction fails, the transaction will be reverted
|
||||
_, err = k.MsgRouterService.InvokeUntyped(ctx, msg)
|
||||
resp, err := k.MsgRouterService.InvokeUntyped(ctx, msg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to execute message %d; message %v: %w", i, msg, err)
|
||||
}
|
||||
|
||||
msgRespAny, err := gogoprotoany.NewAnyWithCacheWithValue(resp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create any for response %d; message %s: %w", i, gogoproto.MessageName(msg), err)
|
||||
}
|
||||
|
||||
results[i], err = gogoproto.Marshal(msgRespAny)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal response %d; message %s: %w", i, gogoproto.MessageName(msg), err)
|
||||
}
|
||||
}
|
||||
|
||||
return results, nil
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
gogoproto "github.com/cosmos/gogoproto/proto"
|
||||
gogoprotoany "github.com/cosmos/gogoproto/types/any"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@ -245,12 +247,13 @@ func (s *TestSuite) TestDispatchAction() {
|
||||
a := banktypes.NewSendAuthorization(coins100, nil, s.accountKeeper.AddressCodec())
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
req authz.MsgExec
|
||||
expectErr bool
|
||||
errMsg string
|
||||
preRun func() sdk.Context
|
||||
postRun func()
|
||||
name string
|
||||
req authz.MsgExec
|
||||
expectErr bool
|
||||
errMsg string
|
||||
expectResp string
|
||||
preRun func() sdk.Context
|
||||
postRun func()
|
||||
}{
|
||||
{
|
||||
"expect error authorization not found",
|
||||
@ -263,6 +266,7 @@ func (s *TestSuite) TestDispatchAction() {
|
||||
}),
|
||||
true,
|
||||
"authorization not found",
|
||||
"",
|
||||
func() sdk.Context {
|
||||
// remove any existing authorizations
|
||||
err := s.authzKeeper.DeleteGrant(s.ctx, granteeAddr, granterAddr, bankSendAuthMsgType)
|
||||
@ -282,6 +286,7 @@ func (s *TestSuite) TestDispatchAction() {
|
||||
}),
|
||||
true,
|
||||
"authorization expired",
|
||||
"",
|
||||
func() sdk.Context {
|
||||
e := now.AddDate(0, 0, 1)
|
||||
err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e)
|
||||
@ -301,6 +306,7 @@ func (s *TestSuite) TestDispatchAction() {
|
||||
}),
|
||||
true,
|
||||
"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)
|
||||
@ -320,6 +326,7 @@ func (s *TestSuite) TestDispatchAction() {
|
||||
}),
|
||||
false,
|
||||
"",
|
||||
"/cosmos.bank.v1beta1.MsgSendResponse",
|
||||
func() sdk.Context {
|
||||
e := now.AddDate(0, 1, 0)
|
||||
err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e)
|
||||
@ -346,6 +353,7 @@ func (s *TestSuite) TestDispatchAction() {
|
||||
}),
|
||||
false,
|
||||
"",
|
||||
"/cosmos.bank.v1beta1.MsgSendResponse",
|
||||
func() sdk.Context {
|
||||
e := now.AddDate(0, 1, 0)
|
||||
err := s.authzKeeper.SaveGrant(s.ctx, granteeAddr, granterAddr, a, &e)
|
||||
@ -372,7 +380,15 @@ func (s *TestSuite) TestDispatchAction() {
|
||||
require.Contains(err.Error(), tc.errMsg)
|
||||
} else {
|
||||
require.NoError(err)
|
||||
require.NotNil(result)
|
||||
require.NotEmpty(result)
|
||||
// unmarshal the result
|
||||
for _, res := range result {
|
||||
var msgRes gogoprotoany.Any
|
||||
err := gogoproto.Unmarshal(res, &msgRes)
|
||||
require.NoError(err)
|
||||
require.NotNil(msgRes)
|
||||
require.Equal(msgRes.TypeUrl, tc.expectResp)
|
||||
}
|
||||
}
|
||||
tc.postRun()
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user