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 <sahithnarahari@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Aaron Craelius 2020-07-23 13:31:42 -04:00 committed by GitHub
parent ee04dd7878
commit 0a498d8c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 8 deletions

View File

@ -182,7 +182,12 @@ test-ledger-mock:
test-ledger: test-ledger-mock
@go test -mod=readonly -v `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger'
test-unit:
test-unit: test-unit-amino # TODO switch test-unit-proto to be default here after proto Tx is fully tested
test-unit-proto:
@VERSION=$(VERSION) go test -mod=readonly ./... -tags='ledger test_ledger_mock test_proto'
test-unit-amino:
@VERSION=$(VERSION) go test -mod=readonly ./... -tags='ledger test_ledger_mock'
test-race:

View File

@ -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)

View File

@ -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)

View File

@ -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{

26
simapp/params/proto.go Normal file
View File

@ -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,
}
}