Skip to content

Commit

Permalink
feat: e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Nov 13, 2024
1 parent dbc47e1 commit 6c084b0
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
40 changes: 37 additions & 3 deletions test/bridge-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ setup() {
echo "=== Running LxLy claim on L2" >&3
timeout="120"
claim_frequency="10"
run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url"
run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" "true"
assert_success

run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value"
Expand All @@ -76,7 +76,7 @@ setup() {
echo "=== Claim in L1 ETH" >&3
timeout="400"
claim_frequency="60"
run wait_for_claim "$timeout" "$claim_frequency" "$l1_rpc_url"
run wait_for_claim "$timeout" "$claim_frequency" "$l1_rpc_url" "true"
assert_success
}

Expand Down Expand Up @@ -133,7 +133,7 @@ setup() {
# Claim deposits (settle them on the L2)
timeout="120"
claim_frequency="10"
run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url"
run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" "true"
assert_success

# Validate that the native token of receiver on L2 has increased by the bridge tokens amount
Expand Down Expand Up @@ -167,3 +167,37 @@ setup() {
fi
assert_success
}

@test "Bridge message with native token" {
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 on L1 to network with bridge message: $l2_rpc_network_id native_token: $native_token_addr" >&3

destination_net=$l2_rpc_network_id
run bridgeMessage "$native_token_addr" "$l1_rpc_url"
assert_success

echo "=== Running LxLy claim message on L2" >&3
timeout="120"
claim_frequency="10"
run wait_for_claim "$timeout" "$claim_frequency" "$l2_rpc_url" "false"
assert_success

run verify_balance "$l2_rpc_url" "$weth_token_addr" "$destination_addr" "$initial_receiver_balance" "$ether_value"
assert_success

echo "=== bridgeMessage L2 WETH: $weth_token_addr to L1 ETH" >&3
destination_addr=$sender_addr
destination_net=0
run bridgeMessage "$weth_token_addr" "$l2_rpc_url"
assert_success

echo "=== Claim message in L1 ETH" >&3
timeout="400"
claim_frequency="60"
run wait_for_claim "$timeout" "$claim_frequency" "$l1_rpc_url" "false"
assert_success
}
40 changes: 38 additions & 2 deletions test/helpers/lxly-bridge-test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ function bridgeAsset() {

function claim() {
local destination_rpc_url="$1"
readonly claim_sig="claimAsset(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)"
local is_asset="$2"
local claim_sig="claimAsset(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)"
if [[ $is_asset == "false" ]]; 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
Expand Down Expand Up @@ -94,6 +99,7 @@ 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 is_asset="$4" # is asset or message
local start_time=$(date +%s)
local end_time=$((start_time + timeout))

Expand All @@ -104,11 +110,41 @@ function wait_for_claim() {
exit 1
fi

run claim $destination_rpc_url
run claim $destination_rpc_url $is_asset
if [ $status -eq 0 ]; then
break
fi

sleep "$claim_frequency"
done
}

function bridgeMessage() {
local token_addr="$1"
local rpc_url="$2"
readonly 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 bridge message $amount [wei] 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" >&3
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
}

0 comments on commit 6c084b0

Please sign in to comment.