Skip to content

Commit

Permalink
[BCF-2706] Remove duplicate externalJobIDs and names from testspecs (#…
Browse files Browse the repository at this point in the history
…11021)

* Remove duplicate externalJobIDs and names from testspecs

* Randomize name and externalJobID in GenerateOCRSpec
  • Loading branch information
cedric-cordenier authored Oct 20, 2023
1 parent ac1fc61 commit 4288e07
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 128 deletions.
24 changes: 12 additions & 12 deletions core/services/job/job_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ func TestORM_CreateJob_OCRBootstrap(t *testing.T) {
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders)
jobORM := NewTestORM(t, db, legacyChains, pipelineORM, bridgesORM, keyStore, config.Database())

jb, err := ocrbootstrap.ValidatedBootstrapSpecToml(testspecs.OCRBootstrapSpec)
jb, err := ocrbootstrap.ValidatedBootstrapSpecToml(testspecs.GetOCRBootstrapSpec())
require.NoError(t, err)

err = jobORM.CreateJob(&jb)
Expand Down Expand Up @@ -800,7 +800,7 @@ func TestORM_CreateJob_OCR2_DuplicatedContractAddress(t *testing.T) {

_, address := cltest.MustInsertRandomKey(t, keyStore.Eth())

jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)

const juelsPerFeeCoinSource = `
Expand All @@ -816,7 +816,7 @@ func TestORM_CreateJob_OCR2_DuplicatedContractAddress(t *testing.T) {
err = jobORM.CreateJob(&jb)
require.NoError(t, err)

jb2, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jb2, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)

jb2.Name = null.StringFrom("Job with same chain id & contract address")
Expand All @@ -826,7 +826,7 @@ func TestORM_CreateJob_OCR2_DuplicatedContractAddress(t *testing.T) {
err = jobORM.CreateJob(&jb2)
require.Error(t, err)

jb3, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jb3, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)
jb3.Name = null.StringFrom("Job with different chain id & same contract address")
jb3.OCR2OracleSpec.TransmitterID = null.StringFrom(address.String())
Expand Down Expand Up @@ -862,7 +862,7 @@ func TestORM_CreateJob_OCR2_Sending_Keys_Transmitter_Keys_Validations(t *testing
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders)
jobORM := NewTestORM(t, db, legacyChains, pipelineORM, bridgesORM, keyStore, config.Database())

jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)

t.Run("sending keys or transmitterID must be defined", func(t *testing.T) {
Expand Down Expand Up @@ -903,7 +903,7 @@ func TestORM_ValidateKeyStoreMatch(t *testing.T) {
var jb job.Job
{
var err error
jb, err = ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jb, err = ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)
}

Expand Down Expand Up @@ -996,7 +996,7 @@ func Test_FindJobs(t *testing.T) {
require.NoError(t, err)

jb2, err := directrequest.ValidatedDirectRequestSpec(
testspecs.DirectRequestSpec,
testspecs.GetDirectRequestSpec(),
)
require.NoError(t, err)

Expand Down Expand Up @@ -1088,7 +1088,7 @@ func Test_FindJob(t *testing.T) {
)
require.NoError(t, err)

jobOCR2, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jobOCR2, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)
jobOCR2.OCR2OracleSpec.TransmitterID = null.StringFrom(address.String())

Expand Down Expand Up @@ -1236,7 +1236,7 @@ func Test_FindJobsByPipelineSpecIDs(t *testing.T) {
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders)
orm := NewTestORM(t, db, legacyChains, pipelineORM, bridgesORM, keyStore, config.Database())

jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.DirectRequestSpec)
jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.GetDirectRequestSpec())
require.NoError(t, err)
jb.DirectRequestSpec.EVMChainID = utils.NewBigI(0)

Expand Down Expand Up @@ -1587,7 +1587,7 @@ func Test_FindPipelineRunByID(t *testing.T) {
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders)
orm := NewTestORM(t, db, legacyChains, pipelineORM, bridgesORM, keyStore, config.Database())

jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.DirectRequestSpec)
jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.GetDirectRequestSpec())
require.NoError(t, err)

err = orm.CreateJob(&jb)
Expand Down Expand Up @@ -1632,7 +1632,7 @@ func Test_FindJobWithoutSpecErrors(t *testing.T) {
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders)
orm := NewTestORM(t, db, legacyChains, pipelineORM, bridgesORM, keyStore, config.Database())

jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.DirectRequestSpec)
jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.GetDirectRequestSpec())
require.NoError(t, err)

err = orm.CreateJob(&jb)
Expand Down Expand Up @@ -1671,7 +1671,7 @@ func Test_FindSpecErrorsByJobIDs(t *testing.T) {
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders)
orm := NewTestORM(t, db, legacyChains, pipelineORM, bridgesORM, keyStore, config.Database())

jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.DirectRequestSpec)
jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.GetDirectRequestSpec())
require.NoError(t, err)

err = orm.CreateJob(&jb)
Expand Down
6 changes: 3 additions & 3 deletions core/services/ocr2/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestGetEVMEffectiveTransmitterID(t *testing.T) {
}

t.Run("when sending keys are not defined, the first one should be set to transmitterID", func(t *testing.T) {
jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)
jb.OCR2OracleSpec.TransmitterID = null.StringFrom("some transmitterID string")
jb.OCR2OracleSpec.RelayConfig["sendingKeys"] = nil
Expand All @@ -150,7 +150,7 @@ func TestGetEVMEffectiveTransmitterID(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)
setTestCase(&jb, tc, txManager)
chain, err := legacyChains.Get(customChainID.String())
Expand All @@ -173,7 +173,7 @@ func TestGetEVMEffectiveTransmitterID(t *testing.T) {
}

t.Run("when forwarders are enabled and chain retrieval fails, error should be handled", func(t *testing.T) {
jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.OCR2EVMSpecMinimal)
jb, err := ocr2validate.ValidatedOracleSpecToml(config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMSpecMinimal())
require.NoError(t, err)
jb.ForwardingAllowed = true
jb.OCR2OracleSpec.TransmitterID = null.StringFrom("0x7e57000000000000000000000000000000000001")
Expand Down
110 changes: 47 additions & 63 deletions core/testdata/testspecs/v2_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ import (
)

var (
CronSpec = `
CronSpecTemplate = `
type = "cron"
schemaVersion = 1
schedule = "CRON_TZ=UTC * 0 0 1 1 *"
externalJobID = "123e4567-e89b-12d3-a456-426655440003"
externalJobID = "%s"
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;
"""
`
CronSpecDotSep = `
CronSpecDotSepTemplate = `
type = "cron"
schemaVersion = 1
schedule = "CRON_TZ=UTC * 0 0 1 1 *"
externalJobID = "123e4567-e89b-12d3-a456-426655440013"
externalJobID = "%s"
observationSource = """
ds [type=http method=GET url="https://chain.link/ETH-USD"];
ds_parse [type=jsonparse path="data.price" separator="."];
Expand All @@ -52,12 +52,12 @@ observationSource = """
ds1 -> ds1_parse -> ds1_multiply;
"""
`
DirectRequestSpec = `
DirectRequestSpecTemplate = `
type = "directrequest"
schemaVersion = 1
name = "example eth request event spec"
name = "%s"
contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C"
externalJobID = "123e4567-e89b-12d3-a456-426655440004"
externalJobID = "%s"
evmChainID = "0"
observationSource = """
ds1 [type=http method=GET url="http://example.com" allowunrestrictednetworkaccess="true"];
Expand All @@ -66,14 +66,14 @@ observationSource = """
ds1 -> ds1_parse -> ds1_multiply;
"""
`
DirectRequestSpecWithRequestersAndMinContractPayment = `
DirectRequestSpecWithRequestersAndMinContractPaymentTemplate = `
type = "directrequest"
schemaVersion = 1
requesters = ["0xaaaa1F8ee20f5565510B84f9353F1E333E753B7a", "0xbbbb70F0e81C6F3430dfdC9fa02fB22BdD818C4e"]
minContractPaymentLinkJuels = "1000000000000000000000"
name = "example eth request event spec with requesters and min contract payment"
name = "%s"
contractAddress = "0x613a38AC1659769640aaE063C651F48E0250454C"
externalJobID = "123e4567-e89b-12d3-a456-426655440014"
externalJobID = "%s"
evmChainID = 0
observationSource = """
ds1 [type=http method=GET url="http://example.com" allowunrestrictednetworkaccess="true"];
Expand All @@ -82,12 +82,12 @@ observationSource = """
ds1 -> ds1_parse -> ds1_multiply;
"""
`
FluxMonitorSpec = `
FluxMonitorSpecTemplate = `
type = "fluxmonitor"
schemaVersion = 1
name = "example flux monitor spec"
name = "%s"
contractAddress = "0x3cCad4715152693fE3BC4460591e3D3Fbd071b42"
externalJobID = "123e4567-e89b-12d3-a456-426655440005"
externalJobID = "%s"
evmChainID = 0
threshold = 0.5
absoluteThreshold = 0.0 # optional
Expand All @@ -113,47 +113,10 @@ ds2 -> ds2_parse -> answer1;
answer1 [type=median index=0];
"""
`
OCR2SolanaSpecMinimal = `type = "offchainreporting2"
schemaVersion = 1
name = "local testing job"
contractID = "VT3AvPr2nyE9Kr7ydDXVvgvJXyBr9tHA5hd6a1GBGBx"
p2pv2Bootstrappers = []
relay = "solana"
pluginType = "median"
transmitterID = "8AuzafoGEz92Z3WGFfKuEh2Ca794U3McLJBy7tfmDynK"
observationSource = """
"""
[pluginConfig]
juelsPerFeeCoinSource = """
"""
[relayConfig]
ocr2ProgramID = "CF13pnKGJ1WJZeEgVAtFdUi4MMndXm9hneiHs8azUaZt"
storeProgramID = "A7Jh2nb1hZHwqEofm4N8SXbKTj82rx7KUfjParQXUyMQ"
transmissionsID = "J6RRmA39u8ZBwrMvRPrJA3LMdg73trb6Qhfo8vjSeadg"
chainID = "Chainlink-99"`

OCR2CosmosSpecMinimal = `type = "offchainreporting2"
schemaVersion = 1
name = "local testing job"
contractID = "wasm1ysjdehnf3a3kpndx74yyg6ry90258y4z5vawjz"
isBootstrapPeer = false
p2pv2Bootstrappers = []
relay = "cosmos"
transmitterID = "wasm1ysjdehnf3a3kpndx74yyg6ry90258y4z5vawjz"
observationSource = """
"""
juelsPerFeeCoinSource = """
"""
[relayConfig]
chainID = "Chainlink-99"`
OCR2CosmosNodeSpecMinimal = OCR2CosmosSpecMinimal + `
nodeName = "some-test-node"`

OCR2EVMSpecMinimal = `type = "offchainreporting2"
OCR2EVMSpecMinimalTemplate = `type = "offchainreporting2"
schemaVersion = 1
name = "local testing job"
name = "%s"
relay = "evm"
contractID = "0x613a38AC1659769640aaE063C651F48E0250454C"
p2pv2Bootstrappers = []
Expand All @@ -169,10 +132,10 @@ observationSource = """
chainID = 0
[pluginConfig]
`
WebhookSpecNoBody = `
WebhookSpecNoBodyTemplate = `
type = "webhook"
schemaVersion = 1
externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F53"
externalJobID = "%s"
observationSource = """
fetch [type=bridge name="%s"]
parse_request [type=jsonparse path="data,result"];
Expand All @@ -183,10 +146,10 @@ observationSource = """
"""
`

