Skip to content

Commit

Permalink
More randomising of externalJobID and name (#11008)
Browse files Browse the repository at this point in the history
* More randomising of externalJobID and name

- Also inline specs that are only used in one place, and remove unused
  specs.

* Review feedback

* Use embed and fix spec
  • Loading branch information
cedric-cordenier authored Oct 20, 2023
1 parent 19866f2 commit 71e7de3
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 243 deletions.
13 changes: 13 additions & 0 deletions core/cmd/direct-request-spec-template.yml
Original file line number Diff line number Diff line change
@@ -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;
"""
25 changes: 9 additions & 16 deletions core/cmd/jobs_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd_test

import (
"bytes"
_ "embed"
"flag"
"fmt"
"testing"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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()

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
isBootstrapPeer = true
20 changes: 12 additions & 8 deletions core/internal/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package features_test
import (
"bytes"
"context"
_ "embed"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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=<{
Expand All @@ -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
"""
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
"""
10 changes: 6 additions & 4 deletions core/services/feeds/rpc_handlers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package feeds_test

import (
"fmt"
"testing"

"github.com/google/uuid"
Expand Down Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 71e7de3

Please sign in to comment.