diff --git a/.github/workflows/live-testnet-tests.yml b/.github/workflows/live-testnet-tests.yml index f79c40f3f1e..2dbb7c3e688 100644 --- a/.github/workflows/live-testnet-tests.yml +++ b/.github/workflows/live-testnet-tests.yml @@ -119,11 +119,12 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }} - name: Build Tests - uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-tests@912bed7e07a1df4d06ea53a031e9773bb65dc7bd # v2.3.0 + uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-tests@8872f6ea8c4a0351206336528d28ebf2f635d80d # v2.3.0 with: test_download_vendor_packages_command: cd ./integration-tests && go mod download token: ${{ secrets.GITHUB_TOKEN }} go_mod_path: ./integration-tests/go.mod + go_tags: embed cache_key_id: core-e2e-${{ env.MOD_CACHE_VERSION }} cache_restore_only: "true" binary_name: tests @@ -276,11 +277,18 @@ jobs: PYROSCOPE_ENVIRONMENT: ci-smoke-${{ matrix.product }}-sepolia PYROSCOPE_KEY: ${{ secrets.QA_PYROSCOPE_KEY }} run: | - # load reusable functions - source ./.github/scripts/functions.sh - - # load reusable functions - source ./.github/scripts/functions.sh + convert_to_toml_array() { + local IFS=',' + local input_array=($1) + local toml_array_format="[" + + for element in "${input_array[@]}"; do + toml_array_format+="\"$element\"," + done + + toml_array_format="${toml_array_format%,}]" + echo "$toml_array_format" + } if [ -n "$PYROSCOPE_SERVER" ]; then pyroscope_enabled=true @@ -366,11 +374,7 @@ jobs: - name: Download Tests Binary uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: tests - - name: Download TOML configs artifact - uses: actions/download-artifact@v3 - with: - name: toml_configs + name: tests - name: Unzip artifact with TOML configs run: unzip toml_configs.zip - name: Prepare Base64 TOML override @@ -379,8 +383,18 @@ jobs: PYROSCOPE_ENVIRONMENT: ci-smoke-${{ matrix.product }}-bsc-testnet PYROSCOPE_KEY: ${{ secrets.QA_PYROSCOPE_KEY }} run: | - # load reusable functions - source ./.github/scripts/functions.sh + convert_to_toml_array() { + local IFS=',' + local input_array=($1) + local toml_array_format="[" + + for element in "${input_array[@]}"; do + toml_array_format+="\"$element\"," + done + + toml_array_format="${toml_array_format%,}]" + echo "$toml_array_format" + } if [ -n "$PYROSCOPE_SERVER" ]; then pyroscope_enabled=true diff --git a/integration-tests/testconfig/configs_embed.go b/integration-tests/testconfig/configs_embed.go new file mode 100644 index 00000000000..0b58f40f5d8 --- /dev/null +++ b/integration-tests/testconfig/configs_embed.go @@ -0,0 +1,21 @@ +//go:build embed +// +build embed + +package testconfig + +import "embed" + +//go:embed default.toml +//go:embed automation/automation.toml +//go:embed functions/functions.toml +//go:embed keeper/keeper.toml +//go:embed logpoller/log_poller.toml +//go:embed node/node.toml +//go:embed ocr/ocr.toml +//go:embed vrfv2/vrfv2.toml +//go:embed vrfv2plus/vrfv2plus.toml +var embeddedConfigsFs embed.FS + +func init() { + areConfigsEmbedded = true +} diff --git a/integration-tests/testconfig/configs_noembed.go b/integration-tests/testconfig/configs_noembed.go new file mode 100644 index 00000000000..95572c4a044 --- /dev/null +++ b/integration-tests/testconfig/configs_noembed.go @@ -0,0 +1,12 @@ +//go:build !embed +// +build !embed + +package testconfig + +import "embed" + +var embeddedConfigsFs embed.FS + +func init() { + areConfigsEmbedded = false +} diff --git a/integration-tests/testconfig/logpoller/config.go b/integration-tests/testconfig/log_poller/config.go similarity index 100% rename from integration-tests/testconfig/logpoller/config.go rename to integration-tests/testconfig/log_poller/config.go diff --git a/integration-tests/testconfig/logpoller/example.toml b/integration-tests/testconfig/log_poller/example.toml similarity index 100% rename from integration-tests/testconfig/logpoller/example.toml rename to integration-tests/testconfig/log_poller/example.toml diff --git a/integration-tests/testconfig/logpoller/log_poller.toml b/integration-tests/testconfig/log_poller/log_poller.toml similarity index 100% rename from integration-tests/testconfig/logpoller/log_poller.toml rename to integration-tests/testconfig/log_poller/log_poller.toml diff --git a/integration-tests/testconfig/testconfig.go b/integration-tests/testconfig/testconfig.go index 895dcdafd57..dcb9c1f729c 100644 --- a/integration-tests/testconfig/testconfig.go +++ b/integration-tests/testconfig/testconfig.go @@ -1,6 +1,7 @@ package testconfig import ( + "embed" "encoding/base64" "fmt" "os" @@ -16,18 +17,17 @@ import ( ctf_config "github.com/smartcontractkit/chainlink-testing-framework/config" ctf_test_env "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" + k8s_config "github.com/smartcontractkit/chainlink-testing-framework/k8s/config" "github.com/smartcontractkit/chainlink-testing-framework/logging" "github.com/smartcontractkit/chainlink-testing-framework/utils/osutil" a_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/automation" f_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/functions" keeper_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/keeper" - lp_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/logpoller" + lp_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/log_poller" ocr_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" vrf_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrf" vrfv2_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2" vrfv2plus_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2plus" - - k8s_config "github.com/smartcontractkit/chainlink-testing-framework/k8s/config" ) type TestConfig struct { @@ -51,6 +51,13 @@ type TestConfig struct { ConfigurationName string `toml:"-"` } +var embeddedConfigs embed.FS +var areConfigsEmbedded bool + +func init() { + embeddedConfigs = embeddedConfigsFs +} + // Returns Grafana URL from Logging config func (c *TestConfig) GetGrafanaURL() (string, error) { if c.Logging.Grafana == nil || c.Logging.Grafana.Url == nil { @@ -163,30 +170,14 @@ func GetConfig(configurationName string, product Product) (TestConfig, error) { logger.Debug().Msgf("Will apply configuration named '%s' if it is found in any of the configs", configurationName) - for _, fileName := range fileNames { - logger.Debug().Msgf("Looking for config file %s", fileName) - filePath, err := osutil.FindFile(fileName, osutil.DEFAULT_STOP_FILE_NAME, 2) - - if err != nil && errors.Is(err, os.ErrNotExist) { - logger.Debug().Msgf("Config file %s not found", fileName) - continue - } else if err != nil { - return TestConfig{}, errors.Wrapf(err, "error looking for file %s", filePath) - } - logger.Debug().Str("location", filePath).Msgf("Found config file %s", fileName) - - content, err := readFile(filePath) - if err != nil { - return TestConfig{}, errors.Wrapf(err, "error reading file %s", filePath) - } - + var byteToTestConfig = func(content []byte) (TestConfig, error) { var readConfig TestConfig - err = toml.Unmarshal(content, &readConfig) + err := toml.Unmarshal(content, &readConfig) if err != nil { return TestConfig{}, errors.Wrapf(err, "error unmarshaling config") } - logger.Debug().Msgf("Successfully unmarshalled config file %s", fileName) + logger.Debug().Msgf("Successfully unmarshalled config file") maybeTestConfigs = append(maybeTestConfigs, readConfig) var someToml map[string]interface{} @@ -196,8 +187,8 @@ func GetConfig(configurationName string, product Product) (TestConfig, error) { } if _, ok := someToml[configurationName]; !ok { - logger.Debug().Msgf("Config file %s does not contain configuration named '%s', will read only default configuration.", fileName, configurationName) - continue + logger.Debug().Msgf("Config file does not contain configuration named '%s', will read only default configuration.", configurationName) + return readConfig, nil } marshalled, err := toml.Marshal(someToml[configurationName]) @@ -211,6 +202,53 @@ func GetConfig(configurationName string, product Product) (TestConfig, error) { } logger.Debug().Msgf("Configuration named '%s' read successfully.", configurationName) + + return readConfig, nil + } + + // read embedded configs is build tag "embed" is set + // this makes our life much easier when using a binary + if areConfigsEmbedded { + logger.Info().Msg("Reading embedded configs") + embeddedFiles := []string{"default.toml", fmt.Sprintf("%s/%s.toml", product, product)} + for _, fileName := range embeddedFiles { + file, err := embeddedConfigs.ReadFile(fileName) + if err != nil { + return TestConfig{}, errors.Wrapf(err, "error reading embedded config") + } + + readConfig, err := byteToTestConfig(file) + if err != nil { + return TestConfig{}, errors.Wrapf(err, "error reading embedded config") + } + + maybeTestConfigs = append(maybeTestConfigs, readConfig) + } + } + + logger.Info().Msg("Reading configs from file system") + for _, fileName := range fileNames { + logger.Debug().Msgf("Looking for config file %s", fileName) + filePath, err := osutil.FindFile(fileName, osutil.DEFAULT_STOP_FILE_NAME, 2) + + if err != nil && errors.Is(err, os.ErrNotExist) { + logger.Debug().Msgf("Config file %s not found", fileName) + continue + } else if err != nil { + return TestConfig{}, errors.Wrapf(err, "error looking for file %s", filePath) + } + logger.Debug().Str("location", filePath).Msgf("Found config file %s", fileName) + + content, err := readFile(filePath) + if err != nil { + return TestConfig{}, errors.Wrapf(err, "error reading file %s", filePath) + } + + readConfig, err := byteToTestConfig(content) + if err != nil { + return TestConfig{}, errors.Wrapf(err, "error reading file %s", filePath) + } + maybeTestConfigs = append(maybeTestConfigs, readConfig) } diff --git a/integration-tests/universal/log_poller/helpers.go b/integration-tests/universal/log_poller/helpers.go index 2b8c0a990a5..88aeb4df23f 100644 --- a/integration-tests/universal/log_poller/helpers.go +++ b/integration-tests/universal/log_poller/helpers.go @@ -43,7 +43,7 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" - lp_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/logpoller" + lp_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/log_poller" "github.com/smartcontractkit/chainlink/integration-tests/types/config/node" )