From 832a21a88f63ea7809ed3562480c3ca2b930ccc1 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Wed, 4 Dec 2024 15:57:18 +0530 Subject: [PATCH 1/3] wip --- test/Makefile | 3 +- test/bats/pp/bridge-ci-e2e.bats | 100 ++++++++++++++++++++++++++++++++ test/bats/pp/bridge-e2e.bats | 4 +- test/bats/pp/e2e-pp.bats | 2 +- 4 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 test/bats/pp/bridge-ci-e2e.bats diff --git a/test/Makefile b/test/Makefile index 05823e66..95abe966 100644 --- a/test/Makefile +++ b/test/Makefile @@ -101,7 +101,8 @@ test-e2e-fork12-rollup: stop .PHONY: test-e2e-fork12-pessimistic test-e2e-fork12-pessimistic: stop ./run-e2e.sh fork12 pessimistic - bats bats/pp/ + bats bats/pp/bridge-ci-e2e.bats + bats bats/pp/e2e-pp.bats .PHONY: stop stop: diff --git a/test/bats/pp/bridge-ci-e2e.bats b/test/bats/pp/bridge-ci-e2e.bats new file mode 100644 index 00000000..846a98db --- /dev/null +++ b/test/bats/pp/bridge-ci-e2e.bats @@ -0,0 +1,100 @@ +setup() { + load '../helpers/common-setup' + load '../helpers/common' + load '../helpers/lxly-bridge' + + _common_setup + + if [ -z "$BRIDGE_ADDRESS" ]; then + local combined_json_file="/opt/zkevm/combined.json" + echo "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" | tail -n +2) + bridge_default_address=$(echo "$combined_json_output" | jq -r .polygonZkEVMBridgeAddress) + BRIDGE_ADDRESS=$bridge_default_address + fi + echo "Bridge address=$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 + run bash -c "$contracts_service_wrapper 'cat $rollup_params_file' | tail -n +2 | jq -r '.gasTokenAddress'" + assert_success + assert_output --regexp "0x[a-fA-F0-9]{40}" + gas_token_addr=$output + fi + readonly is_forced=${IS_FORCED:-"true"} + readonly bridge_addr=$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 $bridge_addr 'networkID() (uint32)') + readonly l2_rpc_network_id=$(cast call --rpc-url $l2_rpc_url $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 $bridge_addr 'WETHToken()' | cast parse-bytes32-address) +} + +@test "Native Gas Token Deposit and Withdrawal Workflow" { + 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 first LxLy deposit on L1 to network: $l2_rpc_network_id native_token: $native_token_addr" >&3 + + destination_net=$l2_rpc_network_id + run bridge_asset "$native_token_addr" "$l1_rpc_url" + assert_success + + echo "=== Running first LxLy claim on L2" >&3 + timeout="120" + claim_frequency="10" + run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" + assert_success + + run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value" + assert_success + + echo "=== bridgeAsset L2 WETH: $weth_token_addr to L1 ETH" >&3 + destination_addr=$sender_addr + destination_net=0 + run bridge_asset "$weth_token_addr" "$l2_rpc_url" + assert_success + + echo "Waiting for one agglayer certificate to settle before the second transaction..." >&3 + settle_certificates_target=1 + agglayer_timeout=600 + run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh "$settle_certificates_target" "$agglayer_timeout" "$l2_rpc_network_id" + assert_success + + echo "=== Running second LxLy deposit on L1 to network: $l2_rpc_network_id native_token: $native_token_addr" >&3 + destination_net=1 + run bridge_asset "$native_token_addr" "$l1_rpc_url" + assert_success + + echo "=== Running second LxLy claim on L2" >&3 + run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" + assert_success + + run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value" + assert_success + + echo "=== bridgeAsset L2 WETH: $weth_token_addr to L1 ETH" >&3 + destination_addr=$sender_addr + destination_net=0 + run bridge_asset "$weth_token_addr" "$l2_rpc_url" + assert_success +} \ No newline at end of file diff --git a/test/bats/pp/bridge-e2e.bats b/test/bats/pp/bridge-e2e.bats index 313b5e41..00fabc4b 100644 --- a/test/bats/pp/bridge-e2e.bats +++ b/test/bats/pp/bridge-e2e.bats @@ -48,6 +48,7 @@ setup() { readonly weth_token_addr=$(cast call --rpc-url $l2_rpc_url $bridge_addr 'WETHToken()' | cast parse-bytes32-address) } +# This test is intended for local debugging, generating only a single certificate @test "Native gas token deposit to WETH" { 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}') @@ -73,5 +74,4 @@ setup() { destination_net=0 run bridge_asset "$weth_token_addr" "$l2_rpc_url" assert_success -} - +} \ No newline at end of file diff --git a/test/bats/pp/e2e-pp.bats b/test/bats/pp/e2e-pp.bats index 4ef831e7..54466cab 100644 --- a/test/bats/pp/e2e-pp.bats +++ b/test/bats/pp/e2e-pp.bats @@ -21,6 +21,6 @@ setup() { readonly bridge_addr=$BRIDGE_ADDRESS readonly l2_rpc_network_id=$(cast call --rpc-url $l2_rpc_url $bridge_addr 'networkID() (uint32)') - run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh 1 600 $l2_rpc_network_id + run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh 2 600 $l2_rpc_network_id assert_success } From 797e04867bd474831342e012f3a9ba5e830fece2 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Thu, 12 Dec 2024 14:52:12 +0530 Subject: [PATCH 2/3] addressed feedback --- .github/workflows/test-e2e.yml | 2 + test/Makefile | 3 +- test/bats/pp/bridge-ci-e2e.bats | 100 -------------------------------- test/bats/pp/bridge-e2e.bats | 43 +++++++++----- test/bats/pp/e2e-pp.bats | 6 +- 5 files changed, 34 insertions(+), 120 deletions(-) delete mode 100644 test/bats/pp/bridge-ci-e2e.bats diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index e164705c..e968c61a 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -95,6 +95,8 @@ jobs: KURTOSIS_FOLDER: ${{ github.workspace }}/kurtosis-cdk BATS_LIB_PATH: /usr/lib/ agglayer_prover_sp1_key: ${{ secrets.SP1_PRIVATE_KEY }} + TARGET_CERTIFICATE: 2 + DEPOSIT_COUNT: 2 - name: Dump enclave logs if: failure() diff --git a/test/Makefile b/test/Makefile index 95abe966..05823e66 100644 --- a/test/Makefile +++ b/test/Makefile @@ -101,8 +101,7 @@ test-e2e-fork12-rollup: stop .PHONY: test-e2e-fork12-pessimistic test-e2e-fork12-pessimistic: stop ./run-e2e.sh fork12 pessimistic - bats bats/pp/bridge-ci-e2e.bats - bats bats/pp/e2e-pp.bats + bats bats/pp/ .PHONY: stop stop: diff --git a/test/bats/pp/bridge-ci-e2e.bats b/test/bats/pp/bridge-ci-e2e.bats deleted file mode 100644 index 846a98db..00000000 --- a/test/bats/pp/bridge-ci-e2e.bats +++ /dev/null @@ -1,100 +0,0 @@ -setup() { - load '../helpers/common-setup' - load '../helpers/common' - load '../helpers/lxly-bridge' - - _common_setup - - if [ -z "$BRIDGE_ADDRESS" ]; then - local combined_json_file="/opt/zkevm/combined.json" - echo "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" | tail -n +2) - bridge_default_address=$(echo "$combined_json_output" | jq -r .polygonZkEVMBridgeAddress) - BRIDGE_ADDRESS=$bridge_default_address - fi - echo "Bridge address=$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 - run bash -c "$contracts_service_wrapper 'cat $rollup_params_file' | tail -n +2 | jq -r '.gasTokenAddress'" - assert_success - assert_output --regexp "0x[a-fA-F0-9]{40}" - gas_token_addr=$output - fi - readonly is_forced=${IS_FORCED:-"true"} - readonly bridge_addr=$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 $bridge_addr 'networkID() (uint32)') - readonly l2_rpc_network_id=$(cast call --rpc-url $l2_rpc_url $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 $bridge_addr 'WETHToken()' | cast parse-bytes32-address) -} - -@test "Native Gas Token Deposit and Withdrawal Workflow" { - 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 first LxLy deposit on L1 to network: $l2_rpc_network_id native_token: $native_token_addr" >&3 - - destination_net=$l2_rpc_network_id - run bridge_asset "$native_token_addr" "$l1_rpc_url" - assert_success - - echo "=== Running first LxLy claim on L2" >&3 - timeout="120" - claim_frequency="10" - run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" - assert_success - - run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value" - assert_success - - echo "=== bridgeAsset L2 WETH: $weth_token_addr to L1 ETH" >&3 - destination_addr=$sender_addr - destination_net=0 - run bridge_asset "$weth_token_addr" "$l2_rpc_url" - assert_success - - echo "Waiting for one agglayer certificate to settle before the second transaction..." >&3 - settle_certificates_target=1 - agglayer_timeout=600 - run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh "$settle_certificates_target" "$agglayer_timeout" "$l2_rpc_network_id" - assert_success - - echo "=== Running second LxLy deposit on L1 to network: $l2_rpc_network_id native_token: $native_token_addr" >&3 - destination_net=1 - run bridge_asset "$native_token_addr" "$l1_rpc_url" - assert_success - - echo "=== Running second LxLy claim on L2" >&3 - run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" - assert_success - - run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value" - assert_success - - echo "=== bridgeAsset L2 WETH: $weth_token_addr to L1 ETH" >&3 - destination_addr=$sender_addr - destination_net=0 - run bridge_asset "$weth_token_addr" "$l2_rpc_url" - assert_success -} \ No newline at end of file diff --git a/test/bats/pp/bridge-e2e.bats b/test/bats/pp/bridge-e2e.bats index 00fabc4b..d2e42671 100644 --- a/test/bats/pp/bridge-e2e.bats +++ b/test/bats/pp/bridge-e2e.bats @@ -16,6 +16,7 @@ setup() { fi echo "Bridge address=$BRIDGE_ADDRESS" >&3 + readonly deposit_count=${DEPOSIT_COUNT:-1} readonly sender_private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} readonly sender_addr="$(cast wallet address --private-key $sender_private_key)" destination_net=${DESTINATION_NET:-"1"} @@ -54,24 +55,34 @@ setup() { 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 on L1 to network: $l2_rpc_network_id native_token: $native_token_addr" >&3 + for i in $(seq 1 $deposit_count); do + echo "=== Running #$i LxLy deposit on L1 to network: $l2_rpc_network_id native_token: $native_token_addr" >&3 - destination_net=$l2_rpc_network_id - run bridge_asset "$native_token_addr" "$l1_rpc_url" - assert_success + destination_net=$l2_rpc_network_id + destination_net=1 + run bridge_asset "$native_token_addr" "$l1_rpc_url" + assert_success - echo "=== Running LxLy claim on L2" >&3 - timeout="120" - claim_frequency="10" - run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" - assert_success + echo "=== Running #$i LxLy claim on L2" >&3 + timeout="120" + claim_frequency="10" + run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" + assert_success - run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value" - assert_success + run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" \ + "$initial_receiver_balance" "$ether_value" + assert_success - echo "=== bridgeAsset L2 WETH: $weth_token_addr to L1 ETH" >&3 - destination_addr=$sender_addr - destination_net=0 - run bridge_asset "$weth_token_addr" "$l2_rpc_url" - assert_success + echo "=== bridgeAsset L2 WETH: $weth_token_addr to L1 ETH" >&3 + destination_addr=$sender_addr + destination_net=0 + run bridge_asset "$weth_token_addr" "$l2_rpc_url" + assert_success + + echo "Waiting for agglayer certificate to settle before sending another transaction..." >&3 + settle_certificates_target=1 + agglayer_timeout=600 + run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh "$settle_certificates_target" "$agglayer_timeout" "$l2_rpc_network_id" + assert_success + done } \ No newline at end of file diff --git a/test/bats/pp/e2e-pp.bats b/test/bats/pp/e2e-pp.bats index 54466cab..ddddb9df 100644 --- a/test/bats/pp/e2e-pp.bats +++ b/test/bats/pp/e2e-pp.bats @@ -3,6 +3,7 @@ setup() { _common_setup + local target_certificate=${TARGET_CERTIFICATE:-1} if [ -z "$BRIDGE_ADDRESS" ]; then local combined_json_file="/opt/zkevm/combined.json" echo "BRIDGE_ADDRESS env variable is not provided, resolving the bridge address from the Kurtosis CDK '$combined_json_file'" >&3 @@ -21,6 +22,7 @@ setup() { readonly bridge_addr=$BRIDGE_ADDRESS readonly l2_rpc_network_id=$(cast call --rpc-url $l2_rpc_url $bridge_addr 'networkID() (uint32)') - run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh 2 600 $l2_rpc_network_id + run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh \ + $target_certificate 600 $l2_rpc_network_id assert_success -} +} \ No newline at end of file From 91b49ba04e8aad5ab80ab49b361564d11f8a9d48 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Tue, 17 Dec 2024 18:23:12 +0530 Subject: [PATCH 3/3] fix --- test/bats/pp/bridge-e2e.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bats/pp/bridge-e2e.bats b/test/bats/pp/bridge-e2e.bats index 0c06a173..4000e97a 100644 --- a/test/bats/pp/bridge-e2e.bats +++ b/test/bats/pp/bridge-e2e.bats @@ -80,7 +80,7 @@ setup() { assert_success echo "Waiting for agglayer certificate to settle before sending another transaction..." >&3 - settle_certificates_target=1 + settle_certificates_target=$i agglayer_timeout=600 run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh "$settle_certificates_target" "$agglayer_timeout" "$l2_rpc_network_id" assert_success