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

Commit

Permalink
tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Apr 15, 2024
1 parent 15593b1 commit 211587b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 13 additions & 0 deletions txmanager/pgstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

txmTypes "github.com/0xPolygon/agglayer/txmanager/types"
"github.com/0xPolygonHermez/zkevm-node/db"
"github.com/ethereum/go-ethereum/common"
"github.com/jackc/pgconn"
"github.com/jackc/pgx/v4"
Expand All @@ -25,6 +26,18 @@ func NewPostgresStorage(db *pgxpool.Pool) *PostgresStorage {
return &PostgresStorage{db}
}

// NewPostgresStorageWithCfg creates a new instance of storage that use based on provided config
func NewPostgresStorageWithCfg(dbCfg db.Config) (*PostgresStorage, error) {
db, err := db.NewSQLDB(dbCfg)
if err != nil {
return nil, err
}

return &PostgresStorage{
db,
}, nil
}

// Add persist a monitored tx
func (s *PostgresStorage) Add(ctx context.Context, mTx txmTypes.MonitoredTx, dbTx pgx.Tx) error {
conn := s.dbConn(dbTx)
Expand Down
12 changes: 6 additions & 6 deletions txmanager/pgstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newStateDBConfig(t *testing.T) db.Config {

func TestAddGetAndUpdate(t *testing.T) {
dbCfg := newStateDBConfig(t)
storage, err := NewPostgresStorage(dbCfg)
storage, err := NewPostgresStorageWithCfg(dbCfg)
require.NoError(t, err)

owner := "owner"
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestAddGetAndUpdate(t *testing.T) {

func TestAddAndGetByStatus(t *testing.T) {
dbCfg := newStateDBConfig(t)
storage, err := NewPostgresStorage(dbCfg)
storage, err := NewPostgresStorageWithCfg(dbCfg)
require.NoError(t, err)

to := common.HexToAddress("0x2")
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestAddAndGetByStatus(t *testing.T) {

func TestAddAndGetBySenderAndStatus(t *testing.T) {
dbCfg := newStateDBConfig(t)
storage, err := NewPostgresStorage(dbCfg)
storage, err := NewPostgresStorageWithCfg(dbCfg)
require.NoError(t, err)

from := common.HexToAddress("0x1")
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestAddAndGetBySenderAndStatus(t *testing.T) {

func TestAddRepeated(t *testing.T) {
dbCfg := newStateDBConfig(t)
storage, err := NewPostgresStorage(dbCfg)
storage, err := NewPostgresStorageWithCfg(dbCfg)
require.NoError(t, err)

owner := "owner"
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestAddRepeated(t *testing.T) {

func TestGetNotFound(t *testing.T) {
dbCfg := newStateDBConfig(t)
storage, err := NewPostgresStorage(dbCfg)
storage, err := NewPostgresStorageWithCfg(dbCfg)
require.NoError(t, err)

_, err = storage.Get(context.Background(), "not found owner", "not found id", nil)
Expand All @@ -329,7 +329,7 @@ func TestGetNotFound(t *testing.T) {

func TestGetByStatusNoRows(t *testing.T) {
dbCfg := newStateDBConfig(t)
storage, err := NewPostgresStorage(dbCfg)
storage, err := NewPostgresStorageWithCfg(dbCfg)
require.NoError(t, err)

mTxs, err := storage.GetByStatus(context.Background(), nil, []txmTypes.MonitoredTxStatus{}, nil)
Expand Down

0 comments on commit 211587b

Please sign in to comment.