Skip to content

Commit

Permalink
Fix the one remaining proto tx bug and flip the switch (#6902)
Browse files Browse the repository at this point in the history
* Fix the one remaining proto tx bug and flip the switch

* Update github CI

* Wrap TxDecoder errors

* Add test

* Cleanup
  • Loading branch information
aaronc authored Jul 30, 2020
1 parent 9ccec07 commit 7e2eea8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ jobs:
with:
file: ./coverage.txt
if: "env.GIT_DIFF != ''"
test-unit-proto-expected-to-fail:
test-unit-amino-might-fail:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: test-unit-proto
run: make test-unit-proto
- name: test-unit-amino
run: make test-unit-amino
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ 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-amino # TODO switch test-unit-proto to be default here after proto Tx is fully tested
test-unit: test-unit-proto

test-unit-proto:
@VERSION=$(VERSION) go test -mod=readonly ./... -tags='ledger test_ledger_mock test_proto'
@VERSION=$(VERSION) go test -mod=readonly ./... -tags='ledger test_ledger_mock'

test-unit-amino:
@VERSION=$(VERSION) go test -mod=readonly ./... -tags='ledger test_ledger_mock'
@VERSION=$(VERSION) go test -mod=readonly ./... -tags='ledger test_ledger_mock test_amino'

test-race:
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
Expand Down Expand Up @@ -736,8 +737,6 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA=
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand Down
3 changes: 1 addition & 2 deletions simapp/params/amino.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// +build !test_proto
// +build test_amino

// TODO switch to test_amino build flag once proto Tx's are ready
package params

import (
Expand Down
3 changes: 1 addition & 2 deletions simapp/params/proto.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// +build test_proto
// +build !test_amino

// TODO switch to !test_amino build flag once proto Tx's are ready
package params

import (
Expand Down
23 changes: 22 additions & 1 deletion x/auth/tx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func TestTxBuilder(t *testing.T) {
_, pubkey, addr := testdata.KeyTestPubAddr()

marshaler := codec.NewHybridCodec(codec.New(), codectypes.NewInterfaceRegistry())
marshaler := codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
txBuilder := newBuilder(std.DefaultPublicKeyCodec{})

cdc := std.DefaultPublicKeyCodec{}
Expand Down Expand Up @@ -230,3 +230,24 @@ func TestBuilderValidateBasic(t *testing.T) {
err = txBuilder.ValidateBasic()
require.Error(t, err)
}

func TestDefaultTxDecoderError(t *testing.T) {
registry := codectypes.NewInterfaceRegistry()
pubKeyCdc := std.DefaultPublicKeyCodec{}
encoder := DefaultTxEncoder()
decoder := DefaultTxDecoder(registry, pubKeyCdc)

builder := newBuilder(pubKeyCdc)
err := builder.SetMsgs(testdata.NewTestMsg())
require.NoError(t, err)

txBz, err := encoder(builder.GetTx())
require.NoError(t, err)

_, err = decoder(txBz)
require.EqualError(t, err, "no registered implementations of type types.Msg: tx parse error")

registry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{})
_, err = decoder(txBz)
require.NoError(t, err)
}
15 changes: 7 additions & 8 deletions x/auth/tx/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"

"github.com/cosmos/cosmos-sdk/types/tx"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx"
)

// DefaultTxDecoder returns a default protobuf TxDecoder using the provided Marshaler and PublicKeyCodec
Expand All @@ -19,18 +18,18 @@ func DefaultTxDecoder(anyUnpacker types.AnyUnpacker, keyCodec cryptotypes.Public
var raw tx.TxRaw
err := cdc.UnmarshalBinaryBare(txBytes, &raw)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
}

var theTx tx.Tx
err = cdc.UnmarshalBinaryBare(txBytes, &theTx)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
}

pks, err := extractPubKeys(theTx, keyCodec)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
}

return &builder{
Expand All @@ -50,12 +49,12 @@ func DefaultJSONTxDecoder(anyUnpacker types.AnyUnpacker, keyCodec cryptotypes.Pu
var theTx tx.Tx
err := cdc.UnmarshalJSON(txBytes, &theTx)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
}

pks, err := extractPubKeys(theTx, keyCodec)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
}

return &builder{
Expand Down
1 change: 1 addition & 0 deletions x/distribution/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgWithdrawDelegatorReward{},
&MsgWithdrawValidatorCommission{},
&MsgSetWithdrawAddress{},
&MsgFundCommunityPool{},
)
registry.RegisterImplementations(
(*govtypes.Content)(nil),
Expand Down

0 comments on commit 7e2eea8

Please sign in to comment.