-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecord_test.go
48 lines (37 loc) · 1.53 KB
/
record_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
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package simplex_test
import (
"simplex"
"simplex/record"
"testing"
"github.com/stretchr/testify/require"
)
func newNotarizationRecord(logger simplex.Logger, signatureAggregator simplex.SignatureAggregator, block simplex.Block, ids []simplex.NodeID) ([]byte, error) {
votesForCurrentRound := make(map[string]*simplex.Vote)
for _, id := range ids {
vote, err := newTestVote(block, id)
if err != nil {
return nil, err
}
votesForCurrentRound[string(id)] = vote
}
notarization, err := simplex.NewNotarization(logger, signatureAggregator, votesForCurrentRound, block.BlockHeader())
if err != nil {
return nil, err
}
record := simplex.NewQuorumRecord(notarization.QC.Bytes(), notarization.Vote.Bytes(), record.NotarizationRecordType)
return record, nil
}
// creates a new finalization certificate
func newFinalizationRecord(t *testing.T, logger simplex.Logger, signatureAggregator simplex.SignatureAggregator, block simplex.Block, ids []simplex.NodeID) (simplex.FinalizationCertificate, []byte) {
finalizations := make([]*simplex.Finalization, len(ids))
for i, id := range ids {
testBlock := block.(*testBlock)
finalizations[i] = newTestFinalization(t, testBlock, id)
}
fCert, err := simplex.NewFinalizationCertificate(logger, signatureAggregator, finalizations)
require.NoError(t, err)
record := simplex.NewQuorumRecord(fCert.QC.Bytes(), fCert.Finalization.Bytes(), record.FinalizationRecordType)
return fCert, record
}