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: bridge e2e testing #57

Merged
merged 28 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bcd62fd
tests: PoC bridge testing with bats
vcastellm Sep 3, 2024
3be3e46
Run bats in e2e
vcastellm Sep 3, 2024
2ed2c8a
Remove unused make lines
vcastellm Sep 6, 2024
8b57644
tests: wip
vcastellm Sep 9, 2024
702165f
test: better
vcastellm Sep 10, 2024
67d3075
Merge remote-tracking branch 'origin/develop' into poc_bats
vcastellm Sep 10, 2024
5e19625
Let's see
vcastellm Sep 10, 2024
f4a7bfa
test: fix test
vcastellm Sep 10, 2024
97d357e
test: use cdk image
vcastellm Sep 10, 2024
d91c20f
test: bats path
vcastellm Sep 10, 2024
98a5261
test: fix
vcastellm Sep 10, 2024
09eeb68
test: deposit on 1
vcastellm Sep 12, 2024
7ad30b2
test: wait for claim
vcastellm Sep 12, 2024
7a2a313
test: timeout
vcastellm Sep 12, 2024
728befb
test: timeout
vcastellm Sep 12, 2024
5e0c439
test: increase timeout
vcastellm Sep 12, 2024
1600349
test: apply feedback
vcastellm Sep 13, 2024
4bf549b
Merge remote-tracking branch 'origin/develop' into poc_bats
vcastellm Sep 13, 2024
3d03ba4
ci: lint action
vcastellm Sep 13, 2024
244eb2d
test: do not prepare if already present
vcastellm Sep 13, 2024
7a1213b
test: Send EOA and deploy contract E2E tests using Bats (#69)
Stefan-Ethernal Sep 16, 2024
2edafe6
test: apply feedback
vcastellm Sep 16, 2024
13df74c
Merge remote-tracking branch 'refs/remotes/origin/poc_bats' into poc_…
vcastellm Sep 16, 2024
0e0172c
Merge remote-tracking branch 'origin/develop' into poc_bats
vcastellm Sep 16, 2024
5d717fa
test: lint
vcastellm Sep 16, 2024
0d71a87
ci: increase lint timeout
vcastellm Sep 16, 2024
c9cbf60
Merge remote-tracking branch 'origin/develop' into poc_bats
vcastellm Sep 16, 2024
0d0f2bf
fix: merge conflict
vcastellm Sep 16, 2024
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: 3 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
repository: 0xPolygon/kurtosis-cdk
path: "kurtosis-cdk"

- name: Setup Bats and bats libs
uses: bats-core/[email protected]
vcastellm marked this conversation as resolved.
Show resolved Hide resolved

- name: Test
run: make test-e2e-${{ matrix.e2e-group }}
working-directory: test
Expand Down
2 changes: 2 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ generate-mocks-da: ## Generates mocks for dataavailability, using mockery tool
.PHONY: test-e2e-elderberry-validium
test-e2e-elderberry-validium: stop ## Runs e2e tests checking elderberry/validium
./run-e2e.sh cdk-validium
bats test/bridge-e2e.bats

.PHONY: test-e2e-elderberry-rollup
test-e2e-elderberry-rollup: stop ## Runs e2e tests checking elderberry/rollup
./run-e2e.sh rollup
bats test/bridge-e2e.bats

.PHONY: stop
stop:
Expand Down
61 changes: 61 additions & 0 deletions test/bridge-e2e.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
setup() {
bats_load_library 'bats-support'
bats_load_library 'bats-assert'
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved

# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
# make executables in src/ visible to PATH
PATH="$DIR/../src:$PATH"

readonly skey=${RAW_PRIVATE_KEY:-"bc6a95c870cce28fe9686fdd70a3a595769e019bb396cd725bc16ec553f07c83"}
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"}
readonly is_forced=${IS_FORCED:-"true"}
readonly bridge_addr=${BRIDGE_ADDRESS:-"0x528e26b25a34a4A5d0dbDa1d57D318153d2ED582"}
readonly meta_bytes=${META_BYTES:-"0x"}
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
readonly subcommand=${1:-"deposit"}

readonly rpc_url=${ETH_RPC_URL:-"https://rpc.cardona.zkevm-rpc.com"}
readonly bridge_api_url=${BRIDGE_API_URL:-"https://bridge-api-cdk-validium-cardona-03-zkevm.polygondev.tools"}

readonly dry_run=${DRY_RUN:-"false"}
readonly claim_sig="claimAsset(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)"
vcastellm marked this conversation as resolved.
Show resolved Hide resolved
readonly bridge_sig='bridgeAsset(uint32,address,uint256,address,bool,bytes)'
vcastellm marked this conversation as resolved.
Show resolved Hide resolved

readonly amount=$(cast to-wei $ether_value ether)
readonly current_addr="$(cast wallet address --private-key $skey)"
readonly rpc_network_id=$(cast call --rpc-url $rpc_url $bridge_addr 'networkID()(uint32)')


2>&1 echo "Running LxLy " $subcommand

2>&1 echo "Checking the current network id: "
2>&1 echo $rpc_network_id

2>&1 echo "The current private key has address: "
2>&1 echo $current_addr

if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then
2>&1 echo "Checking the current ETH balance: "
2>&1 cast balance -e --rpc-url $rpc_url $current_addr
else
2>&1 echo "Checking the current token balance for token at $token_addr: "
2>&1 cast call --rpc-url $rpc_url $token_addr 'balanceOf(address)(uint256)' $current_addr
fi
}

@test "Run deposit" {
load 'helpers/lxly-bridge-test'
run deposit
assert_output --partial 'foo'
}

@test "Run claim" {
load 'helpers/lxly-bridge-test'
run claim
assert_output --partial 'execution reverted'
vcastellm marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 0 additions & 1 deletion test/config/test.kurtosis_template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ AggLayerTxTimeout = "5m"
AggLayerURL = ""
MaxWitnessRetrievalWorkers = 2
SyncModeOnlyEnabled = false
UseFullWitness = false
SequencerPrivateKey = {}
[Aggregator.DB]
Name = "aggregator_db"
Expand Down
79 changes: 79 additions & 0 deletions test/helpers/lxly-bridge-test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# Error code reference https://hackmd.io/WwahVBZERJKdfK3BbKxzQQ
function deposit () {
2>&1 echo "Attempting to deposit $amount wei to net $destination_net for token $token_addr"

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
set -x
cast send --legacy --private-key $skey --value $amount --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
set +x
else
set -x
cast send --legacy --private-key $skey --rpc-url $rpc_url $bridge_addr $bridge_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
set +x
fi
fi
}

function claim() {
readonly bridge_deposit_file=$(mktemp)
readonly claimable_deposit_file=$(mktemp)
2>&1 echo "Getting full list of deposits"
set -x
2>&1 curl -s "$bridge_api_url/bridges/$destination_addr?limit=100&offset=0" | jq '.' | tee $bridge_deposit_file
set +x
2>&1 echo "Looking for claimable deposits"
2>&1 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)
if [[ $claimable_count == 0 ]]; then
2>&1 echo "We have no claimable deposits at this time"
exit
fi
if [[ $rpc_network_id != $destination_net ]]; then
2>&1 echo "The bridge on the current rpc has network id $rpc_network_id but you are claming a transaction on network $destination_net - are you sure you're using the right RPC??"
exit 1
fi
2>&1 echo "We have $claimable_count claimable deposits on network $destination_net. Let's get this party started."
readonly current_deposit=$(mktemp)
readonly current_proof=$(mktemp)
while read deposit_idx; do
2>&1 echo "Starting claim for tx index: "$deposit_idx
2>&1 echo "Deposit info:"
2>&1 jq --arg idx $deposit_idx '.[($idx | tonumber)]' $claimable_deposit_file | tee $current_deposit

curr_deposit_cnt=$(jq -r '.deposit_cnt' $current_deposit)
curr_network_id=$(jq -r '.network_id' $current_deposit)
2>&1 echo "Proof:"
set -x
2>&1 curl -s "$bridge_api_url/merkle-proof?deposit_cnt=$curr_deposit_cnt&net_id=$curr_network_id" | jq '.' | tee $current_proof
set +x

in_merkle_proof="$(jq -r -c '.proof.merkle_proof' $current_proof | tr -d '"')"
in_rollup_merkle_proof="$(jq -r -c '.proof.rollup_merkle_proof' $current_proof | tr -d '"')"
in_global_index=$(jq -r '.global_index' $current_deposit)
in_main_exit_root=$(jq -r '.proof.main_exit_root' $current_proof)
in_rollup_exit_root=$(jq -r '.proof.rollup_exit_root' $current_proof)
in_orig_net=$(jq -r '.orig_net' $current_deposit)
in_orig_addr=$(jq -r '.orig_addr' $current_deposit)
in_dest_net=$(jq -r '.dest_net' $current_deposit)
in_dest_addr=$(jq -r '.dest_addr' $current_deposit)
in_amount=$(jq -r '.amount' $current_deposit)
in_metadata=$(jq -r '.metadata' $current_deposit)

if [[ $dry_run == "true" ]]; then
cast calldata $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
set -x
cast call --rpc-url $rpc_url $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
set +x
else
set -x
cast send --legacy --rpc-url $rpc_url --private-key $skey $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
set +x
fi


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