Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: deposit on 1
Browse files Browse the repository at this point in the history
vcastellm committed Sep 12, 2024
1 parent 98a5261 commit 09eeb68
Showing 2 changed files with 36 additions and 17 deletions.
25 changes: 22 additions & 3 deletions test/bridge-e2e.bats
Original file line number Diff line number Diff line change
@@ -13,15 +13,16 @@ setup() {
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_net=${DESTINATION_NET:-"1"}
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:-$bridge_default_address}
readonly meta_bytes=${META_BYTES:-"0x"}

readonly rpc_url=${ETH_RPC_URL:-"$(kurtosis port print cdk-v1 cdk-erigon-node-001 http-rpc)"}
readonly l1_rpc_url=${ETH_RPC_URL:-"$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)"}
readonly l2_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"}
@@ -30,7 +31,8 @@ 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)')
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)')
}

@test "Run deposit" {
@@ -44,6 +46,23 @@ setup() {
@test "Run claim" {
load 'helpers/lxly-bridge-test'
echo "Running LxLy claim"

# The script timeout (in seconds).
timeout="10"
start_time=$(date +%s)
end_time=$((start_time + timeout))

run claim

# while true; do
# 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
# sleep 10
# done

assert_success
}
28 changes: 14 additions & 14 deletions test/helpers/lxly-bridge-test.bash
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@
function deposit () {
if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then
echo "Checking the current ETH balance: " >&3
cast balance -e --rpc-url $rpc_url $current_addr >&3
cast balance -e --rpc-url $l1_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
cast call --rpc-url $l1_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
@@ -15,9 +15,9 @@ function deposit () {
cast calldata $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
else
if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then
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
cast send --legacy --private-key $skey --value $amount --rpc-url $l1_rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
else
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
cast send --legacy --private-key $skey --rpc-url $l1_rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
fi
fi
}
@@ -31,26 +31,26 @@ function claim() {
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
fi
if [[ $rpc_network_id != $destination_net ]]; then
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
echo "We have $claimable_count claimable deposits on network $destination_net. Let's get this party started."
# if [[ $rpc_network_id != $destination_net ]]; then
# 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??" >&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)
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
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)
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 '"')"
@@ -67,9 +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
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
cast call --rpc-url $l2_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
else
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
cast send --legacy --rpc-url $l2_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
fi


0 comments on commit 09eeb68

Please sign in to comment.