Skip to content

Commit

Permalink
linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
i-norden committed Nov 12, 2021
1 parent 5f4968b commit 9a67034
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 87 deletions.
5 changes: 1 addition & 4 deletions statediff/indexer/database/dump/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,7 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *BatchTx, args processArgs
Data: trx.Data(),
CID: txNode.Cid().String(),
MhKey: shared.MultihashKeyFromCID(txNode.Cid()),
}
txType := trx.Type()
if txType != types.LegacyTxType {
txModel.Type = &txType
Type: trx.Type(),
}
if _, err := fmt.Fprintf(sdi.dump, "%+v\r\n", txModel); err != nil {
return err
Expand Down
5 changes: 1 addition & 4 deletions statediff/indexer/database/sql/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,7 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *BatchTx, args processArgs
Data: trx.Data(),
CID: txNode.Cid().String(),
MhKey: shared.MultihashKeyFromCID(txNode.Cid()),
}
txType := trx.Type()
if txType != types.LegacyTxType {
txModel.Type = &txType
Type: trx.Type(),
}
txID, err := sdi.dbWriter.upsertTransactionCID(tx.dbtx, txModel, args.headerID)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion statediff/indexer/database/sql/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ type Tx interface {
// ScannableRow interface to accommodate different concrete row types
type ScannableRow interface {
Scan(dest ...interface{}) error
StructScan(dest interface{}) error
}

// Result interface to accommodate different concrete result types
Expand Down
3 changes: 2 additions & 1 deletion statediff/indexer/database/sql/pgx_indexer_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"testing"

"github.com/jmoiron/sqlx"
"github.com/multiformats/go-multihash"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -76,7 +77,7 @@ func TestPGXIndexerLegacy(t *testing.T) {
}
header := new(res)

err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).StructScan(header)
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
require.NoError(t, err)

