Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Dec 12, 2024
1 parent 1951ead commit 5bcc3ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions test/bats/pp-multi/bridge-l2_to_l2-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ setup() {
}

@test "Test L2 to L2 bridge" {
echo "=== Running LxLy bridge eth L1 to L2(PP1)" >&3
echo "=== Running LxLy bridge eth L1 to L2(PP1) amount:$amount" >&3
destination_net=$l2_pp1b_network_id
bridge_asset "$native_token_addr" "$l1_rpc_url"
bridge_tx_hash_pp1=$bridge_tx_hash

echo "=== Running LxLy bridge eth L1 to L2(PP2)" >&3
echo "=== Running LxLy bridge eth L1 to L2(PP2) amount:$amount" >&3
destination_net=$l2_pp2b_network_id
bridge_asset "$native_token_addr" "$l1_rpc_url"
bridge_tx_hash_pp2=$bridge_tx_hash

echo "=== Running LxLy claim L1 to L2(PP1) for $bridge_tx_hash" >&3
echo "=== Running LxLy claim L1 to L2(PP1) for $bridge_tx_hash_pp1" >&3
run claim_tx_hash "$timeout" "$bridge_tx_hash_pp1" "$destination_addr" "$l2_pp1_url" "$l2_pp1b_url"
assert_success

echo "=== Running LxLy claim L1 to L2(PP2) for $bridge_tx_hash" >&3
run claim_tx_hash "$timeout" "$bridge_tx_hash_pp1" "$destination_addr" "$l2_pp2_url" "$l2_pp2b_url"
echo "=== Running LxLy claim L1 to L2(PP2) for $bridge_tx_hash_pp2" >&3
run claim_tx_hash "$timeout" "$bridge_tx_hash_pp2" "$destination_addr" "$l2_pp2_url" "$l2_pp2b_url"
assert_success

# reduce eth
ether_value=${ETHER_VALUE:-"0.0100000054"}
amount=$(cast to-wei $ether_value ether)

echo "=== Running LxLy bridge L2(PP1) to L2(PP2)" >&3
echo "=== Running LxLy bridge L2(PP1) to L2(PP2) amount:$amount" >&3
destination_net=$l2_pp2b_network_id
bridge_asset "$native_token_addr" "$l2_pp1_url"

Expand All @@ -59,7 +59,7 @@ setup() {
assert_success

# Now a need to do a bridge on L2 to trigger a certificate:
echo "=== Running LxLy bridge eth L2(PP2) to L1 (trigger a certificate on PP2)" >&3
echo "=== Running LxLy bridge eth L2(PP2) to L1 (trigger a certificate on PP2) amount:$amount" >&3
destination_net=$l1_rpc_network_id
bridge_asset "$native_token_addr" "$l2_pp2_url"

Expand Down
22 changes: 11 additions & 11 deletions test/helpers/lxly-bridge-test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,30 @@ function bridge_asset() {
local bridge_sig='bridgeAsset(uint32,address,uint256,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
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" >&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
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" >&3
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" >&3
echo "bridge_tx_hash=$bridge_tx_hash"
fi
}

Expand Down Expand Up @@ -144,34 +143,35 @@ function claim_tx_hash() {

readonly bridge_deposit_file=$(mktemp)
local ready_for_claim="false"

local start_time=$(date +%s)
local current_time=$(date +%s)
local end_time=$((current_time + timeout))
while true; do
current_time=$(date +%s)
elpased_time=$((current_time - start_time))
if ((current_time > end_time)); then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ❌ Exiting... Timeout reached waiting for tx_hash [$tx_hash] timeout: $timeout!"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ❌ Exiting... Timeout reached waiting for tx_hash [$tx_hash] timeout: $timeout! (elapsed: $elpased_time)"
echo " $current_time > $end_time" >&3
exit 1
fi
curl -s "$bridge_provide_merkel_proof/bridges/$destination_addr?limit=100&offset=0" | jq "[.deposits[] | select(.tx_hash == \"$tx_hash\" )]" > $bridge_deposit_file
deposit_count=$(jq '. | length' $bridge_deposit_file)
if [[ $deposit_count == 0 ]]; then
echo "...[$(date '+%Y-%m-%d %H:%M:%S')] ❌ the tx_hash [$tx_hash] not found" >&3
echo "...[$(date '+%Y-%m-%d %H:%M:%S')] ❌ the tx_hash [$tx_hash] not found (elapsed: $elpased_time / timeout:$timeout)" >&3
sleep "$claim_frequency"
continue
fi
local ready_for_claim=$(jq '.[0].ready_for_claim' $bridge_deposit_file)
if [ $ready_for_claim != "true" ]; then
echo ".... [$(date '+%Y-%m-%d %H:%M:%S')] ⏳ the tx_hash $tx_hash is not ready for claim yet" >&3
echo ".... [$(date '+%Y-%m-%d %H:%M:%S')] ⏳ the tx_hash $tx_hash is not ready for claim yet (elapsed: $elpased_time / timeout:$timeout)" >&3
sleep "$claim_frequency"
continue
else
break
fi
done
# Deposit is ready for claim
echo "....[$(date '+%Y-%m-%d %H:%M:%S')] 🎉 the tx_hash $tx_hash is ready for claim!" >&3
echo "....[$(date '+%Y-%m-%d %H:%M:%S')] 🎉 the tx_hash $tx_hash is ready for claim! (elapsed: $elpased_time)" >&3
local curr_claim_tx_hash=$(jq '.[0].claim_tx_hash' $bridge_deposit_file)
if [ $curr_claim_tx_hash != "\"\"" ]; then
echo "....[$(date '+%Y-%m-%d %H:%M:%S')] 🎉 the tx_hash $tx_hash is already claimed" >&3
Expand Down

0 comments on commit 5bcc3ba

Please sign in to comment.