diff --git a/.github/workflows/docker-test.yaml b/.github/workflows/ctf-docker-test.yaml similarity index 71% rename from .github/workflows/docker-test.yaml rename to .github/workflows/ctf-docker-test.yaml index 0a2f98727..5efc10b4f 100644 --- a/.github/workflows/docker-test.yaml +++ b/.github/workflows/ctf-docker-test.yaml @@ -1,4 +1,4 @@ -name: (all packages) Docker Test Env tests +name: CTF Docker Test Env tests on: pull_request_review: types: [submitted] @@ -6,10 +6,26 @@ on: types: [labeled] jobs: + changes: + runs-on: ubuntu-latest + environment: integration + outputs: + ctf_changes: ${{ steps.changes.outputs.src }} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Check for relevant changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + with: + filters: | + src: + - '!(seth|havoc|wasp|tools)/**' + eth_env: - if: ${{ github.event_name == 'pull_request_review' || github.event.label.name == 'docker_tests' }} + if: ${{ needs.changes.outputs.ctf_changes == 'true' && (github.event_name == 'pull_request_review' || github.event.label.name == 'docker_tests') }} runs-on: ubuntu-latest name: Docker Test ${{ matrix.test.name }} + needs: [changes] strategy: fail-fast: false matrix: diff --git a/.github/workflows/k8s-e2e.yaml b/.github/workflows/ctf-k8s-e2e.yaml similarity index 87% rename from .github/workflows/k8s-e2e.yaml rename to .github/workflows/ctf-k8s-e2e.yaml index edbd23103..f3b577519 100644 --- a/.github/workflows/k8s-e2e.yaml +++ b/.github/workflows/ctf-k8s-e2e.yaml @@ -1,4 +1,4 @@ -name: (k8s package) E2E tests +name: CTF k8s E2E tests on: pull_request: @@ -18,12 +18,29 @@ env: TEST_LOG_LEVEL: debug jobs: + changes: + runs-on: ubuntu-latest + environment: integration + outputs: + ctf_changes: ${{ steps.changes.outputs.src }} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Check for relevant changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + with: + filters: | + src: + - '!(seth|havoc|wasp|tools)/**' + build_tests: runs-on: ubuntu-latest environment: integration permissions: id-token: write contents: read + needs: [changes] + if: needs.changes.outputs.ctf_changes == 'true' steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Build Base Image @@ -34,6 +51,7 @@ jobs: AWS_REGION: ${{ secrets.QA_AWS_REGION }} AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }} - name: Base Image Built + run: | # shellcheck disable=SC2086 cat <>$GITHUB_STEP_SUMMARY @@ -56,6 +74,7 @@ jobs: cat <>$GITHUB_STEP_SUMMARY ### chainlink-testing-framework-tests image tag for this test run :ship: -> \`ci.${{ github.sha }}\` EOT + e2e_tests: runs-on: ubuntu-latest environment: integration @@ -64,8 +83,17 @@ jobs: contents: read env: TEST_SUITE: local-runner + needs: [changes] + if: needs.changes.outputs.ctf_changes == 'true' steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Check for relevant changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + with: + filters: | + src: + - '!(seth|havoc|wasp|tools)/**' - name: Install Nix uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26 with: @@ -108,7 +136,8 @@ jobs: e2e_remote_runner_tests: runs-on: ubuntu-latest environment: integration - needs: [build_tests] + needs: [build_tests, changes] + if: needs.changes.outputs.ctf_changes == 'true' permissions: id-token: write contents: read diff --git a/.github/workflows/k8s-publish-test-base-image.yaml b/.github/workflows/ctf-k8s-publish-test-base-image.yaml similarity index 58% rename from .github/workflows/k8s-publish-test-base-image.yaml rename to .github/workflows/ctf-k8s-publish-test-base-image.yaml index 7cea71c00..5e11bb985 100644 --- a/.github/workflows/k8s-publish-test-base-image.yaml +++ b/.github/workflows/ctf-k8s-publish-test-base-image.yaml @@ -1,10 +1,25 @@ -name: (k8s package) Publish Test Base Image +name: CTF k8s Publish Test Base Image on: push: tags: - 'v*' jobs: + changes: + runs-on: ubuntu-latest + environment: integration + outputs: + ctf_changes: ${{ steps.changes.outputs.src }} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Check for relevant changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + with: + filters: | + src: + - '!(seth|havoc|wasp|tools)/**' + publish_test_base_image: runs-on: ubuntu-latest environment: integration @@ -13,6 +28,8 @@ jobs: contents: read env: BASE_IMAGE_TAG: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/test-base-image:${{ github.ref_name }} + needs: [changes] + if: needs.changes.outputs.ctf_changes == 'true' steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Build Base Image diff --git a/.github/workflows/lint.yaml b/.github/workflows/ctf-lint.yaml similarity index 55% rename from .github/workflows/lint.yaml rename to .github/workflows/ctf-lint.yaml index c0aff1503..fe149e56d 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/ctf-lint.yaml @@ -1,4 +1,4 @@ -name: (all packages) Lints +name: CTF Lints on: push: branches: @@ -6,6 +6,33 @@ on: pull_request: jobs: + changes: + runs-on: ubuntu-latest + environment: integration + outputs: + ctf_changes: ${{ steps.changes.outputs.ctf_src }} + tools_changes: ${{ steps.changes.outputs.tools_src }} + charts_changes: ${{ steps.changes.outputs.charts_src }} + actions_changes: ${{ steps.changes.outputs.actions_src }} + k8s_test_runner_changes: ${{ steps.changes.outputs.k8s_test_runner_src }} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Check for relevant changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + with: + filters: | + ctf_src: + - '!(seth|havoc|wasp|tools)/**' + tools_src: + - 'tools/**' + charts_src: + - 'charts/**' + actions_src: + - '.github/**' + k8s_test_runner_src: + - 'k8s-test-runner/**' + pre-commit: name: Pre-commit checks runs-on: ubuntu-latest @@ -29,8 +56,10 @@ jobs: gitdiffs=\$(git diff --name-only ${BASE_REF}...${HEAD_REF} | xargs) &&\ echo \"changed files: \$gitdiffs\" &&\ pre-commit run --hook-stage pre-commit --show-diff-on-failure --color=always --files \${gitdiffs}" - tools: + + tools-version: name: Get tool-versions + needs: [changes] runs-on: ubuntu-latest steps: - name: Check out Code @@ -40,20 +69,56 @@ jobs: id: tool-versions outputs: golangci-lint-version: ${{ steps.tool-versions.outputs.golangci-lint_version }} - golangci: + + golangci-ctf: name: Linting-${{ matrix.project.name }} runs-on: ubuntu-latest - needs: [tools] + needs: [changes, tools-version] + if: needs.changes.outputs.ctf_changes == 'true' strategy: fail-fast: false matrix: project: - name: root path: ./ + steps: + - name: Check out Code + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Install Go + uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-go@e29366cdecfe6befff9ab8c3cfe4825218505d58 # v2.3.16 + with: + test_download_vendor_packages_command: cd ${{ matrix.project.path }} && go mod download + go_mod_path: ${{ matrix.project.path }}go.mod + cache_key_id: ctf-go-${{ matrix.project.name }} + cache_restore_only: 'false' + - name: golangci-lint ${{ needs.tools-version.outputs.golangci-lint-version }} + uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # v5.1.0 + with: + version: v${{ needs.tools-version.outputs.golangci-lint-version }} + args: --out-format checkstyle:golangci-lint-report.xml + skip-cache: true + working-directory: ${{ matrix.project.path }} + - name: Print lint report artifact + if: always() + run: test -f ${{ matrix.project.path }}golangci-lint-report.xml || true + - name: Store lint report artifact + if: always() + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 + with: + name: golangci-lint-report-${{ matrix.project.name }} + path: ${{ matrix.project.path }}golangci-lint-report.xml + + golangci-tools: + name: Linting-${{ matrix.project.name }} + runs-on: ubuntu-latest + needs: [changes, tools-version] + if: needs.changes.outputs.tools_changes == 'true' + strategy: + fail-fast: false + matrix: + project: - name: gotestloghelper path: ./tools/gotestloghelper/ - - name: k8s-test-runner - path: ./k8s-test-runner/ - name: testlistgenerator path: ./tools/testlistgenerator/ - name: ecrimagefetcher @@ -74,10 +139,48 @@ jobs: go_mod_path: ${{ matrix.project.path }}go.mod cache_key_id: ctf-go-${{ matrix.project.name }} cache_restore_only: 'false' - - name: golangci-lint ${{ needs.tools.outputs.golangci-lint-version }} + - name: golangci-lint ${{ needs.tools-version.outputs.golangci-lint-version }} + uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # v5.1.0 + with: + version: v${{ needs.tools-version.outputs.golangci-lint-version }} + args: --out-format checkstyle:golangci-lint-report.xml + skip-cache: true + working-directory: ${{ matrix.project.path }} + - name: Print lint report artifact + if: always() + run: test -f ${{ matrix.project.path }}golangci-lint-report.xml || true + - name: Store lint report artifact + if: always() + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 + with: + name: golangci-lint-report-${{ matrix.project.name }} + path: ${{ matrix.project.path }}golangci-lint-report.xml + + golangci-k8s-test-runner: + name: Linting-${{ matrix.project.name }} + runs-on: ubuntu-latest + needs: [changes, tools-version] + if: needs.changes.outputs.k8s_test_runner_changes == 'true' + strategy: + fail-fast: false + matrix: + project: + - name: k8s-test-runner + path: ./k8s-test-runner/ + steps: + - name: Check out Code + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Install Go + uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-go@e29366cdecfe6befff9ab8c3cfe4825218505d58 # v2.3.16 + with: + test_download_vendor_packages_command: cd ${{ matrix.project.path }} && go mod download + go_mod_path: ${{ matrix.project.path }}go.mod + cache_key_id: ctf-go-${{ matrix.project.name }} + cache_restore_only: 'false' + - name: golangci-lint ${{ needs.tools-version.outputs.golangci-lint-version }} uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # v5.1.0 with: - version: v${{ needs.tools.outputs.golangci-lint-version }} + version: v${{ needs.tools-version.outputs.golangci-lint-version }} args: --out-format checkstyle:golangci-lint-report.xml skip-cache: true working-directory: ${{ matrix.project.path }} @@ -94,7 +197,7 @@ jobs: vulnerabilities-check: name: Check for Vulnerabilities runs-on: ubuntu-latest - needs: [tools] + needs: [tools-version] steps: - name: Check out Code uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 @@ -113,6 +216,8 @@ jobs: asdf-install: name: Validate GitHub Action Workflows runs-on: ubuntu-latest + needs: [changes] + if: needs.changes.outputs.actions_changes == 'true' || needs.changes.outputs.charts_changes == 'true' steps: - name: Check out Code uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 @@ -122,6 +227,8 @@ jobs: helmlint: name: Lint Helm Charts runs-on: ubuntu-latest + needs: [changes] + if: needs.changes.outputs.charts_changes == 'true' steps: - name: Checkout uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 @@ -139,6 +246,8 @@ jobs: actionlint: name: Validate GitHub Action Workflows runs-on: ubuntu-latest + needs: [changes] + if: needs.changes.outputs.actions_changes == 'true' steps: - name: Check out Code uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 @@ -147,7 +256,8 @@ jobs: sonarqube: name: SonarQube Analysis - needs: [golangci] + needs: [golangci-ctf, golangci-tools, golangci-k8s-test-runner] + if: ${{ needs.golangci-ctf.result != 'skipped' || needs.golangci-tools.result != 'skipped' || needs.golangci-k8s-test-runner.result != 'skipped' }} runs-on: ubuntu-latest steps: - name: Checkout the repo diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/ctf-static-analysis.yaml similarity index 55% rename from .github/workflows/static-analysis.yaml rename to .github/workflows/ctf-static-analysis.yaml index 7d48c9ff5..59b28b757 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/ctf-static-analysis.yaml @@ -1,15 +1,32 @@ -name: (all packages) Static Analysis +name: CTF Static Analysis on: push: branches: [main] schedule: - cron: '23 19 * * 4' jobs: + changes: + runs-on: ubuntu-latest + environment: integration + outputs: + ctf_changes: ${{ steps.changes.outputs.src }} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Check for relevant changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + with: + filters: | + src: + - '!(seth|havoc|wasp|tools)/**' + codeQL: name: CodeQL Checks runs-on: ubuntu-latest permissions: security-events: write + needs: [changes] + if: ${{ needs.changes.outputs.ctf_changes == 'true' }} steps: - name: Checkout repository uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 diff --git a/.github/workflows/test.yaml b/.github/workflows/ctf-test.yaml similarity index 98% rename from .github/workflows/test.yaml rename to .github/workflows/ctf-test.yaml index d8c51a607..b49a87721 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/ctf-test.yaml @@ -1,4 +1,4 @@ -name: (all packages) Unit tests +name: CTF Unit tests on: push: tags: diff --git a/.github/workflows/seth-lint.yml b/.github/workflows/seth-lint.yml index 9549f8188..158432384 100644 --- a/.github/workflows/seth-lint.yml +++ b/.github/workflows/seth-lint.yml @@ -1,4 +1,4 @@ -name: Lint +name: SETH Lint on: push: permissions: @@ -25,7 +25,5 @@ jobs: with: nix_path: nixpkgs=channel:nixos-unstable - name: Run tests - env: - SETH_NETWORK: ${{ matrix.network }} run: | nix develop -c make lint diff --git a/.github/workflows/seth-test-api.yml b/.github/workflows/seth-test-api.yml index a0c5cbd53..4a3fce74e 100644 --- a/.github/workflows/seth-test-api.yml +++ b/.github/workflows/seth-test-api.yml @@ -1,4 +1,4 @@ -name: API tests +name: SETH API tests on: push: concurrency: @@ -33,4 +33,4 @@ jobs: env: SETH_NETWORK: ${{ matrix.network }} run: | - nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_api + nix develop -c make "$SETH_NETWORK" && make SETH_LOG_LEVEL=debug root_private_key="$SETH_ROOT_PRIVATE_KEY" network="$SETH_NETWORK" test_api diff --git a/.github/workflows/seth-test-bumping.yml b/.github/workflows/seth-test-bumping.yml index d65941a30..6d01bc35e 100644 --- a/.github/workflows/seth-test-bumping.yml +++ b/.github/workflows/seth-test-bumping.yml @@ -1,4 +1,4 @@ -name: Gas bumping tests +name: SETH Gas bumping tests on: push: concurrency: @@ -33,4 +33,4 @@ jobs: env: SETH_NETWORK: ${{ matrix.network }} run: | - nix develop -c make $SETH_NETWORK && make SETH_LOG_LEVEL=debug root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_gas_bumping + nix develop -c make "$SETH_NETWORK" && make SETH_LOG_LEVEL=debug root_private_key="$SETH_ROOT_PRIVATE_KEY" network="$SETH_NETWORK" test_gas_bumping diff --git a/.github/workflows/seth-test-cli.yml b/.github/workflows/seth-test-cli.yml index ddc23626e..9ab8094b5 100644 --- a/.github/workflows/seth-test-cli.yml +++ b/.github/workflows/seth-test-cli.yml @@ -1,4 +1,4 @@ -name: CLI tests +name: SETH CLI tests on: push: concurrency: @@ -33,4 +33,4 @@ jobs: env: SETH_NETWORK: ${{ matrix.network }} run: | - nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_cli + nix develop -c make "$SETH_NETWORK" && make SETH_LOG_LEVEL=debug root_private_key="$SETH_ROOT_PRIVATE_KEY" network="$SETH_NETWORK" test_cli diff --git a/.github/workflows/seth-test-decode-testnet.yml b/.github/workflows/seth-test-decode-testnet.yml index 3d25e9c63..13981695d 100644 --- a/.github/workflows/seth-test-decode-testnet.yml +++ b/.github/workflows/seth-test-decode-testnet.yml @@ -1,4 +1,4 @@ -name: Decoding tests (testnets) +name: SETH Decoding tests (testnets) on: push: tags: @@ -36,4 +36,4 @@ jobs: SETH_NETWORK: ${{ matrix.network }} SETH_ROOT_PRIVATE_KEY: ${{ secrets.TESTNET_COMMON_KEYS }} run: | - nix develop -c make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test + nix develop -c make SETH_LOG_LEVEL=debug root_private_key="$SETH_ROOT_PRIVATE_KEY" network="$SETH_NETWORK" test diff --git a/.github/workflows/seth-test-decode.yml b/.github/workflows/seth-test-decode.yml index 0598f922b..dfc78c514 100644 --- a/.github/workflows/seth-test-decode.yml +++ b/.github/workflows/seth-test-decode.yml @@ -1,4 +1,4 @@ -name: Decoding tests +name: SETH Decoding tests on: push: concurrency: @@ -33,4 +33,4 @@ jobs: env: SETH_NETWORK: ${{ matrix.network }} run: | - nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test + nix develop -c make "$SETH_NETWORK" && make SETH_LOG_LEVEL=debug root_private_key="$SETH_ROOT_PRIVATE_KEY" network="$SETH_NETWORK" test diff --git a/.github/workflows/seth-test-others.yml b/.github/workflows/seth-test-others.yml index f6c90f5e3..e6df81892 100644 --- a/.github/workflows/seth-test-others.yml +++ b/.github/workflows/seth-test-others.yml @@ -1,4 +1,4 @@ -name: Other tests +name: SETH Other tests on: push: concurrency: @@ -33,4 +33,4 @@ jobs: env: SETH_NETWORK: ${{ matrix.network }} run: | - nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_others + nix develop -c make "$SETH_NETWORK" && make SETH_LOG_LEVEL=debug root_private_key="$SETH_ROOT_PRIVATE_KEY" network="$SETH_NETWORK" test_others diff --git a/.github/workflows/seth-test-trace.yml b/.github/workflows/seth-test-trace.yml index 07ce3b2ad..89e3a4b99 100644 --- a/.github/workflows/seth-test-trace.yml +++ b/.github/workflows/seth-test-trace.yml @@ -1,4 +1,4 @@ -name: Tracing tests +name: SETH Tracing tests on: push: concurrency: @@ -33,4 +33,4 @@ jobs: env: SETH_NETWORK: ${{ matrix.network }} run: | - nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_trace + nix develop -c make "$SETH_NETWORK" && make SETH_LOG_LEVEL=debug root_private_key="$SETH_ROOT_PRIVATE_KEY" network="$SETH_NETWORK" test_trace diff --git a/.github/workflows/release-tools.yaml b/.github/workflows/tools-release.yaml similarity index 97% rename from .github/workflows/release-tools.yaml rename to .github/workflows/tools-release.yaml index 9a2580048..730d0c98e 100644 --- a/.github/workflows/release-tools.yaml +++ b/.github/workflows/tools-release.yaml @@ -1,4 +1,4 @@ -name: Release Tools +name: TOOLS Release on: push: branches: diff --git a/seth/client_api_test.go b/seth/client_api_test.go index d52568adf..1bc119cd6 100644 --- a/seth/client_api_test.go +++ b/seth/client_api_test.go @@ -9,10 +9,10 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/pkg/errors" - "github.com/smartcontractkit/seth" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/seth/test_utils" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth/test_utils" ) func TestAPI(t *testing.T) { diff --git a/seth/client_contract_map_test.go b/seth/client_contract_map_test.go index f232c3171..25f0311a9 100644 --- a/seth/client_contract_map_test.go +++ b/seth/client_contract_map_test.go @@ -2,13 +2,15 @@ package seth_test import ( "crypto/ecdsa" + "os" + "testing" + "github.com/barkimedes/go-deepcopy" "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/seth" - "github.com/smartcontractkit/seth/test_utils" "github.com/stretchr/testify/require" - "os" - "testing" + + "github.com/smartcontractkit/chainlink-testing-framework/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth/test_utils" ) func TestContractMapSavesDeployedContractsToFileAndReadsThem(t *testing.T) { diff --git a/seth/client_decode_test.go b/seth/client_decode_test.go index 983300e5c..641132dea 100644 --- a/seth/client_decode_test.go +++ b/seth/client_decode_test.go @@ -4,7 +4,7 @@ import ( "math/big" "testing" - "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth" "github.com/stretchr/testify/require" ) diff --git a/seth/client_main_test.go b/seth/client_main_test.go index fac9c360d..0bb339c52 100644 --- a/seth/client_main_test.go +++ b/seth/client_main_test.go @@ -9,12 +9,12 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" - "github.com/smartcontractkit/seth" - network_debug_contract "github.com/smartcontractkit/seth/contracts/bind/debug" - network_sub_contract "github.com/smartcontractkit/seth/contracts/bind/sub" "github.com/stretchr/testify/require" - link_token "github.com/smartcontractkit/seth/contracts/bind/link" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + network_debug_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/debug" + link_token "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link" + network_sub_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/sub" ) /* diff --git a/seth/client_test.go b/seth/client_test.go index bf4132844..37893c594 100644 --- a/seth/client_test.go +++ b/seth/client_test.go @@ -1,12 +1,13 @@ package seth_test import ( - "github.com/ethereum/go-ethereum/common" - link_token "github.com/smartcontractkit/seth/contracts/bind/link" "testing" - "github.com/smartcontractkit/seth" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-testing-framework/seth" + link_token "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link" ) func TestRPCHealthCheckEnabled_Node_OK(t *testing.T) { diff --git a/seth/client_trace_test.go b/seth/client_trace_test.go index 5aee41889..40a33d10d 100644 --- a/seth/client_trace_test.go +++ b/seth/client_trace_test.go @@ -3,7 +3,6 @@ package seth_test import ( "encoding/json" "fmt" - "github.com/smartcontractkit/seth/test_utils" "io" "math/big" "os" @@ -15,12 +14,13 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/smartcontractkit/seth/contracts/bind/link_token_interface" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/seth" - network_debug_contract "github.com/smartcontractkit/seth/contracts/bind/debug" - link_token "github.com/smartcontractkit/seth/contracts/bind/link" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + network_debug_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/debug" + link_token "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link" + "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link_token_interface" + "github.com/smartcontractkit/chainlink-testing-framework/seth/test_utils" ) const ( diff --git a/seth/cmd/seth.go b/seth/cmd/seth.go index 1b7364de0..bac7ef102 100644 --- a/seth/cmd/seth.go +++ b/seth/cmd/seth.go @@ -14,7 +14,7 @@ import ( "github.com/pkg/errors" "github.com/urfave/cli/v2" - "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth" ) const ( diff --git a/seth/cmd/seth/seth.go b/seth/cmd/seth/seth.go index f3e5f42f2..d4264e2f7 100644 --- a/seth/cmd/seth/seth.go +++ b/seth/cmd/seth/seth.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/smartcontractkit/seth/cmd" + "github.com/smartcontractkit/chainlink-testing-framework/seth/cmd" ) func main() { diff --git a/seth/config_test.go b/seth/config_test.go index 2610f21ae..168df9256 100644 --- a/seth/config_test.go +++ b/seth/config_test.go @@ -7,8 +7,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/seth" - link_token "github.com/smartcontractkit/seth/contracts/bind/link" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + link_token "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link" ) func TestConfig_DefaultClient(t *testing.T) { diff --git a/seth/contract_store_test.go b/seth/contract_store_test.go index 265b5dbc5..c6f701e13 100644 --- a/seth/contract_store_test.go +++ b/seth/contract_store_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/pkg/errors" - "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth" "github.com/stretchr/testify/require" ) diff --git a/seth/examples/example_deployment_test.go b/seth/examples/example_deployment_test.go index a692ae372..4605f636e 100644 --- a/seth/examples/example_deployment_test.go +++ b/seth/examples/example_deployment_test.go @@ -5,12 +5,12 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/seth" "github.com/stretchr/testify/require" - network_debug_contract "github.com/smartcontractkit/seth/contracts/bind/debug" - link_token "github.com/smartcontractkit/seth/contracts/bind/link" - network_debug_sub_contract "github.com/smartcontractkit/seth/contracts/bind/sub" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + network_debug_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/debug" + link_token "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link" + network_debug_sub_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/sub" ) // Shows how to deploy a contract with parameterless constructor and bind it to it's Geth wrapper diff --git a/seth/examples/example_test.go b/seth/examples/example_test.go index c2df3161e..551a6c3ea 100644 --- a/seth/examples/example_test.go +++ b/seth/examples/example_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth/test_utils" network_debug_contract "github.com/smartcontractkit/seth/contracts/bind/debug" - "github.com/smartcontractkit/seth/test_utils" ) func commonEnvVars(t *testing.T) { @@ -74,7 +74,7 @@ func TestSmokeExampleMultiKey(t *testing.T) { // to simulate a case, when they were provided as part of the network config, instead of being // generated as ephemeral keys by Seth contract := setup(t) - c := test_utils.NewClientWithAddresses(t, 10) + c := test_utils.NewClientWithAddresses(t, 10, big.NewInt(2)) t.Cleanup(func() { err := seth.ReturnFunds(c, c.Addresses[0].Hex()) require.NoError(t, err) diff --git a/seth/examples/example_tracing_test.go b/seth/examples/example_tracing_test.go index 248c77806..587234ecf 100644 --- a/seth/examples/example_tracing_test.go +++ b/seth/examples/example_tracing_test.go @@ -4,7 +4,7 @@ import ( "math/big" "testing" - "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth" "github.com/stretchr/testify/require" ) diff --git a/seth/examples_wasp/client_main_test.go b/seth/examples_wasp/client_main_test.go index 3f3d26805..1faf98fbf 100644 --- a/seth/examples_wasp/client_main_test.go +++ b/seth/examples_wasp/client_main_test.go @@ -7,10 +7,10 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" - "github.com/smartcontractkit/seth" - network_debug_contract "github.com/smartcontractkit/seth/contracts/bind/debug" - link_token "github.com/smartcontractkit/seth/contracts/bind/link" - network_sub_contract "github.com/smartcontractkit/seth/contracts/bind/sub" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + network_debug_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/debug" + link_token "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link" + network_sub_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/sub" ) func init() { diff --git a/seth/examples_wasp/client_wasp_test.go b/seth/examples_wasp/client_wasp_test.go index 004e626c5..ce47a7554 100644 --- a/seth/examples_wasp/client_wasp_test.go +++ b/seth/examples_wasp/client_wasp_test.go @@ -2,7 +2,7 @@ package examples_wasp import ( "errors" - "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth" "github.com/smartcontractkit/wasp" "github.com/stretchr/testify/require" "math/big" diff --git a/seth/examples_wasp/go.mod b/seth/examples_wasp/go.mod index 43aea6392..107de62d5 100644 --- a/seth/examples_wasp/go.mod +++ b/seth/examples_wasp/go.mod @@ -7,7 +7,7 @@ toolchain go1.22.6 require ( github.com/ethereum/go-ethereum v1.13.8 github.com/pkg/errors v0.9.1 - github.com/smartcontractkit/seth v1.2.0 + github.com/smartcontractkit/chainlink-testing-framework/seth v1.2.0 github.com/smartcontractkit/wasp v0.4.7-0.20240328221214-00cd8313cfd4 github.com/stretchr/testify v1.9.0 ) diff --git a/seth/gas_bump_test.go b/seth/gas_bump_test.go index 043159cf5..b68e76a19 100644 --- a/seth/gas_bump_test.go +++ b/seth/gas_bump_test.go @@ -1,17 +1,17 @@ package seth_test import ( - "github.com/ethereum/go-ethereum/common" - link_token "github.com/smartcontractkit/seth/contracts/bind/link" - "github.com/smartcontractkit/seth/contracts/bind/link_token_interface" - "github.com/smartcontractkit/seth/test_utils" "math/big" "testing" "time" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + link_token "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link" + "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/link_token_interface" + "github.com/smartcontractkit/chainlink-testing-framework/seth/test_utils" ) var oneEth = big.NewInt(1000000000000000000) diff --git a/seth/gas_test.go b/seth/gas_test.go index 6ff44c2c7..5d7262721 100644 --- a/seth/gas_test.go +++ b/seth/gas_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/seth" "github.com/stretchr/testify/require" ) diff --git a/seth/test_utils/client.go b/seth/test_utils/client.go new file mode 100644 index 000000000..9f8201ae3 --- /dev/null +++ b/seth/test_utils/client.go @@ -0,0 +1,161 @@ +package test_utils + +import ( + "context" + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" + + "github.com/smartcontractkit/chainlink-testing-framework/seth" +) + +// NewClientWithEphemeralAddresses creates a new Seth client with the given number of addresses. Each address is funded with the +// calculated with the amount of ETH calculated by dividing the total balance of root key by the number of addresses (minus root key buffer amount). +func NewClientWithEphemeralAddresses(t *testing.T, addressCount int) *seth.Client { + cfg, err := seth.ReadConfig() + require.NoError(t, err, "failed to read config") + + var zero int64 = 0 + cfg.EphemeralAddrs = &zero + + c, err := seth.NewClientWithConfig(cfg) + require.NoError(t, err, "failed to initialize seth") + + var privateKeys []string + var addresses []string + for i := 0; i < addressCount; i++ { + addr, pk, err := seth.NewAddress() + require.NoError(t, err, "failed to generate new address") + + privateKeys = append(privateKeys, pk) + addresses = append(addresses, addr) + } + + gasPrice, err := c.GetSuggestedLegacyFees(context.Background(), seth.Priority_Standard) + if err != nil { + gasPrice = big.NewInt(c.Cfg.Network.GasPrice) + } + + bd, err := c.CalculateSubKeyFunding(int64(addressCount), gasPrice.Int64(), *cfg.RootKeyFundsBuffer) + require.NoError(t, err, "failed to calculate subkey funding") + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + eg, egCtx := errgroup.WithContext(ctx) + // root key is element 0 in ephemeral + for _, addr := range addresses { + addr := addr + eg.Go(func() error { + return c.TransferETHFromKey(egCtx, 0, addr, bd.AddrFunding, gasPrice) + }) + } + err = eg.Wait() + require.NoError(t, err, "failed to transfer funds to subkeys") + + // Add root private key to the list of private keys + pksToUse := []string{cfg.Network.PrivateKeys[0]} + pksToUse = append(pksToUse, privateKeys...) + // Set funded private keys in config and create a new Seth client to simulate a situation, in which PKs were passed in config to a new client + cfg.Network.PrivateKeys = pksToUse + + newClient, err := seth.NewClientWithConfig(cfg) + require.NoError(t, err, "failed to initialize new Seth with private keys") + + return newClient +} + +// NewClientWithAddresses creates a new Seth client with the given number of addresses. Each address is funded with the given amount of native tokens. +func NewClientWithAddresses(t *testing.T, addressCount int, funding *big.Int) *seth.Client { + cfg, err := seth.ReadConfig() + require.NoError(t, err, "failed to read config") + + var zero int64 = 0 + cfg.EphemeralAddrs = &zero + + c, err := seth.NewClientWithConfig(cfg) + require.NoError(t, err, "failed to initialize seth") + + var privateKeys []string + var addresses []string + for i := 0; i < addressCount; i++ { + addr, pk, err := seth.NewAddress() + require.NoError(t, err, "failed to generate new address") + + privateKeys = append(privateKeys, pk) + addresses = append(addresses, addr) + } + + gasPrice, err := c.GetSuggestedLegacyFees(context.Background(), seth.Priority_Standard) + if err != nil { + gasPrice = big.NewInt(c.Cfg.Network.GasPrice) + } + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + eg, egCtx := errgroup.WithContext(ctx) + // root key is element 0 in ephemeral + for _, addr := range addresses { + addr := addr + eg.Go(func() error { + return c.TransferETHFromKey(egCtx, 0, addr, funding, gasPrice) + }) + } + err = eg.Wait() + require.NoError(t, err, "failed to transfer funds to subkeys") + + // Add root private key to the list of private keys + pksToUse := []string{cfg.Network.PrivateKeys[0]} + pksToUse = append(pksToUse, privateKeys...) + // Set funded private keys in config and create a new Seth client to simulate a situation, in which PKs were passed in config to a new client + cfg.Network.PrivateKeys = pksToUse + + newClient, err := seth.NewClientWithConfig(cfg) + require.NoError(t, err, "failed to initialize new Seth with private keys") + + return newClient +} + +// NewPrivateKeyWithFunds generates a new private key and funds it with the given amount of native tokens. +func NewPrivateKeyWithFunds(t *testing.T, c *seth.Client, funds *big.Int) string { + addr, pk, err := seth.NewAddress() + require.NoError(t, err, "failed to generate new address") + + gasPrice, err := c.GetSuggestedLegacyFees(context.Background(), seth.Priority_Standard) + if err != nil { + gasPrice = big.NewInt(c.Cfg.Network.GasPrice) + } + + ctx, cancel := context.WithTimeout(context.Background(), c.Cfg.Network.TxnTimeout.Duration()) + err = c.TransferETHFromKey(ctx, 0, addr, funds, gasPrice) + defer cancel() + require.NoError(t, err, "failed to transfer funds to subkeys") + + return pk +} + +// TransferAllFundsBetweenKeyAndAddress transfers all funds key at specified index has to the given address. +func TransferAllFundsBetweenKeyAndAddress(client *seth.Client, keyNum int, toAddress common.Address) error { + err := client.NonceManager.UpdateNonces() + if err != nil { + return err + } + + gasPrice, err := client.GetSuggestedLegacyFees(context.Background(), seth.Priority_Standard) + if err != nil { + gasPrice = big.NewInt(client.Cfg.Network.GasPrice) + } + + balance, err := client.Client.BalanceAt(context.Background(), client.Addresses[0], nil) + if err != nil { + return err + } + + toTransfer := new(big.Int).Sub(balance, big.NewInt(0).Mul(gasPrice, big.NewInt(client.Cfg.Network.TransferGasFee))) + + ctx, cancel := context.WithTimeout(context.Background(), client.Cfg.Network.TxnTimeout.Duration()) + defer cancel() + return client.TransferETHFromKey(ctx, keyNum, toAddress.Hex(), toTransfer, gasPrice) +} diff --git a/seth/test_utils/config.go b/seth/test_utils/config.go new file mode 100644 index 000000000..bc4e4cea0 --- /dev/null +++ b/seth/test_utils/config.go @@ -0,0 +1,23 @@ +package test_utils + +import ( + "github.com/pelletier/go-toml/v2" + + "github.com/smartcontractkit/chainlink-testing-framework/seth" +) + +// CopyConfig creates a deep copy of Seth config +func CopyConfig(config *seth.Config) (*seth.Config, error) { + marshalled, err := toml.Marshal(config) + if err != nil { + return nil, err + } + + var configCopy seth.Config + err = toml.Unmarshal(marshalled, &configCopy) + if err != nil { + return nil, err + } + + return &configCopy, nil +} diff --git a/seth/tracing_cli_test.go b/seth/tracing_cli_test.go index 98d65a7b6..aef377397 100644 --- a/seth/tracing_cli_test.go +++ b/seth/tracing_cli_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" - "github.com/smartcontractkit/seth" - sethcmd "github.com/smartcontractkit/seth/cmd" "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-testing-framework/seth" + sethcmd "github.com/smartcontractkit/chainlink-testing-framework/seth/cmd" ) func TestCLITracing(t *testing.T) { diff --git a/seth/util.go b/seth/util.go index 07211bb72..076deaefd 100644 --- a/seth/util.go +++ b/seth/util.go @@ -18,8 +18,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" "github.com/pkg/errors" - network_debug_contract "github.com/smartcontractkit/seth/contracts/bind/debug" - network_sub_debug_contract "github.com/smartcontractkit/seth/contracts/bind/sub" + + network_debug_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/debug" + network_sub_debug_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/sub" ) const ( diff --git a/seth/util_test.go b/seth/util_test.go index 76b4f5d65..70349fc71 100644 --- a/seth/util_test.go +++ b/seth/util_test.go @@ -3,14 +3,15 @@ package seth_test import ( "context" "errors" - network_sub_contract "github.com/smartcontractkit/seth/contracts/bind/sub" "math/big" "sync" "testing" "time" - "github.com/smartcontractkit/seth" "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-testing-framework/seth" + network_sub_contract "github.com/smartcontractkit/chainlink-testing-framework/seth/contracts/bind/sub" ) func TestUtilDecodePragmaVersion(t *testing.T) {