Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TT-414] Test Env E2E Builder Changes for Non EVM Chains #10753

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions integration-tests/docker/test_env/test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,23 @@ func NewTestEnv() (*CLClusterTestEnv, error) {
if err != nil {
return nil, err
}
networks := []string{network.Name}
n := []string{network.Name}
return &CLClusterTestEnv{
Geth: test_env.NewGeth(n),
MockServer: test_env.NewMockServer(n),
Network: network,
Geth: test_env.NewGeth(networks),
MockServer: test_env.NewMockServer(networks),
l: log.Logger,
}, nil
}

func (te *CLClusterTestEnv) WithTestEnvConfig(cfg *TestEnvConfig) *CLClusterTestEnv {
tateexon marked this conversation as resolved.
Show resolved Hide resolved
te.Cfg = cfg
n := []string{te.Network.Name}
te.Geth = test_env.NewGeth(n, test_env.WithContainerName(cfg.Geth.ContainerName))
te.MockServer = test_env.NewMockServer(n, test_env.WithContainerName(cfg.MockServer.ContainerName))
Copy link
Collaborator

@lukaszcl lukaszcl Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tateexon Is there an option to just pass cfg.MockServer.ContainerName as param? test_env.NewMockServer(n, cfg.MockServer.ContainerName)? This would make it simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya we can do that. Would be a separate ticket that deals with CTF changes since these methods and patterns would need to be changed there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, ok!

return te
}

