From 093f5707b9747169d293717f0c4cc53d5117c7b8 Mon Sep 17 00:00:00 2001 From: Anindita Ghosh <88458927+AnieeG@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:42:05 -0700 Subject: [PATCH] moving pg and mockserver to CTF (#10372) --- integration-tests/docker/test_env/cl_node.go | 14 +- .../docker/test_env/env_component.go | 21 -- integration-tests/docker/test_env/geth.go | 233 ------------------ .../docker/test_env/mockserver.go | 106 -------- integration-tests/docker/test_env/postgres.go | 83 ------- integration-tests/docker/test_env/test_env.go | 15 +- .../docker/test_env/test_env_builder.go | 9 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/utils/templates/geth.go | 56 ----- integration-tests/utils/templates/secrets.go | 7 +- integration-tests/utils/templates/template.go | 25 -- 12 files changed, 27 insertions(+), 548 deletions(-) delete mode 100644 integration-tests/docker/test_env/env_component.go delete mode 100644 integration-tests/docker/test_env/geth.go delete mode 100644 integration-tests/docker/test_env/mockserver.go delete mode 100644 integration-tests/docker/test_env/postgres.go delete mode 100644 integration-tests/utils/templates/geth.go delete mode 100644 integration-tests/utils/templates/template.go diff --git a/integration-tests/docker/test_env/cl_node.go b/integration-tests/docker/test_env/cl_node.go index 4d690e9dd76..0ec62808feb 100644 --- a/integration-tests/docker/test_env/cl_node.go +++ b/integration-tests/docker/test_env/cl_node.go @@ -18,16 +18,18 @@ import ( "github.com/pelletier/go-toml/v2" "github.com/pkg/errors" "github.com/rs/zerolog/log" + "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" 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/logwatch" - "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" - "github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types" "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" + "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" + "github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype" + "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/utils" "github.com/smartcontractkit/chainlink/integration-tests/utils/templates" @@ -39,11 +41,11 @@ var ( ) type ClNode struct { - EnvComponent + test_env.EnvComponent API *client.ChainlinkClient NodeConfig *chainlink.Config NodeSecretsConfigTOML string - PostgresDb *PostgresDb + PostgresDb *test_env.PostgresDb lw *logwatch.LogWatch } @@ -76,9 +78,9 @@ func WithLogWatch(lw *logwatch.LogWatch) ClNodeOption { func NewClNode(networks []string, nodeConfig *chainlink.Config, opts ...ClNodeOption) *ClNode { nodeDefaultCName := fmt.Sprintf("%s-%s", "cl-node", uuid.NewString()[0:8]) pgDefaultCName := fmt.Sprintf("pg-%s", nodeDefaultCName) - pgDb := NewPostgresDb(networks, WithPostgresDbContainerName(pgDefaultCName)) + pgDb := test_env.NewPostgresDb(networks, test_env.WithPostgresDbContainerName(pgDefaultCName)) n := &ClNode{ - EnvComponent: EnvComponent{ + EnvComponent: test_env.EnvComponent{ ContainerName: nodeDefaultCName, Networks: networks, }, diff --git a/integration-tests/docker/test_env/env_component.go b/integration-tests/docker/test_env/env_component.go deleted file mode 100644 index e6f6fc4b8a6..00000000000 --- a/integration-tests/docker/test_env/env_component.go +++ /dev/null @@ -1,21 +0,0 @@ -package test_env - -import ( - tc "github.com/testcontainers/testcontainers-go" -) - -type EnvComponent struct { - ContainerName string - Container tc.Container - Networks []string -} - -type EnvComponentOption = func(c *EnvComponent) - -func WithContainerName(name string) EnvComponentOption { - return func(c *EnvComponent) { - if name != "" { - c.ContainerName = name - } - } -} diff --git a/integration-tests/docker/test_env/geth.go b/integration-tests/docker/test_env/geth.go deleted file mode 100644 index 764f7acf418..00000000000 --- a/integration-tests/docker/test_env/geth.go +++ /dev/null @@ -1,233 +0,0 @@ -package test_env - -import ( - "context" - "fmt" - "os" - "time" - - "github.com/ethereum/go-ethereum/accounts" - "github.com/ethereum/go-ethereum/accounts/keystore" - "github.com/google/uuid" - "github.com/pkg/errors" - "github.com/rs/zerolog/log" - tc "github.com/testcontainers/testcontainers-go" - tcwait "github.com/testcontainers/testcontainers-go/wait" - - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" - - "github.com/smartcontractkit/chainlink/integration-tests/utils/templates" -) - -const ( - // RootFundingAddr is the static key that hardhat is using - // https://hardhat.org/hardhat-runner/docs/getting-started - // if you need more keys, keep them compatible, so we can swap Geth to Ganache/Hardhat in the future - RootFundingAddr = `0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266` - RootFundingWallet = `{"address":"f39fd6e51aad88f6f4ce6ab8827279cfffb92266","crypto":{"cipher":"aes-128-ctr","ciphertext":"c36afd6e60b82d6844530bd6ab44dbc3b85a53e826c3a7f6fc6a75ce38c1e4c6","cipherparams":{"iv":"f69d2bb8cd0cb6274535656553b61806"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"80d5f5e38ba175b6b89acfc8ea62a6f163970504af301292377ff7baafedab53"},"mac":"f2ecec2c4d05aacc10eba5235354c2fcc3776824f81ec6de98022f704efbf065"},"id":"e5c124e9-e280-4b10-a27b-d7f3e516b408","version":3}` -) - -type Geth struct { - EnvComponent - ExternalHttpUrl string - InternalHttpUrl string - ExternalWsUrl string - InternalWsUrl string -} - -func NewGeth(networks []string, opts ...EnvComponentOption) *Geth { - g := &Geth{ - EnvComponent: EnvComponent{ - ContainerName: fmt.Sprintf("%s-%s", "geth", uuid.NewString()[0:8]), - Networks: networks, - }, - } - for _, opt := range opts { - opt(&g.EnvComponent) - } - return g -} - -func (g *Geth) StartContainer() (blockchain.EVMNetwork, InternalDockerUrls, error) { - r, _, _, err := g.getGethContainerRequest(g.Networks) - if err != nil { - return blockchain.EVMNetwork{}, InternalDockerUrls{}, err - } - ct, err := tc.GenericContainer(context.Background(), - tc.GenericContainerRequest{ - ContainerRequest: *r, - Started: true, - Reuse: true, - }) - if err != nil { - return blockchain.EVMNetwork{}, InternalDockerUrls{}, errors.Wrapf(err, "cannot start geth container") - } - host, err := ct.Host(context.Background()) - if err != nil { - return blockchain.EVMNetwork{}, InternalDockerUrls{}, err - } - httpPort, err := ct.MappedPort(context.Background(), "8544/tcp") - if err != nil { - return blockchain.EVMNetwork{}, InternalDockerUrls{}, err - } - wsPort, err := ct.MappedPort(context.Background(), "8545/tcp") - if err != nil { - return blockchain.EVMNetwork{}, InternalDockerUrls{}, err - } - - g.Container = ct - g.ExternalHttpUrl = fmt.Sprintf("http://%s:%s", host, httpPort.Port()) - g.InternalHttpUrl = fmt.Sprintf("http://%s:8544", g.ContainerName) - g.ExternalWsUrl = fmt.Sprintf("ws://%s:%s", host, wsPort.Port()) - g.InternalWsUrl = fmt.Sprintf("ws://%s:8545", g.ContainerName) - - networkConfig := blockchain.SimulatedEVMNetwork - networkConfig.Name = "geth" - networkConfig.URLs = []string{g.ExternalWsUrl} - networkConfig.HTTPURLs = []string{g.ExternalHttpUrl} - - internalDockerUrls := InternalDockerUrls{ - HttpUrl: g.InternalHttpUrl, - WsUrl: g.InternalWsUrl, - } - - log.Info().Str("containerName", g.ContainerName). - Str("internalHttpUrl", g.InternalHttpUrl). - Str("externalHttpUrl", g.ExternalHttpUrl). - Str("externalWsUrl", g.ExternalWsUrl). - Str("internalWsUrl", g.InternalWsUrl). - Msg("Started Geth container") - - return networkConfig, internalDockerUrls, nil -} - -func (g *Geth) getGethContainerRequest(networks []string) (*tc.ContainerRequest, *keystore.KeyStore, *accounts.Account, error) { - chainId := "1337" - blocktime := "1" - - initScriptFile, err := os.CreateTemp("", "init_script") - if err != nil { - return nil, nil, nil, err - } - _, err = initScriptFile.WriteString(templates.InitGethScript) - if err != nil { - return nil, nil, nil, err - } - keystoreDir, err := os.MkdirTemp("", "keystore") - if err != nil { - return nil, nil, nil, err - } - // Create keystore and ethereum account - ks := keystore.NewKeyStore(keystoreDir, keystore.StandardScryptN, keystore.StandardScryptP) - account, err := ks.NewAccount("") - if err != nil { - return nil, ks, &account, err - } - genesisJsonStr, err := templates.GenesisJsonTemplate{ - ChainId: chainId, - AccountAddr: account.Address.Hex(), - }.String() - if err != nil { - return nil, ks, &account, err - } - genesisFile, err := os.CreateTemp("", "genesis_json") - if err != nil { - return nil, ks, &account, err - } - _, err = genesisFile.WriteString(genesisJsonStr) - if err != nil { - return nil, ks, &account, err - } - key1File, err := os.CreateTemp(keystoreDir, "key1") - if err != nil { - return nil, ks, &account, err - } - _, err = key1File.WriteString(RootFundingWallet) - if err != nil { - return nil, ks, &account, err - } - configDir, err := os.MkdirTemp("", "config") - if err != nil { - return nil, ks, &account, err - } - err = os.WriteFile(configDir+"/password.txt", []byte(""), 0600) - if err != nil { - return nil, ks, &account, err - } - - return &tc.ContainerRequest{ - Name: g.ContainerName, - AlwaysPullImage: true, - Image: "ethereum/client-go:stable", - ExposedPorts: []string{"8544/tcp", "8545/tcp"}, - Networks: networks, - WaitingFor: tcwait.ForLog("Chain head was updated"). - WithStartupTimeout(120 * time.Second). - WithPollInterval(1 * time.Second), - Entrypoint: []string{"sh", "./root/init.sh", - "--dev", - "--password", "/root/config/password.txt", - "--datadir", - "/root/.ethereum/devchain", - "--unlock", - RootFundingAddr, - "--mine", - "--miner.etherbase", - RootFundingAddr, - "--ipcdisable", - "--http", - "--http.vhosts", - "*", - "--http.addr", - "0.0.0.0", - "--http.port=8544", - "--ws", - "--ws.origins", - "*", - "--ws.addr", - "0.0.0.0", - "--ws.port=8545", - "--graphql", - "-graphql.corsdomain", - "*", - "--allow-insecure-unlock", - "--rpc.allow-unprotected-txs", - "--http.api", - "eth,web3,debug", - "--http.corsdomain", - "*", - "--vmdebug", - fmt.Sprintf("--networkid=%s", chainId), - "--rpc.txfeecap", - "0", - "--dev.period", - blocktime, - }, - Files: []tc.ContainerFile{ - { - HostFilePath: initScriptFile.Name(), - ContainerFilePath: "/root/init.sh", - FileMode: 0644, - }, - { - HostFilePath: genesisFile.Name(), - ContainerFilePath: "/root/genesis.json", - FileMode: 0644, - }, - }, - Mounts: tc.ContainerMounts{ - tc.ContainerMount{ - Source: tc.GenericBindMountSource{ - HostPath: keystoreDir, - }, - Target: "/root/.ethereum/devchain/keystore/", - }, - tc.ContainerMount{ - Source: tc.GenericBindMountSource{ - HostPath: configDir, - }, - Target: "/root/config/", - }, - }, - }, ks, &account, nil -} diff --git a/integration-tests/docker/test_env/mockserver.go b/integration-tests/docker/test_env/mockserver.go deleted file mode 100644 index 8a8f966678c..00000000000 --- a/integration-tests/docker/test_env/mockserver.go +++ /dev/null @@ -1,106 +0,0 @@ -package test_env - -import ( - "context" - "fmt" - "net/url" - "strings" - "time" - - "github.com/google/uuid" - "github.com/pkg/errors" - "github.com/rs/zerolog/log" - tc "github.com/testcontainers/testcontainers-go" - tcwait "github.com/testcontainers/testcontainers-go/wait" - - ctfClient "github.com/smartcontractkit/chainlink-testing-framework/client" -) - -type MockServer struct { - EnvComponent - Client *ctfClient.MockserverClient - Endpoint string - InternalEndpoint string - EAMockUrls []*url.URL -} - -func NewMockServer(networks []string, opts ...EnvComponentOption) *MockServer { - ms := &MockServer{ - EnvComponent: EnvComponent{ - ContainerName: fmt.Sprintf("%s-%s", "mockserver", uuid.NewString()[0:8]), - Networks: networks, - }, - } - for _, opt := range opts { - opt(&ms.EnvComponent) - } - return ms -} - -func (ms *MockServer) SetExternalAdapterMocks(count int) error { - for i := 0; i < count; i++ { - path := fmt.Sprintf("/ea-%d", i) - err := ms.Client.SetRandomValuePath(path) - if err != nil { - return err - } - cName, err := ms.Container.Name(context.Background()) - if err != nil { - return err - } - cName = strings.Replace(cName, "/", "", -1) - eaUrl, err := url.Parse(fmt.Sprintf("http://%s:%s%s", - cName, "1080", path)) - if err != nil { - return err - } - ms.EAMockUrls = append(ms.EAMockUrls, eaUrl) - } - return nil -} - -func (ms *MockServer) StartContainer() error { - c, err := tc.GenericContainer(context.Background(), tc.GenericContainerRequest{ - ContainerRequest: ms.getContainerRequest(), - Started: true, - Reuse: true, - }) - if err != nil { - return errors.Wrapf(err, "cannot start MockServer container") - } - ms.Container = c - endpoint, err := c.Endpoint(context.Background(), "http") - if err != nil { - return err - } - log.Info().Any("endpoint", endpoint).Str("containerName", ms.ContainerName). - Msgf("Started MockServer container") - ms.Endpoint = endpoint - ms.InternalEndpoint = fmt.Sprintf("http://%s:%s", ms.ContainerName, "1080") - - client := ctfClient.NewMockserverClient(&ctfClient.MockserverConfig{ - LocalURL: endpoint, - ClusterURL: ms.InternalEndpoint, - }) - if err != nil { - return errors.Wrapf(err, "cannot connect to MockServer client") - } - ms.Client = client - - return nil -} - -func (ms *MockServer) getContainerRequest() tc.ContainerRequest { - return tc.ContainerRequest{ - Name: ms.ContainerName, - Image: "mockserver/mockserver:5.15.0", - ExposedPorts: []string{"1080/tcp"}, - Env: map[string]string{ - "SERVER_PORT": "1080", - }, - Networks: ms.Networks, - WaitingFor: tcwait.ForLog("INFO 1080 started on port: 1080"). - WithStartupTimeout(30 * time.Second). - WithPollInterval(100 * time.Millisecond), - } -} diff --git a/integration-tests/docker/test_env/postgres.go b/integration-tests/docker/test_env/postgres.go deleted file mode 100644 index 64b48235989..00000000000 --- a/integration-tests/docker/test_env/postgres.go +++ /dev/null @@ -1,83 +0,0 @@ -package test_env - -import ( - "context" - "fmt" - "time" - - "github.com/google/uuid" - "github.com/rs/zerolog/log" - tc "github.com/testcontainers/testcontainers-go" - tcwait "github.com/testcontainers/testcontainers-go/wait" -) - -type PostgresDb struct { - EnvComponent - User string - Password string - DbName string - Port string -} - -type PostgresDbOption = func(c *PostgresDb) - -// Sets custom container name if name is not empty -func WithPostgresDbContainerName(name string) PostgresDbOption { - return func(c *PostgresDb) { - if name != "" { - c.ContainerName = name - } - } -} - -func NewPostgresDb(networks []string, opts ...PostgresDbOption) *PostgresDb { - pg := &PostgresDb{ - EnvComponent: EnvComponent{ - ContainerName: fmt.Sprintf("%s-%s", "postgres-db", uuid.NewString()[0:8]), - Networks: networks, - }, - User: "postgres", - Password: "mysecretpassword", - DbName: "testdb", - Port: "5432", - } - for _, opt := range opts { - opt(pg) - } - return pg -} - -func (pg *PostgresDb) StartContainer() error { - req := pg.getContainerRequest() - c, err := tc.GenericContainer(context.Background(), tc.GenericContainerRequest{ - ContainerRequest: *req, - Started: true, - Reuse: true, - }) - if err != nil { - return err - } - pg.Container = c - - log.Info().Str("containerName", pg.ContainerName). - Msg("Started Postgres DB container") - - return nil -} - -func (pg *PostgresDb) getContainerRequest() *tc.ContainerRequest { - return &tc.ContainerRequest{ - Name: pg.ContainerName, - Image: "postgres:15.3", - ExposedPorts: []string{fmt.Sprintf("%s/tcp", pg.Port)}, - Env: map[string]string{ - "POSTGRES_USER": pg.User, - "POSTGRES_DB": pg.DbName, - "POSTGRES_PASSWORD": pg.Password, - }, - Networks: pg.Networks, - WaitingFor: tcwait.ForExec([]string{"psql", "-h", "localhost", - "-U", pg.User, "-c", "select", "1", "-d", pg.DbName}). - WithStartupTimeout(10 * time.Second), - } -} diff --git a/integration-tests/docker/test_env/test_env.go b/integration-tests/docker/test_env/test_env.go index 40e4c27bd2a..c056e92b9fc 100644 --- a/integration-tests/docker/test_env/test_env.go +++ b/integration-tests/docker/test_env/test_env.go @@ -12,6 +12,7 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" "github.com/smartcontractkit/chainlink-testing-framework/logwatch" + "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/integration-tests/client" @@ -32,9 +33,9 @@ type CLClusterTestEnv struct { /* components */ CLNodes []*ClNode - Geth *Geth // for tests using --dev networks + Geth *test_env.Geth // for tests using --dev networks PrivateGethChain []test_env.PrivateGethChain // for tests using non-dev networks - MockServer *MockServer + MockServer *test_env.MockServer EVMClient blockchain.EVMClient ContractDeployer contracts.ContractDeployer ContractLoader contracts.ContractLoader @@ -49,8 +50,8 @@ func NewTestEnv() (*CLClusterTestEnv, error) { networks := []string{network.Name} return &CLClusterTestEnv{ Network: network, - Geth: NewGeth(networks), - MockServer: NewMockServer(networks), + Geth: test_env.NewGeth(networks), + MockServer: test_env.NewMockServer(networks), }, nil } @@ -65,8 +66,8 @@ func NewTestEnvFromCfg(cfg *TestEnvConfig) (*CLClusterTestEnv, error) { return &CLClusterTestEnv{ Cfg: cfg, Network: network, - Geth: NewGeth(networks, WithContainerName(cfg.Geth.ContainerName)), - MockServer: NewMockServer(networks, WithContainerName(cfg.MockServer.ContainerName)), + Geth: test_env.NewGeth(networks, test_env.WithContainerName(cfg.Geth.ContainerName)), + MockServer: test_env.NewMockServer(networks, test_env.WithContainerName(cfg.MockServer.ContainerName)), }, nil } @@ -98,7 +99,7 @@ func (te *CLClusterTestEnv) StartPrivateGethChain() error { return nil } -func (te *CLClusterTestEnv) StartGeth() (blockchain.EVMNetwork, InternalDockerUrls, error) { +func (te *CLClusterTestEnv) StartGeth() (blockchain.EVMNetwork, test_env.InternalDockerUrls, error) { return te.Geth.StartContainer() } diff --git a/integration-tests/docker/test_env/test_env_builder.go b/integration-tests/docker/test_env/test_env_builder.go index 04b9f44f3f7..bacee0c956f 100644 --- a/integration-tests/docker/test_env/test_env_builder.go +++ b/integration-tests/docker/test_env/test_env_builder.go @@ -6,9 +6,11 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog/log" + "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/logwatch" + "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/integration-tests/contracts" @@ -32,11 +34,6 @@ type CLTestEnvBuilder struct { ETHFunds *big.Float } -type InternalDockerUrls struct { - HttpUrl string - WsUrl string -} - func NewCLTestEnvBuilder() *CLTestEnvBuilder { return &CLTestEnvBuilder{ externalAdapterCount: 1, @@ -161,7 +158,7 @@ func (b *CLTestEnvBuilder) buildNewEnv(cfg *TestEnvConfig) (*CLClusterTestEnv, e return te, nil } networkConfig := networks.SelectedNetwork - var internalDockerUrls InternalDockerUrls + var internalDockerUrls test_env.InternalDockerUrls if b.hasGeth && networkConfig.Simulated { networkConfig, internalDockerUrls, err = te.StartGeth() if err != nil { diff --git a/integration-tests/go.mod b/integration-tests/go.mod index b3d6ca34ad7..fd021540c84 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -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.0 + github.com/smartcontractkit/chainlink-testing-framework v1.16.1-0.20230828224428-5b8a157a94d0 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.18 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index a8e55a655a2..e1d894aaf83 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -2247,8 +2247,8 @@ github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230802143301-165000751a8 github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230802143301-165000751a85/go.mod h1:H3/j2l84FsxYevCLNERdVasI7FVr+t2mkpv+BCJLSVw= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230802150127-d2c95679d61a h1:b3rjvZLpTV45TmCV+ALX+EDDslf91pnDUugP54Lu9FA= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230802150127-d2c95679d61a/go.mod h1:LL+FLf10gOUHrF3aUsRGEZlT/w8DaW5T/eEo/54W68c= -github.com/smartcontractkit/chainlink-testing-framework v1.16.0 h1:jLpqwqaTpJXQvTJ1IXTomcCToOdrSCe4+IGcLXGsmD0= -github.com/smartcontractkit/chainlink-testing-framework v1.16.0/go.mod h1:t6FJX3akEfAO31p96ru0ilNPfE9P2UshUlXTIkI58LM= +github.com/smartcontractkit/chainlink-testing-framework v1.16.1-0.20230828224428-5b8a157a94d0 h1:DvIwUQc3/yWlvuXD/t30aOyX5BPVomM7OQT8ZO9VFFo= +github.com/smartcontractkit/chainlink-testing-framework v1.16.1-0.20230828224428-5b8a157a94d0/go.mod h1:t6FJX3akEfAO31p96ru0ilNPfE9P2UshUlXTIkI58LM= 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= diff --git a/integration-tests/utils/templates/geth.go b/integration-tests/utils/templates/geth.go deleted file mode 100644 index 11ccc8dd4ba..00000000000 --- a/integration-tests/utils/templates/geth.go +++ /dev/null @@ -1,56 +0,0 @@ -package templates - -import ( - "github.com/google/uuid" -) - -type GenesisJsonTemplate struct { - AccountAddr string - ChainId string -} - -// String representation of the job -func (c GenesisJsonTemplate) String() (string, error) { - tpl := ` -{ - "config": { - "chainId": {{ .ChainId }}, - "homesteadBlock": 0, - "eip150Block": 0, - "eip155Block": 0, - "eip158Block": 0, - "eip160Block": 0, - "byzantiumBlock": 0, - "constantinopleBlock": 0, - "petersburgBlock": 0, - "istanbulBlock": 0, - "muirGlacierBlock": 0, - "berlinBlock": 0, - "londonBlock": 0 - }, - "nonce": "0x0000000000000042", - "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "difficulty": "1", - "coinbase": "0x3333333333333333333333333333333333333333", - "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "extraData": "0x", - "gasLimit": "8000000000", - "alloc": { - "{{ .AccountAddr }}": { - "balance": "20000000000000000000000" - } - } - }` - return MarshalTemplate(c, uuid.NewString(), tpl) -} - -var InitGethScript = ` -#!/bin/bash -if [ ! -d /root/.ethereum/keystore ]; then - echo "/root/.ethereum/keystore not found, running 'geth init'..." - geth init /root/genesis.json - echo "...done!" -fi - -geth "$@" -` diff --git a/integration-tests/utils/templates/secrets.go b/integration-tests/utils/templates/secrets.go index 09d45f15cca..3d3f9e44a90 100644 --- a/integration-tests/utils/templates/secrets.go +++ b/integration-tests/utils/templates/secrets.go @@ -1,6 +1,9 @@ package templates -import "github.com/google/uuid" +import ( + "github.com/google/uuid" + "github.com/smartcontractkit/chainlink-testing-framework/utils/templates" +) // NodeSecretsTemplate are used as text templates because of secret redacted fields of chainlink.Secrets // secret fields can't be marshalled as a plain text @@ -25,5 +28,5 @@ URL = 'localhost:1338' Username = 'node' Password = 'nodepass' ` - return MarshalTemplate(c, uuid.NewString(), tpl) + return templates.MarshalTemplate(c, uuid.NewString(), tpl) } diff --git a/integration-tests/utils/templates/template.go b/integration-tests/utils/templates/template.go deleted file mode 100644 index 515c9968e1f..00000000000 --- a/integration-tests/utils/templates/template.go +++ /dev/null @@ -1,25 +0,0 @@ -package templates - -import ( - "bytes" - "errors" - "text/template" -) - -var ( - ErrParsingTemplate = errors.New("failed to parse Go text template") -) - -// MarshalTemplate Helper to marshal templates -func MarshalTemplate(jobSpec interface{}, name, templateString string) (string, error) { - var buf bytes.Buffer - tmpl, err := template.New(name).Parse(templateString) - if err != nil { - return "", errors.Join(err, ErrParsingTemplate) - } - err = tmpl.Execute(&buf, jobSpec) - if err != nil { - return "", err - } - return buf.String(), err -}