Skip to content

Commit

Permalink
Update e2e docker tests to use killgrave mock adapter instead of mock…
Browse files Browse the repository at this point in the history
…-server (#10866)

* Update e2e docker tests to use killgrave mock adapter instead of mock-server

* remove mock-server from the builder
  • Loading branch information
tateexon authored Oct 4, 2023
1 parent a35a7e1 commit f560107
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 104 deletions.
21 changes: 11 additions & 10 deletions integration-tests/actions/ocr2_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"crypto/ed25519"
"encoding/hex"
"fmt"
"net/http"
"strings"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/lib/pq"
"github.com/rs/zerolog/log"
ctfClient "github.com/smartcontractkit/chainlink-testing-framework/client"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
Expand All @@ -29,9 +30,9 @@ func CreateOCRv2JobsLocal(
ocrInstances []contracts.OffchainAggregatorV2,
bootstrapNode *client.ChainlinkClient,
workerChainlinkNodes []*client.ChainlinkClient,
mockserver *ctfClient.MockserverClient,
mockServerPath string, // Path on the mock server for the Chainlink nodes to query
mockServerValue int, // Value to get from the mock server when querying the path
mockAdapter *test_env.Killgrave,
mockAdapterPath string, // Path on the mock server for the Chainlink nodes to query
mockAdapterValue int, // Value to get from the mock server when querying the path
chainId uint64, // EVM chain ID
forwardingAllowed bool,
) error {
Expand All @@ -42,12 +43,12 @@ func CreateOCRv2JobsLocal(
}
p2pV2Bootstrapper := fmt.Sprintf("%s@%s:%d", bootstrapP2PIds.Data[0].Attributes.PeerID, bootstrapNode.InternalIP(), 6690)
// Set the value for the jobs to report on
err = mockserver.SetValuePath(mockServerPath, mockServerValue)
err = mockAdapter.SetAdapterBasedIntValuePath(mockAdapterPath, []string{http.MethodGet, http.MethodPost}, mockAdapterValue)
if err != nil {
return err
}
// Set the juelsPerFeeCoinSource config value
err = mockserver.SetValuePath(fmt.Sprintf("%s/juelsPerFeeCoinSource", mockServerPath), mockServerValue)
err = mockAdapter.SetAdapterBasedIntValuePath(fmt.Sprintf("%s/juelsPerFeeCoinSource", mockAdapterPath), []string{http.MethodGet, http.MethodPost}, mockAdapterValue)
if err != nil {
return err
}
Expand All @@ -62,7 +63,7 @@ func CreateOCRv2JobsLocal(
RelayConfig: map[string]interface{}{
"chainID": chainId,
},
MonitoringEndpoint: null.StringFrom(fmt.Sprintf("%s/%s", mockserver.Config.ClusterURL, mockServerPath)),
MonitoringEndpoint: null.StringFrom(fmt.Sprintf("%s/%s", mockAdapter.InternalEndpoint, mockAdapterPath)),
ContractConfigTrackerPollInterval: *models.NewInterval(15 * time.Second),
},
}
Expand All @@ -83,12 +84,12 @@ func CreateOCRv2JobsLocal(
nodeOCRKeyId := nodeOCRKeys.Data[0].ID

bta := &client.BridgeTypeAttributes{
Name: fmt.Sprintf("%s-%s", mockServerPath, uuid.NewString()),
URL: fmt.Sprintf("%s/%s", mockserver.Config.ClusterURL, mockServerPath),
Name: fmt.Sprintf("%s-%s", mockAdapterPath, uuid.NewString()),
URL: fmt.Sprintf("%s/%s", mockAdapter.InternalEndpoint, mockAdapterPath),
}
juelsBridge := &client.BridgeTypeAttributes{
Name: fmt.Sprintf("juels-%s", uuid.NewString()),
URL: fmt.Sprintf("%s/%s/juelsPerFeeCoinSource", mockserver.Config.ClusterURL, mockServerPath),
URL: fmt.Sprintf("%s/%s/juelsPerFeeCoinSource", mockAdapter.InternalEndpoint, mockAdapterPath),
}
err = chainlinkNode.MustCreateBridge(bta)
if err != nil {
Expand Down
25 changes: 13 additions & 12 deletions integration-tests/actions/ocr_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package actions
import (
"fmt"
"math/big"
"net/http"
"strings"

"github.com/ethereum/go-ethereum"
Expand All @@ -11,7 +12,7 @@ import (
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
ctfClient "github.com/smartcontractkit/chainlink-testing-framework/client"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink/integration-tests/client"
Expand Down Expand Up @@ -141,7 +142,7 @@ func CreateOCRJobsLocal(
bootstrapNode *client.ChainlinkClient,
workerNodes []*client.ChainlinkClient,
mockValue int,
mockserver *ctfClient.MockserverClient,
mockAdapter *test_env.Killgrave,
evmChainID string,
) error {
for _, ocrInstance := range ocrInstances {
Expand Down Expand Up @@ -184,9 +185,9 @@ func CreateOCRJobsLocal(
}
bta := &client.BridgeTypeAttributes{
Name: nodeContractPairID,
URL: fmt.Sprintf("%s/%s", mockserver.Config.ClusterURL, strings.TrimPrefix(nodeContractPairID, "/")),
URL: fmt.Sprintf("%s/%s", mockAdapter.InternalEndpoint, strings.TrimPrefix(nodeContractPairID, "/")),
}
err = SetAdapterResponseLocal(mockValue, ocrInstance, node, mockserver)
err = SetAdapterResponseLocal(mockValue, ocrInstance, node, mockAdapter)
if err != nil {
return fmt.Errorf("setting adapter response for OCR node failed: %w", err)
}
Expand Down Expand Up @@ -234,16 +235,16 @@ func SetAdapterResponseLocal(
response int,
ocrInstance contracts.OffchainAggregator,
chainlinkNode *client.ChainlinkClient,
mockserver *ctfClient.MockserverClient,
mockAdapter *test_env.Killgrave,
) error {
nodeContractPairID, err := BuildNodeContractPairIDLocal(chainlinkNode, ocrInstance)
if err != nil {
return err
}
path := fmt.Sprintf("/%s", nodeContractPairID)
err = mockserver.SetValuePath(path, response)
err = mockAdapter.SetAdapterBasedIntValuePath(path, []string{http.MethodGet, http.MethodPost}, response)
if err != nil {
return fmt.Errorf("setting mockserver value path failed: %w", err)
return fmt.Errorf("setting mock adapter value path failed: %w", err)
}
return nil
}
Expand All @@ -252,15 +253,15 @@ func SetAllAdapterResponsesToTheSameValueLocal(
response int,
ocrInstances []contracts.OffchainAggregator,
chainlinkNodes []*client.ChainlinkClient,
mockserver *ctfClient.MockserverClient,
mockAdapter *test_env.Killgrave,
) error {
eg := &errgroup.Group{}
for _, o := range ocrInstances {
ocrInstance := o
for _, n := range chainlinkNodes {
node := n
eg.Go(func() error {
return SetAdapterResponseLocal(response, ocrInstance, node, mockserver)
return SetAdapterResponseLocal(response, ocrInstance, node, mockAdapter)
})
}
}
Expand Down Expand Up @@ -358,7 +359,7 @@ func CreateOCRJobsWithForwarderLocal(
bootstrapNode *client.ChainlinkClient,
workerNodes []*client.ChainlinkClient,
mockValue int,
mockserver *ctfClient.MockserverClient,
mockAdapter *test_env.Killgrave,
evmChainID string,
) error {
for _, ocrInstance := range ocrInstances {
Expand Down Expand Up @@ -401,9 +402,9 @@ func CreateOCRJobsWithForwarderLocal(
}
bta := &client.BridgeTypeAttributes{
Name: nodeContractPairID,
URL: fmt.Sprintf("%s/%s", mockserver.Config.ClusterURL, strings.TrimPrefix(nodeContractPairID, "/")),
URL: fmt.Sprintf("%s/%s", mockAdapter.InternalEndpoint, strings.TrimPrefix(nodeContractPairID, "/")),
}
err = SetAdapterResponseLocal(mockValue, ocrInstance, node, mockserver)
err = SetAdapterResponseLocal(mockValue, ocrInstance, node, mockAdapter)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/actions/vrfv2_actions/vrfv2_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func SetupLocalLoadTestEnv(nodesFunding *big.Float, subFundingLINK *big.Int) (*t
env, err := test_env.NewCLTestEnvBuilder().
WithGeth().
WithLogWatcher().
WithMockServer(1).
WithMockAdapter().
WithCLNodes(1).
WithFunding(nodesFunding).
Build()
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/docker/cmd/test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {

_, err := test_env.NewCLTestEnvBuilder().
WithGeth().
WithMockServer(1).
WithMockAdapter().
WithCLNodes(6).
Build()
if err != nil {
Expand Down
22 changes: 11 additions & 11 deletions integration-tests/docker/test_env/test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type CLClusterTestEnv struct {
CLNodes []*ClNode
Geth *test_env.Geth // for tests using --dev networks
PrivateChain []test_env.PrivateChain // for tests using non-dev networks
MockServer *test_env.MockServer
MockAdapter *test_env.Killgrave
EVMClient blockchain.EVMClient
ContractDeployer contracts.ContractDeployer
ContractLoader contracts.ContractLoader
Expand All @@ -62,28 +62,28 @@ func NewTestEnv() (*CLClusterTestEnv, error) {
}
n := []string{network.Name}
return &CLClusterTestEnv{
Geth: test_env.NewGeth(n),
MockServer: test_env.NewMockServer(n),
Network: network,
l: log.Logger,
Geth: test_env.NewGeth(n),
MockAdapter: test_env.NewKillgrave(n, ""),
Network: network,
l: log.Logger,
}, nil
}

// WithTestEnvConfig sets the test environment cfg.
// Sets up the Geth and MockServer containers with the provided cfg.
// Sets up the Geth and MockAdapter containers with the provided cfg.
func (te *CLClusterTestEnv) WithTestEnvConfig(cfg *TestEnvConfig) *CLClusterTestEnv {
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))
te.Geth = test_env.NewGeth(n, test_env.WithContainerName(te.Cfg.Geth.ContainerName))
te.MockAdapter = test_env.NewKillgrave(n, te.Cfg.MockAdapter.ImpostersPath, test_env.WithContainerName(te.Cfg.MockAdapter.ContainerName))
return te
}

func (te *CLClusterTestEnv) WithTestLogger(t *testing.T) *CLClusterTestEnv {
te.t = t
te.l = logging.GetTestLogger(t)
te.Geth.WithTestLogger(t)
te.MockServer.WithTestLogger(t)
te.MockAdapter.WithTestLogger(t)
return te
}

Expand Down Expand Up @@ -135,8 +135,8 @@ func (te *CLClusterTestEnv) StartGeth() (blockchain.EVMNetwork, test_env.Interna
return te.Geth.StartContainer()
}

func (te *CLClusterTestEnv) StartMockServer() error {
return te.MockServer.StartContainer()
func (te *CLClusterTestEnv) StartMockAdapter() error {
return te.MockAdapter.StartContainer()
}

func (te *CLClusterTestEnv) GetAPIs() []*client.ChainlinkClient {
Expand Down
49 changes: 21 additions & 28 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@ import (
)

type CLTestEnvBuilder struct {
hasLogWatch bool
hasGeth bool
hasMockServer bool
hasForwarders bool
clNodeConfig *chainlink.Config
secretsConfig string
nonDevGethNetworks []blockchain.EVMNetwork
clNodesCount int
externalAdapterCount int
customNodeCsaKeys []string
defaultNodeCsaKeys []string
l zerolog.Logger
t *testing.T
te *CLClusterTestEnv
isNonEVM bool
hasLogWatch bool
hasGeth bool
hasKillgrave bool
hasForwarders bool
clNodeConfig *chainlink.Config
secretsConfig string
nonDevGethNetworks []blockchain.EVMNetwork
clNodesCount int
customNodeCsaKeys []string
defaultNodeCsaKeys []string
l zerolog.Logger
t *testing.T
te *CLClusterTestEnv
isNonEVM bool

/* funding */
ETHFunds *big.Float
}

func NewCLTestEnvBuilder() *CLTestEnvBuilder {
return &CLTestEnvBuilder{
externalAdapterCount: 1,
l: log.Logger,
l: log.Logger,
}
}

Expand Down Expand Up @@ -127,9 +125,8 @@ func (b *CLTestEnvBuilder) WithSecretsConfig(secrets string) *CLTestEnvBuilder {
return b
}

func (b *CLTestEnvBuilder) WithMockServer(externalAdapterCount int) *CLTestEnvBuilder {
b.hasMockServer = true
b.externalAdapterCount = externalAdapterCount
func (b *CLTestEnvBuilder) WithMockAdapter() *CLTestEnvBuilder {
b.hasKillgrave = true
return b
}

Expand All @@ -149,8 +146,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
}
b.l.Info().
Bool("hasGeth", b.hasGeth).
Bool("hasMockServer", b.hasMockServer).
Int("externalAdapterCount", b.externalAdapterCount).
Bool("hasKillgrave", b.hasKillgrave).
Int("clNodesCount", b.clNodesCount).
Strs("customNodeCsaKeys", b.customNodeCsaKeys).
Strs("defaultNodeCsaKeys", b.defaultNodeCsaKeys).
Expand All @@ -168,16 +164,13 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
}
}

if b.hasMockServer {
err = b.te.StartMockServer()
if err != nil {
return nil, err
}
err = b.te.MockServer.SetExternalAdapterMocks(b.externalAdapterCount)
if b.hasKillgrave {
err = b.te.StartMockAdapter()
if err != nil {
return nil, err
}
}

if b.nonDevGethNetworks != nil {
b.te.WithPrivateChain(b.nonDevGethNetworks)
err := b.te.StartPrivateChain()
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/docker/test_env/test_env_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

type TestEnvConfig struct {
Networks []string `json:"networks"`
Geth GethConfig `json:"geth"`
MockServer MockServerConfig `json:"mockserver"`
Nodes []ClNodeConfig `json:"nodes"`
Networks []string `json:"networks"`
Geth GethConfig `json:"geth"`
MockAdapter MockAdapterConfig `json:"mock_adapter"`
Nodes []ClNodeConfig `json:"nodes"`
}

type MockServerConfig struct {
ContainerName string `json:"container_name"`
EAMockUrls []string `json:"external_adapters_mock_urls"`
type MockAdapterConfig struct {
ContainerName string `json:"container_name"`
ImpostersPath string `json:"imposters_path"`
}

type GethConfig struct {
Expand Down
3 changes: 2 additions & 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.38.1
github.com/smartcontractkit/chainlink-testing-framework v1.17.4
github.com/smartcontractkit/chainlink-testing-framework v1.17.6
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20230922131214-122accb19ea6
github.com/smartcontractkit/ocr2keepers v0.7.27
Expand Down Expand Up @@ -354,6 +354,7 @@ require (
github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e // indirect
github.com/opentracing-contrib/go-stdlib v1.0.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
Expand Down
8 changes: 6 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,10 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA=
github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/ovh/go-ovh v1.3.0 h1:mvZaddk4E4kLcXhzb+cxBsMPYp2pHqiQpWYkInsuZPQ=
github.com/ovh/go-ovh v1.3.0/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down Expand Up @@ -2366,8 +2370,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.17.4 h1:N7YK1VZrSxG3PEwY0S7NXJQgSiEvWHR6uKhytfHMTjA=
github.com/smartcontractkit/chainlink-testing-framework v1.17.4/go.mod h1:izzRx4cNihkVP9XY15isSCMW1QAlRK1w5eE23/MbZHM=
github.com/smartcontractkit/chainlink-testing-framework v1.17.6 h1:hcsP1eyzrqQf3veK4xh0T37PFkq5AasDwlgJfl11atY=
github.com/smartcontractkit/chainlink-testing-framework v1.17.6/go.mod h1:rypNxetVFh6bwaoHn05bsd4vCtgdEsF+1Vdyy/AhAR8=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU=
Expand Down
1 change: 0 additions & 1 deletion integration-tests/smoke/automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ func setupAutomationTestDocker(
env, err := test_env.NewCLTestEnvBuilder().
WithTestLogger(t).
WithGeth().
WithMockServer(1).
WithCLNodes(5).
WithCLNodeConfig(clNodeConfig).
WithSecretsConfig(secretsConfig).
Expand Down
Loading

0 comments on commit f560107

Please sign in to comment.