2015-08-10 20:38:45 -07:00
|
|
|
package types
|
2015-04-27 20:55:28 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-12-17 13:57:37 -05: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 13:57:37 -05: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 05:01:47 -05: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 {
|
2016-08-20 15:08:26 -07:00
|
|
|
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 13:57:37 -05: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 23:16:14 -04:00
|
|
|
privVal := GenPrivValidatorFS("")
|
2016-12-17 13:57:37 -05:00
|
|
|
for i := 0; i < b.N; i++ {
|
2017-09-18 18:12:31 -04:00
|
|
|
privVal.Signer.Sign(SignBytes("test_chain_id", testProposal))
|
2016-12-17 13:57:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkProposalVerifySignature(b *testing.B) {
|
|
|
|
signBytes := SignBytes("test_chain_id", testProposal)
|
2017-09-18 23:16:14 -04:00
|
|
|
privVal := GenPrivValidatorFS("")
|
2017-09-18 18:12:31 -04:00
|
|
|
signature, _ := privVal.Signer.Sign(signBytes)
|
|
|
|
pubKey := privVal.PubKey()
|
2016-12-17 13:57:37 -05:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
pubKey.VerifyBytes(SignBytes("test_chain_id", testProposal), signature)
|
|
|
|
}
|
|
|
|
}
|