Skip to content

Commit

Permalink
linter, mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
krehermann committed Jun 19, 2024
1 parent 1715ce5 commit a09bea7
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 106 deletions.
67 changes: 0 additions & 67 deletions core/chains/evm/forwarders/mocks/orm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion core/chains/evm/forwarders/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (o *DSORM) schemaName() string {
return fmt.Sprintf("evm_%s", o.cid.String())
}
return "evm"

}

// CreateForwarder creates the Forwarder address associated with the current EVM chain id.
Expand Down
1 change: 0 additions & 1 deletion core/chains/evm/txmgr/txmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ func TestTxm_CreateTransaction(t *testing.T) {
})

t.Run("forwards tx when a proper forwarder is set up", func(t *testing.T) {

pgtest.MustExec(t, db, `DELETE FROM evm.txes`)
pgtest.MustExec(t, db, `DELETE FROM evm.forwarders`)
evmConfig.MaxQueued = uint64(1)
Expand Down
3 changes: 0 additions & 3 deletions core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,6 @@ func newRelayMigrationOpts(c *cli.Context) *relayMigrationOpts {
Relayer: c.String("relayer"),
ChainID: c.String("chain-id"),
}

}

// MigrateDatabase migrates the database
Expand Down Expand Up @@ -1049,8 +1048,6 @@ func (s *Shell) RollbackDatabase(c *cli.Context) error {
err = fmt.Errorf("unknown relayer '%s'", opts.Relayer)
}
return err

return nil
}

