Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions core/cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,20 @@ func NewApp(s *Shell) *cli.App {
// logger instead.
lggr, closeFn := logger.NewLogger()

cfg, err := opts.New()
if err != nil {
return err
}

s.Logger = lggr
s.Registerer = prometheus.DefaultRegisterer // use the global DefaultRegisterer, should be safe since we only ever run one instance of the app per shell
s.CloseLogger = closeFn
s.Config = cfg

// Only create a new config from opts if one hasn't been pre-set.
// Tests pre-set s.Config with a txdb-wrapped driver for DB isolation;
// unconditionally overwriting it here causes DB writes to leak between tests.
if s.Config == nil {
cfg, err := opts.New()
if err != nil {
return err
}
s.Config = cfg
}

if c.Bool("json") {
s.Renderer = RendererJSON{Writer: os.Stdout}
Expand Down Expand Up @@ -122,11 +127,11 @@ func NewApp(s *Shell) *cli.App {

// Allow for initServerConfig to be called if the flag is provided.
if c.Bool("applyInitServerConfig") {
cfg, err = initServerConfig(&opts, s.configFiles, s.secretsFiles)
serverCfg, err := initServerConfig(&opts, s.configFiles, s.secretsFiles)
if err != nil {
return err
}
s.Config = cfg
s.Config = serverCfg
}

return nil
Expand Down
34 changes: 16 additions & 18 deletions core/cmd/shell_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,15 @@ func TestShell_RemoveBlocks(t *testing.T) {

func TestShell_BeforeNode(t *testing.T) {
testutils.SkipShortDB(t)

// Use a dedicated test database so subtests share state without leaking
// data to the shared test database. The "incorrect password" subtest relies
// on a key ring created by the "correct password" subtest to verify that
// decryption fails with the wrong password.
cfg, _ := heavyweight.FullTestDBV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Insecure.OCRDevelopmentMode = nil
})

tests := []struct {
name string
pwdfile string
Expand All @@ -519,14 +528,6 @@ func TestShell_BeforeNode(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
s.Password.Keystore = models.NewSecret("dummy")
c.EVM[0].Nodes[0].Name = ptr("fake")
c.EVM[0].Nodes[0].HTTPURL = commonconfig.MustParseURL("http://fake.com")
c.EVM[0].Nodes[0].WSURL = commonconfig.MustParseURL("WSS://fake.com/ws")
c.Insecure.OCRDevelopmentMode = nil
})

shell := cmd.Shell{
Config: cfg,
KeyStoreAuthenticator: cmd.TerminalKeyStoreAuthenticator{
Expand Down Expand Up @@ -577,6 +578,13 @@ func TestShell_BeforeNode(t *testing.T) {
}

func TestShell_RunNode_WithBeforeNode(t *testing.T) {
// Use a dedicated test database so subtests share state without leaking
// data to the shared test database. The "incorrect password" subtest relies
// on keystore entries from prior setup to verify decryption failure.
cfg, db := heavyweight.FullTestDBV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Insecure.OCRDevelopmentMode = nil
})

tests := []struct {
name string
pwdfile string
Expand All @@ -588,16 +596,6 @@ func TestShell_RunNode_WithBeforeNode(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
s.Password.Keystore = models.NewSecret("dummy")
c.EVM[0].Nodes[0].Name = ptr("fake")
c.EVM[0].Nodes[0].HTTPURL = commonconfig.MustParseURL("http://fake.com")
c.EVM[0].Nodes[0].WSURL = commonconfig.MustParseURL("WSS://fake.com/ws")
// seems to be needed for config validate
c.Insecure.OCRDevelopmentMode = nil
})

db := pgtest.NewSqlxDB(t)
keyStore := cltest.NewKeyStore(t, db)
authProviderORM := localauth.NewORM(db, time.Minute, logger.TestLogger(t), audit.NoopLogger)

Expand Down
Loading