From ae00337459af5240bbb0b8ad3431d5072ff6abd0 Mon Sep 17 00:00:00 2001 From: Damjan Smickovski Date: Thu, 7 Dec 2023 08:42:47 +0100 Subject: [PATCH 1/6] Adding nix configurations and setup --- integration-tests/default.nix | 14 + integration-tests/flake.lock | 410 ++++++++++++++++++++++++++++ integration-tests/flake.nix | 92 +++++++ integration-tests/smoke/default.nix | 61 +++++ integration-tests/smoke/run_test.sh | 117 ++++++++ integration-tests/smoke/shell.nix | 21 ++ 6 files changed, 715 insertions(+) create mode 100644 integration-tests/default.nix create mode 100644 integration-tests/flake.lock create mode 100644 integration-tests/flake.nix create mode 100644 integration-tests/smoke/default.nix create mode 100755 integration-tests/smoke/run_test.sh create mode 100644 integration-tests/smoke/shell.nix diff --git a/integration-tests/default.nix b/integration-tests/default.nix new file mode 100644 index 00000000000..266d78b0684 --- /dev/null +++ b/integration-tests/default.nix @@ -0,0 +1,14 @@ +{ pkgs # pkgs is a nixpkgs inheriting the system with the gomod2nix overlay to build Go pkgs +}: + + +let + # imports ./ethereum.print-chain/default.nix inheriting pkgs and chainlink-dev args + ethereum_test-run-smoke = pkgs.callPackage ./smoke { inherit pkgs; }; +in +{ + # exports a package. to be consumed by the flake.nix + packages = { + chainlink-dev_ethereum_test-run-smoke = ethereum_test-run-smoke.package; + }; +} diff --git a/integration-tests/flake.lock b/integration-tests/flake.lock new file mode 100644 index 00000000000..5ad89aee21c --- /dev/null +++ b/integration-tests/flake.lock @@ -0,0 +1,410 @@ +{ + "nodes": { + "chainlink": { + "inputs": { + "cl_src": "cl_src", + "flake-utils": "flake-utils", + "gomod2nix": "gomod2nix", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "dir": "chainlink", + "lastModified": 1701700033, + "narHash": "sha256-C6iZcbWN4EDL+TIBa9oYCnVmzUrGvu7mA8Lo3OxlXMo=", + "ref": "main", + "rev": "0b5484846caac8f542d9082ec08700c4205fde07", + "revCount": 121, + "type": "git", + "url": "ssh://git@github.com/smartcontractkit/chainlink-project-nix-poc?dir=chainlink" + }, + "original": { + "dir": "chainlink", + "ref": "main", + "type": "git", + "url": "ssh://git@github.com/smartcontractkit/chainlink-project-nix-poc?dir=chainlink" + } + }, + "chainlink-dev": { + "inputs": { + "flake-utils": "flake-utils_3", + "gomod2nix": "gomod2nix_2", + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "dir": "chainlink-dev", + "lastModified": 1701700033, + "narHash": "sha256-C6iZcbWN4EDL+TIBa9oYCnVmzUrGvu7mA8Lo3OxlXMo=", + "ref": "main", + "rev": "0b5484846caac8f542d9082ec08700c4205fde07", + "revCount": 121, + "type": "git", + "url": "ssh://git@github.com/smartcontractkit/chainlink-project-nix-poc?dir=chainlink-dev" + }, + "original": { + "dir": "chainlink-dev", + "ref": "main", + "type": "git", + "url": "ssh://git@github.com/smartcontractkit/chainlink-project-nix-poc?dir=chainlink-dev" + } + }, + "cl_src": { + "flake": false, + "locked": { + "lastModified": 1694793897, + "narHash": "sha256-mh1D+6Ie/cxoCqobHgora70HJ8Lmj5iOZsKfmty1JZM=", + "owner": "smartcontractkit", + "repo": "chainlink", + "rev": "5036be4a1c953e81b92685eb47423b92248f28b5", + "type": "github" + }, + "original": { + "owner": "smartcontractkit", + "repo": "chainlink", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "inputs": { + "systems": "systems_4" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_5": { + "inputs": { + "systems": "systems_5" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1694616124, + "narHash": "sha256-c49BVhQKw3XDRgt+y+uPAbArtgUlMXCET6VxEBmzHXE=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "f95720e89af6165c8c0aa77f180461fe786f3c21", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "gomod2nix_2": { + "inputs": { + "nixpkgs": "nixpkgs_3", + "utils": "utils" + }, + "locked": { + "lastModified": 1677459247, + "narHash": "sha256-JbakfAiPYmCCV224yAMq/XO0udN5coWv/oazblMKdoY=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "3cbf3a51fe32e2f57af4c52744e7228bab22983d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "gomod2nix_3": { + "inputs": { + "flake-utils": "flake-utils_5", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1701687253, + "narHash": "sha256-qJCMxIKWXonJODPF2oV7mCd0xu7VYVenTucrY0bizto=", + "owner": "tweag", + "repo": "gomod2nix", + "rev": "001bbfa22e2adeb87c34c6015e5694e88721cabe", + "type": "github" + }, + "original": { + "owner": "tweag", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1658285632, + "narHash": "sha256-zRS5S/hoeDGUbO+L95wXG9vJNwsSYcl93XiD0HQBXLk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5342fc6fb59d0595d26883c3cadff16ce58e44f3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1694794664, + "narHash": "sha256-+xvmbTgCKFI5PipQ/Gp6RzeSQPYBoErb6/sGWbwPriw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bdc382d331167df7ec767268f07038f776ee2303", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1658285632, + "narHash": "sha256-zRS5S/hoeDGUbO+L95wXG9vJNwsSYcl93XiD0HQBXLk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5342fc6fb59d0595d26883c3cadff16ce58e44f3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1693377291, + "narHash": "sha256-vYGY9bnqEeIncNarDZYhm6KdLKgXMS+HA2mTRaWEc80=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e7f38be3775bab9659575f192ece011c033655f0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_5": { + "locked": { + "lastModified": 1701436327, + "narHash": "sha256-tRHbnoNI8SIM5O5xuxOmtSLnswEByzmnQcGGyNRjxsE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "91050ea1e57e50388fa87a3302ba12d188ef723a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "plugins": { + "flake": false, + "locked": { + "lastModified": 1, + "narHash": "sha256-/RilsUf0q205chc3pzljKYgIdKB07x7NI7/NNwfL3uA=", + "path": "/nix/store/vwwbgmhvjrcm5ff7qmxjx1g1x5d8qvf2-source/integration-tests", + "type": "path" + }, + "original": { + "path": "/nix/store/vwwbgmhvjrcm5ff7qmxjx1g1x5d8qvf2-source/integration-tests", + "type": "path" + } + }, + "root": { + "inputs": { + "chainlink": "chainlink", + "chainlink-dev": "chainlink-dev", + "flake-utils": "flake-utils_4", + "gomod2nix": "gomod2nix_3", + "nixpkgs": "nixpkgs_5", + "plugins": "plugins" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_5": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/integration-tests/flake.nix b/integration-tests/flake.nix new file mode 100644 index 00000000000..6fd689808ca --- /dev/null +++ b/integration-tests/flake.nix @@ -0,0 +1,92 @@ +{ + description = "Integration tests"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + + # define gomod2nix which is a dependency to build Go lang plugins + gomod2nix = { + url = "github:tweag/gomod2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.utils.follows = "flake-utils"; + }; + + # define chainlink-dev flake as a input + chainlink-dev.url = "git+ssh://git@github.com/smartcontractkit/chainlink-project-nix-poc?ref=main&dir=chainlink-dev"; # this could also be a project URL + chainlink.url = "git+ssh://git@github.com/smartcontractkit/chainlink-project-nix-poc?ref=main&dir=chainlink"; + + # defines plugins module (default.nix) that aggregates all plugins of this project + plugins = { + url = "./"; + flake = false; + }; + }; + outputs = { self, nixpkgs, flake-utils, gomod2nix, ... }@inputs: + # it enables us to generate all outputs for each default system + (flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { + inherit system; + + # add gomod2nix in pkgs as a Go lang dependecy for plugins + overlays = [ + gomod2nix.overlays.default + ]; + }; + + # wrap together dependencies for plugins + commonArgs = { + inherit pkgs; + }; + + # import custom plugins with required args + plugins = pkgs.callPackage ./. commonArgs; + + # it flats the set tree of the plugins for packages and shell. + # (e.g. [ packages.pkg1, packages.pkg2 ] -> [ pkg1, pkg2 ] ) + pluginsPackage = flake-utils.lib.flattenTree plugins.packages; + in + { + # it outputs packages all packages defined in plugins + packages = pluginsPackage; + + # it outputs the default shell + devShells.default = + pkgs.mkShell { + buildInputs = with pkgs; [ + # Go + tools + go + gopls + gotools + go-tools + + # k8s + kube3d + kubectl + k9s + kubernetes-helm + + # NOTE: cannot import all packages through chainlink-dev + # nested relative path import of chainlink breaks nix (cannot dynamically calculate absoluate path) + inputs.chainlink-dev.packages.${system}.chainlink-dev + inputs.chainlink.packages.${system}.chainlink + + # add all local plugins of this project + self.packages.${system}.chainlink-dev_ethereum_test-run-smoke + ]++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + pkgs.darwin.apple_sdk.frameworks.Security + ]; + }; + + apps.chainlink-dev_ethereum_test-run-smoke = { + type = "app"; + program = "${self.packages.${system}.chainlink-dev_ethereum_run-smoke}/bin/chainlink-dev.ethereum.test-run-smoke"; + }; + }) + ); + +} diff --git a/integration-tests/smoke/default.nix b/integration-tests/smoke/default.nix new file mode 100644 index 00000000000..7ebe27d592e --- /dev/null +++ b/integration-tests/smoke/default.nix @@ -0,0 +1,61 @@ +{ pkgs }: + +let + scriptName = "ethereum-smoke-tests"; + go = pkgs.go_1_21; + scriptBuildInputs = with pkgs; [ go go-ethereum ]; # add geth to handle missing underlying dependencies + testDir = toString ./.; + + wrapperScript = pkgs.writeShellScriptBin scriptName '' + #!/usr/bin/env bash + cd ${testDir} + ${testDir}/run_test.sh "$@" + ''; + + symlink = pkgs.symlinkJoin { + name = scriptName; + paths = [ wrapperScript ] ++ scriptBuildInputs; + buildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + wrapProgram $out/bin/${scriptName} \ + --prefix PATH : $out/bin \ + --set GOROOT "${go}/share/go" \ + --run 'export GOPATH=$HOME/go' \ + --run 'export PATH=$GOPATH/bin:$PATH' + ''; + }; + + package = pkgs.stdenv.mkDerivation { + name = scriptName; + buildCommand = "ln -s ${symlink} $out"; + installPhase = '' + mkdir -p $out/bin + cp ${wrapperScript}/bin/${scriptName} $out/bin/ + chmod +x $out/bin/${scriptName} + ''; + meta = { + description = "Main script to run ethereum smoke tests"; + longDescription = '' + TBD + ''; + homepage = "TBD"; + maintainers = [ "QA, TT" ]; + }; + }; +in +{ + package = package; + devShells.default = pkgs.mkShell { + # based on pkgs, add those packages into env + buildInputs = with pkgs; [ + # Go + tools + go + gopls + gotools + go-tools + ]; + + # import any additional build inputs from goPackage + inputsFrom = [ package ]; + }; +} diff --git a/integration-tests/smoke/run_test.sh b/integration-tests/smoke/run_test.sh new file mode 100755 index 00000000000..5f1d315813f --- /dev/null +++ b/integration-tests/smoke/run_test.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +config_loaded=0 + +read_input() { + local prompt=$1 + local allow_empty=$2 + local input_type=$3 + local input + + while true; do + read -p "$prompt" input + + if [[ "$input_type" == "number" ]]; then + if [[ $input =~ ^[0-9]+(\.[0-9]+)?$ ]]; then + break + else + echo "Please enter a valid number." + continue + fi + fi + + if [[ -n "$input" || "$allow_empty" == "true" ]]; then + break + else + echo "This is a required field. Please enter a value." + fi + done + + echo "$input" +} + +select_network_and_set_urls() { + echo "Select a network to run the test on:" + select network in SIMULATED SIMULATED_1 SIMULATED_2 SIMULATED_BESU_NONDEV_1 SIMULATED_BESU_NONDEV_2 SIMULATED_NONDEV ETHEREUM_MAINNET GOERLI SEPOLIA KLAYTN_MAINNET KLAYTN_BAOBAB METIS_ANDROMEDA METIS_STARDUST ARBITRUM_MAINNET ARBITRUM_GOERLI ARBITRUM_SEPOLIA OPTIMISM_MAINNET OPTIMISM_GOERLI OPTIMISM_SEPOLIA BASE_GOERLI BASE_SEPOLIA CELO_ALFAJORES CELO_MAINNET RSK POLYGON_MUMBAI POLYGON_MAINNET AVALANCHE_FUJI AVALANCHE_MAINNET QUORUM SCROLL_SEPOLIA SCROLL_MAINNET BASE_MAINNET BSC_TESTNET BSC_MAINNET LINEA_GOERLI LINEA_MAINNET POLYGON_ZKEVM_GOERLI POLYGON_ZKEVM_MAINNET FANTOM_TESTNET FANTOM_MAINNET WEMIX_TESTNET WEMIX_MAINNET KROMA_SEPOLIA KROMA_MAINNET ZK_SYNC_GOERLI ZK_SYNC_MAINNET; do + if [[ -n "$network" ]]; then + SELECTED_NETWORKS="$network" + break + else + echo "Invalid selection. Please try again." + fi + done + + http_url=$(read_input "Enter HTTP RPC url for $SELECTED_NETWORKS: " false) + ws_url=$(read_input "Enter WS RPC url for $SELECTED_NETWORKS: " false) +} + +# Check for an existing config +load_previous_config() { + local config_file="/tmp/${product}_config.env" + if [ -f "$config_file" ]; then + read -p "Previous configuration for $product found. Load it? (y/n): " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Loading previous configuration..." + source "$config_file" + config_loaded=1 + return 0 + fi + fi + return 1 +} + +# Save config +save_current_config() { + local config_file="/tmp/${product}_config.env" + cat << EOF > "$config_file" +export SELECTED_NETWORKS="$SELECTED_NETWORKS" +export ${SELECTED_NETWORKS}_HTTP_URLS="$http_url" +export ${SELECTED_NETWORKS}_URLS="$ws_url" +export CHAINLINK_ENV_USER="$user" +export TEST_LOG_LEVEL="$log_level" +export ${SELECTED_NETWORKS}_KEYS="$private_key" +export CHAINLINK_IMAGE="$docker_image_repo" +export CHAINLINK_NODE_FUNDING="$funding_per_node" +export CHAINLINK_VERSION="$docker_image_version" +export product="$product" +export SUITE="$additional_args" +EOF +source "$config_file" +} + +# Run tests +run_automation() { + echo "Running command with provided environment variables..." + go test -v -test.run "$SUITE" ./automation_test.go +} + +# Catch errors +trap 'echo "An error occurred. Exiting..."; exit 1;' ERR + +PS3="Please select a product: " +options=("Automation" "Exit") +select product in "${options[@]}"; do + case $product in + "Automation") + if ! load_previous_config; then + user=$(read_input "Please enter a user that the test will run under: " false) + log_level=$(read_input "Select test log level (INFO, DEBUG, ERROR): " false) + select_network_and_set_urls + private_key=$(read_input "Enter the private key the test should use: " false) + docker_image_repo=$(read_input "Enter docker image repository for core: " false) + funding_per_node=$(read_number "Enter funding per node: " false, "number") + docker_image_version=$(read_input "Enter docker image version for core: " false) + additional_args=$(read_input "Enter the test suite: " false) + save_current_config + fi + run_automation + break + ;; + "Exit") + echo "Exiting the wizard." + exit 0 + ;; + *) echo "Invalid option $REPLY";; + esac +done diff --git a/integration-tests/smoke/shell.nix b/integration-tests/smoke/shell.nix new file mode 100644 index 00000000000..f19e1e732a4 --- /dev/null +++ b/integration-tests/smoke/shell.nix @@ -0,0 +1,21 @@ +{ pkgs # pkgs is a nixpkgs inheriting based on system with the gomod2nix overlay to build Go pkgs +, chainlink-dev # chainlink-dev is the devShell of the chainlink-dev CLI +}: + +# exports an shell derivation to be imported by the default.nix +pkgs.mkShell { + # based on pkgs, add those packages into env + buildInputs = with pkgs; [ + # Go + tools + go + gopls + gotools + go-tools + k3dnix + ]; + + # composing chainlink-dev shell to this shell enables us to have chainlink-dev CLI into env + inputsFrom = [ + chainlink-dev + ]; +} From 83b9f594d2f0e9a89393fd492b252557c89a41c8 Mon Sep 17 00:00:00 2001 From: Damjan Smickovski Date: Thu, 7 Dec 2023 08:55:55 +0100 Subject: [PATCH 2/6] Changed script name --- integration-tests/smoke/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/smoke/default.nix b/integration-tests/smoke/default.nix index 7ebe27d592e..5423672a01f 100644 --- a/integration-tests/smoke/default.nix +++ b/integration-tests/smoke/default.nix @@ -1,7 +1,7 @@ { pkgs }: let - scriptName = "ethereum-smoke-tests"; + scriptName = "test-run-smoke"; go = pkgs.go_1_21; scriptBuildInputs = with pkgs; [ go go-ethereum ]; # add geth to handle missing underlying dependencies testDir = toString ./.; From a48397a66b87c518480ed56f6b5764aa4eab0256 Mon Sep 17 00:00:00 2001 From: Damjan Smickovski Date: Thu, 7 Dec 2023 09:01:53 +0100 Subject: [PATCH 3/6] Changed naming --- integration-tests/default.nix | 4 ++-- integration-tests/flake.lock | 6 +++--- integration-tests/flake.nix | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integration-tests/default.nix b/integration-tests/default.nix index 266d78b0684..d9476241266 100644 --- a/integration-tests/default.nix +++ b/integration-tests/default.nix @@ -4,11 +4,11 @@ let # imports ./ethereum.print-chain/default.nix inheriting pkgs and chainlink-dev args - ethereum_test-run-smoke = pkgs.callPackage ./smoke { inherit pkgs; }; + test-run-smoke = pkgs.callPackage ./smoke { inherit pkgs; }; in { # exports a package. to be consumed by the flake.nix packages = { - chainlink-dev_ethereum_test-run-smoke = ethereum_test-run-smoke.package; + integration-tests_test-run-smoke = test-run-smoke.package; }; } diff --git a/integration-tests/flake.lock b/integration-tests/flake.lock index 5ad89aee21c..faee603230b 100644 --- a/integration-tests/flake.lock +++ b/integration-tests/flake.lock @@ -295,12 +295,12 @@ "flake": false, "locked": { "lastModified": 1, - "narHash": "sha256-/RilsUf0q205chc3pzljKYgIdKB07x7NI7/NNwfL3uA=", - "path": "/nix/store/vwwbgmhvjrcm5ff7qmxjx1g1x5d8qvf2-source/integration-tests", + "narHash": "sha256-7ix4mzRyxwNXdLgJ6LzDKjKDnJxci+cwTm2cYJ7Ze80=", + "path": "/nix/store/qyv7rwysb6lrs1jkqpjavd9zmcandmjn-source/integration-tests", "type": "path" }, "original": { - "path": "/nix/store/vwwbgmhvjrcm5ff7qmxjx1g1x5d8qvf2-source/integration-tests", + "path": "/nix/store/qyv7rwysb6lrs1jkqpjavd9zmcandmjn-source/integration-tests", "type": "path" } }, diff --git a/integration-tests/flake.nix b/integration-tests/flake.nix index 6fd689808ca..992710a5c86 100644 --- a/integration-tests/flake.nix +++ b/integration-tests/flake.nix @@ -74,7 +74,7 @@ inputs.chainlink.packages.${system}.chainlink # add all local plugins of this project - self.packages.${system}.chainlink-dev_ethereum_test-run-smoke + self.packages.${system}.integration-tests_test-run-smoke ]++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ # Additional darwin specific inputs can be set here pkgs.libiconv @@ -82,9 +82,9 @@ ]; }; - apps.chainlink-dev_ethereum_test-run-smoke = { + apps.integration-tests_test-run-smoke = { type = "app"; - program = "${self.packages.${system}.chainlink-dev_ethereum_run-smoke}/bin/chainlink-dev.ethereum.test-run-smoke"; + program = "${self.packages.${system}.integration-tests_run-smoke}/bin/integration-tests.test-run-smoke"; }; }) ); From 9ee5e8c4f605a9b604a3e8cd9e4ecb14231921e7 Mon Sep 17 00:00:00 2001 From: Damjan Smickovski Date: Thu, 7 Dec 2023 09:30:17 +0100 Subject: [PATCH 4/6] Adjusted package name --- integration-tests/flake.lock | 6 +++--- integration-tests/smoke/default.nix | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integration-tests/flake.lock b/integration-tests/flake.lock index faee603230b..70d088e4e4d 100644 --- a/integration-tests/flake.lock +++ b/integration-tests/flake.lock @@ -295,12 +295,12 @@ "flake": false, "locked": { "lastModified": 1, - "narHash": "sha256-7ix4mzRyxwNXdLgJ6LzDKjKDnJxci+cwTm2cYJ7Ze80=", - "path": "/nix/store/qyv7rwysb6lrs1jkqpjavd9zmcandmjn-source/integration-tests", + "narHash": "sha256-7vxtoPQQarUWy3nPJdjzInUDcPrH/TgE83pgFFx9eP8=", + "path": "/nix/store/7bi8q2llb9pvgfzc41xlw43j4zvwiirn-source/integration-tests", "type": "path" }, "original": { - "path": "/nix/store/qyv7rwysb6lrs1jkqpjavd9zmcandmjn-source/integration-tests", + "path": "/nix/store/7bi8q2llb9pvgfzc41xlw43j4zvwiirn-source/integration-tests", "type": "path" } }, diff --git a/integration-tests/smoke/default.nix b/integration-tests/smoke/default.nix index 5423672a01f..cd2ebf6eb06 100644 --- a/integration-tests/smoke/default.nix +++ b/integration-tests/smoke/default.nix @@ -1,7 +1,7 @@ { pkgs }: let - scriptName = "test-run-smoke"; + scriptName = "integration-tests_test-run-smoke"; go = pkgs.go_1_21; scriptBuildInputs = with pkgs; [ go go-ethereum ]; # add geth to handle missing underlying dependencies testDir = toString ./.; From fffd8a7de7e0c095c4c357145274a291e4d8bcda Mon Sep 17 00:00:00 2001 From: Damjan Smickovski Date: Thu, 7 Dec 2023 10:28:05 +0100 Subject: [PATCH 5/6] Adjusted naming --- integration-tests/default.nix | 2 +- integration-tests/flake.lock | 6 +++--- integration-tests/flake.nix | 6 +++--- integration-tests/smoke/default.nix | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integration-tests/default.nix b/integration-tests/default.nix index d9476241266..5dc72302416 100644 --- a/integration-tests/default.nix +++ b/integration-tests/default.nix @@ -9,6 +9,6 @@ in { # exports a package. to be consumed by the flake.nix packages = { - integration-tests_test-run-smoke = test-run-smoke.package; + integration-tests_run-smoke = test-run-smoke.package; }; } diff --git a/integration-tests/flake.lock b/integration-tests/flake.lock index 70d088e4e4d..ae1a872fabb 100644 --- a/integration-tests/flake.lock +++ b/integration-tests/flake.lock @@ -295,12 +295,12 @@ "flake": false, "locked": { "lastModified": 1, - "narHash": "sha256-7vxtoPQQarUWy3nPJdjzInUDcPrH/TgE83pgFFx9eP8=", - "path": "/nix/store/7bi8q2llb9pvgfzc41xlw43j4zvwiirn-source/integration-tests", + "narHash": "sha256-5opfeYSAUWRs9vmSNlRQuD9XxnRjIH6+1ee0U815S+s=", + "path": "/nix/store/p8srg1wh944kx3h1pp1qyzsrg8y9rl03-source/integration-tests", "type": "path" }, "original": { - "path": "/nix/store/7bi8q2llb9pvgfzc41xlw43j4zvwiirn-source/integration-tests", + "path": "/nix/store/p8srg1wh944kx3h1pp1qyzsrg8y9rl03-source/integration-tests", "type": "path" } }, diff --git a/integration-tests/flake.nix b/integration-tests/flake.nix index 992710a5c86..56df8615496 100644 --- a/integration-tests/flake.nix +++ b/integration-tests/flake.nix @@ -74,7 +74,7 @@ inputs.chainlink.packages.${system}.chainlink # add all local plugins of this project - self.packages.${system}.integration-tests_test-run-smoke + self.packages.${system}.integration-tests_run-smoke ]++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ # Additional darwin specific inputs can be set here pkgs.libiconv @@ -82,9 +82,9 @@ ]; }; - apps.integration-tests_test-run-smoke = { + apps.integration-tests_run-smoke = { type = "app"; - program = "${self.packages.${system}.integration-tests_run-smoke}/bin/integration-tests.test-run-smoke"; + program = "${self.packages.${system}.integration-tests_run-smoke}/bin/integration-tests_run-smoke"; }; }) ); diff --git a/integration-tests/smoke/default.nix b/integration-tests/smoke/default.nix index cd2ebf6eb06..e7990ba5889 100644 --- a/integration-tests/smoke/default.nix +++ b/integration-tests/smoke/default.nix @@ -1,7 +1,7 @@ { pkgs }: let - scriptName = "integration-tests_test-run-smoke"; + scriptName = "integration-tests_run-smoke"; go = pkgs.go_1_21; scriptBuildInputs = with pkgs; [ go go-ethereum ]; # add geth to handle missing underlying dependencies testDir = toString ./.; From e546099844ab4243136de065ab61c42b4914b81f Mon Sep 17 00:00:00 2001 From: Damjan Smickovski Date: Mon, 11 Dec 2023 10:34:05 +0100 Subject: [PATCH 6/6] Changed script to flag based instead of interactive --- integration-tests/smoke/run_test.sh | 203 ++++++++++++++++------------ 1 file changed, 119 insertions(+), 84 deletions(-) diff --git a/integration-tests/smoke/run_test.sh b/integration-tests/smoke/run_test.sh index 5f1d315813f..ab04dc8ac70 100755 --- a/integration-tests/smoke/run_test.sh +++ b/integration-tests/smoke/run_test.sh @@ -1,73 +1,138 @@ #!/bin/bash -config_loaded=0 - -read_input() { - local prompt=$1 - local allow_empty=$2 - local input_type=$3 - local input - - while true; do - read -p "$prompt" input - - if [[ "$input_type" == "number" ]]; then - if [[ $input =~ ^[0-9]+(\.[0-9]+)?$ ]]; then - break - else - echo "Please enter a valid number." - continue - fi - fi +# Get working dir of script +SCRIPT=$(readlink -f "$0") +TEST_PATH=$(dirname "$SCRIPT") - if [[ -n "$input" || "$allow_empty" == "true" ]]; then - break - else - echo "This is a required field. Please enter a value." - fi - done +# Init +SELECTED_NETWORKS="" +http_url="" +ws_url="" +user="" +log_level="DEBUG" # Default value +private_key="" +docker_image_repo="" +funding_per_node="0.1" # Default value +docker_image_version="" +additional_args="" +product="" +list_networks=0 +load_config="" +show_help=0 - echo "$input" +# Help +usage() { + echo "Usage: $0 [--list-networks] [--load-config file] [--selected-networks SELECTED_NETWORKS] [--http-url http_url] [--ws-url ws_url] [--user user] [--log-level log_level] [--private-key private_key] [--docker-image-repo docker_image_repo] [--funding-per-node funding_per_node] [--docker-image-version docker_image_version] [--test-suite test_suite] [--product product]" + echo + echo "Options:" + echo " --list-networks List all available networks" + echo " --load-config Load configuration from a file" + echo " --selected-networks Specify the selected networks" + echo " --http-url Specify HTTP RPC url" + echo " --ws-url Specify WS RPC url" + echo " --user Specify the user" + echo " --log-level Specify the log level (INFO, DEBUG, ERROR). Default: DEBUG" + echo " --private-key Specify the private key" + echo " --docker-image-repo Specify docker image repository" + echo " --funding-per-node Specify funding per node. Default: 0.1" + echo " --docker-image-version Specify docker image version" + echo " --test-suite Specify additional test suite args" + echo " --product Specify the product (Automation)" + exit 0 } -select_network_and_set_urls() { - echo "Select a network to run the test on:" - select network in SIMULATED SIMULATED_1 SIMULATED_2 SIMULATED_BESU_NONDEV_1 SIMULATED_BESU_NONDEV_2 SIMULATED_NONDEV ETHEREUM_MAINNET GOERLI SEPOLIA KLAYTN_MAINNET KLAYTN_BAOBAB METIS_ANDROMEDA METIS_STARDUST ARBITRUM_MAINNET ARBITRUM_GOERLI ARBITRUM_SEPOLIA OPTIMISM_MAINNET OPTIMISM_GOERLI OPTIMISM_SEPOLIA BASE_GOERLI BASE_SEPOLIA CELO_ALFAJORES CELO_MAINNET RSK POLYGON_MUMBAI POLYGON_MAINNET AVALANCHE_FUJI AVALANCHE_MAINNET QUORUM SCROLL_SEPOLIA SCROLL_MAINNET BASE_MAINNET BSC_TESTNET BSC_MAINNET LINEA_GOERLI LINEA_MAINNET POLYGON_ZKEVM_GOERLI POLYGON_ZKEVM_MAINNET FANTOM_TESTNET FANTOM_MAINNET WEMIX_TESTNET WEMIX_MAINNET KROMA_SEPOLIA KROMA_MAINNET ZK_SYNC_GOERLI ZK_SYNC_MAINNET; do - if [[ -n "$network" ]]; then - SELECTED_NETWORKS="$network" - break - else - echo "Invalid selection. Please try again." +list_networks() { + echo "Available networks:" + networks="SIMULATED SIMULATED_1 SIMULATED_2 SIMULATED_BESU_NONDEV_1 SIMULATED_BESU_NONDEV_2 SIMULATED_NONDEV ETHEREUM_MAINNET GOERLI SEPOLIA KLAYTN_MAINNET KLAYTN_BAOBAB METIS_ANDROMEDA METIS_STARDUST ARBITRUM_MAINNET ARBITRUM_GOERLI ARBITRUM_SEPOLIA OPTIMISM_MAINNET OPTIMISM_GOERLI OPTIMISM_SEPOLIA BASE_GOERLI BASE_SEPOLIA CELO_ALFAJORES CELO_MAINNET RSK POLYGON_MUMBAI POLYGON_MAINNET AVALANCHE_FUJI AVALANCHE_MAINNET QUORUM SCROLL_SEPOLIA SCROLL_MAINNET BASE_MAINNET BSC_TESTNET BSC_MAINNET LINEA_GOERLI LINEA_MAINNET POLYGON_ZKEVM_GOERLI POLYGON_ZKEVM_MAINNET FANTOM_TESTNET FANTOM_MAINNET WEMIX_TESTNET WEMIX_MAINNET KROMA_SEPOLIA KROMA_MAINNET ZK_SYNC_GOERLI ZK_SYNC_MAINNET" + read -r -a network_array <<< "$networks" + columns=4 + for (( i=0; i<${#network_array[@]}; i++ )); do + # Print network name + printf '%-30s' "${network_array[i]}" + + # New line every 'columns' networks + if (( (i + 1) % columns == 0 )); then + echo fi done - - http_url=$(read_input "Enter HTTP RPC url for $SELECTED_NETWORKS: " false) - ws_url=$(read_input "Enter WS RPC url for $SELECTED_NETWORKS: " false) + echo + exit 0 } -# Check for an existing config -load_previous_config() { - local config_file="/tmp/${product}_config.env" - if [ -f "$config_file" ]; then - read -p "Previous configuration for $product found. Load it? (y/n): " -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Loading previous configuration..." - source "$config_file" - config_loaded=1 - return 0 +# Validate config +load_and_validate_config() { + if [ -f "$load_config" ]; then + source "$load_config" + + # Validate mandatory variables + if [ -z "$SELECTED_NETWORKS" ]; then + echo "Error: SELECTED_NETWORKS variable is missing in the configuration file." + exit 1 fi + else + echo "Error: Configuration file '$load_config' not found." + exit 1 fi - return 1 } +# Parse command-line options +while [[ $# -gt 0 ]]; do + case "$1" in + --list-networks ) list_networks=1; shift ;; + --help ) show_help=1; shift ;; + --load-config ) load_config="$2"; shift 2 ;; + --selected-networks ) SELECTED_NETWORKS="$2"; shift 2 ;; + --http-url ) http_url="$2"; shift 2 ;; + --ws-url ) ws_url="$2"; shift 2 ;; + --user ) user="$2"; shift 2 ;; + --log-level ) log_level="$2"; shift 2 ;; + --private-key ) private_key="$2"; shift 2 ;; + --docker-image-repo ) docker_image_repo="$2"; shift 2 ;; + --funding-per-node ) funding_per_node="$2"; shift 2 ;; + --docker-image-version ) docker_image_version="$2"; shift 2 ;; + --test-suite ) additional_args="$2"; shift 2 ;; + --product ) product="$2"; shift 2 ;; + --) shift; break ;; + *) break ;; + esac +done + +if [[ "$list_networks" -eq 1 ]]; then + list_networks +fi + +# Run tests +run_automation() { + echo "Running command with provided environment variables..." + go test -v -test.run "$SUITE" "${TEST_PATH}/automation_test.go" +} + +# Load config +if [[ -n "$load_config" ]]; then + load_and_validate_config + run_automation + exit 0 +fi + +if [[ "$show_help" -eq 1 ]]; then + usage + exit 0 +fi + +# Check arguments +if [[ -z "$SELECTED_NETWORKS" || -z "$http_url" || -z "$ws_url" || -z "$user" || -z "$private_key" || -z "$docker_image_repo" || -z "$docker_image_version" || -z "$additional_args" || -z "$product" ]]; then + echo "All options are mandatory." + usage + exit 1 +fi + # Save config save_current_config() { local config_file="/tmp/${product}_config.env" cat << EOF > "$config_file" export SELECTED_NETWORKS="$SELECTED_NETWORKS" export ${SELECTED_NETWORKS}_HTTP_URLS="$http_url" -export ${SELECTED_NETWORKS}_URLS="$ws_url" +export ${SELECTED_NETWORKS}_WS_URLS="$ws_url" export CHAINLINK_ENV_USER="$user" export TEST_LOG_LEVEL="$log_level" export ${SELECTED_NETWORKS}_KEYS="$private_key" @@ -77,41 +142,11 @@ export CHAINLINK_VERSION="$docker_image_version" export product="$product" export SUITE="$additional_args" EOF -source "$config_file" + source "$config_file" } -# Run tests -run_automation() { - echo "Running command with provided environment variables..." - go test -v -test.run "$SUITE" ./automation_test.go -} - -# Catch errors trap 'echo "An error occurred. Exiting..."; exit 1;' ERR -PS3="Please select a product: " -options=("Automation" "Exit") -select product in "${options[@]}"; do - case $product in - "Automation") - if ! load_previous_config; then - user=$(read_input "Please enter a user that the test will run under: " false) - log_level=$(read_input "Select test log level (INFO, DEBUG, ERROR): " false) - select_network_and_set_urls - private_key=$(read_input "Enter the private key the test should use: " false) - docker_image_repo=$(read_input "Enter docker image repository for core: " false) - funding_per_node=$(read_number "Enter funding per node: " false, "number") - docker_image_version=$(read_input "Enter docker image version for core: " false) - additional_args=$(read_input "Enter the test suite: " false) - save_current_config - fi - run_automation - break - ;; - "Exit") - echo "Exiting the wizard." - exit 0 - ;; - *) echo "Invalid option $REPLY";; - esac -done +# Main execution +save_current_config +run_automation