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

Feature/integration test in CI #11

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 59 additions & 0 deletions .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Regression Tests

on:
workflow_dispatch:
inputs:
zkevm_agglayer:
description: 0xPolygon/agglayer (short commit hash or release tag)
required: true
default: 0.1.4
zkevm_bridge_service:
description: 0xPolygonHermez/zkevm-bridge-service (short commit hash or release tag)
required: true
default: v0.4.2
zkevm_bridge_ui:
description: 0xPolygonHermez/zkevm-bridge-ui (short commit hash or release tag)
required: true
default: '0006445'
zkevm_dac:
description: 0xPolygon/cdk-data-availability (short commit hash or release tag)
required: true
default: 0.0.7
zkevm_node:
description: 0xPolygon/cdk-validium-node (short commit hash or release tag)
required: true
default: 0.6.5-cdk
kurtosis_cli:
description: kurtosis-tech/kurtosis (release tag)
required: false
default: 0.89.3
kurtosis_cdk:
description: 0xPolygon/kurtosis-cdk (release tag)
required: false
default: v0.2.0
bake_time:
description: bake time (minutes)
required: false
default: '30'

jobs:
regression_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Run Regression Tests
uses: 0xPolygon/[email protected]
with:
zkevm_agglayer: ${{ github.event.inputs.zkevm_agglayer }}
zkevm_bridge_service: ${{ github.event.inputs.zkevm_bridge_service }}
zkevm_bridge_ui: ${{ github.event.inputs.zkevm_bridge_ui }}
zkevm_dac: ${{ github.event.inputs.zkevm_dac }}
zkevm_node: ${{ github.event.inputs.zkevm_node }}
kurtosis_cli: ${{ github.event.inputs.kurtosis_cli }}
kurtosis_cdk: ${{ github.event.inputs.kurtosis_cdk }}
bake_time: ${{ github.event.inputs.bake_time }}
- name: Run Integration Tests
run: |
echo "Running Integration Tests"
make -f ./tests/Makefile run-tests
4 changes: 4 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.PHONY: run-tests
run-tests: ## Runs all tests within the workspace
go test -v -race ./...

.PHONY: generate-mocks
generate-mocks: generate-mocks-localbridgesync

Expand Down
49 changes: 49 additions & 0 deletions test/ethtransfer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package test

import (
"math/big"
"testing"
"time"

"github.com/0xPolygon/cdk/test/operations"
"github.com/stretchr/testify/require"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/jsonrpc"
"github.com/umbracle/ethgo/wallet"
)

func TestEthTransfer(t *testing.T) {
operations.L2RPCURL = operations.GetL2RPCURL()

const amountOfTxsToSend = 10
client, err := jsonrpc.NewClient(operations.L2RPCURL)
require.NoError(t, err)
key, err := operations.GetL2Wallet()
require.NoError(t, err)
signer := wallet.NewEIP155Signer(operations.L2ChainID)
initialNonce, err := client.Eth().GetNonce(key.Address(), ethgo.Latest)
require.NoError(t, err)
gasPrice, err := client.Eth().GasPrice()
require.NoError(t, err)

txHashes := []ethgo.Hash{}
for i := 0; i < amountOfTxsToSend; i++ {
tx := &ethgo.Transaction{
ChainID: big.NewInt(operations.L2ChainID),
Nonce: initialNonce + uint64(i),
GasPrice: gasPrice,
Gas: 21000,
To: &ethgo.ZeroAddress,
}
signedTxn, err := signer.SignTx(tx, key)
require.NoError(t, err)
rawTx, err := signedTxn.MarshalRLPTo(nil)
require.NoError(t, err)
hash, err := client.Eth().SendRawTransaction(rawTx)
require.NoError(t, err)
txHashes = append(txHashes, hash)
}
for _, h := range txHashes {
require.NoError(t, operations.WaitTxToBeMined(h, operations.Verified, client, time.Minute*2))
}
}
34 changes: 34 additions & 0 deletions test/operations/operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package operations

import(
"encoding/hex"
"github.com/umbracle/ethgo/wallet"
)

const (
L1RPCURL = "http://el-1-geth-lighthouse:8545"
L2ChainID = 10101

// Prefunded account present on kurtosis-cdk
PrivateKeyWithFundsOnL2 = "12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"
)

var L2RPCURL = "http://localhost:8123"

func GetL2Wallet() (*wallet.Key, error) {
prvKeyBytes, err := hex.DecodeString(PrivateKeyWithFundsOnL2)
if err != nil {
return nil, err
}
return wallet.NewWalletFromPrivKey(prvKeyBytes)
}

func GetL2RPCURL() string {
cmd := exec.Command("kurtosis", "port", "print", "cdk-v1", "zkevm-node-rpc-001", "http-rpc")
output, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("Failed to execute command: %s", err)
}

return strings.TrimSpace(string(output))
}
67 changes: 67 additions & 0 deletions test/operations/transactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package operations

import (
"errors"
"fmt"
"time"

"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/jsonrpc"
)

type ConfirmationLevel string

const (
Trusted ConfirmationLevel = "trusted"
Virtual ConfirmationLevel = "virtual"
Verified ConfirmationLevel = "verified"
)

func WaitTxToBeMined(hash ethgo.Hash, level ConfirmationLevel, client *jsonrpc.Client, timeout time.Duration) error {
startingTime := time.Now()
fmt.Printf("waiting for tx %s to be included in the %s state\n", hash.String(), level)
var (
encodedL2BlockNumber string
isVirtualized bool
isVerified bool
)
for time.Since(startingTime) < timeout {
if encodedL2BlockNumber == "" {
receipt, err := client.Eth().GetTransactionReceipt(hash)
if err != nil || receipt == nil {
time.Sleep(time.Second)
continue
}
fmt.Printf("tx %s included in the trusted state at the L2 block %d\n", hash.String(), receipt.BlockNumber)
if level == Trusted {
return nil
}
encodedL2BlockNumber = fmt.Sprintf("0x%x", receipt.BlockNumber)
}

if !isVirtualized {
if err := client.Call("zkevm_isBlockVirtualized", &isVirtualized, encodedL2BlockNumber); err != nil {
time.Sleep(time.Second)
continue
}
if isVirtualized {
fmt.Printf("tx %s included in the virtual state\n", hash.String())
if level == Virtual {
return nil
}
} else {
time.Sleep(time.Second)
continue
}
}
if err := client.Call("zkevm_isBlockConsolidated", &isVerified, encodedL2BlockNumber); err != nil {
time.Sleep(time.Second)
continue
}
if isVerified {
fmt.Printf("tx %s included in the verified state\n", hash.String())
return nil
}
}
return errors.New("timed out")
}
Loading