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 20 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
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v3
- name: Lint
run: |
make install-linter
make lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
4 changes: 4 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ 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
env:
KURTOSIS_FOLDER: ${{ github.workspace }}/kurtosis-cdk
BATS_LIB_PATH: /usr/lib/
20 changes: 0 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ LDFLAGS += -X 'github.com/0xPolygon/cdk.GitRev=$(GITREV)'
LDFLAGS += -X 'github.com/0xPolygon/cdk.GitBranch=$(GITBRANCH)'
LDFLAGS += -X 'github.com/0xPolygon/cdk.BuildDate=$(DATE)'

# Variables
VENV = .venv
VENV_PYTHON = $(VENV)/bin/python
SYSTEM_PYTHON = $(or $(shell which python3), $(shell which python))
PYTHON = $(or $(wildcard $(VENV_PYTHON)), "install_first_venv")
GENERATE_SCHEMA_DOC = $(VENV)/bin/generate-schema-doc
GENERATE_DOC_PATH = "docs/config-file/"
GENERATE_DOC_TEMPLATES_PATH = "docs/config-file/templates/"

# Check dependencies
# Check for Go
.PHONY: check-go
Expand Down Expand Up @@ -87,22 +78,11 @@ test-unit:
.PHONY: test-seq_sender
test-seq_sender:
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -timeout 200s ./sequencesender/...


.PHONY: install-linter
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
install-linter: ## Installs the linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.54.2

.PHONY: lint
lint: ## Runs the linter
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/golangci-lint run

$(VENV_PYTHON):
rm -rf $(VENV)
$(SYSTEM_PYTHON) -m venv $(VENV)

venv: $(VENV_PYTHON)

.PHONY: generate-code-from-proto
generate-code-from-proto: ## Generates code from proto files
cd proto/src/proto/aggregator/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../aggregator/prover --go-grpc_out=../../../../../aggregator/prover --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative aggregator.proto
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 .

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

.PHONY: stop
stop:
Expand Down
68 changes: 68 additions & 0 deletions test/bridge-e2e.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
setup() {
load 'helpers/common-setup'
_common_setup

$PROJECT_ROOT/test/scripts/kurtosis_prepare_params_yml.sh ../kurtosis-cdk cdk-validium
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
vcastellm marked this conversation as resolved.
Show resolved Hide resolved

# 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
vcastellm marked this conversation as resolved.
Show resolved Hide resolved
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"}
readonly is_forced=${IS_FORCED:-"true"}
readonly bridge_addr=${BRIDGE_ADDRESS:-$bridge_default_address}
readonly meta_bytes=${META_BYTES:-"0x"}
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved

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 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)')
}

@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"

# 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

assert_success
}
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
10 changes: 10 additions & 0 deletions test/e2e.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
setup() {
load 'helpers/common-setup'
_common_setup
}

@test "Verify batches" {
echo "Waiting 10 minutes to get some verified batch...."
run $PROJECT_ROOT/test/scripts/batch_verification_monitor.sh 0 600
assert_success
}
13 changes: 13 additions & 0 deletions test/helpers/common-setup.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

_common_setup() {
bats_load_library 'bats-support'
bats_load_library 'bats-assert'

# 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
PROJECT_ROOT="$( cd "$( dirname "$BATS_TEST_FILENAME" )/.." >/dev/null 2>&1 && pwd )"
# make executables in src/ visible to PATH
PATH="$PROJECT_ROOT/src:$PATH"
}
77 changes: 77 additions & 0 deletions test/helpers/lxly-bridge-test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# Error code reference https://hackmd.io/WwahVBZERJKdfK3BbKxzQQ
function deposit () {
readonly deposit_sig='bridgeAsset(uint32,address,uint256,address,bool,bytes)'

if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then
echo "Checking the current ETH balance: " >&3
cast balance -e --rpc-url $l1_rpc_url $current_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)' $current_addr >&3
fi

echo "Attempting to deposit $amount wei to net $destination_net for token $token_addr" >&3

