Code Clean Up
This commit is contained in:
parent
fc6a9379e1
commit
a60d5a016d
@ -14,3 +14,7 @@ It is recommended that you move the following repositories under this folder. Ke
|
|||||||
## Symlinks
|
## Symlinks
|
||||||
|
|
||||||
You can also create symlinks in this folder with the location of your repositories.
|
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.
|
||||||
|
@ -2,23 +2,18 @@ package sql_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"github.com/multiformats/go-multihash"
|
"github.com/multiformats/go-multihash"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"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"
|
||||||
"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/interfaces"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
|
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
|
||||||
@ -26,7 +21,6 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
db sql.Database
|
db sql.Database
|
||||||
sqlxdb *sqlx.DB
|
|
||||||
err error
|
err error
|
||||||
ind interfaces.StateDiffIndexer
|
ind interfaces.StateDiffIndexer
|
||||||
chainConf = params.MainnetChainConfig
|
chainConf = params.MainnetChainConfig
|
||||||
@ -156,25 +150,6 @@ func checkTxClosure(t *testing.T, idle, inUse, open int64) {
|
|||||||
require.Equal(t, open, db.Stats().Open())
|
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) {
|
func tearDown(t *testing.T) {
|
||||||
sql.TearDownDB(t, db)
|
sql.TearDownDB(t, db)
|
||||||
err := ind.Close()
|
err := ind.Close()
|
||||||
|
@ -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()
|
db, err = postgres.SetupSQLXDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ind, err = sql.NewStateDiffIndexer(context.Background(), chainConf, db)
|
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)
|
require.NoError(t, err)
|
||||||
var tx interfaces.Batch
|
var tx interfaces.Batch
|
||||||
tx, err = ind.PushBlock(
|
tx, err = ind.PushBlock(
|
||||||
@ -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())
|
test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, testBlock.Number().Uint64())
|
||||||
return ind, tx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func tearDown(t *testing.T) {
|
func tearDown(t *testing.T) {
|
||||||
|
@ -8,14 +8,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"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"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
chainConf = params.MainnetChainConfig
|
|
||||||
knownGapsFilePath = "./known_gaps.sql"
|
knownGapsFilePath = "./known_gaps.sql"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,7 +44,7 @@ func TestKnownGaps(t *testing.T) {
|
|||||||
|
|
||||||
testWriteToDb(t, tests, true)
|
testWriteToDb(t, tests, true)
|
||||||
testWriteToFile(t, tests, true)
|
testWriteToFile(t, tests, true)
|
||||||
//testFindAndUpdateGaps(t, true)
|
testFindAndUpdateGaps(t, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test writing blocks to the DB
|
// test writing blocks to the DB
|
||||||
@ -204,7 +202,6 @@ func setupDb(t *testing.T) sql.Database {
|
|||||||
t.Error("Can't create a DB connection....")
|
t.Error("Can't create a DB connection....")
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// stateDiff, err := sql.NewStateDiffIndexer(context.Background(), chainConf, db)
|
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,6 @@ type Service struct {
|
|||||||
maxRetry uint
|
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
|
// BlockCache caches the last block for safe access from different service loops
|
||||||
type BlockCache struct {
|
type BlockCache struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
Loading…
Reference in New Issue
Block a user