tendermint/types/proposal_test.go

50 lines
1.3 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
2016-12-02 02:01:47 -08:00
expected := `{"chain_id":"test_chain_id","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_block_id":{},"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) {
2017-09-18 20:16:14 -07:00
privVal := GenPrivValidatorFS("")
2016-12-17 10:57:37 -08:00
for i := 0; i < b.N; i++ {
2017-09-21 08:42:44 -07:00
_, err := privVal.Signer.Sign(SignBytes("test_chain_id", testProposal))
if err != nil {
b.Error(err)
}
2016-12-17 10:57:37 -08:00
}
}
func BenchmarkProposalVerifySignature(b *testing.B) {
signBytes := SignBytes("test_chain_id", testProposal)
2017-09-18 20:16:14 -07:00
privVal := GenPrivValidatorFS("")
2017-09-18 15:12:31 -07:00
signature, _ := privVal.Signer.Sign(signBytes)
pubKey := privVal.GetPubKey()
2016-12-17 10:57:37 -08:00
for i := 0; i < b.N; i++ {
pubKey.VerifyBytes(SignBytes("test_chain_id", testProposal), signature)
}
}