Skip to content

Commit

Permalink
fix: consolidate variables and verbose logging in deposit function
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Sep 19, 2024
1 parent b7a1fcf commit 4408171
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
18 changes: 8 additions & 10 deletions test/access-list-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ setup() {
load 'helpers/common'
_common_setup

readonly sequencer=${KURTOSIS_NODE:-cdk-erigon-sequencer-001}
readonly node=${KURTOSIS_NODE:-cdk-erigon-node-001}
readonly l2_rpc_url=${RPC_URL:-$(kurtosis port print "$enclave" "$node" http-rpc)}
readonly erigon_sequencer_node=${KURTOSIS_ERIGON_SEQUENCER:-cdk-erigon-sequencer-001}
readonly kurtosis_sequencer_wrapper=${KURTOSIS_SEQUENCER_WRAPPER:-"kurtosis service exec $enclave $erigon_sequencer_node"}
readonly key=${SENDER_key:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"}
readonly receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"}
readonly data_dir=${ACL_DATA_DIR:-"/home/erigon/data/dynamic-kurtosis-sequencer/txpool/acls"}
readonly kurtosis_sequencer_wrapper=${KURTOSIS_SEQUENCER_WRAPPER:-"kurtosis service exec $enclave $sequencer"}
}

teardown() {
Expand Down Expand Up @@ -69,7 +67,7 @@ set_acl_mode() {

run set_acl_mode "blocklist"
run add_to_access_list "blocklist" "deploy"
run deployContract $l2_rpc_url $key $contract_artifact
run deployContract $l2_rpc_url $key $contract_artifact

assert_failure
assert_output --partial "sender disallowed to deploy contract by ACL policy"
Expand Down Expand Up @@ -98,19 +96,19 @@ set_acl_mode() {
@test "Test Allow List - Sending regular transaction when address is in allow list" {
local value="10ether"

run set_acl_mode "allowlist"
run add_to_access_list "allowlist" "sendTx"
run set_acl_mode "allowlist"
run add_to_access_list "allowlist" "sendTx"
run sendTx $l2_rpc_url $key $receiver $value

assert_success
assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)"
}

@test "Test Allow List - Sending contracts deploy transaction when address is in allow list" {
local contract_artifact="./contracts/erc20mock/ERC20Mock.json"

run set_acl_mode "allowlist"
run add_to_access_list "allowlist" "deploy"
run set_acl_mode "allowlist"
run add_to_access_list "allowlist" "deploy"
run deployContract $l2_rpc_url $key $contract_artifact

assert_success
Expand Down
3 changes: 0 additions & 3 deletions test/basic-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ setup() {
load 'helpers/common'
_common_setup

readonly node=${KURTOSIS_NODE:-cdk-erigon-node-001}
readonly sender_private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"}
readonly receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"}

readonly l2_rpc_url=${L2_ETH_RPC_URL:-$(kurtosis port print "$enclave" "$node" http-rpc)}
}

@test "Send EOA transaction" {
Expand Down
19 changes: 8 additions & 11 deletions test/bridge-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ setup() {
[ $? -ne 0 ] && echo "Error preparing params.yml" && exit 1

if [ -z "$BRIDGE_ADDRESS" ]; then
local combined_json_path="/opt/zkevm/combined.json"
echo "BRIDGE_ADDRESS env variable is not provided, resolving the bridge address from the Kurtosis CDK '$combined_json_path'" >&3
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_path" | tail -n +2)
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
Expand All @@ -24,21 +24,19 @@ setup() {
destination_net=${DESTINATION_NET:-"1"}
destination_addr=${DESTINATION_ADDRESS:-"0x0bb7AA0b4FdC2D2862c088424260e99ed6299148"}
ether_value=${ETHER_VALUE:-"0.0200000054"}
readonly amount=$(cast to-wei $ether_value ether)
token_addr=${TOKEN_ADDRESS:-"0x0000000000000000000000000000000000000000"}
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 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 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)')
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" {
Expand Down Expand Up @@ -118,7 +116,6 @@ setup() {
echo "Receiver balance: $receiver_balance" >&3
assert_equal "$receiver_balance" "$expected_balance"

# TODO:
# Send approve transaction
deposit_ether_value="0.1ether"
run sendTx "$l1_rpc_url" "$sender_private_key" "$gas_token_addr" "$approve_fn_sig" "$bridge_addr" "$deposit_ether_value"
Expand Down
3 changes: 3 additions & 0 deletions test/helpers/common-setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ _common_setup() {
readonly balance_of_fn_sig="function balanceOf(address) (uint256)"
readonly approve_fn_sig="function approve(address,uint256)"


# Kurtosis enclave and service identifiers
readonly enclave=${KURTOSIS_ENCLAVE:-cdk-v1}
readonly contracts_container=${KURTOSIS_CONTRACTS:-contracts-001}
readonly contracts_service_wrapper=${KURTOSIS_CONTRACTS_WRAPPER:-"kurtosis service exec $enclave $contracts_container"}
readonly erigon_rpc_node=${KURTOSIS_ERIGON_RPC:-cdk-erigon-node-001}
readonly l2_rpc_url=${L2_ETH_RPC_URL:-"$(kurtosis port print $enclave $erigon_rpc_node http-rpc)"}
}
18 changes: 9 additions & 9 deletions test/helpers/lxly-bridge-test.bash
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env bash
# Error code reference https://hackmd.io/WwahVBZERJKdfK3BbKxzQQ
function deposit () {
function deposit() {
readonly deposit_sig='bridgeAsset(uint32,address,uint256,address,bool,bytes)'

if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then
echo "Checking the current ETH balance: " >&3
echo "The ETH balance for sender "$sender_addr":" >&3
cast balance -e --rpc-url $l1_rpc_url $sender_addr >&3
else
echo "Checking the current token balance for token at $token_addr: " >&3
cast call --rpc-url $l1_rpc_url $token_addr 'balanceOf(address)(uint256)' $sender_addr >&3
echo "The "$token_addr" token balance for sender "$sender_addr":" >&3
balance_wei=$(cast call --rpc-url "$l1_rpc_url" "$token_addr" "$balance_of_fn_sig" "$sender_addr")
echo "$(cast --from-wei "$balance_wei")" >&3
fi

echo "Attempting to deposit $amount wei to net $destination_net for token $token_addr" >&3
echo "Attempting to deposit $amount [wei] to $destination_addr, token $token_addr (sender=$sender_addr, network id=$destination_net, rpc url=$l1_rpc_url)" >&3

if [[ $dry_run == "true" ]]; then
cast calldata $deposit_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
Expand All @@ -30,7 +31,7 @@ function claim() {
readonly claimable_deposit_file=$(mktemp)
echo "Getting full list of deposits" >&3
curl -s "$bridge_api_url/bridges/$destination_addr?limit=100&offset=0" | jq '.' | tee $bridge_deposit_file

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)
Expand All @@ -40,7 +41,7 @@ function claim() {
echo "We have no claimable deposits at this time" >&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)
Expand Down Expand Up @@ -72,6 +73,5 @@ function claim() {
cast send --legacy --rpc-url $l2_rpc_url --private-key $sender_private_key $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


done < <(seq 0 $((claimable_count - 1)) )
done < <(seq 0 $((claimable_count - 1)))
}

0 comments on commit 4408171

Please sign in to comment.