-
Notifications
You must be signed in to change notification settings - Fork 36
/
nethermind_base.go
172 lines (145 loc) · 5.04 KB
/
nethermind_base.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package test_env
import (
"context"
"fmt"
"testing"
"time"
"github.com/rs/zerolog"
tc "github.com/testcontainers/testcontainers-go"
tcwait "github.com/testcontainers/testcontainers-go/wait"
"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/config"
"github.com/smartcontractkit/chainlink-testing-framework/docker"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
)
const (
defaultNethermindEth1Image = "nethermind/nethermind:1.16.0"
defaultNethermindEth2Image = "nethermind/nethermind:1.25.1"
nethermindBaseImageName = "nethermind/nethermind"
nethermindGitRepo = "NethermindEth/nethermind"
)
type Nethermind struct {
EnvComponent
ExternalHttpUrl string
InternalHttpUrl string
ExternalWsUrl string
InternalWsUrl string
InternalExecutionURL string
ExternalExecutionURL string
generatedDataHostDir string
chainConfig *config.EthereumChainConfig
consensusLayer config.ConsensusLayer
ethereumVersion config.EthereumVersion
l zerolog.Logger
t *testing.T
}
func (g *Nethermind) WithTestInstance(t *testing.T) ExecutionClient {
g.l = logging.GetTestLogger(t)
g.t = t
return g
}
func (g *Nethermind) StartContainer() (blockchain.EVMNetwork, error) {
var r *tc.ContainerRequest
var err error
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 {
r, err = g.getEth1ContainerRequest()
} else {
r, err = g.getEth2ContainerRequest()
}
if err != nil {
return blockchain.EVMNetwork{}, err
}
l := logging.GetTestContainersGoTestLogger(g.t)
ct, err := docker.StartContainerWithRetry(g.l, tc.GenericContainerRequest{
ContainerRequest: *r,
Reuse: g.WasRecreated,
Started: true,
Logger: l,
})
if err != nil {
return blockchain.EVMNetwork{}, fmt.Errorf("cannot start nethermind container: %w", err)
}
host, err := GetHost(context.Background(), ct)
if err != nil {
return blockchain.EVMNetwork{}, err
}
httpPort, err := ct.MappedPort(context.Background(), NatPort(DEFAULT_EVM_NODE_HTTP_PORT))
if err != nil {
return blockchain.EVMNetwork{}, err
}
wsPort, err := ct.MappedPort(context.Background(), NatPort(DEFAULT_EVM_NODE_WS_PORT))
if err != nil {
return blockchain.EVMNetwork{}, err
}
if g.GetEthereumVersion() == config.EthereumVersion_Eth2 {
executionPort, err := ct.MappedPort(context.Background(), NatPort(ETH2_EXECUTION_PORT))
if err != nil {
return blockchain.EVMNetwork{}, err
}
g.InternalExecutionURL = FormatHttpUrl(g.ContainerName, ETH2_EXECUTION_PORT)
g.ExternalExecutionURL = FormatHttpUrl(host, executionPort.Port())
}
g.Container = ct
g.ExternalHttpUrl = FormatHttpUrl(host, httpPort.Port())
g.InternalHttpUrl = FormatHttpUrl(g.ContainerName, DEFAULT_EVM_NODE_HTTP_PORT)
g.ExternalWsUrl = FormatWsUrl(host, wsPort.Port())
g.InternalWsUrl = FormatWsUrl(g.ContainerName, DEFAULT_EVM_NODE_WS_PORT)
networkConfig := blockchain.SimulatedEVMNetwork
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 {
networkConfig.Name = fmt.Sprintf("Private Eth-1-PoA [nethermind %s", g.ContainerVersion)
networkConfig.GasEstimationBuffer = 100_000_000_000
} else {
networkConfig.Name = fmt.Sprintf("Private Eth-2-PoS [nethermind %s] + %s", g.ContainerVersion, g.consensusLayer)
}
networkConfig.URLs = []string{g.ExternalWsUrl}
networkConfig.HTTPURLs = []string{g.ExternalHttpUrl}
g.l.Info().Str("containerName", g.ContainerName).
Msg("Started Nethermind container")
return networkConfig, nil
}
func (g *Nethermind) GetInternalExecutionURL() string {
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 {
panic("eth1 node doesn't have an execution URL")
}
return g.InternalExecutionURL
}
func (g *Nethermind) GetExternalExecutionURL() string {
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 {
panic("eth1 node doesn't have an execution URL")
}
return g.ExternalExecutionURL
}
func (g *Nethermind) GetInternalHttpUrl() string {
return g.InternalHttpUrl
}
func (g *Nethermind) GetInternalWsUrl() string {
return g.InternalWsUrl
}
func (g *Nethermind) GetExternalHttpUrl() string {
return g.ExternalHttpUrl
}
func (g *Nethermind) GetExternalWsUrl() string {
return g.ExternalWsUrl
}
func (g *Nethermind) GetContainerName() string {
return g.ContainerName
}
func (g *Nethermind) GetContainer() *tc.Container {
return &g.Container
}
func (g *Nethermind) GetEthereumVersion() config.EthereumVersion {
return g.ethereumVersion
}
func (g *Nethermind) WaitUntilChainIsReady(ctx context.Context, waitTime time.Duration) error {
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 {
return nil
}
waitForFirstBlock := tcwait.NewLogStrategy("Improved post-merge block").WithPollInterval(1 * time.Second).WithStartupTimeout(waitTime)
return waitForFirstBlock.WaitUntilReady(ctx, *g.GetContainer())
}
func (g *Nethermind) GethConsensusMechanism() ConsensusMechanism {
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 {
return ConsensusMechanism_PoA
}
return ConsensusMechanism_PoS
}