Skip to content

Commit

Permalink
[CAPPL-303] Add commands to deploy the workflow registry
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Dec 17, 2024
1 parent b76f9b3 commit c7c2e89
Show file tree
Hide file tree
Showing 20 changed files with 799 additions and 81 deletions.
19 changes: 10 additions & 9 deletions deployment/keystone/changeset/append_node_capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
)
Expand All @@ -29,10 +30,10 @@ func TestAppendNodeCapabilities(t *testing.T) {
caps = []kcr.CapabilitiesRegistryCapability{capA, capB}
)
t.Run("no mcms", func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
})

Expand All @@ -58,10 +59,10 @@ func TestAppendNodeCapabilities(t *testing.T) {
})
})
t.Run("with mcms", func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
UseMCMS: true,
})
Expand Down Expand Up @@ -108,7 +109,7 @@ func TestAppendNodeCapabilities(t *testing.T) {
}

// validateUpdate checks reads nodes from the registry and checks they have the expected updates
func validateCapabilityAppends(t *testing.T, te TestEnv, appended map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) {
func validateCapabilityAppends(t *testing.T, te test.TestEnv, appended map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) {
registry := te.ContractSets()[te.RegistrySelector].CapabilitiesRegistry
wfP2PIDs := p2pIDs(t, maps.Keys(te.WFNodes))
nodes, err := registry.GetNodesByP2PIds(nil, wfP2PIDs)
Expand Down
17 changes: 9 additions & 8 deletions deployment/keystone/changeset/deploy_forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test"
)

func TestDeployForwarder(t *testing.T) {
Expand Down Expand Up @@ -56,10 +57,10 @@ func TestConfigureForwarders(t *testing.T) {
for _, nChains := range []int{1, 3} {
name := fmt.Sprintf("nChains=%d", nChains)
t.Run(name, func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: nChains,
})

Expand Down Expand Up @@ -93,10 +94,10 @@ func TestConfigureForwarders(t *testing.T) {
for _, nChains := range []int{1, 3} {
name := fmt.Sprintf("nChains=%d", nChains)
t.Run(name, func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: nChains,
UseMCMS: true,
})
Expand Down
17 changes: 9 additions & 8 deletions deployment/keystone/changeset/deploy_ocr3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
kslib "github.com/smartcontractkit/chainlink/deployment/keystone"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test"
)

func TestDeployOCR3(t *testing.T) {
Expand Down Expand Up @@ -54,10 +55,10 @@ func TestConfigureOCR3(t *testing.T) {

t.Run("no mcms", func(t *testing.T) {

te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
})

Expand Down Expand Up @@ -85,10 +86,10 @@ func TestConfigureOCR3(t *testing.T) {
})

t.Run("mcms", func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
UseMCMS: true,
})
Expand Down
33 changes: 33 additions & 0 deletions deployment/keystone/changeset/internal/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,47 @@ import (
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
workflow_registry "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/workflow/generated/workflow_registry_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
)

type SetupTestWorkflowRegistryResponse struct {
Registry *workflow_registry.WorkflowRegistry
Chain deployment.Chain
RegistrySelector uint64
AddressBook deployment.AddressBook
}

func SetupTestWorkflowRegistry(t *testing.T, lggr logger.Logger, chainSel uint64) *SetupTestWorkflowRegistryResponse {
chain := testChain(t)

deployer, err := kslib.NewWorkflowRegistryDeployer()
require.NoError(t, err)
resp, err := deployer.Deploy(kslib.DeployRequest{Chain: chain})
require.NoError(t, err)

addressBook := deployment.NewMemoryAddressBookFromMap(
map[uint64]map[string]deployment.TypeAndVersion{
chainSel: map[string]deployment.TypeAndVersion{
resp.Address.Hex(): resp.Tv,
},
},
)

return &SetupTestWorkflowRegistryResponse{
Registry: deployer.Contract(),
Chain: chain,
RegistrySelector: chain.Selector,
AddressBook: addressBook,
}
}

type Don struct {
Name string
P2PIDs []p2pkey.PeerID
CapabilityConfigs []internal.CapabilityConfig
}

type SetupTestRegistryRequest struct {
P2pToCapabilities map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability
NopToNodes map[kcr.CapabilitiesRegistryNodeOperator][]*internal.P2PSignerEnc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package changeset_test
package test

import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"math"
"sort"
"testing"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"golang.org/x/exp/maps"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/deployment"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
Expand All @@ -26,33 +25,11 @@ import (
"github.com/smartcontractkit/chainlink/deployment/keystone"
kslib "github.com/smartcontractkit/chainlink/deployment/keystone"
kschangeset "github.com/smartcontractkit/chainlink/deployment/keystone/changeset"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/workflowregistry"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
)

func TestSetupTestEnv(t *testing.T) {
t.Parallel()
ctx := tests.Context(t)
for _, useMCMS := range []bool{true, false} {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
NumChains: 3,
UseMCMS: useMCMS,
})
t.Run(fmt.Sprintf("set up test env using MCMS: %t", useMCMS), func(t *testing.T) {
require.NotNil(t, te.Env.ExistingAddresses)
require.Len(t, te.Env.Chains, 3)
require.NotEmpty(t, te.RegistrySelector)
require.NotNil(t, te.Env.Offchain)
r, err := te.Env.Offchain.ListNodes(ctx, &node.ListNodesRequest{})
require.NoError(t, err)
require.Len(t, r.Nodes, 12)
})
}
}

type DonConfig struct {
N int
}
Expand Down Expand Up @@ -143,6 +120,10 @@ func SetupTestEnv(t *testing.T, c TestConfig) TestEnv {
Changeset: commonchangeset.WrapChangeSet(kschangeset.DeployForwarder),
Config: registryChainSel,
},
{
Changeset: commonchangeset.WrapChangeSet(workflowregistry.Deploy),
Config: registryChainSel,
},
})
require.NoError(t, err)
require.NotNil(t, e)
Expand Down Expand Up @@ -318,15 +299,15 @@ func validateInitialChainState(t *testing.T, env deployment.Environment, registr
// all contracts on registry chain
registryChainAddrs, err := ad.AddressesForChain(registryChainSel)
require.NoError(t, err)
require.Len(t, registryChainAddrs, 3) // registry, ocr3, forwarder
require.Len(t, registryChainAddrs, 4) // registry, ocr3, forwarder, workflowRegistry
// only forwarder on non-home chain
for sel := range env.Chains {
chainAddrs, err := ad.AddressesForChain(sel)
require.NoError(t, err)
if sel != registryChainSel {
require.Len(t, chainAddrs, 1)
} else {
require.Len(t, chainAddrs, 3)
require.Len(t, chainAddrs, 4)
}
containsForwarder := false
for _, tv := range chainAddrs {
Expand Down
34 changes: 34 additions & 0 deletions deployment/keystone/changeset/test/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node"
)

func TestSetupTestEnv(t *testing.T) {
t.Parallel()
ctx := tests.Context(t)
for _, useMCMS := range []bool{true, false} {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
NumChains: 3,
UseMCMS: useMCMS,
})
t.Run(fmt.Sprintf("set up test env using MCMS: %t", useMCMS), func(t *testing.T) {
require.NotNil(t, te.Env.ExistingAddresses)
require.Len(t, te.Env.Chains, 3)
require.NotEmpty(t, te.RegistrySelector)
require.NotNil(t, te.Env.Offchain)
r, err := te.Env.Offchain.ListNodes(ctx, &node.ListNodesRequest{})
require.NoError(t, err)
require.Len(t, r.Nodes, 12)
})
}
}
17 changes: 9 additions & 8 deletions deployment/keystone/changeset/update_don_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
)
Expand All @@ -29,10 +30,10 @@ func TestUpdateDon(t *testing.T) {
caps = []kcr.CapabilitiesRegistryCapability{capA, capB}
)
t.Run("no mcms", func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
})

