Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: e2e checking for multiples certificates submitted #225

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
100 changes: 100 additions & 0 deletions test/bats/pp/bridge-ci-e2e.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
setup() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not expanding the existing one to send multiple deposits? Or even better to somehow parameterize how many of deposits we want to make?

So the optimal approach for me is to keep only the bridge-e2e.bats and either change the existing Native gas token deposit to WETH test to perform multiple deposits, or parameterize that test with deposits count (so that we can provide only single deposit in case we want to debug it for example). WDYT?

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
}
4 changes: 2 additions & 2 deletions test/bats/pp/bridge-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand All @@ -73,5 +74,4 @@ setup() {
destination_net=0
run bridge_asset "$weth_token_addr" "$l2_rpc_url"
assert_success
}

}
2 changes: 1 addition & 1 deletion test/bats/pp/e2e-pp.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading