From 9c8486d9f3e2ccb8973449b8fef6e12e8436d8d2 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 22 Oct 2020 16:24:32 +0200 Subject: [PATCH 01/18] Add invoke & NewStream --- client/tx_config.go | 3 +++ x/auth/tx/msg_service.go | 35 +++++++++++++++++++++++++++++++++++ x/auth/tx/msg_service_test.go | 1 + 3 files changed, 39 insertions(+) create mode 100644 x/auth/tx/msg_service.go create mode 100644 x/auth/tx/msg_service_test.go diff --git a/client/tx_config.go b/client/tx_config.go index 6992a7a2402d..70cc4862a9c2 100644 --- a/client/tx_config.go +++ b/client/tx_config.go @@ -1,6 +1,8 @@ package client import ( + gogogrpc "github.com/gogo/protobuf/grpc" + sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -34,6 +36,7 @@ type ( // signatures, and provide canonical bytes to sign over. The transaction must // also know how to encode itself. TxBuilder interface { + gogogrpc.ClientConn GetTx() signing.Tx SetMsgs(msgs ...sdk.Msg) error diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go new file mode 100644 index 000000000000..590cfcb1977b --- /dev/null +++ b/x/auth/tx/msg_service.go @@ -0,0 +1,35 @@ +package tx + +import ( + gocontext "context" + "fmt" + + "google.golang.org/grpc" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Invoke implements the grpc ClientConn.Invoke method. +func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { + req, ok := args.(sdk.MsgRequest) + if !ok { + return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) + } + + err := req.ValidateBasic() + if err != nil { + return err + } + + w.SetMsgs(sdk.ServiceMsg{ + MethodName: method, + Request: req, + }) + + return nil +} + +// NewStream implements the grpc ClientConn.NewStream method. +func (w *wrapper) NewStream(gocontext.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, fmt.Errorf("not supported") +} diff --git a/x/auth/tx/msg_service_test.go b/x/auth/tx/msg_service_test.go new file mode 100644 index 000000000000..0ad772042e21 --- /dev/null +++ b/x/auth/tx/msg_service_test.go @@ -0,0 +1 @@ +package tx_test From 2c36489d569c9c03fc77d3e2f8423acf2badb926 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 22 Oct 2020 16:27:30 +0200 Subject: [PATCH 02/18] Remove validate basic --- x/auth/tx/msg_service.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index 590cfcb1977b..f7cba3ec6d08 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -16,11 +16,6 @@ func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interfa return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) } - err := req.ValidateBasic() - if err != nil { - return err - } - w.SetMsgs(sdk.ServiceMsg{ MethodName: method, Request: req, From 097c13f7b18efba914167c2766334e1fb12f2682 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 22 Oct 2020 16:35:10 +0200 Subject: [PATCH 03/18] Update test --- x/auth/legacy/legacytx/msg_service.go | 30 ++++++++++++++++++++ x/auth/tx/msg_service_test.go | 1 - x/bank/client/cli/cli_test.go | 41 ++------------------------- 3 files changed, 33 insertions(+), 39 deletions(-) create mode 100644 x/auth/legacy/legacytx/msg_service.go delete mode 100644 x/auth/tx/msg_service_test.go diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go new file mode 100644 index 000000000000..44f37655e98f --- /dev/null +++ b/x/auth/legacy/legacytx/msg_service.go @@ -0,0 +1,30 @@ +package legacytx + +import ( + gocontext "context" + "fmt" + + "google.golang.org/grpc" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Invoke implements the grpc ClientConn.Invoke method. +func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { + req, ok := args.(sdk.MsgRequest) + if !ok { + return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) + } + + s.SetMsgs(sdk.ServiceMsg{ + MethodName: method, + Request: req, + }) + + return nil +} + +// NewStream implements the grpc ClientConn.NewStream method. +func (s *StdTxBuilder) NewStream(gocontext.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, fmt.Errorf("not supported") +} diff --git a/x/auth/tx/msg_service_test.go b/x/auth/tx/msg_service_test.go deleted file mode 100644 index 0ad772042e21..000000000000 --- a/x/auth/tx/msg_service_test.go +++ /dev/null @@ -1 +0,0 @@ -package tx_test diff --git a/x/bank/client/cli/cli_test.go b/x/bank/client/cli/cli_test.go index c68be4ccd348..8b153d000d18 100644 --- a/x/bank/client/cli/cli_test.go +++ b/x/bank/client/cli/cli_test.go @@ -9,9 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/gogo/protobuf/grpc" - grpc2 "google.golang.org/grpc" - "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" tmcli "github.com/tendermint/tendermint/libs/cli" @@ -302,38 +299,6 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() { } } -// 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 -} - -func (t *serviceMsgClientConn) Invoke(_ context.Context, method string, args, _ interface{}, _ ...grpc2.CallOption) error { - req, ok := args.(sdk.MsgRequest) - if !ok { - return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) - } - - err := req.ValidateBasic() - if err != nil { - return err - } - - t.msgs = append(t.msgs, sdk.ServiceMsg{ - MethodName: method, - Request: req, - }) - - return nil -} - -func (t *serviceMsgClientConn) NewStream(context.Context, *grpc2.StreamDesc, string, ...grpc2.CallOption) (grpc2.ClientStream, error) { - return nil, fmt.Errorf("not supported") -} - -var _ grpc.ClientConn = &serviceMsgClientConn{} - // newSendTxMsgServiceCmd is just for the purpose of testing ServiceMsg's in an end-to-end case. It is effectively // NewSendTxCmd but using MsgClient. func newSendTxMsgServiceCmd() *cobra.Command { @@ -361,15 +326,15 @@ ignored as it is implied from [from_key_or_address].`, return err } + txBuilder := clientCtx.TxConfig.NewTxBuilder() msg := types.NewMsgSend(clientCtx.GetFromAddress(), toAddr, coins) - svcMsgClientConn := &serviceMsgClientConn{} - bankMsgClient := types.NewMsgClient(svcMsgClientConn) + bankMsgClient := types.NewMsgClient(txBuilder) _, err = bankMsgClient.Send(context.Background(), msg) if err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), txBuilder.GetTx().GetMsgs()...) }, } From b0e89dc5be056c25c64376f054fd6462ef84d359 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 22 Oct 2020 18:30:30 +0200 Subject: [PATCH 04/18] WIP --- codec/types/any.go | 17 ++++++++++++----- types/tx/types.go | 1 + x/auth/tx/builder.go | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/codec/types/any.go b/codec/types/any.go index 38fe4b42aa72..02dba0171557 100644 --- a/codec/types/any.go +++ b/codec/types/any.go @@ -68,11 +68,11 @@ func NewAnyWithValue(value proto.Message) (*Any, error) { return any, nil } -// Pack packs the value x in the Any or returns an error. This also caches -// the packed value so that it can be retrieved from GetCachedValue without -// unmarshaling -func (any *Any) Pack(x proto.Message) error { - any.TypeUrl = "/" + proto.MessageName(x) +// PackWithCustomTypeURL packs the value x in the Any or returns an error, +// allowing for a custom TypeUrl. This also caches the packed value so that it +// can be retrieved fromGetCachedValue without unmarshaling. +func (any *Any) PackWithCustomTypeURL(typeURL string, x proto.Message) error { + any.TypeUrl = typeURL bz, err := proto.Marshal(x) if err != nil { return err @@ -84,6 +84,13 @@ func (any *Any) Pack(x proto.Message) error { return nil } +// Pack packs the value x in the Any or returns an error. This also caches +// the packed value so that it can be retrieved from GetCachedValue without +// unmarshaling +func (any *Any) Pack(x proto.Message) error { + return any.PackWithCustomTypeURL("/"+proto.MessageName(x), x) +} + // UnsafePackAny packs the value x in the Any and instead of returning the error // in the case of a packing failure, keeps the cached value. This should only // be used in situations where compatibility is needed with amino. Amino-only diff --git a/types/tx/types.go b/types/tx/types.go index e9066ef41b42..7252eaa4ef2e 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -29,6 +29,7 @@ func (t *Tx) GetMsgs() []sdk.Msg { for i, any := range anys { var msg sdk.Msg if isServiceMsg(any.TypeUrl) { + fmt.Println("GetMsgs any=", any) msg = sdk.ServiceMsg{ MethodName: any.TypeUrl, Request: any.GetCachedValue().(sdk.MsgRequest), diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index b3697e70b262..79997afd5627 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -212,7 +212,7 @@ func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { if err != nil { return err } - anys[i] = &codectypes.Any{ + anys[i] = any & codectypes.Any{ TypeUrl: msg.MethodName, Value: bz, } From 7b44e68d592aefbefe55e2ac411a7498fae440a9 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 23 Oct 2020 12:41:36 +0200 Subject: [PATCH 05/18] NewAnyWithWithTypeURL --- codec/types/any.go | 19 +++++++++++++++++++ x/auth/tx/builder.go | 6 +----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/codec/types/any.go b/codec/types/any.go index 02dba0171557..5262fd92057c 100644 --- a/codec/types/any.go +++ b/codec/types/any.go @@ -68,6 +68,25 @@ func NewAnyWithValue(value proto.Message) (*Any, error) { return any, nil } +// NewAnyWithWithTypeURL constructs a new Any packed with the value provided +// and a custom TypeURL. It returns an error if that value couldn't be packed. +// This also cachesthe packed value so that it can be retrieved from +// GetCachedValue without unmarshaling. +// +// Ex: +// This will allow us to pack service methods in Any's using the full method name +// as the type URL and the request body as the value. +func NewAnyWithWithTypeURL(typeURL string, value proto.Message) (*Any, error) { + any := &Any{} + + err := any.PackWithCustomTypeURL(typeURL, value) + if err != nil { + return nil, err + } + + return any, nil +} + // PackWithCustomTypeURL packs the value x in the Any or returns an error, // allowing for a custom TypeUrl. This also caches the packed value so that it // can be retrieved fromGetCachedValue without unmarshaling. diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 79997afd5627..1a36da0b5fc9 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -208,14 +208,10 @@ func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { switch msg := msg.(type) { case sdk.ServiceMsg: { - bz, err := proto.Marshal(msg.Request) + anys[i], err = codectypes.NewAnyWithWithTypeURL(msg.MethodName, msg.Request) if err != nil { return err } - anys[i] = any & codectypes.Any{ - TypeUrl: msg.MethodName, - Value: bz, - } } default: { From 7b1e26abbcee4c9fa0af046948ec79335cac95f5 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 23 Oct 2020 14:16:58 +0200 Subject: [PATCH 06/18] Add todo comment for amino --- x/auth/legacy/legacytx/msg_service.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index 44f37655e98f..2593010e62c0 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -10,6 +10,7 @@ import ( ) // Invoke implements the grpc ClientConn.Invoke method. +// TODO Full amino support still needs to be added as part of https://github.com/cosmos/cosmos-sdk/issues/7541. func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) if !ok { From 12cba1e81c66a58eacfe70025fd49ea6f7407f18 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 23 Oct 2020 14:21:40 +0200 Subject: [PATCH 07/18] Add Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c60d7ed2b7f..8d9900580744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (codec) [\#7519](https://github.com/cosmos/cosmos-sdk/pull/7519) `InterfaceRegistry` now inherits `jsonpb.AnyResolver`, and has a `RegisterCustomTypeURL` method to support ADR 031 packing of `Any`s. `AnyResolver` is now a required parameter to `RejectUnknownFields`. * (baseapp) [\#7519](https://github.com/cosmos/cosmos-sdk/pull/7519) Add `ServiceMsgRouter` to BaseApp to handle routing of protobuf service `Msg`s. The two new types defined in ADR 031, `sdk.ServiceMsg` and `sdk.MsgRequest` are introduced with this router. +* (client) [\#7630](https://github.com/cosmos/cosmos-sdk/pull/7630) `TxBuilder` extends `grpc.ClientConn` to be able to create txs with ADR 031 service `Msg`s. ### Bug Fixes From 73af33393bf5f3279fa49d62760d306dbd601e1f Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 23 Oct 2020 14:24:00 +0200 Subject: [PATCH 08/18] Remove println --- types/tx/types.go | 1 - 1 file changed, 1 deletion(-) diff --git a/types/tx/types.go b/types/tx/types.go index 7252eaa4ef2e..e9066ef41b42 100644 --- a/types/tx/types.go +++ b/types/tx/types.go @@ -29,7 +29,6 @@ func (t *Tx) GetMsgs() []sdk.Msg { for i, any := range anys { var msg sdk.Msg if isServiceMsg(any.TypeUrl) { - fmt.Println("GetMsgs any=", any) msg = sdk.ServiceMsg{ MethodName: any.TypeUrl, Request: any.GetCachedValue().(sdk.MsgRequest), From 383b3e8d5f9761a34b113a60367bf2f3bbc63dd8 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 23 Oct 2020 14:41:04 +0200 Subject: [PATCH 09/18] Update codec/types/any.go Co-authored-by: Alessio Treglia --- codec/types/any.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/codec/types/any.go b/codec/types/any.go index 5262fd92057c..8c3cd0fa070f 100644 --- a/codec/types/any.go +++ b/codec/types/any.go @@ -79,8 +79,7 @@ func NewAnyWithValue(value proto.Message) (*Any, error) { func NewAnyWithWithTypeURL(typeURL string, value proto.Message) (*Any, error) { any := &Any{} - err := any.PackWithCustomTypeURL(typeURL, value) - if err != nil { + if err := any.PackWithCustomTypeURL(typeURL, value); err != nil { return nil, err } From 24cdb72cf720ce9c966a3e2e4ac3899879dd618e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 23 Oct 2020 15:58:14 +0200 Subject: [PATCH 10/18] Add AppendMsgs --- client/tx_config.go | 1 + codec/types/any.go | 4 ++-- x/auth/legacy/legacytx/msg_service.go | 2 +- x/auth/legacy/legacytx/stdtx_builder.go | 6 ++++++ x/auth/tx/builder.go | 14 +++++++++++--- x/auth/tx/msg_service.go | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/client/tx_config.go b/client/tx_config.go index 70cc4862a9c2..3163bf1a4476 100644 --- a/client/tx_config.go +++ b/client/tx_config.go @@ -39,6 +39,7 @@ type ( gogogrpc.ClientConn GetTx() signing.Tx + AppendMsgs(msg ...sdk.Msg) error SetMsgs(msgs ...sdk.Msg) error SetSignatures(signatures ...signingtypes.SignatureV2) error SetMemo(memo string) diff --git a/codec/types/any.go b/codec/types/any.go index 5262fd92057c..46a37f34dfe4 100644 --- a/codec/types/any.go +++ b/codec/types/any.go @@ -68,7 +68,7 @@ func NewAnyWithValue(value proto.Message) (*Any, error) { return any, nil } -// NewAnyWithWithTypeURL constructs a new Any packed with the value provided +// NewAnyWithTypeURL constructs a new Any packed with the value provided // and a custom TypeURL. It returns an error if that value couldn't be packed. // This also cachesthe packed value so that it can be retrieved from // GetCachedValue without unmarshaling. @@ -76,7 +76,7 @@ func NewAnyWithValue(value proto.Message) (*Any, error) { // Ex: // This will allow us to pack service methods in Any's using the full method name // as the type URL and the request body as the value. -func NewAnyWithWithTypeURL(typeURL string, value proto.Message) (*Any, error) { +func NewAnyWithTypeURL(typeURL string, value proto.Message) (*Any, error) { any := &Any{} err := any.PackWithCustomTypeURL(typeURL, value) diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index 2593010e62c0..8c8364d5c24b 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -17,7 +17,7 @@ func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply in return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) } - s.SetMsgs(sdk.ServiceMsg{ + s.AppendMsgs(sdk.ServiceMsg{ MethodName: method, Request: req, }) diff --git a/x/auth/legacy/legacytx/stdtx_builder.go b/x/auth/legacy/legacytx/stdtx_builder.go index 1b1a55c042e7..0f0fb4c1cb6d 100644 --- a/x/auth/legacy/legacytx/stdtx_builder.go +++ b/x/auth/legacy/legacytx/stdtx_builder.go @@ -27,6 +27,12 @@ func (s *StdTxBuilder) GetTx() authsigning.Tx { return s.StdTx } +// AppendMsgs implements TxBuilder.AppendMsgs +func (s *StdTxBuilder) AppendMsgs(msgs ...sdk.Msg) error { + s.Msgs = append(s.Msgs, msgs...) + return nil +} + // SetMsgs implements TxBuilder.SetMsgs func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error { s.Msgs = msgs diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 1a36da0b5fc9..374f1588cd39 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -200,7 +200,8 @@ func (w *wrapper) GetSignaturesV2() ([]signing.SignatureV2, error) { return res, nil } -func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { +// AppendMsgs implemented the TxBuilder.AppendMsgs method. +func (w *wrapper) AppendMsgs(msgs ...sdk.Msg) error { anys := make([]*codectypes.Any, len(msgs)) for i, msg := range msgs { @@ -208,7 +209,7 @@ func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { switch msg := msg.(type) { case sdk.ServiceMsg: { - anys[i], err = codectypes.NewAnyWithWithTypeURL(msg.MethodName, msg.Request) + anys[i], err = codectypes.NewAnyWithTypeURL(msg.MethodName, msg.Request) if err != nil { return err } @@ -224,7 +225,7 @@ func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { } - w.tx.Body.Messages = anys + w.tx.Body.Messages = append(w.tx.Body.Messages, anys...) // set bodyBz to nil because the cached bodyBz no longer matches tx.Body w.bodyBz = nil @@ -232,6 +233,13 @@ func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { return nil } +// AppendMsgs implemented the TxBuilder.SetMsgs method. +func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { + w.tx.Body.Messages = make([]*codectypes.Any, len(msgs)) + + return w.AppendMsgs(msgs...) +} + // SetTimeoutHeight sets the transaction's height timeout. func (w *wrapper) SetTimeoutHeight(height uint64) { w.tx.Body.TimeoutHeight = height diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index f7cba3ec6d08..33a2af27e44d 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -16,7 +16,7 @@ func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interfa return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) } - w.SetMsgs(sdk.ServiceMsg{ + w.AppendMsgs(sdk.ServiceMsg{ MethodName: method, Request: req, }) From 70c0ebf16fa69c09034f19da23ff424492ddebed Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 23 Oct 2020 16:13:09 +0200 Subject: [PATCH 11/18] Rename SetMsgs to AppendMsgs --- CHANGELOG.md | 2 +- baseapp/msg_service_router_test.go | 2 +- client/grpc/simulate/simulate_test.go | 2 +- client/tx/legacy.go | 2 +- client/tx/legacy_test.go | 2 +- client/tx/tx.go | 2 +- client/tx_config.go | 1 - simapp/helpers/test_helpers.go | 2 +- simapp/simd/cmd/testnet.go | 2 +- testutil/network/network.go | 2 +- x/auth/ante/ante_test.go | 6 +++--- x/auth/ante/basic_test.go | 8 ++++---- x/auth/ante/fee_test.go | 4 ++-- x/auth/ante/setup_test.go | 4 ++-- x/auth/ante/sigverify_test.go | 10 +++++----- x/auth/ante/testutil_test.go | 2 +- x/auth/client/cli/cli_test.go | 4 ++-- x/auth/client/rest/rest_test.go | 2 +- x/auth/legacy/legacytx/stdtx_builder.go | 6 ------ x/auth/testutil/suite.go | 8 ++++---- x/auth/tx/builder.go | 7 ------- x/auth/tx/builder_test.go | 10 +++++----- x/auth/tx/direct_test.go | 2 +- x/auth/tx/encode_decode_test.go | 2 +- x/auth/tx/legacy_amino_json_test.go | 2 +- x/genutil/gentx_test.go | 6 +++--- x/genutil/types/genesis_state_test.go | 4 ++-- x/gov/client/utils/query_test.go | 2 +- 28 files changed, 47 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d9900580744..039742552b16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/staking) [\#7499](https://github.com/cosmos/cosmos-sdk/pull/7499) `BondStatus` is now a protobuf `enum` instead of an `int32`, and JSON serialized using its protobuf name, so expect names like `BOND_STATUS_UNBONDING` as opposed to `Unbonding`. * (x/evidence) [\#7538](https://github.com/cosmos/cosmos-sdk/pull/7538) The ABCI's `Result.Data` field of `MsgSubmitEvidence` does not contain the raw evidence's hash, but the encoded `MsgSubmitEvidenceResponse` struct. +* (client) [\#7630](https://github.com/cosmos/cosmos-sdk/pull/7630) `TxBuilder`'s `SetMsgs` method has been converted to `AppendMsgs`. Moreover, `TxBuilder` extends `grpc.ClientConn` to be able to create txs with ADR 031 service `Msg`s. ### API Breaking @@ -54,7 +55,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (codec) [\#7519](https://github.com/cosmos/cosmos-sdk/pull/7519) `InterfaceRegistry` now inherits `jsonpb.AnyResolver`, and has a `RegisterCustomTypeURL` method to support ADR 031 packing of `Any`s. `AnyResolver` is now a required parameter to `RejectUnknownFields`. * (baseapp) [\#7519](https://github.com/cosmos/cosmos-sdk/pull/7519) Add `ServiceMsgRouter` to BaseApp to handle routing of protobuf service `Msg`s. The two new types defined in ADR 031, `sdk.ServiceMsg` and `sdk.MsgRequest` are introduced with this router. -* (client) [\#7630](https://github.com/cosmos/cosmos-sdk/pull/7630) `TxBuilder` extends `grpc.ClientConn` to be able to create txs with ADR 031 service `Msg`s. ### Bug Fixes diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index f0f9be57b43f..4a4648e58bbb 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -36,7 +36,7 @@ func TestMsgService(t *testing.T) { txBuilder := encCfg.TxConfig.NewTxBuilder() txBuilder.SetFeeAmount(testdata.NewTestFeeAmount()) txBuilder.SetGasLimit(testdata.NewTestGasLimit()) - err := txBuilder.SetMsgs(msg) + err := txBuilder.AppendMsgs(msg) require.NoError(t, err) // First round: we gather all the signer infos. We use the "set empty diff --git a/client/grpc/simulate/simulate_test.go b/client/grpc/simulate/simulate_test.go index 7e25c1123297..9d6b10791f24 100644 --- a/client/grpc/simulate/simulate_test.go +++ b/client/grpc/simulate/simulate_test.go @@ -77,7 +77,7 @@ func (s IntegrationTestSuite) TestSimulateService() { // Create a txBuilder. txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txBuilder.SetMsgs(msg) + txBuilder.AppendMsgs(msg) txBuilder.SetMemo(memo) txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) diff --git a/client/tx/legacy.go b/client/tx/legacy.go index 71f0fe8c4eeb..9eec189cde6b 100644 --- a/client/tx/legacy.go +++ b/client/tx/legacy.go @@ -36,7 +36,7 @@ func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (legacytx.StdTx, // CopyTx copies a Tx to a new TxBuilder, allowing conversion between // different transaction formats. func CopyTx(tx signing.Tx, builder client.TxBuilder) error { - err := builder.SetMsgs(tx.GetMsgs()...) + err := builder.AppendMsgs(tx.GetMsgs()...) if err != nil { return err } diff --git a/client/tx/legacy_test.go b/client/tx/legacy_test.go index 4884faa83c5e..d9872fb19660 100644 --- a/client/tx/legacy_test.go +++ b/client/tx/legacy_test.go @@ -43,7 +43,7 @@ func buildTestTx(t *testing.T, builder client.TxBuilder) { builder.SetMemo(memo) builder.SetGasLimit(gas) builder.SetFeeAmount(fee) - err := builder.SetMsgs(msg) + err := builder.AppendMsgs(msg) require.NoError(t, err) err = builder.SetSignatures(sig) require.NoError(t, err) diff --git a/client/tx/tx.go b/client/tx/tx.go index 43f2235b1b9b..242ae11411cf 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -234,7 +234,7 @@ func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (client.TxBuilder, error) { tx := txf.txConfig.NewTxBuilder() - if err := tx.SetMsgs(msgs...); err != nil { + if err := tx.AppendMsgs(msgs...); err != nil { return nil, err } diff --git a/client/tx_config.go b/client/tx_config.go index 3163bf1a4476..3bdb2145fc3e 100644 --- a/client/tx_config.go +++ b/client/tx_config.go @@ -40,7 +40,6 @@ type ( GetTx() signing.Tx AppendMsgs(msg ...sdk.Msg) error - SetMsgs(msgs ...sdk.Msg) error SetSignatures(signatures ...signingtypes.SignatureV2) error SetMemo(memo string) SetFeeAmount(amount sdk.Coins) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index 9e8a4d97143e..163f3fc9b320 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -43,7 +43,7 @@ func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, ch } tx := gen.NewTxBuilder() - err := tx.SetMsgs(msgs...) + err := tx.AppendMsgs(msgs...) if err != nil { return nil, err } diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index d17e57fb95f7..cdbf8badba52 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -217,7 +217,7 @@ func InitTestnet( } txBuilder := clientCtx.TxConfig.NewTxBuilder() - if err := txBuilder.SetMsgs(createValMsg); err != nil { + if err := txBuilder.AppendMsgs(createValMsg); err != nil { return err } diff --git a/testutil/network/network.go b/testutil/network/network.go index 1ab9006f8ea1..12f4b311a833 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -310,7 +310,7 @@ func New(t *testing.T, cfg Config) *Network { memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port()) fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(0))) txBuilder := cfg.TxConfig.NewTxBuilder() - require.NoError(t, txBuilder.SetMsgs(createValMsg)) + require.NoError(t, txBuilder.AppendMsgs(createValMsg)) txBuilder.SetFeeAmount(fee) // Arbitrary fee txBuilder.SetGasLimit(1000000) // Need at least 100386 txBuilder.SetMemo(memo) diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 0d9ef82f44be..acbbbc8fd323 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -103,7 +103,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSigErrors() { privs, accNums, accSeqs = []crypto.PrivKey{}, []uint64{}, []uint64{} // Create tx manually to test the tx's signers - suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID()) suite.Require().NoError(err) // tx.GetSigners returns addresses in correct order: addr1, addr2, addr3 @@ -837,7 +837,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() { privs, accNums, accSeqs = []crypto.PrivKey{accounts[1].priv}, []uint64{1}, []uint64{0} msgs = []sdk.Msg{testdata.NewTestMsg(accounts[1].acc.GetAddress())} - suite.txBuilder.SetMsgs(msgs...) + suite.txBuilder.AppendMsgs(msgs...) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -1062,7 +1062,7 @@ func (suite *AnteTestSuite) TestAnteHandlerReCheck() { msg := testdata.NewTestMsg(accounts[0].acc.GetAddress()) msgs := []sdk.Msg{msg} - suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) suite.txBuilder.SetMemo("thisisatestmemo") diff --git a/x/auth/ante/basic_test.go b/x/auth/ante/basic_test.go index 8b304d180e51..9db1b50f3a11 100644 --- a/x/auth/ante/basic_test.go +++ b/x/auth/ante/basic_test.go @@ -24,7 +24,7 @@ func (suite *AnteTestSuite) TestValidateBasic() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -65,7 +65,7 @@ func (suite *AnteTestSuite) TestValidateMemo() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -115,7 +115,7 @@ func (suite *AnteTestSuite) TestConsumeGasForTxSize() { for _, tc := range testCases { suite.Run(tc.name, func() { suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) suite.txBuilder.SetMemo(strings.Repeat("01234567890", 10)) @@ -207,7 +207,7 @@ func (suite *AnteTestSuite) TestTxHeightTimeoutDecorator() { suite.Run(tc.name, func() { suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) diff --git a/x/auth/ante/fee_test.go b/x/auth/ante/fee_test.go index 4264baf399bb..bf669b166ebf 100644 --- a/x/auth/ante/fee_test.go +++ b/x/auth/ante/fee_test.go @@ -23,7 +23,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -72,7 +72,7 @@ func (suite *AnteTestSuite) TestDeductFees() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) diff --git a/x/auth/ante/setup_test.go b/x/auth/ante/setup_test.go index 8454ec26a191..251f3b8410ef 100644 --- a/x/auth/ante/setup_test.go +++ b/x/auth/ante/setup_test.go @@ -21,7 +21,7 @@ func (suite *AnteTestSuite) TestSetup() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -56,7 +56,7 @@ func (suite *AnteTestSuite) TestRecoverPanic() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 2eb235b2f1be..1052b2604086 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -40,7 +40,7 @@ func (suite *AnteTestSuite) TestSetPubKey() { suite.app.AccountKeeper.SetAccount(suite.ctx, acc) msgs[i] = testdata.NewTestMsg(addr) } - suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() @@ -167,7 +167,7 @@ func (suite *AnteTestSuite) TestSigVerification() { suite.ctx = suite.ctx.WithIsReCheckTx(tc.recheck) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // Create new txBuilder for each test - suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -252,7 +252,7 @@ func (suite *AnteTestSuite) TestSigVerification_ExplicitAmino() { suite.ctx = suite.ctx.WithIsReCheckTx(tc.recheck) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // Create new txBuilder for each test - suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -309,7 +309,7 @@ func (suite *AnteTestSuite) runSigDecorators(params types.Params, _ bool, privs accNums[i] = uint64(i) accSeqs[i] = uint64(0) } - suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() @@ -342,7 +342,7 @@ func (suite *AnteTestSuite) TestIncrementSequenceDecorator() { suite.app.AccountKeeper.SetAccount(suite.ctx, acc) msgs := []sdk.Msg{testdata.NewTestMsg(addr)} - suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) privs := []crypto.PrivKey{priv} accNums := []uint64{suite.app.AccountKeeper.GetAccount(suite.ctx, addr).GetAccountNumber()} accSeqs := []uint64{suite.app.AccountKeeper.GetAccount(suite.ctx, addr).GetSequence()} diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index a6755d0c35af..2d3126b27b13 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -144,7 +144,7 @@ type TestCase struct { // CreateTestTx is a helper function to create a tx given multiple inputs. func (suite *AnteTestSuite) RunTestCase(privs []crypto.PrivKey, msgs []sdk.Msg, feeAmount sdk.Coins, gasLimit uint64, accNums, accSeqs []uint64, chainID string, tc TestCase) { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { - suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 72e53a97a4ee..d310ec9cf9df 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -784,7 +784,7 @@ func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) { require.NoError(t, err) to, err := sdk.AccAddressFromBech32("cosmos1cxlt8kznps92fwu3j6npahx4mjfutydyene2qw") require.NoError(t, err) - err = builder.SetMsgs(banktypes.NewMsgSend(from, to, sdk.Coins{sdk.NewInt64Coin("stake", 10000)})) + err = builder.AppendMsgs(banktypes.NewMsgSend(from, to, sdk.Coins{sdk.NewInt64Coin("stake", 10000)})) require.NoError(t, err) txContents, err := txCfg.TxJSONEncoder()(builder.GetTx()) txFileName := filepath.Join(testDir, "tx.json") @@ -847,7 +847,7 @@ func (s *IntegrationTestSuite) TestTxWithoutPublicKey() { msg := banktypes.NewMsgSend(val1.Address, val1.Address, sdk.NewCoins( sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)), )) - err := txBuilder.SetMsgs(msg) + err := txBuilder.AppendMsgs(msg) s.Require().NoError(err) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(150)))) txBuilder.SetGasLimit(testdata.NewTestGasLimit()) diff --git a/x/auth/client/rest/rest_test.go b/x/auth/client/rest/rest_test.go index 1c8d4924266c..9ec62ac81d93 100644 --- a/x/auth/client/rest/rest_test.go +++ b/x/auth/client/rest/rest_test.go @@ -193,7 +193,7 @@ func (s *IntegrationTestSuite) createTestStdTx(val *network.Validator, sequence txBuilder := txConfig.NewTxBuilder() feeAmount := sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)} gasLimit := testdata.NewTestGasLimit() - txBuilder.SetMsgs(msg) + txBuilder.AppendMsgs(msg) txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo("foobar") diff --git a/x/auth/legacy/legacytx/stdtx_builder.go b/x/auth/legacy/legacytx/stdtx_builder.go index 0f0fb4c1cb6d..6f27d0405051 100644 --- a/x/auth/legacy/legacytx/stdtx_builder.go +++ b/x/auth/legacy/legacytx/stdtx_builder.go @@ -33,12 +33,6 @@ func (s *StdTxBuilder) AppendMsgs(msgs ...sdk.Msg) error { return nil } -// SetMsgs implements TxBuilder.SetMsgs -func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error { - s.Msgs = msgs - return nil -} - // SetSignatures implements TxBuilder.SetSignatures. func (s *StdTxBuilder) SetSignatures(signatures ...signing.SignatureV2) error { sigs := make([]StdSignature, len(signatures)) diff --git a/x/auth/testutil/suite.go b/x/auth/testutil/suite.go index 518e502de1ca..16216f9c349d 100644 --- a/x/auth/testutil/suite.go +++ b/x/auth/testutil/suite.go @@ -69,7 +69,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetMsgs() { txBuilder := s.TxConfig.NewTxBuilder() - err := txBuilder.SetMsgs(msgs...) + err := txBuilder.AppendMsgs(msgs...) s.Require().NoError(err) tx := txBuilder.GetTx() s.Require().Equal(msgs, tx.GetMsgs()) @@ -89,7 +89,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { msg := testdata.NewTestMsg(addr) msigAddr := sdk.AccAddress(multisigPk.Address()) msg2 := testdata.NewTestMsg(msigAddr) - err := txBuilder.SetMsgs(msg, msg2) + err := txBuilder.AppendMsgs(msg, msg2) s.Require().NoError(err) // check that validation fails @@ -245,7 +245,7 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() { txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo(memo) - err := txBuilder.SetMsgs(msg) + err := txBuilder.AppendMsgs(msg) s.Require().NoError(err) err = txBuilder.SetSignatures(sig) s.Require().NoError(err) @@ -301,7 +301,7 @@ func (s *TxConfigTestSuite) TestWrapTxBuilder() { txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo(memo) - err := txBuilder.SetMsgs(msg) + err := txBuilder.AppendMsgs(msg) s.Require().NoError(err) newTxBldr, err := s.TxConfig.WrapTxBuilder(txBuilder.GetTx()) diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 374f1588cd39..49ff00d5c177 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -233,13 +233,6 @@ func (w *wrapper) AppendMsgs(msgs ...sdk.Msg) error { return nil } -// AppendMsgs implemented the TxBuilder.SetMsgs method. -func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { - w.tx.Body.Messages = make([]*codectypes.Any, len(msgs)) - - return w.AppendMsgs(msgs...) -} - // SetTimeoutHeight sets the transaction's height timeout. func (w *wrapper) SetTimeoutHeight(height uint64) { w.tx.Body.TimeoutHeight = height diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 21e097ddf7f8..97a37547461f 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -84,7 +84,7 @@ func TestTxBuilder(t *testing.T) { t.Log("verify that calling the SetMsgs, SetMemo results in the correct getBodyBytes") require.NotEqual(t, bodyBytes, txBuilder.getBodyBytes()) - err = txBuilder.SetMsgs(msgs...) + err = txBuilder.AppendMsgs(msgs...) require.NoError(t, err) require.NotEqual(t, bodyBytes, txBuilder.getBodyBytes()) txBuilder.SetMemo(memo) @@ -155,7 +155,7 @@ func TestBuilderValidateBasic(t *testing.T) { Sequence: 0, // Arbitrary account sequence } - err := txBuilder.SetMsgs(msgs...) + err := txBuilder.AppendMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) err = txBuilder.SetSignatures(sig1, sig2) @@ -176,7 +176,7 @@ func TestBuilderValidateBasic(t *testing.T) { require.Equal(t, sdkerrors.ErrNoSignatures.ABCICode(), code) // require to fail with nil values for tx, authinfo - err = txBuilder.SetMsgs(msgs...) + err = txBuilder.AppendMsgs(msgs...) require.NoError(t, err) err = txBuilder.ValidateBasic() require.Error(t, err) @@ -276,7 +276,7 @@ func TestBuilderFeePayer(t *testing.T) { t.Run(name, func(t *testing.T) { // setup basic tx txBuilder := newBuilder() - err := txBuilder.SetMsgs(msgs...) + err := txBuilder.AppendMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) txBuilder.SetFeeAmount(feeAmount) @@ -300,7 +300,7 @@ func TestBuilderFeeGranter(t *testing.T) { msgs := []sdk.Msg{msg1} txBuilder := newBuilder() - err := txBuilder.SetMsgs(msgs...) + err := txBuilder.AppendMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) txBuilder.SetFeeAmount(feeAmount) diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 286b5c15e2ef..7142636f0d50 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -55,7 +55,7 @@ func TestDirectModeHandler(t *testing.T) { fee := txtypes.Fee{Amount: sdk.NewCoins(sdk.NewInt64Coin("atom", 150)), GasLimit: 20000} - err = txBuilder.SetMsgs(msgs...) + err = txBuilder.AppendMsgs(msgs...) require.NoError(t, err) txBuilder.SetMemo(memo) txBuilder.SetFeeAmount(fee.Amount) diff --git a/x/auth/tx/encode_decode_test.go b/x/auth/tx/encode_decode_test.go index 55fff38c366f..5baecfbe561f 100644 --- a/x/auth/tx/encode_decode_test.go +++ b/x/auth/tx/encode_decode_test.go @@ -24,7 +24,7 @@ func TestDefaultTxDecoderError(t *testing.T) { decoder := DefaultTxDecoder(cdc) builder := newBuilder() - err := builder.SetMsgs(testdata.NewTestMsg()) + err := builder.AppendMsgs(testdata.NewTestMsg()) require.NoError(t, err) txBz, err := encoder(builder.GetTx()) diff --git a/x/auth/tx/legacy_amino_json_test.go b/x/auth/tx/legacy_amino_json_test.go index 3db335286901..3c926117d1a0 100644 --- a/x/auth/tx/legacy_amino_json_test.go +++ b/x/auth/tx/legacy_amino_json_test.go @@ -29,7 +29,7 @@ func buildTx(t *testing.T, bldr *wrapper) { bldr.SetGasLimit(gas) bldr.SetMemo(memo) bldr.SetTimeoutHeight(timeout) - require.NoError(t, bldr.SetMsgs(msg)) + require.NoError(t, bldr.AppendMsgs(msg)) } func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 671431ed9e56..616f737cba48 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -90,7 +90,7 @@ func (suite *GenTxTestSuite) TestSetGenTxsInAppGenesisState() { { "one genesis transaction", func() { - err := txBuilder.SetMsgs(suite.msg1) + err := txBuilder.AppendMsgs(suite.msg1) suite.Require().NoError(err) tx := txBuilder.GetTx() genTxs = []sdk.Tx{tx} @@ -100,7 +100,7 @@ func (suite *GenTxTestSuite) TestSetGenTxsInAppGenesisState() { { "two genesis transactions", func() { - err := txBuilder.SetMsgs(suite.msg1, suite.msg2) + err := txBuilder.AppendMsgs(suite.msg1, suite.msg2) suite.Require().NoError(err) tx := txBuilder.GetTx() genTxs = []sdk.Tx{tx} @@ -218,7 +218,7 @@ func (suite *GenTxTestSuite) TestDeliverGenTxs() { { "no signature supplied", func() { - err := txBuilder.SetMsgs(suite.msg1) + err := txBuilder.AppendMsgs(suite.msg1) suite.Require().NoError(err) genTxs = make([]json.RawMessage, 1) diff --git a/x/genutil/types/genesis_state_test.go b/x/genutil/types/genesis_state_test.go index ce0015420d0d..ffd19ebc0689 100644 --- a/x/genutil/types/genesis_state_test.go +++ b/x/genutil/types/genesis_state_test.go @@ -47,7 +47,7 @@ func TestValidateGenesisMultipleMessages(t *testing.T) { txGen := simapp.MakeEncodingConfig().TxConfig txBuilder := txGen.NewTxBuilder() - require.NoError(t, txBuilder.SetMsgs(msg1, msg2)) + require.NoError(t, txBuilder.AppendMsgs(msg1, msg2)) tx := txBuilder.GetTx() genesisState := types.NewGenesisStateFromTx(txGen.TxJSONEncoder(), []sdk.Tx{tx}) @@ -63,7 +63,7 @@ func TestValidateGenesisBadMessage(t *testing.T) { txGen := simapp.MakeEncodingConfig().TxConfig txBuilder := txGen.NewTxBuilder() - err := txBuilder.SetMsgs(msg1) + err := txBuilder.AppendMsgs(msg1) require.NoError(t, err) tx := txBuilder.GetTx() diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index c6f999e86ee6..b7460ed75ef7 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -156,7 +156,7 @@ func TestGetPaginatedVotes(t *testing.T) { for i := range tc.msgs { txBuilder := clientCtx.TxConfig.NewTxBuilder() - err := txBuilder.SetMsgs(tc.msgs[i]...) + err := txBuilder.AppendMsgs(tc.msgs[i]...) require.NoError(t, err) tx, err := clientCtx.TxConfig.TxEncoder()(txBuilder.GetTx()) From 92679a44fa80198c8f0ba2b3d6a34d7e13985850 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 26 Oct 2020 10:38:20 +0100 Subject: [PATCH 12/18] Address review comments --- codec/types/any.go | 10 +++------- x/auth/legacy/legacytx/msg_service.go | 3 ++- x/auth/tx/msg_service.go | 3 ++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/codec/types/any.go b/codec/types/any.go index 832896a37d40..3c87b03c982a 100644 --- a/codec/types/any.go +++ b/codec/types/any.go @@ -79,17 +79,13 @@ func NewAnyWithValue(value proto.Message) (*Any, error) { func NewAnyWithTypeURL(typeURL string, value proto.Message) (*Any, error) { any := &Any{} - if err := any.PackWithCustomTypeURL(typeURL, value); err != nil { - return nil, err - } - - return any, nil + return any, any.packWithCustomTypeURL(typeURL, value) } // PackWithCustomTypeURL packs the value x in the Any or returns an error, // allowing for a custom TypeUrl. This also caches the packed value so that it // can be retrieved fromGetCachedValue without unmarshaling. -func (any *Any) PackWithCustomTypeURL(typeURL string, x proto.Message) error { +func (any *Any) packWithCustomTypeURL(typeURL string, x proto.Message) error { any.TypeUrl = typeURL bz, err := proto.Marshal(x) if err != nil { @@ -106,7 +102,7 @@ func (any *Any) PackWithCustomTypeURL(typeURL string, x proto.Message) error { // the packed value so that it can be retrieved from GetCachedValue without // unmarshaling func (any *Any) Pack(x proto.Message) error { - return any.PackWithCustomTypeURL("/"+proto.MessageName(x), x) + return any.packWithCustomTypeURL("/"+proto.MessageName(x), x) } // UnsafePackAny packs the value x in the Any and instead of returning the error diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index 8c8364d5c24b..4df8c335d0f0 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -7,6 +7,7 @@ import ( "google.golang.org/grpc" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // Invoke implements the grpc ClientConn.Invoke method. @@ -14,7 +15,7 @@ import ( func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) if !ok { - return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%T should implement %T", args, (*sdk.MsgRequest)(nil)) } s.AppendMsgs(sdk.ServiceMsg{ diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index 33a2af27e44d..9e0ca8a241f5 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -7,13 +7,14 @@ import ( "google.golang.org/grpc" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // Invoke implements the grpc ClientConn.Invoke method. func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) if !ok { - return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%T should implement %T", args, (*sdk.MsgRequest)(nil)) } w.AppendMsgs(sdk.ServiceMsg{ From 4e2f3a5898829643ab28ff3aaeaf03032f74402e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 26 Oct 2020 14:12:26 +0100 Subject: [PATCH 13/18] Add comment --- x/auth/legacy/legacytx/msg_service.go | 3 ++- x/auth/tx/msg_service.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index 4df8c335d0f0..c3071d6ec075 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -10,7 +10,8 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// Invoke implements the grpc ClientConn.Invoke method. +// Invoke implements the grpc ClientConn.Invoke method. This is to that we can +// use ADR-031 service `Msg`s with StdTxBuilder. // TODO Full amino support still needs to be added as part of https://github.com/cosmos/cosmos-sdk/issues/7541. func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index 9e0ca8a241f5..0250da573eff 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -10,7 +10,8 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// Invoke implements the grpc ClientConn.Invoke method. +// Invoke implements the grpc ClientConn.Invoke method. This is to that we can +// use ADR-031 service `Msg`s with wrapper. func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) if !ok { From dc1613b8876229aaa01304c30798623da406034b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 26 Oct 2020 14:18:14 +0100 Subject: [PATCH 14/18] Typo --- x/auth/legacy/legacytx/msg_service.go | 2 +- x/auth/tx/msg_service.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index c3071d6ec075..3a8f48593fb3 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -10,7 +10,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// Invoke implements the grpc ClientConn.Invoke method. This is to that we can +// Invoke implements the grpc ClientConn.Invoke method. This is so that we can // use ADR-031 service `Msg`s with StdTxBuilder. // TODO Full amino support still needs to be added as part of https://github.com/cosmos/cosmos-sdk/issues/7541. func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index 0250da573eff..d41a20637e61 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -10,7 +10,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// Invoke implements the grpc ClientConn.Invoke method. This is to that we can +// Invoke implements the grpc ClientConn.Invoke method. This is so that we can // use ADR-031 service `Msg`s with wrapper. func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) From 173b75d4333f47e37c58498c13a498eb49e06c8b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 11 Dec 2020 11:57:35 +0100 Subject: [PATCH 15/18] Use SetMsgs --- baseapp/msg_service_router_test.go | 2 +- client/tx/legacy.go | 2 +- client/tx/legacy_test.go | 2 +- client/tx/tx.go | 2 +- client/tx_config.go | 2 +- simapp/helpers/test_helpers.go | 2 +- simapp/simd/cmd/testnet.go | 2 +- testutil/network/network.go | 2 +- x/auth/ante/ante_test.go | 6 +++--- x/auth/ante/basic_test.go | 8 ++++---- x/auth/ante/fee_test.go | 4 ++-- x/auth/ante/setup_test.go | 4 ++-- x/auth/ante/sigverify_test.go | 8 ++++---- x/auth/ante/testutil_test.go | 2 +- x/auth/client/cli/cli_test.go | 4 ++-- x/auth/client/rest/rest_test.go | 2 +- x/auth/legacy/legacytx/msg_service.go | 2 +- x/auth/testutil/suite.go | 8 ++++---- x/auth/tx/builder.go | 4 ++-- x/auth/tx/builder_test.go | 10 +++++----- x/auth/tx/direct_test.go | 2 +- x/auth/tx/encode_decode_test.go | 2 +- x/auth/tx/legacy_amino_json_test.go | 2 +- x/auth/tx/msg_service.go | 2 +- x/genutil/gentx_test.go | 6 +++--- x/genutil/types/genesis_state_test.go | 4 ++-- x/gov/client/utils/query_test.go | 2 +- 27 files changed, 49 insertions(+), 49 deletions(-) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 500249a461f8..34f9c080277e 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -84,7 +84,7 @@ func TestMsgService(t *testing.T) { txBuilder := encCfg.TxConfig.NewTxBuilder() txBuilder.SetFeeAmount(testdata.NewTestFeeAmount()) txBuilder.SetGasLimit(testdata.NewTestGasLimit()) - err := txBuilder.AppendMsgs(msg) + err := txBuilder.SetMsgs(msg) require.NoError(t, err) // First round: we gather all the signer infos. We use the "set empty diff --git a/client/tx/legacy.go b/client/tx/legacy.go index 4d741085252c..b551ecebb81c 100644 --- a/client/tx/legacy.go +++ b/client/tx/legacy.go @@ -37,7 +37,7 @@ func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (legacytx.StdTx, // different transaction formats. If ignoreSignatureError is true, copying will continue // tx even if the signature cannot be set in the target builder resulting in an unsigned tx. func CopyTx(tx signing.Tx, builder client.TxBuilder, ignoreSignatureError bool) error { - err := builder.AppendMsgs(tx.GetMsgs()...) + err := builder.SetMsgs(tx.GetMsgs()...) if err != nil { return err } diff --git a/client/tx/legacy_test.go b/client/tx/legacy_test.go index 6e51b6e57bfa..b10c51e34402 100644 --- a/client/tx/legacy_test.go +++ b/client/tx/legacy_test.go @@ -44,7 +44,7 @@ func buildTestTx(t *testing.T, builder client.TxBuilder) { builder.SetMemo(memo) builder.SetGasLimit(gas) builder.SetFeeAmount(fee) - err := builder.AppendMsgs(msg) + err := builder.SetMsgs(msg) require.NoError(t, err) err = builder.SetSignatures(sig) require.NoError(t, err) diff --git a/client/tx/tx.go b/client/tx/tx.go index d4154026087b..980c253a80e0 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -233,7 +233,7 @@ func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (client.TxBuilder, error) { tx := txf.txConfig.NewTxBuilder() - if err := tx.AppendMsgs(msgs...); err != nil { + if err := tx.SetMsgs(msgs...); err != nil { return nil, err } diff --git a/client/tx_config.go b/client/tx_config.go index 3bdb2145fc3e..a1477c29b1e1 100644 --- a/client/tx_config.go +++ b/client/tx_config.go @@ -39,7 +39,7 @@ type ( gogogrpc.ClientConn GetTx() signing.Tx - AppendMsgs(msg ...sdk.Msg) error + SetMsgs(msg ...sdk.Msg) error SetSignatures(signatures ...signingtypes.SignatureV2) error SetMemo(memo string) SetFeeAmount(amount sdk.Coins) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index 1d5164a809b3..9ccecbd976c4 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -42,7 +42,7 @@ func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, ch } tx := gen.NewTxBuilder() - err := tx.AppendMsgs(msgs...) + err := tx.SetMsgs(msgs...) if err != nil { return nil, err } diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 229314a3d6c4..3355c04b4e71 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -217,7 +217,7 @@ func InitTestnet( } txBuilder := clientCtx.TxConfig.NewTxBuilder() - if err := txBuilder.AppendMsgs(createValMsg); err != nil { + if err := txBuilder.SetMsgs(createValMsg); err != nil { return err } diff --git a/testutil/network/network.go b/testutil/network/network.go index 47bcb020b600..a50c6fa935af 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -311,7 +311,7 @@ func New(t *testing.T, cfg Config) *Network { memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port()) fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(0))) txBuilder := cfg.TxConfig.NewTxBuilder() - require.NoError(t, txBuilder.AppendMsgs(createValMsg)) + require.NoError(t, txBuilder.SetMsgs(createValMsg)) txBuilder.SetFeeAmount(fee) // Arbitrary fee txBuilder.SetGasLimit(1000000) // Need at least 100386 txBuilder.SetMemo(memo) diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 8564cd9628e8..7659f3e1043d 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -103,7 +103,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSigErrors() { privs, accNums, accSeqs = []cryptotypes.PrivKey{}, []uint64{}, []uint64{} // Create tx manually to test the tx's signers - suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID()) suite.Require().NoError(err) // tx.GetSigners returns addresses in correct order: addr1, addr2, addr3 @@ -837,7 +837,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() { privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[1].priv}, []uint64{1}, []uint64{0} msgs = []sdk.Msg{testdata.NewTestMsg(accounts[1].acc.GetAddress())} - suite.txBuilder.AppendMsgs(msgs...) + suite.txBuilder.SetMsgs(msgs...) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -1062,7 +1062,7 @@ func (suite *AnteTestSuite) TestAnteHandlerReCheck() { msg := testdata.NewTestMsg(accounts[0].acc.GetAddress()) msgs := []sdk.Msg{msg} - suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) suite.txBuilder.SetMemo("thisisatestmemo") diff --git a/x/auth/ante/basic_test.go b/x/auth/ante/basic_test.go index f15b582e4a2e..08567348857e 100644 --- a/x/auth/ante/basic_test.go +++ b/x/auth/ante/basic_test.go @@ -22,7 +22,7 @@ func (suite *AnteTestSuite) TestValidateBasic() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -63,7 +63,7 @@ func (suite *AnteTestSuite) TestValidateMemo() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -113,7 +113,7 @@ func (suite *AnteTestSuite) TestConsumeGasForTxSize() { for _, tc := range testCases { suite.Run(tc.name, func() { suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() - suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) suite.txBuilder.SetMemo(strings.Repeat("01234567890", 10)) @@ -205,7 +205,7 @@ func (suite *AnteTestSuite) TestTxHeightTimeoutDecorator() { suite.Run(tc.name, func() { suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() - suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) diff --git a/x/auth/ante/fee_test.go b/x/auth/ante/fee_test.go index 98f82c99ce18..84e5adb60db7 100644 --- a/x/auth/ante/fee_test.go +++ b/x/auth/ante/fee_test.go @@ -22,7 +22,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -71,7 +71,7 @@ func (suite *AnteTestSuite) TestDeductFees() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) diff --git a/x/auth/ante/setup_test.go b/x/auth/ante/setup_test.go index c58293de7a02..4942665cac04 100644 --- a/x/auth/ante/setup_test.go +++ b/x/auth/ante/setup_test.go @@ -19,7 +19,7 @@ func (suite *AnteTestSuite) TestSetup() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -54,7 +54,7 @@ func (suite *AnteTestSuite) TestRecoverPanic() { msg := testdata.NewTestMsg(addr1) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.AppendMsgs(msg)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index ad58043ad0fe..337618fab50f 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -39,7 +39,7 @@ func (suite *AnteTestSuite) TestSetPubKey() { suite.app.AccountKeeper.SetAccount(suite.ctx, acc) msgs[i] = testdata.NewTestMsg(addr) } - suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() @@ -166,7 +166,7 @@ func (suite *AnteTestSuite) TestSigVerification() { suite.ctx = suite.ctx.WithIsReCheckTx(tc.recheck) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // Create new txBuilder for each test - suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -251,7 +251,7 @@ func (suite *AnteTestSuite) TestSigVerification_ExplicitAmino() { suite.ctx = suite.ctx.WithIsReCheckTx(tc.recheck) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // Create new txBuilder for each test - suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -308,7 +308,7 @@ func (suite *AnteTestSuite) runSigDecorators(params types.Params, _ bool, privs accNums[i] = uint64(i) accSeqs[i] = uint64(0) } - suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) feeAmount := testdata.NewTestFeeAmount() gasLimit := testdata.NewTestGasLimit() diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index be5eed544b29..5a1cfc4ec44c 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -144,7 +144,7 @@ type TestCase struct { // CreateTestTx is a helper function to create a tx given multiple inputs. func (suite *AnteTestSuite) RunTestCase(privs []cryptotypes.PrivKey, msgs []sdk.Msg, feeAmount sdk.Coins, gasLimit uint64, accNums, accSeqs []uint64, chainID string, tc TestCase) { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { - suite.Require().NoError(suite.txBuilder.AppendMsgs(msgs...)) + suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 94865bfab062..b935d6641258 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -848,7 +848,7 @@ func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) { require.NoError(t, err) to, err := sdk.AccAddressFromBech32("cosmos1cxlt8kznps92fwu3j6npahx4mjfutydyene2qw") require.NoError(t, err) - err = builder.AppendMsgs(banktypes.NewMsgSend(from, to, sdk.Coins{sdk.NewInt64Coin("stake", 10000)})) + err = builder.SetMsgs(banktypes.NewMsgSend(from, to, sdk.Coins{sdk.NewInt64Coin("stake", 10000)})) require.NoError(t, err) txContents, err := txCfg.TxJSONEncoder()(builder.GetTx()) txFileName := filepath.Join(testDir, "tx.json") @@ -911,7 +911,7 @@ func (s *IntegrationTestSuite) TestTxWithoutPublicKey() { msg := banktypes.NewMsgSend(val1.Address, val1.Address, sdk.NewCoins( sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)), )) - err := txBuilder.AppendMsgs(msg) + err := txBuilder.SetMsgs(msg) s.Require().NoError(err) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(150)))) txBuilder.SetGasLimit(testdata.NewTestGasLimit()) diff --git a/x/auth/client/rest/rest_test.go b/x/auth/client/rest/rest_test.go index 8ea6990e20b5..cc1a5d1cdeb6 100644 --- a/x/auth/client/rest/rest_test.go +++ b/x/auth/client/rest/rest_test.go @@ -364,7 +364,7 @@ func (s *IntegrationTestSuite) createTestStdTx(val *network.Validator, accNum, s txBuilder := txConfig.NewTxBuilder() feeAmount := sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)} gasLimit := testdata.NewTestGasLimit() - txBuilder.AppendMsgs(msg) + txBuilder.SetMsgs(msg) txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo("foobar") diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index 3a8f48593fb3..620d114b68f0 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -19,7 +19,7 @@ func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply in return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%T should implement %T", args, (*sdk.MsgRequest)(nil)) } - s.AppendMsgs(sdk.ServiceMsg{ + s.SetMsgs(sdk.ServiceMsg{ MethodName: method, Request: req, }) diff --git a/x/auth/testutil/suite.go b/x/auth/testutil/suite.go index 5689283593db..f8002e68e4e6 100644 --- a/x/auth/testutil/suite.go +++ b/x/auth/testutil/suite.go @@ -69,7 +69,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetMsgs() { txBuilder := s.TxConfig.NewTxBuilder() - err := txBuilder.AppendMsgs(msgs...) + err := txBuilder.SetMsgs(msgs...) s.Require().NoError(err) tx := txBuilder.GetTx() s.Require().Equal(msgs, tx.GetMsgs()) @@ -89,7 +89,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { msg := testdata.NewTestMsg(addr) msigAddr := sdk.AccAddress(multisigPk.Address()) msg2 := testdata.NewTestMsg(msigAddr) - err := txBuilder.AppendMsgs(msg, msg2) + err := txBuilder.SetMsgs(msg, msg2) s.Require().NoError(err) // check that validation fails @@ -245,7 +245,7 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() { txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo(memo) - err := txBuilder.AppendMsgs(msg) + err := txBuilder.SetMsgs(msg) s.Require().NoError(err) err = txBuilder.SetSignatures(sig) s.Require().NoError(err) @@ -301,7 +301,7 @@ func (s *TxConfigTestSuite) TestWrapTxBuilder() { txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo(memo) - err := txBuilder.AppendMsgs(msg) + err := txBuilder.SetMsgs(msg) s.Require().NoError(err) newTxBldr, err := s.TxConfig.WrapTxBuilder(txBuilder.GetTx()) diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index f268b89a42f2..c4366e4a2fbe 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -197,8 +197,8 @@ func (w *wrapper) GetSignaturesV2() ([]signing.SignatureV2, error) { return res, nil } -// AppendMsgs implemented the TxBuilder.AppendMsgs method. -func (w *wrapper) AppendMsgs(msgs ...sdk.Msg) error { +// SetMsgs implemented the TxBuilder.SetMsgs method. +func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { anys := make([]*codectypes.Any, len(msgs)) for i, msg := range msgs { diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 97a37547461f..21e097ddf7f8 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -84,7 +84,7 @@ func TestTxBuilder(t *testing.T) { t.Log("verify that calling the SetMsgs, SetMemo results in the correct getBodyBytes") require.NotEqual(t, bodyBytes, txBuilder.getBodyBytes()) - err = txBuilder.AppendMsgs(msgs...) + err = txBuilder.SetMsgs(msgs...) require.NoError(t, err) require.NotEqual(t, bodyBytes, txBuilder.getBodyBytes()) txBuilder.SetMemo(memo) @@ -155,7 +155,7 @@ func TestBuilderValidateBasic(t *testing.T) { Sequence: 0, // Arbitrary account sequence } - err := txBuilder.AppendMsgs(msgs...) + err := txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) err = txBuilder.SetSignatures(sig1, sig2) @@ -176,7 +176,7 @@ func TestBuilderValidateBasic(t *testing.T) { require.Equal(t, sdkerrors.ErrNoSignatures.ABCICode(), code) // require to fail with nil values for tx, authinfo - err = txBuilder.AppendMsgs(msgs...) + err = txBuilder.SetMsgs(msgs...) require.NoError(t, err) err = txBuilder.ValidateBasic() require.Error(t, err) @@ -276,7 +276,7 @@ func TestBuilderFeePayer(t *testing.T) { t.Run(name, func(t *testing.T) { // setup basic tx txBuilder := newBuilder() - err := txBuilder.AppendMsgs(msgs...) + err := txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) txBuilder.SetFeeAmount(feeAmount) @@ -300,7 +300,7 @@ func TestBuilderFeeGranter(t *testing.T) { msgs := []sdk.Msg{msg1} txBuilder := newBuilder() - err := txBuilder.AppendMsgs(msgs...) + err := txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetGasLimit(200000) txBuilder.SetFeeAmount(feeAmount) diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 7142636f0d50..286b5c15e2ef 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -55,7 +55,7 @@ func TestDirectModeHandler(t *testing.T) { fee := txtypes.Fee{Amount: sdk.NewCoins(sdk.NewInt64Coin("atom", 150)), GasLimit: 20000} - err = txBuilder.AppendMsgs(msgs...) + err = txBuilder.SetMsgs(msgs...) require.NoError(t, err) txBuilder.SetMemo(memo) txBuilder.SetFeeAmount(fee.Amount) diff --git a/x/auth/tx/encode_decode_test.go b/x/auth/tx/encode_decode_test.go index 5baecfbe561f..55fff38c366f 100644 --- a/x/auth/tx/encode_decode_test.go +++ b/x/auth/tx/encode_decode_test.go @@ -24,7 +24,7 @@ func TestDefaultTxDecoderError(t *testing.T) { decoder := DefaultTxDecoder(cdc) builder := newBuilder() - err := builder.AppendMsgs(testdata.NewTestMsg()) + err := builder.SetMsgs(testdata.NewTestMsg()) require.NoError(t, err) txBz, err := encoder(builder.GetTx()) diff --git a/x/auth/tx/legacy_amino_json_test.go b/x/auth/tx/legacy_amino_json_test.go index 3c926117d1a0..3db335286901 100644 --- a/x/auth/tx/legacy_amino_json_test.go +++ b/x/auth/tx/legacy_amino_json_test.go @@ -29,7 +29,7 @@ func buildTx(t *testing.T, bldr *wrapper) { bldr.SetGasLimit(gas) bldr.SetMemo(memo) bldr.SetTimeoutHeight(timeout) - require.NoError(t, bldr.AppendMsgs(msg)) + require.NoError(t, bldr.SetMsgs(msg)) } func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) { diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index d41a20637e61..42c51e235043 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -18,7 +18,7 @@ func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interfa return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%T should implement %T", args, (*sdk.MsgRequest)(nil)) } - w.AppendMsgs(sdk.ServiceMsg{ + w.SetMsgs(sdk.ServiceMsg{ MethodName: method, Request: req, }) diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 1a62f4e964ca..b4b843bc986e 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -90,7 +90,7 @@ func (suite *GenTxTestSuite) TestSetGenTxsInAppGenesisState() { { "one genesis transaction", func() { - err := txBuilder.AppendMsgs(suite.msg1) + err := txBuilder.SetMsgs(suite.msg1) suite.Require().NoError(err) tx := txBuilder.GetTx() genTxs = []sdk.Tx{tx} @@ -100,7 +100,7 @@ func (suite *GenTxTestSuite) TestSetGenTxsInAppGenesisState() { { "two genesis transactions", func() { - err := txBuilder.AppendMsgs(suite.msg1, suite.msg2) + err := txBuilder.SetMsgs(suite.msg1, suite.msg2) suite.Require().NoError(err) tx := txBuilder.GetTx() genTxs = []sdk.Tx{tx} @@ -218,7 +218,7 @@ func (suite *GenTxTestSuite) TestDeliverGenTxs() { { "no signature supplied", func() { - err := txBuilder.AppendMsgs(suite.msg1) + err := txBuilder.SetMsgs(suite.msg1) suite.Require().NoError(err) genTxs = make([]json.RawMessage, 1) diff --git a/x/genutil/types/genesis_state_test.go b/x/genutil/types/genesis_state_test.go index 2c84a53002ff..01e1db9fd330 100644 --- a/x/genutil/types/genesis_state_test.go +++ b/x/genutil/types/genesis_state_test.go @@ -47,7 +47,7 @@ func TestValidateGenesisMultipleMessages(t *testing.T) { txGen := simapp.MakeTestEncodingConfig().TxConfig txBuilder := txGen.NewTxBuilder() - require.NoError(t, txBuilder.AppendMsgs(msg1, msg2)) + require.NoError(t, txBuilder.SetMsgs(msg1, msg2)) tx := txBuilder.GetTx() genesisState := types.NewGenesisStateFromTx(txGen.TxJSONEncoder(), []sdk.Tx{tx}) @@ -63,7 +63,7 @@ func TestValidateGenesisBadMessage(t *testing.T) { txGen := simapp.MakeTestEncodingConfig().TxConfig txBuilder := txGen.NewTxBuilder() - err := txBuilder.AppendMsgs(msg1) + err := txBuilder.SetMsgs(msg1) require.NoError(t, err) tx := txBuilder.GetTx() diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index a7a6cd84dd9b..81b15a457fb1 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -156,7 +156,7 @@ func TestGetPaginatedVotes(t *testing.T) { for i := range tc.msgs { txBuilder := clientCtx.TxConfig.NewTxBuilder() - err := txBuilder.AppendMsgs(tc.msgs[i]...) + err := txBuilder.SetMsgs(tc.msgs[i]...) require.NoError(t, err) tx, err := clientCtx.TxConfig.TxEncoder()(txBuilder.GetTx()) From 7b9da51c7159686e9fb8f0e25005d1d7762ea88c Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 11 Dec 2020 12:06:21 +0100 Subject: [PATCH 16/18] remove AppendMsg --- client/tx_config.go | 2 +- x/auth/legacy/legacytx/msg_service.go | 3 +- x/auth/tx/builder.go | 2 +- x/auth/tx/msg_service.go | 3 +- x/bank/client/cli/cli_test.go | 46 --------------------------- 5 files changed, 6 insertions(+), 50 deletions(-) diff --git a/client/tx_config.go b/client/tx_config.go index a1477c29b1e1..70cc4862a9c2 100644 --- a/client/tx_config.go +++ b/client/tx_config.go @@ -39,7 +39,7 @@ type ( gogogrpc.ClientConn GetTx() signing.Tx - SetMsgs(msg ...sdk.Msg) error + SetMsgs(msgs ...sdk.Msg) error SetSignatures(signatures ...signingtypes.SignatureV2) error SetMemo(memo string) SetFeeAmount(amount sdk.Coins) diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index 620d114b68f0..1182360084f4 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -19,10 +19,11 @@ func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply in return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%T should implement %T", args, (*sdk.MsgRequest)(nil)) } - s.SetMsgs(sdk.ServiceMsg{ + msgs := append(s.Msgs, sdk.ServiceMsg{ MethodName: method, Request: req, }) + s.SetMsgs(msgs...) return nil } diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index c4366e4a2fbe..e4c96c5989f0 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -222,7 +222,7 @@ func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error { } - w.tx.Body.Messages = append(w.tx.Body.Messages, anys...) + w.tx.Body.Messages = anys // set bodyBz to nil because the cached bodyBz no longer matches tx.Body w.bodyBz = nil diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index 42c51e235043..7e3385b6c60c 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -18,10 +18,11 @@ func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interfa return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%T should implement %T", args, (*sdk.MsgRequest)(nil)) } - w.SetMsgs(sdk.ServiceMsg{ + msgs := append(w.GetMsgs(), sdk.ServiceMsg{ MethodName: method, Request: req, }) + w.SetMsgs(msgs...) return nil } diff --git a/x/bank/client/cli/cli_test.go b/x/bank/client/cli/cli_test.go index 1af79a46fc81..9b8c5cf612ad 100644 --- a/x/bank/client/cli/cli_test.go +++ b/x/bank/client/cli/cli_test.go @@ -6,13 +6,11 @@ import ( "testing" "github.com/gogo/protobuf/proto" - "github.com/spf13/cobra" "github.com/stretchr/testify/suite" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -297,50 +295,6 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() { } } -// newSendTxMsgServiceCmd is just for the purpose of testing ServiceMsg's in an end-to-end case. It is effectively -// NewSendTxCmd but using MsgClient. -func newSendTxMsgServiceCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "send [from_key_or_address] [to_address] [amount]", - Short: `Send funds from one account to another. Note, the'--from' flag is -ignored as it is implied from [from_key_or_address].`, - Args: cobra.ExactArgs(3), - RunE: func(cmd *cobra.Command, args []string) error { - cmd.Flags().Set(flags.FlagFrom, args[0]) - - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) - if err != nil { - return err - } - - toAddr, err := sdk.AccAddressFromBech32(args[1]) - if err != nil { - return err - } - - coins, err := sdk.ParseCoins(args[2]) - if err != nil { - return err - } - - txBuilder := clientCtx.TxConfig.NewTxBuilder() - msg := types.NewMsgSend(clientCtx.GetFromAddress(), toAddr, coins) - bankMsgClient := types.NewMsgClient(txBuilder) - _, err = bankMsgClient.Send(context.Background(), msg) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), txBuilder.GetTx().GetMsgs()...) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} - // TestBankMsgService does a basic test of whether or not service Msg's as defined // in ADR 031 work in the most basic end-to-end case. func (s *IntegrationTestSuite) TestBankMsgService() { From 808364434aa52f17fbb870ce848c029feb29f66f Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 11 Dec 2020 12:16:47 +0100 Subject: [PATCH 17/18] Add comments and CHANHGELOG --- CHANGELOG.md | 1 + x/auth/legacy/legacytx/msg_service.go | 3 ++- x/auth/tx/msg_service.go | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 963a60161db8..c871c7bdfb07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Updated iavl dependency to v0.15-rc2 * (version) [\#7848](https://github.com/cosmos/cosmos-sdk/pull/7848) [\#7941](https://github.com/cosmos/cosmos-sdk/pull/7941) `version --long` output now shows the list of build dependencies and replaced build dependencies. * (x/genutil) [\#8099](https://github.com/cosmos/cosmos-sdk/pull/8099) `init` now supports a `--recover` flag to recover the private validator key from a given mnemonic +* (tx) [\#7630](https://github.com/cosmos/cosmos-sdk/pull/7630) TxBuilder now extends gogogrpc.ClientConn to support ADR-031 service Msgs. ### State Machine Breaking Changes diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index 1182360084f4..8a01f1c8e9c9 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -11,7 +11,8 @@ import ( ) // Invoke implements the grpc ClientConn.Invoke method. This is so that we can -// use ADR-031 service `Msg`s with StdTxBuilder. +// use ADR-031 service `Msg`s with StdTxBuilder. Invoking this method will +// **append** the service Msg into the TxBuilder's Msgs array. // TODO Full amino support still needs to be added as part of https://github.com/cosmos/cosmos-sdk/issues/7541. func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index 7e3385b6c60c..dbf0809f3dea 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -11,7 +11,8 @@ import ( ) // Invoke implements the grpc ClientConn.Invoke method. This is so that we can -// use ADR-031 service `Msg`s with wrapper. +// use ADR-031 service `Msg`s with wrapper. Invoking this method will +// **append** the service Msg into the TxBuilder's Msgs array. func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) if !ok { From ade84b5c02eda7d322330b5a810c9581f33867ae Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 11 Dec 2020 12:19:17 +0100 Subject: [PATCH 18/18] Add validate basic --- x/auth/legacy/legacytx/msg_service.go | 5 +++++ x/auth/tx/msg_service.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/x/auth/legacy/legacytx/msg_service.go b/x/auth/legacy/legacytx/msg_service.go index 8a01f1c8e9c9..7827f1d528fd 100644 --- a/x/auth/legacy/legacytx/msg_service.go +++ b/x/auth/legacy/legacytx/msg_service.go @@ -20,6 +20,11 @@ func (s *StdTxBuilder) Invoke(_ gocontext.Context, method string, args, reply in return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%T should implement %T", args, (*sdk.MsgRequest)(nil)) } + err := req.ValidateBasic() + if err != nil { + return err + } + msgs := append(s.Msgs, sdk.ServiceMsg{ MethodName: method, Request: req, diff --git a/x/auth/tx/msg_service.go b/x/auth/tx/msg_service.go index dbf0809f3dea..94e9f661063c 100644 --- a/x/auth/tx/msg_service.go +++ b/x/auth/tx/msg_service.go @@ -19,6 +19,11 @@ func (w *wrapper) Invoke(_ gocontext.Context, method string, args, reply interfa return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "%T should implement %T", args, (*sdk.MsgRequest)(nil)) } + err := req.ValidateBasic() + if err != nil { + return err + } + msgs := append(w.GetMsgs(), sdk.ServiceMsg{ MethodName: method, Request: req,