From 8b57644f023f3fa7a73889bce927929787fb958c Mon Sep 17 00:00:00 2001 From: Victor Castell <0x@vcastellm.xyz> Date: Mon, 9 Sep 2024 18:25:46 +0000 Subject: [PATCH] tests: wip --- test/bridge-e2e.bats | 46 +++++++++----------- test/helpers/lxly-bridge-test.bash | 48 ++++++++++----------- test/scripts/kurtosis_prepare_params_yml.sh | 8 +--- 3 files changed, 45 insertions(+), 57 deletions(-) diff --git a/test/bridge-e2e.bats b/test/bridge-e2e.bats index 3c9c2937..184d7ec3 100644 --- a/test/bridge-e2e.bats +++ b/test/bridge-e2e.bats @@ -1,5 +1,5 @@ setup() { - bats_load_library 'bats-support' + bats_load_library 'bats-support' bats_load_library 'bats-assert' # get the containing directory of this file @@ -9,18 +9,26 @@ setup() { # make executables in src/ visible to PATH PATH="$DIR/../src:$PATH" - readonly skey=${RAW_PRIVATE_KEY:-"bc6a95c870cce28fe9686fdd70a3a595769e019bb396cd725bc16ec553f07c83"} - readonly destination_net=${DESTINATION_NET:-"1"} + $DIR/scripts/kurtosis_prepare_params_yml.sh ../kurtosis-cdk cdk-validium + + # Check if the genesis file is already downloaded + if [ ! -f "./tmp/cdk/genesis/genesis.json" ]; then + kurtosis files download cdk-v1 genesis ./tmp/cdk/genesis + fi + # Download the genesis file + readonly bridge_default_address=$(jq -r ".genesis[] | select(.contractName == \"PolygonZkEVMBridge proxy\") | .address" ./tmp/cdk/genesis/genesis.json) + + readonly skey=${RAW_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} + readonly destination_net=${DESTINATION_NET:-"0"} readonly destination_addr=${DESTINATION_ADDRESS:-"0x0bb7AA0b4FdC2D2862c088424260e99ed6299148"} readonly ether_value=${ETHER_VALUE:-"0.0200000054"} readonly token_addr=${TOKEN_ADDRESS:-"0x0000000000000000000000000000000000000000"} readonly is_forced=${IS_FORCED:-"true"} - readonly bridge_addr=${BRIDGE_ADDRESS:-"0x528e26b25a34a4A5d0dbDa1d57D318153d2ED582"} + readonly bridge_addr=${BRIDGE_ADDRESS:-$bridge_default_address} readonly meta_bytes=${META_BYTES:-"0x"} - readonly subcommand=${1:-"deposit"} - readonly rpc_url=${ETH_RPC_URL:-"https://rpc.cardona.zkevm-rpc.com"} - readonly bridge_api_url=${BRIDGE_API_URL:-"https://bridge-api-cdk-validium-cardona-03-zkevm.polygondev.tools"} + readonly rpc_url=${ETH_RPC_URL:-"$(kurtosis port print cdk-v1 cdk-erigon-node-001 http-rpc)"} + readonly bridge_api_url=${BRIDGE_API_URL:-"$(kurtosis port print cdk-v1 zkevm-bridge-service-001 rpc)"} readonly dry_run=${DRY_RUN:-"false"} readonly claim_sig="claimAsset(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)" @@ -29,33 +37,19 @@ setup() { readonly amount=$(cast to-wei $ether_value ether) readonly current_addr="$(cast wallet address --private-key $skey)" readonly rpc_network_id=$(cast call --rpc-url $rpc_url $bridge_addr 'networkID()(uint32)') - - - 2>&1 echo "Running LxLy " $subcommand - - 2>&1 echo "Checking the current network id: " - 2>&1 echo $rpc_network_id - - 2>&1 echo "The current private key has address: " - 2>&1 echo $current_addr - - if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then - 2>&1 echo "Checking the current ETH balance: " - 2>&1 cast balance -e --rpc-url $rpc_url $current_addr - else - 2>&1 echo "Checking the current token balance for token at $token_addr: " - 2>&1 cast call --rpc-url $rpc_url $token_addr 'balanceOf(address)(uint256)' $current_addr - fi } @test "Run deposit" { load 'helpers/lxly-bridge-test' + echo "Running LxLy deposit" >&3 run deposit - assert_output --partial 'foo' + assert_success + assert_output --partial 'transactionHash' } @test "Run claim" { load 'helpers/lxly-bridge-test' + echo "Running LxLy claim" run claim - assert_output --partial 'execution reverted' + assert_success } diff --git a/test/helpers/lxly-bridge-test.bash b/test/helpers/lxly-bridge-test.bash index 959153f4..34c9ed4d 100644 --- a/test/helpers/lxly-bridge-test.bash +++ b/test/helpers/lxly-bridge-test.bash @@ -1,19 +1,23 @@ #!/usr/bin/env bash # Error code reference https://hackmd.io/WwahVBZERJKdfK3BbKxzQQ function deposit () { - 2>&1 echo "Attempting to deposit $amount wei to net $destination_net for token $token_addr" + if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then + echo "Checking the current ETH balance: " >&3 + cast balance -e --rpc-url $rpc_url $current_addr >&3 + else + echo "Checking the current token balance for token at $token_addr: " >&3 + cast call --rpc-url $rpc_url $token_addr 'balanceOf(address)(uint256)' $current_addr >&3 + fi + + echo "Attempting to deposit $amount wei to net $destination_net for token $token_addr" >&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 - set -x cast send --legacy --private-key $skey --value $amount --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes - set +x else - set -x cast send --legacy --private-key $skey --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes - set +x fi fi } @@ -21,35 +25,33 @@ function deposit () { function claim() { readonly bridge_deposit_file=$(mktemp) readonly claimable_deposit_file=$(mktemp) - 2>&1 echo "Getting full list of deposits" - set -x - 2>&1 curl -s "$bridge_api_url/bridges/$destination_addr?limit=100&offset=0" | jq '.' | tee $bridge_deposit_file - set +x - 2>&1 echo "Looking for claimable deposits" - 2>&1 jq '[.deposits[] | select(.ready_for_claim == true and .claim_tx_hash == "" and .dest_net == '$destination_net')]' $bridge_deposit_file | tee $claimable_deposit_file + echo "Getting full list of deposits" >&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) if [[ $claimable_count == 0 ]]; then - 2>&1 echo "We have no claimable deposits at this time" + echo "We have no claimable deposits at this time" >&3 exit fi if [[ $rpc_network_id != $destination_net ]]; then - 2>&1 echo "The bridge on the current rpc has network id $rpc_network_id but you are claming a transaction on network $destination_net - are you sure you're using the right RPC??" + echo "The bridge on the current rpc has network id $rpc_network_id but you are claming a transaction on network $destination_net - are you sure you're using the right RPC??" exit 1 fi - 2>&1 echo "We have $claimable_count claimable deposits on network $destination_net. Let's get this party started." + echo "We have $claimable_count claimable deposits on network $destination_net. Let's get this party started." readonly current_deposit=$(mktemp) readonly current_proof=$(mktemp) while read deposit_idx; do - 2>&1 echo "Starting claim for tx index: "$deposit_idx - 2>&1 echo "Deposit info:" - 2>&1 jq --arg idx $deposit_idx '.[($idx | tonumber)]' $claimable_deposit_file | tee $current_deposit + 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 curr_deposit_cnt=$(jq -r '.deposit_cnt' $current_deposit) curr_network_id=$(jq -r '.network_id' $current_deposit) - 2>&1 echo "Proof:" - set -x - 2>&1 curl -s "$bridge_api_url/merkle-proof?deposit_cnt=$curr_deposit_cnt&net_id=$curr_network_id" | jq '.' | tee $current_proof - set +x + echo "Proof:" >&3 + + 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 '"')" @@ -65,13 +67,9 @@ function claim() { 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 - set -x cast call --rpc-url $rpc_url $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 - set +x else - set -x cast send --legacy --rpc-url $rpc_url --private-key $skey $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 - set +x fi diff --git a/test/scripts/kurtosis_prepare_params_yml.sh b/test/scripts/kurtosis_prepare_params_yml.sh index 66353606..a27171ca 100755 --- a/test/scripts/kurtosis_prepare_params_yml.sh +++ b/test/scripts/kurtosis_prepare_params_yml.sh @@ -12,12 +12,7 @@ if [ -z $KURTOSIS_FOLDER ]; then exit 1 fi -FORK_NAME=$2 -if [ -z $FORK_NAME ]; then - echo "Missing param Fork Name" - exit 1 -fi -DATA_AVAILABILITY_MODE=$3 +DATA_AVAILABILITY_MODE=$2 if [ -z $DATA_AVAILABILITY_MODE ]; then echo "Missing param Data Availability Mode : [rollup, cdk-validium]" exit 1 @@ -25,5 +20,6 @@ fi mkdir -p $(dirname $DEST_KURTOSIS_PARAMS_YML) cp $KURTOSIS_FOLDER/params.yml $DEST_KURTOSIS_PARAMS_YML +yq -Y --in-place ".args.cdk_node_image = \"cdk\"" $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