Skip to content

Commit

Permalink
[TT-591] Fix E2E Test Logging In Parallel Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tateexon committed Sep 12, 2023
1 parent bb06998 commit a5e0ff9
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 51 deletions.
33 changes: 17 additions & 16 deletions integration-tests/actions/automation_ocr_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ package actions
import (
"encoding/json"
"fmt"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/lib/pq"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/require"
"github.com/rs/zerolog"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
Expand All @@ -30,24 +27,23 @@ import (
)

func BuildAutoOCR2ConfigVarsLocal(
t *testing.T,
l zerolog.Logger,
chainlinkNodes []*client.ChainlinkClient,
registryConfig contracts.KeeperRegistrySettings,
registrar string,
deltaStage time.Duration,
) (contracts.OCRv2Config, error) {
return BuildAutoOCR2ConfigVarsWithKeyIndexLocal(t, chainlinkNodes, registryConfig, registrar, deltaStage, 0)
return BuildAutoOCR2ConfigVarsWithKeyIndexLocal(l, chainlinkNodes, registryConfig, registrar, deltaStage, 0)
}

func BuildAutoOCR2ConfigVarsWithKeyIndexLocal(
t *testing.T,
l zerolog.Logger,
chainlinkNodes []*client.ChainlinkClient,
registryConfig contracts.KeeperRegistrySettings,
registrar string,
deltaStage time.Duration,
keyIndex int,
) (contracts.OCRv2Config, error) {
l := utils.GetTestLogger(t)
S, oracleIdentities, err := GetOracleIdentitiesWithKeyIndexLocal(chainlinkNodes, keyIndex)
if err != nil {
return contracts.OCRv2Config{}, err
Expand Down Expand Up @@ -136,13 +132,17 @@ func BuildAutoOCR2ConfigVarsWithKeyIndexLocal(

var signers []common.Address
for _, signer := range signerOnchainPublicKeys {
require.Equal(t, 20, len(signer), "OnChainPublicKey '%v' has wrong length for address", signer)
if len(signer) != 20 {
return contracts.OCRv2Config{}, fmt.Errorf("OnChainPublicKey '%v' has wrong length for address", signer)
}
signers = append(signers, common.BytesToAddress(signer))
}

var transmitters []common.Address
for _, transmitter := range transmitterAccounts {
require.True(t, common.IsHexAddress(string(transmitter)), "TransmitAccount '%s' is not a valid Ethereum address", string(transmitter))
if !common.IsHexAddress(string(transmitter)) {
return contracts.OCRv2Config{}, fmt.Errorf("TransmitAccount '%s' is not a valid Ethereum address", string(transmitter))
}
transmitters = append(transmitters, common.HexToAddress(string(transmitter)))
}

Expand All @@ -164,6 +164,7 @@ func BuildAutoOCR2ConfigVarsWithKeyIndexLocal(

// CreateOCRKeeperJobs bootstraps the first node and to the other nodes sends ocr jobs
func CreateOCRKeeperJobsLocal(
l zerolog.Logger,
chainlinkNodes []*client.ChainlinkClient,
registryAddr string,
chainID int64,
Expand All @@ -173,7 +174,7 @@ func CreateOCRKeeperJobsLocal(
bootstrapNode := chainlinkNodes[0]
bootstrapP2PIds, err := bootstrapNode.MustReadP2PKeys()
if err != nil {
log.Error().Err(err).Msg("Shouldn't fail reading P2P keys from bootstrap node")
l.Error().Err(err).Msg("Shouldn't fail reading P2P keys from bootstrap node")
return err
}
bootstrapP2PId := bootstrapP2PIds.Data[0].Attributes.PeerID
Expand Down Expand Up @@ -201,20 +202,20 @@ func CreateOCRKeeperJobsLocal(
}
_, err = bootstrapNode.MustCreateJob(bootstrapSpec)
if err != nil {
log.Error().Err(err).Msg("Shouldn't fail creating bootstrap job on bootstrap node")
l.Error().Err(err).Msg("Shouldn't fail creating bootstrap job on bootstrap node")
return err
}

P2Pv2Bootstrapper := fmt.Sprintf("%s@%s:%d", bootstrapP2PId, bootstrapNode.InternalIP(), 6690)
for nodeIndex := 1; nodeIndex < len(chainlinkNodes); nodeIndex++ {
nodeTransmitterAddress, err := chainlinkNodes[nodeIndex].EthAddresses()
if err != nil {
log.Error().Err(err).Msgf("Shouldn't fail getting primary ETH address from OCR node %d", nodeIndex+1)
l.Error().Err(err).Msgf("Shouldn't fail getting primary ETH address from OCR node %d", nodeIndex+1)
return err
}
nodeOCRKeys, err := chainlinkNodes[nodeIndex].MustReadOCR2Keys()
if err != nil {
log.Error().Err(err).Msgf("Shouldn't fail getting OCR keys from OCR node %d", nodeIndex+1)
l.Error().Err(err).Msgf("Shouldn't fail getting OCR keys from OCR node %d", nodeIndex+1)
return err
}
var nodeOCRKeyId []string
Expand Down Expand Up @@ -248,11 +249,11 @@ func CreateOCRKeeperJobsLocal(

_, err = chainlinkNodes[nodeIndex].MustCreateJob(&autoOCR2JobSpec)
if err != nil {
log.Error().Err(err).Msgf("Shouldn't fail creating OCR Task job on OCR node %d err: %+v", nodeIndex+1, err)
l.Error().Err(err).Msgf("Shouldn't fail creating OCR Task job on OCR node %d err: %+v", nodeIndex+1, err)
return err
}

}
log.Info().Msg("Done creating OCR automation jobs")
l.Info().Msg("Done creating OCR automation jobs")
return nil
}
13 changes: 7 additions & 6 deletions integration-tests/actions/keeper_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package actions
import (
"fmt"

"github.com/rs/zerolog/log"
"github.com/rs/zerolog"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
)

func CreateKeeperJobsLocal(
l zerolog.Logger,
chainlinkNodes []*client.ChainlinkClient,
keeperRegistry contracts.KeeperRegistry,
ocrConfig contracts.OCRv2Config,
Expand All @@ -17,12 +18,12 @@ func CreateKeeperJobsLocal(
primaryNode := chainlinkNodes[0]
primaryNodeAddress, err := primaryNode.PrimaryEthAddress()
if err != nil {
log.Error().Err(err).Msg("Reading ETH Keys from Chainlink Client shouldn't fail")
l.Error().Err(err).Msg("Reading ETH Keys from Chainlink Client shouldn't fail")
return nil, err
}
nodeAddresses, err := ChainlinkNodeAddressesLocal(chainlinkNodes)
if err != nil {
log.Error().Err(err).Msg("Retrieving on-chain wallet addresses for chainlink nodes shouldn't fail")
l.Error().Err(err).Msg("Retrieving on-chain wallet addresses for chainlink nodes shouldn't fail")
return nil, err
}
nodeAddressesStr, payees := make([]string, 0), make([]string, 0)
Expand All @@ -32,14 +33,14 @@ func CreateKeeperJobsLocal(
}
err = keeperRegistry.SetKeepers(nodeAddressesStr, payees, ocrConfig)
if err != nil {
log.Error().Err(err).Msg("Setting keepers in the registry shouldn't fail")
l.Error().Err(err).Msg("Setting keepers in the registry shouldn't fail")
return nil, err
}
jobs := []*client.Job{}
for _, chainlinkNode := range chainlinkNodes {
chainlinkNodeAddress, err := chainlinkNode.PrimaryEthAddress()
if err != nil {
log.Error().Err(err).Msg("Error retrieving chainlink node address")
l.Error().Err(err).Msg("Error retrieving chainlink node address")
return nil, err
}
job, err := chainlinkNode.MustCreateJob(&client.KeeperJobSpec{
Expand All @@ -49,7 +50,7 @@ func CreateKeeperJobsLocal(
MinIncomingConfirmations: 1,
})
if err != nil {
log.Error().Err(err).Msg("Creating KeeperV2 Job shouldn't fail")
l.Error().Err(err).Msg("Creating KeeperV2 Job shouldn't fail")
return nil, err
}
jobs = append(jobs, job)
Expand Down
8 changes: 5 additions & 3 deletions integration-tests/docker/test_env/cl_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/google/uuid"
"github.com/pelletier/go-toml/v2"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog"
tc "github.com/testcontainers/testcontainers-go"
tcwait "github.com/testcontainers/testcontainers-go/wait"

Expand Down Expand Up @@ -48,6 +48,7 @@ type ClNode struct {
lw *logwatch.LogWatch
ContainerImage string
ContainerVersion string
l zerolog.Logger
}

type ClNodeOption = func(c *ClNode)
Expand Down Expand Up @@ -76,7 +77,7 @@ func WithLogWatch(lw *logwatch.LogWatch) ClNodeOption {
}
}

func NewClNode(networks []string, nodeConfig *chainlink.Config, opts ...ClNodeOption) *ClNode {
func NewClNode(networks []string, nodeConfig *chainlink.Config, logger zerolog.Logger, opts ...ClNodeOption) *ClNode {
nodeDefaultCName := fmt.Sprintf("%s-%s", "cl-node", uuid.NewString()[0:8])
pgDefaultCName := fmt.Sprintf("pg-%s", nodeDefaultCName)
pgDb := test_env.NewPostgresDb(networks, test_env.WithPostgresDbContainerName(pgDefaultCName))
Expand All @@ -87,6 +88,7 @@ func NewClNode(networks []string, nodeConfig *chainlink.Config, opts ...ClNodeOp
},
NodeConfig: nodeConfig,
PostgresDb: pgDb,
l: logger,
}
for _, opt := range opts {
opt(n)
Expand Down Expand Up @@ -258,7 +260,7 @@ func (n *ClNode) StartContainer() error {
if err != nil {
return err
}
log.Info().Str("containerName", n.ContainerName).
n.l.Info().Str("containerName", n.ContainerName).
Str("clEndpoint", clEndpoint).
Str("clInternalIP", ip).
Msg("Started Chainlink Node container")
Expand Down
17 changes: 10 additions & 7 deletions integration-tests/docker/test_env/test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog"
tc "github.com/testcontainers/testcontainers-go"
"golang.org/x/sync/errgroup"

Expand Down Expand Up @@ -40,9 +40,10 @@ type CLClusterTestEnv struct {
EVMClient blockchain.EVMClient
ContractDeployer contracts.ContractDeployer
ContractLoader contracts.ContractLoader
l zerolog.Logger
}

func NewTestEnv() (*CLClusterTestEnv, error) {
func NewTestEnv(l zerolog.Logger) (*CLClusterTestEnv, error) {
utils.SetupCoreDockerEnvLogger()
network, err := docker.CreateNetwork()
if err != nil {
Expand All @@ -53,22 +54,24 @@ func NewTestEnv() (*CLClusterTestEnv, error) {
Network: network,
Geth: test_env.NewGeth(networks),
MockServer: test_env.NewMockServer(networks),
l: l,
}, nil
}

func NewTestEnvFromCfg(cfg *TestEnvConfig) (*CLClusterTestEnv, error) {
func NewTestEnvFromCfg(l zerolog.Logger, cfg *TestEnvConfig) (*CLClusterTestEnv, error) {
utils.SetupCoreDockerEnvLogger()
network, err := docker.CreateNetwork()
if err != nil {
return nil, err
}
networks := []string{network.Name}
log.Info().Interface("Cfg", cfg).Send()
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: l,
}, nil
}

Expand Down Expand Up @@ -130,7 +133,7 @@ func (te *CLClusterTestEnv) StartClNodes(nodeConfig *chainlink.Config, count int
nodeContainerName = te.Cfg.Nodes[nodeIndex].NodeContainerName
dbContainerName = te.Cfg.Nodes[nodeIndex].DbContainerName
}
n := NewClNode([]string{te.Network.Name}, nodeConfig,
n := NewClNode([]string{te.Network.Name}, nodeConfig, te.l,
WithNodeContainerName(nodeContainerName),
WithDbContainerName(dbContainerName),
)
Expand Down Expand Up @@ -199,15 +202,15 @@ func (te *CLClusterTestEnv) Terminate() error {
// Cleanup cleans the environment up after it's done being used, mainly for returning funds when on live networks.
// Intended to be used as part of t.Cleanup() in tests.
func (te *CLClusterTestEnv) Cleanup() error {
log.Info().Msg("Attempting to return Chainlink node funds to default network wallets")
te.l.Info().Msg("Attempting to return Chainlink node funds to default network wallets")
if te.EVMClient == nil {
return errors.New("blockchain client is nil, unable to return funds from chainlink nodes")
}
if te.CLNodes == nil {
return errors.New("chainlink nodes are nil, unable to return funds from chainlink nodes")
}
if te.EVMClient.NetworkSimulated() {
log.Info().Str("Network Name", te.EVMClient.GetNetworkName()).
te.l.Info().Str("Network Name", te.EVMClient.GetNetworkName()).
Msg("Network is a simulated network. Skipping fund return.")
return nil
}
Expand Down
14 changes: 11 additions & 3 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
Expand All @@ -29,6 +30,7 @@ type CLTestEnvBuilder struct {
externalAdapterCount int
customNodeCsaKeys []string
defaultNodeCsaKeys []string
l zerolog.Logger

/* funding */
ETHFunds *big.Float
Expand All @@ -37,9 +39,15 @@ type CLTestEnvBuilder struct {
func NewCLTestEnvBuilder() *CLTestEnvBuilder {
return &CLTestEnvBuilder{
externalAdapterCount: 1,
l: log.Logger,
}
}

func (b *CLTestEnvBuilder) WithLogger(l zerolog.Logger) *CLTestEnvBuilder {
b.l = l
return b
}

func (b *CLTestEnvBuilder) WithLogWatcher() *CLTestEnvBuilder {
b.hasLogWatch = true
return b
Expand Down Expand Up @@ -95,7 +103,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
}

func (b *CLTestEnvBuilder) buildNewEnv(cfg *TestEnvConfig) (*CLClusterTestEnv, error) {
log.Info().
b.l.Info().
Bool("hasGeth", b.hasGeth).
Bool("hasMockServer", b.hasMockServer).
Int("externalAdapterCount", b.externalAdapterCount).
Expand All @@ -107,12 +115,12 @@ func (b *CLTestEnvBuilder) buildNewEnv(cfg *TestEnvConfig) (*CLClusterTestEnv, e
var te *CLClusterTestEnv
var err error
if cfg != nil {
te, err = NewTestEnvFromCfg(cfg)
te, err = NewTestEnvFromCfg(b.l, cfg)
if err != nil {
return nil, err
}
} else {
te, err = NewTestEnv()
te, err = NewTestEnv(b.l)
if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions integration-tests/smoke/automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ func TestAutomationCheckPerformGasLimit(t *testing.T) {
highCheckGasLimit := automationDefaultRegistryConfig
highCheckGasLimit.CheckGasLimit = uint32(5000000)
highCheckGasLimit.RegistryVersion = registryVersion
ocrConfig, err := actions.BuildAutoOCR2ConfigVarsLocal(t, nodesWithoutBootstrap, highCheckGasLimit, registrar.Address(), 30*time.Second)
ocrConfig, err := actions.BuildAutoOCR2ConfigVarsLocal(l, nodesWithoutBootstrap, highCheckGasLimit, registrar.Address(), 30*time.Second)
require.NoError(t, err, "Error building OCR config")

err = registry.SetConfig(highCheckGasLimit, ocrConfig)
Expand Down Expand Up @@ -990,6 +990,7 @@ func setupAutomationTestDocker(
contracts.KeeperRegistrar,
*test_env.CLClusterTestEnv,
) {
l := utils.GetTestLogger(t)
// Add registry version to config
registryConfig.RegistryVersion = registryVersion
network := networks.SelectedNetwork
Expand All @@ -1008,6 +1009,7 @@ func setupAutomationTestDocker(

// launch the environment
env, err := test_env.NewCLTestEnvBuilder().
WithLogger(l).
WithGeth().
WithMockServer(1).
WithCLNodes(5).
Expand Down Expand Up @@ -1040,9 +1042,9 @@ func setupAutomationTestDocker(
err = linkToken.Transfer(registry.Address(), big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(int64(defaultAmountOfUpkeeps))))
require.NoError(t, err, "Funding keeper registry contract shouldn't fail")

err = actions.CreateOCRKeeperJobsLocal(nodeClients, registry.Address(), network.ChainID, 0, registryVersion)
err = actions.CreateOCRKeeperJobsLocal(l, nodeClients, registry.Address(), network.ChainID, 0, registryVersion)
require.NoError(t, err, "Error creating OCR Keeper Jobs")
ocrConfig, err := actions.BuildAutoOCR2ConfigVarsLocal(t, workerNodes, registryConfig, registrar.Address(), 30*time.Second)
ocrConfig, err := actions.BuildAutoOCR2ConfigVarsLocal(l, workerNodes, registryConfig, registrar.Address(), 30*time.Second)
require.NoError(t, err, "Error building OCR config vars")
err = registry.SetConfig(automationDefaultRegistryConfig, ocrConfig)
require.NoError(t, err, "Registry config should be set successfully")
Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestCronBasic(t *testing.T) {
l := utils.GetTestLogger(t)

env, err := test_env.NewCLTestEnvBuilder().
WithLogger(l).
WithGeth().
WithMockServer(1).
WithCLNodes(1).
Expand Down
Loading

0 comments on commit a5e0ff9

Please sign in to comment.