-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
438 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package test_env | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"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" | ||
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" | ||
) | ||
|
||
const ( | ||
defaultRethEth2Image = "ghcr.io/paradigmxyz/reth:v1.0.0" | ||
rethBaseImageName = "ghcr.io/paradigmxyz/reth" | ||
rethGitRepo = "paradigmxyz/reth" | ||
) | ||
|
||
type Reth 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 *Reth) WithTestInstance(t *testing.T) ExecutionClient { | ||
g.l = logging.GetTestLogger(t) | ||
g.t = t | ||
return g | ||
} | ||
|
||
func (g *Reth) StartContainer() (blockchain.EVMNetwork, error) { | ||
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 { | ||
return blockchain.EVMNetwork{}, errors.New(config.Eth1NotSupportedByRethMsg) | ||
} | ||
|
||
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 reth container: %w", err) | ||
} | ||
|
||
host, err := GetHost(testcontext.Get(g.t), ct) | ||
if err != nil { | ||
return blockchain.EVMNetwork{}, err | ||
} | ||
httpPort, err := ct.MappedPort(testcontext.Get(g.t), NatPort(DEFAULT_EVM_NODE_HTTP_PORT)) | ||
if err != nil { | ||
return blockchain.EVMNetwork{}, err | ||
} | ||
|
||
wsPort, err := ct.MappedPort(testcontext.Get(g.t), NatPort(DEFAULT_EVM_NODE_WS_PORT)) | ||
if err != nil { | ||
return blockchain.EVMNetwork{}, err | ||
} | ||
|
||
if g.GetEthereumVersion() == config.EthereumVersion_Eth2 { | ||
executionPort, err := ct.MappedPort(testcontext.Get(g.t), 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-PoW [reth %s]", g.ContainerVersion) | ||
} else { | ||
networkConfig.Name = fmt.Sprintf("Private Eth-2-PoS [reth %s] + %s", g.ContainerVersion, g.consensusLayer) | ||
} | ||
networkConfig.URLs = []string{g.ExternalWsUrl} | ||
networkConfig.HTTPURLs = []string{g.ExternalHttpUrl} | ||
networkConfig.SimulationType = "Reth" | ||
|
||
g.l.Info().Str("containerName", g.ContainerName). | ||
Msg("Started Reth container") | ||
|
||
return networkConfig, nil | ||
} | ||
|
||
func (g *Reth) GetInternalExecutionURL() string { | ||
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 { | ||
panic("eth1 node doesn't have an execution URL") | ||
} | ||
return g.InternalExecutionURL | ||
} | ||
|
||
func (g *Reth) GetExternalExecutionURL() string { | ||
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 { | ||
panic("eth1 node doesn't have an execution URL") | ||
} | ||
return g.ExternalExecutionURL | ||
} | ||
|
||
func (g *Reth) GetInternalHttpUrl() string { | ||
return g.InternalHttpUrl | ||
} | ||
|
||
func (g *Reth) GetInternalWsUrl() string { | ||
return g.InternalWsUrl | ||
} | ||
|
||
func (g *Reth) GetExternalHttpUrl() string { | ||
return g.ExternalHttpUrl | ||
} | ||
|
||
func (g *Reth) GetExternalWsUrl() string { | ||
return g.ExternalWsUrl | ||
} | ||
|
||
func (g *Reth) GetContainerName() string { | ||
return g.ContainerName | ||
} | ||
|
||
func (g *Reth) GetContainer() *tc.Container { | ||
return &g.Container | ||
} | ||
|
||
func (g *Reth) GetEthereumVersion() config.EthereumVersion { | ||
return g.ethereumVersion | ||
} | ||
|
||
func (g *Reth) WaitUntilChainIsReady(ctx context.Context, waitTime time.Duration) error { | ||
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 { | ||
return nil | ||
} | ||
waitForFirstBlock := tcwait.NewLogStrategy("Block added to canonical chain").WithPollInterval(1 * time.Second).WithStartupTimeout(waitTime) | ||
return waitForFirstBlock.WaitUntilReady(ctx, *g.GetContainer()) | ||
} | ||
|
||
func (g *Reth) GethConsensusMechanism() ConsensusMechanism { | ||
if g.GetEthereumVersion() == config.EthereumVersion_Eth1 { | ||
return ConsensusMechanism_PoW | ||
} | ||
return ConsensusMechanism_PoS | ||
} |
Oops, something went wrong.