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.

37 lines
1023 B

  1. package types
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestVoteSignable(t *testing.T) {
  7. var stamp, err = time.Parse(timeFormat, "2017-12-25T03:00:01.234Z")
  8. if err != nil {
  9. t.Fatal(err)
  10. }
  11. vote := &Vote{
  12. ValidatorAddress: []byte("addr"),
  13. ValidatorIndex: 56789,
  14. Height: 12345,
  15. Round: 23456,
  16. Timestamp: stamp,
  17. Type: byte(2),
  18. BlockID: BlockID{
  19. Hash: []byte("hash"),
  20. PartsHeader: PartSetHeader{
  21. Total: 1000000,
  22. Hash: []byte("parts_hash"),
  23. },
  24. },
  25. }
  26. signBytes := SignBytes("test_chain_id", vote)
  27. signStr := string(signBytes)
  28. expected := `{"chain_id":"test_chain_id","vote":{"block_id":{"hash":"68617368","parts":{"hash":"70617274735F68617368","total":1000000}},"height":12345,"round":23456,"timestamp":"2017-12-25T03:00:01.234Z","type":2}}`
  29. if signStr != expected {
  30. // NOTE: when this fails, you probably want to fix up consensus/replay_test too
  31. t.Errorf("Got unexpected sign string for Vote. Expected:\n%v\nGot:\n%v", expected, signStr)
  32. }
  33. }