Skip to content

Commit

Permalink
feat: aggsender e2e (#183)
Browse files Browse the repository at this point in the history
- Split FEP and PP e2e tests
- Add PP that check on aggsender database if there are 1 settle certificate
- Add sqlite client to docker
  • Loading branch information
joanestebanr authored Nov 19, 2024
1 parent 6e4577f commit df57e65
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- "fork11-rollup"
- "fork12-validium"
- "fork12-rollup"
- "fork12-pessimistic"
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down Expand Up @@ -70,7 +71,7 @@ jobs:
with:
repository: 0xPolygon/kurtosis-cdk
path: "kurtosis-cdk"
ref: "v0.2.19"
ref: "v0.2.21"

- name: Setup Bats and bats libs
uses: bats-core/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ RUN cargo build --release --bin cdk
# CONTAINER FOR RUNNING BINARY
FROM --platform=${BUILDPLATFORM} debian:bookworm-slim

RUN apt-get update && apt-get install -y ca-certificates postgresql-client libssl-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y ca-certificates sqlite3 procps libssl-dev && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/cdk /usr/local/bin/
COPY --from=build /go/src/github.com/0xPolygon/cdk/target/cdk-node /usr/local/bin/

Expand Down
3 changes: 0 additions & 3 deletions aggsender/types/epoch_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,3 @@ type EpochNotifier interface {
Start(ctx context.Context)
String() string
}

type BridgeL2Syncer interface {
}
13 changes: 9 additions & 4 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,27 @@ generate-mocks-bridgesync: ## Generates mocks for bridgesync, using mockery tool
.PHONY: test-e2e-fork9-validium
test-e2e-fork9-validium: stop
./run-e2e.sh fork9 cdk-validium
bats .
bats bats/fep/

.PHONY: test-e2e-fork11-rollup
test-e2e-fork11-rollup: stop
./run-e2e.sh fork11 rollup
bats .
bats bats/fep/

.PHONY: test-e2e-fork12-validium
test-e2e-fork12-validium: stop
./run-e2e.sh fork12 cdk-validium
bats .
bats bats/fep/

.PHONY: test-e2e-fork12-rollup
test-e2e-fork12-rollup: stop
./run-e2e.sh fork12 rollup
bats .
bats bats/fep/

.PHONY: test-e2e-fork12-pessimistic
test-e2e-fork12-pessimistic: stop
./run-e2e.sh fork12 pessimistic
bats bats/pp/

.PHONY: stop
stop:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setup() {
load 'helpers/common-setup'
load 'helpers/common'
load '../../helpers/common-setup'
load '../../helpers/common'
_common_setup

readonly erigon_sequencer_node=${KURTOSIS_ERIGON_SEQUENCER:-cdk-erigon-sequencer-001}
Expand Down
4 changes: 2 additions & 2 deletions test/basic-e2e.bats → test/bats/fep/basic-e2e.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setup() {
load 'helpers/common-setup'
load 'helpers/common'
load '../../helpers/common-setup'
load '../../helpers/common'
_common_setup

readonly sender_private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"}
Expand Down
6 changes: 3 additions & 3 deletions test/bridge-e2e.bats → test/bats/fep/bridge-e2e.bats
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
setup() {
load 'helpers/common-setup'
load '../../helpers/common-setup'
_common_setup
load 'helpers/common'
load 'helpers/lxly-bridge-test'
load '../../helpers/common'
load '../../helpers/lxly-bridge-test'

if [ -z "$BRIDGE_ADDRESS" ]; then
local combined_json_file="/opt/zkevm/combined.json"
Expand Down
4 changes: 2 additions & 2 deletions test/e2e.bats → test/bats/fep/e2e.bats
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
setup() {
load 'helpers/common-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
run $PROJECT_ROOT/../scripts/batch_verification_monitor.sh 0 600
assert_success
}
76 changes: 76 additions & 0 deletions test/bats/pp/bridge-e2e.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
setup() {
load '../../helpers/common-setup'
_common_setup
load '../../helpers/common'
load '../../helpers/lxly-bridge-test'

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 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}')
echo "Initial receiver balance of native token on L2 $initial_receiver_balance" >&3

echo "=== Running LxLy deposit on L1 to network: $l2_rpc_network_id native_token: $native_token_addr" >&3

destination_net=$l2_rpc_network_id
run bridgeAsset "$native_token_addr" "$l1_rpc_url"
assert_success

echo "=== Running 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 bridgeAsset "$weth_token_addr" "$l2_rpc_url"
assert_success
}

10 changes: 10 additions & 0 deletions test/bats/pp/e2e-pp.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 settle certificate...."
run $PROJECT_ROOT/../scripts/agglayer_certificates_monitor.sh 1 600
assert_success
}
14 changes: 14 additions & 0 deletions test/combinations/fork12-pessimistic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
args:
agglayer_image: ghcr.io/agglayer/agglayer:0.2.0-rc.11
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta8
cdk_node_image: cdk
zkevm_bridge_proxy_image: haproxy:3.0-bookworm
zkevm_bridge_service_image: hermeznetwork/zkevm-bridge-service:v0.6.0-RC1
zkevm_bridge_ui_image: leovct/zkevm-bridge-ui:multi-network
zkevm_contracts_image: nulyjkdhthz/zkevm-contracts:v9.0.0-rc.3-pp-fork.12
additional_services: []
consensus_contract_type: pessimistic
sequencer_type: erigon
erigon_strict_mode: false
zkevm_use_gas_token_contract: true
enable_normalcy: true
70 changes: 70 additions & 0 deletions test/scripts/agglayer_certificates_monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# This script monitors the agglayer certificates progress of pessimistic proof.

function parse_params(){
# Check if the required arguments are provided.
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <settle_certificates_target> <timeout>"
exit 1
fi

# The number of batches to be verified.
settle_certificates_target="$1"

# The script timeout (in seconds).
timeout="$2"
}

function check_timeout(){
local _end_time=$1
current_time=$(date +%s)
if ((current_time > _end_time)); then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ❌ Exiting... Timeout reached not found the expected numbers of settled certs!"
exit 1
fi
}

function check_num_certificates(){
local _cmd="echo 'select status, count(*) from certificate_info group by status;' | sqlite3 /tmp/aggsender.sqlite"
local _outcmd=$(mktemp)
kurtosis service exec cdk cdk-node-001 "$_cmd" > $_outcmd
if [ $? -ne 0 ]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Error executing command kurtosis service: $_cmd"
# clean temp file
rm $_outcmd
return
fi
local num_certs=$(cat $_outcmd | tail -n +2 | cut -f 2 -d '|' | xargs |tr ' ' '+' | bc)
# Get the number of settled certificates "4|0"
local _num_settle_certs=$(cat $_outcmd | tail -n +2 | grep ^${aggsender_status_settled} | cut -d'|' -f2)
[ -z "$_num_settle_certs" ] && _num_settle_certs=0
# clean temp file
rm $_outcmd
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Num certificates on aggsender: $num_certs. Settled certificates : $_num_settle_certs"
if [ $num_certs -ge $settle_certificates_target ]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ✅ Exiting... $num_certs certificates were settled! (total certs $num_certs)"
exit 0
fi
}

# MAIN
declare -A aggsender_status_map=(
[0]="Pending"
[1]="Proven"
[2]="Candidate"
[3]="InError"
[4]="Settled"
)

readonly aggsender_status_settled=4


parse_params $*
start_time=$(date +%s)
end_time=$((start_time + timeout))
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Start monitoring agglayer certificates progress..."
while true; do
check_num_certificates
check_timeout $end_time
sleep 10
done

0 comments on commit df57e65

Please sign in to comment.