if [[ $dry_run == "true" ]]; then
cast calldata $deposit_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
else
if [[ $token_addr == "0x0000000000000000000000000000000000000000" ]]; then
cast send --legacy --private-key $skey --value $amount --rpc-url $l1_rpc_url $bridge_addr $deposit_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
else
cast send --legacy --private-key $skey --rpc-url $l1_rpc_url $bridge_addr $deposit_sig $destination_net $destination_addr $amount $token_addr $is_forced $meta_bytes
fi
fi
}

function claim() {
readonly claim_sig="claimAsset(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)"
readonly bridge_deposit_file=$(mktemp)
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)
echo "Found $claimable_count claimable deposits" >&3

if [[ $claimable_count == 0 ]]; then
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)
while read deposit_idx; do
echo "Starting claim for tx index: "$deposit_idx >&3
echo "Deposit info:" >&3
jq --arg idx $deposit_idx '.[($idx | tonumber)]' $claimable_deposit_file | tee $current_deposit >&3

curr_deposit_cnt=$(jq -r '.deposit_cnt' $current_deposit)
curr_network_id=$(jq -r '.network_id' $current_deposit)
curl -s "$bridge_api_url/merkle-proof?deposit_cnt=$curr_deposit_cnt&net_id=$curr_network_id" | jq '.' | tee $current_proof

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
cast call --rpc-url $l2_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
else
cast send --legacy --rpc-url $l2_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
fi


done < <(seq 0 $((claimable_count - 1)) )
}
5 changes: 1 addition & 4 deletions test/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ else
echo "docker cdk:latest already exists"
fi

$BASE_FOLDER/scripts/kurtosis_prepare_params_yml.sh "$KURTOSIS_FOLDER" "elderberry" "cdk-validium"
$BASE_FOLDER/scripts/kurtosis_prepare_params_yml.sh "$KURTOSIS_FOLDER" "cdk-validium"
[ $? -ne 0 ] && echo "Error preparing params.yml" && exit 1

kurtosis clean --all
kurtosis run --enclave cdk-v1 --args-file $DEST_KURTOSIS_PARAMS_YML --image-download always $KURTOSIS_FOLDER
#[ $? -ne 0 ] && echo "Error running kurtosis" && exit 1
echo "Waiting 10 minutes to get some verified batch...."
scripts/batch_verification_monitor.sh 0 600
15 changes: 8 additions & 7 deletions test/scripts/kurtosis_prepare_params_yml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ if [ -z $DEST_KURTOSIS_PARAMS_YML ]; then
exit 1
fi

# Check if the destination params file exists and don't do nothing
if [ -f $DEST_KURTOSIS_PARAMS_YML ]; then
echo "Destination params file already exists"
exit 0
fi

KURTOSIS_FOLDER=$1
if [ -z $KURTOSIS_FOLDER ]; then
echo "Missing param Kurtosis Folder"
exit 1
fi

FORK_NAME=$2
if [ -z $FORK_NAME ]; then
echo "Missing param Fork Name"
exit 1
fi
DATA_AVAILABILITY_MODE=$3
DATA_AVAILABILITY_MODE=$2
if [ -z $DATA_AVAILABILITY_MODE ]; then
echo "Missing param Data Availability Mode : [rollup, cdk-validium]"
exit 1
fi

mkdir -p $(dirname $DEST_KURTOSIS_PARAMS_YML)
cp $KURTOSIS_FOLDER/params.yml $DEST_KURTOSIS_PARAMS_YML
yq -Y --in-place ".args.cdk_node_image = \"cdk\"" $DEST_KURTOSIS_PARAMS_YML
yq -Y --in-place ".args.data_availability_mode = \"$DATA_AVAILABILITY_MODE\"" $DEST_KURTOSIS_PARAMS_YML
yq -Y --in-place ".args.zkevm_sequence_sender_image = \"cdk:latest\"" $DEST_KURTOSIS_PARAMS_YML
Loading