Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix the one remaining proto tx bug and flip the switch #6902

Merged
merged 7 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

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

lol

Copy link
Collaborator

Choose a reason for hiding this comment

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

why the might-fail?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because when we remove HybridCodec in #6837, it will start failing until we finish #6190.

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