Skip to content

Commit

Permalink
Adds test - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzaldysanchez committed Nov 20, 2024
1 parent 3d1351e commit a582991
Show file tree
Hide file tree
Showing 3 changed files with 507 additions and 17 deletions.
35 changes: 18 additions & 17 deletions deployment/common/changeset/capability_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/common/view/v1_0"
"github.com/smartcontractkit/chainlink/deployment/keystone"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
)

Expand Down Expand Up @@ -41,31 +42,31 @@ func HydrateCapabilityRegistry(v v1_0.CapabilityRegistryView, env deployment.Env
return nil, fmt.Errorf("failed to deploy contract: %w", err)
}

nodesParams, err := v.NodesToNodesParams()
if err != nil {
return nil, fmt.Errorf("failed to convert nodes to nodes params: %w", err)
nopsParams := v.NopsToNopsParams()
for _, nop := range v.Nops {
nopsParams = append(nopsParams, capabilities_registry.CapabilitiesRegistryNodeOperator{
Admin: nop.Admin,
Name: nop.Name,
})
}
tx, err := deployedContract.Contract.AddNodes(chain.DeployerKey, nodesParams)
if _, err = deployment.ConfirmIfNoError(chain, tx, err); err != nil {
return nil, fmt.Errorf("failed to add nodes: %w", err)
tx, err := deployedContract.Contract.AddNodeOperators(chain.DeployerKey, nopsParams)
if _, err = deployment.ConfirmIfNoError(chain, tx, keystone.DecodeErr(capabilities_registry.CapabilitiesRegistryABI, err)); err != nil {
return nil, fmt.Errorf("failed to add node operators: %w", err)
}

capabilitiesParams := v.CapabilitiesToCapabilitiesParams()
tx, err = deployedContract.Contract.AddCapabilities(chain.DeployerKey, capabilitiesParams)
if _, err = deployment.ConfirmIfNoError(chain, tx, err); err != nil {
if _, err = deployment.ConfirmIfNoError(chain, tx, keystone.DecodeErr(capabilities_registry.CapabilitiesRegistryABI, err)); err != nil {
return nil, fmt.Errorf("failed to add capabilities: %w", err)
}

nopsParams := v.NopsToNopsParams()
for _, nop := range v.Nops {
nopsParams = append(nopsParams, capabilities_registry.CapabilitiesRegistryNodeOperator{
Admin: nop.Admin,
Name: nop.Name,
})
nodesParams, err := v.NodesToNodesParams()
if err != nil {
return nil, fmt.Errorf("failed to convert nodes to nodes params: %w", err)
}
tx, err = deployedContract.Contract.AddNodeOperators(chain.DeployerKey, nopsParams)
if _, err = deployment.ConfirmIfNoError(chain, tx, err); err != nil {
return nil, fmt.Errorf("failed to add node operators: %w", err)
tx, err = deployedContract.Contract.AddNodes(chain.DeployerKey, nodesParams)
if _, err = deployment.ConfirmIfNoError(chain, tx, keystone.DecodeErr(capabilities_registry.CapabilitiesRegistryABI, err)); err != nil {
return nil, fmt.Errorf("failed to add nodes: %w", err)
}

for _, don := range v.Dons {
Expand All @@ -78,7 +79,7 @@ func HydrateCapabilityRegistry(v v1_0.CapabilityRegistryView, env deployment.Env
peerIds = append(peerIds, id)
}
tx, err = deployedContract.Contract.AddDON(chain.DeployerKey, peerIds, cfgs, don.IsPublic, don.AcceptsWorkflows, don.F)
if _, err = deployment.ConfirmIfNoError(chain, tx, err); err != nil {
if _, err = deployment.ConfirmIfNoError(chain, tx, keystone.DecodeErr(capabilities_registry.CapabilitiesRegistryABI, err)); err != nil {
return nil, fmt.Errorf("failed to add don: %w", err)
}
}
Expand Down
34 changes: 34 additions & 0 deletions deployment/common/changeset/capability_registry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package changeset

import (
"encoding/json"
"os"
"testing"

chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink/deployment/common/view/v1_0"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestHydrateCapabilityRegistry(t *testing.T) {
b, err := os.ReadFile("testdata/capability_registry_view.json")
require.NoError(t, err)
require.NotEmpty(t, b)
var capabilityRegistryView v1_0.CapabilityRegistryView
require.NoError(t, json.Unmarshal(b, &capabilityRegistryView))

chainID := chainsel.TEST_90000001.EvmChainID + 1
cfg := HydrateConfig{ChainID: chainID}
env := memory.NewMemoryEnvironment(t, logger.TestLogger(t), zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Bootstraps: 1,
Chains: 2,
Nodes: 4,
})
hydrated, err := HydrateCapabilityRegistry(capabilityRegistryView, env, cfg)
require.NoError(t, err)
require.NotNil(t, hydrated)
}
Loading

0 comments on commit a582991

Please sign in to comment.