Updates post review

* remove StreamCodeAndCodeHash
* Makefile: local build target
* clean up comments & unused
This commit is contained in:
2023-07-14 13:16:39 +08:00
parent c96215f9be
commit c4f16290c7
30 changed files with 672 additions and 260 deletions
@@ -28,7 +28,8 @@ import (
)
func setupLegacyPGXIndexer(t *testing.T) {
db, err = postgres.SetupPGXDB(postgres.TestConfig)
config, _ := postgres.TestConfig.WithEnv()
db, err = postgres.SetupPGXDB(config)
if err != nil {
t.Fatal(err)
}
+15 -5
View File
@@ -29,17 +29,27 @@ import (
"github.com/cerc-io/plugeth-statediff/indexer/test"
)
var defaultPgConfig postgres.Config
func init() {
var err error
defaultPgConfig, err = postgres.TestConfig.WithEnv()
if err != nil {
panic(err)
}
}
func setupPGXIndexer(t *testing.T, config postgres.Config) {
db, err = postgres.SetupPGXDB(config)
if err != nil {
t.Fatal(err)
}
ind, err = sql.NewStateDiffIndexer(context.Background(), mocks.TestConfig, db)
ind, err = sql.NewStateDiffIndexer(context.Background(), mocks.TestChainConfig, db)
require.NoError(t, err)
}
func setupPGX(t *testing.T) {
setupPGXWithConfig(t, postgres.TestConfig)
setupPGXWithConfig(t, defaultPgConfig)
}
func setupPGXWithConfig(t *testing.T, config postgres.Config) {
@@ -48,7 +58,7 @@ func setupPGXWithConfig(t *testing.T, config postgres.Config) {
}
func setupPGXNonCanonical(t *testing.T) {
setupPGXIndexer(t, postgres.TestConfig)
setupPGXIndexer(t, defaultPgConfig)
test.SetupTestDataNonCanonical(t, ind)
}
@@ -103,7 +113,7 @@ func TestPGXIndexer(t *testing.T) {
})
t.Run("Publish and index with CopyFrom enabled.", func(t *testing.T) {
config := postgres.TestConfig
config := defaultPgConfig
config.CopyFrom = true
setupPGXWithConfig(t, config)
@@ -169,7 +179,7 @@ func TestPGXIndexerNonCanonical(t *testing.T) {
}
func TestPGXWatchAddressMethods(t *testing.T) {
setupPGXIndexer(t, postgres.TestConfig)
setupPGXIndexer(t, defaultPgConfig)
defer tearDown(t)
defer checkTxClosure(t, 1, 0, 1)
+8 -7
View File
@@ -31,8 +31,9 @@ import (
)
var (
pgConfig, _ = postgres.MakeConfig(postgres.TestConfig)
ctx = context.Background()
pgConfig, _ = postgres.TestConfig.WithEnv()
pgxConfig, _ = postgres.MakeConfig(pgConfig)
ctx = context.Background()
)
func expectContainsSubstring(t *testing.T, full string, sub string) {
@@ -43,9 +44,9 @@ func expectContainsSubstring(t *testing.T, full string, sub string) {
func TestPostgresPGX(t *testing.T) {
t.Run("connects to the sql", func(t *testing.T) {
dbPool, err := pgxpool.ConnectConfig(context.Background(), pgConfig)
dbPool, err := pgxpool.ConnectConfig(context.Background(), pgxConfig)
if err != nil {
t.Fatalf("failed to connect to db with connection string: %s err: %v", pgConfig.ConnString(), err)
t.Fatalf("failed to connect to db with connection string: %s err: %v", pgxConfig.ConnString(), err)
}
if dbPool == nil {
t.Fatal("DB pool is nil")
@@ -61,9 +62,9 @@ func TestPostgresPGX(t *testing.T) {
// sized int, so use string representation of big.Int
// and cast on insert
dbPool, err := pgxpool.ConnectConfig(context.Background(), pgConfig)
dbPool, err := pgxpool.ConnectConfig(context.Background(), pgxConfig)
if err != nil {
t.Fatalf("failed to connect to db with connection string: %s err: %v", pgConfig.ConnString(), err)
t.Fatalf("failed to connect to db with connection string: %s err: %v", pgxConfig.ConnString(), err)
}
defer dbPool.Close()
@@ -111,7 +112,7 @@ func TestPostgresPGX(t *testing.T) {
badHash := fmt.Sprintf("x %s", strings.Repeat("1", 100))
badInfo := node.Info{GenesisBlock: badHash, NetworkID: "1", ID: "x123", ClientName: "geth"}
_, err := postgres.NewPGXDriver(ctx, postgres.TestConfig, badInfo)
_, err := postgres.NewPGXDriver(ctx, pgConfig, badInfo)
if err == nil {
t.Fatal("Expected an error")
}
+3 -3
View File
@@ -35,7 +35,7 @@ func TestPostgresSQLX(t *testing.T) {
t.Run("connects to the database", func(t *testing.T) {
var err error
connStr := postgres.TestConfig.DbConnectionString()
connStr := pgConfig.DbConnectionString()
sqlxdb, err = sqlx.Connect("postgres", connStr)
if err != nil {
@@ -58,7 +58,7 @@ func TestPostgresSQLX(t *testing.T) {
// sized int, so use string representation of big.Int
// and cast on insert
connStr := postgres.TestConfig.DbConnectionString()
connStr := pgConfig.DbConnectionString()
db, err := sqlx.Connect("postgres", connStr)
if err != nil {
t.Fatal(err)
@@ -109,7 +109,7 @@ func TestPostgresSQLX(t *testing.T) {
badHash := fmt.Sprintf("x %s", strings.Repeat("1", 100))
badInfo := node.Info{GenesisBlock: badHash, NetworkID: "1", ID: "x123", ClientName: "geth"}
_, err := postgres.NewSQLXDriver(ctx, postgres.TestConfig, badInfo)
_, err := postgres.NewSQLXDriver(ctx, pgConfig, badInfo)
if err == nil {
t.Fatal("Expected an error")
}
@@ -25,7 +25,10 @@ import (
// SetupSQLXDB is used to setup a sqlx db for tests
func SetupSQLXDB() (sql.Database, error) {
conf := TestConfig
conf, err := TestConfig.WithEnv()
if err != nil {
return nil, err
}
conf.MaxIdle = 0
driver, err := NewSQLXDriver(context.Background(), conf, node.Info{})
if err != nil {
+1 -1
View File
@@ -34,7 +34,7 @@ func setupSQLXIndexer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
ind, err = sql.NewStateDiffIndexer(context.Background(), mocks.TestConfig, db)
ind, err = sql.NewStateDiffIndexer(context.Background(), mocks.TestChainConfig, db)
require.NoError(t, err)
}