Skip to content

Commit

Permalink
feat: integrate aggsender_find_imported_bridgeto e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Dec 18, 2024
1 parent 046b264 commit aab2021
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
3 changes: 3 additions & 0 deletions aggsender/rpc/aggsender_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ func (b *AggsenderRPC) GetCertificateHeaderPerHeight(height *uint64) (interface{
if err != nil {
return nil, rpc.NewRPCError(rpc.DefaultErrorCode, fmt.Sprintf("error getting certificate by height: %v", err))
}
if certInfo == nil {
return nil, rpc.NewRPCError(rpc.NotFoundErrorCode, "certificate not found")
}
return certInfo, nil
}
23 changes: 17 additions & 6 deletions test/bats/pp-multi/bridge-l2_to_l2-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ setup() {
_common_multi_setup
load '../../helpers/common'
load '../../helpers/lxly-bridge-test'
load '../../helpers/aggsender'

add_cdk_network2_to_agglayer
fund_claim_tx_manager
mint_pol_token
if [ ! -f $aggsender_find_imported_bridge ]; then
echo "missing required tool: $aggsender_find_imported_bridge" >&3
return 1
fi

#add_cdk_network2_to_agglayer
#fund_claim_tx_manager
#mint_pol_token

ether_value=${ETHER_VALUE:-"0.0200000054"}
amount=$(cast to-wei $ether_value ether)
Expand All @@ -24,6 +30,9 @@ setup() {
claim_frequency="30"

gas_price=$(cast gas-price --rpc-url "$l2_rpc_url")



}

@test "Test L2 to L2 bridge" {
Expand Down Expand Up @@ -72,7 +81,9 @@ setup() {
assert_success

echo "=== Check if deposit is in a settled certificate"

aggsender_pp1_url=http://localhost:5576/
../../../../target/aggsender_find_imported_bridge $aggsender_pp1_url $global_index_pp2_to_pp1
echo "$aggsender_find_imported_bridge $l2_pp1_cdk_node_url $global_index_pp2_to_pp1"

echo "=== Waiting to settled certificate with imported bridge for global_index: $global_index_pp2_to_pp1"
wait_to_settled_certificate_containing_global_index $l2_pp1_cdk_node_url $global_index_pp2_to_pp1

}
10 changes: 10 additions & 0 deletions test/helpers/aggsender.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

function wait_to_settled_certificate_containing_global_index(){
local _l2_pp1_cdk_node_url=$1
local _global_index=$2
local _check_frequency=${3:-30}
local _timeout=${4:-300}
echo "... waiting for certificate with global index $_global_index" >&3
run_with_timeout "settle cert for $_global_index" $_check_frequency $_timeout $aggsender_find_imported_bridge $_l2_pp1_cdk_node_url $_global_index
}
5 changes: 4 additions & 1 deletion test/helpers/common-multi_cdk-setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ _common_multi_setup() {
readonly gas_token_address=$(<gas-token-address.json)
readonly l2_pp1b_url=$(kurtosis port print $enclave zkevm-bridge-service-001 rpc)
readonly l2_pp2b_url=$(kurtosis port print $enclave zkevm-bridge-service-002 rpc)

readonly l2_pp1_cdk_node_url=$(kurtosis port print $enclave cdk-node-001 rpc)
readonly l2_pp2_cdk_node_url=$(kurtosis port print $enclave cdk-node-002 rpc)

#readonly l1_rpc_network_id=$(cast call --rpc-url $l1_rpc_url $bridge_addr 'networkID() (uint32)')
#readonly l2_pp1b_network_id=$(cast call --rpc-url $l2_pp1_url $bridge_addr 'networkID() (uint32)')
#readonly l2_pp2b_network_id=$(cast call --rpc-url $l2_pp2_url $bridge_addr 'networkID() (uint32)')
readonly l1_rpc_network_id=0
readonly l2_pp1b_network_id=1
readonly l2_pp2b_network_id=2
readonly aggsender_find_imported_bridge="../target/aggsender_find_imported_bridge"
echo "=== Bridge address=$bridge_address ===" >&3
echo "=== POL address=$pol_address ===" >&3
echo "=== Gas token address=$gas_token_address ===" >&3
Expand Down
26 changes: 26 additions & 0 deletions test/helpers/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,29 @@ function mint_erc20_tokens() {
run send_tx "$rpc_url" "$minter_private_key" "$erc20_token_addr" "$mint_fn_sig" "$receiver" "$tokens_amount"
assert_success
}

function run_with_timeout(){
local name="$1"
local run_frequency=$2
local timeout=$3
shift 3
local start_time=$(date +%s)
local end_time=$((start_time + timeout))
while true; do
local current_time=$(date +%s)
if ((current_time > end_time)); then
echo "....[$(date '+%Y-%m-%d %H:%M:%S')] ❌ Exiting [$name]... Timeout reached!" >&3
exit 1
fi
echo "....[$(date '+%Y-%m-%d %H:%M:%S')] ⏳Running [$name] ..." >&3
echo "executing: $*"
run $*
echo "result: $status"
if [ $status -eq 0 ]; then
echo "....[$(date '+%Y-%m-%d %H:%M:%S')] ✅ successful [$name] " >&3
break
fi
echo "....[$(date '+%Y-%m-%d %H:%M:%S')] ⏳ Sleep [$name] time: $run_frequency" >&3
sleep "$run_frequency"
done
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func certContainsGlobalIndex(cert *types.CertificateInfo, globalIndex *agglayer.
var certSigned agglayer.SignedCertificate
err := json.Unmarshal([]byte(cert.SignedCertificate), &certSigned)
if err != nil {
return false, err
log.Debugf("cert: %v", cert.SignedCertificate)
return false, fmt.Errorf("error Unmarshal cert. Err: %w", err)
}
for _, importedBridge := range certSigned.ImportedBridgeExits {
if *importedBridge.GlobalIndex == *globalIndex {
Expand All @@ -77,6 +78,7 @@ func main() {
log.Errorf("Error: %v", err)
os.Exit(errLevelComms)
}

currentHeight := cert.Height
for cert != nil {
found, err := certContainsGlobalIndex(cert, decodedGlobalIndex)
Expand Down

0 comments on commit aab2021

Please sign in to comment.