Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ettec committed Jan 10, 2025
1 parent 351403a commit c6adbc7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
54 changes: 38 additions & 16 deletions core/capabilities/integration_tests/framework/don.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,23 @@ type DON struct {

nodeConfigModifiers []func(c *chainlink.Config, node *capabilityNode)

fakeLibOcr *FakeLibOCR
addOCR3NonStandardCapability bool

triggerFactories []TriggerFactory
targetFactories []TargetFactory
}

func NewDON(ctx context.Context, t *testing.T, lggr logger.Logger, donConfig DonConfiguration,
dependentDONs []commoncap.DON, donContext DonContext, supportsOCR bool) *DON {
dependentDONs []commoncap.DON, donContext DonContext, supportsOCR bool, protocolRoundInterval time.Duration) *DON {
don := &DON{t: t, lggr: lggr.Named(donConfig.name), config: donConfig, capabilitiesRegistry: donContext.capabilityRegistry,
workflowRegistry: donContext.workflowRegistry}

protocolRoundInterval := 1 * time.Second

var newOracleFactoryFn standardcapabilities.NewOracleFactoryFn
var libOcr *FakeLibOCR
if supportsOCR {
// This is required to support the non standard OCR3 capability - will be removed when required OCR3 behaviour is implemented as standard capabilities
libOcr = NewFakeLibOCR(t, lggr, donConfig.F, protocolRoundInterval)
servicetest.Run(t, libOcr)
don.fakeLibOcr = NewFakeLibOCR(t, lggr, donConfig.F, protocolRoundInterval)
servicetest.Run(t, don.fakeLibOcr)
}

for i, member := range donConfig.Members {
Expand Down Expand Up @@ -271,11 +269,12 @@ func (d *DON) Start(ctx context.Context) error {
}

if d.addOCR3NonStandardCapability {
libocr := NewFakeLibOCR(d.t, d.lggr, d.config.F, 1*time.Second)
servicetest.Run(d.t, libocr)
if d.fakeLibOcr == nil {
return errors.New("don does not support OCR")
}

for _, node := range d.nodes {
addOCR3Capability(ctx, d.t, d.lggr, node.registry, libocr, d.config.F, node.KeyBundle)
addOCR3Capability(ctx, d.t, d.lggr, node.registry, d.fakeLibOcr, d.config.F, node.KeyBundle)
}
}

Expand Down Expand Up @@ -466,7 +465,29 @@ func (d *DON) AddOCR3NonStandardCapability() {
})
}

func (d *DON) AddPublishedEthereumWriteTargetNonStandardCapability(forwarderAddr common.Address) (string, error) {
published := true

capabilityID, s, err := d.addEtherueumWriteTarget(forwarderAddr, published)
if err != nil {
return s, err
}

return capabilityID, nil
}

func (d *DON) AddEthereumWriteTargetNonStandardCapability(forwarderAddr common.Address) (string, error) {
published := false

capabilityID, s, err := d.addEtherueumWriteTarget(forwarderAddr, published)
if err != nil {
return s, err
}

return capabilityID, nil
}

func (d *DON) addEtherueumWriteTarget(forwarderAddr common.Address, published bool) (string, string, error) {
d.nodeConfigModifiers = append(d.nodeConfigModifiers, func(c *chainlink.Config, node *capabilityNode) {
eip55Address := types.EIP55AddressFromAddress(forwarderAddr)
c.EVM[0].Chain.Workflow.ForwarderAddress = &eip55Address
Expand All @@ -488,7 +509,7 @@ func (d *DON) AddEthereumWriteTargetNonStandardCapability(forwarderAddr common.A

configWithLimit, err := values.WrapMap(map[string]any{"gasLimit": 500000})
if err != nil {
return "", fmt.Errorf("failed to wrap map: %w", err)
return "", "", fmt.Errorf("failed to wrap map: %w", err)
}

targetCapabilityConfig.DefaultConfig = values.Proto(configWithLimit).GetMapValue()
Expand All @@ -499,12 +520,13 @@ func (d *DON) AddEthereumWriteTargetNonStandardCapability(forwarderAddr common.A
},
}

d.publishedCapabilities = append(d.publishedCapabilities, capability{
donCapabilityConfig: targetCapabilityConfig,
registryConfig: writeChain,
})

return capabilityID, nil
if published {
d.publishedCapabilities = append(d.publishedCapabilities, capability{
donCapabilityConfig: targetCapabilityConfig,
registryConfig: writeChain,
})
}
return capabilityID, "", nil
}

func addOCR3Capability(ctx context.Context, t *testing.T, lggr logger.Logger, capabilityRegistry *capabilities.Registry,
Expand Down
7 changes: 4 additions & 3 deletions core/capabilities/integration_tests/keystone/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"math/big"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -60,7 +61,7 @@ func setupKeystoneDons(ctx context.Context, t *testing.T, lggr logger.SugaredLog
func createKeystoneTriggerDon(ctx context.Context, t *testing.T, lggr logger.SugaredLogger, triggerDonInfo framework.DonConfiguration,
donContext framework.DonContext, trigger framework.TriggerFactory) *framework.DON {
triggerDon := framework.NewDON(ctx, t, lggr, triggerDonInfo,
[]commoncap.DON{}, donContext, false)
[]commoncap.DON{}, donContext, false, 1*time.Second)

triggerDon.AddExternalTriggerCapability(trigger)
triggerDon.Initialise()
Expand All @@ -69,7 +70,7 @@ func createKeystoneTriggerDon(ctx context.Context, t *testing.T, lggr logger.Sug

func createKeystoneWriteTargetDon(ctx context.Context, t *testing.T, lggr logger.SugaredLogger, targetDonInfo framework.DonConfiguration, donContext framework.DonContext, forwarderAddr common.Address) *framework.DON {
writeTargetDon := framework.NewDON(ctx, t, lggr, targetDonInfo,
[]commoncap.DON{}, donContext, false)
[]commoncap.DON{}, donContext, false, 1*time.Second)
_, err := writeTargetDon.AddEthereumWriteTargetNonStandardCapability(forwarderAddr)
require.NoError(t, err)
writeTargetDon.Initialise()
Expand All @@ -80,7 +81,7 @@ func createKeystoneWorkflowDon(ctx context.Context, t *testing.T, lggr logger.Su
triggerDonInfo framework.DonConfiguration, targetDonInfo framework.DonConfiguration, donContext framework.DonContext) *framework.DON {
workflowDon := framework.NewDON(ctx, t, lggr, workflowDonInfo,
[]commoncap.DON{triggerDonInfo.DON, targetDonInfo.DON},
donContext, true)
donContext, true, 1*time.Second)

workflowDon.AddOCR3NonStandardCapability()
workflowDon.Initialise()
Expand Down

0 comments on commit c6adbc7

Please sign in to comment.