Skip to content

Commit

Permalink
CCIP-3055 Creating Local docker tests for ccip smoke (#14357)
Browse files Browse the repository at this point in the history
* ccip deployment local dev env

* jd interface update

* fix environment building

* devenv set up

* changes

* delete non-required file

* ccip common config

* remove task

* add docker env

* delete

* all changes

* changes

* adding ccip integration tests

* move test to smoke

* remove redundant

* remove unnecessary changes

* remove

* fix go mod

* fix lint

* add jobtype

* add ccip jobtype

* add ccip job type in feeds service

* add assertions

* all changes

* add changeset

* lint fix

* reduce flakey test

* add changeset tag

* revert unwanted

* rename func

* lint fix
  • Loading branch information
AnieeG authored Sep 16, 2024
1 parent 7a06f5f commit ac3523a
Show file tree
Hide file tree
Showing 45 changed files with 2,424 additions and 536 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-dolphins-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal Add ccip JobType in feeds service and other jobtype validations
11 changes: 11 additions & 0 deletions core/services/feeds/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"

ccip "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/validate"
"github.com/smartcontractkit/chainlink/v2/plugins"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
Expand Down Expand Up @@ -818,6 +820,13 @@ func (s *service) ApproveSpec(ctx context.Context, id int64, force bool) error {
return fmt.Errorf("failed while checking for existing workflow job: %w", txerr)
}
}
case job.CCIP:
existingJobID, txerr = tx.jobORM.FindJobIDByCapabilityNameAndVersion(ctx, *j.CCIPSpec)
// Return an error if the repository errors. If there is a not found
// error we want to continue with approving the job.
if txerr != nil && !errors.Is(txerr, sql.ErrNoRows) {
return fmt.Errorf("failed while checking for existing ccip job: %w", txerr)
}
default:
return errors.Errorf("unsupported job type when approving job proposal specs: %s", j.Type)
}
Expand Down Expand Up @@ -1202,6 +1211,8 @@ func (s *service) generateJob(ctx context.Context, spec string) (*job.Job, error
js, err = fluxmonitorv2.ValidatedFluxMonitorSpec(s.jobCfg, spec)
case job.Workflow:
js, err = workflows.ValidatedWorkflowJobSpec(spec)
case job.CCIP:
js, err = ccip.ValidatedCCIPSpec(spec)
default:
return nil, errors.Errorf("unknown job type: %s", jobType)
}
Expand Down
57 changes: 57 additions & 0 deletions core/services/job/mocks/orm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions core/services/job/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type ORM interface {
WithDataSource(source sqlutil.DataSource) ORM

FindJobIDByWorkflow(ctx context.Context, spec WorkflowSpec) (int32, error)
FindJobIDByCapabilityNameAndVersion(ctx context.Context, spec CCIPSpec) (int32, error)
}

type ORMConfig interface {
Expand Down Expand Up @@ -1123,6 +1124,18 @@ INNER JOIN workflow_specs ws on jobs.workflow_spec_id = ws.id AND ws.workflow_ow
return
}

func (o *orm) FindJobIDByCapabilityNameAndVersion(ctx context.Context, spec CCIPSpec) (jobID int32, err error) {
stmt := `
SELECT jobs.id FROM jobs
INNER JOIN ccip_specs ccip on jobs.ccip_spec_id = ccip.id AND ccip.capability_labelled_name = $1 AND ccip.capability_version = $2
`
err = o.ds.GetContext(ctx, &jobID, stmt, spec.CapabilityLabelledName, spec.CapabilityVersion)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
err = fmt.Errorf("error searching for job for CCIP (capabilityName,capabilityVersion) ('%s','%s'): %w", spec.CapabilityLabelledName, spec.CapabilityVersion, err)
}
return
}

