mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-31 04:01:55 +00:00
types: tests build
This commit is contained in:
@@ -26,7 +26,7 @@ func init() {
|
||||
}
|
||||
|
||||
func TestProposalSignable(t *testing.T) {
|
||||
signBytes := SignBytes("test_chain_id", testProposal)
|
||||
signBytes := testProposal.SignBytes("test_chain_id")
|
||||
signStr := string(signBytes)
|
||||
|
||||
expected := `{"chain_id":"test_chain_id","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_block_id":{},"pol_round":-1,"round":23456,"timestamp":"2018-02-11T07:09:22.765Z"}}`
|
||||
@@ -48,24 +48,25 @@ func TestProposalVerifySignature(t *testing.T) {
|
||||
pubKey := privVal.GetPubKey()
|
||||
|
||||
prop := NewProposal(4, 2, PartSetHeader{777, []byte("proper")}, 2, BlockID{})
|
||||
signBytes := SignBytes("test_chain_id", prop)
|
||||
signBytes := prop.SignBytes("test_chain_id")
|
||||
|
||||
// sign it
|
||||
signature, err := privVal.Signer.Sign(signBytes)
|
||||
require.NoError(t, err)
|
||||
|
||||
// verify the same proposal
|
||||
valid := pubKey.VerifyBytes(SignBytes("test_chain_id", prop), signature)
|
||||
valid := pubKey.VerifyBytes(prop.SignBytes("test_chain_id"), signature)
|
||||
require.True(t, valid)
|
||||
|
||||
// serialize, deserialize and verify again....
|
||||
newProp := new(Proposal)
|
||||
bs := wire.BinaryBytes(prop)
|
||||
err = wire.ReadBinaryBytes(bs, &newProp)
|
||||
bs, err := wire.MarshalBinary(prop)
|
||||
require.NoError(t, err)
|
||||
err = wire.UnmarshalBinary(bs, &newProp)
|
||||
require.NoError(t, err)
|
||||
|
||||
// verify the transmitted proposal
|
||||
newSignBytes := SignBytes("test_chain_id", newProp)
|
||||
newSignBytes := newProp.SignBytes("test_chain_id")
|
||||
require.Equal(t, string(signBytes), string(newSignBytes))
|
||||
valid = pubKey.VerifyBytes(newSignBytes, signature)
|
||||
require.True(t, valid)
|
||||
@@ -73,14 +74,14 @@ func TestProposalVerifySignature(t *testing.T) {
|
||||
|
||||
func BenchmarkProposalWriteSignBytes(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
SignBytes("test_chain_id", testProposal)
|
||||
testProposal.SignBytes("test_chain_id")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkProposalSign(b *testing.B) {
|
||||
privVal := GenPrivValidatorFS("")
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := privVal.Signer.Sign(SignBytes("test_chain_id", testProposal))
|
||||
_, err := privVal.Signer.Sign(testProposal.SignBytes("test_chain_id"))
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
@@ -88,12 +89,12 @@ func BenchmarkProposalSign(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkProposalVerifySignature(b *testing.B) {
|
||||
signBytes := SignBytes("test_chain_id", testProposal)
|
||||
signBytes := testProposal.SignBytes("test_chain_id")
|
||||
privVal := GenPrivValidatorFS("")
|
||||
signature, _ := privVal.Signer.Sign(signBytes)
|
||||
pubKey := privVal.GetPubKey()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
pubKey.VerifyBytes(SignBytes("test_chain_id", testProposal), signature)
|
||||
pubKey.VerifyBytes(testProposal.SignBytes("test_chain_id"), signature)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user