-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_funcs.go
71 lines (59 loc) · 2.34 KB
/
test_funcs.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
/*
github.com/tcrain/cons - Experimental project for testing and scaling consensus algorithms.
Copyright (C) 2020 The project authors - tcrain
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package bincons1
import (
"github.com/tcrain/cons/consensus/deserialized"
"github.com/tcrain/cons/consensus/types"
"testing"
"github.com/tcrain/cons/consensus/auth/sig"
"github.com/tcrain/cons/consensus/cons"
"github.com/tcrain/cons/consensus/messages"
"github.com/tcrain/cons/consensus/messagetypes"
)
// CreateAuxProofItems is used during unit tests to create a list of signed message supporting a binvalue and round.
func CreateAuxProofItems(idx types.ConsensusIndex, round types.ConsensusRound, binVal types.BinVal, bct cons.ConsTestItems, t *testing.T) []*deserialized.DeserializedItem {
ret := make([]*deserialized.DeserializedItem, len(bct.PrivKeys))
for i := range bct.PrivKeys {
priv := bct.PrivKeys[i]
inHdr := messagetypes.NewAuxProofMessage(false)
inHdr.Round = round
inHdr.BinVal = binVal
hdr := sig.NewMultipleSignedMsg(idx, priv.GetPub(), inHdr)
if _, err := hdr.Serialize(messages.NewMessage(nil)); err != nil {
panic(err)
}
mySig, err := priv.GenerateSig(hdr, nil, hdr.GetSignType())
if err != nil {
panic(err)
}
hdr.SetSigItems([]*sig.SigItem{mySig})
hdrs := make([]messages.MsgHeader, 1)
hdrs[0] = hdr
msg := messages.InitMsgSetup(hdrs, t)
encMsg := sig.NewUnencodedMsg(msg)
dser := sig.NewMultipleSignedMsg(idx, priv.GetPub(), messagetypes.NewAuxProofMessage(false))
_, err = (dser).Deserialize(msg, types.IntIndexFuns)
if err != nil {
t.Error(err)
}
ret[i] = &deserialized.DeserializedItem{
Index: idx,
HeaderType: messages.HdrAuxProof,
Header: dser,
IsDeserialized: true,
Message: encMsg}
}
return ret
}