// PipelineRunsByJobsIDs returns pipeline runs for multiple jobs, not preloading data
func (o *orm) PipelineRunsByJobsIDs(ctx context.Context, ids []int32) (runs []pipeline.Run, err error) {
err = o.transact(ctx, false, func(tx *orm) error {
Expand Down
1 change: 1 addition & 0 deletions core/services/job/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
Webhook: {},
Workflow: {},
StandardCapabilities: {},
CCIP: {},
}
)

Expand Down
4 changes: 3 additions & 1 deletion core/web/jobs_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/google/uuid"
"github.com/pkg/errors"

ccip "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/validate"
"github.com/smartcontractkit/chainlink/v2/core/logger/audit"
"github.com/smartcontractkit/chainlink/v2/core/services/blockhashstore"
"github.com/smartcontractkit/chainlink/v2/core/services/blockheaderfeeder"
Expand Down Expand Up @@ -258,7 +259,8 @@ func (jc *JobsController) validateJobSpec(ctx context.Context, tomlString string
jb, err = workflows.ValidatedWorkflowJobSpec(tomlString)
case job.StandardCapabilities:
jb, err = standardcapabilities.ValidatedStandardCapabilitiesSpec(tomlString)

case job.CCIP:
jb, err = ccip.ValidatedCCIPSpec(tomlString)
default:
return jb, http.StatusUnprocessableEntity, errors.Errorf("unknown job type: %s", jobType)
}
Expand Down
4 changes: 4 additions & 0 deletions core/web/resolver/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-common/pkg/assets"

"github.com/smartcontractkit/chainlink/v2/core/auth"
"github.com/smartcontractkit/chainlink/v2/core/bridges"
ccip "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/validate"
"github.com/smartcontractkit/chainlink/v2/core/logger/audit"
"github.com/smartcontractkit/chainlink/v2/core/services/blockhashstore"
"github.com/smartcontractkit/chainlink/v2/core/services/blockheaderfeeder"
Expand Down Expand Up @@ -1066,6 +1068,8 @@ func (r *Resolver) CreateJob(ctx context.Context, args struct {
jb, err = standardcapabilities.ValidatedStandardCapabilitiesSpec(args.Input.TOML)
case job.Stream:
jb, err = streams.ValidatedStreamSpec(args.Input.TOML)
case job.CCIP:
jb, err = ccip.ValidatedCCIPSpec(args.Input.TOML)
default:
return NewCreateJobPayload(r.App, nil, map[string]string{
"Job Type": fmt.Sprintf("unknown job type: %s", jbt),
Expand Down
1 change: 1 addition & 0 deletions integration-tests/.tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ k3d 5.4.6
kubectl 1.25.5
nodejs 20.13.1
golangci-lint 1.59.1
task 3.35.1
14 changes: 7 additions & 7 deletions integration-tests/ccip-tests/testsetups/test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func SetResourceProfile(cpu, mem string) map[string]interface{} {
}
}

func setNodeConfig(nets []blockchain.EVMNetwork, nodeConfig, commonChain string, configByChain map[string]string) (*corechainlink.Config, string, error) {
func SetNodeConfig(nets []blockchain.EVMNetwork, nodeConfig, commonChain string, configByChain map[string]string) (*corechainlink.Config, string, error) {
var tomlCfg *corechainlink.Config
var err error
var commonChainConfig *evmcfg.Chain
Expand Down Expand Up @@ -122,7 +122,7 @@ func ChainlinkPropsForUpdate(
chainConfigByChain = testInputs.EnvInput.NewCLCluster.Common.ChainConfigTOMLByChain
}

_, tomlStr, err := setNodeConfig(
_, tomlStr, err := SetNodeConfig(
testInputs.SelectedNetworks,
nodeConfig, commonChainConfig, chainConfigByChain,
)
Expand Down Expand Up @@ -150,7 +150,7 @@ func ChainlinkPropsForUpdate(
"version": upgradeTag,
},
}
_, tomlStr, err := setNodeConfig(
_, tomlStr, err := SetNodeConfig(
testInputs.SelectedNetworks,
testInputs.EnvInput.NewCLCluster.Common.BaseConfigTOML,
testInputs.EnvInput.NewCLCluster.Common.CommonChainConfigTOML,
Expand Down Expand Up @@ -216,7 +216,7 @@ func ChainlinkChart(
chainConfigByChain = testInputs.EnvInput.NewCLCluster.Common.ChainConfigTOMLByChain
}

_, tomlStr, err := setNodeConfig(nets, nodeConfig, commonChainConfig, chainConfigByChain)
_, tomlStr, err := SetNodeConfig(nets, nodeConfig, commonChainConfig, chainConfigByChain)
require.NoError(t, err)
nodesMap = append(nodesMap, map[string]any{
"name": clNode.Name,
Expand All @@ -240,7 +240,7 @@ func ChainlinkChart(
return chainlink.New(0, clProps)
}
clProps["replicas"] = pointer.GetInt(testInputs.EnvInput.NewCLCluster.NoOfNodes)
_, tomlStr, err := setNodeConfig(
_, tomlStr, err := SetNodeConfig(
nets,
testInputs.EnvInput.NewCLCluster.Common.BaseConfigTOML,
testInputs.EnvInput.NewCLCluster.Common.CommonChainConfigTOML,
Expand Down Expand Up @@ -335,7 +335,7 @@ func DeployLocalCluster(
// if individual nodes are specified, then deploy them with specified configs
if len(testInputs.EnvInput.NewCLCluster.Nodes) > 0 {
for _, clNode := range testInputs.EnvInput.NewCLCluster.Nodes {
toml, _, err := setNodeConfig(
toml, _, err := SetNodeConfig(
selectedNetworks,
clNode.BaseConfigTOML,
clNode.CommonChainConfigTOML,
Expand Down Expand Up @@ -364,7 +364,7 @@ func DeployLocalCluster(
} else {
// if no individual nodes are specified, then deploy the number of nodes specified in the env input with common config
for i := 0; i < noOfNodes; i++ {
toml, _, err := setNodeConfig(
toml, _, err := SetNodeConfig(
selectedNetworks,
testInputs.EnvInput.NewCLCluster.Common.BaseConfigTOML,
testInputs.EnvInput.NewCLCluster.Common.CommonChainConfigTOML,
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/client/chainlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,9 @@ func CreateNodeKeysBundle(nodes []*ChainlinkClient, chainName string, chainId st
if err != nil {
return nil, nil, err
}

if len(p2pkeys.Data) == 0 {
return nil, nil, fmt.Errorf("found no P2P Keys on the Chainlink node. Node URL: %s", n.URL())
}
peerID := p2pkeys.Data[0].Attributes.PeerID
// If there is already a txkey present for the chain skip creating a new one
// otherwise the test logic will need multiple key management (like funding all the keys,
Expand Down
7 changes: 6 additions & 1 deletion integration-tests/deployment/ccip/add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/integration-tests/deployment"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
Expand Down Expand Up @@ -152,6 +154,9 @@ func TestAddChainInbound(t *testing.T) {

// TODO: Send via all inbound lanes and use parallel helper
// Now that the proposal has been executed we expect to be able to send traffic to this new 4th chain.
startBlock, err := e.Env.Chains[newChain].LatestBlockNum(testcontext.Get(t))
require.NoError(t, err)
seqNr := SendRequest(t, e.Env, state, initialDeploy[0], newChain, true)
ConfirmExecution(t, e.Env.Chains[initialDeploy[0]], e.Env.Chains[newChain], state.Chains[newChain].OffRamp, seqNr)
require.NoError(t,
ConfirmExecWithSeqNr(t, e.Env.Chains[initialDeploy[0]], e.Env.Chains[newChain], state.Chains[newChain].OffRamp, &startBlock, seqNr))
}
6 changes: 5 additions & 1 deletion integration-tests/deployment/ccip/add_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/v2/core/logger"
)

Expand Down Expand Up @@ -48,9 +50,11 @@ func TestAddLane(t *testing.T) {
require.Len(t, offRamps, 0)
}
}
startBlock, err := e.Env.Chains[to].LatestBlockNum(testcontext.Get(t))
require.NoError(t, err)
seqNum := SendRequest(t, e.Env, state, from, to, false)
require.Equal(t, uint64(1), seqNum)
ConfirmExecution(t, e.Env.Chains[from], e.Env.Chains[to], state.Chains[to].OffRamp, seqNum)
require.NoError(t, ConfirmExecWithSeqNr(t, e.Env.Chains[from], e.Env.Chains[to], state.Chains[to].OffRamp, &startBlock, seqNum))

// TODO: Add a second lane, then disable the first and
// ensure we can send on the second but not the first.
Expand Down
Loading

0 comments on commit ac3523a

Please sign in to comment.