Skip to content

Commit

Permalink
Merge pull request #650 from 0xPolygonHermez/feature/test_bridge_mess…
Browse files Browse the repository at this point in the history
…ages_real_netowrk

- Closes #651 If claim is disabled keep updating deposit status
- Closes #648 Error if rollup ID is 0
- It create a new suite for e2e test for real networks doing a bridgeMessage L1<->L2
  • Loading branch information
joanestebanr authored Jul 10, 2024
2 parents c520777 + a696532 commit c9d5006
Show file tree
Hide file tree
Showing 22 changed files with 1,753 additions and 144 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ on:
types: [opened, synchronize] # Trigger on new PR and existing with new commits
branches:
- develop


jobs:
deploy_devnet:
regression_tests:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout Repository
uses: actions/checkout@v2

- name: Build image (with proposed code changes) locally
id: build
Expand All @@ -22,13 +22,14 @@ jobs:
echo $GITHUB_SHA_SHORT
echo "::set-output name=GITHUB_SHA_SHORT::$GITHUB_SHA_SHORT"
fi
- name: Set up Docker
uses: docker/setup-buildx-action@v1

- name: Run regression tests against JIT container image
- name: Run Regression Tests
uses: 0xPolygon/kurtosis-cdk@v0.1.9
with:
zkevm_bridge_service: ${{ steps.build.outputs.GITHUB_SHA_SHORT }}
kurtosis_cli: 0.89.3
kurtosis_cdk: v0.2.0
zkevm_agglayer: '0.1.4'
zkevm_bridge_ui: '0006445'
zkevm_dac: '0.0.7'
zkevm_node: '0.6.5-cdk'
kurtosis_cdk: 'v0.2.3'
kurtosis_cli: '0.89.3'
bake_time: 30
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Test-e2e
on:
push:
branches:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2ecompress.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Test-e2compress
on:
push:
branches:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-edge.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Test-edge
on:
push:
branches:
Expand Down
11 changes: 8 additions & 3 deletions DockerfileE2ETest
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ COPY . /src
RUN cd /src && make build-test-e2e-real_network

# CONTAINER FOR RUNNING BINARY
FROM alpine:3.16.0
COPY --from=build /src/dist/zkevm-bridge-e2e-real_network /app/zkevm-bridge-e2e-real_network
CMD ["/bin/sh", "-c", "/app/zkevm-bridge-e2e-real_network -test.failfast -test.v"]
FROM alpine:3.16.0 AS ERC20
COPY --from=build /src/dist/zkevm-bridge-e2e-real_network-erc20 /app/zkevm-bridge-e2e-real_network-erc20
CMD ["/bin/sh", "-c", "/app/zkevm-bridge-e2e-real_network-erc20 -test.failfast -test.v"]

# CONTAINER FOR RUNNING BINARY
FROM alpine:3.16.0 AS MSG
COPY --from=build /src/dist/zkevm-bridge-e2e-real_network-bridgemsg /app/zkevm-bridge-e2e-real_network-bridgemsg
CMD ["/bin/sh", "-c", "/app/zkevm-bridge-e2e-real_network-bridgemsg -test.failfast -test.v"]
24 changes: 16 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ build-docker: ## Builds a docker image with the zkevm bridge binary
docker build -t zkevm-bridge-service -f ./Dockerfile .

.PHONY: build-docker-e2e-real_network
build-docker-e2e-real_network: ## Builds a docker image with the zkevm bridge binary for e2e tests with real network
docker build -f DockerfileE2ETest . -t bridge-e2e-realnetwork-erc20
build-docker-e2e-real_network: build-docker-e2e-real_network-erc20 build-docker-e2e-real_network-msg ## Builds a docker image with the zkevm bridge binary for e2e tests with real network


.PHONY: build-docker-e2e-real_network-erc20
build-docker-e2e-real_network-erc20: ## Builds a docker image with the zkevm bridge binary for e2e ERC20 tests with real network
docker build -f DockerfileE2ETest . -t bridge-e2e-realnetwork-erc20 --target ERC20

.PHONY: build-docker-e2e-real_network-msg
build-docker-e2e-real_network-msg: ## Builds a docker image with the zkevm bridge binary for e2e BridgeMessage tests with real network
docker build -f DockerfileE2ETest . -t bridge-e2e-realnetwork-msg --target MSG

.PHONY: run-db-node
run-db-node: ## Runs the node database
Expand Down Expand Up @@ -270,8 +278,10 @@ test-e2ecompress: build-docker stop run ## Runs all tests checking race conditio

