From 858a5957636af2a5b2431d96a67a593edd4b275b Mon Sep 17 00:00:00 2001 From: dan moore Date: Thu, 25 Apr 2024 07:49:29 -0500 Subject: [PATCH 1/8] feature: ephemeral cdk devnets with integration tests --- .github/workflows/regression-tests.yml | 200 +++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 .github/workflows/regression-tests.yml diff --git a/.github/workflows/regression-tests.yml b/.github/workflows/regression-tests.yml new file mode 100644 index 00000000..a9351d65 --- /dev/null +++ b/.github/workflows/regression-tests.yml @@ -0,0 +1,200 @@ +name: Regression Tests +'on': + workflow_dispatch: + inputs: + zkevm_agglayer: + description: 0xPolygon/agglayer (short commit hash or release tag) + required: true + default: 0.1.4 + zkevm_bridge_service: + description: 0xPolygonHermez/zkevm-bridge-service (short commit hash or release tag) + required: true + default: v0.4.2 + zkevm_bridge_ui: + description: 0xPolygonHermez/zkevm-bridge-ui (short commit hash or release tag) + required: true + default: '0006445' + zkevm_dac: + description: 0xPolygon/cdk-data-availability (short commit hash or release tag) + required: true + default: 0.0.7 + zkevm_node: + description: 0xPolygon/cdk-validium-node (short commit hash or release tag) + required: true + default: 0.6.5-cdk + bake_time: + description: bake time (minutes) + required: false + default: 30 +jobs: + deploy_devnet: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Set up Docker + uses: docker/setup-buildx-action@v1 + - name: Clone and build agglayer, if no release tag given + run: | + if [[ ${{ github.event.inputs.zkevm_agglayer }} =~ ^[0-9a-fA-F]{7}$ ]]; then + git clone https://github.com/0xPolygon/agglayer.git + cd agglayer + git checkout "${{ github.event.inputs.zkevm_agglayer }}" + docker compose -f docker/docker-compose.yaml build --no-cache agglayer + else + echo "Skipping building agglayer as release tag provided: ${{ github.event.inputs.zkevm_agglayer }}" + fi + - name: Clone and build zkevm-bridge-service, if no release tag given + run: | + if [[ ${{ github.event.inputs.zkevm_bridge_service }} =~ ^[0-9a-fA-F]{7}$ ]]; then + git clone https://github.com/0xPolygonHermez/zkevm-bridge-service.git + cd zkevm-bridge-service + git checkout "${{ github.event.inputs.zkevm_bridge_service }}" + docker build -t zkevm-bridge-service:local -f ./Dockerfile . + else + echo "Skipping building zkevm-bridge-service as release tag provided: ${{ github.event.inputs.zkevm_bridge_service }}" + fi + - name: Clone and build zkevm-bridge-ui, if no release tag given + run: | + if [[ ${{ github.event.inputs.zkevm_bridge_ui }} =~ ^[0-9a-fA-F]{7}$ ]]; then + git clone https://github.com/0xPolygonHermez/zkevm-bridge-ui.git + cd zkevm-bridge-ui + git checkout "${{ github.event.inputs.zkevm_bridge_ui }}" + docker build -t zkevm-bridge-ui:local -f ./Dockerfile . + else + echo "Skipping building zkevm-bridge-ui as release tag provided: ${{ github.event.inputs.zkevm_bridge_ui }}" + fi + - name: Clone and build cdk-data-availability, if no release tag given + run: | + if [[ ${{ github.event.inputs.zkevm_dac }} =~ ^[0-9a-fA-F]{7}$ ]]; then + git clone https://github.com/0xPolygon/cdk-data-availability.git + cd cdk-data-availability + git checkout "${{ github.event.inputs.zkevm_dac }}" + docker build -t cdk-data-availability:local -f ./Dockerfile . + else + echo "Skipping building cdk-data-availability as release tag provided: ${{ github.event.inputs.zkevm_dac }}" + fi + - name: Clone and build cdk-validium-node, if no release tag given + run: | + if [[ ${{ github.event.inputs.zkevm_node }} =~ ^[0-9a-fA-F]{7}$ ]]; then + git clone https://github.com/0xPolygon/cdk-validium-node.git + cd cdk-validium-node + git checkout "${{ github.event.inputs.zkevm_node }}" + docker build -t cdk-validium-node:local -f ./Dockerfile . + else + echo "Skipping building cdk-validium-node as release tag provided: ${{ github.event.inputs.zkevm_node }}" + fi + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + - name: Clone internal kurtosis-cdk repo + run: | + git clone https://github.com/0xPolygon/kurtosis-cdk.git + - name: Install kurtosis + run: | + echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list + sudo apt update + sudo apt install kurtosis-cli + kurtosis analytics disable + - name: Install yq + run: pip3 install yq + - name: Update kurtosis params.yml with custom devnet containers + run: | + cd kurtosis-cdk + # when short commit hash given, reference custom image built earlier tagged 'local' + if [[ ${{ github.event.inputs.zkevm_agglayer }} =~ ^[0-9a-fA-F]{7}$ ]]; then + agglayer_tag="local" + agglayer_docker_hub="agglayer" + else + agglayer_tag="${{ github.event.inputs.zkevm_agglayer }}" + agglayer_docker_hub="0xpolygon/agglayer" + fi + + if [[ ${{ github.event.inputs.zkevm_bridge_service }} =~ ^[0-9a-fA-F]{7}$ ]]; then + bridge_service_tag="local" + bridge_service_docker_hub="zkevm-bridge-service" + else + bridge_service_tag="${{ github.event.inputs.zkevm_bridge_service }}" + bridge_service_docker_hub="hermeznetwork/zkevm-bridge-service" + fi + + if [[ ${{ github.event.inputs.zkevm_bridge_ui }} =~ ^[0-9a-fA-F]{7}$ ]]; then + bridge_ui_tag="local" + bridge_ui_docker_hub="zkevm-bridge-ui" + else + bridge_ui_tag="${{ github.event.inputs.zkevm_bridge_ui }}" + bridge_ui_docker_hub="hermeznetwork/zkevm-bridge-ui" + fi + + if [[ ${{ github.event.inputs.zkevm_dac }} =~ ^[0-9a-fA-F]{7}$ ]]; then + dac_tag="local" + dac_docker_hub="cdk-data-availability" + else + dac_tag="${{ github.event.inputs.zkevm_dac }}" + dac_docker_hub="0xpolygon/cdk-data-availability" + fi + + if [[ ${{ github.event.inputs.zkevm_node }} =~ ^[0-9a-fA-F]{7}$ ]]; then + node_tag="local" + node_docker_hub="cdk-validium-node" + else + node_tag="${{ github.event.inputs.zkevm_node }}" + node_docker_hub="0xpolygon/cdk-validium-node" + fi + + cat params.yml + + yq -Y --in-place ".args.zkevm_agglayer_image = \"$agglayer_docker_hub:$agglayer_tag\"" params.yml + yq -Y --in-place ".args.zkevm_bridge_service_image = \"$bridge_service_docker_hub:$bridge_service_tag\"" params.yml + yq -Y --in-place ".args.zkevm_bridge_ui_image = \"$bridge_ui_docker_hub:$bridge_ui_tag\"" params.yml + yq -Y --in-place ".args.zkevm_da_image = \"$dac_docker_hub:$dac_tag\"" params.yml + yq -Y --in-place ".args.zkevm_node_image = \"$node_docker_hub:$node_tag\"" params.yml + + cat params.yml + - name: Deploy CDK devnet on local github runner + run: | + cd kurtosis-cdk + kurtosis clean --all + kurtosis run --enclave cdk-v1 --args-file params.yml --image-download always . + - name: Monitor and report any potential regressions to CI logs + run: | + bake_time="${{ github.event.inputs.bake_time }}" + end_minute=$(( $(date +'%M') + bake_time)) + + export ETH_RPC_URL="$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" + INITIAL_STATUS=$(cast rpc zkevm_verifiedBatchNumber 2>/dev/null) + incremented=false + + while [ $(date +'%M') -lt $end_minute ]; do + # Attempt to connect to the service + if STATUS=$(cast rpc zkevm_verifiedBatchNumber 2>/dev/null); then + echo "ZKEVM_VERIFIED_BATCH_NUMBER: $STATUS" + + # Check if STATUS has incremented + if [ "$STATUS" != "$INITIAL_STATUS" ]; then + incremented=true + echo "ZKEVM_VERIFIED_BATCH_NUMBER successfully incremented to $STATUS. Exiting..." + exit 0 + fi + else + echo "Failed to connect, waiting and retrying..." + sleep 60 + continue + fi + sleep 60 + done + + if ! $incremented; then + echo "ZKEVM_VERIFIED_BATCH_NUMBER did not increment. This may indicate chain experienced a regression. Please investigate." + exit 1 + fi + - name: Install polycli and send transaction load for further integration tests + run: | + git clone https://github.com/maticnetwork/polygon-cli.git + cd polygon-cli + make install + export PATH="$HOME/go/bin:$PATH" + export PK="0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625" + export ETH_RPC_URL="$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" + polycli loadtest --rpc-url "$ETH_RPC_URL" --legacy --private-key "$PK" --verbosity 700 --requests 500 --rate-limit 5 --mode t + polycli loadtest --rpc-url "$ETH_RPC_URL" --legacy --private-key "$PK" --verbosity 700 --requests 500 --rate-limit 10 --mode t + polycli loadtest --rpc-url "$ETH_RPC_URL" --legacy --private-key "$PK" --verbosity 700 --requests 500 --rate-limit 10 --mode 2 From 7191b62e59d21d358b5a09cee94965c5fdaecce1 Mon Sep 17 00:00:00 2001 From: dan moore Date: Wed, 8 May 2024 06:59:09 -0500 Subject: [PATCH 2/8] simplify logic w shared git action --- .github/workflows/regression-tests.yml | 193 +++---------------------- 1 file changed, 24 insertions(+), 169 deletions(-) diff --git a/.github/workflows/regression-tests.yml b/.github/workflows/regression-tests.yml index a9351d65..15588843 100644 --- a/.github/workflows/regression-tests.yml +++ b/.github/workflows/regression-tests.yml @@ -1,5 +1,6 @@ name: Regression Tests -'on': + +on: workflow_dispatch: inputs: zkevm_agglayer: @@ -22,179 +23,33 @@ name: Regression Tests description: 0xPolygon/cdk-validium-node (short commit hash or release tag) required: true default: 0.6.5-cdk + kurtosis_cli: + description: kurtosis-tech/kurtosis (release tag) + required: false + default: 0.89.3 + kurtosis_cdk: + description: 0xPolygon/kurtosis-cdk (release tag) + required: false + default: v0.2.0 bake_time: description: bake time (minutes) required: false default: 30 + jobs: - deploy_devnet: + regression_tests: runs-on: ubuntu-latest steps: - - name: Checkout repository + - name: Checkout Repository uses: actions/checkout@v2 - - name: Set up Docker - uses: docker/setup-buildx-action@v1 - - name: Clone and build agglayer, if no release tag given - run: | - if [[ ${{ github.event.inputs.zkevm_agglayer }} =~ ^[0-9a-fA-F]{7}$ ]]; then - git clone https://github.com/0xPolygon/agglayer.git - cd agglayer - git checkout "${{ github.event.inputs.zkevm_agglayer }}" - docker compose -f docker/docker-compose.yaml build --no-cache agglayer - else - echo "Skipping building agglayer as release tag provided: ${{ github.event.inputs.zkevm_agglayer }}" - fi - - name: Clone and build zkevm-bridge-service, if no release tag given - run: | - if [[ ${{ github.event.inputs.zkevm_bridge_service }} =~ ^[0-9a-fA-F]{7}$ ]]; then - git clone https://github.com/0xPolygonHermez/zkevm-bridge-service.git - cd zkevm-bridge-service - git checkout "${{ github.event.inputs.zkevm_bridge_service }}" - docker build -t zkevm-bridge-service:local -f ./Dockerfile . - else - echo "Skipping building zkevm-bridge-service as release tag provided: ${{ github.event.inputs.zkevm_bridge_service }}" - fi - - name: Clone and build zkevm-bridge-ui, if no release tag given - run: | - if [[ ${{ github.event.inputs.zkevm_bridge_ui }} =~ ^[0-9a-fA-F]{7}$ ]]; then - git clone https://github.com/0xPolygonHermez/zkevm-bridge-ui.git - cd zkevm-bridge-ui - git checkout "${{ github.event.inputs.zkevm_bridge_ui }}" - docker build -t zkevm-bridge-ui:local -f ./Dockerfile . - else - echo "Skipping building zkevm-bridge-ui as release tag provided: ${{ github.event.inputs.zkevm_bridge_ui }}" - fi - - name: Clone and build cdk-data-availability, if no release tag given - run: | - if [[ ${{ github.event.inputs.zkevm_dac }} =~ ^[0-9a-fA-F]{7}$ ]]; then - git clone https://github.com/0xPolygon/cdk-data-availability.git - cd cdk-data-availability - git checkout "${{ github.event.inputs.zkevm_dac }}" - docker build -t cdk-data-availability:local -f ./Dockerfile . - else - echo "Skipping building cdk-data-availability as release tag provided: ${{ github.event.inputs.zkevm_dac }}" - fi - - name: Clone and build cdk-validium-node, if no release tag given - run: | - if [[ ${{ github.event.inputs.zkevm_node }} =~ ^[0-9a-fA-F]{7}$ ]]; then - git clone https://github.com/0xPolygon/cdk-validium-node.git - cd cdk-validium-node - git checkout "${{ github.event.inputs.zkevm_node }}" - docker build -t cdk-validium-node:local -f ./Dockerfile . - else - echo "Skipping building cdk-validium-node as release tag provided: ${{ github.event.inputs.zkevm_node }}" - fi - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 - - name: Clone internal kurtosis-cdk repo - run: | - git clone https://github.com/0xPolygon/kurtosis-cdk.git - - name: Install kurtosis - run: | - echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list - sudo apt update - sudo apt install kurtosis-cli - kurtosis analytics disable - - name: Install yq - run: pip3 install yq - - name: Update kurtosis params.yml with custom devnet containers - run: | - cd kurtosis-cdk - # when short commit hash given, reference custom image built earlier tagged 'local' - if [[ ${{ github.event.inputs.zkevm_agglayer }} =~ ^[0-9a-fA-F]{7}$ ]]; then - agglayer_tag="local" - agglayer_docker_hub="agglayer" - else - agglayer_tag="${{ github.event.inputs.zkevm_agglayer }}" - agglayer_docker_hub="0xpolygon/agglayer" - fi - - if [[ ${{ github.event.inputs.zkevm_bridge_service }} =~ ^[0-9a-fA-F]{7}$ ]]; then - bridge_service_tag="local" - bridge_service_docker_hub="zkevm-bridge-service" - else - bridge_service_tag="${{ github.event.inputs.zkevm_bridge_service }}" - bridge_service_docker_hub="hermeznetwork/zkevm-bridge-service" - fi - - if [[ ${{ github.event.inputs.zkevm_bridge_ui }} =~ ^[0-9a-fA-F]{7}$ ]]; then - bridge_ui_tag="local" - bridge_ui_docker_hub="zkevm-bridge-ui" - else - bridge_ui_tag="${{ github.event.inputs.zkevm_bridge_ui }}" - bridge_ui_docker_hub="hermeznetwork/zkevm-bridge-ui" - fi - - if [[ ${{ github.event.inputs.zkevm_dac }} =~ ^[0-9a-fA-F]{7}$ ]]; then - dac_tag="local" - dac_docker_hub="cdk-data-availability" - else - dac_tag="${{ github.event.inputs.zkevm_dac }}" - dac_docker_hub="0xpolygon/cdk-data-availability" - fi - - if [[ ${{ github.event.inputs.zkevm_node }} =~ ^[0-9a-fA-F]{7}$ ]]; then - node_tag="local" - node_docker_hub="cdk-validium-node" - else - node_tag="${{ github.event.inputs.zkevm_node }}" - node_docker_hub="0xpolygon/cdk-validium-node" - fi - - cat params.yml - - yq -Y --in-place ".args.zkevm_agglayer_image = \"$agglayer_docker_hub:$agglayer_tag\"" params.yml - yq -Y --in-place ".args.zkevm_bridge_service_image = \"$bridge_service_docker_hub:$bridge_service_tag\"" params.yml - yq -Y --in-place ".args.zkevm_bridge_ui_image = \"$bridge_ui_docker_hub:$bridge_ui_tag\"" params.yml - yq -Y --in-place ".args.zkevm_da_image = \"$dac_docker_hub:$dac_tag\"" params.yml - yq -Y --in-place ".args.zkevm_node_image = \"$node_docker_hub:$node_tag\"" params.yml - - cat params.yml - - name: Deploy CDK devnet on local github runner - run: | - cd kurtosis-cdk - kurtosis clean --all - kurtosis run --enclave cdk-v1 --args-file params.yml --image-download always . - - name: Monitor and report any potential regressions to CI logs - run: | - bake_time="${{ github.event.inputs.bake_time }}" - end_minute=$(( $(date +'%M') + bake_time)) - - export ETH_RPC_URL="$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" - INITIAL_STATUS=$(cast rpc zkevm_verifiedBatchNumber 2>/dev/null) - incremented=false - - while [ $(date +'%M') -lt $end_minute ]; do - # Attempt to connect to the service - if STATUS=$(cast rpc zkevm_verifiedBatchNumber 2>/dev/null); then - echo "ZKEVM_VERIFIED_BATCH_NUMBER: $STATUS" - - # Check if STATUS has incremented - if [ "$STATUS" != "$INITIAL_STATUS" ]; then - incremented=true - echo "ZKEVM_VERIFIED_BATCH_NUMBER successfully incremented to $STATUS. Exiting..." - exit 0 - fi - else - echo "Failed to connect, waiting and retrying..." - sleep 60 - continue - fi - sleep 60 - done - - if ! $incremented; then - echo "ZKEVM_VERIFIED_BATCH_NUMBER did not increment. This may indicate chain experienced a regression. Please investigate." - exit 1 - fi - - name: Install polycli and send transaction load for further integration tests - run: | - git clone https://github.com/maticnetwork/polygon-cli.git - cd polygon-cli - make install - export PATH="$HOME/go/bin:$PATH" - export PK="0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625" - export ETH_RPC_URL="$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" - polycli loadtest --rpc-url "$ETH_RPC_URL" --legacy --private-key "$PK" --verbosity 700 --requests 500 --rate-limit 5 --mode t - polycli loadtest --rpc-url "$ETH_RPC_URL" --legacy --private-key "$PK" --verbosity 700 --requests 500 --rate-limit 10 --mode t - polycli loadtest --rpc-url "$ETH_RPC_URL" --legacy --private-key "$PK" --verbosity 700 --requests 500 --rate-limit 10 --mode 2 + - name: Run Regression Tests + uses: 0xPolygon/kurtosis-cdk@v0.1.6 + with: + zkevm_agglayer: ${{ github.event.inputs.zkevm_agglayer }} + zkevm_bridge_service: ${{ github.event.inputs.zkevm_bridge_service }} + zkevm_bridge_ui: ${{ github.event.inputs.zkevm_bridge_ui }} + zkevm_dac: ${{ github.event.inputs.zkevm_dac }} + zkevm_node: ${{ github.event.inputs.zkevm_node }} + kurtosis_cli: ${{ github.event.inputs.kurtosis_cli }} + kurtosis_cdk: ${{ github.event.inputs.kurtosis_cdk }} + bake_time: ${{ github.event.inputs.bake_time }} \ No newline at end of file From 4e7437e923f33864dcdea2803ee47dd27c26093d Mon Sep 17 00:00:00 2001 From: dan moore Date: Wed, 8 May 2024 17:07:38 -0500 Subject: [PATCH 3/8] bump git action version --- .github/workflows/regression-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/regression-tests.yml b/.github/workflows/regression-tests.yml index 15588843..18eb48d0 100644 --- a/.github/workflows/regression-tests.yml +++ b/.github/workflows/regression-tests.yml @@ -43,7 +43,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v2 - name: Run Regression Tests - uses: 0xPolygon/kurtosis-cdk@v0.1.6 + uses: 0xPolygon/kurtosis-cdk@v0.1.7 with: zkevm_agglayer: ${{ github.event.inputs.zkevm_agglayer }} zkevm_bridge_service: ${{ github.event.inputs.zkevm_bridge_service }} @@ -52,4 +52,4 @@ jobs: zkevm_node: ${{ github.event.inputs.zkevm_node }} kurtosis_cli: ${{ github.event.inputs.kurtosis_cli }} kurtosis_cdk: ${{ github.event.inputs.kurtosis_cdk }} - bake_time: ${{ github.event.inputs.bake_time }} \ No newline at end of file + bake_time: ${{ github.event.inputs.bake_time }} From 2244b9ee18dd66e6e5062aae8be93347fa547dae Mon Sep 17 00:00:00 2001 From: dan moore Date: Thu, 9 May 2024 07:49:04 -0500 Subject: [PATCH 4/8] bump version --- .github/workflows/regression-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/regression-tests.yml b/.github/workflows/regression-tests.yml index 18eb48d0..ed609dc2 100644 --- a/.github/workflows/regression-tests.yml +++ b/.github/workflows/regression-tests.yml @@ -43,7 +43,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v2 - name: Run Regression Tests - uses: 0xPolygon/kurtosis-cdk@v0.1.7 + uses: 0xPolygon/kurtosis-cdk@v0.1.8 with: zkevm_agglayer: ${{ github.event.inputs.zkevm_agglayer }} zkevm_bridge_service: ${{ github.event.inputs.zkevm_bridge_service }} From 4925a49b19efd078fca8c5f56b859b176d9f1c37 Mon Sep 17 00:00:00 2001 From: dan moore Date: Thu, 9 May 2024 08:34:33 -0500 Subject: [PATCH 5/8] bump version --- .github/workflows/regression-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/regression-tests.yml b/.github/workflows/regression-tests.yml index ed609dc2..bb61aa4b 100644 --- a/.github/workflows/regression-tests.yml +++ b/.github/workflows/regression-tests.yml @@ -43,7 +43,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v2 - name: Run Regression Tests - uses: 0xPolygon/kurtosis-cdk@v0.1.8 + uses: 0xPolygon/kurtosis-cdk@v0.1.9 with: zkevm_agglayer: ${{ github.event.inputs.zkevm_agglayer }} zkevm_bridge_service: ${{ github.event.inputs.zkevm_bridge_service }} From 7f715d07e084afca25155d0f32063790e5df3c76 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Mon, 1 Jul 2024 17:36:49 +0530 Subject: [PATCH 6/8] tests with kurtosis --- test/Makefile | 3 ++ test/ethtransfer_test.go | 54 ++++++++++++++++++++++++++ test/operations/operations.go | 24 ++++++++++++ test/operations/transactions.go | 67 +++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 test/Makefile create mode 100644 test/ethtransfer_test.go create mode 100644 test/operations/operations.go create mode 100644 test/operations/transactions.go diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 00000000..93a62f50 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,3 @@ +.PHONY: run-tests +run-tests: ## Runs all tests within the workspace + go test -v -race ./... \ No newline at end of file diff --git a/test/ethtransfer_test.go b/test/ethtransfer_test.go new file mode 100644 index 00000000..e7326c20 --- /dev/null +++ b/test/ethtransfer_test.go @@ -0,0 +1,54 @@ +package test + +import ( + "math/big" + "testing" + "time" + + "github.com/0xPolygon/cdk/test/operations" + "github.com/stretchr/testify/require" + "github.com/umbracle/ethgo" + "github.com/umbracle/ethgo/jsonrpc" + "github.com/umbracle/ethgo/wallet" +) + +func TestEthTransfer(t *testing.T) { + cmd := exec.Command("kurtosis", "port", "print", "cdk-v1", "zkevm-node-rpc-001", "http-rpc") + output, err := cmd.CombinedOutput() + if err != nil { + log.Fatalf("Failed to execute command: %s", err) + } + operations.L2RPCURL = strings.TrimSpace(string(output)) + + const amountOfTxsToSend = 10 + client, err := jsonrpc.NewClient(operations.L2RPCURL) + require.NoError(t, err) + key, err := operations.GetL2Wallet() + require.NoError(t, err) + signer := wallet.NewEIP155Signer(operations.L2ChainID) + initialNonce, err := client.Eth().GetNonce(key.Address(), ethgo.Latest) + require.NoError(t, err) + gasPrice, err := client.Eth().GasPrice() + require.NoError(t, err) + + txHashes := []ethgo.Hash{} + for i := 0; i < amountOfTxsToSend; i++ { + tx := ðgo.Transaction{ + ChainID: big.NewInt(operations.L2ChainID), + Nonce: initialNonce + uint64(i), + GasPrice: gasPrice, + Gas: 21000, + To: ðgo.ZeroAddress, + } + signedTxn, err := signer.SignTx(tx, key) + require.NoError(t, err) + rawTx, err := signedTxn.MarshalRLPTo(nil) + require.NoError(t, err) + hash, err := client.Eth().SendRawTransaction(rawTx) + require.NoError(t, err) + txHashes = append(txHashes, hash) + } + for _, h := range txHashes { + require.NoError(t, operations.WaitTxToBeMined(h, operations.Verified, client, time.Minute*2)) + } +} \ No newline at end of file diff --git a/test/operations/operations.go b/test/operations/operations.go new file mode 100644 index 00000000..f4fc7ca9 --- /dev/null +++ b/test/operations/operations.go @@ -0,0 +1,24 @@ +package operations + +import( + "encoding/hex" + "github.com/umbracle/ethgo/wallet" +) + +const ( + L1RPCURL = "http://el-1-geth-lighthouse:8545" + L2ChainID = 10101 + + // Prefunded account present on kurtosis-cdk + PrivateKeyWithFundsOnL2 = "12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625" +) + +var L2RPCURL = "http://localhost:8123" + +func GetL2Wallet() (*wallet.Key, error) { + prvKeyBytes, err := hex.DecodeString(PrivateKeyWithFundsOnL2) + if err != nil { + return nil, err + } + return wallet.NewWalletFromPrivKey(prvKeyBytes) +} \ No newline at end of file diff --git a/test/operations/transactions.go b/test/operations/transactions.go new file mode 100644 index 00000000..a680dd70 --- /dev/null +++ b/test/operations/transactions.go @@ -0,0 +1,67 @@ +package operations + +import ( + "errors" + "fmt" + "time" + + "github.com/umbracle/ethgo" + "github.com/umbracle/ethgo/jsonrpc" +) + +type ConfirmationLevel string + +const ( + Trusted ConfirmationLevel = "trusted" + Virtual ConfirmationLevel = "virtual" + Verified ConfirmationLevel = "verified" +) + +func WaitTxToBeMined(hash ethgo.Hash, level ConfirmationLevel, client *jsonrpc.Client, timeout time.Duration) error { + startingTime := time.Now() + fmt.Printf("waiting for tx %s to be included in the %s state\n", hash.String(), level) + var ( + encodedL2BlockNumber string + isVirtualized bool + isVerified bool + ) + for time.Since(startingTime) < timeout { + if encodedL2BlockNumber == "" { + receipt, err := client.Eth().GetTransactionReceipt(hash) + if err != nil || receipt == nil { + time.Sleep(time.Second) + continue + } + fmt.Printf("tx %s included in the trusted state at the L2 block %d\n", hash.String(), receipt.BlockNumber) + if level == Trusted { + return nil + } + encodedL2BlockNumber = fmt.Sprintf("0x%x", receipt.BlockNumber) + } + + if !isVirtualized { + if err := client.Call("zkevm_isBlockVirtualized", &isVirtualized, encodedL2BlockNumber); err != nil { + time.Sleep(time.Second) + continue + } + if isVirtualized { + fmt.Printf("tx %s included in the virtual state\n", hash.String()) + if level == Virtual { + return nil + } + } else { + time.Sleep(time.Second) + continue + } + } + if err := client.Call("zkevm_isBlockConsolidated", &isVerified, encodedL2BlockNumber); err != nil { + time.Sleep(time.Second) + continue + } + if isVerified { + fmt.Printf("tx %s included in the verified state\n", hash.String()) + return nil + } + } + return errors.New("timed out") +} \ No newline at end of file From 357e53939a72b5564a528c0180678e2d8fe36ae2 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Mon, 1 Jul 2024 17:41:45 +0530 Subject: [PATCH 7/8] wip --- .github/workflows/regression-tests.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/regression-tests.yml b/.github/workflows/regression-tests.yml index bb61aa4b..5d28f728 100644 --- a/.github/workflows/regression-tests.yml +++ b/.github/workflows/regression-tests.yml @@ -34,7 +34,7 @@ on: bake_time: description: bake time (minutes) required: false - default: 30 + default: '30' jobs: regression_tests: @@ -53,3 +53,7 @@ jobs: kurtosis_cli: ${{ github.event.inputs.kurtosis_cli }} kurtosis_cdk: ${{ github.event.inputs.kurtosis_cdk }} bake_time: ${{ github.event.inputs.bake_time }} + - name: Run Integration Tests + run: | + echo "Running Integration Tests" + make -f ./tests/Makefile run-tests From fb4c61dbc7770a74650f30148cef91bdf3822f5f Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Wed, 17 Jul 2024 18:55:31 +0530 Subject: [PATCH 8/8] address comments --- test/ethtransfer_test.go | 7 +------ test/operations/operations.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/ethtransfer_test.go b/test/ethtransfer_test.go index e7326c20..b474da7e 100644 --- a/test/ethtransfer_test.go +++ b/test/ethtransfer_test.go @@ -13,12 +13,7 @@ import ( ) func TestEthTransfer(t *testing.T) { - cmd := exec.Command("kurtosis", "port", "print", "cdk-v1", "zkevm-node-rpc-001", "http-rpc") - output, err := cmd.CombinedOutput() - if err != nil { - log.Fatalf("Failed to execute command: %s", err) - } - operations.L2RPCURL = strings.TrimSpace(string(output)) + operations.L2RPCURL = operations.GetL2RPCURL() const amountOfTxsToSend = 10 client, err := jsonrpc.NewClient(operations.L2RPCURL) diff --git a/test/operations/operations.go b/test/operations/operations.go index f4fc7ca9..f9ea6d6b 100644 --- a/test/operations/operations.go +++ b/test/operations/operations.go @@ -21,4 +21,14 @@ func GetL2Wallet() (*wallet.Key, error) { return nil, err } return wallet.NewWalletFromPrivKey(prvKeyBytes) +} + +func GetL2RPCURL() string { + cmd := exec.Command("kurtosis", "port", "print", "cdk-v1", "zkevm-node-rpc-001", "http-rpc") + output, err := cmd.CombinedOutput() + if err != nil { + log.Fatalf("Failed to execute command: %s", err) + } + + return strings.TrimSpace(string(output)) } \ No newline at end of file