Skip to content

Commit

Permalink
Use an interface to standardize all docker container set up for vario…
Browse files Browse the repository at this point in the history
…us blockchain clients (#10626)

Co-authored-by: Sri Kidambi <[email protected]>
  • Loading branch information
kidambisrinivas and kidambisrinivas authored Sep 13, 2023
1 parent e197ff9 commit e027262
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
32 changes: 22 additions & 10 deletions integration-tests/docker/test_env/test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test_env

import (
"encoding/json"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/keystore"
Expand Down Expand Up @@ -34,8 +35,8 @@ type CLClusterTestEnv struct {

/* components */
CLNodes []*ClNode
Geth *test_env.Geth // for tests using --dev networks
PrivateGethChain []test_env.PrivateGethChain // for tests using non-dev networks
Geth *test_env.Geth // for tests using --dev networks
PrivateChain []test_env.PrivateChain // for tests using non-dev networks
MockServer *test_env.MockServer
EVMClient blockchain.EVMClient
ContractDeployer contracts.ContractDeployer
Expand Down Expand Up @@ -76,23 +77,34 @@ func (te *CLClusterTestEnv) ParallelTransactions(enabled bool) {
te.EVMClient.ParallelTransactions(enabled)
}

func (te *CLClusterTestEnv) WithPrivateGethChain(evmNetworks []blockchain.EVMNetwork) *CLClusterTestEnv {
var chains []test_env.PrivateGethChain
func (te *CLClusterTestEnv) WithPrivateChain(evmNetworks []blockchain.EVMNetwork) *CLClusterTestEnv {
var chains []test_env.PrivateChain
for _, evmNetwork := range evmNetworks {
n := evmNetwork
chains = append(chains, test_env.NewPrivateGethChain(&n, []string{te.Network.Name}))
var privateChain test_env.PrivateChain
switch n.SimulationType {
case "besu":
privateChain = test_env.NewPrivateBesuChain(&n, []string{te.Network.Name})
default:
privateChain = test_env.NewPrivateGethChain(&n, []string{te.Network.Name})
}
chains = append(chains, privateChain)
}
te.PrivateGethChain = chains
te.PrivateChain = chains
return te
}

func (te *CLClusterTestEnv) StartPrivateGethChain() error {
for _, chain := range te.PrivateGethChain {
err := chain.PrimaryNode.Start()
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"))
}
err := primaryNode.Start()
if err != nil {
return err
}
err = chain.PrimaryNode.ConnectToClient()
err = primaryNode.ConnectToClient()
if err != nil {
return err
}
Expand Down
25 changes: 15 additions & 10 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test_env

import (
"fmt"
"math/big"
"os"

Expand Down Expand Up @@ -136,19 +137,23 @@ func (b *CLTestEnvBuilder) buildNewEnv(cfg *TestEnvConfig) (*CLClusterTestEnv, e
}
}
if b.nonDevGethNetworks != nil {
te.WithPrivateGethChain(b.nonDevGethNetworks)
err := te.StartPrivateGethChain()
te.WithPrivateChain(b.nonDevGethNetworks)
err := te.StartPrivateChain()
if err != nil {
return te, err
}
var nonDevGethNetworks []blockchain.EVMNetwork
for i, n := range te.PrivateGethChain {
nonDevGethNetworks = append(nonDevGethNetworks, *n.NetworkConfig)
nonDevGethNetworks[i].URLs = []string{n.PrimaryNode.InternalWsUrl}
nonDevGethNetworks[i].HTTPURLs = []string{n.PrimaryNode.InternalHttpUrl}
}
if nonDevGethNetworks == nil {
return nil, errors.New("cannot create nodes with custom config without nonDevGethNetworks")
var nonDevNetworks []blockchain.EVMNetwork
for i, n := range te.PrivateChain {
primaryNode := n.GetPrimaryNode()
if primaryNode == nil {
return te, errors.WithStack(fmt.Errorf("Primary node is nil in PrivateChain interface"))
}
nonDevNetworks = append(nonDevNetworks, *n.GetNetworkConfig())
nonDevNetworks[i].URLs = []string{primaryNode.GetInternalWsUrl()}
nonDevNetworks[i].HTTPURLs = []string{primaryNode.GetInternalHttpUrl()}
}
if nonDevNetworks == nil {
return nil, errors.New("cannot create nodes with custom config without nonDevNetworks")
}

err = te.StartClNodes(b.clNodeConfig, b.clNodesCount)
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/rs/zerolog v1.30.0
github.com/slack-go/slack v0.12.2
github.com/smartcontractkit/chainlink-env v0.36.0
github.com/smartcontractkit/chainlink-testing-framework v1.16.8
github.com/smartcontractkit/chainlink-testing-framework v1.16.9-0.20230913144245-620fbcd69dfb
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20230816220705-665e93233ae5
github.com/smartcontractkit/ocr2keepers v0.7.23
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2258,8 +2258,8 @@ github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97ac
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97aca/go.mod h1:RIUJXn7EVp24TL2p4FW79dYjyno23x5mjt1nKN+5WEk=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918 h1:ByVauKFXphRlSNG47lNuxZ9aicu+r8AoNp933VRPpCw=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918/go.mod h1:/yp/sqD8Iz5GU5fcercjrw0ivJF7HDcupYg+Gjr7EPg=
github.com/smartcontractkit/chainlink-testing-framework v1.16.8 h1:YcjSYi6Pm2vOBToxNAmuCrUyb/yymLxjmIEffHUJuhA=
github.com/smartcontractkit/chainlink-testing-framework v1.16.8/go.mod h1:Ry6fRPr8TwrIsYVNEF1pguAgzE3QW1s54tbLWnFtfI4=
github.com/smartcontractkit/chainlink-testing-framework v1.16.9-0.20230913144245-620fbcd69dfb h1:ZLBIvWgoB4Op24yNYJ87qGI9yd6B/6WM+uYs3Vj1Hww=
github.com/smartcontractkit/chainlink-testing-framework v1.16.9-0.20230913144245-620fbcd69dfb/go.mod h1:Ry6fRPr8TwrIsYVNEF1pguAgzE3QW1s54tbLWnFtfI4=
github.com/smartcontractkit/go-plugin v0.0.0-20230605132010-0f4d515d1472 h1:x3kNwgFlDmbE/n0gTSRMt9GBDfsfGrs4X9b9arPZtFI=
github.com/smartcontractkit/go-plugin v0.0.0-20230605132010-0f4d515d1472/go.mod h1:6/1TEzT0eQznvI/gV2CM29DLSkAK/e58mUWKVsPaph0=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU=
Expand Down

0 comments on commit e027262

Please sign in to comment.