diff --git a/types/proto_generator.go b/types/proto_generator.go new file mode 100644 index 000000000..985dba549 --- /dev/null +++ b/types/proto_generator.go @@ -0,0 +1,24 @@ +// Code generated by github.com/Liamsi/protogenerat0r DO NOT EDIT. + +package types + +import ( + "os" + + // we use dedis' protobuf library to generate proto files from go-structs + // see: https://github.com/dedis/protobuf#generating-proto-files + "github.com/dedis/protobuf" +) + +var structTypes = []interface{}{ + PartSetHeader{}, + //SignedHeader{}, + Vote{}, + //VoteSet{}, +} + +// Call this method to generate protobuf messages: +func GenerateProtos() { + // see: https://github.com/dedis/protobuf#generating-proto-files + protobuf.GenerateProtobufDefinition(os.Stdout, structTypes, nil, nil) +} diff --git a/types/proto_generator_test.go b/types/proto_generator_test.go new file mode 100644 index 000000000..fa62bfe70 --- /dev/null +++ b/types/proto_generator_test.go @@ -0,0 +1,11 @@ +// Code generated by github.com/Liamsi/protogenerat0r DO NOT EDIT. + +package types + +import "testing" + +func TestGenerateProtos(t *testing.T) { + // TODO: meh, this doesn't work reliably enough for votes :-( + // had to write some proto stuff manually + GenerateProtos() +} diff --git a/types/types.pb.go b/types/types.pb.go new file mode 100644 index 000000000..cd5d35200 --- /dev/null +++ b/types/types.pb.go @@ -0,0 +1,747 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: types/types.proto + +package types + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import types "github.com/gogo/protobuf/types" + +import bytes "bytes" + +import strings "strings" +import reflect "reflect" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type VoteCustomType struct { + Vote *Vote `protobuf:"bytes,1,req,name=vote,customtype=Vote" json:"vote,omitempty"` +} + +func (m *VoteCustomType) Reset() { *m = VoteCustomType{} } +func (*VoteCustomType) ProtoMessage() {} +func (*VoteCustomType) Descriptor() ([]byte, []int) { + return fileDescriptor_types_71084d3349e31fa5, []int{0} +} +func (m *VoteCustomType) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_VoteCustomType.Unmarshal(m, b) +} +func (m *VoteCustomType) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_VoteCustomType.Marshal(b, m, deterministic) +} +func (dst *VoteCustomType) XXX_Merge(src proto.Message) { + xxx_messageInfo_VoteCustomType.Merge(dst, src) +} +func (m *VoteCustomType) XXX_Size() int { + return xxx_messageInfo_VoteCustomType.Size(m) +} +func (m *VoteCustomType) XXX_DiscardUnknown() { + xxx_messageInfo_VoteCustomType.DiscardUnknown(m) +} + +var xxx_messageInfo_VoteCustomType proto.InternalMessageInfo + +type VoteType struct { + Type uint32 `protobuf:"varint,1,req,name=Type" json:"Type"` + Height int64 `protobuf:"varint,2,req,name=Height" json:"Height"` + Round int64 `protobuf:"varint,3,req,name=Round" json:"Round"` + BlockID *BlockIDType `protobuf:"bytes,4,req,name=BlockID" json:"BlockID,omitempty"` + TimestampField *types.Timestamp `protobuf:"bytes,5,req,name=timestamp_field,json=timestampField" json:"timestamp_field,omitempty"` + ValidatorAddress []byte `protobuf:"bytes,6,req,name=ValidatorAddress" json:"ValidatorAddress"` + ValidatorIndex int64 `protobuf:"varint,7,req,name=ValidatorIndex" json:"ValidatorIndex"` + Signature []byte `protobuf:"bytes,8,opt,name=Signature" json:"Signature"` +} + +func (m *VoteType) Reset() { *m = VoteType{} } +func (*VoteType) ProtoMessage() {} +func (*VoteType) Descriptor() ([]byte, []int) { + return fileDescriptor_types_71084d3349e31fa5, []int{1} +} +func (m *VoteType) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_VoteType.Unmarshal(m, b) +} +func (m *VoteType) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_VoteType.Marshal(b, m, deterministic) +} +func (dst *VoteType) XXX_Merge(src proto.Message) { + xxx_messageInfo_VoteType.Merge(dst, src) +} +func (m *VoteType) XXX_Size() int { + return xxx_messageInfo_VoteType.Size(m) +} +func (m *VoteType) XXX_DiscardUnknown() { + xxx_messageInfo_VoteType.DiscardUnknown(m) +} + +var xxx_messageInfo_VoteType proto.InternalMessageInfo + +func (m *VoteType) GetType() uint32 { + if m != nil { + return m.Type + } + return 0 +} + +func (m *VoteType) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *VoteType) GetRound() int64 { + if m != nil { + return m.Round + } + return 0 +} + +func (m *VoteType) GetBlockID() *BlockIDType { + if m != nil { + return m.BlockID + } + return nil +} + +func (m *VoteType) GetTimestampField() *types.Timestamp { + if m != nil { + return m.TimestampField + } + return nil +} + +func (m *VoteType) GetValidatorAddress() []byte { + if m != nil { + return m.ValidatorAddress + } + return nil +} + +func (m *VoteType) GetValidatorIndex() int64 { + if m != nil { + return m.ValidatorIndex + } + return 0 +} + +func (m *VoteType) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +type PartSetHeaderType struct { + Total int64 `protobuf:"zigzag64,1,req,name=total" json:"total"` + Hash []byte `protobuf:"bytes,2,req,name=hash" json:"hash"` +} + +func (m *PartSetHeaderType) Reset() { *m = PartSetHeaderType{} } +func (*PartSetHeaderType) ProtoMessage() {} +func (*PartSetHeaderType) Descriptor() ([]byte, []int) { + return fileDescriptor_types_71084d3349e31fa5, []int{2} +} +func (m *PartSetHeaderType) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_PartSetHeaderType.Unmarshal(m, b) +} +func (m *PartSetHeaderType) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_PartSetHeaderType.Marshal(b, m, deterministic) +} +func (dst *PartSetHeaderType) XXX_Merge(src proto.Message) { + xxx_messageInfo_PartSetHeaderType.Merge(dst, src) +} +func (m *PartSetHeaderType) XXX_Size() int { + return xxx_messageInfo_PartSetHeaderType.Size(m) +} +func (m *PartSetHeaderType) XXX_DiscardUnknown() { + xxx_messageInfo_PartSetHeaderType.DiscardUnknown(m) +} + +var xxx_messageInfo_PartSetHeaderType proto.InternalMessageInfo + +func (m *PartSetHeaderType) GetTotal() int64 { + if m != nil { + return m.Total + } + return 0 +} + +func (m *PartSetHeaderType) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +type BlockIDType struct { + Hash []byte `protobuf:"bytes,1,opt,name=Hash" json:"Hash"` + PartSetHeader *PartSetHeaderType `protobuf:"bytes,2,opt,name=PartSetHeader" json:"PartSetHeader,omitempty"` +} + +func (m *BlockIDType) Reset() { *m = BlockIDType{} } +func (*BlockIDType) ProtoMessage() {} +func (*BlockIDType) Descriptor() ([]byte, []int) { + return fileDescriptor_types_71084d3349e31fa5, []int{3} +} +func (m *BlockIDType) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlockIDType.Unmarshal(m, b) +} +func (m *BlockIDType) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlockIDType.Marshal(b, m, deterministic) +} +func (dst *BlockIDType) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockIDType.Merge(dst, src) +} +func (m *BlockIDType) XXX_Size() int { + return xxx_messageInfo_BlockIDType.Size(m) +} +func (m *BlockIDType) XXX_DiscardUnknown() { + xxx_messageInfo_BlockIDType.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockIDType proto.InternalMessageInfo + +func (m *BlockIDType) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +func (m *BlockIDType) GetPartSetHeader() *PartSetHeaderType { + if m != nil { + return m.PartSetHeader + } + return nil +} + +func init() { + proto.RegisterType((*VoteCustomType)(nil), "types.VoteCustomType") + proto.RegisterType((*VoteType)(nil), "types.VoteType") + proto.RegisterType((*PartSetHeaderType)(nil), "types.PartSetHeaderType") + proto.RegisterType((*BlockIDType)(nil), "types.BlockIDType") +} +func (this *VoteCustomType) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*VoteCustomType) + if !ok { + that2, ok := that.(VoteCustomType) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if that1.Vote == nil { + if this.Vote != nil { + return false + } + } else if !this.Vote.Equal(*that1.Vote) { + return false + } + return true +} +func (this *VoteType) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*VoteType) + if !ok { + that2, ok := that.(VoteType) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Type != that1.Type { + return false + } + if this.Height != that1.Height { + return false + } + if this.Round != that1.Round { + return false + } + if !this.BlockID.Equal(that1.BlockID) { + return false + } + if !this.TimestampField.Equal(that1.TimestampField) { + return false + } + if !bytes.Equal(this.ValidatorAddress, that1.ValidatorAddress) { + return false + } + if this.ValidatorIndex != that1.ValidatorIndex { + return false + } + if !bytes.Equal(this.Signature, that1.Signature) { + return false + } + return true +} +func (this *PartSetHeaderType) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PartSetHeaderType) + if !ok { + that2, ok := that.(PartSetHeaderType) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Total != that1.Total { + return false + } + if !bytes.Equal(this.Hash, that1.Hash) { + return false + } + return true +} +func (this *BlockIDType) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*BlockIDType) + if !ok { + that2, ok := that.(BlockIDType) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Hash, that1.Hash) { + return false + } + if !this.PartSetHeader.Equal(that1.PartSetHeader) { + return false + } + return true +} +func (this *VoteCustomType) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&types.VoteCustomType{") + if this.Vote != nil { + s = append(s, "Vote: "+valueToGoStringTypes(this.Vote, "Vote")+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *VoteType) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 12) + s = append(s, "&types.VoteType{") + s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") + s = append(s, "Height: "+fmt.Sprintf("%#v", this.Height)+",\n") + s = append(s, "Round: "+fmt.Sprintf("%#v", this.Round)+",\n") + if this.BlockID != nil { + s = append(s, "BlockID: "+fmt.Sprintf("%#v", this.BlockID)+",\n") + } + if this.TimestampField != nil { + s = append(s, "TimestampField: "+fmt.Sprintf("%#v", this.TimestampField)+",\n") + } + s = append(s, "ValidatorAddress: "+fmt.Sprintf("%#v", this.ValidatorAddress)+",\n") + s = append(s, "ValidatorIndex: "+fmt.Sprintf("%#v", this.ValidatorIndex)+",\n") + s = append(s, "Signature: "+fmt.Sprintf("%#v", this.Signature)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *PartSetHeaderType) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&types.PartSetHeaderType{") + s = append(s, "Total: "+fmt.Sprintf("%#v", this.Total)+",\n") + s = append(s, "Hash: "+fmt.Sprintf("%#v", this.Hash)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *BlockIDType) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&types.BlockIDType{") + s = append(s, "Hash: "+fmt.Sprintf("%#v", this.Hash)+",\n") + if this.PartSetHeader != nil { + s = append(s, "PartSetHeader: "+fmt.Sprintf("%#v", this.PartSetHeader)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringTypes(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func NewPopulatedVoteCustomType(r randyTypes, easy bool) *VoteCustomType { + this := &VoteCustomType{} + this.Vote = NewPopulatedVote(r) + if !easy && r.Intn(10) != 0 { + } + return this +} + +func NewPopulatedVoteType(r randyTypes, easy bool) *VoteType { + this := &VoteType{} + this.Type = uint32(r.Uint32()) + this.Height = int64(r.Int63()) + if r.Intn(2) == 0 { + this.Height *= -1 + } + this.Round = int64(r.Int63()) + if r.Intn(2) == 0 { + this.Round *= -1 + } + this.BlockID = NewPopulatedBlockIDType(r, easy) + this.TimestampField = types.NewPopulatedTimestamp(r, easy) + v1 := r.Intn(100) + this.ValidatorAddress = make([]byte, v1) + for i := 0; i < v1; i++ { + this.ValidatorAddress[i] = byte(r.Intn(256)) + } + this.ValidatorIndex = int64(r.Int63()) + if r.Intn(2) == 0 { + this.ValidatorIndex *= -1 + } + v2 := r.Intn(100) + this.Signature = make([]byte, v2) + for i := 0; i < v2; i++ { + this.Signature[i] = byte(r.Intn(256)) + } + if !easy && r.Intn(10) != 0 { + } + return this +} + +func NewPopulatedPartSetHeaderType(r randyTypes, easy bool) *PartSetHeaderType { + this := &PartSetHeaderType{} + this.Total = int64(r.Int63()) + if r.Intn(2) == 0 { + this.Total *= -1 + } + v3 := r.Intn(100) + this.Hash = make([]byte, v3) + for i := 0; i < v3; i++ { + this.Hash[i] = byte(r.Intn(256)) + } + if !easy && r.Intn(10) != 0 { + } + return this +} + +func NewPopulatedBlockIDType(r randyTypes, easy bool) *BlockIDType { + this := &BlockIDType{} + v4 := r.Intn(100) + this.Hash = make([]byte, v4) + for i := 0; i < v4; i++ { + this.Hash[i] = byte(r.Intn(256)) + } + if r.Intn(10) != 0 { + this.PartSetHeader = NewPopulatedPartSetHeaderType(r, easy) + } + if !easy && r.Intn(10) != 0 { + } + return this +} + +type randyTypes interface { + Float32() float32 + Float64() float64 + Int63() int64 + Int31() int32 + Uint32() uint32 + Intn(n int) int +} + +func randUTF8RuneTypes(r randyTypes) rune { + ru := r.Intn(62) + if ru < 10 { + return rune(ru + 48) + } else if ru < 36 { + return rune(ru + 55) + } + return rune(ru + 61) +} +func randStringTypes(r randyTypes) string { + v5 := r.Intn(100) + tmps := make([]rune, v5) + for i := 0; i < v5; i++ { + tmps[i] = randUTF8RuneTypes(r) + } + return string(tmps) +} +func randUnrecognizedTypes(r randyTypes, maxFieldNumber int) (dAtA []byte) { + l := r.Intn(5) + for i := 0; i < l; i++ { + wire := r.Intn(4) + if wire == 3 { + wire = 5 + } + fieldNumber := maxFieldNumber + r.Intn(100) + dAtA = randFieldTypes(dAtA, r, fieldNumber, wire) + } + return dAtA +} +func randFieldTypes(dAtA []byte, r randyTypes, fieldNumber int, wire int) []byte { + key := uint32(fieldNumber)<<3 | uint32(wire) + switch wire { + case 0: + dAtA = encodeVarintPopulateTypes(dAtA, uint64(key)) + v6 := r.Int63() + if r.Intn(2) == 0 { + v6 *= -1 + } + dAtA = encodeVarintPopulateTypes(dAtA, uint64(v6)) + case 1: + dAtA = encodeVarintPopulateTypes(dAtA, uint64(key)) + dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) + case 2: + dAtA = encodeVarintPopulateTypes(dAtA, uint64(key)) + ll := r.Intn(100) + dAtA = encodeVarintPopulateTypes(dAtA, uint64(ll)) + for j := 0; j < ll; j++ { + dAtA = append(dAtA, byte(r.Intn(256))) + } + default: + dAtA = encodeVarintPopulateTypes(dAtA, uint64(key)) + dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) + } + return dAtA +} +func encodeVarintPopulateTypes(dAtA []byte, v uint64) []byte { + for v >= 1<<7 { + dAtA = append(dAtA, uint8(uint64(v)&0x7f|0x80)) + v >>= 7 + } + dAtA = append(dAtA, uint8(v)) + return dAtA +} +func (m *VoteCustomType) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Vote != nil { + l = m.Vote.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *VoteType) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + n += 1 + sovTypes(uint64(m.Type)) + n += 1 + sovTypes(uint64(m.Height)) + n += 1 + sovTypes(uint64(m.Round)) + if m.BlockID != nil { + l = m.BlockID.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.TimestampField != nil { + l = m.TimestampField.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.ValidatorAddress != nil { + l = len(m.ValidatorAddress) + n += 1 + l + sovTypes(uint64(l)) + } + n += 1 + sovTypes(uint64(m.ValidatorIndex)) + if m.Signature != nil { + l = len(m.Signature) + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *PartSetHeaderType) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + n += 1 + sozTypes(uint64(m.Total)) + if m.Hash != nil { + l = len(m.Hash) + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *BlockIDType) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Hash != nil { + l = len(m.Hash) + n += 1 + l + sovTypes(uint64(l)) + } + if m.PartSetHeader != nil { + l = m.PartSetHeader.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func sovTypes(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *VoteCustomType) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&VoteCustomType{`, + `Vote:` + valueToStringTypes(this.Vote) + `,`, + `}`, + }, "") + return s +} +func (this *VoteType) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&VoteType{`, + `Type:` + fmt.Sprintf("%v", this.Type) + `,`, + `Height:` + fmt.Sprintf("%v", this.Height) + `,`, + `Round:` + fmt.Sprintf("%v", this.Round) + `,`, + `BlockID:` + strings.Replace(fmt.Sprintf("%v", this.BlockID), "BlockIDType", "BlockIDType", 1) + `,`, + `TimestampField:` + strings.Replace(fmt.Sprintf("%v", this.TimestampField), "Timestamp", "types.Timestamp", 1) + `,`, + `ValidatorAddress:` + fmt.Sprintf("%v", this.ValidatorAddress) + `,`, + `ValidatorIndex:` + fmt.Sprintf("%v", this.ValidatorIndex) + `,`, + `Signature:` + fmt.Sprintf("%v", this.Signature) + `,`, + `}`, + }, "") + return s +} +func (this *PartSetHeaderType) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&PartSetHeaderType{`, + `Total:` + fmt.Sprintf("%v", this.Total) + `,`, + `Hash:` + fmt.Sprintf("%v", this.Hash) + `,`, + `}`, + }, "") + return s +} +func (this *BlockIDType) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&BlockIDType{`, + `Hash:` + fmt.Sprintf("%v", this.Hash) + `,`, + `PartSetHeader:` + strings.Replace(fmt.Sprintf("%v", this.PartSetHeader), "PartSetHeaderType", "PartSetHeaderType", 1) + `,`, + `}`, + }, "") + return s +} +func valueToStringTypes(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} + +func init() { proto.RegisterFile("types/types.proto", fileDescriptor_types_71084d3349e31fa5) } + +var fileDescriptor_types_71084d3349e31fa5 = []byte{ + // 462 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x50, 0xbf, 0x6e, 0xd3, 0x40, + 0x18, 0xbf, 0x73, 0x9d, 0x36, 0x7c, 0xa1, 0x29, 0xbd, 0xe9, 0x64, 0xa1, 0x8b, 0xe5, 0x29, 0x43, + 0xeb, 0xa0, 0xce, 0x08, 0x44, 0x8a, 0x50, 0xb2, 0x21, 0xb7, 0xea, 0x8a, 0xdc, 0xfa, 0xea, 0x58, + 0x38, 0xb9, 0xc8, 0x3e, 0x23, 0xba, 0xf1, 0x08, 0x3c, 0x06, 0x8f, 0xc0, 0x23, 0x74, 0xcc, 0x82, + 0x54, 0x31, 0x54, 0xc4, 0x59, 0x18, 0x3b, 0x32, 0xa2, 0xfb, 0x6c, 0xa7, 0x69, 0xbb, 0xd8, 0xf7, + 0xfd, 0xfe, 0x7c, 0xf7, 0xbb, 0x1f, 0xec, 0xeb, 0xab, 0xb9, 0xcc, 0x07, 0xf8, 0xf5, 0xe7, 0x99, + 0xd2, 0x8a, 0xb5, 0x70, 0x70, 0x0e, 0xe3, 0x44, 0x4f, 0x8a, 0x73, 0xff, 0x42, 0x4d, 0x07, 0xb1, + 0x8a, 0xd5, 0x00, 0xd9, 0xf3, 0xe2, 0x12, 0x27, 0x1c, 0xf0, 0x54, 0xb9, 0x9c, 0x5e, 0xac, 0x54, + 0x9c, 0xca, 0x7b, 0x95, 0x4e, 0xa6, 0x32, 0xd7, 0xe1, 0x74, 0x5e, 0x09, 0xbc, 0xb7, 0xd0, 0x3d, + 0x53, 0x5a, 0x1e, 0x17, 0xb9, 0x56, 0xd3, 0xd3, 0xab, 0xb9, 0x64, 0x87, 0x60, 0x7f, 0x51, 0x5a, + 0x72, 0xea, 0x5a, 0xfd, 0xce, 0xd1, 0x9e, 0x5f, 0x85, 0x30, 0x22, 0x43, 0x0f, 0xdb, 0xbf, 0x6f, + 0x7b, 0xb6, 0x99, 0x02, 0x94, 0x79, 0xbf, 0x2c, 0x68, 0x37, 0x24, 0xe3, 0x60, 0x9b, 0x3f, 0x7a, + 0x77, 0x87, 0xf6, 0xf5, 0x6d, 0x8f, 0x04, 0x88, 0xb0, 0x97, 0xb0, 0x3d, 0x92, 0x49, 0x3c, 0xd1, + 0xdc, 0x72, 0xad, 0xfe, 0x56, 0xcd, 0xd5, 0x18, 0x73, 0xa0, 0x15, 0xa8, 0x62, 0x16, 0xf1, 0xad, + 0x0d, 0xb2, 0x82, 0xd8, 0x01, 0xec, 0x0c, 0x53, 0x75, 0xf1, 0x79, 0xfc, 0x9e, 0xdb, 0x18, 0x89, + 0xd5, 0x91, 0x6a, 0xd4, 0xac, 0x0f, 0x1a, 0x09, 0x3b, 0x86, 0xbd, 0xf5, 0x13, 0x3f, 0x5d, 0x26, + 0x32, 0x8d, 0x78, 0x0b, 0x5d, 0x8e, 0x5f, 0x55, 0xe1, 0x37, 0x55, 0xf8, 0xa7, 0x8d, 0x2e, 0xe8, + 0xae, 0x2d, 0x1f, 0x8c, 0x83, 0xbd, 0x82, 0x17, 0x67, 0x61, 0x9a, 0x44, 0xa1, 0x56, 0xd9, 0xbb, + 0x28, 0xca, 0x64, 0x9e, 0xf3, 0x6d, 0xd7, 0xea, 0x3f, 0xaf, 0x93, 0x3d, 0x61, 0xd9, 0x01, 0x74, + 0xd7, 0xd8, 0x78, 0x16, 0xc9, 0xaf, 0x7c, 0x67, 0xe3, 0x25, 0x8f, 0x38, 0xe6, 0xc1, 0xb3, 0x93, + 0x24, 0x9e, 0x85, 0xba, 0xc8, 0x24, 0x6f, 0xbb, 0x74, 0xbd, 0xf8, 0x1e, 0xf6, 0xc6, 0xb0, 0xff, + 0x31, 0xcc, 0xf4, 0x89, 0xd4, 0x23, 0x19, 0x46, 0x32, 0xc3, 0x16, 0x1d, 0x68, 0x69, 0xa5, 0xc3, + 0x14, 0x0b, 0x66, 0x4d, 0x4f, 0x08, 0x99, 0xee, 0x27, 0x61, 0x3e, 0xc1, 0x7e, 0x9b, 0x7d, 0x88, + 0x78, 0x31, 0x74, 0x36, 0xba, 0x32, 0xc2, 0x91, 0x11, 0xd2, 0x8d, 0x8b, 0x11, 0x61, 0x6f, 0x60, + 0xf7, 0xc1, 0x9d, 0xdc, 0x72, 0x69, 0xbf, 0x73, 0xc4, 0xeb, 0xc2, 0x9f, 0xe4, 0x09, 0x1e, 0xca, + 0x87, 0xaf, 0x17, 0x4b, 0x41, 0x6e, 0x96, 0x82, 0xdc, 0x2d, 0x05, 0xfd, 0xb7, 0x14, 0xf4, 0x5b, + 0x29, 0xe8, 0x8f, 0x52, 0xd0, 0x9f, 0xa5, 0xa0, 0xd7, 0xa5, 0x20, 0x8b, 0x52, 0x90, 0x3f, 0xa5, + 0xa0, 0x7f, 0x4b, 0x41, 0xee, 0x4a, 0x41, 0xbf, 0xaf, 0x04, 0x59, 0xac, 0x04, 0xb9, 0x59, 0x09, + 0xf2, 0x3f, 0x00, 0x00, 0xff, 0xff, 0xda, 0xcf, 0x0f, 0x20, 0xf5, 0x02, 0x00, 0x00, +} diff --git a/types/types.proto b/types/types.proto new file mode 100644 index 000000000..42a56c354 --- /dev/null +++ b/types/types.proto @@ -0,0 +1,40 @@ +syntax = "proto2"; + +package types; + + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.populate_all) = true; +option (gogoproto.testgen_all) = true; + +message VoteCustomType { + required VoteType vote = 1 [(gogoproto.customtype) = "Vote"]; +} + +message VoteType { + required uint32 Type = 1; + required int64 Height = 2; + required int64 Round = 3; + required BlockIDType BlockID = 4; + required google.protobuf.Timestamp timestamp_field = 5; + required bytes ValidatorAddress = 6; + required int64 ValidatorIndex = 7; + optional bytes Signature = 8; +} + +// TODO: try if it's worth using custom types here too instead? +// (probably not a good idea: more interface methods to implement +// and this messages do not travel the wire separately) +message PartSetHeaderType { + required sint64 total = 1; + required bytes hash = 2; +} + +message BlockIDType { + optional bytes Hash = 1; + optional PartSetHeaderType PartSetHeader = 2; +} diff --git a/types/typespb_test.go b/types/typespb_test.go new file mode 100644 index 000000000..15bf8bb56 --- /dev/null +++ b/types/typespb_test.go @@ -0,0 +1,508 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: types/types.proto + +package types + +import testing "testing" +import math_rand "math/rand" +import time "time" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import go_parser "go/parser" +import proto "github.com/gogo/protobuf/proto" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestVoteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteCustomType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &VoteCustomType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestVoteTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &VoteType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestPartSetHeaderTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedPartSetHeaderType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &PartSetHeaderType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestBlockIDTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBlockIDType(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &BlockIDType{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestVoteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteCustomType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &VoteCustomType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestVoteTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &VoteType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestPartSetHeaderTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedPartSetHeaderType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &PartSetHeaderType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBlockIDTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBlockIDType(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &BlockIDType{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestVoteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &VoteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestVoteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteCustomType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &VoteCustomType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestVoteTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &VoteType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestVoteTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &VoteType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestPartSetHeaderTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedPartSetHeaderType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &PartSetHeaderType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestPartSetHeaderTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedPartSetHeaderType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &PartSetHeaderType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBlockIDTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBlockIDType(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &BlockIDType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBlockIDTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBlockIDType(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &BlockIDType{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestVoteCustomTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedVoteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestVoteTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedVoteType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestPartSetHeaderTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedPartSetHeaderType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBlockIDTypeGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBlockIDType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestVoteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteCustomType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestVoteTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedVoteType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestPartSetHeaderTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedPartSetHeaderType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestBlockIDTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedBlockIDType(popr, true) + size2 := github_com_gogo_protobuf_proto.Size(p) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := github_com_gogo_protobuf_proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestVoteCustomTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedVoteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestVoteTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedVoteType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestPartSetHeaderTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedPartSetHeaderType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestBlockIDTypeStringer(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBlockIDType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/types/vote.go b/types/vote.go index ad05d688d..8f2165bfa 100644 --- a/types/vote.go +++ b/types/vote.go @@ -2,10 +2,16 @@ package types import ( "bytes" + "encoding/json" "errors" "fmt" "time" + "github.com/gogo/protobuf/proto" + "github.com/gogo/protobuf/types" + "github.com/golang/protobuf/ptypes" + tspb "github.com/golang/protobuf/ptypes/timestamp" + "github.com/tendermint/tendermint/crypto" cmn "github.com/tendermint/tendermint/libs/common" ) @@ -159,3 +165,92 @@ func (vote *Vote) ValidateBasic() error { } return nil } + +func (vote Vote) toCustomType() VoteCustomType { + return VoteCustomType{Vote: &vote} +} +func (vote Vote) Equal(other Vote) bool { + proto := vote.toVoteType() + return proto.Equal(other.toVoteType()) +} + +func (vote *Vote) toVoteType() *VoteType { + proto := &VoteType{ + Type: uint32(vote.Type), + Height: vote.Height, + Round: int64(vote.Round), // TODO + BlockID: &BlockIDType{Hash: vote.BlockID.Hash, PartSetHeader: &PartSetHeaderType{Total: int64(vote.BlockID.PartsHeader.Total), Hash: vote.BlockID.PartsHeader.Hash.Bytes()}}, + TimestampField: &types.Timestamp{Seconds: int64(vote.Timestamp.Second()), Nanos: int32(vote.Timestamp.Nanosecond())}, + ValidatorAddress: vote.ValidatorAddress[:], + ValidatorIndex: int64(vote.ValidatorIndex), + Signature: vote.Signature, + } + return proto +} + +func fromVoteType(voteType *VoteType) *Vote { + vote := &Vote{} + if voteType != nil { + vote.Type = SignedMsgType(voteType.Type) + + vote.Height = voteType.Height + vote.Round = int(voteType.Round) // FIXME + vote.BlockID = BlockID{Hash: voteType.BlockID.Hash, PartsHeader: PartSetHeader{int(voteType.BlockID.PartSetHeader.Total), voteType.BlockID.PartSetHeader.Hash}} + ti, err := ptypes.Timestamp(&tspb.Timestamp{Seconds: voteType.TimestampField.Seconds, Nanos: voteType.TimestampField.Nanos}) + if err != nil { + panic(err) + } + vote.Timestamp = ti + vote.ValidatorAddress = voteType.ValidatorAddress + vote.ValidatorIndex = int(voteType.ValidatorIndex) // FIXME + + vote.Signature = voteType.Signature + } + + return vote +} + +func (vote *Vote) Size() int { + return vote.toVoteType().Size() +} + +func NewPopulatedVote(r randyTypes) *Vote { + data := NewPopulatedVoteType(r, false) + gt := fromVoteType(data) + return gt +} + +func (vote Vote) Marshal() ([]byte, error) { + vt := vote.toVoteType() + return proto.Marshal(vt) +} + +func (vote *Vote) Unmarshal(data []byte) error { + pr := &VoteType{} + err := proto.Unmarshal(data, pr) + if err != nil { + return err + } + + *vote = *fromVoteType(pr) + return nil +} + +func (vote Vote) MarshalJSON() ([]byte, error) { + return json.Marshal(vote) +} + +func (gt *Vote) UnmarshalJSON(data []byte) error { + var v Vote + err := json.Unmarshal(data, &v) + if err != nil { + return err + } + *gt = v + return nil +} + +func (gt Vote) Compare(other Vote) int { + // todo + return 1 +}