Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service msgs simulations #8188

Merged
merged 5 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion types/simulation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package simulation
import (
"encoding/json"
"math/rand"
"reflect"
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -75,7 +76,16 @@ func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) Oper
}

// NewOperationMsg - create a new operation message from sdk.Msg
func NewOperationMsg(msg sdk.Msg, ok bool, comment string) OperationMsg {
func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec) OperationMsg {
if reflect.TypeOf(msg) == reflect.TypeOf(sdk.ServiceMsg{}) {
srvMsg, ok := msg.(sdk.ServiceMsg)
if !ok {
panic("failed: type assert")
}
bz := cdc.MustMarshalJSON(srvMsg.Request)

return NewOperationMsgBasic(msg.Route(), msg.Type(), comment, ok, bz)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we shouldn't worry about Route and Msg here I think. Instead we should use the MethodName.

}
return NewOperationMsgBasic(msg.Route(), msg.Type(), comment, ok, msg.GetSignBytes())
}

Expand Down
12 changes: 6 additions & 6 deletions x/authz/client/cli/service_msg_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ gogogrpc.ClientConn = &serviceMsgClientConn{}
var _ gogogrpc.ClientConn = &ServiceMsgClientConn{}

// serviceMsgClientConn is an instance of grpc.ClientConn that is used to test building
// transactions with MsgClient's. It is intended to be replaced by the work in
// https://github.com/cosmos/cosmos-sdk/issues/7541 when that is ready.
type serviceMsgClientConn struct {
msgs []sdk.Msg
type ServiceMsgClientConn struct {
Msgs []sdk.Msg
}

func (t *serviceMsgClientConn) Invoke(_ context.Context, method string, args, _ interface{}, _ ...grpc.CallOption) error {
func (t *ServiceMsgClientConn) Invoke(_ context.Context, method string, args, _ interface{}, _ ...grpc.CallOption) error {
req, ok := args.(sdk.MsgRequest)
if !ok {
return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil))
Expand All @@ -30,14 +30,14 @@ func (t *serviceMsgClientConn) Invoke(_ context.Context, method string, args, _
return err
}

t.msgs = append(t.msgs, sdk.ServiceMsg{
t.Msgs = append(t.Msgs, sdk.ServiceMsg{
MethodName: method,
Request: req,
})

return nil
}

func (t *serviceMsgClientConn) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) {
func (t *ServiceMsgClientConn) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) {
return nil, fmt.Errorf("not supported")
}
12 changes: 6 additions & 6 deletions x/authz/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ Examples:
return err
}

svcMsgClientConn := &serviceMsgClientConn{}
svcMsgClientConn := &ServiceMsgClientConn{}
authzMsgClient := types.NewMsgClient(svcMsgClientConn)
_, err = authzMsgClient.GrantAuthorization(context.Background(), msg)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.Msgs...)

},
}
Expand Down Expand Up @@ -131,14 +131,14 @@ Example:

msg := types.NewMsgRevokeAuthorization(granter, grantee, msgAuthorized)

svcMsgClientConn := &serviceMsgClientConn{}
svcMsgClientConn := &ServiceMsgClientConn{}
authzMsgClient := types.NewMsgClient(svcMsgClientConn)
_, err = authzMsgClient.RevokeAuthorization(context.Background(), &msg)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.Msgs...)
},
}
flags.AddTxFlagsToCmd(cmd)
Expand Down Expand Up @@ -180,14 +180,14 @@ Example:
}

msg := types.NewMsgExecAuthorized(grantee, serviceMsgs)
svcMsgClientConn := &serviceMsgClientConn{}
svcMsgClientConn := &ServiceMsgClientConn{}
authzMsgClient := types.NewMsgClient(svcMsgClientConn)
_, err = authzMsgClient.ExecAuthorized(context.Background(), &msg)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.Msgs...)
},
}

Expand Down
1 change: 0 additions & 1 deletion x/authz/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string {
var grantA, grantB types.AuthorizationGrant
cdc.MustUnmarshalBinaryBare(kvA.Value, &grantA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &grantB)
fmt.Println(grantA)
return fmt.Sprintf("%v\n%v", grantA, grantB)
default:
panic(fmt.Sprintf("invalid authz key %X", kvA.Key))
Expand Down
Loading