diff --git a/types/vote.go b/types/vote.go index 8f2165bfa..fee463b8f 100644 --- a/types/vote.go +++ b/types/vote.go @@ -166,9 +166,6 @@ 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()) @@ -180,7 +177,7 @@ func (vote *Vote) toVoteType() *VoteType { 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())}, + TimestampField: &types.Timestamp{Seconds: int64(vote.Timestamp.Unix()), Nanos: int32(vote.Timestamp.Nanosecond())}, ValidatorAddress: vote.ValidatorAddress[:], ValidatorIndex: int64(vote.ValidatorIndex), Signature: vote.Signature, @@ -197,6 +194,8 @@ func fromVoteType(voteType *VoteType) *Vote { 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}) + ti = ti.UTC().Truncate(0) + fmt.Println("ti", ti) if err != nil { panic(err) } diff --git a/types/vote_test.go b/types/vote_test.go index af8a9625b..a7e958d02 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" amino "github.com/tendermint/go-amino" @@ -293,3 +294,21 @@ func TestVoteValidateBasic(t *testing.T) { }) } } + +func TestVoteEncodingRountrip(t *testing.T) { + // none of the below would pass validation: + now := time.Now().Truncate(0).UTC() + bid := BlockID{Hash: []byte("fake hash"), PartsHeader: PartSetHeader{0, []byte("another fake hash")}} + vote := &Vote{Height: 1, Round: 1, Type: PrevoteType, BlockID: bid, ValidatorAddress: []byte("no real addr"), Timestamp: now, Signature: []byte("totaly_fake_sig")} + + bz, err := proto.Marshal(&VoteCustomType{vote}) + if err != nil { + panic(err) + } + vct := &VoteCustomType{} + err = proto.Unmarshal(bz, vct) + if err != nil { + panic(err) + } + require.Equal(t, vct.Vote, vote) +}