func (te *CLClusterTestEnv) WithTestLogger(t *testing.T) *CLClusterTestEnv {
te.t = t
te.l = logging.GetTestLogger(t)
Expand All @@ -76,23 +84,6 @@ func (te *CLClusterTestEnv) WithTestLogger(t *testing.T) *CLClusterTestEnv {
return te
}

func NewTestEnvFromCfg(l zerolog.Logger, cfg *TestEnvConfig) (*CLClusterTestEnv, error) {
utils.SetupCoreDockerEnvLogger()
network, err := docker.CreateNetwork(log.Logger)
if err != nil {
return nil, err
}
networks := []string{network.Name}
l.Info().Interface("Cfg", cfg).Send()
return &CLClusterTestEnv{
Cfg: cfg,
Network: network,
Geth: test_env.NewGeth(networks, test_env.WithContainerName(cfg.Geth.ContainerName)),
MockServer: test_env.NewMockServer(networks, test_env.WithContainerName(cfg.MockServer.ContainerName)),
l: log.Logger,
}, nil
}

func (te *CLClusterTestEnv) ParallelTransactions(enabled bool) {
te.EVMClient.ParallelTransactions(enabled)
}
Expand Down Expand Up @@ -123,7 +114,7 @@ func (te *CLClusterTestEnv) StartPrivateChain() error {
for _, chain := range te.PrivateChain {
primaryNode := chain.GetPrimaryNode()
if primaryNode == nil {
return errors.WithStack(fmt.Errorf("Primary node is nil in PrivateChain interface"))
return errors.WithStack(fmt.Errorf("primary node is nil in PrivateChain interface"))
}
err := primaryNode.Start()
if err != nil {
Expand Down
148 changes: 82 additions & 66 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type CLTestEnvBuilder struct {
defaultNodeCsaKeys []string
l zerolog.Logger
t *testing.T
te *CLClusterTestEnv
isNonEVM bool

/* funding */
ETHFunds *big.Float
Expand All @@ -46,6 +48,32 @@ func NewCLTestEnvBuilder() *CLTestEnvBuilder {
}
}

func (b *CLTestEnvBuilder) WithTestEnv(te *CLClusterTestEnv) (*CLTestEnvBuilder, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tateexon what this function does? Creates builder from config file? If yes, maybe it should not be CLTestEnvBuilder method but a normal function? And maybe a better name could be sth like "NewTestEnvBuilderFromConfig()`?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a comment to the function but I intend it to be used just like any of the other With commands except this one needs some error handling. We had handling of the CLClusterTestEnv configuration spread out and unable to easily be changed and used outside of EVM use cases so this just bundles it up into one place and exposes it as part of the builder chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

envConfigPath, isSet := os.LookupEnv("TEST_ENV_CONFIG_PATH")
var cfg *TestEnvConfig
var err error
if isSet {
cfg, err = NewTestEnvConfigFromFile(envConfigPath)
if err != nil {
return nil, err
}
}

if te != nil {
b.te = te
} else {
b.te, err = NewTestEnv()
if err != nil {
return nil, err
}
}

if cfg != nil {
b.te = b.te.WithTestEnvConfig(cfg)
}
return b, nil
}

func (b *CLTestEnvBuilder) WithTestLogger(t *testing.T) *CLTestEnvBuilder {
b.t = t
b.l = logging.GetTestLogger(t)
Expand Down Expand Up @@ -93,20 +121,19 @@ func (b *CLTestEnvBuilder) WithMockServer(externalAdapterCount int) *CLTestEnvBu
return b
}

func (b *CLTestEnvBuilder) WithNonEVM() *CLTestEnvBuilder {
b.isNonEVM = true
return b
}

func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
envConfigPath, isSet := os.LookupEnv("TEST_ENV_CONFIG_PATH")
if isSet {
cfg, err := NewTestEnvConfigFromFile(envConfigPath)
if b.te == nil {
var err error
b, err = b.WithTestEnv(nil)
if err != nil {
return nil, err
}
_ = os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true")
return b.buildNewEnv(cfg)
}
return b.buildNewEnv(nil)
}

func (b *CLTestEnvBuilder) buildNewEnv(cfg *TestEnvConfig) (*CLClusterTestEnv, error) {
b.l.Info().
Bool("hasGeth", b.hasGeth).
Bool("hasMockServer", b.hasMockServer).
Expand All @@ -116,52 +143,39 @@ func (b *CLTestEnvBuilder) buildNewEnv(cfg *TestEnvConfig) (*CLClusterTestEnv, e
Strs("defaultNodeCsaKeys", b.defaultNodeCsaKeys).
Msg("Building CL cluster test environment..")

var te *CLClusterTestEnv
var err error
if cfg != nil {
te, err = NewTestEnvFromCfg(b.l, cfg)
if err != nil {
return nil, err
}
} else {
te, err = NewTestEnv()
if err != nil {
return nil, err
}
}

if b.t != nil {
te.WithTestLogger(b.t)
b.te.WithTestLogger(b.t)
}

if b.hasLogWatch {
te.LogWatch, err = logwatch.NewLogWatch(nil, nil)
b.te.LogWatch, err = logwatch.NewLogWatch(nil, nil)
if err != nil {
return nil, err
}
}

if b.hasMockServer {
err = te.StartMockServer()
err = b.te.StartMockServer()
if err != nil {
return nil, err
}
err = te.MockServer.SetExternalAdapterMocks(b.externalAdapterCount)
err = b.te.MockServer.SetExternalAdapterMocks(b.externalAdapterCount)
if err != nil {
return nil, err
}
}
if b.nonDevGethNetworks != nil {
te.WithPrivateChain(b.nonDevGethNetworks)
err := te.StartPrivateChain()
b.te.WithPrivateChain(b.nonDevGethNetworks)
err := b.te.StartPrivateChain()
if err != nil {
return te, err
return b.te, err
}
var nonDevNetworks []blockchain.EVMNetwork
for i, n := range te.PrivateChain {
for i, n := range b.te.PrivateChain {
primaryNode := n.GetPrimaryNode()
if primaryNode == nil {
return te, errors.WithStack(fmt.Errorf("Primary node is nil in PrivateChain interface"))
return b.te, errors.WithStack(fmt.Errorf("primary node is nil in PrivateChain interface"))
}
nonDevNetworks = append(nonDevNetworks, *n.GetNetworkConfig())
nonDevNetworks[i].URLs = []string{primaryNode.GetInternalWsUrl()}
Expand All @@ -171,40 +185,41 @@ func (b *CLTestEnvBuilder) buildNewEnv(cfg *TestEnvConfig) (*CLClusterTestEnv, e
return nil, errors.New("cannot create nodes with custom config without nonDevNetworks")
}

err = te.StartClNodes(b.clNodeConfig, b.clNodesCount)
err = b.te.StartClNodes(b.clNodeConfig, b.clNodesCount)
if err != nil {
return nil, err
}
return te, nil
return b.te, nil
}
networkConfig := networks.SelectedNetwork
var internalDockerUrls test_env.InternalDockerUrls
if b.hasGeth && networkConfig.Simulated {
networkConfig, internalDockerUrls, err = te.StartGeth()
networkConfig, internalDockerUrls, err = b.te.StartGeth()
if err != nil {
return nil, err
}

}

bc, err := blockchain.NewEVMClientFromNetwork(networkConfig, b.l)
if err != nil {
return nil, err
}

te.EVMClient = bc
if !b.isNonEVM {
bc, err := blockchain.NewEVMClientFromNetwork(networkConfig, b.l)
if err != nil {
return nil, err
}

cd, err := contracts.NewContractDeployer(bc, b.l)
if err != nil {
return nil, err
}
te.ContractDeployer = cd
b.te.EVMClient = bc
cd, err := contracts.NewContractDeployer(bc, b.l)
if err != nil {
return nil, err
}
b.te.ContractDeployer = cd

cl, err := contracts.NewContractLoader(bc, b.l)
if err != nil {
return nil, err
cl, err := contracts.NewContractLoader(bc, b.l)
if err != nil {
return nil, err
}
b.te.ContractLoader = cl
}
te.ContractLoader = cl

var nodeCsaKeys []string

Expand All @@ -219,39 +234,40 @@ func (b *CLTestEnvBuilder) buildNewEnv(cfg *TestEnvConfig) (*CLClusterTestEnv, e
node.WithP2Pv1(),
)
}
//node.SetDefaultSimulatedGeth(cfg, te.Geth.InternalWsUrl, te.Geth.InternalHttpUrl, b.hasForwarders)

var httpUrls []string
var wsUrls []string
if networkConfig.Simulated {
httpUrls = []string{internalDockerUrls.HttpUrl}
wsUrls = []string{internalDockerUrls.WsUrl}
} else {
httpUrls = networkConfig.HTTPURLs
wsUrls = networkConfig.URLs
}
if !b.isNonEVM {
var httpUrls []string
var wsUrls []string
if networkConfig.Simulated {
httpUrls = []string{internalDockerUrls.HttpUrl}
wsUrls = []string{internalDockerUrls.WsUrl}
} else {
httpUrls = networkConfig.HTTPURLs
wsUrls = networkConfig.URLs
}

node.SetChainConfig(cfg, wsUrls, httpUrls, networkConfig, b.hasForwarders)
node.SetChainConfig(cfg, wsUrls, httpUrls, networkConfig, b.hasForwarders)
}

err := te.StartClNodes(cfg, b.clNodesCount)
err := b.te.StartClNodes(cfg, b.clNodesCount)
if err != nil {
return nil, err
}

nodeCsaKeys, err = te.GetNodeCSAKeys()
nodeCsaKeys, err = b.te.GetNodeCSAKeys()
if err != nil {
return nil, err
}
b.defaultNodeCsaKeys = nodeCsaKeys
}

if b.hasGeth && b.clNodesCount > 0 && b.ETHFunds != nil {
te.ParallelTransactions(true)
defer te.ParallelTransactions(false)
if err := te.FundChainlinkNodes(b.ETHFunds); err != nil {
b.te.ParallelTransactions(true)
defer b.te.ParallelTransactions(false)
if err := b.te.FundChainlinkNodes(b.ETHFunds); err != nil {
return nil, err
}
}

return te, nil
return b.te, nil
}
Loading