/
job_factories.go
70 lines (59 loc) · 2.49 KB
/
job_factories.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cltest
import (
"fmt"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/jmoiron/sqlx"
"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
)
const (
minimalOCRNonBootstrapTemplate = `
type = "offchainreporting"
schemaVersion = 1
contractAddress = "%s"
evmChainID = "0"
p2pPeerID = "%s"
p2pv2Bootstrappers = ["12D3KooWHfYFQ8hGttAYbMCevQVESEQhzJAqFZokMVtom8bNxwGq@127.0.0.1:5001"]
isBootstrapPeer = false
transmitterAddress = "%s"
keyBundleID = "%s"
observationTimeout = "10s"
observationSource = """
ds1 [type=http method=GET url="http://data.com"];
ds1_parse [type=jsonparse path="USD" lax=true];
ds1 -> ds1_parse;
"""
`
)
func MinimalOCRNonBootstrapSpec(contractAddress, transmitterAddress ethkey.EIP55Address, peerID p2pkey.PeerID, keyBundleID string) string {
return fmt.Sprintf(minimalOCRNonBootstrapTemplate, contractAddress, peerID, transmitterAddress.Hex(), keyBundleID)
}
func MustInsertWebhookSpec(t *testing.T, db *sqlx.DB) (job.Job, job.WebhookSpec) {
jobORM, pipelineORM := getORMs(t, db)
webhookSpec := job.WebhookSpec{}
require.NoError(t, jobORM.InsertWebhookSpec(&webhookSpec))
pSpec := pipeline.Pipeline{}
pipelineSpecID, err := pipelineORM.CreateSpec(pSpec, 0)
require.NoError(t, err)
createdJob := job.Job{WebhookSpecID: &webhookSpec.ID, WebhookSpec: &webhookSpec, SchemaVersion: 1, Type: "webhook",
ExternalJobID: uuid.New(), PipelineSpecID: pipelineSpecID}
require.NoError(t, jobORM.InsertJob(&createdJob))
return createdJob, webhookSpec
}
func getORMs(t *testing.T, db *sqlx.DB) (jobORM job.ORM, pipelineORM pipeline.ORM) {
config := configtest.NewTestGeneralConfig(t)
keyStore := NewKeyStore(t, db, config.Database())
lggr := logger.TestLogger(t)
pipelineORM = pipeline.NewORM(db, lggr, config.Database(), config.JobPipeline().MaxSuccessfulRuns())
bridgeORM := bridges.NewORM(db, lggr, config.Database())
jobORM = job.NewORM(db, pipelineORM, bridgeORM, keyStore, lggr, config.Database())
t.Cleanup(func() { jobORM.Close() })
return
}