From 55f34974054798f76765786e0c987a6c28153d9e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 23 Jul 2020 13:31:42 -0400 Subject: [PATCH] Add protobuf Tx unit tests (#6614) * Enable proto tx by default and add test_amino build flag. * Enable proto TxDecoder * update makefile * fix conflicts * Revert AminoCodec change * Make test-unit-amino default for now * Make test-unit-amino default for now Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: sahith-narahari Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- app.go | 4 ++-- encoding.go | 4 +--- params/amino.go | 6 ++++-- params/proto.go | 26 ++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 params/proto.go diff --git a/app.go b/app.go index 8b326a0d76ab..6d194a3fd58f 100644 --- a/app.go +++ b/app.go @@ -178,7 +178,7 @@ func NewSimApp( cdc := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry - bApp := baseapp.NewBaseApp(appName, logger, db, authtypes.DefaultTxDecoder(cdc), baseAppOptions...) + bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) bApp.GRPCQueryRouter().SetAnyUnpacker(interfaceRegistry) @@ -366,7 +366,7 @@ func NewSimApp( app.SetAnteHandler( ante.NewAnteHandler( app.AccountKeeper, app.BankKeeper, ante.DefaultSigVerificationGasConsumer, - authtypes.LegacyAminoJSONHandler{}, + encodingConfig.TxConfig.SignModeHandler(), ), ) app.SetEndBlocker(app.EndBlocker) diff --git a/encoding.go b/encoding.go index 58f899edd7a5..7bb939bb7773 100644 --- a/encoding.go +++ b/encoding.go @@ -5,9 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/std" ) -// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration. -// -// TODO: this file should add a "+build test_amino" flag for #6190 and a proto.go file with a protobuf configuration +// MakeEncodingConfig creates an EncodingConfig for testing func MakeEncodingConfig() params.EncodingConfig { encodingConfig := params.MakeEncodingConfig() std.RegisterCodec(encodingConfig.Amino) diff --git a/params/amino.go b/params/amino.go index 6cb8a4de636a..871dba814e64 100644 --- a/params/amino.go +++ b/params/amino.go @@ -1,3 +1,6 @@ +// +build !test_proto + +// TODO switch to test_amino build flag once proto Tx's are ready package params import ( @@ -7,11 +10,10 @@ import ( ) // MakeEncodingConfig creates an EncodingConfig for an amino based test configuration. -// -// TODO: this file should add a "+build test_amino" flag for #6190 and a proto.go file with a protobuf configuration func MakeEncodingConfig() EncodingConfig { cdc := codec.New() interfaceRegistry := types.NewInterfaceRegistry() + // TODO: switch to using AminoCodec here once amino compatibility is fixed marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) return EncodingConfig{ diff --git a/params/proto.go b/params/proto.go new file mode 100644 index 000000000000..012361d1dc51 --- /dev/null +++ b/params/proto.go @@ -0,0 +1,26 @@ +// +build test_proto + +// TODO switch to !test_amino build flag once proto Tx's are ready +package params + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/x/auth/tx" +) + +// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration. +func MakeEncodingConfig() EncodingConfig { + cdc := codec.New() + interfaceRegistry := types.NewInterfaceRegistry() + marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) + txGen := tx.NewTxConfig(marshaler, std.DefaultPublicKeyCodec{}, tx.DefaultSignModeHandler()) + + return EncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxConfig: txGen, + Amino: cdc, + } +}