You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

7 years ago
  1. package types
  2. import (
  3. "testing"
  4. "github.com/tendermint/tendermint/types/proto3"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/golang/protobuf/proto"
  7. "time"
  8. )
  9. func TestProto3Compatibility(t *testing.T) {
  10. // TODO(ismail): table tests instead...
  11. tm, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006")
  12. assert.NoError(t, err)
  13. pbHeader := proto3.Header{
  14. ChainID: "cosmos",
  15. Height:150,
  16. Time: &proto3.Timestamp{Seconds:tm.Unix(), Nanos:int32(tm.Nanosecond())},
  17. NumTxs: 7,
  18. LastBlockID: &proto3.BlockID{
  19. Hash: []byte("some serious hashing"),
  20. PartsHeader:&proto3.PartSetHeader{
  21. Total: 8,
  22. Hash: []byte("some more serious hashing"),
  23. },
  24. },
  25. TotalTxs: 100,
  26. LastCommitHash: []byte("commit hash"),
  27. DataHash: []byte("data hash"),
  28. ValidatorsHash:[]byte("validators hash"),
  29. }
  30. // TODO(ismail): add another test where parts are missing (to see if default values are treated equiv.)
  31. aminoHeader := Header{
  32. ChainID: "cosmos",
  33. Height:150,
  34. Time: tm,
  35. NumTxs: 7,
  36. LastBlockID: BlockID{
  37. Hash: []byte("some serious hashing"),
  38. PartsHeader: PartSetHeader{
  39. Total: 8,
  40. Hash: []byte("some more serious hashing"),
  41. },
  42. },
  43. TotalTxs: 100,
  44. LastCommitHash: []byte("commit hash"),
  45. DataHash: []byte("data hash"),
  46. ValidatorsHash:[]byte("validators hash"),
  47. }
  48. ab, err := cdc.MarshalBinaryBare(aminoHeader)
  49. assert.NoError(t, err, "unexpected error")
  50. pb, err := proto.Marshal(&pbHeader)
  51. assert.NoError(t, err, "unexpected error")
  52. // This works:
  53. assert.Equal(t, ab, pb, "encoding doesn't match")
  54. }