.PHONY: build-test-e2e-real_network
build-test-e2e-real_network: ## Build binary for e2e tests with real network
go test -c ./test/e2e/ -o dist/zkevm-bridge-e2e-real_network -tags='e2e_real_network_erc20'
./dist/zkevm-bridge-e2e-real_network -test.failfast -test.list Test
go test -c ./test/e2e/ -o dist/zkevm-bridge-e2e-real_network-erc20 -tags='e2e_real_network_erc20'
go test -c ./test/e2e/ -o dist/zkevm-bridge-e2e-real_network-bridgemsg -tags='e2e_real_network_msg'
./dist/zkevm-bridge-e2e-real_network-erc20 -test.failfast -test.list Test
./dist/zkevm-bridge-e2e-real_network-bridgemsg -test.failfast -test.list Test

.PHONY: validate
validate: lint build test-full ## Validates the whole integrity of the code base
Expand Down Expand Up @@ -299,9 +309,7 @@ generate-mocks: ## Generates mocks for the tests, using mockery tool
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --all --case snake --dir claimtxman/ --output claimtxman/mocks --outpkg mock_txcompressor ${COMMON_MOCKERY_PARAMS}


.PHONY: generate-smart-contracts-bindings
.PHONY: generate-smartcontracts-bindings
generate-smartcontracts-bindings: ## Generates the smart contracts bindings
@for contract in `ls -1 etherman/smartcontracts/json/*.json | xargs -l basename`; do \
./scripts/generate-smartcontracts-bindings.sh $${contract%.*}; \
done
cd scripts && ./generate-smartcontracts-bindings.sh

