/
sync_committee_aggregator_proof_type.go
85 lines (72 loc) · 2.73 KB
/
sync_committee_aggregator_proof_type.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
83
84
85
package spectest
import (
"encoding/hex"
"path/filepath"
"reflect"
"strings"
"testing"
"github.com/bloxapp/ssv-spec/ssv/spectest/tests/runner/duties/synccommitteeaggregator"
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
typescomparable "github.com/bloxapp/ssv-spec/types/testingutils/comparable"
"github.com/stretchr/testify/require"
"github.com/bloxapp/ssv/logging"
"github.com/bloxapp/ssv/protocol/v2/ssv/queue"
"github.com/bloxapp/ssv/protocol/v2/ssv/runner"
ssvtesting "github.com/bloxapp/ssv/protocol/v2/ssv/testing"
protocoltesting "github.com/bloxapp/ssv/protocol/v2/testing"
)
func RunSyncCommitteeAggProof(t *testing.T, test *synccommitteeaggregator.SyncCommitteeAggregatorProofSpecTest) {
overrideStateComparisonForSyncCommitteeAggregatorProofSpecTest(t, test, test.Name)
ks := testingutils.Testing4SharesSet()
share := testingutils.TestingShare(ks)
logger := logging.TestLogger(t)
v := ssvtesting.BaseValidator(logger, keySetForShare(share))
r := v.DutyRunners[types.BNRoleSyncCommitteeContribution]
r.GetBeaconNode().(*testingutils.TestingBeaconNode).SetSyncCommitteeAggregatorRootHexes(test.ProofRootsMap)
lastErr := v.StartDuty(logger, &testingutils.TestingSyncCommitteeContributionDuty)
for _, msg := range test.Messages {
dmsg, err := queue.DecodeSSVMessage(msg)
if err != nil {
lastErr = err
continue
}
err = v.ProcessMessage(logger, dmsg)
if err != nil {
lastErr = err
}
}
if len(test.ExpectedError) != 0 {
require.EqualError(t, lastErr, test.ExpectedError)
} else {
require.NoError(t, lastErr)
}
// post root
postRoot, err := r.GetBaseRunner().State.GetRoot()
require.NoError(t, err)
require.EqualValues(t, test.PostDutyRunnerStateRoot, hex.EncodeToString(postRoot[:]))
}
func overrideStateComparisonForSyncCommitteeAggregatorProofSpecTest(t *testing.T, test *synccommitteeaggregator.SyncCommitteeAggregatorProofSpecTest, name string) {
testType := reflect.TypeOf(test).String()
testType = strings.Replace(testType, "spectest.", "synccommitteeaggregator.", 1)
runnerState := &runner.State{}
specDir, err := protocoltesting.GetSpecDir("", filepath.Join("ssv", "spectest"))
require.NoError(t, err)
runnerState, err = typescomparable.UnmarshalStateComparison(specDir, name, testType, runnerState)
require.NoError(t, err)
root, err := runnerState.GetRoot()
require.NoError(t, err)
test.PostDutyRunnerStateRoot = hex.EncodeToString(root[:])
}
func keySetForShare(share *types.Share) *testingutils.TestKeySet {
if share.Quorum == 5 {
return testingutils.Testing7SharesSet()
}
if share.Quorum == 7 {
return testingutils.Testing10SharesSet()
}
if share.Quorum == 9 {
return testingutils.Testing13SharesSet()
}
return testingutils.Testing4SharesSet()
}