From 3502c7fdd4abc46e69e9f6345a03a6203808620a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Sat, 11 Nov 2023 19:08:48 +0100 Subject: [PATCH 1/9] Introduce E2E tests execution GH workflow --- .github/e2e.yaml | 39 +++++++++++++++++++++++++++++++++++++++ Makefile | 6 +++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .github/e2e.yaml diff --git a/.github/e2e.yaml b/.github/e2e.yaml new file mode 100644 index 0000000..64ef811 --- /dev/null +++ b/.github/e2e.yaml @@ -0,0 +1,39 @@ +name: E2E tests +on: # yamllint disable-line rule:truthy + push: + branches: + - main + pull_request: + workflow_dispatch: + workflow_call: + outputs: + workflow_output: + description: "E2E output" + value: ${{ jobs.build.outputs.run_e2e_failure }} + +jobs: + build: + runs-on: ubuntu-latest + env: + CI_VERBOSE: true + outputs: + e2e_output_failure: ${{ steps.run_e2e_failure.outputs.test_output }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run tests + run: make e2e-tests + + - name: Run tests failed + if: failure() + id: run_e2e_failure + run: echo "test_output=false" >> $GITHUB_OUTPUT + + - name: Archive test logs + if: always() + uses: actions/upload-artifact@v3 + with: + name: e2e-logs + path: e2e-logs-*/ + retention-days: 30 diff --git a/Makefile b/Makefile index ab57bc6..dbfc22f 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,11 @@ lint: ## Runs the linter .DEFAULT_GOAL := help .PHONY: help -help: ## Prints this help +help: ## Prints the help @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ | sort \ | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: e2e-tests +e2e-tests: ## Runs E2E tests + go test -v -timeout=30m github.com/0xPolygon/beethoven/test From 82ddc77e942fb052cb63aa6b9f69270903176189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 20 Nov 2023 12:05:51 +0100 Subject: [PATCH 2/9] Update docker-compose for e2e tests --- .github/e2e.yaml | 4 +- test/Makefile | 9 +- ...docker-compose.yml => docker-compose.yaml} | 110 +++++++++++++----- 3 files changed, 85 insertions(+), 38 deletions(-) rename test/{docker-compose.yml => docker-compose.yaml} (61%) diff --git a/.github/e2e.yaml b/.github/e2e.yaml index 64ef811..11669ef 100644 --- a/.github/e2e.yaml +++ b/.github/e2e.yaml @@ -9,10 +9,10 @@ on: # yamllint disable-line rule:truthy outputs: workflow_output: description: "E2E output" - value: ${{ jobs.build.outputs.run_e2e_failure }} + value: ${{ jobs.execution.outputs.run_e2e_failure }} jobs: - build: + execution: runs-on: ubuntu-latest env: CI_VERBOSE: true diff --git a/test/Makefile b/test/Makefile index fcddd58..9e6d0a5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,11 +1,8 @@ .PHONY: run run: stop ## Run all the services needed to perform an E2E test - docker compose up -d zkevm-state-db zkevm-pool-db beethoven-db l1 - sleep 1 - docker compose up -d zkevm-prover beethoven - sleep 3 - docker compose up -d zkevm-node + docker compose -f docker-compose.yaml up -d l1 zkevm-prover zkevm-node + docker compose -f docker-compose.yaml up -d --build beethoven .PHONY: stop stop: ## Stop all the services needed to perform an E2E test - docker compose down \ No newline at end of file + docker compose -f docker-compose.yaml down diff --git a/test/docker-compose.yml b/test/docker-compose.yaml similarity index 61% rename from test/docker-compose.yml rename to test/docker-compose.yaml index d633e69..62c78bb 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yaml @@ -1,8 +1,9 @@ version: '3.5' services: zkevm-state-db: + image: postgres:16.0-alpine container_name: zkevm-state-db - image: postgres + command: ["postgres", "-N", "500"] deploy: resources: limits: @@ -14,14 +15,22 @@ services: volumes: - ./config/init_prover_db.sql:/docker-entrypoint-initdb.d/init.sql environment: - - POSTGRES_USER=state_user - - POSTGRES_PASSWORD=state_password - - POSTGRES_DB=state_db - command: ["postgres", "-N", "500"] + POSTGRES_USER: state_user + POSTGRES_PASSWORD: state_password + POSTGRES_DB: state_db + healthcheck: + test: [ "CMD-SHELL", "pg_isready", "-d", "prover_db" ] + interval: 30s + timeout: 60s + retries: 5 + start_period: 10s + networks: + - beethoven-localnet zkevm-pool-db: container_name: zkevm-pool-db - image: postgres + image: postgres:16.0-alpine + command: ["postgres", "-N", "500"] deploy: resources: limits: @@ -31,14 +40,22 @@ services: ports: - 5433:5432 environment: - - POSTGRES_USER=pool_user - - POSTGRES_PASSWORD=pool_password - - POSTGRES_DB=pool_db - command: ["postgres", "-N", "500"] + POSTGRES_USER: pool_user + POSTGRES_PASSWORD: pool_password + POSTGRES_DB: pool_db + healthcheck: + test: [ "CMD-SHELL", "pg_isready", "-d", "pool_db" ] + interval: 30s + timeout: 60s + retries: 5 + start_period: 10s + networks: + - beethoven-localnet beethoven-db: container_name: beethoven-db - image: postgres + image: postgres:16.0-alpine + command: ["postgres", "-N", "500"] deploy: resources: limits: @@ -47,34 +64,50 @@ services: memory: 1G ports: - 5435:5432 + healthcheck: + test: [ "CMD-SHELL", "pg_isready", "-d", "beethoven_db" ] + interval: 30s + timeout: 60s + retries: 5 + start_period: 10s environment: - - POSTGRES_USER=beethoven_user - - POSTGRES_PASSWORD=beethoven_password - - POSTGRES_DB=beethoven_db - command: ["postgres", "-N", "500"] + POSTGRES_USER: beethoven_user + POSTGRES_PASSWORD: beethoven_password + POSTGRES_DB: beethoven_db + networks: + - beethoven-localnet + restart: always zkevm-node: container_name: zkevm-node image: hermeznetwork/cdk-validium-node:beethoven + command: + - "/bin/sh" + - "-c" + - "/app/cdk-validium-node approve --network custom --custom-network-file /app/genesis.json --am 115792089237316195423570985008687907853269984665640564039457584007913129639935 -y --cfg /app/config.toml --key-store-path /pk/sequencer.keystore --password testonly && + /app/cdk-validium-node run --network custom --custom-network-file /app/genesis.json --cfg /app/config.toml --components \"synchronizer,rpc,sequencer,sequence-sender,aggregator,eth-tx-manager,l2gaspricer\"" ports: - 8123:8123 - 61090:61090 + depends_on: + zkevm-state-db: + condition: service_healthy + zkevm-pool-db: + condition: service_healthy + zkevm-prover: + condition: service_started + l1: + condition: service_started volumes: - ./config/sequencer.keystore:/pk/sequencer.keystore - ./config/node.toml:/app/config.toml - ./config/genesis.json:/app/genesis.json - command: - - "/bin/sh" - - "-c" - - "/app/cdk-validium-node approve --network custom --custom-network-file /app/genesis.json --am 115792089237316195423570985008687907853269984665640564039457584007913129639935 -y --cfg /app/config.toml --key-store-path /pk/sequencer.keystore --password testonly && - /app/cdk-validium-node run --network custom --custom-network-file /app/genesis.json --cfg /app/config.toml --components \"synchronizer,rpc,sequencer,sequence-sender,aggregator,eth-tx-manager,l2gaspricer\"" + networks: + - beethoven-localnet l1: container_name: l1 image: hermeznetwork/geth-cdk-validium-contracts:v0.0.1 - ports: - - 8545:8545 - - 8546:8546 command: - "--http" - "--http.api" @@ -98,27 +131,44 @@ services: - "--syncmode" - "full" - "--rpc.allow-unprotected-txs" + ports: + - 8545:8545 + - 8546:8546 + networks: + - beethoven-localnet zkevm-prover: container_name: zkevm-prover image: hermeznetwork/zkevm-prover:v2.2.0 + command: [ + "zkProver", + "-c", + "/usr/src/app/config.json" + ] + depends_on: + zkevm-state-db: + condition: service_healthy ports: - 50061:50061 # MT - 50071:50071 # Executor volumes: - ./config/prover.json:/usr/src/app/config.json - command: > - zkProver -c /usr/src/app/config.json + networks: + - beethoven-localnet beethoven: container_name: beethoven image: beethoven + command: [ 'run', '--cfg', '/app/config.toml'] ports: - - 4444:4444 + - 8444:8444 volumes: - ./config/interop.keystore:/pk/interop.keystore - ./config/beethoven.toml:/app/config.toml - command: - - "/bin/sh" - - "-c" - - "/app/beethoven run --cfg /app/config.toml" \ No newline at end of file + networks: + - beethoven-localnet + restart: always + +networks: + beethoven-localnet: + driver: bridge \ No newline at end of file From 899d5939c47bc8ad3fe984a83a9762c1e3236f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 20 Nov 2023 14:01:11 +0100 Subject: [PATCH 3/9] Use make and docker-compose from the root folder --- test/e2e_test.go | 13 +++++++++---- test/test-cluster.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 test/test-cluster.go diff --git a/test/e2e_test.go b/test/e2e_test.go index 47b0207..ce79b47 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -3,7 +3,6 @@ package test import ( "context" "math/big" - "os/exec" "testing" "time" @@ -20,15 +19,21 @@ func TestEthTransfer(t *testing.T) { if testing.Short() { t.Skip() } + + cluster, err := newTestCluster("") + require.NoError(t, err) + ctx := context.Background() defer func() { - msg, err := exec.Command("make", "stop").CombinedOutput() + msg, err := cluster.stop() require.NoError(t, err, string(msg)) + require.NoError(t, cluster.reset()) }() + log.Info("restarting docker containers for the test") - msg, err := exec.Command("make", "stop").CombinedOutput() + msg, err := cluster.stop() require.NoError(t, err, string(msg)) - msg, err = exec.Command("make", "run").CombinedOutput() + msg, err = cluster.start() require.NoError(t, err, string(msg)) time.Sleep(5 * time.Second) diff --git a/test/test-cluster.go b/test/test-cluster.go new file mode 100644 index 0000000..05e5dfc --- /dev/null +++ b/test/test-cluster.go @@ -0,0 +1,43 @@ +package test + +import ( + "os" + "os/exec" + "path/filepath" +) + +type testCluster struct { + path string + originalWorkDir string +} + +func newTestCluster(path string) (*testCluster, error) { + workDir, err := os.Getwd() + if err != nil { + return nil, err + } + + if path == "" { + parentDir := filepath.Dir(workDir) + if err := os.Chdir(parentDir); err != nil { + return nil, err + } + } + + return &testCluster{ + path: path, + originalWorkDir: workDir, + }, nil +} + +func (t *testCluster) start() ([]byte, error) { + return exec.Command("make", "run-docker").CombinedOutput() +} + +func (t *testCluster) stop() ([]byte, error) { + return exec.Command("make", "stop-docker").CombinedOutput() +} + +func (t *testCluster) reset() error { + return os.Chdir(t.originalWorkDir) +} From 371844dc6e847160828993e5f4fc5aea2b8942cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 20 Nov 2023 14:07:12 +0100 Subject: [PATCH 4/9] Remove test/Makefile and test/docker-compose.yaml --- test/Makefile | 8 -- test/docker-compose.yaml | 174 --------------------------------------- 2 files changed, 182 deletions(-) delete mode 100644 test/Makefile delete mode 100644 test/docker-compose.yaml diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 9e6d0a5..0000000 --- a/test/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -.PHONY: run -run: stop ## Run all the services needed to perform an E2E test - docker compose -f docker-compose.yaml up -d l1 zkevm-prover zkevm-node - docker compose -f docker-compose.yaml up -d --build beethoven - -.PHONY: stop -stop: ## Stop all the services needed to perform an E2E test - docker compose -f docker-compose.yaml down diff --git a/test/docker-compose.yaml b/test/docker-compose.yaml deleted file mode 100644 index 62c78bb..0000000 --- a/test/docker-compose.yaml +++ /dev/null @@ -1,174 +0,0 @@ -version: '3.5' -services: - zkevm-state-db: - image: postgres:16.0-alpine - container_name: zkevm-state-db - command: ["postgres", "-N", "500"] - deploy: - resources: - limits: - memory: 2G - reservations: - memory: 1G - ports: - - 5432:5432 - volumes: - - ./config/init_prover_db.sql:/docker-entrypoint-initdb.d/init.sql - environment: - POSTGRES_USER: state_user - POSTGRES_PASSWORD: state_password - POSTGRES_DB: state_db - healthcheck: - test: [ "CMD-SHELL", "pg_isready", "-d", "prover_db" ] - interval: 30s - timeout: 60s - retries: 5 - start_period: 10s - networks: - - beethoven-localnet - - zkevm-pool-db: - container_name: zkevm-pool-db - image: postgres:16.0-alpine - command: ["postgres", "-N", "500"] - deploy: - resources: - limits: - memory: 2G - reservations: - memory: 1G - ports: - - 5433:5432 - environment: - POSTGRES_USER: pool_user - POSTGRES_PASSWORD: pool_password - POSTGRES_DB: pool_db - healthcheck: - test: [ "CMD-SHELL", "pg_isready", "-d", "pool_db" ] - interval: 30s - timeout: 60s - retries: 5 - start_period: 10s - networks: - - beethoven-localnet - - beethoven-db: - container_name: beethoven-db - image: postgres:16.0-alpine - command: ["postgres", "-N", "500"] - deploy: - resources: - limits: - memory: 2G - reservations: - memory: 1G - ports: - - 5435:5432 - healthcheck: - test: [ "CMD-SHELL", "pg_isready", "-d", "beethoven_db" ] - interval: 30s - timeout: 60s - retries: 5 - start_period: 10s - environment: - POSTGRES_USER: beethoven_user - POSTGRES_PASSWORD: beethoven_password - POSTGRES_DB: beethoven_db - networks: - - beethoven-localnet - restart: always - - zkevm-node: - container_name: zkevm-node - image: hermeznetwork/cdk-validium-node:beethoven - command: - - "/bin/sh" - - "-c" - - "/app/cdk-validium-node approve --network custom --custom-network-file /app/genesis.json --am 115792089237316195423570985008687907853269984665640564039457584007913129639935 -y --cfg /app/config.toml --key-store-path /pk/sequencer.keystore --password testonly && - /app/cdk-validium-node run --network custom --custom-network-file /app/genesis.json --cfg /app/config.toml --components \"synchronizer,rpc,sequencer,sequence-sender,aggregator,eth-tx-manager,l2gaspricer\"" - ports: - - 8123:8123 - - 61090:61090 - depends_on: - zkevm-state-db: - condition: service_healthy - zkevm-pool-db: - condition: service_healthy - zkevm-prover: - condition: service_started - l1: - condition: service_started - volumes: - - ./config/sequencer.keystore:/pk/sequencer.keystore - - ./config/node.toml:/app/config.toml - - ./config/genesis.json:/app/genesis.json - networks: - - beethoven-localnet - - l1: - container_name: l1 - image: hermeznetwork/geth-cdk-validium-contracts:v0.0.1 - command: - - "--http" - - "--http.api" - - "admin,eth,debug,miner,net,txpool,personal,web3" - - "--http.addr" - - "0.0.0.0" - - "--http.corsdomain" - - "*" - - "--http.vhosts" - - "*" - - "--ws" - - "--ws.origins" - - "*" - - "--ws.addr" - - "0.0.0.0" - - "--dev" - - "--dev.period" - - "1" - - "--datadir" - - "/geth_data" - - "--syncmode" - - "full" - - "--rpc.allow-unprotected-txs" - ports: - - 8545:8545 - - 8546:8546 - networks: - - beethoven-localnet - - zkevm-prover: - container_name: zkevm-prover - image: hermeznetwork/zkevm-prover:v2.2.0 - command: [ - "zkProver", - "-c", - "/usr/src/app/config.json" - ] - depends_on: - zkevm-state-db: - condition: service_healthy - ports: - - 50061:50061 # MT - - 50071:50071 # Executor - volumes: - - ./config/prover.json:/usr/src/app/config.json - networks: - - beethoven-localnet - - beethoven: - container_name: beethoven - image: beethoven - command: [ 'run', '--cfg', '/app/config.toml'] - ports: - - 8444:8444 - volumes: - - ./config/interop.keystore:/pk/interop.keystore - - ./config/beethoven.toml:/app/config.toml - networks: - - beethoven-localnet - restart: always - -networks: - beethoven-localnet: - driver: bridge \ No newline at end of file From e5ab677d36561421dc98963258e5604553c1831e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 20 Nov 2023 14:09:49 +0100 Subject: [PATCH 5/9] Move e2e.yaml to workflows folder --- .github/{ => workflows}/e2e.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/e2e.yaml (100%) diff --git a/.github/e2e.yaml b/.github/workflows/e2e.yaml similarity index 100% rename from .github/e2e.yaml rename to .github/workflows/e2e.yaml From 5df8a2396aa8bc034c4c1aed3c47090111c142a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 20 Nov 2023 14:17:19 +0100 Subject: [PATCH 6/9] Minor change --- test/test-cluster.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/test-cluster.go b/test/test-cluster.go index 05e5dfc..071fb19 100644 --- a/test/test-cluster.go +++ b/test/test-cluster.go @@ -7,8 +7,8 @@ import ( ) type testCluster struct { - path string - originalWorkDir string + path string + origWorkDir string } func newTestCluster(path string) (*testCluster, error) { @@ -18,15 +18,16 @@ func newTestCluster(path string) (*testCluster, error) { } if path == "" { - parentDir := filepath.Dir(workDir) - if err := os.Chdir(parentDir); err != nil { - return nil, err - } + path = filepath.Dir(workDir) + } + + if err := os.Chdir(path); err != nil { + return nil, err } return &testCluster{ - path: path, - originalWorkDir: workDir, + path: path, + origWorkDir: workDir, }, nil } @@ -39,5 +40,5 @@ func (t *testCluster) stop() ([]byte, error) { } func (t *testCluster) reset() error { - return os.Chdir(t.originalWorkDir) + return os.Chdir(t.origWorkDir) } From 8bf1ebf5549558c4c4a5b4f1e4fa342b03d5836f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 20 Nov 2023 14:56:39 +0100 Subject: [PATCH 7/9] Simplify and comments --- test/e2e_test.go | 1 - test/test-cluster.go | 24 +++++++++--------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/test/e2e_test.go b/test/e2e_test.go index ce79b47..26a4be2 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -27,7 +27,6 @@ func TestEthTransfer(t *testing.T) { defer func() { msg, err := cluster.stop() require.NoError(t, err, string(msg)) - require.NoError(t, cluster.reset()) }() log.Info("restarting docker containers for the test") diff --git a/test/test-cluster.go b/test/test-cluster.go index 071fb19..7f530b1 100644 --- a/test/test-cluster.go +++ b/test/test-cluster.go @@ -6,18 +6,17 @@ import ( "path/filepath" ) +// testCluster represents abstraction that enables management of Docker containers type testCluster struct { - path string - origWorkDir string + path string } func newTestCluster(path string) (*testCluster, error) { - workDir, err := os.Getwd() - if err != nil { - return nil, err - } - if path == "" { + workDir, err := os.Getwd() + if err != nil { + return nil, err + } path = filepath.Dir(workDir) } @@ -25,20 +24,15 @@ func newTestCluster(path string) (*testCluster, error) { return nil, err } - return &testCluster{ - path: path, - origWorkDir: workDir, - }, nil + return &testCluster{path: path}, nil } +// start starts required Docker containers func (t *testCluster) start() ([]byte, error) { return exec.Command("make", "run-docker").CombinedOutput() } +// stop stop and destroys running Docker containers func (t *testCluster) stop() ([]byte, error) { return exec.Command("make", "stop-docker").CombinedOutput() } - -func (t *testCluster) reset() error { - return os.Chdir(t.origWorkDir) -} From c17ba6edcab2f4a621d033b998287712ba5d5130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 20 Nov 2023 15:46:01 +0100 Subject: [PATCH 8/9] Comment archive test logs and call destroy-docker --- .github/workflows/e2e.yaml | 15 ++++++++------- test/test-cluster.go | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 11669ef..d1341c2 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -30,10 +30,11 @@ jobs: id: run_e2e_failure run: echo "test_output=false" >> $GITHUB_OUTPUT - - name: Archive test logs - if: always() - uses: actions/upload-artifact@v3 - with: - name: e2e-logs - path: e2e-logs-*/ - retention-days: 30 + # TODO: Uncomment when we establish writing to log files in E2E framework + # - name: Archive test logs + # if: always() + # uses: actions/upload-artifact@v3 + # with: + # name: e2e-logs + # path: e2e-logs-*/ + # retention-days: 30 diff --git a/test/test-cluster.go b/test/test-cluster.go index 7f530b1..fe8ea16 100644 --- a/test/test-cluster.go +++ b/test/test-cluster.go @@ -34,5 +34,5 @@ func (t *testCluster) start() ([]byte, error) { // stop stop and destroys running Docker containers func (t *testCluster) stop() ([]byte, error) { - return exec.Command("make", "stop-docker").CombinedOutput() + return exec.Command("make", "destroy-docker").CombinedOutput() } From ee2aba08e136ba2199c8fcc557961eee722386b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 20 Nov 2023 16:14:02 +0100 Subject: [PATCH 9/9] Minor changes --- test/test-cluster.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test-cluster.go b/test/test-cluster.go index fe8ea16..ae3c27b 100644 --- a/test/test-cluster.go +++ b/test/test-cluster.go @@ -6,11 +6,12 @@ import ( "path/filepath" ) -// testCluster represents abstraction that enables management of Docker containers +// testCluster represents abstraction that enables Docker containers management type testCluster struct { path string } +// newTestCluster is a constructor function for testCluster instance func newTestCluster(path string) (*testCluster, error) { if path == "" { workDir, err := os.Getwd()