-
Notifications
You must be signed in to change notification settings - Fork 5
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: Custom native gas token transfer E2E test #79
Merged
Stefan-Ethernal
merged 24 commits into
develop
from
CDK-482-e-2-e-implement-a-custom-native-gas-token-scenario
Sep 20, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8f7193b
fix: cleanup unused env vars
Stefan-Ethernal 615ffcc
test: introduce use l1 gas token env var
Stefan-Ethernal b6ff112
fix: rename sequencer wrapper command
Stefan-Ethernal 470a391
test: custom native token transfer (wip)
Stefan-Ethernal 8392952
feat: parameterize rpc urls in the helper functions
Stefan-Ethernal 4d1f0f5
test: mint erc20 gas token on l1 and assert the balance
Stefan-Ethernal 202f6b9
fix: get only first part of calculated balance
Stefan-Ethernal b7184ba
fix: try to trim the end by using sed
Stefan-Ethernal ce48c5a
fix: print receiver balance
Stefan-Ethernal 39357dc
test: parameterize gas token address
Stefan-Ethernal 89463cd
fix: trim the receiver_balance var
Stefan-Ethernal 8ea940d
fix: consolidate naming
Stefan-Ethernal 3618ab8
test: move variables and tests around, approve gas token on L1 and ru…
Stefan-Ethernal b7a2146
fix: rebase (rename sender_addr to sender because of the naming colli…
Stefan-Ethernal b7a1fcf
fix: access list e2e tests
Stefan-Ethernal 4408171
fix: consolidate variables and verbose logging in deposit function
Stefan-Ethernal 9c07f4d
test: wrap up the custom native token transfer e2e test
Stefan-Ethernal 29516a9
fix: test
Stefan-Ethernal 2ff8991
fix: trim the initial sender balance variable
Stefan-Ethernal c5c56f0
test: logs
Stefan-Ethernal ad645a5
fix: handle overflows during sum
Stefan-Ethernal a9a12e1
fix: use the basic calculator to compare very wei amounts
Stefan-Ethernal 958ad61
fix: remove log
Stefan-Ethernal c39fd68
fix: rename checkBalances
Stefan-Ethernal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,128 @@ | ||
setup() { | ||
load 'helpers/common-setup' | ||
_common_setup | ||
load 'helpers/common' | ||
load 'helpers/lxly-bridge-test' | ||
|
||
readonly data_availability_mode=${DATA_AVAILABILITY_MODE:-"cdk-validium"} | ||
$PROJECT_ROOT/test/scripts/kurtosis_prepare_params_yml.sh ../kurtosis-cdk $data_availability_mode | ||
[ $? -ne 0 ] && echo "Error preparing params.yml" && exit 1 | ||
|
||
# Check if the genesis file is already downloaded | ||
if [ ! -f "./tmp/cdk/genesis/genesis.json" ]; then | ||
mkdir -p ./tmp/cdk | ||
kurtosis files download cdk-v1 genesis ./tmp/cdk/genesis | ||
[ $? -ne 0 ] && echo "Error downloading genesis file" && exit 1 | ||
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 | ||
# Download the genesis file | ||
readonly bridge_default_address=$(jq -r ".genesis[] | select(.contractName == \"PolygonZkEVMBridge proxy\") | .address" ./tmp/cdk/genesis/genesis.json) | ||
|
||
readonly skey=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} | ||
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"} | ||
|
||
echo "Bridge address=$BRIDGE_ADDRESS" >&3 | ||
|
||
readonly sender_private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} | ||
destination_net=${DESTINATION_NET:-"1"} | ||
destination_addr=${DESTINATION_ADDRESS:-"0x0bb7AA0b4FdC2D2862c088424260e99ed6299148"} | ||
ether_value=${ETHER_VALUE:-"0.0200000054"} | ||
amount=$(cast to-wei $ether_value ether) | ||
token_addr=${TOKEN_ADDRESS:-"0x0000000000000000000000000000000000000000"} | ||
readonly is_forced=${IS_FORCED:-"true"} | ||
readonly bridge_addr=${BRIDGE_ADDRESS:-$bridge_default_address} | ||
readonly bridge_addr=$BRIDGE_ADDRESS | ||
readonly meta_bytes=${META_BYTES:-"0x"} | ||
|
||
readonly l1_rpc_url=${L1_ETH_RPC_URL:-"$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)"} | ||
readonly l2_rpc_url=${L2_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 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 amount=$(cast to-wei $ether_value ether) | ||
readonly current_addr="$(cast wallet address --private-key $skey)" | ||
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)') | ||
readonly sender_addr="$(cast wallet address --private-key $sender_private_key)" | ||
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" { | ||
load 'helpers/lxly-bridge-test' | ||
echo "Running LxLy deposit" >&3 | ||
run deposit | ||
assert_success | ||
assert_output --partial 'transactionHash' | ||
} | ||
|
||
@test "Run claim" { | ||
load 'helpers/lxly-bridge-test' | ||
echo "Running LxLy claim" | ||
echo "Running LxLy claim" >&3 | ||
|
||
# The script timeout (in seconds). | ||
timeout="120" | ||
start_time=$(date +%s) | ||
end_time=$((start_time + timeout)) | ||
|
||
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 | ||
if [ $status -eq 0 ]; then | ||
break | ||
fi | ||
sleep 10 | ||
done | ||
|
||
claim_frequency="10" | ||
run wait_for_claim "$timeout" "$claim_frequency" | ||
assert_success | ||
} | ||
|
||
@test "Custom native token transfer" { | ||
# Use GAS_TOKEN_ADDR if provided, otherwise retrieve from file | ||
if [[ -n "$GAS_TOKEN_ADDR" ]]; then | ||
echo "Using provided GAS_TOKEN_ADDR: $GAS_TOKEN_ADDR" >&3 | ||
local 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}" | ||
local gas_token_addr=$output | ||
fi | ||
|
||
echo "Gas token addr $gas_token_addr, L1 RPC: $l1_rpc_url" >&3 | ||
|
||
# Set receiver address and query for its initial native token balance on the L2 | ||
receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"} | ||
local initial_receiver_balance=$(cast balance --ether "$receiver" --rpc-url "$l2_rpc_url") | ||
echo "Initial receiver balance of native token on L2 $initial_receiver_balance" >&3 | ||
|
||
# Query for initial sender balance | ||
run queryContract "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$sender_addr" | ||
assert_success | ||
local gas_token_init_sender_balance=$(echo "$output" | tail -n 1 | awk '{print $1}') | ||
echo "Initial sender balance $gas_token_init_sender_balance" of gas token on L1 >&3 | ||
|
||
# Mint gas token on L1 | ||
local tokens_amount="0.1ether" | ||
local wei_amount=$(cast --to-unit $tokens_amount wei) | ||
local minter_key=${MINTER_KEY:-"42b6e34dc21598a807dc19d7784c71b2a7a01f6480dc6f58258f78e539f1a1fa"} | ||
run mint_erc20_tokens "$l1_rpc_url" "$gas_token_addr" "$minter_key" "$sender_addr" "$tokens_amount" | ||
assert_success | ||
|
||
# Assert that balance of gas token (on the L1) is correct | ||
run queryContract "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$sender_addr" | ||
assert_success | ||
local gas_token_final_sender_balance=$(echo "$output" | | ||
tail -n 1 | | ||
awk '{print $1}') | ||
local expected_balance=$(echo "$gas_token_init_sender_balance + $wei_amount" | | ||
bc | | ||
awk '{print $1}') | ||
|
||
echo "Sender balance ($sender_addr) (gas token L1): $gas_token_final_sender_balance" >&3 | ||
assert_equal "$gas_token_final_sender_balance" "$expected_balance" | ||
|
||
# Send approve transaction to the gas token on L1 | ||
deposit_ether_value="0.1ether" | ||
run sendTx "$l1_rpc_url" "$sender_private_key" "$gas_token_addr" "$approve_fn_sig" "$bridge_addr" "$deposit_ether_value" | ||
assert_success | ||
assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" | ||
|
||
# Deposit | ||
token_addr=$gas_token_addr | ||
destination_addr=$receiver | ||
destination_net=$l2_rpc_network_id | ||
amount=$wei_amount | ||
run deposit | ||
assert_success | ||
|
||
# Claim deposits (settle them on the L2) | ||
timeout="120" | ||
claim_frequency="10" | ||
run wait_for_claim "$timeout" "$claim_frequency" | ||
assert_success | ||
|
||
# Validate that the native token of receiver on L2 has increased by the bridge tokens amount | ||
run verify_native_token_balance "$l2_rpc_url" "$receiver" "$initial_receiver_balance" "$tokens_amount" | ||
assert_success | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test looks so big, can we split it in smaller tests? I feel it can be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we split the test into smaller ones, it does not make sense. If we could somehow interlock the tests, that would make sense, but to the best of my knowledge, we cannot do it in the Bats...?
I can get rid of assertions for the sender's initial and final balance for the gas token and just blindly assume that minting did what it was supposed to and that the balance was increased (in case it returns the function that sends mint transaction yields zero status code). In that case, it would mean, I remove these two parts of the code:
Does it sound good enough?