test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String())
Expand Down
32 changes: 13 additions & 19 deletions statediff/indexer/database/sql/pgx_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
dshelp "github.com/ipfs/go-ipfs-ds-help"
"github.com/jmoiron/sqlx"
"github.com/multiformats/go-multihash"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -164,7 +165,7 @@ func TestPGXIndexer(t *testing.T) {
BaseFee *int64 `db:"base_fee"`
}
header := new(res)
err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).StructScan(header)
err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -216,12 +217,12 @@ func TestPGXIndexer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
txTypePgStr := `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
switch c {
case trx1CID.String():
test_helpers.ExpectEqual(t, data, tx1)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
Expand All @@ -231,8 +232,7 @@ func TestPGXIndexer(t *testing.T) {
case trx2CID.String():
test_helpers.ExpectEqual(t, data, tx2)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
Expand All @@ -242,8 +242,7 @@ func TestPGXIndexer(t *testing.T) {
case trx3CID.String():
test_helpers.ExpectEqual(t, data, tx3)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
Expand All @@ -253,8 +252,7 @@ func TestPGXIndexer(t *testing.T) {
case trx4CID.String():
test_helpers.ExpectEqual(t, data, tx4)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -284,8 +282,7 @@ func TestPGXIndexer(t *testing.T) {
case trx5CID.String():
test_helpers.ExpectEqual(t, data, tx5)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -398,6 +395,7 @@ func TestPGXIndexer(t *testing.T) {
t.Fatal(err)
}

postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
switch c {
case rct1CID.String():
test_helpers.ExpectEqual(t, data, rct1)
Expand All @@ -411,35 +409,31 @@ func TestPGXIndexer(t *testing.T) {
case rct2CID.String():
test_helpers.ExpectEqual(t, data, rct2)
var postState string
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
err = db.Get(context.Background(), &postState, pgStr, c)
err = db.Get(context.Background(), &postState, postStatePgStr, c)
if err != nil {
t.Fatal(err)
}
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState1)
case rct3CID.String():
test_helpers.ExpectEqual(t, data, rct3)
var postState string
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
err = db.Get(context.Background(), &postState, pgStr, c)
err = db.Get(context.Background(), &postState, postStatePgStr, c)
if err != nil {
t.Fatal(err)
}
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState2)
case rct4CID.String():
test_helpers.ExpectEqual(t, data, rct4)
var postState string
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
err = db.Get(context.Background(), &postState, pgStr, c)
err = db.Get(context.Background(), &postState, postStatePgStr, c)
if err != nil {
t.Fatal(err)
}
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
case rct5CID.String():
test_helpers.ExpectEqual(t, data, rct5)
var postState string
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
err = db.Get(context.Background(), &postState, pgStr, c)
err = db.Get(context.Background(), &postState, postStatePgStr, c)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion statediff/indexer/database/sql/postgres/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
)

// DriverType to explicity type the kind of sql driver we are using
// DriverType to explicitly type the kind of sql driver we are using
type DriverType string

const (
Expand Down
20 changes: 2 additions & 18 deletions statediff/indexer/database/sql/postgres/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ func (pgx *PGXDriver) createNode() error {

// QueryRow satisfies sql.Database
func (pgx *PGXDriver) QueryRow(ctx context.Context, sql string, args ...interface{}) sql.ScannableRow {
rows, _ := pgx.pool.Query(ctx, sql, args...)
return rowsWrapper{rows: rows}
return pgx.pool.QueryRow(ctx, sql, args...)
}

// Exec satisfies sql.Database
Expand Down Expand Up @@ -160,20 +159,6 @@ func (pgx *PGXDriver) Context() context.Context {
return pgx.ctx
}

type rowsWrapper struct {
rows pgx.Rows
}

// Scan satisfies sql.ScannableRow
func (r rowsWrapper) Scan(dest ...interface{}) error {
return (pgx.Row)(r.rows).Scan(dest...)
}

// StructScan satisfies sql.ScannableRow
func (r rowsWrapper) StructScan(dest interface{}) error {
return pgxscan.ScanRow(dest, r.rows)
}

type resultWrapper struct {
ct pgconn.CommandTag
}
Expand Down Expand Up @@ -234,8 +219,7 @@ type pgxTxWrapper struct {

// QueryRow satisfies sql.Tx
func (t pgxTxWrapper) QueryRow(ctx context.Context, sql string, args ...interface{}) sql.ScannableRow {
rows, _ := t.tx.Query(ctx, sql, args...)
return rowsWrapper{rows: rows}
return t.tx.QueryRow(ctx, sql, args...)
}

// Exec satisfies sql.Tx
Expand Down
8 changes: 4 additions & 4 deletions statediff/indexer/database/sql/sqlx_indexer_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import (
"context"
"testing"

"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"

"github.com/ipfs/go-cid"
"github.com/jmoiron/sqlx"
"github.com/multiformats/go-multihash"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
"github.com/ethereum/go-ethereum/statediff/indexer/test_helpers"
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestSQLXIndexerLegacy(t *testing.T) {
BaseFee *int64 `db:"base_fee"`
}
header := new(res)
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).StructScan(header)
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
require.NoError(t, err)

test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String())
Expand Down
57 changes: 25 additions & 32 deletions statediff/indexer/database/sql/sqlx_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
dshelp "github.com/ipfs/go-ipfs-ds-help"
"github.com/jmoiron/sqlx"
"github.com/multiformats/go-multihash"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -190,7 +191,7 @@ func TestSQLXIndexer(t *testing.T) {
BaseFee *int64 `db:"base_fee"`
}
header := new(res)
err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).StructScan(header)
err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -242,50 +243,47 @@ func TestSQLXIndexer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
txTypePgStr := `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
switch c {
case trx1CID.String():
test_helpers.ExpectEqual(t, data, tx1)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
var txType uint8
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
if txType != nil {
t.Fatalf("expected nil tx_type, got %d", *txType)
if txType != 0 {
t.Fatalf("expected LegacyTxType (0), got %d", txType)
}
case trx2CID.String():
test_helpers.ExpectEqual(t, data, tx2)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
var txType uint8
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
if txType != nil {
t.Fatalf("expected nil tx_type, got %d", *txType)
if txType != 0 {
t.Fatalf("expected LegacyTxType (0), got %d", txType)
}
case trx3CID.String():
test_helpers.ExpectEqual(t, data, tx3)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
var txType uint8
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
if txType != nil {
t.Fatalf("expected nil tx_type, got %d", *txType)
if txType != 0 {
t.Fatalf("expected LegacyTxType (0), got %d", txType)
}
case trx4CID.String():
test_helpers.ExpectEqual(t, data, tx4)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
var txType uint8
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
if *txType != types.AccessListTxType {
t.Fatalf("expected AccessListTxType (1), got %d", *txType)
if txType != types.AccessListTxType {
t.Fatalf("expected AccessListTxType (1), got %d", txType)
}
accessListElementModels := make([]models.AccessListElementModel, 0)
pgStr = `SELECT access_list_element.* FROM eth.access_list_element INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.id) WHERE cid = $1 ORDER BY access_list_element.index ASC`
Expand All @@ -310,8 +308,7 @@ func TestSQLXIndexer(t *testing.T) {
case trx5CID.String():
test_helpers.ExpectEqual(t, data, tx5)
var txType *uint8
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
err = db.Get(context.Background(), &txType, pgStr, c)
err = db.Get(context.Background(), &txType, txTypePgStr, c)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -423,7 +420,7 @@ func TestSQLXIndexer(t *testing.T) {
if err != nil {
t.Fatal(err)
}

postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
switch c {
case rct1CID.String():
test_helpers.ExpectEqual(t, data, rct1)
Expand All @@ -437,35 +434,31 @@ func TestSQLXIndexer(t *testing.T) {
case rct2CID.String():
test_helpers.ExpectEqual(t, data, rct2)
var postState string
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
err = db.Get(context.Background(), &postState, pgStr, c)
err = db.Get(context.Background(), &postState, postStatePgStr, c)
if err != nil {
t.Fatal(err)
}
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState1)
case rct3CID.String():
test_helpers.ExpectEqual(t, data, rct3)
var postState string
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
err = db.Get(context.Background(), &postState, pgStr, c)
err = db.Get(context.Background(), &postState, postStatePgStr, c)
if err != nil {
t.Fatal(err)
}
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState2)
case rct4CID.String():
test_helpers.ExpectEqual(t, data, rct4)
var postState string
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
err = db.Get(context.Background(), &postState, pgStr, c)
err = db.Get(context.Background(), &postState, postStatePgStr, c)
if err != nil {
t.Fatal(err)
}
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
case rct5CID.String():
test_helpers.ExpectEqual(t, data, rct5)
var postState string
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
err = db.Get(context.Background(), &postState, pgStr, c)
err = db.Get(context.Background(), &postState, postStatePgStr, c)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion statediff/indexer/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type TxModel struct {
Dst string `db:"dst"`
Src string `db:"src"`
Data []byte `db:"tx_data"`
Type *uint8 `db:"tx_type"`
Type uint8 `db:"tx_type"`
}

// AccessListElementModel is the db model for eth.access_list_entry
Expand Down
Loading

0 comments on commit 9a67034

Please sign in to comment.