forked from algorand/go-algorand
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage_test.go
82 lines (69 loc) · 2.53 KB
/
message_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2019 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.
package agreement
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/committee"
"github.com/algorand/go-algorand/protocol"
)
var poolAddr = basics.Address{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
func BenchmarkVoteDecoding(b *testing.B) {
oneTimeSecrets := crypto.GenerateOneTimeSignatureSecrets(300, 1000)
id := crypto.OneTimeSignatureIdentifier{
Batch: 1000,
// Avoid generating the last few offsets (in a batch size of 256), so we can increment correctly
Offset: crypto.RandUint64() % 250,
}
proposal := unauthenticatedProposal{
OriginalPeriod: period(crypto.RandUint64() % 250),
}
var vrfProof crypto.VRFProof
crypto.SystemRNG.RandBytes(vrfProof[:])
var sendAddr basics.Address
crypto.SystemRNG.RandBytes(sendAddr[:])
uv := unauthenticatedVote{
R: rawVote{
Sender: sendAddr,
Round: basics.Round(356),
Period: period(4),
Step: step(3),
Proposal: proposalValue{
OriginalPeriod: period(3),
OriginalProposer: poolAddr,
BlockDigest: crypto.Hash([]byte{1, 2, 3}),
EncodingDigest: crypto.Hash([]byte{5, 6, 7}),
},
},
Cred: committee.UnauthenticatedCredential{
Proof: vrfProof,
},
Sig: oneTimeSecrets.Sign(id, proposal),
}
msgBytes := protocol.Encode(&uv)
// make sure we know how to decode this correctly.
iVote, err := decodeVote(msgBytes)
require.Nil(b, err)
decodedVote := iVote.(unauthenticatedVote)
require.Equal(b, uv.R.Period, decodedVote.R.Period)
// and now, let's measure the performance.
b.ResetTimer()
for i := 0; i < b.N; i++ {
decodeVote(msgBytes)
}
}