diff --git a/.github/test-e2e.yml b/.github/test-e2e.yml new file mode 100644 index 00000000..06a695ad --- /dev/null +++ b/.github/test-e2e.yml @@ -0,0 +1,40 @@ +--- +name: Test e2e +on: + push: + branches: + - main + - master + - develop + - update-external-dependencies + - 'release/**' + pull_request: + +jobs: + test-e2e: + strategy: + fail-fast: false + matrix: + go-version: [ 1.21.x ] + goarch: [ "amd64" ] + e2e-group: [ "elderberry-validium", "elderberry-rollup" ] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + env: + GOARCH: ${{ matrix.goarch }} + + - name: Build Docker + run: make build-docker + + + + - name: Test + run: make test-e2e-${{ matrix.e2e-group }} + working-directory: test diff --git a/Dockerfile b/Dockerfile index 19aef335..294dd305 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,6 @@ RUN cd /src && make build # CONTAINER FOR RUNNING BINARY FROM alpine:3.18.4 COPY --from=build /src/dist/cdk /app/cdk -RUN apk update && apk add postgresql15-client +RUN mkdir /app/data && apk update && apk add postgresql15-client EXPOSE 8123 CMD ["/bin/sh", "-c", "/app/cdk run"] diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 00000000..43facfe5 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,23 @@ +.PHONY: test-e2e-elderberry-validium +test-e2e-elderberry-validium: stop ## Runs e2e tests checking elderberry/validium + ./run-e2e-seq_sender.sh cdk-validium + +.PHONY: test-e2e-elderberry-rollup +test-e2e-elderberry-rollup: stop ## Runs e2e tests checking elderberry/rollup + ./run-e2e-seq_sender.sh rollup + +.PHONY: stop +stop: + kurtosis clean --all + + +## Help display. +## Pulls comments from beside commands and prints a nicely formatted +## display with the commands and their usage information. +.DEFAULT_GOAL := help + +.PHONY: help +help: ## Prints this help + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ + | sort \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/test/config/test.kurtosis_template.toml b/test/config/test.kurtosis_template.toml index 061a4838..b2f7f68f 100644 --- a/test/config/test.kurtosis_template.toml +++ b/test/config/test.kurtosis_template.toml @@ -15,6 +15,7 @@ Level = "info" Outputs = ["stderr"] [SequenceSender] +IsValidiumMode={{.zkevm_is_validium}} WaitPeriodSendSequence = "15s" LastBatchVirtualizationTimeMaxWaitPeriod = "10s" L1BlockTimestampMargin = "30s" diff --git a/test/run-e2e-seq_sender.sh b/test/run-e2e-seq_sender.sh new file mode 100755 index 00000000..222a0131 --- /dev/null +++ b/test/run-e2e-seq_sender.sh @@ -0,0 +1,32 @@ +#!/bin/bash +source $(dirname $0)/scripts/env.sh +FORK=elderberry +DATA_AVAILABILITY_MODE=$1 +if [ -z $DATA_AVAILABILITY_MODE ]; then + echo "Missing DATA_AVAILABILITY_MODE: ['rollup', 'cdk-validium']" + exit 1 +fi +KURTOSIS_VERSION=jesteban/cdk-seq_sender +BASE_FOLDER=$(dirname $0) +KURTOSIS_FOLDER=$($BASE_FOLDER/scripts/get_kurtosis_clone_folder.sh $KURTOSIS_VERSION) +[ $? -ne 0 ] && echo "Error getting kurtosis folder" && exit 1 + +$BASE_FOLDER/scripts/clone_kurtosis.sh $KURTOSIS_VERSION "$KURTOSIS_FOLDER" +[ $? -ne 0 ] && echo "Error cloning kurtosis " && exit 1 + +docker images -q cdk:latest > /dev/null +if [ $? -ne 0 ] ; then + echo "Building cdk:latest" + pushd $BASE_FOLDER/.. + make build-docker + popd +else + echo "docker cdk:latest already exists" +fi + +$BASE_FOLDER/scripts/kurtosis_prepare_params_yml.sh "$KURTOSIS_FOLDER" "elderberry" "cdk-validium" +[ $? -ne 0 ] && echo "Error preparing params.yml" && exit 1 + +kurtosis clean --all +kurtosis run --enclave cdk-v1 --args-file $DEST_KURTOSIS_PARAMS_YML --image-download always $KURTOSIS_FOLDER +[ $? -ne 0 ] && echo "Error running kurtosis" && exit 1 \ No newline at end of file diff --git a/test/scripts/clone_kurtosis.sh b/test/scripts/clone_kurtosis.sh new file mode 100755 index 00000000..f4505e75 --- /dev/null +++ b/test/scripts/clone_kurtosis.sh @@ -0,0 +1,31 @@ +#!/bin/bash +source $(dirname $0)/env.sh + +usage() { + echo "Usage: $0 " + echo "Clones kurtosis-cdk version to folder " +} + +KURTOSIS_CDK_URL="git@github.com:0xPolygon/kurtosis-cdk.git" +KURTOSIS_VERSION=$1 +if [ -z $KURTOSIS_VERSION ]; then + echo "Missing param KURTOSIS_VERSION" + usage + exit 1 +fi +DEST_FOLDER="$2" +if [ -z $DEST_FOLDER ]; then + echo "Missing param Destination Folder" + usage + exit 1 +fi +if [ -d $DEST_FOLDER ]; then + echo "Folder $DEST_FOLDER already exists. No cloning needed" + pushd $DEST_FOLDER > /dev/null + echo "Pulling latest changes" + git pull + popd > /dev/null + exit 0 +fi +echo "Cloning kurtosis-cdk version $KURTOSIS_VERSION to folder $DEST_FOLDER" +git clone --depth=1 $KURTOSIS_CDK_URL -b "$KURTOSIS_VERSION" "$DEST_FOLDER" \ No newline at end of file diff --git a/test/scripts/env.sh b/test/scripts/env.sh new file mode 100644 index 00000000..bb814ff9 --- /dev/null +++ b/test/scripts/env.sh @@ -0,0 +1,5 @@ +#!/bin/bash +### Common variables +ENCLAVE=cdk-v1 +TMP_CDK_FOLDER=/tmp/cdk +DEST_KURTOSIS_PARAMS_YML=$TMP_CDK_FOLDER/e2e-params.yml \ No newline at end of file diff --git a/test/scripts/get_kurtosis_clone_folder.sh b/test/scripts/get_kurtosis_clone_folder.sh new file mode 100755 index 00000000..0a1946b5 --- /dev/null +++ b/test/scripts/get_kurtosis_clone_folder.sh @@ -0,0 +1,11 @@ +#!/bin/bash +source $(dirname $0)/env.sh + +KURTOSIS_VERSION=$1 +if [ -z $KURTOSIS_VERSION ]; then + echo "KURTOSIS_VERSION is not set. Must be set on file env.sh" + exit 1 +fi +KURTOSIS_VERSION_FOLDER_NAME=$(echo $KURTOSIS_VERSION | tr -c '[:alnum:]._-' '_') +DEST_FOLDER=$TMP_CDK_FOLDER/kurtosis-cdk-$KURTOSIS_VERSION_FOLDER_NAME +echo $DEST_FOLDER \ No newline at end of file diff --git a/test/scripts/kurtosis_prepare_params_yml.sh b/test/scripts/kurtosis_prepare_params_yml.sh new file mode 100755 index 00000000..3921deaa --- /dev/null +++ b/test/scripts/kurtosis_prepare_params_yml.sh @@ -0,0 +1,35 @@ +#!/bin/bash +source $(dirname $0)/env.sh + +if [ -z $DEST_KURTOSIS_PARAMS_YML ]; then + echo "DEST_KURTOSIS_PARAMS_YML is not set. Must be set on file env.sh" + exit 1 +fi + +KURTOSIS_FOLDER=$1 +if [ -z $KURTOSIS_FOLDER ]; then + echo "Missing param Kurtosis Folder" + exit 1 +fi + +FORK_NAME=$2 +if [ -z $FORK_NAME ]; then + echo "Missing param Fork Name" + exit 1 +fi +DATA_AVAILABILITY_MODE=$3 +if [ -z $DATA_AVAILABILITY_MODE ]; then + echo "Missing param Data Availability Mode : [rollup, cdk-validium]" + exit 1 +fi + + + + +cp $KURTOSIS_FOLDER/cdk-erigon-sequencer-params.yml $DEST_KURTOSIS_PARAMS_YML +yq -Y --in-place ".args.data_availability_mode = \"$DATA_AVAILABILITY_MODE\"" $DEST_KURTOSIS_PARAMS_YML +yq -Y --in-place ".args.zkevm_sequence_sender_image = \"cdk:latest\"" $DEST_KURTOSIS_PARAMS_YML +yq -Y --in-place ".args.sequencer_type = \"erigon\"" $DEST_KURTOSIS_PARAMS_YML +yq -Y --in-place ".args.deploy_cdk_erigon_node = true" $DEST_KURTOSIS_PARAMS_YML +yq -Y --in-place ".args.sequencer_type = \"erigon\"" $DEST_KURTOSIS_PARAMS_YML +yq -Y --in-place ".args.sequencer_sender_type = \"cdk\"" $DEST_KURTOSIS_PARAMS_YML \ No newline at end of file