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.

46 lines
1.3 KiB

10 years ago
7 years ago
7 years ago
  1. package types
  2. import (
  3. "testing"
  4. )
  5. var testProposal = &Proposal{
  6. Height: 12345,
  7. Round: 23456,
  8. BlockPartsHeader: PartSetHeader{111, []byte("blockparts")},
  9. POLRound: -1,
  10. }
  11. func TestProposalSignable(t *testing.T) {
  12. signBytes := SignBytes("test_chain_id", testProposal)
  13. signStr := string(signBytes)
  14. expected := `{"chain_id":"test_chain_id","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_block_id":{},"pol_round":-1,"round":23456}}`
  15. if signStr != expected {
  16. t.Errorf("Got unexpected sign string for Proposal. Expected:\n%v\nGot:\n%v", expected, signStr)
  17. }
  18. }
  19. func BenchmarkProposalWriteSignBytes(b *testing.B) {
  20. for i := 0; i < b.N; i++ {
  21. SignBytes("test_chain_id", testProposal)
  22. }
  23. }
  24. func BenchmarkProposalSign(b *testing.B) {
  25. privVal := GenPrivValidatorFS("")
  26. for i := 0; i < b.N; i++ {
  27. privVal.Signer.Sign(SignBytes("test_chain_id", testProposal))
  28. }
  29. }
  30. func BenchmarkProposalVerifySignature(b *testing.B) {
  31. signBytes := SignBytes("test_chain_id", testProposal)
  32. privVal := GenPrivValidatorFS("")
  33. signature, _ := privVal.Signer.Sign(signBytes)
  34. pubKey := privVal.GetPubKey()
  35. for i := 0; i < b.N; i++ {
  36. pubKey.VerifyBytes(SignBytes("test_chain_id", testProposal), signature)
  37. }
  38. }