WebhookSpecWithBody = `
WebhookSpecWithBodyTemplate = `
type = "webhook"
schemaVersion = 1
externalJobID = "0EEC7E1D-D0D2-476C-A1A8-72DFB6633F54"
externalJobID = "%s"
observationSource = """
parse_request [type=jsonparse path="data,result" data="$(jobRun.requestBody)"];
multiply [type=multiply times="100"];
Expand All @@ -198,7 +161,7 @@ observationSource = """

OCRBootstrapSpec = `
type = "bootstrap"
name = "bootstrap"
name = "%s"
relay = "evm"
schemaVersion = 1
contractID = "0x613a38AC1659769640aaE063C651F48E0250454C"
Expand All @@ -207,6 +170,27 @@ chainID = 1337
`
)

func GetOCRBootstrapSpec() string {
return fmt.Sprintf(OCRBootstrapSpec, uuid.New())
}

func GetDirectRequestSpec() string {
uuid := uuid.New()
return GetDirectRequestSpecWithUUID(uuid)
}

func GetDirectRequestSpecWithUUID(u uuid.UUID) string {
return fmt.Sprintf(DirectRequestSpecTemplate, u, u)
}

func GetOCR2EVMSpecMinimal() string {
return fmt.Sprintf(OCR2EVMSpecMinimalTemplate, uuid.New())
}

