Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Unit test Etherman #28

Merged
merged 15 commits into from
Dec 15, 2023
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
docker/data
.idea
coverage.out
17 changes: 15 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import (
"os/signal"
"time"

beethoven "github.com/0xPolygon/beethoven"
"github.com/0xPolygon/cdk-data-availability/dummyinterfaces"
dbConf "github.com/0xPolygon/cdk-validium-node/db"
"github.com/0xPolygon/cdk-validium-node/ethtxmanager"
"github.com/0xPolygon/cdk-validium-node/jsonrpc"
"github.com/0xPolygon/cdk-validium-node/log"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/sdk/metric"

beethoven "github.com/0xPolygon/beethoven"
"github.com/0xPolygon/beethoven/config"
"github.com/0xPolygon/beethoven/db"
"github.com/0xPolygon/beethoven/etherman"
Expand Down Expand Up @@ -93,7 +94,19 @@ func start(cliCtx *cli.Context) error {
if err != nil {
log.Fatal(err)
}
ethMan, err := etherman.New(cliCtx.Context, c.L1.NodeURL, *auth)

// Connect to ethereum node
ethClient, err := ethclient.DialContext(cliCtx.Context, c.L1.NodeURL)
if err != nil {
log.Fatal("error connecting to %s: %+v", c.L1.NodeURL, err)
}

// Make sure the connection is okay
if _, err = ethClient.ChainID(cliCtx.Context); err != nil {
log.Fatal("error getting chain ID from l1 with address: %+v", err)
}

ethMan, err := etherman.New(ethClient, *auth)
if err != nil {
log.Fatal(err)
}
Expand Down
21 changes: 5 additions & 16 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package etherman
import (
"context"
"errors"
"github.com/jackc/pgx/v4"
"math/big"
"time"

Expand All @@ -15,29 +16,14 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/jackc/pgx/v4"
)

type Etherman struct {
ethClient EthereumClient
auth bind.TransactOpts
}

func New(ctx context.Context, url string, auth bind.TransactOpts) (Etherman, error) {
// Connect to ethereum node
ethClient, err := ethclient.DialContext(ctx, url)
if err != nil {
log.Errorf("error connecting to %s: %+v", url, err)
return Etherman{}, err
}

// Make sure the connection is okay
if _, err = ethClient.ChainID(ctx); err != nil {
log.Errorf("error getting chain ID from l1 with %s address: %+v", url, err)
return Etherman{}, err
}

func New(ethClient EthereumClient, auth bind.TransactOpts) (Etherman, error) {
return Etherman{
ethClient: ethClient,
auth: auth,
Expand All @@ -49,6 +35,7 @@ func (e *Etherman) GetSequencerAddr(l1Contract common.Address) (common.Address,
if err != nil {
return common.Address{}, err
}

return contract.TrustedSequencer(&bind.CallOpts{Pending: false})
}

Expand All @@ -69,6 +56,7 @@ func (e *Etherman) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVerifie
log.Errorf("error geting ABI: %v, Proof: %s", err)
return nil, err
}

return abi.Pack(
"verifyBatchesTrustedAggregator",
pendStateNum,
Expand Down Expand Up @@ -177,6 +165,7 @@ func (e *Etherman) GetRevertMessage(ctx context.Context, tx *types.Transaction)

if receipt.Status == types.ReceiptStatusFailed {
revertMessage, err := operations.RevertReason(ctx, e.ethClient, tx, receipt.BlockNumber)

if err != nil {
return "", err
}
Expand Down
Loading
Loading