diff --git a/core/cmd/direct-request-spec-template.yml b/core/cmd/direct-request-spec-template.yml new file mode 100644 index 00000000000..5774e9a7933 --- /dev/null +++ b/core/cmd/direct-request-spec-template.yml @@ -0,0 +1,13 @@ +type = "directrequest" +schemaVersion = 1 +evmChainID = "0" +name = "%s" +contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C" +externalJobID = "%s" +observationSource = """ + ds1 [type=http method=GET url="http://example.com" allowunrestrictednetworkaccess="true"]; + ds1_merge [type=merge left="{}"] + ds1_parse [type=jsonparse path="USD"]; + ds1_multiply [type=multiply times=100]; + ds1 -> ds1_parse -> ds1_multiply; +""" diff --git a/core/cmd/jobs_commands_test.go b/core/cmd/jobs_commands_test.go index acb5731b785..b83b17f0be6 100644 --- a/core/cmd/jobs_commands_test.go +++ b/core/cmd/jobs_commands_test.go @@ -2,6 +2,7 @@ package cmd_test import ( "bytes" + _ "embed" "flag" "fmt" "testing" @@ -295,21 +296,8 @@ func TestJob_ToRows(t *testing.T) { }, job.ToRows()) } -const directRequestSpecTemplate = ` -type = "directrequest" -schemaVersion = 1 -evmChainID = "0" -name = "%s" -contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C" -externalJobID = "%s" -observationSource = """ - ds1 [type=http method=GET url="http://example.com" allowunrestrictednetworkaccess="true"]; - ds1_merge [type=merge left="{}"] - ds1_parse [type=jsonparse path="USD"]; - ds1_multiply [type=multiply times=100]; - ds1 -> ds1_parse -> ds1_multiply; -""" -` +//go:embed direct-request-spec-template.yml +var directRequestSpecTemplate string func getDirectRequestSpec() string { return fmt.Sprintf(directRequestSpecTemplate, uuid.New(), uuid.New()) @@ -371,6 +359,9 @@ func TestShell_ShowJob(t *testing.T) { assert.Equal(t, createOutput.ID, job.ID) } +//go:embed ocr-bootstrap-spec.yml +var ocrBootstrapSpec string + func TestShell_CreateJobV2(t *testing.T) { t.Parallel() @@ -393,7 +384,9 @@ func TestShell_CreateJobV2(t *testing.T) { fs := flag.NewFlagSet("", flag.ExitOnError) cltest.FlagSetApplyFromAction(client.CreateJob, fs, "") - require.NoError(t, fs.Parse([]string{"../testdata/tomlspecs/ocr-bootstrap-spec.toml"})) + nameAndExternalJobID := uuid.New() + spec := fmt.Sprintf(ocrBootstrapSpec, nameAndExternalJobID, nameAndExternalJobID) + require.NoError(t, fs.Parse([]string{spec})) err := client.CreateJob(cli.NewContext(nil, fs, nil)) require.NoError(t, err) diff --git a/core/testdata/tomlspecs/ocr-bootstrap-spec.toml b/core/cmd/ocr-bootstrap-spec.yml similarity index 76% rename from core/testdata/tomlspecs/ocr-bootstrap-spec.toml rename to core/cmd/ocr-bootstrap-spec.yml index 9df0a861960..9db118b77cd 100644 --- a/core/testdata/tomlspecs/ocr-bootstrap-spec.toml +++ b/core/cmd/ocr-bootstrap-spec.yml @@ -1,9 +1,10 @@ type = "offchainreporting" schemaVersion = 1 contractAddress = "0x27548a32b9aD5D64c5945EaE9Da5337bc3169D15" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F50" +externalJobID = "%s" +name = "%s" evmChainID = "0" p2pBootstrapPeers = [ "/dns4/chain.link/tcp/1234/p2p/16Uiu2HAm58SP7UL8zsnpeuwHfytLocaqgnyaYKP8wu7qRdrixLju", ] -isBootstrapPeer = true \ No newline at end of file +isBootstrapPeer = true diff --git a/core/internal/features/features_test.go b/core/internal/features/features_test.go index b2199d1c8ba..e287a0b05a7 100644 --- a/core/internal/features/features_test.go +++ b/core/internal/features/features_test.go @@ -3,6 +3,7 @@ package features_test import ( "bytes" "context" + _ "embed" "encoding/json" "fmt" "io" @@ -337,6 +338,12 @@ func setupOperatorContracts(t *testing.T) OperatorContracts { } } +//go:embed singleword-spec-template.yml +var singleWordSpecTemplate string + +//go:embed multiword-spec-template.yml +var multiWordSpecTemplate string + // Tests both single and multiple word responses - // i.e. both fulfillOracleRequest2 and fulfillOracleRequest. func TestIntegration_DirectRequest(t *testing.T) { @@ -352,7 +359,6 @@ func TestIntegration_DirectRequest(t *testing.T) { for _, tt := range tests { test := tt t.Run(test.name, func(t *testing.T) { - t.Parallel() // Simulate a consumer contract calling to obtain ETH quotes in 3 different currencies // in a single callback. config := configtest2.NewGeneralConfigSimulated(t, func(c *chainlink.Config, s *chainlink.Secrets) { @@ -388,9 +394,9 @@ func TestIntegration_DirectRequest(t *testing.T) { mockServerEUR := cltest.NewHTTPMockServer(t, 200, "GET", `{"EUR": 507.07}`) mockServerJPY := cltest.NewHTTPMockServer(t, 200, "GET", `{"JPY": 63818.86}`) - spec := string(cltest.MustReadFile(t, "../../testdata/tomlspecs/multiword-response-spec.toml")) - spec = strings.ReplaceAll(spec, "0x613a38AC1659769640aaE063C651F48E0250454C", operatorContracts.operatorAddress.Hex()) - spec = strings.ReplaceAll(spec, "example", "example 1") // make the name unique + nameAndExternalJobID := uuid.New() + addr := operatorContracts.operatorAddress.Hex() + spec := fmt.Sprintf(multiWordSpecTemplate, nameAndExternalJobID, addr, nameAndExternalJobID, addr) j := cltest.CreateJobViaWeb(t, app, []byte(cltest.MustJSONMarshal(t, web.CreateJobRequest{TOML: spec}))) cltest.AwaitJobActive(t, app.JobSpawner(), j.ID, 5*time.Second) @@ -426,10 +432,8 @@ func TestIntegration_DirectRequest(t *testing.T) { cltest.AssertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) assertPricesUint256(t, big.NewInt(61464), big.NewInt(50707), big.NewInt(6381886), operatorContracts.multiWord) - // Do a single word request - singleWordSpec := string(cltest.MustReadFile(t, "../../testdata/tomlspecs/direct-request-spec-cbor.toml")) - singleWordSpec = strings.ReplaceAll(singleWordSpec, "0x613a38AC1659769640aaE063C651F48E0250454C", operatorContracts.operatorAddress.Hex()) - singleWordSpec = strings.ReplaceAll(singleWordSpec, "example", "example 2") // make the name unique + nameAndExternalJobID = uuid.New() + singleWordSpec := fmt.Sprintf(singleWordSpecTemplate, nameAndExternalJobID, addr, nameAndExternalJobID, addr) jobSingleWord := cltest.CreateJobViaWeb(t, app, []byte(cltest.MustJSONMarshal(t, web.CreateJobRequest{TOML: singleWordSpec}))) cltest.AwaitJobActive(t, app.JobSpawner(), jobSingleWord.ID, 5*time.Second) diff --git a/core/testdata/tomlspecs/multiword-response-spec.toml b/core/internal/features/multiword-spec-template.yml similarity index 88% rename from core/testdata/tomlspecs/multiword-response-spec.toml rename to core/internal/features/multiword-spec-template.yml index 31da76b797c..8479212f7d4 100644 --- a/core/testdata/tomlspecs/multiword-response-spec.toml +++ b/core/internal/features/multiword-spec-template.yml @@ -1,41 +1,34 @@ type = "directrequest" schemaVersion = 1 -name = "example eth request event spec" -contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C" -evmChainID = "1337" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F47" +name = "%s" +contractAddress = "%s" +evmChainID = 1337 +externalJobID = "%s" observationSource = """ decode_log [type=ethabidecodelog abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"] decode_cbor [type=cborparse data="$(decode_log.data)"] - decode_log -> decode_cbor - decode_cbor -> usd decode_cbor -> eur decode_cbor -> jpy - usd [type=http method=GET url="$(decode_cbor.urlUSD)" allowunrestrictednetworkaccess="true"] usd_parse [type=jsonparse path="$(decode_cbor.pathUSD)"] usd_multiply [type=multiply value="$(usd_parse)", times="100"] usd -> usd_parse -> usd_multiply - eur [type=http method=GET url="$(decode_cbor.urlEUR)" allowunrestrictednetworkaccess="true"] eur_parse [type=jsonparse path="$(decode_cbor.pathEUR)"] eur_multiply [type=multiply value="$(eur_parse)", times="100"] eur -> eur_parse -> eur_multiply - jpy [type=http method=GET url="$(decode_cbor.urlJPY)" allowunrestrictednetworkaccess="true"] jpy_parse [type=jsonparse path="$(decode_cbor.pathJPY)"] jpy_multiply [type=multiply value="$(jpy_parse)", times="100"] jpy -> jpy_parse -> jpy_multiply - usd_multiply -> encode_mwr eur_multiply -> encode_mwr jpy_multiply -> encode_mwr - encode_mwr [type=ethabiencode abi="(bytes32 requestId, uint256 usd, uint256 eur, uint256 jpy)" data=<{ @@ -51,7 +44,6 @@ observationSource = """ "callbackFunctionId": $(decode_log.callbackFunctionId), "expiration": $(decode_log.cancelExpiration), "data": $(encode_mwr)}>] - submit_tx [type=ethtx to="0x613a38AC1659769640aaE063C651F48E0250454C" data="$(encode_tx)" minConfirmations="2"] - + submit_tx [type=ethtx to="%s" data="$(encode_tx)" minConfirmations="2"] encode_mwr -> encode_tx -> submit_tx """ diff --git a/core/testdata/tomlspecs/direct-request-spec-cbor.toml b/core/internal/features/singleword-spec-template.yml similarity index 83% rename from core/testdata/tomlspecs/direct-request-spec-cbor.toml rename to core/internal/features/singleword-spec-template.yml index 500c4973d88..4ceef574d91 100644 --- a/core/testdata/tomlspecs/direct-request-spec-cbor.toml +++ b/core/internal/features/singleword-spec-template.yml @@ -1,8 +1,8 @@ type = "directrequest" schemaVersion = 1 -name = "example eth request event spec" -contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F90" +name = "%s" +contractAddress = "%s" +externalJobID = "%s" evmChainID = 1337 observationSource = """ decode_log [type=ethabidecodelog @@ -22,6 +22,6 @@ observationSource = """ "callbackFunctionId": $(decode_log.callbackFunctionId), "expiration": $(decode_log.cancelExpiration), "data": $(encode_data)}>] - submit [type=ethtx to="0x613a38AC1659769640aaE063C651F48E0250454C" data="$(encode_tx)" minConfirmations="2"] + submit [type=ethtx to="%s" data="$(encode_tx)" minConfirmations="2"] decode_log->decode_cbor->ds1 -> ds1_parse -> ds1_multiply->encode_data->encode_tx->submit; """ diff --git a/core/services/feeds/rpc_handlers_test.go b/core/services/feeds/rpc_handlers_test.go index 26b21aeb65a..1648c05954d 100644 --- a/core/services/feeds/rpc_handlers_test.go +++ b/core/services/feeds/rpc_handlers_test.go @@ -1,6 +1,7 @@ package feeds_test import ( + "fmt" "testing" "github.com/google/uuid" @@ -34,10 +35,11 @@ func setupTestHandlers(t *testing.T) *TestRPCHandlers { func Test_RPCHandlers_ProposeJob(t *testing.T) { var ( - ctx = testutils.Context(t) - jobID = uuid.New() - spec = FluxMonitorTestSpec - version = int64(1) + ctx = testutils.Context(t) + jobID = uuid.New() + nameAndExternalJobID = uuid.New() + spec = fmt.Sprintf(FluxMonitorTestSpecTemplate, nameAndExternalJobID, nameAndExternalJobID) + version = int64(1) ) h := setupTestHandlers(t) diff --git a/core/services/feeds/service_test.go b/core/services/feeds/service_test.go index 28bb9c3afcc..744c5d14702 100644 --- a/core/services/feeds/service_test.go +++ b/core/services/feeds/service_test.go @@ -45,12 +45,12 @@ import ( "gopkg.in/guregu/null.v4" ) -const FluxMonitorTestSpec = ` +const FluxMonitorTestSpecTemplate = ` type = "fluxmonitor" schemaVersion = 1 -name = "example flux monitor spec" +name = "%s" contractAddress = "0x3cCad4715152693fE3BC4460591e3D3Fbd071b42" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F47" +externalJobID = "%s" threshold = 0.5 absoluteThreshold = 0.0 # optional @@ -68,11 +68,11 @@ answer1 [type=median index=0]; """ ` -const OCR1TestSpec = ` +const OCR1TestSpecTemplate = ` type = "offchainreporting" schemaVersion = 1 -name = "example OCR1 spec" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F46" +name = "%s" +externalJobID = "%s" evmChainID = 0 contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C" p2pBootstrapPeers = [ @@ -102,14 +102,14 @@ observationSource = """ """ ` -const OCR2TestSpec = ` +const OCR2TestSpecTemplate = ` type = "offchainreporting2" pluginType = "median" schemaVersion = 1 -name = "example OCR2 spec" +name = "%s" relay = "evm" contractID = "0x613a38AC1659769640aaE063C651F48E0250454C" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F47" +externalJobID = "%s" observationSource = """ ds1 [type=bridge name=voter_turnout]; ds1_parse [type=jsonparse path="one,two"]; @@ -128,10 +128,10 @@ ds1 -> ds1_parse -> ds1_multiply -> answer1; answer1 [type=median index=0]; """ ` -const BootstrapTestSpec = ` +const BootstrapTestSpecTemplate = ` type = "bootstrap" schemaVersion = 1 -name = "example Bootstrap spec" +name = "%s" contractID = "0x613a38AC1659769640aaE063C651F48E0250454C" relay = "evm" [relayConfig] @@ -539,62 +539,68 @@ func Test_Service_ProposeJob(t *testing.T) { var ( idFluxMonitor = int64(1) remoteUUIDFluxMonitor = uuid.New() + nameAndExternalJobID = uuid.New() + spec = fmt.Sprintf(FluxMonitorTestSpecTemplate, nameAndExternalJobID, nameAndExternalJobID) argsFluxMonitor = &feeds.ProposeJobArgs{ FeedsManagerID: 1, RemoteUUID: remoteUUIDFluxMonitor, - Spec: FluxMonitorTestSpec, + Spec: spec, Version: 1, } jpFluxMonitor = feeds.JobProposal{ FeedsManagerID: 1, - Name: null.StringFrom("example flux monitor spec"), + Name: null.StringFrom(nameAndExternalJobID.String()), RemoteUUID: remoteUUIDFluxMonitor, Status: feeds.JobProposalStatusPending, } specFluxMonitor = feeds.JobProposalSpec{ - Definition: FluxMonitorTestSpec, + Definition: spec, Status: feeds.SpecStatusPending, Version: argsFluxMonitor.Version, JobProposalID: idFluxMonitor, } - idOCR1 = int64(2) - remoteUUIDOCR1 = uuid.New() - argsOCR1 = &feeds.ProposeJobArgs{ + idOCR1 = int64(2) + remoteUUIDOCR1 = uuid.New() + ocr1NameAndExternalJobID = uuid.New() + ocr1Spec = fmt.Sprintf(OCR1TestSpecTemplate, ocr1NameAndExternalJobID, ocr1NameAndExternalJobID) + argsOCR1 = &feeds.ProposeJobArgs{ FeedsManagerID: 1, RemoteUUID: remoteUUIDOCR1, - Spec: OCR1TestSpec, + Spec: ocr1Spec, Version: 1, } jpOCR1 = feeds.JobProposal{ FeedsManagerID: 1, - Name: null.StringFrom("example OCR1 spec"), + Name: null.StringFrom(ocr1NameAndExternalJobID.String()), RemoteUUID: remoteUUIDOCR1, Status: feeds.JobProposalStatusPending, } specOCR1 = feeds.JobProposalSpec{ - Definition: OCR1TestSpec, + Definition: ocr1Spec, Status: feeds.SpecStatusPending, Version: argsOCR1.Version, JobProposalID: idOCR1, } - idOCR2 = int64(3) - remoteUUIDOCR2 = uuid.New() - argsOCR2 = &feeds.ProposeJobArgs{ + idOCR2 = int64(3) + remoteUUIDOCR2 = uuid.New() + ocr2NameAndExternalJobID = uuid.New() + ocr2Spec = fmt.Sprintf(OCR2TestSpecTemplate, ocr2NameAndExternalJobID, ocr2NameAndExternalJobID) + argsOCR2 = &feeds.ProposeJobArgs{ FeedsManagerID: 1, RemoteUUID: remoteUUIDOCR2, - Spec: OCR2TestSpec, + Spec: ocr2Spec, Version: 1, } jpOCR2 = feeds.JobProposal{ FeedsManagerID: 1, - Name: null.StringFrom("example OCR2 spec"), + Name: null.StringFrom(ocr2NameAndExternalJobID.String()), RemoteUUID: remoteUUIDOCR2, Status: feeds.JobProposalStatusPending, } specOCR2 = feeds.JobProposalSpec{ - Definition: OCR2TestSpec, + Definition: ocr2Spec, Status: feeds.SpecStatusPending, Version: argsOCR2.Version, JobProposalID: idOCR2, @@ -602,20 +608,22 @@ func Test_Service_ProposeJob(t *testing.T) { idBootstrap = int64(4) remoteUUIDBootstrap = uuid.New() + bootstrapName = uuid.New() + bootstrapSpec = fmt.Sprintf(BootstrapTestSpecTemplate, bootstrapName) argsBootstrap = &feeds.ProposeJobArgs{ FeedsManagerID: 1, RemoteUUID: remoteUUIDBootstrap, - Spec: BootstrapTestSpec, + Spec: bootstrapSpec, Version: 1, } jpBootstrap = feeds.JobProposal{ FeedsManagerID: 1, - Name: null.StringFrom("example Bootstrap spec"), + Name: null.StringFrom(bootstrapName.String()), RemoteUUID: remoteUUIDBootstrap, Status: feeds.JobProposalStatusPending, } specBootstrap = feeds.JobProposalSpec{ - Definition: BootstrapTestSpec, + Definition: bootstrapSpec, Status: feeds.SpecStatusPending, Version: argsBootstrap.Version, JobProposalID: idBootstrap, @@ -702,7 +710,7 @@ func Test_Service_ProposeJob(t *testing.T) { name: "must be an ocr job to include bootstraps", before: func(svc *TestService) {}, args: &feeds.ProposeJobArgs{ - Spec: FluxMonitorTestSpec, + Spec: spec, Multiaddrs: pq.StringArray{"/dns4/example.com"}, }, wantErr: "only OCR job type supports multiaddr", diff --git a/core/testdata/tomlspecs/cron-spec.toml b/core/testdata/tomlspecs/cron-spec.toml deleted file mode 100644 index c4b463acb5f..00000000000 --- a/core/testdata/tomlspecs/cron-spec.toml +++ /dev/null @@ -1,10 +0,0 @@ -type = "cron" -schemaVersion = 1 -schedule = "CRON_TZ=UTC 0 0 1 1 *" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F40" -observationSource = """ -ds [type=http method=GET url="https://chain.link/ETH-USD"]; -ds_parse [type=jsonparse path="data,price"]; -ds_multiply [type=multiply times=100]; -ds -> ds_parse -> ds_multiply; -""" diff --git a/core/testdata/tomlspecs/flux-monitor-spec.toml b/core/testdata/tomlspecs/flux-monitor-spec.toml deleted file mode 100644 index 14bcfb3e19c..00000000000 --- a/core/testdata/tomlspecs/flux-monitor-spec.toml +++ /dev/null @@ -1,28 +0,0 @@ -type = "fluxmonitor" -schemaVersion = 1 -name = "example flux monitor spec" -contractAddress = "0x3cCad4715152693fE3BC4460591e3D3Fbd071b42" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F47" -threshold = 0.5 -absoluteThreshold = 0.0 # optional - -idleTimerPeriod = "1s" -idleTimerDisabled = false - -pollTimerPeriod = "1m" -pollTimerDisabled = false - -observationSource = """ -// data source 1 -ds1 [type=http method=GET url="https://api.coindesk.com/v1/bpi/currentprice.json"]; -jp1 [type=jsonparse path="bpi,USD,rate_float"]; - -// data source 2 -ds2 [type=http method=GET url="https://api.coindesk.com/v1/bpi/currentprice.json"]; -jp2 [type=jsonparse path="bpi,USD,rate_float"]; - -ds1 -> jp1 -> answer1; -ds2 -> jp2 -> answer1; - -answer1 [type=median index=0]; -""" diff --git a/core/testdata/tomlspecs/ocr-spec-local-test.toml b/core/testdata/tomlspecs/ocr-spec-local-test.toml deleted file mode 100644 index 1993d738845..00000000000 --- a/core/testdata/tomlspecs/ocr-spec-local-test.toml +++ /dev/null @@ -1,20 +0,0 @@ -type = "offchainreporting" -schemaVersion = 1 -maxTaskDuration = "10s" -contractAddress = "0x934F3b67915BFbc98d5204122e0BE0ea69F91268" -p2pBootstrapPeers = [ - "/dns4/chain.link/tcp/1234/p2p/16Uiu2HAm58SP7UL8zsnpeuwHfytLocaqgnyaYKP8wu7qRdrixLju", -] -p2pv2BootstrapPeers = [] -isBootstrapPeer = false -monitoringEndpoint = "test:101" -# Below graph will succeed to run through the pipeline -observationSource = """ -// data source 1 -ds1 [type=http method=GET url="https://api.coindesk.com/v1/bpi/currentprice.json"]; -jp [type=jsonparse path="bpi,USD,rate_float"]; -ds1->jp; -""" -keyBundleID = "f5bf259689b26f1374efb3c9a9868796953a0f814bb2d39b968d0e61b58620a5" -transmitterAddress= "0x2901c8E3BD2D219Ca3c8f4af2f119883b6155219" -p2pPeerID = "12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X" diff --git a/core/testdata/tomlspecs/oracle-spec-invalid-key.toml b/core/testdata/tomlspecs/oracle-spec-invalid-key.toml deleted file mode 100644 index fba4b1ba5d3..00000000000 --- a/core/testdata/tomlspecs/oracle-spec-invalid-key.toml +++ /dev/null @@ -1,34 +0,0 @@ -type = "offchainreporting" -schemaVersion = 1 -contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C" -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F52" -p2pPeerID = "12D3KooWHfYFQ8hGttAYbMCevQVESEQhzJAqFZokMVtom8bNxwGq" -p2pBootstrapPeers = [ - "/dns4/chain.link/tcp/1234/p2p/16Uiu2HAm58SP7UL8zsnpeuwHfytLocaqgnyaYKP8wu7qRdrixLju", -] -isBootstrapNode = false -keyBundleID = "73e8966a78ca09bb912e9565cfb79fbe8a6048fab1f0cf49b18047c3895e0447" -monitoringEndpoint = "chain.link:4321" -transmitterAddress = "0xaA07d525B4006a2f927D79CA78a23A8ee680A32A" -observationTimeout = "10s" -blockchainTimeout = "20s" -contractConfigTrackerSubscribeInterval = "2m" -contractConfigTrackerPollInterval = "1m" -contractConfigConfirmations = 3 -observationSource = """ - // data source 1 - ds1 [type=bridge name=voter_turnout]; - ds1_parse [type=jsonparse path="one,two"]; - ds1_multiply [type=multiply times=1.23]; - - // data source 2 - ds2 [type=http method=GET url="https://chain.link/voter_turnout/USA-2020" requestData="{\\"hi\\": \\"hello\\"}"]; - ds2_parse [type=jsonparse path="three,four"]; - ds2_multiply [type=multiply times=4.56]; - - ds1 -> ds1_parse -> ds1_multiply -> answer1; - ds2 -> ds2_parse -> ds2_multiply -> answer1; - - answer1 [type=median index=0]; - answer2 [type=bridge name=election_winner index=1]; -""" diff --git a/core/testdata/tomlspecs/presumptive-success-job.toml b/core/testdata/tomlspecs/presumptive-success-job.toml deleted file mode 100644 index 7f99ff6abe7..00000000000 --- a/core/testdata/tomlspecs/presumptive-success-job.toml +++ /dev/null @@ -1,13 +0,0 @@ -type = "webhook" -schemaVersion = 1 -externalJobID = "D80D56A0-8E43-4CFA-B7BD-035390F0F54C" -observationSource = """ - fail_but_i_dont_care [type=fail] - succeed1 [type=memo value=10] - succeed2 [type=memo value=5] - final [type=mean] - - fail_but_i_dont_care -> final; - succeed1 -> final; - succeed2 -> final; -""" diff --git a/core/testdata/tomlspecs/vrf-spec.toml b/core/testdata/tomlspecs/vrf-spec.toml deleted file mode 100644 index e44e5154c09..00000000000 --- a/core/testdata/tomlspecs/vrf-spec.toml +++ /dev/null @@ -1,26 +0,0 @@ -type = "vrf" -externalJobID = "123e4567-e89b-12d3-a456-426655440001" -schemaVersion = 1 -name = "vrf-primary" -coordinatorAddress = "0xABA5eDc1a551E55b1A570c0e1f1055e5BE11eca7" -confirmations = 6 -publicKey = "0x49cf5e2bf04a57620ac3833c998b37e78c0c7ad89b6a9cbc4ce6dba31729930000" -observationSource=""" -decode_log [type=ethabidecodelog - abi="RandomnessRequest(bytes32 keyHash,uint256 seed,bytes32 indexed jobID,address sender,uint256 fee,bytes32 requestID)" - data="$(jobRun.logData)" - topics="$(jobRun.logTopics)"] -vrf [type=vrf - publicKey="$(jobSpec.publicKey)" - requestBlockHash="$(jobRun.logBlockHash)" - requestBlockNumber="$(jobRun.logBlockNumber)" - topics="$(jobRun.logTopics)"] -encode_tx [type=ethabiencode - abi="fulfillRandomnessRequest(bytes proof)" - data="{\\"proof\\": $(vrf)}"] -submit_tx [type=ethtx to="0xABA5eDc1a551E55b1A570c0e1f1055e5BE11eca7" - data="$(encode_tx)" - minConfirmations="0" - txMeta="{\\"requestTxHash\\": $(jobRun.logTxHash),\\"requestID\\": $(decode_log.requestID),\\"jobID\\": $(jobSpec.databaseID)}"] -decode_log->vrf->encode_tx->submit_tx -""" diff --git a/core/testdata/tomlspecs/vrf-v2-spec.toml b/core/testdata/tomlspecs/vrf-v2-spec.toml deleted file mode 100644 index 46747f7c157..00000000000 --- a/core/testdata/tomlspecs/vrf-v2-spec.toml +++ /dev/null @@ -1,31 +0,0 @@ -type = "vrf" -externalJobID = "123e4567-e89b-12d3-a456-426655440001" -schemaVersion = 1 -name = "vrf-v2-primary" -coordinatorAddress = "0xABA5eDc1a551E55b1A570c0e1f1055e5BE11eca7" -confirmations = 6 -publicKey = "0x49cf5e2bf04a57620ac3833c998b37e78c0c7ad89b6a9cbc4ce6dba31729930000" -pollPeriod = "5s" -observationSource=""" -decode_log [type=ethabidecodelog - abi="RandomWordsRequested(bytes32 indexed keyHash,uint256 requestId,uint256 preSeed,uint64 indexed subId,uint16 minimumRequestConfirmations,uint32 callbackGasLimit,uint32 numWords,address indexed sender)" - data="$(jobRun.logData)" - topics="$(jobRun.logTopics)"] -vrf [type=vrfv2 - publicKey="$(jobSpec.publicKey)" - requestBlockHash="$(jobRun.logBlockHash)" - requestBlockNumber="$(jobRun.logBlockNumber)" - topics="$(jobRun.logTopics)"] -estimate_gas [type=estimategaslimit - to="%s" - multiplier="1.1" - data="$(vrf.output)"] -simulate [type=ethcall - to="%s" - gas="$(estimate_gas)" - gasPrice="$(jobSpec.maxGasPrice)" - extractRevertReason=true - contract="%s" - data="$(vrf.output)"] -decode_log->vrf->estimate_gas->simulate -""" diff --git a/core/web/jobs_controller_test.go b/core/web/jobs_controller_test.go index d650d50abbf..e270ee9ef49 100644 --- a/core/web/jobs_controller_test.go +++ b/core/web/jobs_controller_test.go @@ -2,6 +2,7 @@ package web_test import ( "bytes" + _ "embed" "encoding/hex" "encoding/json" "fmt" @@ -379,16 +380,21 @@ func TestJobsController_Create_WebhookSpec(t *testing.T) { require.NoError(t, err) } +//go:embed webhook-spec-template.yml +var webhookSpecTemplate string + func TestJobsController_FailToCreate_EmptyJsonAttribute(t *testing.T) { app := cltest.NewApplicationEVMDisabled(t) require.NoError(t, app.Start(testutils.Context(t))) client := app.NewHTTPClient(nil) - tomlBytes := cltest.MustReadFile(t, "../testdata/tomlspecs/webhook-job-spec-with-empty-json.toml") - body, _ := json.Marshal(web.CreateJobRequest{ - TOML: string(tomlBytes), + nameAndExternalJobID := uuid.New() + spec := fmt.Sprintf(webhookSpecTemplate, nameAndExternalJobID, nameAndExternalJobID) + body, err := json.Marshal(web.CreateJobRequest{ + TOML: spec, }) + require.NoError(t, err) response, cleanup := client.Post("/v2/jobs", bytes.NewReader(body)) defer cleanup() diff --git a/core/testdata/tomlspecs/webhook-job-spec-with-empty-json.toml b/core/web/webhook-spec-template.yml similarity index 86% rename from core/testdata/tomlspecs/webhook-job-spec-with-empty-json.toml rename to core/web/webhook-spec-template.yml index 1f99dcb3d17..b490a15dda1 100644 --- a/core/testdata/tomlspecs/webhook-job-spec-with-empty-json.toml +++ b/core/web/webhook-spec-template.yml @@ -1,6 +1,7 @@ type = "webhook" schemaVersion = 1 -externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F53" +externalJobID = "%s" +name = "%s" observationSource = """ fetch [type=bridge name="fetch_bridge"] parse_request [type=jsonparse path="data,result"];