func GetWebhookSpecNoBody(u uuid.UUID, fetchBridge, submitBridge string) string {
return fmt.Sprintf(WebhookSpecNoBodyTemplate, u, fetchBridge, submitBridge)
}

type KeeperSpecParams struct {
Name string
ContractAddress string
Expand Down Expand Up @@ -482,9 +466,9 @@ func (os OCRSpec) Toml() string {
}

func GenerateOCRSpec(params OCRSpecParams) OCRSpec {
jobID := "123e4567-e89b-12d3-a456-426655440001"
if params.JobID != "" {
jobID = params.JobID
jobID := params.JobID
if jobID == "" {
jobID = uuid.New().String()
}
transmitterAddress := "0xF67D0290337bca0847005C7ffD1BC75BA9AAE6e4"
if params.TransmitterAddress != "" {
Expand All @@ -494,9 +478,9 @@ func GenerateOCRSpec(params OCRSpecParams) OCRSpec {
if params.ContractAddress != "" {
contractAddress = params.ContractAddress
}
name := "web oracle spec"
if params.Name != "" {
name = params.Name
name := params.Name
if params.Name == "" {
name = jobID
}
ds1BridgeName := fmt.Sprintf("automatically_generated_bridge_%s", uuid.New().String())
if params.DS1BridgeName != "" {
Expand Down
Loading

0 comments on commit 4288e07

Please sign in to comment.