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.

39 lines
1.2 KiB

  1. package types
  2. import (
  3. "reflect"
  4. "testing"
  5. "github.com/tendermint/tendermint/crypto/tmhash"
  6. tmrand "github.com/tendermint/tendermint/libs/rand"
  7. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  8. )
  9. func TestCanonicalizeBlockID(t *testing.T) {
  10. randhash := tmrand.Bytes(tmhash.Size)
  11. block1 := tmproto.BlockID{Hash: randhash,
  12. PartSetHeader: tmproto.PartSetHeader{Total: 5, Hash: randhash}}
  13. block2 := tmproto.BlockID{Hash: randhash,
  14. PartSetHeader: tmproto.PartSetHeader{Total: 10, Hash: randhash}}
  15. cblock1 := tmproto.CanonicalBlockID{Hash: randhash,
  16. PartSetHeader: tmproto.CanonicalPartSetHeader{Total: 5, Hash: randhash}}
  17. cblock2 := tmproto.CanonicalBlockID{Hash: randhash,
  18. PartSetHeader: tmproto.CanonicalPartSetHeader{Total: 10, Hash: randhash}}
  19. tests := []struct {
  20. name string
  21. args tmproto.BlockID
  22. want *tmproto.CanonicalBlockID
  23. }{
  24. {"first", block1, &cblock1},
  25. {"second", block2, &cblock2},
  26. }
  27. for _, tt := range tests {
  28. tt := tt
  29. t.Run(tt.name, func(t *testing.T) {
  30. if got := CanonicalizeBlockID(tt.args); !reflect.DeepEqual(got, tt.want) {
  31. t.Errorf("CanonicalizeBlockID() = %v, want %v", got, tt.want)
  32. }
  33. })
  34. }
  35. }