forked from ssvlabs/ssv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_test.go
70 lines (54 loc) · 1.51 KB
/
setup_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
package tests
import (
"context"
"testing"
spectypes "github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"github.com/bloxapp/ssv/logging"
"github.com/bloxapp/ssv/network"
p2pv1 "github.com/bloxapp/ssv/network/p2p"
"github.com/bloxapp/ssv/protocol/v2/types"
)
const (
maxSupportedCommittee = 10
maxSupportedQuorum = 7
)
var sharedData *SharedData
type SharedData struct {
Nodes map[spectypes.OperatorID]network.P2PNetwork
}
func GetSharedData(t *testing.T) SharedData { //singleton B-)
require.NotNil(t, sharedData, "shared data hadn't set up, try to run test with -test.main flag")
return *sharedData
}
func TestMain(m *testing.M) {
ctx := context.Background()
if err := logging.SetGlobalLogger("debug", "capital", "console", nil); err != nil {
panic(err)
}
logger := zap.L().Named("integration-tests")
types.SetDefaultDomain(testingutils.TestingSSVDomainType)
ln, err := p2pv1.CreateAndStartLocalNet(ctx, logger, p2pv1.LocalNetOptions{
Nodes: maxSupportedCommittee,
MinConnected: maxSupportedQuorum,
UseDiscv5: false,
})
if err != nil {
logger.Fatal("error creating and start local net", zap.Error(err))
return
}
nodes := map[spectypes.OperatorID]network.P2PNetwork{}
for i := 0; i < len(ln.Nodes); i++ {
nodes[spectypes.OperatorID(i+1)] = ln.Nodes[i]
}
sharedData = &SharedData{
Nodes: nodes,
}
m.Run()
//teardown
for i := 0; i < len(ln.Nodes); i++ {
_ = ln.Nodes[i].Close()
}
}