tendermint/types/proposal_test.go

47 lines
1.2 KiB
Go
Raw Normal View History

package types
2015-04-27 20:55:28 -07:00
import (
"testing"
)
2016-12-17 10:57:37 -08:00
var testProposal = &Proposal{
Height: 12345,
Round: 23456,
BlockPartsHeader: PartSetHeader{111, []byte("blockparts")},
POLRound: -1,
}
2015-04-27 20:55:28 -07:00
func TestProposalSignable(t *testing.T) {
2016-12-17 10:57:37 -08:00
signBytes := SignBytes("test_chain_id", testProposal)
2015-04-27 20:55:28 -07:00
signStr := string(signBytes)
2015-06-24 14:04:40 -07:00
expected := `{"chain_id":"test_chain_id","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_block_id":null,"pol_round":-1,"round":23456}}`
2015-04-27 20:55:28 -07:00
if signStr != expected {
t.Errorf("Got unexpected sign string for Proposal. Expected:\n%v\nGot:\n%v", expected, signStr)
2015-04-27 20:55:28 -07:00
}
}
2016-12-17 10:57:37 -08:00
func BenchmarkProposalWriteSignBytes(b *testing.B) {
for i := 0; i < b.N; i++ {
SignBytes("test_chain_id", testProposal)
}
}
func BenchmarkProposalSign(b *testing.B) {
privVal := GenPrivValidator()
for i := 0; i < b.N; i++ {
privVal.Sign(SignBytes("test_chain_id", testProposal))
}
}
func BenchmarkProposalVerifySignature(b *testing.B) {
signBytes := SignBytes("test_chain_id", testProposal)
privVal := GenPrivValidator()
signature := privVal.Sign(signBytes)
pubKey := privVal.PubKey
for i := 0; i < b.N; i++ {
pubKey.VerifyBytes(SignBytes("test_chain_id", testProposal), signature)
}
}