Skip to content

Commit

Permalink
Code Clean Up
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdul Rabbani committed Mar 30, 2022
1 parent fc6a937 commit a60d5a0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 38 deletions.
4 changes: 4 additions & 0 deletions related-repositories/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ It is recommended that you move the following repositories under this folder. Ke
## Symlinks

You can also create symlinks in this folder with the location of your repositories.

# Dependencies

If you want to use `foundry-test`, you will need to utilize the recommended setup.
25 changes: 0 additions & 25 deletions statediff/indexer/database/sql/indexer_shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@ package sql_test

import (
"bytes"
"context"
"errors"
"fmt"
"os"
"testing"

"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/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/statediff/indexer/database/file"
"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"
)

var (
db sql.Database
sqlxdb *sqlx.DB
err error
ind interfaces.StateDiffIndexer
chainConf = params.MainnetChainConfig
Expand Down Expand Up @@ -156,25 +150,6 @@ func checkTxClosure(t *testing.T, idle, inUse, open int64) {
require.Equal(t, open, db.Stats().Open())
}

func setupDb(t *testing.T) (*sql.StateDiffIndexer, error) {
db, err = postgres.SetupSQLXDB()
if err != nil {
t.Fatal(err)
}
stateDiff, err := sql.NewStateDiffIndexer(context.Background(), chainConf, db)
return stateDiff, err
}

func setupFile(t *testing.T) interfaces.StateDiffIndexer {
if _, err := os.Stat(file.TestConfig.FilePath); !errors.Is(err, os.ErrNotExist) {
err := os.Remove(file.TestConfig.FilePath)
require.NoError(t, err)
}
ind, err = file.NewStateDiffIndexer(context.Background(), mocks.TestConfig, file.TestConfig)
require.NoError(t, err)
return ind
}

func tearDown(t *testing.T) {
sql.TearDownDB(t, db)
err := ind.Close()
Expand Down
8 changes: 1 addition & 7 deletions statediff/indexer/database/sql/mainnet_tests/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,12 @@ func testPushBlockAndState(t *testing.T, block *types.Block, receipts types.Rece
})
}

func setupDb(t *testing.T) (interfaces.StateDiffIndexer, error) {
func setup(t *testing.T, testBlock *types.Block, testReceipts types.Receipts) {
db, err = postgres.SetupSQLXDB()
if err != nil {
t.Fatal(err)
}
ind, err = sql.NewStateDiffIndexer(context.Background(), chainConf, db)
return ind, err
}

func setup(t *testing.T, testBlock *types.Block, testReceipts types.Receipts) (interfaces.StateDiffIndexer, interfaces.Batch) {
ind, err = setupDb(t)
require.NoError(t, err)
var tx interfaces.Batch
tx, err = ind.PushBlock(
Expand All @@ -105,7 +100,6 @@ func setup(t *testing.T, testBlock *types.Block, testReceipts types.Receipts) (i
}

test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, testBlock.Number().Uint64())
return ind, tx
}

func tearDown(t *testing.T) {
Expand Down
5 changes: 1 addition & 4 deletions statediff/known_gaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (
"testing"

"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
"github.com/stretchr/testify/require"
)

var (
chainConf = params.MainnetChainConfig
knownGapsFilePath = "./known_gaps.sql"
)

Expand Down Expand Up @@ -46,7 +44,7 @@ func TestKnownGaps(t *testing.T) {

testWriteToDb(t, tests, true)
testWriteToFile(t, tests, true)
//testFindAndUpdateGaps(t, true)
testFindAndUpdateGaps(t, true)
}

// test writing blocks to the DB
Expand Down Expand Up @@ -204,7 +202,6 @@ func setupDb(t *testing.T) sql.Database {
t.Error("Can't create a DB connection....")
t.Fatal(err)
}
// stateDiff, err := sql.NewStateDiffIndexer(context.Background(), chainConf, db)
return db
}

Expand Down
2 changes: 0 additions & 2 deletions statediff/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ type Service struct {
maxRetry uint
}

// This structure keeps track of the knownGaps at any given moment in time

// BlockCache caches the last block for safe access from different service loops
type BlockCache struct {
sync.Mutex
Expand Down

0 comments on commit a60d5a0

Please sign in to comment.