Add support for protobuf TxGenerator and SIGN_MODE_DIRECT (#6385)
* Add TxWrapper, encoder, decoder and DirectModeHandler * fix pkg name * Update API and leave test TODO's * Update TxWrapper API * tests for tx wrapper (#6410) * WIP: added test for direct mode handler * updated code * Add msg * Update TxWrapper API * Fix pubkey declaration * Add pubkey for tests * Fix SetFee * Remove logs * Avoid global var declaration for tests * Add test for GetPubKeys * Fix direct signing tests * Add more test cases for GetSignBytes * Revert SetFee API * Remove logs * Refactor tests Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> * Refactoring * Refactoring * Integrate SignatureV2 API * Fix wrapper tests * Fix tests * Linting and API tweaks * Update API * WIP on updating API * Fix tests * Update to new SigVerifiableTx * Rename * Update docs to reflect ADR 020 * proto-gen * proto docs * cleanup * cleanup * cleanup * cleanup * cleanup * cleanup * cleanup * Add tests * Refactor and improving test coverage * WIP on test coverage * WIP on test coverage * proto-gen * Fix CompactBitArray.Size() bug * Rename * Remove Builder interface * Address review comments * Update x/auth/tx/sigs.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/auth/tx/encoder.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/auth/tx/encoder.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Address review feedback * Fix build issues * Resolve conflicts * Fix ValidateBasic test coverage * Add test for malicious multisig Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
co-authored by
anilCSE
sahith-narahari
Federico Kunze
atheeshp
Alexander Bezobchuk
parent
feb69770ef
commit
2f44fbf2ab
+10
-8
@@ -1,8 +1,10 @@
|
||||
package codec
|
||||
package codec_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec/testdata"
|
||||
@@ -23,32 +25,32 @@ func NewTestInterfaceRegistry() types.InterfaceRegistry {
|
||||
func TestMarshalAny(t *testing.T) {
|
||||
registry := types.NewInterfaceRegistry()
|
||||
|
||||
cdc := NewProtoCodec(registry)
|
||||
cdc := codec.NewProtoCodec(registry)
|
||||
|
||||
kitty := &testdata.Cat{Moniker: "Kitty"}
|
||||
bz, err := MarshalAny(cdc, kitty)
|
||||
bz, err := codec.MarshalAny(cdc, kitty)
|
||||
require.NoError(t, err)
|
||||
|
||||
var animal testdata.Animal
|
||||
|
||||
// empty registry should fail
|
||||
err = UnmarshalAny(cdc, &animal, bz)
|
||||
err = codec.UnmarshalAny(cdc, &animal, bz)
|
||||
require.Error(t, err)
|
||||
|
||||
// wrong type registration should fail
|
||||
registry.RegisterImplementations((*testdata.Animal)(nil), &testdata.Dog{})
|
||||
err = UnmarshalAny(cdc, &animal, bz)
|
||||
err = codec.UnmarshalAny(cdc, &animal, bz)
|
||||
require.Error(t, err)
|
||||
|
||||
// should pass
|
||||
registry = NewTestInterfaceRegistry()
|
||||
cdc = NewProtoCodec(registry)
|
||||
err = UnmarshalAny(cdc, &animal, bz)
|
||||
cdc = codec.NewProtoCodec(registry)
|
||||
err = codec.UnmarshalAny(cdc, &animal, bz)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, kitty, animal)
|
||||
|
||||
// nil should fail
|
||||
registry = NewTestInterfaceRegistry()
|
||||
err = UnmarshalAny(cdc, nil, bz)
|
||||
err = codec.UnmarshalAny(cdc, nil, bz)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
@@ -125,7 +125,12 @@ func (pc *ProtoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error {
|
||||
return fmt.Errorf("cannot protobuf JSON decode unsupported type: %T", ptr)
|
||||
}
|
||||
|
||||
return jsonpb.Unmarshal(strings.NewReader(string(bz)), m)
|
||||
err := jsonpb.Unmarshal(strings.NewReader(string(bz)), m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return types.UnpackInterfaces(ptr, pc.anyUnpacker)
|
||||
}
|
||||
|
||||
func (pc *ProtoCodec) MustUnmarshalJSON(bz []byte, ptr interface{}) {
|
||||
|
||||
Vendored
+458
-31
@@ -7,6 +7,8 @@ import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
grpc1 "github.com/gogo/protobuf/grpc"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
grpc "google.golang.org/grpc"
|
||||
@@ -536,6 +538,105 @@ func (m *TestAnyResponse) GetHasAnimal() *HasAnimal {
|
||||
return nil
|
||||
}
|
||||
|
||||
// msg type for testing
|
||||
type TestMsg struct {
|
||||
Signers []github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,rep,name=signers,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"signers,omitempty"`
|
||||
}
|
||||
|
||||
func (m *TestMsg) Reset() { *m = TestMsg{} }
|
||||
func (m *TestMsg) String() string { return proto.CompactTextString(m) }
|
||||
func (*TestMsg) ProtoMessage() {}
|
||||
func (*TestMsg) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2fcc84b9998d60d8, []int{11}
|
||||
}
|
||||
func (m *TestMsg) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *TestMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_TestMsg.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *TestMsg) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_TestMsg.Merge(m, src)
|
||||
}
|
||||
func (m *TestMsg) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *TestMsg) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_TestMsg.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_TestMsg proto.InternalMessageInfo
|
||||
|
||||
func (m *TestMsg) GetSigners() []github_com_cosmos_cosmos_sdk_types.AccAddress {
|
||||
if m != nil {
|
||||
return m.Signers
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bad MultiSignature with extra fields
|
||||
type BadMultiSignature struct {
|
||||
Signatures [][]byte `protobuf:"bytes,1,rep,name=signatures,proto3" json:"signatures,omitempty"`
|
||||
MaliciousField []byte `protobuf:"bytes,5,opt,name=malicious_field,json=maliciousField,proto3" json:"malicious_field,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *BadMultiSignature) Reset() { *m = BadMultiSignature{} }
|
||||
func (m *BadMultiSignature) String() string { return proto.CompactTextString(m) }
|
||||
func (*BadMultiSignature) ProtoMessage() {}
|
||||
func (*BadMultiSignature) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2fcc84b9998d60d8, []int{12}
|
||||
}
|
||||
func (m *BadMultiSignature) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *BadMultiSignature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_BadMultiSignature.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *BadMultiSignature) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_BadMultiSignature.Merge(m, src)
|
||||
}
|
||||
func (m *BadMultiSignature) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *BadMultiSignature) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_BadMultiSignature.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_BadMultiSignature proto.InternalMessageInfo
|
||||
|
||||
func (m *BadMultiSignature) GetSignatures() [][]byte {
|
||||
if m != nil {
|
||||
return m.Signatures
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BadMultiSignature) GetMaliciousField() []byte {
|
||||
if m != nil {
|
||||
return m.MaliciousField
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Dog)(nil), "testdata.Dog")
|
||||
proto.RegisterType((*Cat)(nil), "testdata.Cat")
|
||||
@@ -548,42 +649,51 @@ func init() {
|
||||
proto.RegisterType((*SayHelloResponse)(nil), "testdata.SayHelloResponse")
|
||||
proto.RegisterType((*TestAnyRequest)(nil), "testdata.TestAnyRequest")
|
||||
proto.RegisterType((*TestAnyResponse)(nil), "testdata.TestAnyResponse")
|
||||
proto.RegisterType((*TestMsg)(nil), "testdata.TestMsg")
|
||||
proto.RegisterType((*BadMultiSignature)(nil), "testdata.BadMultiSignature")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("proto.proto", fileDescriptor_2fcc84b9998d60d8) }
|
||||
|
||||
var fileDescriptor_2fcc84b9998d60d8 = []byte{
|
||||
// 467 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x6f, 0xd3, 0x30,
|
||||
0x18, 0xc6, 0x6b, 0xba, 0x3f, 0xed, 0xdb, 0x6a, 0x45, 0x66, 0xa0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 0xaa, 0x35, 0x0f, 0xf2, 0xb3, 0xac, 0x5d, 0x5b, 0x06, 0xf1,
|
||||
0x16, 0x8e, 0xcd, 0x83, 0xe8, 0xb0, 0x96, 0xfd, 0x1b, 0x95, 0x35, 0xda, 0xb1, 0xa3, 0xfd, 0xef,
|
||||
0x66, 0xbf, 0x36, 0x36, 0xb9, 0xdf, 0xd8, 0xe4, 0xcf, 0xc6, 0x26, 0x3f, 0xb6, 0x76, 0xeb, 0x7e,
|
||||
0x6b, 0xb7, 0x7e, 0x6f, 0xed, 0xd6, 0xe7, 0x57, 0x61, 0x9c, 0x45, 0xeb, 0x85, 0x1b, 0x88, 0xd4,
|
||||
0x0b, 0x84, 0x4c, 0x85, 0x34, 0x7f, 0xe7, 0x72, 0x79, 0xed, 0x05, 0x62, 0x89, 0x81, 0x57, 0x62,
|
||||
0x17, 0x47, 0x2a, 0xf0, 0xc9, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x82, 0x85, 0xb8, 0x56, 0xc6,
|
||||
0x03, 0x00, 0x00,
|
||||
// 583 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcd, 0x6e, 0xd4, 0x30,
|
||||
0x10, 0xc7, 0x6b, 0xb6, 0x9f, 0xb3, 0x51, 0x17, 0x4c, 0x41, 0x69, 0x0e, 0x69, 0x15, 0x09, 0x75,
|
||||
0x25, 0x68, 0x22, 0x5a, 0xf5, 0xd2, 0x03, 0x52, 0x5a, 0x16, 0x2a, 0xa1, 0x5e, 0x52, 0xc4, 0x81,
|
||||
0x4b, 0xe5, 0x4d, 0x5c, 0xaf, 0xd5, 0xc4, 0x2e, 0x71, 0x52, 0x35, 0x3c, 0x05, 0xaf, 0xc0, 0xd3,
|
||||
0xc0, 0x71, 0x8f, 0x9c, 0x10, 0xda, 0x7d, 0x0b, 0x4e, 0x28, 0xdf, 0x4b, 0xb5, 0xaa, 0xf6, 0x92,
|
||||
0xcc, 0x8c, 0xff, 0xf3, 0xb3, 0x3d, 0x7f, 0x43, 0xf7, 0x26, 0x96, 0x89, 0xb4, 0x8b, 0x2f, 0x5e,
|
||||
0x4f, 0xa8, 0x4a, 0x02, 0x92, 0x10, 0x63, 0x9b, 0x49, 0xc9, 0x42, 0xea, 0x14, 0xf5, 0x61, 0x7a,
|
||||
0xe5, 0x10, 0x91, 0x95, 0x22, 0x63, 0x8b, 0x49, 0x26, 0x8b, 0xd0, 0xc9, 0xa3, 0xb2, 0x6a, 0xed,
|
||||
0x43, 0xe7, 0xad, 0x64, 0x18, 0xc3, 0xb2, 0xe2, 0x5f, 0xa9, 0x8e, 0x76, 0x51, 0x7f, 0xc3, 0x2b,
|
||||
0xe2, 0xbc, 0x26, 0x48, 0x44, 0xf5, 0x47, 0x65, 0x2d, 0x8f, 0xad, 0x23, 0xe8, 0x9c, 0x92, 0x04,
|
||||
0xeb, 0xb0, 0x16, 0x49, 0xc1, 0xaf, 0x69, 0x5c, 0x75, 0xd4, 0x29, 0xde, 0x82, 0x95, 0x90, 0xdf,
|
||||
0x52, 0x55, 0x74, 0xad, 0x78, 0x65, 0x62, 0xbd, 0x87, 0x8d, 0x33, 0xa2, 0x5c, 0xc1, 0x23, 0x12,
|
||||
0xe2, 0x57, 0xb0, 0x4a, 0x8a, 0xa8, 0xe8, 0xed, 0x1e, 0x6c, 0xd9, 0xe5, 0xa1, 0xed, 0xfa, 0xd0,
|
||||
0xb6, 0x2b, 0x32, 0xaf, 0xd2, 0x60, 0x0d, 0xd0, 0x5d, 0x01, 0xeb, 0x78, 0xe8, 0xce, 0x3a, 0x05,
|
||||
0xed, 0x8c, 0xa8, 0x96, 0x75, 0x08, 0x30, 0x22, 0xea, 0x72, 0x01, 0xde, 0xc6, 0xa8, 0x6e, 0xb2,
|
||||
0xce, 0xa1, 0x57, 0x42, 0x5a, 0xce, 0x31, 0x6c, 0xe6, 0x9c, 0x05, 0x59, 0xda, 0x68, 0xa6, 0xd7,
|
||||
0xda, 0x83, 0xee, 0xc0, 0x1f, 0x49, 0x8f, 0x7e, 0x49, 0xa9, 0x2a, 0x67, 0x43, 0x95, 0x22, 0x8c,
|
||||
0x36, 0xb3, 0x29, 0x53, 0xab, 0x0f, 0x5a, 0x29, 0x54, 0x37, 0x52, 0x28, 0xfa, 0x80, 0xf2, 0x05,
|
||||
0xf4, 0x2e, 0x48, 0x76, 0x46, 0xc3, 0xb0, 0xc1, 0xd6, 0x6e, 0xa0, 0x19, 0x37, 0x6c, 0x78, 0xdc,
|
||||
0xca, 0x2a, 0xa8, 0x01, 0xeb, 0x2c, 0xa6, 0x34, 0xe1, 0x82, 0x55, 0xda, 0x26, 0xb7, 0x06, 0xb0,
|
||||
0xf9, 0x91, 0xaa, 0x24, 0xbf, 0x42, 0x45, 0x3d, 0x04, 0x20, 0x22, 0x5b, 0x68, 0x7e, 0x44, 0x64,
|
||||
0xd5, 0x85, 0x07, 0xd0, 0x6b, 0x30, 0xd5, 0xae, 0x07, 0x73, 0x7c, 0x78, 0x6a, 0xd7, 0xcf, 0xd2,
|
||||
0x6e, 0x86, 0x35, 0x6b, 0xc3, 0x27, 0x58, 0xcb, 0x31, 0xe7, 0x8a, 0xe1, 0x0f, 0xb0, 0xa6, 0x38,
|
||||
0x13, 0x34, 0x56, 0x3a, 0xda, 0xed, 0xf4, 0xb5, 0x93, 0xd7, 0x7f, 0x7f, 0xef, 0xec, 0x33, 0x9e,
|
||||
0x8c, 0xd2, 0xa1, 0xed, 0xcb, 0xc8, 0xf1, 0xa5, 0x8a, 0xa4, 0xaa, 0x7e, 0xfb, 0x2a, 0xb8, 0x76,
|
||||
0x92, 0xec, 0x86, 0x2a, 0xdb, 0xf5, 0x7d, 0x37, 0x08, 0x62, 0xaa, 0x94, 0x57, 0x13, 0xac, 0x21,
|
||||
0x3c, 0x39, 0x21, 0xc1, 0x79, 0x1a, 0x26, 0xfc, 0x82, 0x33, 0x41, 0x92, 0x34, 0xa6, 0xd8, 0x04,
|
||||
0x50, 0x75, 0x52, 0x6d, 0xe2, 0xcd, 0x54, 0xf0, 0x1e, 0xf4, 0x22, 0x12, 0x72, 0x9f, 0xcb, 0x54,
|
||||
0x5d, 0x5e, 0x71, 0x1a, 0x06, 0xfa, 0xca, 0x2e, 0xea, 0x6b, 0xde, 0x66, 0x53, 0x7e, 0x97, 0x57,
|
||||
0x8f, 0x97, 0xc7, 0xdf, 0x77, 0xd0, 0xc1, 0x0f, 0x04, 0xdd, 0xfc, 0xf0, 0x17, 0x34, 0xbe, 0xe5,
|
||||
0x3e, 0xc5, 0x47, 0xb0, 0x9c, 0x5b, 0x8b, 0x9f, 0xb5, 0x77, 0x9e, 0x79, 0x13, 0xc6, 0xf3, 0xfb,
|
||||
0xe5, 0x6a, 0x6c, 0x2e, 0xac, 0xd7, 0x06, 0xe2, 0xed, 0x56, 0x73, 0xcf, 0x7b, 0xc3, 0x98, 0xb7,
|
||||
0x54, 0x21, 0xde, 0x94, 0x53, 0x74, 0x45, 0x86, 0xf5, 0x56, 0xf6, 0xbf, 0xcd, 0xc6, 0xf6, 0x9c,
|
||||
0x95, 0xb2, 0xff, 0x64, 0xf0, 0x73, 0x62, 0xa2, 0xf1, 0xc4, 0x44, 0x7f, 0x26, 0x26, 0xfa, 0x36,
|
||||
0x35, 0x97, 0xc6, 0x53, 0x73, 0xe9, 0xd7, 0xd4, 0x5c, 0xfa, 0xfc, 0xf2, 0xc1, 0xf9, 0xfb, 0x32,
|
||||
0xa0, 0xbe, 0x53, 0x63, 0x87, 0xab, 0xc5, 0x63, 0x39, 0xfc, 0x17, 0x00, 0x00, 0xff, 0xff, 0x6f,
|
||||
0x03, 0x13, 0xf7, 0x98, 0x04, 0x00, 0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
@@ -1110,6 +1220,81 @@ func (m *TestAnyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *TestMsg) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *TestMsg) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *TestMsg) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Signers) > 0 {
|
||||
for iNdEx := len(m.Signers) - 1; iNdEx >= 0; iNdEx-- {
|
||||
i -= len(m.Signers[iNdEx])
|
||||
copy(dAtA[i:], m.Signers[iNdEx])
|
||||
i = encodeVarintProto(dAtA, i, uint64(len(m.Signers[iNdEx])))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *BadMultiSignature) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *BadMultiSignature) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *BadMultiSignature) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.XXX_unrecognized != nil {
|
||||
i -= len(m.XXX_unrecognized)
|
||||
copy(dAtA[i:], m.XXX_unrecognized)
|
||||
}
|
||||
if len(m.MaliciousField) > 0 {
|
||||
i -= len(m.MaliciousField)
|
||||
copy(dAtA[i:], m.MaliciousField)
|
||||
i = encodeVarintProto(dAtA, i, uint64(len(m.MaliciousField)))
|
||||
i--
|
||||
dAtA[i] = 0x2a
|
||||
}
|
||||
if len(m.Signatures) > 0 {
|
||||
for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- {
|
||||
i -= len(m.Signatures[iNdEx])
|
||||
copy(dAtA[i:], m.Signatures[iNdEx])
|
||||
i = encodeVarintProto(dAtA, i, uint64(len(m.Signatures[iNdEx])))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintProto(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovProto(v)
|
||||
base := offset
|
||||
@@ -1274,6 +1459,43 @@ func (m *TestAnyResponse) Size() (n int) {
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *TestMsg) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Signers) > 0 {
|
||||
for _, b := range m.Signers {
|
||||
l = len(b)
|
||||
n += 1 + l + sovProto(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *BadMultiSignature) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Signatures) > 0 {
|
||||
for _, b := range m.Signatures {
|
||||
l = len(b)
|
||||
n += 1 + l + sovProto(uint64(l))
|
||||
}
|
||||
}
|
||||
l = len(m.MaliciousField)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovProto(uint64(l))
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovProto(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
@@ -2305,6 +2527,211 @@ func (m *TestAnyResponse) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *TestMsg) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowProto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: TestMsg: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: TestMsg: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Signers", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowProto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Signers = append(m.Signers, make([]byte, postIndex-iNdEx))
|
||||
copy(m.Signers[len(m.Signers)-1], dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipProto(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *BadMultiSignature) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowProto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: BadMultiSignature: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: BadMultiSignature: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowProto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Signatures = append(m.Signatures, make([]byte, postIndex-iNdEx))
|
||||
copy(m.Signatures[len(m.Signatures)-1], dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 5:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field MaliciousField", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowProto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.MaliciousField = append(m.MaliciousField[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.MaliciousField == nil {
|
||||
m.MaliciousField = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipProto(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthProto
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipProto(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
|
||||
Vendored
+13
@@ -2,6 +2,7 @@ syntax = "proto3";
|
||||
package testdata;
|
||||
|
||||
import "google/protobuf/any.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/codec/testdata";
|
||||
|
||||
@@ -57,3 +58,15 @@ message TestAnyRequest {
|
||||
message TestAnyResponse {
|
||||
HasAnimal has_animal = 1;
|
||||
}
|
||||
|
||||
// msg type for testing
|
||||
message TestMsg {
|
||||
repeated bytes signers = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
|
||||
}
|
||||
|
||||
// bad MultiSignature with extra fields
|
||||
message BadMultiSignature {
|
||||
option (gogoproto.goproto_unrecognized) = true;
|
||||
repeated bytes signatures = 1;
|
||||
bytes malicious_field = 5;
|
||||
}
|
||||
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg {
|
||||
return &TestMsg{
|
||||
Signers: addrs,
|
||||
}
|
||||
}
|
||||
|
||||
var _ sdk.Msg = (*TestMsg)(nil)
|
||||
|
||||
func (msg *TestMsg) Route() string { return "TestMsg" }
|
||||
func (msg *TestMsg) Type() string { return "Test message" }
|
||||
func (msg *TestMsg) GetSignBytes() []byte {
|
||||
bz, err := json.Marshal(msg.Signers)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
func (msg *TestMsg) ValidateBasic() error { return nil }
|
||||
Reference in New Issue
Block a user