Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not panic when adding a job if ETH_DISABLED=true #4238

Merged
merged 2 commits into from
Apr 20, 2021
Merged
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
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah saw that locally as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure how this ever worked tbh


// 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