5 changes: 5 additions & 0 deletions claimtxman/claimtxman.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func (tm *ClaimTxManager) processDepositStatus(ger *etherman.GlobalExitRoot, dbT
log.Errorf("error getting and updating L1DepositsStatus. Error: %v", err)
return err
}
if !tm.cfg.Enabled {
log.Infof("ClaimTxManager is disabled. No auto-claim")
return nil
}
for _, deposit := range deposits {
if tm.l2NetworkID != deposit.DestinationNetwork {
log.Infof("Ignoring deposit: %d: dest_net: %d, we are:%d", deposit.DepositCount, deposit.DestinationNetwork, tm.l2NetworkID)
Expand Down Expand Up @@ -223,6 +227,7 @@ func (tm *ClaimTxManager) processDepositStatus(ger *etherman.GlobalExitRoot, dbT
log.Errorf("error BuildSendClaim tx for deposit %d. Error: %v", deposit.DepositCount, err)
return err
}

if err = tm.addClaimTx(deposit.DepositCount, tm.auth.From, tx.To(), nil, tx.Data(), ger.GlobalExitRoot, dbTx); err != nil {
log.Errorf("error adding claim tx for deposit %d. Error: %v", deposit.DepositCount, err)
return err
Expand Down
65 changes: 25 additions & 40 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func start(ctx *cli.Context) error {
if err != nil {
return err
}
log.Infof("kzevmAddr = %s", c.NetworkConfig.PolygonZkEvmAddress.String())
log.Infof("RollupManagerAddress = %s", c.NetworkConfig.PolygonRollupManagerAddress.String())
setupLog(c.Log)
err = db.RunMigrations(c.SyncDB)
if err != nil {
Expand All @@ -55,11 +57,11 @@ func start(ctx *cli.Context) error {
}

networkID, err := l1Etherman.GetNetworkID(ctx.Context)
log.Infof("main network id: %d", networkID)
if err != nil {
log.Error(err)
return err
}
log.Infof("main network id: %d", networkID)

var networkIDs = []uint{networkID}
for _, client := range l2Ethermans {
Expand Down Expand Up @@ -114,46 +116,29 @@ func start(ctx *cli.Context) error {
go runSynchronizer(ctx.Context, 0, bridgeController, client, c.Synchronizer, storage, zkEVMClient, chExitRootEvent, chSynced)
}

if c.ClaimTxManager.Enabled {
for i := 0; i < len(c.Etherman.L2URLs); i++ {
// we should match the orders of L2URLs between etherman and claimtxman
// since we are using the networkIDs in the same order
ctx := context.Background()
client, err := utils.NewClient(ctx, c.Etherman.L2URLs[i], c.NetworkConfig.L2PolygonBridgeAddresses[i])
if err != nil {
log.Fatalf("error creating client for L2 %s. Error: %v", c.Etherman.L2URLs[i], err)
}
nonceCache, err := claimtxman.NewNonceCache(ctx, client)
if err != nil {
log.Fatalf("error creating nonceCache for L2 %s. Error: %v", c.Etherman.L2URLs[i], err)
}
auth, err := client.GetSignerFromKeystore(ctx, c.ClaimTxManager.PrivateKey)
if err != nil {
log.Fatalf("error creating signer for L2 %s. Error: %v", c.Etherman.L2URLs[i], err)
}

claimTxManager, err := claimtxman.NewClaimTxManager(ctx, c.ClaimTxManager, chExitRootEvent, chSynced,
c.Etherman.L2URLs[i], networkIDs[i+1], c.NetworkConfig.L2PolygonBridgeAddresses[i], bridgeService, storage, rollupID, l2Ethermans[i], nonceCache, auth)
if err != nil {
log.Fatalf("error creating claim tx manager for L2 %s. Error: %v", c.Etherman.L2URLs[i], err)
}
go claimTxManager.Start()
for i := 0; i < len(c.Etherman.L2URLs); i++ {
// we should match the orders of L2URLs between etherman and claimtxman
// since we are using the networkIDs in the same order
ctx := context.Background()
client, err := utils.NewClient(ctx, c.Etherman.L2URLs[i], c.NetworkConfig.L2PolygonBridgeAddresses[i])
if err != nil {
log.Fatalf("error creating client for L2 %s. Error: %v", c.Etherman.L2URLs[i], err)
}
} else {
log.Warn("ClaimTxManager not configured")
go func() {
for {
select {
case <-chExitRootEvent:
log.Debug("New GER received")
case netID := <-chSynced:
log.Debug("NetworkID synced: ", netID)
case <-ctx.Context.Done():
log.Debug("Stopping goroutine that listen new GER updates")
return
}
}
}()
nonceCache, err := claimtxman.NewNonceCache(ctx, client)
if err != nil {
log.Fatalf("error creating nonceCache for L2 %s. Error: %v", c.Etherman.L2URLs[i], err)
}
auth, err := client.GetSignerFromKeystore(ctx, c.ClaimTxManager.PrivateKey)
if err != nil {
log.Fatalf("error creating signer for L2 %s. Error: %v", c.Etherman.L2URLs[i], err)
}

claimTxManager, err := claimtxman.NewClaimTxManager(ctx, c.ClaimTxManager, chExitRootEvent, chSynced,
c.Etherman.L2URLs[i], networkIDs[i+1], c.NetworkConfig.L2PolygonBridgeAddresses[i], bridgeService, storage, rollupID, l2Ethermans[i], nonceCache, auth)
if err != nil {
log.Fatalf("error creating claim tx manager for L2 %s. Error: %v", c.Etherman.L2URLs[i], err)
}
go claimTxManager.Start()
}

// Wait for an in interrupt.
Expand Down
25 changes: 25 additions & 0 deletions docs/e2e-realnetwork-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Test Real network using e2e Test
This suite is for test the bridge service running in a real network.
The included tests are:
- ERC20 L1->L2 expecting auto-claim
- ERC20 L2->L1
- BridgeMessage L1->L2
- BridgeMessage L2->L1

# Build docker
First you need to build the docker that include the tests.
`make build-docker-e2e-real_network-ERC20`
or
`make build-docker-e2e-real_network-MSG`


## Create a config file
Check the config example `test/config/bridge_network_e2e/cardona.toml`

## Execute docker using the config file
- Create the config file in `/tmp/test.toml`
- Launch tests:
```
$ docker run --volume "./tmp/:/config/" --env BRIDGE_TEST_CONFIG_FILE=/config/test.toml bridge-e2e-realnetwork-erc20
$docker run --volume "./tmp/:/config/" --env BRIDGE_TEST_CONFIG_FILE=/config/test.toml bridge-e2e-realnetwork-erc20
```
3 changes: 3 additions & 0 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ func NewClient(cfg Config, polygonBridgeAddr, polygonZkEVMGlobalExitRootAddress,
return nil, err
}
log.Debug("rollupID: ", rollupID)
if rollupID == 0 {
return nil, fmt.Errorf("rollupID is 0, this is not allowed. Check the rollup contract (%s)", polygonZkEvmAddress.String())
}
var scAddresses []common.Address
scAddresses = append(scAddresses, polygonZkEVMGlobalExitRootAddress, polygonBridgeAddr, polygonRollupManagerAddress)

Expand Down
2 changes: 1 addition & 1 deletion etherman/smartcontracts/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The folder `generated_binding` have autogenerated files to use the contracts
You can generate from root folder project invoking:
```
make generate-smartcontracts-bindings
make generate-smartcontracts-bindings
```

## Folder json
Expand Down
7 changes: 7 additions & 0 deletions scripts/generate-smartcontracts-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ gen() {
abigen --bin ${OUTPUT_BASE_DIR}/bin/${package}.bin --abi ${OUTPUT_BASE_DIR}/abi/${package}.abi --pkg=${package} --out=${OUTPUT_BASE_DIR}/${package}/${package}.go
}

gen_from_json(){
local package=$1
mkdir -p ${OUTPUT_BASE_DIR}/${package}
abigen --combined-json ${OUTPUT_BASE_DIR}/json/${package}.json --pkg=${package} --out=${OUTPUT_BASE_DIR}/${package}/${package}.go
}

#gen_from_json pingreceiver
gen claimcompressor
Loading

0 comments on commit c9d5006

Please sign in to comment.