Skip to content

Commit

Permalink
Do not panic when adding a job if ETH_DISABLED=true (#4238)
Browse files Browse the repository at this point in the history
* Do not panic when adding a job if ETH_DISABLED=true

* Fix tests
  • Loading branch information
samsondav committed Apr 20, 2021
1 parent 38df1f9 commit a692d54
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/internal/fixtures/web/ethlog_noop_job.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"initiators": [{"type": "ethLog"}],
"tasks": [{"type": "NoOp","confirmations": 100}]
}
2 changes: 1 addition & 1 deletion core/internal/gethwrappers/go_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/stretchr/testify/require"
)

const compileCommand = "../scripts/native_solc_compile_all"
const compileCommand = "../../../evm-contracts/scripts/native_solc_compile_all"

// TestCheckContractHashesFromLastGoGenerate compares the abi and bytecode of the
// contract artifacts in evm-contracts/solc with the abi and bytecode stored in the
Expand Down
4 changes: 4 additions & 0 deletions core/services/job_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (js *jobSubscriber) AddJob(job models.JobSpec, bn *models.Head) error {
if !job.IsLogInitiated() {
return nil
}
if js.store.Config.EthereumDisabled() {
logger.Errorw(fmt.Sprintf("ACTION REQUIRED: Attempted to add job with name '%s' but Ethereum was disabled. This job is NOT running.", job.Name), "job", job)
return nil
}

sub, err := StartJobSubscription(job, bn, js.store, js.runManager)
if err != nil {
Expand Down
42 changes: 42 additions & 0 deletions core/web/job_specs_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,48 @@ func TestJobSpecsController_Create_Task_Only(t *testing.T) {
assert.Equal(t, expected, strings.TrimSpace(body))
}

func TestJobSpecsController_Create_EthDisabled(t *testing.T) {
t.Parallel()

rpcClient, gethClient, _, assertMocksCalled := cltest.NewEthMocksWithStartupAssertions(t)
defer assertMocksCalled()
app, cleanup := cltest.NewApplication(t,
eth.NewClientWith(rpcClient, gethClient),
)
t.Cleanup(cleanup)
app.Config.Set("ETH_DISABLED", true)
require.NoError(t, app.Start())

client := app.NewHTTPClient()

t.Run("VRF", func(t *testing.T) {
jsonStr := cltest.MustReadFile(t, "./../testdata/jsonspecs/randomness_job.json")
resp, cleanup := client.Post("/v2/specs", bytes.NewBuffer(jsonStr))
t.Cleanup(cleanup)

assert.Equal(t, 200, resp.StatusCode)
cltest.AssertCount(t, app.Store, models.JobSpec{}, 1)
})

t.Run("runlog", func(t *testing.T) {
jsonStr := cltest.MustReadFile(t, "../internal/fixtures/web/runlog_noop_job.json")
resp, cleanup := client.Post("/v2/specs", bytes.NewBuffer(jsonStr))
t.Cleanup(cleanup)

assert.Equal(t, 200, resp.StatusCode)
cltest.AssertCount(t, app.Store, models.JobSpec{}, 2)
})

t.Run("ethlog", func(t *testing.T) {
jsonStr := cltest.MustReadFile(t, "../internal/fixtures/web/runlog_noop_job.json")
resp, cleanup := client.Post("/v2/specs", bytes.NewBuffer(jsonStr))
t.Cleanup(cleanup)

assert.Equal(t, 200, resp.StatusCode)
cltest.AssertCount(t, app.Store, models.JobSpec{}, 3)
})
}

func BenchmarkJobSpecsController_Show(b *testing.B) {
app, cleanup := cltest.NewApplication(b)
defer cleanup()
Expand Down
1 change: 1 addition & 0 deletions core/web/jobs_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func TestJobsController_Create_HappyPath_FluxMonitorSpec(t *testing.T) {
assert.Equal(t, float32(0.5), jb.FluxMonitorSpec.Threshold)
assert.Equal(t, float32(0), jb.FluxMonitorSpec.AbsoluteThreshold)
}

func TestJobsController_Index_HappyPath(t *testing.T) {
client, ocrJobSpecFromFile, _, ereJobSpecFromFile, _ := setupJobSpecsControllerTestsWithJobs(t)

Expand Down

0 comments on commit a692d54

Please sign in to comment.