diff --git a/.github/test_fork11_rollup_e2e_args.json b/.github/test_fork11_rollup_e2e_args.json new file mode 100644 index 000000000..3cace6af5 --- /dev/null +++ b/.github/test_fork11_rollup_e2e_args.json @@ -0,0 +1,13 @@ +{ + "args": { + "zkevm_contracts_image": "leovct/zkevm-contracts:v7.0.0-rc.2-fork.11-patch.1", + "zkevm_prover_image": "hermeznetwork/zkevm-prover:v7.0.4-hotfix.2-fork.11", + "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.0-fork11", + "cdk_node_image": "cdk:local", + "gas_token_enabled": true, + "gas_token_address": "", + "data_availability_mode": "rollup", + "sequencer_type": "erigon", + "agglayer_image": "ghcr.io/agglayer/agglayer:0.2.0-rc.19" + } +} diff --git a/.github/test_fork12_cdk_validium_e2e_args.json b/.github/test_fork12_cdk_validium_e2e_args.json new file mode 100644 index 000000000..ec9491e72 --- /dev/null +++ b/.github/test_fork12_cdk_validium_e2e_args.json @@ -0,0 +1,11 @@ +{ + "args": { + "zkevm_contracts_image": "jhkimqd/zkevm-contracts:v10.0.0-rc.6-fork.12", + "zkevm_prover_image": "hermeznetwork/zkevm-prover:v8.0.0-RC16-fork.12", + "cdk_node_image": "cdk:local", + "gas_token_enabled": true, + "gas_token_address": "", + "data_availability_mode": "cdk-validium", + "sequencer_type": "erigon" + } +} diff --git a/.github/test_fork12_rollup_e2e_args.json b/.github/test_fork12_rollup_e2e_args.json new file mode 100644 index 000000000..b5d9ac012 --- /dev/null +++ b/.github/test_fork12_rollup_e2e_args.json @@ -0,0 +1,11 @@ +{ + "args": { + "zkevm_contracts_image": "jhkimqd/zkevm-contracts:v10.0.0-rc.6-fork.12", + "zkevm_prover_image": "hermeznetwork/zkevm-prover:v8.0.0-RC16-fork.12", + "cdk_node_image": "cdk:local", + "gas_token_enabled": true, + "gas_token_address": "", + "data_availability_mode": "rollup", + "sequencer_type": "erigon" + } +} diff --git a/.github/test_fork9_cdk_validium_e2e_args.json b/.github/test_fork9_cdk_validium_e2e_args.json new file mode 100644 index 000000000..4853bfb8a --- /dev/null +++ b/.github/test_fork9_cdk_validium_e2e_args.json @@ -0,0 +1,17 @@ +{ + "args": { + "zkevm_contracts_image": "leovct/zkevm-contracts:v6.0.0-rc.1-fork.9-patch.1", + "zkevm_prover_image": "hermeznetwork/zkevm-prover:v6.0.8", + "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", + "cdk_validium_node_image": "ghcr.io/0xpolygon/cdk-validium-node:0.6.4-cdk.10", + "cdk_node_image": "cdk:local", + "gas_token_enabled": true, + "gas_token_address": "", + "additional_services": [ + "pless_zkevm_node" + ], + "data_availability_mode": "cdk-validium", + "sequencer_type": "erigon", + "agglayer_image": "ghcr.io/agglayer/agglayer:0.2.0-rc.19" + } +} diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index e01df83e9..3fce6852d 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -6,6 +6,10 @@ on: workflow_dispatch: {} +permissions: + id-token: write + contents: write + jobs: build-cdk-image: runs-on: ubuntu-latest @@ -30,79 +34,127 @@ jobs: name: cdk path: /tmp/cdk.tar - test-e2e: + read-test-args: + name: Read tests args runs-on: ubuntu-latest - timeout-minutes: 60 - needs: build-cdk-image - strategy: - fail-fast: false - matrix: - e2e-group: - - "fork9-validium" - - "fork11-rollup" - - "fork12-validium" - - "fork12-rollup" + outputs: + test-fork9-cdk-validium-e2e-args: ${{ steps.read-args.outputs.test-fork9-cdk-validium-e2e-args }} + test-fork11-rollup-e2e-args: ${{ steps.read-args.outputs.test-fork11-rollup-e2e-args }} + test-fork12-cdk-validium-e2e-args: ${{ steps.read-args.outputs.test-fork12-cdk-validium-e2e-args }} + test-fork12-rollup-e2e-args: ${{ steps.read-args.outputs.test-fork12-rollup-e2e-args }} steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Checkout Kurtosis CDK - uses: actions/checkout@v4 - with: - repository: 0xPolygon/kurtosis-cdk - path: kurtosis-cdk - ref: c3caebc409c7f69354ae012f15cac76f3edf8503 - - - name: Install Kurtosis CDK tools - uses: ./kurtosis-cdk/.github/actions/setup-kurtosis-cdk - - - name: Install polycli - run: | - POLYCLI_VERSION="${{ vars.POLYCLI_VERSION }}" - tmp_dir=$(mktemp -d) - curl -L "https://github.com/0xPolygon/polygon-cli/releases/download/${POLYCLI_VERSION}/polycli_${POLYCLI_VERSION}_linux_amd64.tar.gz" | tar -xz -C "$tmp_dir" - mv "$tmp_dir"/* /usr/local/bin/polycli - rm -rf "$tmp_dir" - sudo chmod +x /usr/local/bin/polycli - /usr/local/bin/polycli version + - name: Checkout + uses: actions/checkout@v4 - - name: Setup Bats and bats libs - uses: bats-core/bats-action@2.0.0 - - - name: Download cdk archive - uses: actions/download-artifact@v4 - with: - name: cdk - path: /tmp - - - name: Load cdk image - run: | - docker load --input /tmp/cdk.tar - docker image ls -a + - name: Read kurtosis-cdk-args from file + id: read-args + run: | + CONTENT=$(cat ./.github/test_fork9_cdk_validium_e2e_args.json | jq -c .) + echo "test-fork9-cdk-validium-e2e-args=${CONTENT}" >> $GITHUB_OUTPUT + CONTENT=$(cat ./.github/test_fork11_rollup_e2e_args.json | jq -c .) + echo "test-fork11-rollup-e2e-args=${CONTENT}" >> $GITHUB_OUTPUT + CONTENT=$(cat ./.github/test_fork12_cdk_validium_e2e_args.json | jq -c .) + echo "test-fork12-cdk-validium-e2e-args=${CONTENT}" >> $GITHUB_OUTPUT + CONTENT=$(cat ./.github/test_fork12_rollup_e2e_args.json | jq -c .) + echo "test-fork12-rollup-e2e-args=${CONTENT}" >> $GITHUB_OUTPUT - - name: Run e2e tests - run: make test-e2e-${{ matrix.e2e-group }} - working-directory: test - env: - KURTOSIS_FOLDER: ${{ github.workspace }}/kurtosis-cdk - BATS_LIB_PATH: /usr/lib/ - agglayer_prover_sp1_key: ${{ secrets.SP1_PRIVATE_KEY }} - - - name: Dump enclave logs - if: failure() - run: kurtosis dump ./dump + test-fork9-cdk-validium-e2e: + name: E2E test + needs: + - build-cdk-image + - read-test-args + uses: agglayer/e2e/.github/workflows/cdk-e2e.yml@41dd4252fec7e16d6b6199652a182c47b40b02d6 + secrets: inherit + with: + kurtosis-cdk-ref: 651696273abfaf19eae8233a3863f5e93091c087 + agglayer-e2e-ref: 41dd4252fec7e16d6b6199652a182c47b40b02d6 + test-name: test-fork9-cdk-validium-e2e + kurtosis-cdk-args: ${{ needs.read-test-args.outputs.test-fork9-cdk-validium-e2e-args }} - - name: Generate archive name - if: failure() - run: | - archive_name="dump_run_with_args_${{matrix.e2e-group}}_${{ github.run_id }}" - echo "ARCHIVE_NAME=${archive_name}" >> "$GITHUB_ENV" - echo "Generated archive name: ${archive_name}" - kurtosis service exec cdk cdk-node-001 'cat /etc/cdk/cdk-node-config.toml' > ./dump/cdk-node-config.toml + check-fork9-cdk-validium-e2e-result: + name: Check E2E results + permissions: + id-token: write + contents: write + needs: + - test-fork9-cdk-validium-e2e + if: always() + runs-on: ubuntu-latest + steps: + - run: exit 1 + if: ${{ contains(fromJSON('["failure", "cancelled"]'), needs.test-fork9-cdk-validium-e2e.result) }} - - name: Upload logs - if: failure() - uses: actions/upload-artifact@v4 - with: - name: ${{ env.ARCHIVE_NAME }} - path: ./dump + test-fork11-rollup-e2e: + name: E2E test + needs: + - build-cdk-image + - read-test-args + uses: agglayer/e2e/.github/workflows/cdk-e2e.yml@41dd4252fec7e16d6b6199652a182c47b40b02d6 + secrets: inherit + with: + kurtosis-cdk-ref: 651696273abfaf19eae8233a3863f5e93091c087 + agglayer-e2e-ref: 41dd4252fec7e16d6b6199652a182c47b40b02d6 + test-name: test-fork11-rollup-e2e + kurtosis-cdk-args: ${{ needs.read-test-args.outputs.test-fork11-rollup-e2e-args }} + + check-fork11-rollup-e2e-result: + name: Check E2E results + permissions: + id-token: write + contents: write + needs: + - test-fork11-rollup-e2e + if: always() + runs-on: ubuntu-latest + steps: + - run: exit 1 + if: ${{ contains(fromJSON('["failure", "cancelled"]'), needs.test-fork11-rollup-e2e.result) }} + + test-fork12-cdk-validium-e2e: + name: E2E test + needs: + - build-cdk-image + - read-test-args + uses: agglayer/e2e/.github/workflows/cdk-e2e.yml@41dd4252fec7e16d6b6199652a182c47b40b02d6 + secrets: inherit + with: + kurtosis-cdk-ref: 651696273abfaf19eae8233a3863f5e93091c087 + agglayer-e2e-ref: 41dd4252fec7e16d6b6199652a182c47b40b02d6 + test-name: test-fork12-cdk-validium-e2e + kurtosis-cdk-args: ${{ needs.read-test-args.outputs.test-fork12-cdk-validium-e2e-args }} + + check-fork12-cdk-validium-e2e-result: + name: Check E2E results + permissions: + id-token: write + contents: write + needs: + - test-fork12-cdk-validium-e2e + if: always() + runs-on: ubuntu-latest + steps: + - run: exit 1 + if: ${{ contains(fromJSON('["failure", "cancelled"]'), needs.test-fork12-cdk-validium-e2e.result) }} + + test-fork12-rollup-e2e: + name: E2E test + needs: + - build-cdk-image + - read-test-args + uses: agglayer/e2e/.github/workflows/cdk-e2e.yml@41dd4252fec7e16d6b6199652a182c47b40b02d6 + secrets: inherit + with: + kurtosis-cdk-ref: 651696273abfaf19eae8233a3863f5e93091c087 + agglayer-e2e-ref: 41dd4252fec7e16d6b6199652a182c47b40b02d6 + test-name: test-fork12-rollup-e2e + kurtosis-cdk-args: ${{ needs.read-test-args.outputs.test-fork12-rollup-e2e-args }} + + check-fork12-rollup-e2e-result: + name: Check E2E results + needs: + - test-fork12-rollup-e2e + if: always() + runs-on: ubuntu-latest + steps: + - run: exit 1 + if: ${{ contains(fromJSON('["failure", "cancelled"]'), needs.test-fork12-rollup-e2e.result) }} diff --git a/Makefile b/Makefile index 1a7d76c24..055443259 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ build-go: .PHONY: build-docker build-docker: ## Builds a docker image with the cdk binary - docker build -t cdk -f ./Dockerfile . + docker build -t cdk:local -f ./Dockerfile . .PHONY: build-docker-nc build-docker-nc: ## Builds a docker image with the cdk binary - but without build cache diff --git a/test/bats/access-list-e2e.bats b/test/bats/access-list-e2e.bats deleted file mode 100644 index bf8c7533e..000000000 --- a/test/bats/access-list-e2e.bats +++ /dev/null @@ -1,119 +0,0 @@ -setup() { - load 'helpers/common-setup' - load 'helpers/common' - - _common_setup - - readonly erigon_sequencer_node=${KURTOSIS_ERIGON_SEQUENCER:-cdk-erigon-sequencer-001} - readonly kurtosis_sequencer_wrapper=${KURTOSIS_SEQUENCER_WRAPPER:-"kurtosis service exec $enclave $erigon_sequencer_node"} - readonly key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} - readonly receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"} - readonly data_dir=${ACL_DATA_DIR:-"/home/erigon/data/dynamic-kurtosis-sequencer/txpool/acls"} -} - -teardown() { - run set_acl_mode "disabled" -} - -# Helper function to add address to acl dynamically -add_to_access_list() { - local acl_type="$1" - local policy="$2" - local sender=$(cast wallet address "$key") - - run $kurtosis_sequencer_wrapper "acl add --datadir $data_dir --address $sender --type $acl_type --policy $policy" -} - -# Helper function to set the acl mode command dynamically -set_acl_mode() { - local mode="$1" - - run $kurtosis_sequencer_wrapper "acl mode --datadir $data_dir --mode $mode" -} - -@test "Test Block List - Sending regular transaction when address not in block list" { - local value="10ether" - run set_acl_mode "blocklist" - run send_tx $l2_rpc_url $key $receiver $value - - assert_success - assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" -} - -@test "Test Block List - Sending contracts deploy transaction when address not in block list" { - local contract_artifact="./contracts/erc20mock/ERC20Mock.json" - run set_acl_mode "blocklist" - run deploy_contract $l2_rpc_url $key $contract_artifact - - assert_success - - contract_addr=$(echo "$output" | tail -n 1) - assert_output --regexp "0x[a-fA-F0-9]{40}" -} - -@test "Test Block List - Sending regular transaction when address is in block list" { - local value="10ether" - - run set_acl_mode "blocklist" - run add_to_access_list "blocklist" "sendTx" - - run send_tx $l2_rpc_url $key $receiver $value - - assert_failure - assert_output --partial "sender disallowed to send tx by ACL policy" -} - -@test "Test Block List - Sending contracts deploy transaction when address is in block list" { - local contract_artifact="./contracts/erc20mock/ERC20Mock.json" - - run set_acl_mode "blocklist" - run add_to_access_list "blocklist" "deploy" - run deploy_contract $l2_rpc_url $key $contract_artifact - - assert_failure - assert_output --partial "sender disallowed to deploy contract by ACL policy" -} - -@test "Test Allow List - Sending regular transaction when address not in allow list" { - local value="10ether" - - run set_acl_mode "allowlist" - run send_tx $l2_rpc_url $key $receiver $value - - assert_failure - assert_output --partial "sender disallowed to send tx by ACL policy" -} - -@test "Test Allow List - Sending contracts deploy transaction when address not in allow list" { - local contract_artifact="./contracts/erc20mock/ERC20Mock.json" - - run set_acl_mode "allowlist" - run deploy_contract $l2_rpc_url $key $contract_artifact - - assert_failure - assert_output --partial "sender disallowed to deploy contract by ACL policy" -} - -@test "Test Allow List - Sending regular transaction when address is in allow list" { - local value="10ether" - - run set_acl_mode "allowlist" - run add_to_access_list "allowlist" "sendTx" - run send_tx $l2_rpc_url $key $receiver $value - - assert_success - assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" -} - -@test "Test Allow List - Sending contracts deploy transaction when address is in allow list" { - local contract_artifact="./contracts/erc20mock/ERC20Mock.json" - - run set_acl_mode "allowlist" - run add_to_access_list "allowlist" "deploy" - run deploy_contract $l2_rpc_url $key $contract_artifact - - assert_success - - contract_addr=$(echo "$output" | tail -n 1) - assert_output --regexp "0x[a-fA-F0-9]{40}" -} diff --git a/test/bats/basic-e2e.bats b/test/bats/basic-e2e.bats deleted file mode 100644 index 0fbb7f40b..000000000 --- a/test/bats/basic-e2e.bats +++ /dev/null @@ -1,196 +0,0 @@ -setup() { - load 'helpers/common-setup' - load 'helpers/common' - - _common_setup - - readonly sender_private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} - readonly receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"} -} - -@test "Send EOA transaction" { - local sender_addr=$(cast wallet address --private-key "$sender_private_key") - local initial_nonce=$(cast nonce "$sender_addr" --rpc-url "$l2_rpc_url") || { - echo "Failed to retrieve nonce for sender: $sender_addr using RPC URL: $l2_rpc_url" - return 1 - } - local value="10ether" - - # case 1: Transaction successful sender has sufficient balance - run send_tx "$l2_rpc_url" "$sender_private_key" "$receiver" "$value" - assert_success - assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" - - # case 2: Transaction rejected as sender attempts to transfer more than it has in its wallet. - # Transaction will fail pre-validation check on the node and will be dropped subsequently from the pool - # without recording it on the chain and hence nonce will not change - local sender_balance=$(cast balance "$sender_addr" --ether --rpc-url "$l2_rpc_url") || { - echo "Failed to retrieve balance for sender: $sender_addr using RPC URL: $l2_rpc_url" - return 1 - } - local excessive_value=$(echo "$sender_balance + 1" | bc)"ether" - run send_tx "$l2_rpc_url" "$sender_private_key" "$receiver" "$excessive_value" - assert_failure - - # Check whether the sender's nonce was updated correctly - local final_nonce=$(cast nonce "$sender_addr" --rpc-url "$l2_rpc_url") || { - echo "Failed to retrieve nonce for sender: $sender_addr using RPC URL: $l2_rpc_url" - return 1 - } - assert_equal "$final_nonce" "$(echo "$initial_nonce + 1" | bc)" -} - -@test "Test ERC20Mock contract" { - local contract_artifact="./contracts/erc20mock/ERC20Mock.json" - wallet_A_output=$(cast wallet new) - address_A=$(echo "$wallet_A_output" | grep "Address" | awk '{print $2}') - address_A_private_key=$(echo "$wallet_A_output" | grep "Private key" | awk '{print $3}') - address_B=$(cast wallet new | grep "Address" | awk '{print $2}') - - # Deploy ERC20Mock - run deploy_contract "$l2_rpc_url" "$sender_private_key" "$contract_artifact" - assert_success - contract_addr=$(echo "$output" | tail -n 1) - - # Mint ERC20 tokens - local amount="5" - - run send_tx "$l2_rpc_url" "$sender_private_key" "$contract_addr" "$mint_fn_sig" "$address_A" "$amount" - assert_success - assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" - - ## Case 2: Insufficient gas scenario => Transactions fails - # nonce would not increase since transaction fails at the node's pre-validation check - # Get bytecode from the contract artifact - local bytecode=$(jq -r .bytecode "$contract_artifact") - if [[ -z "$bytecode" || "$bytecode" == "null" ]]; then - echo "Error: Failed to read bytecode from $contract_artifact" - return 1 - fi - - # Estimate gas, gas price and gas cost - local gas_units=$(cast estimate --rpc-url "$l2_rpc_url" --create "$bytecode") - gas_units=$(echo "scale=0; $gas_units / 2" | bc) - local gas_price=$(cast gas-price --rpc-url "$l2_rpc_url") - local value=$(echo "$gas_units * $gas_price" | bc) - local value_ether=$(cast to-unit "$value" ether)"ether" - - # Transfer only half amount of tokens needed for contract deployment fees - cast_output=$(cast send --rpc-url "$l2_rpc_url" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1) - if [[ $? -ne 0 ]]; then - echo "Error: Failed to send transaction. Output:" - echo "$cast_output" - return 1 - fi - - # Fetch initial nonce for address_A - local address_A_initial_nonce=$(cast nonce "$address_A" --rpc-url "$l2_rpc_url") || return 1 - # Attempt to deploy contract with insufficient gas - run deploy_contract "$l2_rpc_url" "$address_A_private_key" "$contract_artifact" - assert_failure - - ## Case 3: Transaction should fail as address_A tries to transfer more tokens than it has - # nonce would not increase - # Transfer funds for gas fees to address_A - value_ether="4ether" - cast_output=$(cast send --rpc-url "$l2_rpc_url" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1) - if [[ $? -ne 0 ]]; then - echo "Error: Failed to send transaction. Output:" - echo "$cast_output" - return 1 - fi - - # Fetch balance of address_A to simulate excessive transfer - run query_contract "$l2_rpc_url" "$contract_addr" "$balance_of_fn_sig" "$address_A" - assert_success - local address_A_Balance=$(echo "$output" | tail -n 1) - address_A_Balance=$(echo "$address_A_Balance" | xargs) - - # Set excessive amount for transfer - local excessive_amount=$(echo "$address_A_Balance + 1" | bc) - - # Attempt transfer of excessive amount from address_A to address_B - local tranferFnSig="transfer(address,uint256)" - run send_tx "$l2_rpc_url" "$address_A_private_key" "$contract_addr" "$tranferFnSig" "$address_B" "$excessive_amount" - assert_failure - - # Verify balance of address_A after failed transaction - run query_contract "$l2_rpc_url" "$contract_addr" "$balance_of_fn_sig" "$address_A" - assert_success - address_A_BalanceAfterFailedTx=$(echo "$output" | tail -n 1) - address_A_BalanceAfterFailedTx=$(echo "$address_A_BalanceAfterFailedTx" | xargs) - - # Ensure balance is unchanged - assert_equal "$address_A_BalanceAfterFailedTx" "$address_A_Balance" - - # Verify balance of address_B is still zero - run query_contract "$l2_rpc_url" "$contract_addr" "$balance_of_fn_sig" "$address_B" - assert_success - local address_B_Balance=$(echo "$output" | tail -n 1) - address_B_Balance=$(echo "$address_B_Balance" | xargs) - - assert_equal "$address_B_Balance" "0" - - # Nonce should not increase - local address_A_final_nonce=$(cast nonce "$address_A" --rpc-url "$l2_rpc_url") || { - echo "Failed to retrieve nonce for sender: $address_A using RPC URL: $l2_rpc_url" - return 1 - } - assert_equal "$address_A_final_nonce" "$address_A_initial_nonce" -} - - -@test "Deploy and test UniswapV3 contract" { - # Generate new key pair - wallet_A_output=$(cast wallet new) - address_A=$(echo "$wallet_A_output" | grep "Address" | awk '{print $2}') - address_A_private_key=$(echo "$wallet_A_output" | grep "Private key" | awk '{print $3}') - - # Transfer funds for gas - local value_ether="50ether" - cast_output=$(cast send --rpc-url "$l2_rpc_url" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1) - if [[ $? -ne 0 ]]; then - echo "Error: Failed to send transaction. Output:" - echo "$cast_output" - return 1 - fi - - run polycli loadtest uniswapv3 --legacy -v 600 --rpc-url $l2_rpc_url --private-key $address_A_private_key - assert_success - - # Remove ANSI escape codes from the output - output=$(echo "$output" | sed -r "s/\x1B\[[0-9;]*[mGKH]//g") - - # Check if all required Uniswap contracts were deployed - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=WETH9" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapV3Factory" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapInterfaceMulticall" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=ProxyAdmin" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=TickLens" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NFTDescriptor" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NonfungibleTokenPositionDescriptor" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=TransparentUpgradeableProxy" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NonfungiblePositionManager" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=V3Migrator" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapV3Staker" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=QuoterV2" - assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=SwapRouter02" - - # Check if ERC20 tokens were minted - assert_output --regexp "Minted tokens amount=[0-9]+ recipient=0x[a-fA-F0-9]{40} token=SwapperA" - assert_output --regexp "Minted tokens amount=[0-9]+ recipient=0x[a-fA-F0-9]{40} token=SwapperB" - - # Check if liquidity pool was created and initialized - assert_output --regexp "Pool created and initialized fees=[0-9]+" - - # Check if liquidity was provided to the pool - assert_output --regexp "Liquidity provided to the pool liquidity=[0-9]+" - - # Check if transaction got executed successfully - assert_output --regexp "Starting main load test loop currentNonce=[0-9]+" - assert_output --regexp "Finished main load test loop lastNonce=[0-9]+ startNonce=[0-9]+" - assert_output --regexp "Got final block number currentNonce=[0-9]+ final block number=[0-9]+" - assert_output --regexp "Num errors numErrors=0" - assert_output --regexp "Finished" -} - diff --git a/test/bats/bridge-e2e.bats b/test/bats/bridge-e2e.bats deleted file mode 100644 index f031556c6..000000000 --- a/test/bats/bridge-e2e.bats +++ /dev/null @@ -1,203 +0,0 @@ -setup() { - load 'helpers/common-setup' - load 'helpers/common' - load 'helpers/lxly-bridge' - - _common_setup - - if [ -z "$L1_BRIDGE_ADDRESS" ]; then - local combined_json_file="/opt/zkevm/combined.json" - echo "L1_BRIDGE_ADDRESS env variable is not provided, resolving the bridge address from the Kurtosis CDK '$combined_json_file'" >&3 - - # Fetching the combined JSON output and filtering to get polygonZkEVMBridgeAddress - combined_json_output=$($contracts_service_wrapper "cat $combined_json_file") - if echo "$combined_json_output" | jq empty > /dev/null 2>&1; then - l1_bridge_address=$(echo "$combined_json_output" | jq -r .polygonZkEVMBridgeAddress) - l2_bridge_address=$(echo "$combined_json_output" | jq -r .polygonZkEVML2BridgeAddress) - else - l1_bridge_address=$(echo "$combined_json_output" | tail -n +2 | jq -r .polygonZkEVMBridgeAddress) - l2_bridge_address=$(echo "$combined_json_output" | tail -n +2 | jq -r .polygonZkEVML2BridgeAddress) - fi - L1_BRIDGE_ADDRESS=$l1_bridge_address - L2_BRIDGE_ADDRESS=$l2_bridge_address - fi - echo "L1 Bridge address=$L1_BRIDGE_ADDRESS" >&3 - echo "L2 Bridge address=$L2_BRIDGE_ADDRESS" >&3 - - readonly sender_private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} - readonly sender_addr="$(cast wallet address --private-key $sender_private_key)" - destination_net=${DESTINATION_NET:-"1"} - destination_addr=${DESTINATION_ADDRESS:-"0x0bb7AA0b4FdC2D2862c088424260e99ed6299148"} - ether_value=${ETHER_VALUE:-"0.0200000054"} - amount=$(cast to-wei $ether_value ether) - readonly native_token_addr=${NATIVE_TOKEN_ADDRESS:-"0x0000000000000000000000000000000000000000"} - if [[ -n "$GAS_TOKEN_ADDR" ]]; then - echo "Using provided GAS_TOKEN_ADDR: $GAS_TOKEN_ADDR" >&3 - gas_token_addr="$GAS_TOKEN_ADDR" - else - echo "GAS_TOKEN_ADDR not provided, retrieving from rollup parameters file." >&3 - readonly rollup_params_file=/opt/zkevm/create_rollup_parameters.json - rollup_params_output=$($contracts_service_wrapper "cat $rollup_params_file") - if echo "$rollup_params_output" | jq empty > /dev/null 2>&1; then - gas_token_addr=$(echo "$rollup_params_output" | jq -r .gasTokenAddress) - else - gas_token_addr=$(echo "$rollup_params_output" | tail -n +2 | jq -r .gasTokenAddress) - fi - fi - readonly is_forced=${IS_FORCED:-"true"} - readonly l1_bridge_addr=$L1_BRIDGE_ADDRESS - readonly l2_bridge_addr=$L2_BRIDGE_ADDRESS - readonly meta_bytes=${META_BYTES:-"0x"} - - readonly l1_rpc_url=${L1_ETH_RPC_URL:-"$(kurtosis port print $enclave el-1-geth-lighthouse rpc)"} - readonly bridge_api_url=${BRIDGE_API_URL:-"$(kurtosis port print $enclave zkevm-bridge-service-001 rpc)"} - - readonly dry_run=${DRY_RUN:-"false"} - readonly l1_rpc_network_id=$(cast call --rpc-url $l1_rpc_url $l1_bridge_addr 'networkID() (uint32)') - readonly l2_rpc_network_id=$(cast call --rpc-url $l2_rpc_url $l2_bridge_addr 'networkID() (uint32)') - gas_price=$(cast gas-price --rpc-url "$l2_rpc_url") - readonly weth_token_addr=$(cast call --rpc-url $l2_rpc_url $l2_bridge_addr 'WETHToken()' | cast parse-bytes32-address) -} - -# Helper function to run native gas token deposit to WETH -native_gas_token_deposit_to_WETH() { - local bridge_type="$1" - - echo "Bridge_type: $bridge_type" >&3 - - destination_addr=$sender_addr - local initial_receiver_balance=$(cast call --rpc-url "$l2_rpc_url" "$weth_token_addr" "$balance_of_fn_sig" "$destination_addr" | awk '{print $1}') - echo "Initial receiver balance of native token on L2 $initial_receiver_balance" >&3 - - echo "=== Running LxLy deposit $bridge_type on L1 to network: $l2_rpc_network_id native_token: $native_token_addr" >&3 - - destination_net=$l2_rpc_network_id - - if [[ $bridge_type == "bridgeMessage" ]]; then - run bridge_message "$native_token_addr" "$l1_rpc_url" "$l1_bridge_addr" - else - run bridge_asset "$native_token_addr" "$l1_rpc_url" "$l1_bridge_addr" - fi - assert_success - - echo "=== Claiming on L2..." >&3 - timeout="120" - claim_frequency="10" - run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" "$bridge_type" "$l2_bridge_addr" - assert_success - - run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value" - assert_success - - echo "=== $bridge_type L2 WETH: $weth_token_addr to L1 ETH" >&3 - destination_addr=$sender_addr - destination_net=0 - - if [[ $bridge_type == "bridgeMessage" ]]; then - run bridge_message "$weth_token_addr" "$l2_rpc_url" "$l2_bridge_addr" - else - run bridge_asset "$weth_token_addr" "$l2_rpc_url" "$l2_bridge_addr" - fi - assert_success - - echo "=== Claiming on L1..." >&3 - timeout="400" - claim_frequency="60" - run wait_for_claim "$timeout" "$claim_frequency" "$l1_rpc_url" "$bridge_type" "$l1_bridge_addr" - assert_success -} - -@test "Native gas token deposit to WETH - BridgeAsset" { - run native_gas_token_deposit_to_WETH "bridgeAsset" -} - -@test "Native gas token deposit to WETH - BridgeMessage" { - run native_gas_token_deposit_to_WETH "bridgeMessage" -} - -@test "Custom gas token deposit" { - echo "Gas token addr $gas_token_addr, L1 RPC: $l1_rpc_url" >&3 - - # Set receiver address and query for its initial native token balance on the L2 - receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"} - local initial_receiver_balance=$(cast balance "$receiver" --rpc-url "$l2_rpc_url") - echo "Initial receiver balance of native token on L2 $initial_receiver_balance" >&3 - - local l1_minter_balance=$(cast balance "0x8943545177806ED17B9F23F0a21ee5948eCaa776" --rpc-url "$l1_rpc_url") - echo "Initial minter balance on L1 $l1_minter_balance" >&3 - - # Query for initial sender balance - run query_contract "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$sender_addr" - assert_success - local gas_token_init_sender_balance=$(echo "$output" | tail -n 1 | awk '{print $1}') - echo "Initial sender balance $gas_token_init_sender_balance" of gas token on L1 >&3 - - # Mint gas token on L1 - local tokens_amount="0.1ether" - local wei_amount=$(cast --to-unit $tokens_amount wei) - local minter_key=${MINTER_KEY:-"bcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31"} - run mint_erc20_tokens "$l1_rpc_url" "$gas_token_addr" "$minter_key" "$sender_addr" "$tokens_amount" - assert_success - - # Assert that balance of gas token (on the L1) is correct - run query_contract "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$sender_addr" - assert_success - local gas_token_final_sender_balance=$(echo "$output" | - tail -n 1 | - awk '{print $1}') - local expected_balance=$(echo "$gas_token_init_sender_balance + $wei_amount" | - bc | - awk '{print $1}') - - echo "Sender balance ($sender_addr) (gas token L1): $gas_token_final_sender_balance" >&3 - assert_equal "$gas_token_final_sender_balance" "$expected_balance" - - # Send approve transaction to the gas token on L1 - deposit_ether_value="0.1ether" - run send_tx "$l1_rpc_url" "$sender_private_key" "$gas_token_addr" "$approve_fn_sig" "$l1_bridge_addr" "$deposit_ether_value" - assert_success - assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" - - # Deposit - destination_addr=$receiver - destination_net=$l2_rpc_network_id - amount=$wei_amount - run bridge_asset "$gas_token_addr" "$l1_rpc_url" "$l1_bridge_addr" - assert_success - - # Claim deposits (settle them on the L2) - timeout="120" - claim_frequency="10" - run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" "bridgeAsset" "$l2_bridge_addr" - assert_success - - # Validate that the native token of receiver on L2 has increased by the bridge tokens amount - run verify_balance "$l2_rpc_url" "$native_token_addr" "$receiver" "$initial_receiver_balance" "$tokens_amount" - assert_success -} - -@test "Custom gas token withdrawal" { - echo "Running LxLy withdrawal" >&3 - echo "Gas token addr $gas_token_addr, L1 RPC: $l1_rpc_url" >&3 - - local initial_receiver_balance=$(cast call --rpc-url "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$destination_addr" | awk '{print $1}') - echo "Receiver balance of gas token on L1 $initial_receiver_balance" >&3 - - destination_net=$l1_rpc_network_id - run bridge_asset "$native_token_addr" "$l2_rpc_url" "$l2_bridge_addr" - assert_success - - # Claim withdrawals (settle them on the L1) - timeout="720" - claim_frequency="10" - destination_net=$l1_rpc_network_id - run wait_for_claim "$timeout" "$claim_frequency" "$l1_rpc_url" "bridgeAsset" "$l1_bridge_addr" - assert_success - - # Validate that the token of receiver on L1 has increased by the bridge tokens amount - run verify_balance "$l1_rpc_url" "$gas_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value" - if [ $status -eq 0 ]; then - break - fi - assert_success -} diff --git a/test/bats/e2e.bats b/test/bats/e2e.bats deleted file mode 100644 index e53bba1fb..000000000 --- a/test/bats/e2e.bats +++ /dev/null @@ -1,11 +0,0 @@ -setup() { - load 'helpers/common-setup' - - _common_setup -} - -@test "Verify batches" { - echo "Waiting 10 minutes to get some verified batch...." - run $PROJECT_ROOT/scripts/batch_verification_monitor.sh 0 600 - assert_success -} diff --git a/test/bats/helpers/common-setup.bash b/test/bats/helpers/common-setup.bash deleted file mode 100644 index 5f53cbf83..000000000 --- a/test/bats/helpers/common-setup.bash +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -_common_setup() { - bats_load_library 'bats-support' - bats_load_library 'bats-assert' - - # get the containing directory of this file - # use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0, - # as those will point to the bats executable's location or the preprocessed file respectively - PROJECT_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." >/dev/null 2>&1 && pwd)" - # make executables in src/ visible to PATH - PATH="$PROJECT_ROOT/src:$PATH" - - # ERC20 contracts function signatures - readonly mint_fn_sig="function mint(address,uint256)" - readonly balance_of_fn_sig="function balanceOf(address) (uint256)" - readonly approve_fn_sig="function approve(address,uint256)" - - - # Kurtosis enclave and service identifiers - readonly enclave=${KURTOSIS_ENCLAVE:-cdk} - readonly contracts_container=${KURTOSIS_CONTRACTS:-contracts-001} - readonly contracts_service_wrapper=${KURTOSIS_CONTRACTS_WRAPPER:-"kurtosis service exec $enclave $contracts_container"} - readonly erigon_rpc_node=${KURTOSIS_ERIGON_RPC:-cdk-erigon-rpc-001} - readonly l2_rpc_url=${L2_ETH_RPC_URL:-"$(kurtosis port print $enclave $erigon_rpc_node rpc)"} -} diff --git a/test/bats/helpers/common.bash b/test/bats/helpers/common.bash deleted file mode 100644 index fa56ee0bd..000000000 --- a/test/bats/helpers/common.bash +++ /dev/null @@ -1,377 +0,0 @@ -#!/usr/bin/env bash - -function deploy_contract() { - local rpc_url="$1" - local private_key="$2" - local contract_artifact="$3" - - # Check if rpc_url is available - if [[ -z "$rpc_url" ]]; then - echo "Error: rpc_url parameter is not set." - return 1 - fi - - if [[ ! -f "$contract_artifact" ]]; then - echo "Error: Contract artifact '$contract_artifact' does not exist." - return 1 - fi - - # Get the sender address - local sender=$(cast wallet address "$private_key") - if [[ $? -ne 0 ]]; then - echo "Error: Failed to retrieve sender address." - return 1 - fi - - echo "Attempting to deploy contract artifact '$contract_artifact' to $rpc_url (sender: $sender)" >&3 - - # Get bytecode from the contract artifact - local bytecode=$(jq -r .bytecode "$contract_artifact") - if [[ -z "$bytecode" || "$bytecode" == "null" ]]; then - echo "Error: Failed to read bytecode from $contract_artifact" - return 1 - fi - - # Send the transaction and capture the output - gas_price=$(cast gas-price --rpc-url "$rpc_url") - local comp_gas_price=$(bc -l <<< "$gas_price * 1.5" | sed 's/\..*//') - if [[ $? -ne 0 ]]; then - echo "Failed to calculate gas price" >&3 - exit 1 - fi - local cast_output=$(cast send --rpc-url "$rpc_url" \ - --private-key "$private_key" \ - --gas-price $comp_gas_price \ - --legacy \ - --create "$bytecode" \ - 2>&1) - - # Check if cast send was successful - if [[ $? -ne 0 ]]; then - echo "Error: Failed to send transaction." - echo "$cast_output" - return 1 - fi - - echo "Deploy contract output:" >&3 - echo "$cast_output" >&3 - - # Extract the contract address from the output - local deployed_contract_address=$(echo "$cast_output" | grep 'contractAddress' | sed 's/contractAddress\s\+//') - echo "Deployed contract address: $deployed_contract_address" >&3 - - if [[ -z "$deployed_contract_address" ]]; then - echo "Error: Failed to extract deployed contract address" - echo "$cast_output" - return 1 - fi - - if [[ ! "$deployed_contract_address" =~ ^0x[a-fA-F0-9]{40}$ ]]; then - echo "Error: Invalid contract address $deployed_contract_address" - return 1 - fi - - # Print contract address for return - echo "$deployed_contract_address" - - return 0 -} - -function send_tx() { - # Check if at least 4 arguments are provided - if [[ $# -lt 4 ]]; then - echo "Usage: send_tx [ ...]" - return 1 - fi - - local rpc_url="$1" # RPC URL - local private_key="$2" # Sender private key - local receiver_addr="$3" # Receiver address - local value_or_function_sig="$4" # Value or function signature - - # Error handling: Ensure the receiver is a valid Ethereum address - if [[ ! "$receiver_addr" =~ ^0x[a-fA-F0-9]{40}$ ]]; then - echo "Error: Invalid receiver address '$receiver_addr'." - return 1 - fi - - shift 4 # Shift the first 4 arguments (rpc_url, private_key, receiver_addr, value_or_function_sig) - local params=("$@") # Collect all remaining arguments as function parameters - - # Get sender address from private key - local sender - sender=$(cast wallet address "$private_key") || { - echo "Error: Failed to extract the sender address." - return 1 - } - - # Check if the value_or_function_sig is a numeric value (Ether to be transferred) - if [[ "$value_or_function_sig" =~ ^[0-9]+(\.[0-9]+)?(ether)?$ ]]; then - # Case: Ether transfer (EOA transaction) - # Get initial ether balances of sender and receiver - local sender_addr=$(cast wallet address --private-key "$private_key") - local sender_initial_balance receiver_initial_balance - sender_initial_balance=$(cast balance "$sender_addr" --ether --rpc-url "$rpc_url") || return 1 - receiver_initial_balance=$(cast balance "$receiver_addr" --ether --rpc-url "$rpc_url") || return 1 - - send_eoa_transaction "$private_key" "$receiver_addr" "$value_or_function_sig" "$sender_addr" "$sender_initial_balance" "$receiver_initial_balance" - else - # Case: Smart contract interaction (contract interaction with function signature and parameters) - send_smart_contract_transaction "$private_key" "$receiver_addr" "$value_or_function_sig" "${params[@]}" - fi -} - -function send_eoa_transaction() { - local private_key="$1" - local receiver_addr="$2" - local value="$3" - local sender="$4" - local sender_initial_balance="$5" - local receiver_initial_balance="$6" - - echo "Sending EOA transaction (from: $sender, rpc url: $rpc_url) to: $receiver_addr with value: $value" >&3 - - # Send transaction via cast - local cast_output tx_hash - gas_price=$(cast gas-price --rpc-url "$rpc_url") - local comp_gas_price=$(bc -l <<< "$gas_price * 1.5" | sed 's/\..*//') - if [[ $? -ne 0 ]]; then - echo "Failed to calculate gas price" >&3 - exit 1 - fi - echo "cast send --gas-price $comp_gas_price --rpc-url $rpc_url --private-key $private_key $receiver_addr --value $value --legacy" >&3 - cast_output=$(cast send --gas-price $comp_gas_price --rpc-url "$rpc_url" --private-key "$private_key" "$receiver_addr" --value "$value" --legacy 2>&1) - if [[ $? -ne 0 ]]; then - echo "Error: Failed to send transaction. Output:" - echo "$cast_output" - return 1 - fi - - tx_hash=$(extract_tx_hash "$cast_output") - [[ -z "$tx_hash" ]] && { - echo "Error: Failed to extract transaction hash." - return 1 - } - - check_balances "$sender" "$receiver_addr" "$value" "$tx_hash" "$sender_initial_balance" "$receiver_initial_balance" - if [[ $? -ne 0 ]]; then - echo "Error: Balance not updated correctly." - return 1 - fi - - echo "Transaction successful (transaction hash: $tx_hash)" -} - -function send_smart_contract_transaction() { - local private_key="$1" - local receiver_addr="$2" - local function_sig="$3" - shift 3 - local params=("$@") - - echo "Sending smart contract transaction to $receiver_addr with function signature: '$function_sig' and params: ${params[*]}" >&3 - - # Send the smart contract interaction using cast - local cast_output tx_hash - gas_price=$(cast gas-price --rpc-url "$rpc_url") - local comp_gas_price=$(bc -l <<< "$gas_price * 1.5" | sed 's/\..*//') - if [[ $? -ne 0 ]]; then - echo "Failed to calculate gas price" >&3 - exit 1 - fi - cast_output=$(cast send "$receiver_addr" --rpc-url "$rpc_url" --private-key "$private_key" --gas-price $comp_gas_price --legacy "$function_sig" "${params[@]}" 2>&1) - if [[ $? -ne 0 ]]; then - echo "Error: Failed to send transaction. Output:" - echo "$cast_output" - return 1 - fi - - tx_hash=$(extract_tx_hash "$cast_output") - [[ -z "$tx_hash" ]] && { - echo "Error: Failed to extract transaction hash." - return 1 - } - - echo "Transaction successful (transaction hash: $tx_hash)" -} - -function extract_tx_hash() { - local cast_output="$1" - echo "$cast_output" | grep 'transactionHash' | awk '{print $2}' | tail -n 1 -} - -function query_contract() { - local rpc_url="$1" # RPC URL - local addr="$2" # Contract address - local funcSignature="$3" # Function signature - shift 3 # Shift past the first 3 arguments - local params=("$@") # Collect remaining arguments as parameters array - - echo "Querying state of $addr account (RPC URL: $rpc_url) with function signature: '$funcSignature' and params: ${params[*]}" >&3 - - # Check if rpc url is available - if [[ -z "$rpc_url" ]]; then - echo "Error: rpc_url parameter is not provided." - return 1 - fi - - # Check if the contract address is valid - if [[ ! "$addr" =~ ^0x[a-fA-F0-9]{40}$ ]]; then - echo "Error: Invalid contract address '$addr'." - return 1 - fi - - # Call the contract using `cast call` - local result - result=$(cast call --rpc-url "$rpc_url" "$addr" "$funcSignature" "${params[@]}" 2>&1) - - # Check if the call was successful - if [[ $? -ne 0 ]]; then - echo "Error: Failed to query contract." - echo "$result" - return 1 - fi - - # Return the result (contract query response) - echo "$result" - - return 0 -} - -function check_balances() { - local sender="$1" - local receiver="$2" - local amount="$3" - local tx_hash="$4" - local sender_initial_balance="$5" - local receiver_initial_balance="$6" - - # Ethereum address regex: 0x followed by 40 hexadecimal characters - if [[ ! "$sender" =~ ^0x[a-fA-F0-9]{40}$ ]]; then - echo "Error: Invalid sender address '$sender'." - return 1 - fi - - if [[ ! "$receiver" =~ ^0x[a-fA-F0-9]{40}$ ]]; then - echo "Error: Invalid receiver address '$receiver'." - return 1 - fi - - # Transaction hash regex: 0x followed by 64 hexadecimal characters - if [[ ! "$tx_hash" =~ ^0x[a-fA-F0-9]{64}$ ]]; then - echo "Error: Invalid transaction hash: $tx_hash". - return 1 - fi - - local sender_final_balance=$(cast balance "$sender" --ether --rpc-url "$rpc_url") || return 1 - local tx_output=$(cast tx "$tx_hash" --rpc-url "$rpc_url") - local gas_used=$(tx_output | grep '^gas ' | awk '{print $2}') - local gas_price=$(tx_output | grep '^gasPrice' | awk '{print $2}') - local gas_fee=$(echo "$gas_used * $gas_price" | bc) - local gas_fee_in_ether=$(cast to-unit "$gas_fee" ether) - - local sender_balance_change=$(echo "$sender_initial_balance - $sender_final_balance" | bc) - echo "Sender balance changed by: '$sender_balance_change' wei" - echo "Gas fee paid: '$gas_fee_in_ether' ether" - - local receiver_final_balance=$(cast balance "$receiver" --ether --rpc-url "$rpc_url") || return 1 - local receiver_balance_change=$(echo "$receiver_final_balance - $receiver_initial_balance" | bc) - echo "Receiver balance changed by: '$receiver_balance_change' wei" - - # Trim 'ether' suffix from amount to get the numeric part - local value_in_ether=$(echo "$amount" | sed 's/ether$//') - - if ! echo "$receiver_balance_change == $value_in_ether" | bc -l; then - echo "Error: receiver balance updated incorrectly. Expected: $value_in_ether, Actual: $receiver_balance_change" - return 1 - fi - - # Calculate expected sender balance change - local expected_sender_change=$(echo "$value_in_ether + $gas_fee_in_ether" | bc) - if ! echo "$sender_balance_change == $expected_sender_change" | bc -l; then - echo "Error: sender balance updated incorrectly. Expected: $expected_sender_change, Actual: $sender_balance_change" - return 1 - fi -} - -function verify_balance() { - local rpc_url="$1" # RPC URL - local token_addr="$2" # gas token contract address - local account="$3" # account address - local initial_balance_wei="$4" # initial balance in Wei (decimal) - local ether_amount="$5" # amount to be added (in Ether, decimal) - - # Trim 'ether' from ether_amount if it exists - ether_amount=$(echo "$ether_amount" | sed 's/ether//') - local amount_wei=$(cast --to-wei "$ether_amount") - - # Get final balance in wei (after the operation) - local final_balance_wei - if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then - final_balance_wei=$(cast balance "$account" --rpc-url "$rpc_url" | awk '{print $1}') - else - final_balance_wei=$(cast call --rpc-url "$rpc_url" "$token_addr" "$balance_of_fn_sig" "$destination_addr" | awk '{print $1}') - fi - echo "Final balance of $account in $rpc_url: $final_balance_wei wei" >&3 - - # Calculate expected final balance (initial_balance + amount) - local expected_final_balance_wei=$(echo "$initial_balance_wei + $amount_wei" | bc) - - # Check if final_balance matches the expected final balance - if [ "$(echo "$final_balance_wei == $expected_final_balance_wei" | bc)" -eq 1 ]; then - echo "✅ Balance verification successful: final balance is correct." - else - echo "❌ Balance verification failed: expected $expected_final_balance_wei but got $final_balance_wei." >&3 - exit 1 - fi -} - -function mint_erc20_tokens() { - local rpc_url="$1" # The L1 RPC URL - local erc20_token_addr="$2" # The gas token contract address - local minter_private_key="$3" # The minter private key - local receiver="$4" # The receiver address (for minted tokens) - local tokens_amount="$5" # The amount of tokens to transfer (e.g., "0.1ether") - - # Query the erc20 token balance of the sender - run query_contract "$rpc_url" "$erc20_token_addr" "$balance_of_fn_sig" "$sender_addr" - assert_success - local erc20_token_balance=$(echo "$output" | tail -n 1) - - # Log the account's current gas token balance - echo "Initial account balance: $erc20_token_balance wei" >&3 - - # Convert tokens_amount to Wei for comparison - local wei_amount=$(cast --to-unit "$tokens_amount" wei) - - # Mint the required tokens by sending a transaction - run send_tx "$rpc_url" "$minter_private_key" "$erc20_token_addr" "$mint_fn_sig" "$receiver" "$tokens_amount" - assert_success -} - -function run_with_timeout(){ - local name="$1" - local run_frequency=$2 - local timeout=$3 - shift 3 - local start_time=$(date +%s) - local end_time=$((start_time + timeout)) - while true; do - local current_time=$(date +%s) - if ((current_time > end_time)); then - echo "....[$(date '+%Y-%m-%d %H:%M:%S')] ❌ Exiting [$name]... Timeout reached!" >&3 - exit 1 - fi - echo "....[$(date '+%Y-%m-%d %H:%M:%S')] ⏳Running [$name] ..." >&3 - echo "executing: $*" - run $* - echo "output: $output" - echo "result: $status" - if [ $status -eq 0 ]; then - echo "....[$(date '+%Y-%m-%d %H:%M:%S')] ✅ successful [$name] " >&3 - break - fi - echo "....[$(date '+%Y-%m-%d %H:%M:%S')] ⏳ Sleep [$name] time: $run_frequency" >&3 - sleep "$run_frequency" - done -} \ No newline at end of file diff --git a/test/bats/helpers/lxly-bridge.bash b/test/bats/helpers/lxly-bridge.bash deleted file mode 100644 index 83317a988..000000000 --- a/test/bats/helpers/lxly-bridge.bash +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env bash -# Error code reference https://hackmd.io/WwahVBZERJKdfK3BbKxzQQ -function bridge_message() { - local token_addr="$1" - local rpc_url="$2" - local bridge_addr="$3" - local bridge_sig='bridgeMessage(uint32,address,bool,bytes)' - - if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then - echo "The ETH balance for sender "$sender_addr":" >&3 - cast balance -e --rpc-url $rpc_url $sender_addr >&3 - else - echo "The "$token_addr" token balance for sender "$sender_addr":" >&3 - echo "cast call --rpc-url $rpc_url $token_addr \"$balance_of_fn_sig\" $sender_addr" >&3 - balance_wei=$(cast call --rpc-url "$rpc_url" "$token_addr" "$balance_of_fn_sig" "$sender_addr" | awk '{print $1}') - echo "$(cast --from-wei "$balance_wei")" >&3 - fi - - echo "Attempting to deposit $amount [wei] using bridgeMessage to $destination_addr, token $token_addr (sender=$sender_addr, network id=$destination_net, rpc url=$rpc_url)" >&3 - - if [[ $dry_run == "true" ]]; then - cast calldata $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes - else - if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then - echo "cast send --legacy --private-key $sender_private_key --value $amount --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $is_forced $meta_bytes" - cast send --legacy --private-key $sender_private_key --value $amount --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $is_forced $meta_bytes - else - echo "cast send --legacy --private-key $sender_private_key --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $is_forced $meta_bytes" - cast send --legacy --private-key $sender_private_key --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $is_forced $meta_bytes - fi - fi -} - -# returns: -# - bridge_tx_hash -function bridge_asset() { - local token_addr="$1" - local rpc_url="$2" - local bridge_addr="$3" - local bridge_sig='bridgeAsset(uint32,address,uint256,address,bool,bytes)' - - if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then - echo "...The ETH balance for sender "$sender_addr":" $(cast balance -e --rpc-url $rpc_url $sender_addr) >&3 - else - echo "The "$token_addr" token balance for sender "$sender_addr":" >&3 - echo "cast call --rpc-url $rpc_url $token_addr \"$balance_of_fn_sig\" $sender_addr" - balance_wei=$(cast call --rpc-url "$rpc_url" "$token_addr" "$balance_of_fn_sig" "$sender_addr" | awk '{print $1}') - echo "$(cast --from-wei "$balance_wei")" >&3 - fi - - echo "....Attempting to deposit $amount [wei] using bridgeAsset to $destination_addr, token $token_addr (sender=$sender_addr, network id=$destination_net, rpc url=$rpc_url)" >&3 - - if [[ $dry_run == "true" ]]; then - cast calldata $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes - else - local tmp_response_file=$(mktemp) - if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then - echo "cast send --legacy --private-key $sender_private_key --value $amount --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes" - cast send --legacy --private-key $sender_private_key --value $amount --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes > $tmp_response_file - else - echo "cast send --legacy --private-key $sender_private_key --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes" - - cast send --legacy --private-key $sender_private_key --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes > $tmp_response_file - fi - export bridge_tx_hash=$(grep "^transactionHash" $tmp_response_file | cut -f 2- -d ' ' | sed 's/ //g') - echo "bridge_tx_hash=$bridge_tx_hash" - fi -} - -function claim() { - local destination_rpc_url="$1" - local bridge_type="$2" - local bridge_addr="$3" - local claim_sig="claimAsset(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)" - if [[ $bridge_type == "bridgeMessage" ]]; then - claim_sig="claimMessage(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)" - fi - - readonly bridge_deposit_file=$(mktemp) - readonly claimable_deposit_file=$(mktemp) - echo "Getting full list of deposits" >&3 - echo " curl -s \"$bridge_api_url/bridges/$destination_addr?limit=100&offset=0\"" >&3 - curl -s "$bridge_api_url/bridges/$destination_addr?limit=100&offset=0" | jq '.' | tee $bridge_deposit_file - - echo "Looking for claimable deposits" >&3 - jq '[.deposits[] | select(.ready_for_claim == true and .claim_tx_hash == "" and .dest_net == '$destination_net')]' $bridge_deposit_file | tee $claimable_deposit_file - readonly claimable_count=$(jq '. | length' $claimable_deposit_file) - echo "Found $claimable_count claimable deposits" >&3 - - if [[ $claimable_count == 0 ]]; then - echo "We have no claimable deposits at this time" >&3 - exit 1 - fi - - echo "We have $claimable_count claimable deposits on network $destination_net. Let's get this party started." >&3 - readonly current_deposit=$(mktemp) - readonly current_proof=$(mktemp) - local gas_price_factor=1 - while read deposit_idx; do - echo "Starting claim for tx index: "$deposit_idx >&3 - echo "Deposit info:" >&3 - jq --arg idx $deposit_idx '.[($idx | tonumber)]' $claimable_deposit_file | tee $current_deposit >&3 - - curr_deposit_cnt=$(jq -r '.deposit_cnt' $current_deposit) - curr_network_id=$(jq -r '.network_id' $current_deposit) - curl -s "$bridge_api_url/merkle-proof?deposit_cnt=$curr_deposit_cnt&net_id=$curr_network_id" | jq '.' | tee $current_proof - - in_merkle_proof="$(jq -r -c '.proof.merkle_proof' $current_proof | tr -d '"')" - in_rollup_merkle_proof="$(jq -r -c '.proof.rollup_merkle_proof' $current_proof | tr -d '"')" - in_global_index=$(jq -r '.global_index' $current_deposit) - in_main_exit_root=$(jq -r '.proof.main_exit_root' $current_proof) - in_rollup_exit_root=$(jq -r '.proof.rollup_exit_root' $current_proof) - in_orig_net=$(jq -r '.orig_net' $current_deposit) - in_orig_addr=$(jq -r '.orig_addr' $current_deposit) - in_dest_net=$(jq -r '.dest_net' $current_deposit) - in_dest_addr=$(jq -r '.dest_addr' $current_deposit) - in_amount=$(jq -r '.amount' $current_deposit) - in_metadata=$(jq -r '.metadata' $current_deposit) - - if [[ $dry_run == "true" ]]; then - cast calldata $claim_sig "$in_merkle_proof" "$in_rollup_merkle_proof" $in_global_index $in_main_exit_root $in_rollup_exit_root $in_orig_net $in_orig_addr $in_dest_net $in_dest_addr $in_amount $in_metadata - else - local comp_gas_price=$(bc -l <<< "$gas_price * 1.5" | sed 's/\..*//') - if [[ $? -ne 0 ]]; then - echo "Failed to calculate gas price" >&3 - exit 1 - fi - - echo "cast send --legacy --gas-price $comp_gas_price --rpc-url $destination_rpc_url --private-key $sender_private_key $bridge_addr \"$claim_sig\" \"$in_merkle_proof\" \"$in_rollup_merkle_proof\" $in_global_index $in_main_exit_root $in_rollup_exit_root $in_orig_net $in_orig_addr $in_dest_net $in_dest_addr $in_amount $in_metadata" >&3 - cast send --legacy --gas-price $comp_gas_price --rpc-url $destination_rpc_url --private-key $sender_private_key $bridge_addr "$claim_sig" "$in_merkle_proof" "$in_rollup_merkle_proof" $in_global_index $in_main_exit_root $in_rollup_exit_root $in_orig_net $in_orig_addr $in_dest_net $in_dest_addr $in_amount $in_metadata - fi - - done < <(seq 0 $((claimable_count - 1))) -} - -function wait_for_claim() { - local timeout="$1" # timeout (in seconds) - local claim_frequency="$2" # claim frequency (in seconds) - local destination_rpc_url="$3" # destination rpc url - local bridge_type="$4" # bridgeAsset or bridgeMessage - local bridge_addr="$5" - local start_time=$(date +%s) - local end_time=$((start_time + timeout)) - - while true; do - local current_time=$(date +%s) - if ((current_time > end_time)); then - echo "[$(date '+%Y-%m-%d %H:%M:%S')] ❌ Exiting... Timeout reached!" - exit 1 - fi - - run claim $destination_rpc_url $bridge_type $bridge_addr - if [ $status -eq 0 ]; then - break - fi - - sleep "$claim_frequency" - done -} diff --git a/test/combinations/fork11-rollup.yml b/test/combinations/fork11-rollup.yml deleted file mode 100644 index e83ac5f01..000000000 --- a/test/combinations/fork11-rollup.yml +++ /dev/null @@ -1,9 +0,0 @@ -args: - zkevm_contracts_image: leovct/zkevm-contracts:v7.0.0-rc.2-fork.11-patch.1 - zkevm_prover_image: hermeznetwork/zkevm-prover:v7.0.4-hotfix.2-fork.11 - cdk_node_image: cdk - gas_token_enabled: true - gas_token_address: '' - data_availability_mode: rollup - sequencer_type: erigon - agglayer_image: ghcr.io/agglayer/agglayer:0.2.0-rc.19 diff --git a/test/combinations/fork12-cdk-validium.yml b/test/combinations/fork12-cdk-validium.yml deleted file mode 100644 index 58c212bd7..000000000 --- a/test/combinations/fork12-cdk-validium.yml +++ /dev/null @@ -1,9 +0,0 @@ -args: - zkevm_contracts_image: jhkimqd/zkevm-contracts:v10.0.0-rc.6-fork.12 - zkevm_prover_image: hermeznetwork/zkevm-prover:v8.0.0-RC16-fork.12 - zkevm_node_image: hermeznetwork/zkevm-node:v0.7.0-fork11 - cdk_node_image: cdk:latest - gas_token_enabled: true - gas_token_address: '' - data_availability_mode: cdk-validium - sequencer_type: erigon diff --git a/test/combinations/fork12-rollup.yml b/test/combinations/fork12-rollup.yml deleted file mode 100644 index 8d324507d..000000000 --- a/test/combinations/fork12-rollup.yml +++ /dev/null @@ -1,8 +0,0 @@ -args: - zkevm_contracts_image: jhkimqd/zkevm-contracts:v10.0.0-rc.6-fork.12 - zkevm_prover_image: hermeznetwork/zkevm-prover:v8.0.0-RC16-fork.12 - cdk_node_image: cdk:latest - gas_token_enabled: true - gas_token_address: '' - data_availability_mode: rollup - sequencer_type: erigon diff --git a/test/combinations/fork9-cdk-validium.yml b/test/combinations/fork9-cdk-validium.yml deleted file mode 100644 index 70f617a53..000000000 --- a/test/combinations/fork9-cdk-validium.yml +++ /dev/null @@ -1,11 +0,0 @@ -args: - zkevm_contracts_image: leovct/zkevm-contracts:v6.0.0-rc.1-fork.9-patch.1 - zkevm_prover_image: hermeznetwork/zkevm-prover:v6.0.8 - zkevm_node_image: hermeznetwork/zkevm-node:v0.7.3 - cdk_validium_node_image: ghcr.io/0xpolygon/cdk-validium-node:0.6.4-cdk.10 - agglayer_image: ghcr.io/agglayer/agglayer:0.2.0-rc.19 - cdk_node_image: cdk - gas_token_enabled: true - gas_token_address: '' - additional_services: - - pless_zkevm_node diff --git a/test/run-e2e.sh b/test/run-e2e.sh deleted file mode 100755 index 6f67301af..000000000 --- a/test/run-e2e.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -source $(dirname $0)/scripts/env.sh -source $(dirname $0)/scripts/shared.sh - -FORK=$1 -if [ -z $FORK ]; then - echo "Missing FORK: ['fork9', 'fork12']" - exit 1 -fi - -DATA_AVAILABILITY_MODE=$2 -if [ -z $DATA_AVAILABILITY_MODE ]; then - echo "Missing DATA_AVAILABILITY_MODE: ['rollup', 'cdk-validium']" - exit 1 -fi - -BASE_FOLDER=$(dirname $0) -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 - -kurtosis clean --all -override_cdk_node_config_file $DATA_AVAILABILITY_MODE - -KURTOSIS_CONFIG_FILE="combinations/$FORK-$DATA_AVAILABILITY_MODE.yml" -TEMP_CONFIG_FILE=$(mktemp --suffix ".yml") -echo "rendering $KURTOSIS_CONFIG_FILE to temp file $TEMP_CONFIG_FILE" -go run ../scripts/run_template.go $KURTOSIS_CONFIG_FILE > $TEMP_CONFIG_FILE -kurtosis run --enclave cdk --args-file "$TEMP_CONFIG_FILE" --image-download always $KURTOSIS_FOLDER -rm $TEMP_CONFIG_FILE \ No newline at end of file diff --git a/test/run-local-e2e.sh b/test/run-local-e2e.sh new file mode 100755 index 000000000..16b6b5549 --- /dev/null +++ b/test/run-local-e2e.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +set -euo pipefail + +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +log_info() { + echo -e "${GREEN}[INFO]${NC} $*" | tee -a "$LOG_FILE" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $*" | tee -a "$LOG_FILE" +} + +trap 'log_error "Script failed at line $LINENO"' ERR + +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi + +TEST_TYPE=$1 +KURTOSIS_FOLDER=$2 +E2E_FOLDER=$3 + +PROJECT_ROOT="$PWD" +ROOT_FOLDER="/tmp/cdk-e2e-run" +LOG_FOLDER="$ROOT_FOLDER/logs" +LOG_FILE="$LOG_FOLDER/run-local-e2e.log" + +rm -rf "$ROOT_FOLDER" +mkdir -p "$LOG_FOLDER" + +exec > >(tee -a "$LOG_FILE") 2>&1 + +log_info "Starting local E2E setup..." + +# Build cdk Docker Image if it doesn't exist +if [ "$(docker images -q cdk:local | wc -l)" -eq 0 ]; then + log_info "Building cdk:local docker image..." + pushd "$PROJECT_ROOT" > /dev/null + make build-docker + popd > /dev/null +else + log_info "Docker image cdk:local already exists." +fi + +log_info "Using provided Kurtosis CDK repo at: $KURTOSIS_FOLDER" + +pushd "$KURTOSIS_FOLDER" > /dev/null +log_info "Cleaning any existing Kurtosis enclaves..." +kurtosis clean --all + +ENCLAVE="cdk" + +# Start Kurtosis Enclave +log_info "Starting Kurtosis enclave" + +if [ "$TEST_TYPE" == "fork9-cdk-validium" ]; then + kurtosis run --enclave "$ENCLAVE" --args-file "$PROJECT_ROOT/.github/test_fork9_cdk_validium_e2e_args.json" . +elif [ "$TEST_TYPE" == "fork11-rollup" ]; then + kurtosis run --enclave "$ENCLAVE" --args-file "$PROJECT_ROOT/.github/test_fork11_rollup_e2e_args.json" . +elif [ "$TEST_TYPE" == "fork12-cdk-validium" ]; then + kurtosis run --enclave "$ENCLAVE" --args-file "$PROJECT_ROOT/.github/test_fork12_cdk_validium_e2e_args.json" . +elif [ "$TEST_TYPE" == "fork12-rollup" ]; then + kurtosis run --enclave "$ENCLAVE" --args-file "$PROJECT_ROOT/.github/test_fork12_rollup_e2e_args.json" . +else + log_error "Unknown test type: $TEST_TYPE" + exit 1 +fi + +log_info "$ENCLAVE enclave started successfully." +popd > /dev/null + +log_info "Using provided Agglayer E2E repo at: $E2E_FOLDER" + +pushd "$E2E_FOLDER" > /dev/null + +# Setup environment +log_info "Setting up e2e environment..." +set -a +source ./tests/.env +set +a + +export BATS_LIB_PATH="$PWD/core/helpers/lib" +export PROJECT_ROOT="$PWD" +export ENCLAVE="$ENCLAVE" +export DISABLE_L2_FUND="true" + +log_info "Running BATS E2E tests..." +bats ./tests/cdk + +popd > /dev/null +log_info "E2E tests executed. Logs saved to $LOG_FILE"