Expand Down Expand Up @@ -70,10 +71,10 @@ func TestUpdateDon(t *testing.T) {
})
})
t.Run("with mcms", func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
UseMCMS: true,
})
Expand Down
19 changes: 10 additions & 9 deletions deployment/keystone/changeset/update_node_capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset"
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
)
Expand All @@ -29,10 +30,10 @@ func TestUpdateNodeCapabilities(t *testing.T) {
caps = []kcr.CapabilitiesRegistryCapability{capA, capB}
)
t.Run("no mcms", func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
})

Expand Down Expand Up @@ -79,10 +80,10 @@ func TestUpdateNodeCapabilities(t *testing.T) {
})
})
t.Run("with mcms", func(t *testing.T) {
te := SetupTestEnv(t, TestConfig{
WFDonConfig: DonConfig{N: 4},
AssetDonConfig: DonConfig{N: 4},
WriterDonConfig: DonConfig{N: 4},
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
UseMCMS: true,
})
Expand Down Expand Up @@ -140,7 +141,7 @@ func TestUpdateNodeCapabilities(t *testing.T) {
}

// validateUpdate checks reads nodes from the registry and checks they have the expected updates
func validateCapabilityUpdates(t *testing.T, te TestEnv, expected map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) {
func validateCapabilityUpdates(t *testing.T, te test.TestEnv, expected map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) {
registry := te.ContractSets()[te.RegistrySelector].CapabilitiesRegistry
wfP2PIDs := p2pIDs(t, maps.Keys(te.WFNodes))
nodes, err := registry.GetNodesByP2PIds(nil, wfP2PIDs)
Expand Down
Loading

0 comments on commit c7c2e89

Please sign in to comment.