// VersionDatabase displays the current database version.
Expand Down
8 changes: 0 additions & 8 deletions core/store/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,8 @@ import (
//go:embed migrations/*.sql migrations/*.go
var embedMigrations embed.FS

// go:embed plugins/relayers/**/*.tmpl.sql
var embedRelayerMigrations embed.FS

const PLUGIN_MIGRATIONS_DIR string = "plugins"

const MIGRATIONS_DIR string = "migrations"

// go:embed manifest.txt
var migrationManifest string

func init() {
setupCoreMigrations()
logMigrations := os.Getenv("CL_LOG_SQL_MIGRATIONS")
Expand Down
7 changes: 0 additions & 7 deletions core/store/migrate/plugins/relayer/evm/0002_initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,3 @@ func Register0002(val Cfg) error {
goose.AddMigrationContext(upFunc, downFunc)
return nil
}

func generateExec(execString string) func(ctx context.Context, tx *sql.Tx) error {
return func(ctx context.Context, tx *sql.Tx) error {
_, err := tx.ExecContext(ctx, execString)
return err
}
}
55 changes: 39 additions & 16 deletions core/store/migrate/plugins/relayer/evm/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,33 @@ import (
"gopkg.in/guregu/null.v4"
)

func setupPluginMigrations(cfg Cfg) {
func setupPluginMigrations(cfg Cfg) error {
// reset the base fs and the global migrations
goose.SetBaseFS(nil) // we don't want to use the base fs for plugin migrations because the embedded fs contains templates, not sql files
goose.ResetGlobalMigrations()
goose.SetTableName(fmt.Sprintf("goose_migration_relayer_%s_%s", cfg.Schema, cfg.ChainID.String()))
Register0002(cfg)
err := Register0002(cfg)
if err != nil {
return fmt.Errorf("failed to register migration 0002: %w", err)
}
return nil
}

// Migrate migrates a subsystem of the chainlink database.
// It generates migrations based on the template for the subsystem and applies them to the database.
func Migrate(ctx context.Context, db *sql.DB, cfg Cfg) error {
tmpDir := os.TempDir()
tmpDir, err := os.MkdirTemp("", cfg.Schema)
if err != nil {
return fmt.Errorf("failed to create temp dir: %w", err)
}
defer os.RemoveAll(tmpDir)

//defer setupCoreMigrations()
setupPluginMigrations(cfg)

d := filepath.Join(tmpDir, cfg.Schema, fmt.Sprintf("%s", cfg.ChainID))
err := os.MkdirAll(d, os.ModePerm)
err = setupPluginMigrations(cfg)
if err != nil {
return fmt.Errorf("failed to setup plugin migrations: %w", err)
}
d := filepath.Join(tmpDir, cfg.Schema, cfg.ChainID.String())
err = os.MkdirAll(d, os.ModePerm)
if err != nil {
return fmt.Errorf("failed to create directory %s: %w", d, err)
}
Expand All @@ -48,14 +56,19 @@ func Migrate(ctx context.Context, db *sql.DB, cfg Cfg) error {
}

func Rollback(ctx context.Context, db *sql.DB, version null.Int, cfg Cfg) error {
tmpDir := os.TempDir()
tmpDir, err := os.MkdirTemp("", cfg.Schema)
if err != nil {
return fmt.Errorf("failed to create temp dir: %w", err)
}
defer os.RemoveAll(tmpDir)

setupPluginMigrations(cfg)

err = setupPluginMigrations(cfg)
if err != nil {
return fmt.Errorf("failed to setup plugin migrations: %w", err)
}
// TODO: should these be saved somewhere? if so where, if not if the db itself?)
d := filepath.Join(tmpDir, cfg.Schema, fmt.Sprintf("%s", cfg.ChainID))
err := os.MkdirAll(d, os.ModePerm)
d := filepath.Join(tmpDir, cfg.Schema, cfg.ChainID.String())
err = os.MkdirAll(d, os.ModePerm)
if err != nil {
return fmt.Errorf("failed to create directory %s: %w", d, err)
}
Expand All @@ -74,14 +87,24 @@ func Rollback(ctx context.Context, db *sql.DB, version null.Int, cfg Cfg) error
}

func Current(ctx context.Context, db *sql.DB, cfg Cfg) (int64, error) {
setupPluginMigrations(cfg)
err := setupPluginMigrations(cfg)
if err != nil {
return -1, fmt.Errorf("failed to setup plugin migrations: %w", err)
}
// set the base fs only for status so that the templates are listed
// an alternative would be to somehow keep track of the erated sql files, but that would be more complex
// and error prone WRT to restarts
goose.SetBaseFS(embeddedTmplFS)
return goose.EnsureDBVersion(db)
}

func Status(ctx context.Context, db *sql.DB, cfg Cfg) error {
setupPluginMigrations(cfg)
err := setupPluginMigrations(cfg)
if err != nil {
return fmt.Errorf("failed to setup plugin migrations: %w", err)
}
// set the base fs only for status so that the templates are listed
// an alternative would be to somehow keep track of the generated sql files, but that would be more complex
// an alternative would be to somehow keep track of the erated sql files, but that would be more complex
// and error prone WRT to restarts
goose.SetBaseFS(embeddedTmplFS)
return goose.Status(db, MigrationRootDir)
Expand Down
1 change: 0 additions & 1 deletion core/store/migrate/plugins/relayer/evm/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func TestMigrate(t *testing.T) {

t.Run("core migration with optional relayer migration", func(t *testing.T) {
_, db := heavyweight.FullTestDBEmptyV2(t, nil)

Expand Down
2 changes: 1 addition & 1 deletion core/store/migrate/plugins/relayer/evm/testutils/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/google/uuid"
"github.com/jmoiron/sqlx"
"github.com/scylladb/go-reflectx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/test-go/testify/assert"

"github.com/smartcontractkit/chainlink/v2/core/internal/cltest/heavyweight"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ require (
github.com/smartcontractkit/wsrpc v0.8.1
github.com/spf13/cast v1.6.0
github.com/stretchr/testify v1.9.0
github.com/test-go/testify v1.1.4
github.com/theodesp/go-heaps v0.0.0-20190520121037-88e35354fe0a
github.com/tidwall/gjson v1.17.0
github.com/ugorji/go/codec v1.2.12
Expand Down Expand Up @@ -299,6 +298,7 @@ require (
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125 // indirect
github.com/test-go/testify v1.1.4 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
Expand Down

0 comments on commit a09bea7

Please sign in to comment.