Fix the one remaining proto tx bug and flip the switch (#6902)
* Fix the one remaining proto tx bug and flip the switch * Update github CI * Wrap TxDecoder errors * Add test * Cleanup
This commit is contained in:
parent
9ccec075e2
commit
7e2eea84c6
|
@ -188,9 +188,9 @@ jobs:
|
||||||
with:
|
with:
|
||||||
file: ./coverage.txt
|
file: ./coverage.txt
|
||||||
if: "env.GIT_DIFF != ''"
|
if: "env.GIT_DIFF != ''"
|
||||||
test-unit-proto-expected-to-fail:
|
test-unit-amino-might-fail:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: test-unit-proto
|
- name: test-unit-amino
|
||||||
run: make test-unit-proto
|
run: make test-unit-amino
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -182,13 +182,13 @@ test-ledger-mock:
|
||||||
test-ledger: test-ledger-mock
|
test-ledger: test-ledger-mock
|
||||||
@go test -mod=readonly -v `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger'
|
@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:
|
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:
|
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:
|
test-race:
|
||||||
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)
|
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)
|
||||||
|
|
3
go.sum
3
go.sum
|
@ -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.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 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
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/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 v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||||
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
|
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
|
||||||
|
@ -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 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
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.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 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
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=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
|
|
|
@ -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
|
package params
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -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
|
package params
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
func TestTxBuilder(t *testing.T) {
|
func TestTxBuilder(t *testing.T) {
|
||||||
_, pubkey, addr := testdata.KeyTestPubAddr()
|
_, pubkey, addr := testdata.KeyTestPubAddr()
|
||||||
|
|
||||||
marshaler := codec.NewHybridCodec(codec.New(), codectypes.NewInterfaceRegistry())
|
marshaler := codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||||
txBuilder := newBuilder(std.DefaultPublicKeyCodec{})
|
txBuilder := newBuilder(std.DefaultPublicKeyCodec{})
|
||||||
|
|
||||||
cdc := std.DefaultPublicKeyCodec{}
|
cdc := std.DefaultPublicKeyCodec{}
|
||||||
|
@ -230,3 +230,24 @@ func TestBuilderValidateBasic(t *testing.T) {
|
||||||
err = txBuilder.ValidateBasic()
|
err = txBuilder.ValidateBasic()
|
||||||
require.Error(t, err)
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -5,11 +5,10 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
|
||||||
|
|
||||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/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
|
// DefaultTxDecoder returns a default protobuf TxDecoder using the provided Marshaler and PublicKeyCodec
|
||||||
|
@ -19,18 +18,18 @@ func DefaultTxDecoder(anyUnpacker types.AnyUnpacker, keyCodec cryptotypes.Public
|
||||||
var raw tx.TxRaw
|
var raw tx.TxRaw
|
||||||
err := cdc.UnmarshalBinaryBare(txBytes, &raw)
|
err := cdc.UnmarshalBinaryBare(txBytes, &raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var theTx tx.Tx
|
var theTx tx.Tx
|
||||||
err = cdc.UnmarshalBinaryBare(txBytes, &theTx)
|
err = cdc.UnmarshalBinaryBare(txBytes, &theTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
pks, err := extractPubKeys(theTx, keyCodec)
|
pks, err := extractPubKeys(theTx, keyCodec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &builder{
|
return &builder{
|
||||||
|
@ -50,12 +49,12 @@ func DefaultJSONTxDecoder(anyUnpacker types.AnyUnpacker, keyCodec cryptotypes.Pu
|
||||||
var theTx tx.Tx
|
var theTx tx.Tx
|
||||||
err := cdc.UnmarshalJSON(txBytes, &theTx)
|
err := cdc.UnmarshalJSON(txBytes, &theTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
pks, err := extractPubKeys(theTx, keyCodec)
|
pks, err := extractPubKeys(theTx, keyCodec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &builder{
|
return &builder{
|
||||||
|
|
|
@ -24,6 +24,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||||
&MsgWithdrawDelegatorReward{},
|
&MsgWithdrawDelegatorReward{},
|
||||||
&MsgWithdrawValidatorCommission{},
|
&MsgWithdrawValidatorCommission{},
|
||||||
&MsgSetWithdrawAddress{},
|
&MsgSetWithdrawAddress{},
|
||||||
|
&MsgFundCommunityPool{},
|
||||||
)
|
)
|
||||||
registry.RegisterImplementations(
|
registry.RegisterImplementations(
|
||||||
(*govtypes.Content)(nil),
|
(*govtypes.Content)(nil),
|
||||||
|
|
Loading…
Reference in New Issue